Location: PHPKode > projects > Openelibrary > e-library/languagelist.php
<?php 
session_start();
ob_start();
?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php
if (@phpversion() >= '5.0.0' && (!@ini_get('register_long_arrays') || @ini_get('register_long_arrays') == '0' || strtolower(@ini_get('register_long_arrays')) == 'off')) { // PHP5 with register_long_arrays off
	$HTTP_POST_VARS = &$_POST;
	$HTTP_GET_VARS = &$_GET;
	$HTTP_SERVER_VARS = &$_SERVER;
	$HTTP_COOKIE_VARS = &$_COOKIE;
	$HTTP_ENV_VARS = &$_ENV;
	$HTTP_POST_FILES = &$_FILES;
	if (isset($_SESSION)) $HTTP_SESSION_VARS = &$_SESSION;
}
?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("languageinfo.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("phpmkrfn.php") ?>
<?php include ("ewupload.php") ?>
<?php
	if (!IsLoggedIn() && (@$HTTP_COOKIE_VARS[ewCookieAutoLogin] == "autologin" && @$HTTP_COOKIE_VARS[ewCookiePassword] <> "")) {
		ob_end_clean();
		header("Location: login.php");
		exit();
	}
	LoadUserLevel();
	$ewCurSec = (IsLoggedIn())? CurrentUserLevelPriv("language") : GetAnonymousPriv("language");
	if (($ewCurSec & ewAllowList) <> ewAllowList) {
		ob_end_clean();
		header("Location: login.php");
		exit();
	}
?>
<?php

// Initialize common variables
$x_id_language = NULL;
$ox_id_language = NULL;
$z_id_language = NULL;
$ar_x_id_language = NULL;
$ari_x_id_language = NULL;
$x_id_languageList = NULL;
$x_id_languageChk = NULL;
$cbo_x_id_language_js = NULL;
$x_language = NULL;
$ox_language = NULL;
$z_language = NULL;
$ar_x_language = NULL;
$ari_x_language = NULL;
$x_languageList = NULL;
$x_languageChk = NULL;
$cbo_x_language_js = NULL;
?>
<?php
$nStartRec = 0;
$nStopRec = 0;
$nTotalRecs = 0;
$nRecCount = 0;
$nRecActual = 0;
$sKeyMaster = "";
$sDbWhereMaster = "";
$sSrchAdvanced = "";
$psearch = "";
$psearchtype = "";
$sDbWhereDetail = "";
$sSrchBasic = "";
$sSrchWhere = "";
$sDbWhere = "";
$sOrderBy = "";
$sSqlMaster = "";
$sListTrJs = "";
$bEditRow = "";
$nEditRowCnt = "";
$sDeleteConfirmMsg = "";
$nDisplayRecs = "20";
$nRecRange = 10;

// Set up records per page dynamically
SetUpDisplayRecs();

// Open connection to the database
$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);

// Handle reset command
ResetCmd();

// Get search criteria for Basic (Quick) Search
$psearch = (!get_magic_quotes_gpc()) ? addslashes(@$HTTP_GET_VARS[ewTblBasicSrch]) : @$HTTP_GET_VARS[ewTblBasicSrch];
$psearchtype = @$HTTP_GET_VARS[ewTblBasicSrchType];
SetUpBasicSearch();

// Build search criteria
if ($sSrchAdvanced != "") {
	if ($sSrchWhere <> "") $sSrchWhere .= " AND ";
	$sSrchWhere .= "(" . $sSrchAdvanced . ")"; // Advanced Search
}
if ($sSrchBasic != "") {
	if ($sSrchWhere <> "") $sSrchWhere .= " AND ";
	$sSrchWhere .= "(" . $sSrchBasic . ")"; // Basic Search
}

// Save search criteria
if ($sSrchWhere != "") {
	$HTTP_SESSION_VARS[ewSessionTblSearchWhere] = $sSrchWhere;

	// Reset start record counter (new search)
	$nStartRec = 1;
	$HTTP_SESSION_VARS[ewSessionTblStartRec] = $nStartRec;
} else {
	$sSrchWhere = @$HTTP_SESSION_VARS[ewSessionTblSearchWhere];
	RestoreSearch();
}

// Build filter condition
$sDbWhere = "";
if (($ewCurSec & ewAllowList) <> ewAllowList) {
	$sDbWhere = "(0=1)";
}
if ($sDbWhereDetail <> "") {
	if ($sDbWhere <> "") $sDbWhere .= " AND ";
	$sDbWhere .= "(" . $sDbWhereDetail . ")";
}
if ($sSrchWhere <> "") {
	if ($sDbWhere <> "") $sDbWhere .= " AND ";
	$sDbWhere .= "(" . $sSrchWhere . ")";
}

// Set up sorting order
$sOrderBy = "";
SetUpSortOrder();
$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sDbWhere, $sOrderBy);

// echo $sSql . "<br>"; // Uncomment to show SQL for debugging
?>
<?php include ("header.php") ?>
<script type="text/javascript">
<!--
EW_LookupFn = "ewlookup.php"; // ewlookup file name
EW_AddOptFn = "ewaddopt.php"; // ewaddopt.php file name
EW_MultiPagePage = "Page"; // multi-page Page Text
EW_MultiPageOf = "of"; // multi-page Of Text

//-->
</script>
<script type="text/javascript" src="ewp.js"></script>
<script type="text/javascript">
<!--
EW_dateSep = "/"; // set date separator	

//-->
</script>
<script type="text/javascript">
<!--
var firstrowoffset = 1; // first data row start at
var tablename = 'ewlistmain'; // table name
var lastrowoffset = 0; // footer row
var usecss = true; // use css
var rowclass = 'ewTableRow'; // row class
var rowaltclass = 'ewTableAltRow'; // row alternate class
var rowmoverclass = 'ewTableHighlightRow'; // row mouse over class
var rowselectedclass = 'ewTableSelectRow'; // row selected class
var roweditclass = 'ewTableEditRow'; // row edit class
var rowcolor = '#E4E4E4'; // row color
var rowaltcolor = '#F5F5F5'; // row alternate color
var rowmovercolor = '#FFCCFF'; // row mouse over color
var rowselectedcolor = '#CCFFFF'; // row selected color
var roweditcolor = '#FFFF99'; // row edit color

//-->
</script>
<script type="text/javascript">
<!--
	var EW_DHTMLEditors = [];

//-->
</script>
<?php

// Set up recordset
$rs = phpmkr_query($sSql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
$nTotalRecs = phpmkr_num_rows($rs);
if ($nDisplayRecs <= 0) { // Display all records
	$nDisplayRecs = $nTotalRecs;
}
$nStartRec = 1;
SetUpStartRec(); // Set up start record position
?>
<p><span class="phpmaker">TABLE: Type of language
</span></p>
<form id="flanguagelistsrch" name="flanguagelistsrch" action="languagelist.php" >
<table class="ewBasicSearch">
	<tr>
		<td><span class="phpmaker">
			<input type="text" name="<?php echo ewTblBasicSrch; ?>" size="20" value="<?php echo $psearch;?>">
			<input type="Submit" name="Submit" value="Search&nbsp;(*)">&nbsp;
			<input type="Button" name="Reset" value="Reset" onclick="EW_clearForm(this.form);this.form.<?php echo ewTblBasicSrchType;?>[0].checked = true;">&nbsp;
			<a href="languagelist.php?cmd=reset">Show all</a>&nbsp;
		</span></td>
	</tr>
	<tr>
	<td><span class="phpmaker"><input type="radio" name="<?php echo ewTblBasicSrchType;?>" value="" <?php if ($psearchtype == "") { ?>checked<?php } ?>>Exact phrase&nbsp;&nbsp;<input type="radio" name="<?php echo ewTblBasicSrchType; ?>" value="AND" <?php if ($psearchtype == "AND") { ?>checked<?php } ?>>All words&nbsp;&nbsp;<input type="radio" name="<?php echo ewTblBasicSrchType; ?>" value="OR" <?php if ($psearchtype == "OR") { ?>checked<?php } ?>>Any word</span></td>
	</tr>
</table>
</form>
<?php if (($ewCurSec & ewAllowAdd) == ewAllowAdd) { ?>
<table class="ewListAdd">
	<tr>
		<td><span class="phpmaker"><a href="languageadd.php">Add</a></span></td>
	</tr>
</table>
<p>
<?php } ?>
<?php
if (@$HTTP_SESSION_VARS[ewSessionMessage] <> "") {
?>
<p><span class="ewmsg"><?php echo $HTTP_SESSION_VARS[ewSessionMessage]; ?></span></p>
<?php
	$HTTP_SESSION_VARS[ewSessionMessage] = ""; // Clear message
}
?>
<?php if ($nTotalRecs > 0)  { ?>
<form method="post">
<table id="ewlistmain" class="ewTable">
	<!-- Table header -->
	<tr class="ewTableHeader">
		<td valign="top"><span>
	<a href="languagelist.php?order=<?php echo urlencode("id_language"); ?>">
	id language<?php if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_id_language"] == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_id_language"] == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?>
	</a>
		</span></td>
		<td valign="top"><span>
	<a href="languagelist.php?order=<?php echo urlencode("language"); ?>">
	language&nbsp;(*)<?php if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_language"] == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_language"] == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?>
	</a>
		</span></td>
<?php if (($ewCurSec & ewAllowView) == ewAllowView) { ?>
<td>&nbsp;</td>
<?php } ?>
<?php if (($ewCurSec & ewAllowEdit) == ewAllowEdit) { ?>
<td>&nbsp;</td>
<?php } ?>
<?php if (($ewCurSec & ewAllowAdd) == ewAllowAdd) { ?>
<td>&nbsp;</td>
<?php } ?>
<?php if (($ewCurSec & ewAllowDelete) == ewAllowDelete) { ?>
<td>&nbsp;</td>
<?php } ?>
	</tr>
<?php

// Avoid starting record > total records
if ($nStartRec > $nTotalRecs) {
	$nStartRec = $nTotalRecs;
}

// Set the last record to display
$nStopRec = $nStartRec + $nDisplayRecs - 1;

// Move to the first record
$nRecCount = $nStartRec - 1;
if (phpmkr_num_rows($rs) > 0) {
	phpmkr_data_seek($rs, $nStartRec -1);
}
$nRecActual = 0;
while (($row = @phpmkr_fetch_array($rs)) && ($nRecCount < $nStopRec)) {
	$nRecCount = $nRecCount + 1;
	if ($nRecCount >= $nStartRec) {
		$nRecActual++;

		// Set row color
		$sItemRowClass = " class=\"ewTableRow\"";
		$sListTrJs = " onmouseover='ew_mouseover(this);' onmouseout='ew_mouseout(this);' onclick='ew_click(this);'";

		// Display alternate color for rows
		if ($nRecCount % 2 <> 1) {
			$sItemRowClass = " class=\"ewTableAltRow\"";
		}
		$x_id_language = $row["id_language"];
		$x_language = $row["language"];
?>
	<!-- Table body -->
	<tr<?php echo $sItemRowClass; ?><?php echo $sListTrJs; ?>>
		<!-- id_language -->
		<td><span>
<?php echo $x_id_language; ?>
</span></td>
		<!-- language -->
		<td><span>
<?php echo $x_language; ?>
</span></td>
<?php if (($ewCurSec & ewAllowView) == ewAllowView) { ?>
<td><span class="phpmaker"><a href="<?php if ($x_id_language <> "") {echo "languageview.php?id_language=" . urlencode($x_id_language); } else { echo "javascript:alert('Invalid Record! Key is null');";} ?>">View</a></span></td>
<?php } ?>
<?php if (($ewCurSec & ewAllowEdit) == ewAllowEdit) { ?>
<td><span class="phpmaker"><a href="<?php if ($x_id_language <> "") {echo "languageedit.php?id_language=" . urlencode($x_id_language); } else { echo "javascript:alert('Invalid Record! Key is null');";} ?>">Edit</a></span></td>
<?php } ?>
<?php if (($ewCurSec & ewAllowAdd) == ewAllowAdd) { ?>
<td><span class="phpmaker"><a href="<?php if ($x_id_language <> "") {echo "languageadd.php?id_language=" . urlencode($x_id_language); } else { echo "javascript:alert('Invalid Record! Key is null');";} ?>">Copy</a></span></td>
<?php } ?>
<?php if (($ewCurSec & ewAllowDelete) == ewAllowDelete) { ?>
<td><span class="phpmaker"><a href="<?php if ($x_id_language <> "") {echo "languagedelete.php?id_language=" . urlencode($x_id_language); } else { echo "javascript:alert('Invalid Record! Key is null');";} ?>">Delete</a></span></td>
<?php } ?>
	</tr>
<?php
	}
}
?>
</table>
</form>
<?php 
}

// Close recordset and connection
phpmkr_free_result($rs);
phpmkr_db_close($conn);
?>
<form action="languagelist.php" name="ewpagerform" id="ewpagerform">
<table>
	<tr>
		<td nowrap>
<?php
if ($nTotalRecs > 0) {
	$rsEof = ($nTotalRecs < ($nStartRec + $nDisplayRecs));
	$PrevStart = $nStartRec - $nDisplayRecs;
	if ($PrevStart < 1) { $PrevStart = 1; }
	$NextStart = $nStartRec + $nDisplayRecs;
	if ($NextStart > $nTotalRecs) { $NextStart = $nStartRec ; }
	$LastStart = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1;
	?>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpmaker">Page&nbsp;</span></td>
<!--first page button-->
	<?php if ($nStartRec == 1) { ?>
	<td><img src="images/firstdisab.gif" alt="First" width="16" height="16" border="0"></td>
	<?php } else { ?>
	<td><a href="languagelist.php?start=1"><img src="images/first.gif" alt="First" width="16" height="16" border="0"></a></td>
	<?php } ?>
<!--previous page button-->
	<?php if ($PrevStart == $nStartRec) { ?>
	<td><img src="images/prevdisab.gif" alt="Previous" width="16" height="16" border="0"></td>
	<?php } else { ?>
	<td><a href="languagelist.php?start=<?php echo $PrevStart; ?>"><img src="images/prev.gif" alt="Previous" width="16" height="16" border="0"></a></td>
	<?php } ?>
<!--current page number-->
	<td><input type="text" name="pageno" value="<?php echo intval(($nStartRec-1)/$nDisplayRecs+1); ?>" size="4"></td>
<!--next page button-->
	<?php if ($NextStart == $nStartRec) { ?>
	<td><img src="images/nextdisab.gif" alt="Next" width="16" height="16" border="0"></td>
	<?php } else { ?>
	<td><a href="languagelist.php?start=<?php echo $NextStart; ?>"><img src="images/next.gif" alt="Next" width="16" height="16" border="0"></a></td>
	<?php  } ?>
<!--last page button-->
	<?php if ($LastStart == $nStartRec) { ?>
	<td><img src="images/lastdisab.gif" alt="Last" width="16" height="16" border="0"></td>
	<?php } else { ?>
	<td><a href="languagelist.php?start=<?php echo $LastStart; ?>"><img src="images/last.gif" alt="Last" width="16" height="16" border="0"></a></td>
	<?php } ?>
	<td><span class="phpmaker">&nbsp;of <?php echo intval(($nTotalRecs-1)/$nDisplayRecs+1);?></span></td>
	</tr></table>
	<?php if ($nStartRec > $nTotalRecs) { $nStartRec = $nTotalRecs; }
	$nStopRec = $nStartRec + $nDisplayRecs - 1;
	$nRecCount = $nTotalRecs - 1;
	if ($rsEof) { $nRecCount = $nTotalRecs; }
	if ($nStopRec > $nRecCount) { $nStopRec = $nRecCount; } ?>
	<span class="phpmaker">Records <?php echo $nStartRec; ?> to <?php echo $nStopRec; ?> of <?php echo $nTotalRecs; ?></span>
<?php } else { ?>
	<?php if (($ewCurSec & ewAllowList) == ewAllowList) { ?>
	<?php if ($sSrchWhere == "0=101") { ?>
	<span class="phpmaker"></span>
	<?php } else { ?>
	<span class="phpmaker">No records found</span>
	<?php } ?>
	<?php } else { ?>
	<span class="phpmaker">You do not have the right permission to view the page</span>
	<?php  } ?>
<?php } ?>
		</td>
<?php if ($nTotalRecs > 0) { ?>
		<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td align="right" valign="top" nowrap><span class="phpmaker">Records Per Page&nbsp;
		<select name="<?php echo ewTblRecPerPage; ?>" onChange="this.form.pageno.value = 1;this.form.submit();" class="phpmaker">
			<option value="20"<?php if ($nDisplayRecs == 20) { echo " selected";  }?>>20</option>
			<option value="40"<?php if ($nDisplayRecs == 40) { echo " selected";  }?>>40</option>
			<option value="ALL"<?php if (@$HTTP_SESSION_VARS[ewSessionTblRecPerPage] == -1) { echo " selected";  }?>>All Records</option>
		</select>
		</span></td>
<?php } ?>
	</tr>
</table>
</form>
<?php include ("footer.php") ?>
<?php

//-------------------------------------------------------------------------------
// Function SetUpDisplayRecs
// - Set up Number of Records displayed per page based on Form element RecPerPage
// - Variables setup: nDisplayRecs

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 BasicSearchSQL
// - Build WHERE clause for a keyword

function BasicSearchSQL($Keyword)
{
	$sKeyword = (!get_magic_quotes_gpc()) ? addslashes($Keyword) : $Keyword;
	$BasicSearchSQL = "";
	$BasicSearchSQL.= "`language` 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_id_language"] = "";
	$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_language"] = "";
	$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_id_language"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_id_language"];
	$GLOBALS["x_language"] = @$HTTP_SESSION_VARS[ewSessionTblAdvSrch . "_x_language"];
	$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 `id_language`
		if ($sOrder == "id_language") {
			$sSortField = "`id_language`";
			$sLastSort = @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_id_language"];
			$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			$HTTP_SESSION_VARS[ewSessionTblSort . "_x_id_language"] = $sThisSort;
		} else {
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_id_language"] <> "") { @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_id_language"] = ""; }
		}

		// Field `language`
		if ($sOrder == "language") {
			$sSortField = "`language`";
			$sLastSort = @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_language"];
			$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			$HTTP_SESSION_VARS[ewSessionTblSort . "_x_language"] = $sThisSort;
		} else {
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_language"] <> "") { @$HTTP_SESSION_VARS[ewSessionTblSort . "_x_language"] = ""; }
		}
		$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_id_language"] <> "") { $HTTP_SESSION_VARS[ewSessionTblSort . "_x_id_language"] = ""; }
			if (@$HTTP_SESSION_VARS[ewSessionTblSort . "_x_language"] <> "") { $HTTP_SESSION_VARS[ewSessionTblSort . "_x_language"] = ""; }
		}

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