Location: PHPKode > projects > Openelibrary > e-library/include/search_functions.php
<?


function SetUpDisplayRecs()
{
	global $HTTP_SESSION_VARS;
	global $HTTP_GET_VARS;
	global $nStartRec;
	global $nDisplayRecs;
	global $nTotalRecs;
	$sWrk = @$HTTP_GET_VARS[ewTblRecPerPage];
	if ($sWrk <> "") {
		if (is_numeric($sWrk)) {
			$nDisplayRecs = $sWrk;
		} else {
			if (strtolower($sWrk) == "all") { // Display all records
				$nDisplayRecs = -1;
			} else {
				$nDisplayRecs = 20;  // Non-numeric, load default
			}
		}
		$HTTP_SESSION_VARS[ewSessionTblRecPerPage] = $nDisplayRecs; // Save to Session

		// Reset Start Position (Reset Command)
		$nStartRec = 1;
		$HTTP_SESSION_VARS[ewSessionTblStartRec] = $nStartRec;
	} else {
		if (@$HTTP_SESSION_VARS[ewSessionTblRecPerPage] <> "") {
			$nDisplayRecs = $HTTP_SESSION_VARS[ewSessionTblRecPerPage]; // Restore from Session
		} else {
			$nDisplayRecs = 20; // Load Default
		}
	}
}

//-------------------------------------------------------------------------------
// Function SetUpAdvancedSearch
// - Set up Advanced Search parameter based on querystring parameters from Advanced Search Page
// - Variables setup: sSrchAdvanced

function SetUpAdvancedSearch()
{
	global $HTTP_GET_VARS;
	global $HTTP_SESSION_VARS;
	global $sSrchAdvanced;

	// Field title
	$sSrchStr = "";
		$GLOBALS["x_title"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_title"]) : @$HTTP_GET_VARS["x_title"];
	$GLOBALS["z_title"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_title"]) : @$HTTP_GET_VARS["z_title"];
	$arrFldOpr = split(",", $GLOBALS["z_title"]);
	if ($GLOBALS["x_title"] <> "" And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.title " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_title"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field title_en
	$sSrchStr = "";
		$GLOBALS["x_title_en"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_title_en"]) : @$HTTP_GET_VARS["x_title_en"];
	$GLOBALS["z_title_en"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_title_en"]) : @$HTTP_GET_VARS["z_title_en"];
	$arrFldOpr = split(",", $GLOBALS["z_title_en"]);
	if ($GLOBALS["x_title_en"] <> "" And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.title_en " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_title_en"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field Autore
	$sSrchStr = "";
		$GLOBALS["x_Autore"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_Autore"]) : @$HTTP_GET_VARS["x_Autore"];
	$GLOBALS["z_Autore"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_Autore"]) : @$HTTP_GET_VARS["z_Autore"];
	$arrFldOpr = split(",", $GLOBALS["z_Autore"]);
	if ($GLOBALS["x_Autore"] <> "" And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.Autore " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_Autore"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_tip_autore
	$sSrchStr = "";
		$GLOBALS["x_id_tip_autore"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_tip_autore"]) : @$HTTP_GET_VARS["x_id_tip_autore"];
	$GLOBALS["z_id_tip_autore"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_tip_autore"]) : @$HTTP_GET_VARS["z_id_tip_autore"];
	$arrFldOpr = split(",", $GLOBALS["z_id_tip_autore"]);
	if ($GLOBALS["x_id_tip_autore"] <> "" And is_numeric($GLOBALS["x_id_tip_autore"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_tip_autore " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_tip_autore"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_autor_gender
	$sSrchStr = "";
		$GLOBALS["x_id_autor_gender"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_autor_gender"]) : @$HTTP_GET_VARS["x_id_autor_gender"];
	$GLOBALS["z_id_autor_gender"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_autor_gender"]) : @$HTTP_GET_VARS["z_id_autor_gender"];
	$arrFldOpr = split(",", $GLOBALS["z_id_autor_gender"]);
	if ($GLOBALS["x_id_autor_gender"] <> "" And is_numeric($GLOBALS["x_id_autor_gender"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_autor_gender " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_autor_gender"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_thematic
	$sSrchStr = "";
	if (@$HTTP_GET_VARS["a_search"] == "E") {
		$GLOBALS["x_id_thematic"] = @implode(",", @$HTTP_GET_VARS["x_id_thematic"]);	
	} else {
		$GLOBALS["x_id_thematic"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_thematic"]) : @$HTTP_GET_VARS["x_id_thematic"];
	}
	$GLOBALS["z_id_thematic"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_thematic"]) : @$HTTP_GET_VARS["z_id_thematic"];
	$arrFldOpr = split(",", $GLOBALS["z_id_thematic"]);
	if ($GLOBALS["x_id_thematic"] <> "" And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_thematic " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_thematic"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field anno_pub
	$sSrchStr = "";
		$GLOBALS["x_anno_pub"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_anno_pub"]) : @$HTTP_GET_VARS["x_anno_pub"];
	$GLOBALS["z_anno_pub"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_anno_pub"]) : @$HTTP_GET_VARS["z_anno_pub"];
	$arrFldOpr = split(",", $GLOBALS["z_anno_pub"]);
	if ($GLOBALS["x_anno_pub"] <> "" And is_numeric($GLOBALS["x_anno_pub"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.anno_pub " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_anno_pub"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_place_city
	$sSrchStr = "";
		$GLOBALS["x_id_place_city"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_place_city"]) : @$HTTP_GET_VARS["x_id_place_city"];
	$GLOBALS["z_id_place_city"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_place_city"]) : @$HTTP_GET_VARS["z_id_place_city"];
	$arrFldOpr = split(",", $GLOBALS["z_id_place_city"]);
	if ($GLOBALS["x_id_place_city"] <> "" And is_numeric($GLOBALS["x_id_place_city"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_place_city " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_place_city"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field Editorial_Publisher
	$sSrchStr = "";
		$GLOBALS["x_Editorial_Publisher"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_Editorial_Publisher"]) : @$HTTP_GET_VARS["x_Editorial_Publisher"];
	$GLOBALS["z_Editorial_Publisher"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_Editorial_Publisher"]) : @$HTTP_GET_VARS["z_Editorial_Publisher"];
	$arrFldOpr = split(",", $GLOBALS["z_Editorial_Publisher"]);
	if ($GLOBALS["x_Editorial_Publisher"] <> "" And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.Editorial_Publisher " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_Editorial_Publisher"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_language
	$sSrchStr = "";
		$GLOBALS["x_id_language"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_language"]) : @$HTTP_GET_VARS["x_id_language"];
	$GLOBALS["z_id_language"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_language"]) : @$HTTP_GET_VARS["z_id_language"];
	$arrFldOpr = split(",", $GLOBALS["z_id_language"]);
	if ($GLOBALS["x_id_language"] <> "" And is_numeric($GLOBALS["x_id_language"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_language " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_language"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_version
	$sSrchStr = "";
		$GLOBALS["x_id_version"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_version"]) : @$HTTP_GET_VARS["x_id_version"];
	$GLOBALS["z_id_version"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_version"]) : @$HTTP_GET_VARS["z_id_version"];
	$arrFldOpr = split(",", $GLOBALS["z_id_version"]);
	if ($GLOBALS["x_id_version"] <> "" And is_numeric($GLOBALS["x_id_version"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_version " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_version"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_tipo_testo
	$sSrchStr = "";
	if (@$HTTP_GET_VARS["a_search"] == "E") {
		$GLOBALS["x_id_tipo_testo"] = @implode(",", @$HTTP_GET_VARS["x_id_tipo_testo"]);	
	} else {
		$GLOBALS["x_id_tipo_testo"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_tipo_testo"]) : @$HTTP_GET_VARS["x_id_tipo_testo"];
	}
	$GLOBALS["z_id_tipo_testo"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_tipo_testo"]) : @$HTTP_GET_VARS["z_id_tipo_testo"];
	$arrFldOpr = split(",", $GLOBALS["z_id_tipo_testo"]);
	if ($GLOBALS["x_id_tipo_testo"] <> "" And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_tipo_testo " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_tipo_testo"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_license
	$sSrchStr = "";
		$GLOBALS["x_id_license"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_license"]) : @$HTTP_GET_VARS["x_id_license"];
	$GLOBALS["z_id_license"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_license"]) : @$HTTP_GET_VARS["z_id_license"];
	$arrFldOpr = split(",", $GLOBALS["z_id_license"]);
	if ($GLOBALS["x_id_license"] <> "" And is_numeric($GLOBALS["x_id_license"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_license " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_license"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field Extension
	$sSrchStr = "";
		$GLOBALS["x_Extension"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_Extension"]) : @$HTTP_GET_VARS["x_Extension"];
	$GLOBALS["z_Extension"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_Extension"]) : @$HTTP_GET_VARS["z_Extension"];
	$arrFldOpr = split(",", $GLOBALS["z_Extension"]);
	if ($GLOBALS["x_Extension"] <> "" And is_numeric($GLOBALS["x_Extension"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.Extension " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_Extension"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}

	// Field id_access
	$sSrchStr = "";
		$GLOBALS["x_id_access"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_id_access"]) : @$HTTP_GET_VARS["x_id_access"];
	$GLOBALS["z_id_access"] = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_id_access"]) : @$HTTP_GET_VARS["z_id_access"];
	$arrFldOpr = split(",", $GLOBALS["z_id_access"]);
	if ($GLOBALS["x_id_access"] <> "" And is_numeric($GLOBALS["x_id_access"]) And isValidOpr($arrFldOpr)) {
		$sSrchStr .= "autori.id_access " . $arrFldOpr[0] . " " . @$arrFldOpr[1] . AdjustSql($GLOBALS["x_id_access"]) . @$arrFldOpr[2] . " ";
	}
	if ($sSrchStr <> "") {
		if ($sSrchAdvanced <> "") $sSrchAdvanced .= " AND ";
		$sSrchAdvanced .= "(" . $sSrchStr . ")";
	}
	if ($sSrchAdvanced <> "") { // Save settings
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_title"] = $GLOBALS["x_title"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_title_en"] = $GLOBALS["x_title_en"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Autore"] = $GLOBALS["x_Autore"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_tip_autore"] = $GLOBALS["x_id_tip_autore"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_autor_gender"] = $GLOBALS["x_id_autor_gender"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_thematic"] = $GLOBALS["x_id_thematic"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_anno_pub"] = $GLOBALS["x_anno_pub"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_place_city"] = $GLOBALS["x_id_place_city"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Editorial_Publisher"] = $GLOBALS["x_Editorial_Publisher"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_language"] = $GLOBALS["x_id_language"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_version"] = $GLOBALS["x_id_version"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_tipo_testo"] = $GLOBALS["x_id_tipo_testo"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_license"] = $GLOBALS["x_id_license"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Extension"] = $GLOBALS["x_Extension"];
		$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_access"] = $GLOBALS["x_id_access"];
	}
}

//-------------------------------------------------------------------------------
// Function BasicSearchSQL
// - Build WHERE clause for a keyword

function BasicSearchSQL($Keyword)
{
	$sKeyword = (!get_magic_quotes_gpc()) ? addslashes($Keyword) : $Keyword;
	$BasicSearchSQL = "";
	$BasicSearchSQL.= "autori.title LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.title_en LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.Autore LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.abstract LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.id_thematic LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.semantic LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.Editorial_Publisher LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.id_tipo_testo LIKE '%" . $sKeyword . "%' OR ";
	if (is_numeric($sKeyword)) { $BasicSearchSQL .= "autori.id_access = " . $sKeyword . " OR " ; }
	$BasicSearchSQL.= "autori.articolo LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.access_type_c LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.bib_reference LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.comments LIKE '%" . $sKeyword . "%' OR ";
	if (substr($BasicSearchSQL, -4) == " OR ") { $BasicSearchSQL = substr($BasicSearchSQL, 0, strlen($BasicSearchSQL)-4); }
	return $BasicSearchSQL;
}


function BasicSearchSQL_unlike($Keyword)
{
	$sKeyword = (!get_magic_quotes_gpc()) ? addslashes($Keyword) : $Keyword;
	$BasicSearchSQL = "";
	$BasicSearchSQL.= "autori.title NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.title_en NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.Autore NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.abstract NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.id_thematic NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.semantic NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.Editorial_Publisher NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.id_tipo_testo NOT LIKE '%" . $sKeyword . "%' OR ";
	if (is_numeric($sKeyword)) { $BasicSearchSQL .= "autori.id_access = " . $sKeyword . " OR " ; }
	$BasicSearchSQL.= "autori.articolo NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.access_type_c NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.bib_reference NOT LIKE '%" . $sKeyword . "%' OR ";
	$BasicSearchSQL.= "autori.comments NOT LIKE '%" . $sKeyword . "%' OR ";
	if (substr($BasicSearchSQL, -4) == " OR ") { $BasicSearchSQL = substr($BasicSearchSQL, 0, strlen($BasicSearchSQL)-4); }
	return $BasicSearchSQL;
}
//-------------------------------------------------------------------------------
// Function SetUpBasicSearch
// - Set up Basic Search parameter based on form elements pSearch & pSearchType
// - Variables setup: sSrchBasic

function SetUpBasicSearch()
{
	global $HTTP_GET_VARS;
	global $HTTP_SESSION_VARS;
	global $sSrchBasic, $psearch, $psearchtype;
	if ($psearch <> "") {
		if ($psearchtype <> "") {
			while (strpos($psearch, "  ") != false) {
				$psearch = str_replace("  ", " ",$psearch);
			}
			$arKeyword = split(" ", trim($psearch));
			foreach ($arKeyword as $sKeyword) {
				$sSrchBasic .= "(" . BasicSearchSQL($sKeyword) . ") " . $psearchtype . " ";
			}
		} else {
			$sSrchBasic = BasicSearchSQL($psearch);
		}
	}
	if (substr($sSrchBasic, -4) == " OR ") { $sSrchBasic = substr($sSrchBasic, 0, strlen($sSrchBasic)-4); }
	if (substr($sSrchBasic, -5) == " AND ") { $sSrchBasic = substr($sSrchBasic, 0, strlen($sSrchBasic)-5); }
	if ($psearch <> "") {
		$HTTP_SESSION_VARS[ewSessionTblBasicSrch] = $psearch;
		$HTTP_SESSION_VARS[ewSessionTblBasicSrchType] = $psearchtype;
	}
}

//-------------------------------------------------------------------------------
// Function ResetSearch
// - Clear all search parameters

function ResetSearch() 
{
	global $HTTP_SESSION_VARS;

	// Clear search where
	$sSrchWhere = "";
	$HTTP_SESSION_VARS[ewSessionTblSearchWhere] = $sSrchWhere;

	// Clear advanced search parameters
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_title"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_title_en"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Autore"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_tip_autore"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_autor_gender"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_thematic"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_anno_pub"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_place_city"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Editorial_Publisher"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_language"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_version"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_tipo_testo"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_license"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Extension"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_access"] = "";
	$HTTP_SESSION_VARS[ewSessionTblBasicSrch] = "";
	$HTTP_SESSION_VARS[ewSessionTblBasicSrchType] = "";
}

//-------------------------------------------------------------------------------
// Function RestoreSearch
// - Restore all search parameters
//

function RestoreSearch()
{
	global $HTTP_SESSION_VARS;

	// Restore advanced search settings
	$GLOBALS["x_title"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_title"];
	$GLOBALS["x_title_en"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_title_en"];
	$GLOBALS["x_Autore"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Autore"];
	$GLOBALS["x_id_tip_autore"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_tip_autore"];
	$GLOBALS["x_id_autor_gender"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_autor_gender"];
	$GLOBALS["x_id_thematic"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_thematic"];
	$GLOBALS["x_anno_pub"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_anno_pub"];
	$GLOBALS["x_id_place_city"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_place_city"];
	$GLOBALS["x_Editorial_Publisher"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Editorial_Publisher"];
	$GLOBALS["x_id_language"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_language"];
	$GLOBALS["x_id_version"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_version"];
	$GLOBALS["x_id_tipo_testo"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_tipo_testo"];
	$GLOBALS["x_id_license"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_license"];
	$GLOBALS["x_Extension"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_Extension"];
	$GLOBALS["x_id_access"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_access"];
	$GLOBALS["psearch"] = @$HTTP_SESSION_VARS[ewSessionTblBasicSrch];
	$GLOBALS["psearchtype"] = @$HTTP_SESSION_VARS[ewSessionTblBasicSrchType];
}

//-------------------------------------------------------------------------------
// Function SetUpSortOrder
// - Set up Sort parameters based on Sort Links clicked
// - Variables setup: sOrderBy, Session(TblOrderBy), Session(Tbl_Field_Sort)

function SetUpSortOrder()
{
	global $HTTP_SESSION_VARS;
	global $HTTP_GET_VARS;
	global $sOrderBy;
	global $sDefaultOrderBy;

	// Check for an Order parameter
	if (strlen(@$HTTP_GET_VARS["order"]) > 0) {
		$sOrder = @$HTTP_GET_VARS["order"];

		// Field autori.title
		if ($sOrder == "title") {
			$sSortField = "autori.title";
			$sLastSort = @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title"];
			$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title"] = $sThisSort;
		} else {
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title"] <> "") { @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title"] = ""; }
		}

		// Field autori.title_en
		if ($sOrder == "title_en") {
			$sSortField = "autori.title_en";
			$sLastSort = @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title_en"];
			$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title_en"] = $sThisSort;
		} else {
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title_en"] <> "") { @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title_en"] = ""; }
		}

		// Field autori.Autore
		if ($sOrder == "Autore") {
			$sSortField = "autori.Autore";
			$sLastSort = @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_Autore"];
			$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			$HTTP_SESSION_VARS[ewSessionTblSort . "_x_Autore"] = $sThisSort;
		} else {
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_Autore"] <> "") { @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_Autore"] = ""; }
		}
		$HTTP_SESSION_VARS[ewSessionTblOrderBy] = $sSortField . " " . $sThisSort;
		$HTTP_SESSION_VARS[ewSessionTblStartRec] = 1;
	}
	$sOrderBy = @$HTTP_SESSION_VARS[ewSessionTblOrderBy];
	if ($sOrderBy == "") {
		$sOrderBy = ewSqlOrderBy;
		@$HTTP_SESSION_VARS[ewSessionTblOrderBy] = $sOrderBy;
		if ($sOrderBy <> "") {
			$arOrderBy = explode(",", ewSqlOrderBySessions);
			for($i=0; $i<count($arOrderBy); $i+=2) {
				@$HTTP_SESSION_VARS[ewSessionTblSort . "_" . $arOrderBy[$i]] = $arOrderBy[$i+1];
			}
		}
	}
}

//-------------------------------------------------------------------------------
// Function SetUpStartRec
//- Set up Starting Record parameters based on Pager Navigation
// - Variables setup: nStartRec

function SetUpStartRec()
{

	// Check for a START parameter
	global $HTTP_SESSION_VARS;
	global $HTTP_GET_VARS;
	global $nStartRec;
	global $nDisplayRecs;
	global $nTotalRecs;
	if (strlen(@$HTTP_GET_VARS[ewTblStartRec]) > 0) {
		$nStartRec = @$HTTP_GET_VARS[ewTblStartRec];
		$HTTP_SESSION_VARS[ewSessionTblStartRec] = $nStartRec;
	} elseif (strlen(@$HTTP_GET_VARS["pageno"]) > 0) {
		$nPageNo = @$HTTP_GET_VARS["pageno"];
		if (is_numeric($nPageNo)) {
			$nStartRec = ($nPageNo-1)*$nDisplayRecs+1;
			if ($nStartRec <= 0) {
				$nStartRec = 1;
			} elseif ($nStartRec >= (($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1) {
				$nStartRec = (($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1;
			}
			$HTTP_SESSION_VARS[ewSessionTblStartRec] = $nStartRec;
		} else {
			$nStartRec = @$HTTP_SESSION_VARS[ewSessionTblStartRec];
			if  (!(is_numeric($nStartRec)) || ($nStartRec == "")) {
				$nStartRec = 1; // Reset start record counter
				$HTTP_SESSION_VARS[ewSessionTblStartRec] = $nStartRec;
			}
		}
	} else {
		$nStartRec = @$HTTP_SESSION_VARS[ewSessionTblStartRec];
		if (!(is_numeric($nStartRec)) || ($nStartRec == "")) {
			$nStartRec = 1; // Reset start record counter
			$HTTP_SESSION_VARS[ewSessionTblStartRec] = $nStartRec;
		}
	}
}

//-------------------------------------------------------------------------------
// Function ResetCmd
// - Clear list page parameters
// - RESET: reset search parameters
// - RESETALL: reset search & master/detail parameters
// - RESETSORT: reset sort parameters

function ResetCmd()
{
	global $HTTP_SESSION_VARS;
	global $HTTP_GET_VARS;

	// Get Reset command
	if (strlen(@$HTTP_GET_VARS["cmd"]) > 0) {
		$sCmd = @$HTTP_GET_VARS["cmd"];
		if (strtolower($sCmd) == "reset") { // Reset search criteria
			ResetSearch();
		} elseif (strtolower($sCmd) == "resetall") { // Reset search criteria and session vars
			ResetSearch();
		} elseif (strtolower($sCmd) == "resetsort") { // Reset sort criteria
			$sOrderBy = "";
			$HTTP_SESSION_VARS[ewSessionTblOrderBy] = $sOrderBy;
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title"] <> "") { $HTTP_SESSION_VARS[ewSessionTblSort . "_x_title"] = ""; }
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_title_en"] <> "") { $HTTP_SESSION_VARS[ewSessionTblSort . "_x_title_en"] = ""; }
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_Autore"] <> "") { $HTTP_SESSION_VARS[ewSessionTblSort . "_x_Autore"] = ""; }
		}

		// Reset start position (Reset command)
		$nStartRec = 1;
		$HTTP_SESSION_VARS[ewSessionTblStartRec] = $nStartRec;
	}
}
?>
Return current item: Openelibrary