Location: PHPKode > projects > Science Lab Inventory & Order Management > sciencelabinv/orderslist.php
<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "ordersinfo.php" ?>
<?php include "order_detailinfo.php" ?>
<?php include "roomsinfo.php" ?>
<?php include "useraccountsinfo.php" ?>
<?php include "lessoninfo.php" ?>
<?php include "userfn7.php" ?>
<?php

// Create page object
$orders_list = new corders_list();
$Page =& $orders_list;

// Page init
$orders_list->Page_Init();

// Page main
$orders_list->Page_Main();
?>
<?php include "header.php" ?>
<?php if ($orders->Export == "") { ?>
<script type="text/javascript">
<!--

// Create page object
var orders_list = new ew_Page("orders_list");

// page properties
orders_list.PageID = "list"; // page ID
orders_list.FormID = "forderslist"; // form ID
var EW_PAGE_ID = orders_list.PageID; // for backward compatibility

// extend page with ValidateForm function
orders_list.ValidateForm = function(fobj) {
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	var addcnt = 0;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		var chkthisrow = true;
		if (fobj.a_list && fobj.a_list.value == "gridinsert")
			chkthisrow = !(this.EmptyRow(fobj, infix));
		else
			chkthisrow = true;
		if (chkthisrow) {
			addcnt += 1;
		elm = fobj.elements["x" + infix + "_lesson"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($orders->lesson->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_title"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($orders->title->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_request_date"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($orders->request_date->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_request_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($orders->request_date->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_return_date"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($orders->return_date->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_return_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($orders->return_date->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_attachment"];
		if (elm && !ew_CheckFileType(elm.value))
			return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
		} // End Grid Add checking
	}
	if (fobj.a_list && fobj.a_list.value == "gridinsert" && addcnt == 0) { // No row added
		alert(ewLanguage.Phrase("NoAddRecord"));
		return false;
	}
	return true;
}

// Extend page with empty row check
orders_list.EmptyRow = function(fobj, infix) {
	if (ew_ValueChanged(fobj, infix, "lesson", false)) return false;
	if (ew_ValueChanged(fobj, infix, "title", false)) return false;
	if (ew_ValueChanged(fobj, infix, "room", false)) return false;
	if (ew_ValueChanged(fobj, infix, "request_date", false)) return false;
	if (ew_ValueChanged(fobj, infix, "return_date", false)) return false;
	if (ew_ValueChanged(fobj, infix, "attachment", false)) return false;
	return true;
}

// extend page with Form_CustomValidate function
orders_list.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
orders_list.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
	ew_ClickAll(elem);
}
<?php if (EW_CLIENT_VALIDATE) { ?>
orders_list.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
orders_list.ValidateRequired = false; // no JavaScript validation
<?php } ?>

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

//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<?php } ?>
<?php if ($orders->Export == "") { ?>
<?php
$gsMasterReturnUrl = "lessonlist.php";
if ($orders_list->sDbMasterFilter <> "" && $orders->getCurrentMasterTable() == "lesson") {
	if ($orders_list->bMasterRecordExists) {
		if ($orders->getCurrentMasterTable() == $orders->TableVar) $gsMasterReturnUrl .= "?" . EW_TABLE_SHOW_MASTER . "=";
?>
<?php include "lessonmaster.php" ?>
<?php
	}
}
?>
<?php
$gsMasterReturnUrl = "roomslist.php";
if ($orders_list->sDbMasterFilter <> "" && $orders->getCurrentMasterTable() == "rooms") {
	if ($orders_list->bMasterRecordExists) {
		if ($orders->getCurrentMasterTable() == $orders->TableVar) $gsMasterReturnUrl .= "?" . EW_TABLE_SHOW_MASTER . "=";
?>
<?php include "roomsmaster.php" ?>
<?php
	}
}
?>
<?php
$gsMasterReturnUrl = "useraccountslist.php";
if ($orders_list->sDbMasterFilter <> "" && $orders->getCurrentMasterTable() == "useraccounts") {
	if ($orders_list->bMasterRecordExists) {
		if ($orders->getCurrentMasterTable() == $orders->TableVar) $gsMasterReturnUrl .= "?" . EW_TABLE_SHOW_MASTER . "=";
?>
<?php include "useraccountsmaster.php" ?>
<?php
	}
}
?>
<?php } ?>
<?php
if ($orders->CurrentAction == "gridadd") {
	$orders->CurrentFilter = "0=1";
	$orders_list->lStartRec = 1;
	if ($orders_list->lDisplayRecs <= 0)
		$orders_list->lDisplayRecs = 10;
	$orders_list->lTotalRecs = $orders_list->lDisplayRecs;
	$orders_list->lStopRec = $orders_list->lDisplayRecs;
} else {
	$bSelectLimit = EW_SELECT_LIMIT;
	if ($bSelectLimit) {
		$orders_list->lTotalRecs = $orders->SelectRecordCount();
	} else {
		if ($rs = $orders_list->LoadRecordset())
			$orders_list->lTotalRecs = $rs->RecordCount();
	}
	$orders_list->lStartRec = 1;
	if ($orders_list->lDisplayRecs <= 0 || ($orders->Export <> "" && $orders->ExportAll)) // Display all records
		$orders_list->lDisplayRecs = $orders_list->lTotalRecs;
	if (!($orders->Export <> "" && $orders->ExportAll))
		$orders_list->SetUpStartRec(); // Set up start record position
	if ($bSelectLimit)
		$rs = $orders_list->LoadRecordset($orders_list->lStartRec-1, $orders_list->lDisplayRecs);
}
?>
<p><span class="phpmaker" style="white-space: nowrap;"><?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $orders->TableCaption() ?>
<?php if ($orders->Export == "" && $orders->CurrentAction == "") { ?>
&nbsp;&nbsp;<a href="<?php echo $orders_list->ExportPrintUrl ?>"><?php echo $Language->Phrase("PrinterFriendly") ?></a>
&nbsp;&nbsp;<a href="<?php echo $orders_list->ExportHtmlUrl ?>"><?php echo $Language->Phrase("ExportToHtml") ?></a>
&nbsp;&nbsp;<a href="<?php echo $orders_list->ExportExcelUrl ?>"><?php echo $Language->Phrase("ExportToExcel") ?></a>
&nbsp;&nbsp;<a href="<?php echo $orders_list->ExportWordUrl ?>"><?php echo $Language->Phrase("ExportToWord") ?></a>
&nbsp;&nbsp;<a href="<?php echo $orders_list->ExportCsvUrl ?>"><?php echo $Language->Phrase("ExportToCsv") ?></a>
&nbsp;&nbsp;<a name="emf_orders" id="emf_orders" href="javascript:void(0);" onclick="ew_EmailDialogShow({lnk:'emf_orders',hdr:ewLanguage.Phrase('ExportToEmail'),f:document.forderslist,sel:false});"><?php echo $Language->Phrase("ExportToEmail") ?></a>
<?php } ?>
</span></p>
<?php if ($Security->CanSearch()) { ?>
<?php if ($orders->Export == "" && $orders->CurrentAction == "") { ?>
<a href="javascript:ew_ToggleSearchPanel(orders_list);" style="text-decoration: none;"><img id="orders_list_SearchImage" src="images/collapse.gif" alt="" width="9" height="9" border="0"></a><span class="phpmaker">&nbsp;<?php echo $Language->Phrase("Search") ?></span><br>
<div id="orders_list_SearchPanel">
<form name="forderslistsrch" id="forderslistsrch" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
<input type="hidden" id="t" name="t" value="orders">
<table class="ewBasicSearch">
	<tr>
		<td><span class="phpmaker">
			<input type="text" name="<?php echo EW_TABLE_BASIC_SEARCH ?>" id="<?php echo EW_TABLE_BASIC_SEARCH ?>" size="20" value="<?php echo ew_HtmlEncode($orders->getSessionBasicSearchKeyword()) ?>">
			<input type="Submit" name="Submit" id="Submit" value="<?php echo ew_BtnCaption($Language->Phrase("QuickSearchBtn")) ?>">&nbsp;
			<a href="<?php echo $orders_list->PageUrl() ?>cmd=reset"><?php echo $Language->Phrase("ShowAll") ?></a>&nbsp;
		</span></td>
	</tr>
	<tr>
	<td><span class="phpmaker"><label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value=""<?php if ($orders->getSessionBasicSearchType() == "") { ?> checked="checked"<?php } ?>><?php echo $Language->Phrase("ExactPhrase") ?></label>&nbsp;&nbsp;<label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="AND"<?php if ($orders->getSessionBasicSearchType() == "AND") { ?> checked="checked"<?php } ?>><?php echo $Language->Phrase("AllWord") ?></label>&nbsp;&nbsp;<label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="OR"<?php if ($orders->getSessionBasicSearchType() == "OR") { ?> checked="checked"<?php } ?>><?php echo $Language->Phrase("AnyWord") ?></label></span></td>
	</tr>
</table>
</form>
</div>
<?php } ?>
<?php } ?>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$orders_list->ShowMessage();
?>
<br>
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<?php if ($orders->Export == "") { ?>
<div class="ewGridUpperPanel">
<?php if ($orders->CurrentAction <> "gridadd" && $orders->CurrentAction <> "gridedit") { ?>
<form name="ewpagerform" id="ewpagerform" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
<table border="0" cellspacing="0" cellpadding="0" class="ewPager">
	<tr>
		<td nowrap>
<?php if (!isset($orders_list->Pager)) $orders_list->Pager = new cPrevNextPager($orders_list->lStartRec, $orders_list->lDisplayRecs, $orders_list->lTotalRecs) ?>
<?php if ($orders_list->Pager->RecordCount > 0) { ?>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpmaker"><?php echo $Language->Phrase("Page") ?>&nbsp;</span></td>
<!--first page button-->
	<?php if ($orders_list->Pager->FirstButton->Enabled) { ?>
	<td><a href="<?php echo $orders_list->PageUrl() ?>start=<?php echo $orders_list->Pager->FirstButton->Start ?>"><img src="images/first.gif" alt="<?php echo $Language->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></a></td>
	<?php } else { ?>
	<td><img src="images/firstdisab.gif" alt="<?php echo $Language->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></td>
	<?php } ?>
<!--previous page button-->
	<?php if ($orders_list->Pager->PrevButton->Enabled) { ?>
	<td><a href="<?php echo $orders_list->PageUrl() ?>start=<?php echo $orders_list->Pager->PrevButton->Start ?>"><img src="images/prev.gif" alt="<?php echo $Language->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></a></td>
	<?php } else { ?>
	<td><img src="images/prevdisab.gif" alt="<?php echo $Language->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></td>
	<?php } ?>
<!--current page number-->
	<td><input type="text" name="<?php echo EW_TABLE_PAGE_NO ?>" id="<?php echo EW_TABLE_PAGE_NO ?>" value="<?php echo $orders_list->Pager->CurrentPage ?>" size="4"></td>
<!--next page button-->
	<?php if ($orders_list->Pager->NextButton->Enabled) { ?>
	<td><a href="<?php echo $orders_list->PageUrl() ?>start=<?php echo $orders_list->Pager->NextButton->Start ?>"><img src="images/next.gif" alt="<?php echo $Language->Phrase("PagerNext") ?>" width="16" height="16" border="0"></a></td>	
	<?php } else { ?>
	<td><img src="images/nextdisab.gif" alt="<?php echo $Language->Phrase("PagerNext") ?>" width="16" height="16" border="0"></td>
	<?php } ?>
<!--last page button-->
	<?php if ($orders_list->Pager->LastButton->Enabled) { ?>
	<td><a href="<?php echo $orders_list->PageUrl() ?>start=<?php echo $orders_list->Pager->LastButton->Start ?>"><img src="images/last.gif" alt="<?php echo $Language->Phrase("PagerLast") ?>" width="16" height="16" border="0"></a></td>	
	<?php } else { ?>
	<td><img src="images/lastdisab.gif" alt="<?php echo $Language->Phrase("PagerLast") ?>" width="16" height="16" border="0"></td>
	<?php } ?>
	<td><span class="phpmaker">&nbsp;<?php echo $Language->Phrase("of") ?>&nbsp;<?php echo $orders_list->Pager->PageCount ?></span></td>
	</tr></table>
	</td>	
	<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<td>
	<span class="phpmaker"><?php echo $Language->Phrase("Record") ?>&nbsp;<?php echo $orders_list->Pager->FromIndex ?>&nbsp;<?php echo $Language->Phrase("To") ?>&nbsp;<?php echo $orders_list->Pager->ToIndex ?>&nbsp;<?php echo $Language->Phrase("Of") ?>&nbsp;<?php echo $orders_list->Pager->RecordCount ?></span>
<?php } else { ?>
	<?php if ($Security->CanList()) { ?>
	<?php if ($orders_list->sSrchWhere == "0=101") { ?>
	<span class="phpmaker"><?php echo $Language->Phrase("EnterSearchCriteria") ?></span>
	<?php } else { ?>
	<span class="phpmaker"><?php echo $Language->Phrase("NoRecord") ?></span>
	<?php } ?>
	<?php } else { ?>
	<span class="phpmaker"><?php echo $Language->Phrase("NoPermission") ?></span>
	<?php } ?>
<?php } ?>
		</td>
<?php if ($orders_list->lTotalRecs > 0) { ?>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td><table border="0" cellspacing="0" cellpadding="0"><tr><td><?php echo $Language->Phrase("RecordsPerPage") ?>&nbsp;</td><td>
<input type="hidden" id="t" name="t" value="orders">
<select name="<?php echo EW_TABLE_REC_PER_PAGE ?>" id="<?php echo EW_TABLE_REC_PER_PAGE ?>" onchange="this.form.submit();" class="phpmaker">
<option value="10"<?php if ($orders_list->lDisplayRecs == 10) { ?> selected="selected"<?php } ?>>10</option>
<option value="25"<?php if ($orders_list->lDisplayRecs == 25) { ?> selected="selected"<?php } ?>>25</option>
<option value="50"<?php if ($orders_list->lDisplayRecs == 50) { ?> selected="selected"<?php } ?>>50</option>
<option value="ALL"<?php if ($orders->getRecordsPerPage() == -1) { ?> selected="selected"<?php } ?>><?php echo $Language->Phrase("AllRecords") ?></option>
</select></td></tr></table>
		</td>
<?php } ?>
	</tr>
</table>
</form>
<?php } ?>
<span class="phpmaker">
<?php if ($orders->CurrentAction <> "gridadd" && $orders->CurrentAction <> "gridedit") { // Not grid add/edit mode ?>
<?php if ($Security->CanAdd()) { ?>
<a href="<?php echo $orders_list->AddUrl ?>"><?php echo $Language->Phrase("AddLink") ?></a>&nbsp;&nbsp;
<a href="<?php echo $orders_list->GridAddUrl ?>"><?php echo $Language->Phrase("GridAddLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php if ($Security->CanEdit()) { ?>
<?php if ($orders_list->lTotalRecs > 0) { ?>
<a href="<?php echo $orders_list->GridEditUrl ?>"><?php echo $Language->Phrase("GridEditLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php if ($orders_list->lTotalRecs > 0) { ?>
<?php if ($Security->CanDelete()) { ?>
<a href="" onclick="ew_SubmitSelected(document.forderslist, '<?php echo $orders_list->MultiDeleteUrl ?>');return false;"><?php echo $Language->Phrase("DeleteSelectedLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php } else { // Grid add/edit mode ?>
<?php if ($orders->CurrentAction == "gridadd") { ?>
<a href="" onclick="f=document.forderslist;if(orders_list.ValidateForm(f))f.submit();return false;"><?php echo $Language->Phrase("GridInsertLink") ?></a>&nbsp;&nbsp;
<a href="<?php echo $orders_list->PageUrl() ?>a=cancel"><?php echo $Language->Phrase("GridCancelLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php if ($orders->CurrentAction == "gridedit") { ?>
<?php if ($orders->UpdateConflict == "U") { // Record already updated by other user ?>
<a href="<?php echo $orders_list->GridEditUrl ?>"><?php echo $Language->Phrase("ReloadLink") ?></a>&nbsp;&nbsp;
<a href="" onclick="f=document.forderslist;if(orders_list.ValidateForm(f))f.submit();return false;"><?php echo $Language->Phrase("OverwriteLink") ?></a>&nbsp;&nbsp;
<a href="<?php echo $orders_list->PageUrl() ?>a=cancel"><?php echo $Language->Phrase("ConflictCancelLink") ?></a>&nbsp;&nbsp;
<?php } else { ?>
<a href="" onclick="f=document.forderslist;if(orders_list.ValidateForm(f))f.submit();return false;"><?php echo $Language->Phrase("GridSaveLink") ?></a>&nbsp;&nbsp;
<a href="<?php echo $orders_list->PageUrl() ?>a=cancel"><?php echo $Language->Phrase("GridCancelLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php } ?>
</span>
</div>
<?php } ?>
<form name="forderslist" id="forderslist" class="ewForm" action="<?php echo ew_CurrentPage() ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="t" id="t" value="orders">
<div id="gmp_orders" class="ewGridMiddlePanel">
<?php if ($orders_list->lTotalRecs > 0) { ?>
<table cellspacing="0" rowhighlightclass="ewTableHighlightRow" rowselectclass="ewTableSelectRow" roweditclass="ewTableEditRow" class="ewTable ewTableSeparate">
<?php echo $orders->TableCustomInnerHtml ?>
<thead><!-- Table header -->
	<tr class="ewTableHeader">
<?php

// Render list options
$orders_list->RenderListOptions();

// Render list options (header, left)
$orders_list->ListOptions->Render("header", "left");
?>
<?php if ($orders->lesson->Visible) { // lesson ?>
	<?php if ($orders->SortUrl($orders->lesson) == "") { ?>
		<td><?php echo $orders->lesson->FldCaption() ?></td>
	<?php } else { ?>
		<td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $orders->SortUrl($orders->lesson) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $orders->lesson->FldCaption() ?></td><td style="width: 10px;"><?php if ($orders->lesson->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($orders->lesson->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
		</div></td>		
	<?php } ?>
<?php } ?>		
<?php if ($orders->title->Visible) { // title ?>
	<?php if ($orders->SortUrl($orders->title) == "") { ?>
		<td><?php echo $orders->title->FldCaption() ?></td>
	<?php } else { ?>
		<td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $orders->SortUrl($orders->title) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $orders->title->FldCaption() ?><?php echo $Language->Phrase("SrchLegend") ?></td><td style="width: 10px;"><?php if ($orders->title->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($orders->title->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
		</div></td>		
	<?php } ?>
<?php } ?>		
<?php if ($orders->room->Visible) { // room ?>
	<?php if ($orders->SortUrl($orders->room) == "") { ?>
		<td><?php echo $orders->room->FldCaption() ?></td>
	<?php } else { ?>
		<td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $orders->SortUrl($orders->room) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $orders->room->FldCaption() ?></td><td style="width: 10px;"><?php if ($orders->room->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($orders->room->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
		</div></td>		
	<?php } ?>
<?php } ?>		
<?php if ($orders->order_date->Visible) { // order_date ?>
	<?php if ($orders->SortUrl($orders->order_date) == "") { ?>
		<td><?php echo $orders->order_date->FldCaption() ?></td>
	<?php } else { ?>
		<td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $orders->SortUrl($orders->order_date) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $orders->order_date->FldCaption() ?></td><td style="width: 10px;"><?php if ($orders->order_date->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($orders->order_date->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
		</div></td>		
	<?php } ?>
<?php } ?>		
<?php if ($orders->request_date->Visible) { // request_date ?>
	<?php if ($orders->SortUrl($orders->request_date) == "") { ?>
		<td><?php echo $orders->request_date->FldCaption() ?></td>
	<?php } else { ?>
		<td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $orders->SortUrl($orders->request_date) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $orders->request_date->FldCaption() ?></td><td style="width: 10px;"><?php if ($orders->request_date->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($orders->request_date->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
		</div></td>		
	<?php } ?>
<?php } ?>		
<?php if ($orders->return_date->Visible) { // return_date ?>
	<?php if ($orders->SortUrl($orders->return_date) == "") { ?>
		<td><?php echo $orders->return_date->FldCaption() ?></td>
	<?php } else { ?>
		<td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $orders->SortUrl($orders->return_date) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $orders->return_date->FldCaption() ?></td><td style="width: 10px;"><?php if ($orders->return_date->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($orders->return_date->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
		</div></td>		
	<?php } ?>
<?php } ?>		
<?php if ($orders->teacher->Visible) { // teacher ?>
	<?php if ($orders->SortUrl($orders->teacher) == "") { ?>
		<td><?php echo $orders->teacher->FldCaption() ?></td>
	<?php } else { ?>
		<td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $orders->SortUrl($orders->teacher) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $orders->teacher->FldCaption() ?><?php echo $Language->Phrase("SrchLegend") ?></td><td style="width: 10px;"><?php if ($orders->teacher->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($orders->teacher->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
		</div></td>		
	<?php } ?>
<?php } ?>		
<?php if ($orders->attachment->Visible) { // attachment ?>
	<?php if ($orders->SortUrl($orders->attachment) == "") { ?>
		<td><?php echo $orders->attachment->FldCaption() ?></td>
	<?php } else { ?>
		<td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $orders->SortUrl($orders->attachment) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $orders->attachment->FldCaption() ?></td><td style="width: 10px;"><?php if ($orders->attachment->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($orders->attachment->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
		</div></td>		
	<?php } ?>
<?php } ?>		
<?php

// Render list options (header, right)
$orders_list->ListOptions->Render("header", "right");
?>
	</tr>
</thead>
<?php
if ($orders->ExportAll && $orders->Export <> "") {
	$orders_list->lStopRec = $orders_list->lTotalRecs;
} else {
	$orders_list->lStopRec = $orders_list->lStartRec + $orders_list->lDisplayRecs - 1; // Set the last record to display
}
$orders_list->lRecCount = $orders_list->lStartRec - 1;
if ($rs && !$rs->EOF) {
	$rs->MoveFirst();
	if (!$bSelectLimit && $orders_list->lStartRec > 1)
		$rs->Move($orders_list->lStartRec - 1);
}

// Initialize aggregate
$orders->RowType = EW_ROWTYPE_AGGREGATEINIT;
$orders_list->RenderRow();
$orders_list->lRowCnt = 0;
if ($orders->CurrentAction == "gridadd")
	$orders_list->lRowIndex = 0;
if ($orders->CurrentAction == "gridedit")
	$orders_list->lRowIndex = 0;
while (($orders->CurrentAction == "gridadd" || !$rs->EOF) &&
	$orders_list->lRecCount < $orders_list->lStopRec) {
	$orders_list->lRecCount++;
	if (intval($orders_list->lRecCount) >= intval($orders_list->lStartRec)) {
		$orders_list->lRowCnt++;
		if ($orders->CurrentAction == "gridadd" || $orders->CurrentAction == "gridedit")
			$orders_list->lRowIndex++;

	// Init row class and style
	$orders->CssClass = "";
	$orders->CssStyle = "";
	$orders->RowAttrs = array('onmouseover'=>'ew_MouseOver(event, this);', 'onmouseout'=>'ew_MouseOut(event, this);', 'onclick'=>'ew_Click(event, this);');
	if ($orders->CurrentAction == "gridadd") {
		$orders_list->LoadDefaultValues(); // Load default values
	} else {
		$orders_list->LoadRowValues($rs); // Load row values
	}
	$orders->RowType = EW_ROWTYPE_VIEW; // Render view
	if ($orders->CurrentAction == "gridadd") // Grid add
		$orders->RowType = EW_ROWTYPE_ADD; // Render add
	if ($orders->CurrentAction == "gridadd" && $orders->EventCancelled) // Insert failed
		$orders_list->RestoreCurrentRowFormValues($orders_list->lRowIndex); // Restore form values
	if ($orders->CurrentAction == "gridedit") { // Grid edit
		$orders->RowType = EW_ROWTYPE_EDIT; // Render edit
		if (!$orders->EventCancelled)
			$orders_list->HashValue = $orders_list->GetRsHash($rs); // Get hash value for record
	}
	if ($orders->RowType == EW_ROWTYPE_EDIT && $orders->EventCancelled) { // Update failed
		if ($orders->CurrentAction == "gridedit")
			$orders_list->RestoreCurrentRowFormValues($orders_list->lRowIndex); // Restore form values
	}
	if ($orders->RowType == EW_ROWTYPE_EDIT) // Edit row
		$orders_list->lEditRowCnt++;
	if ($orders->RowType == EW_ROWTYPE_ADD || $orders->RowType == EW_ROWTYPE_EDIT) { // Add / Edit row
		$orders->RowAttrs = array_merge($orders->RowAttrs, array('onmouseover'=>'this.edit=true;ew_MouseOver(event, this);', 'onmouseout'=>'ew_MouseOut(event, this);', 'onclick'=>'ew_Click(event, this);'));
		$orders->CssClass = "ewTableEditRow";
	}

	// Render row
	$orders_list->RenderRow();

	// Render list options
	$orders_list->RenderListOptions();
?>
	<tr<?php echo $orders->RowAttributes() ?>>
<?php

// Render list options (body, left)
$orders_list->ListOptions->Render("body", "left");
?>
	<?php if ($orders->lesson->Visible) { // lesson ?>
		<td<?php echo $orders->lesson->CellAttributes() ?>>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<?php if ($orders->lesson->getSessionValue() <> "") { ?>
<div<?php echo $orders->lesson->ViewAttributes() ?>>
<?php if ($orders->lesson->HrefValue <> "" || $orders->lesson->TooltipValue <> "" || $orders->note->ViewValue <> "") { ?>
<a href="javascript:void(0);" onmouseover="ew_ShowTooltip(this, 'tt_orders_x<?php echo $orders_list->lRowCnt ?>_lesson');" onmouseout="ew_HideTooltip();"><?php echo $orders->lesson->ListViewValue() ?></a>
<?php } else { ?>
<?php echo $orders->lesson->ListViewValue() ?>
<?php } ?>
</div><div id="tt_orders_x<?php echo $orders_list->lRowCnt ?>_lesson" style="display: none">
<?php if ($orders->lesson->TooltipValue <> "") { ?>
<?php echo $orders->lesson->TooltipValue ?>
<?php } else { ?>
<div<?php echo $orders->note->ViewAttributes() ?>><?php echo $orders->note->ViewValue ?></div>
<?php } ?>
</div>
<input type="hidden" id="x<?php echo $orders_list->lRowIndex ?>_lesson" name="x<?php echo $orders_list->lRowIndex ?>_lesson" value="<?php echo ew_HtmlEncode($orders->lesson->CurrentValue) ?>">
<?php } else { ?>
<select id="x<?php echo $orders_list->lRowIndex ?>_lesson" name="x<?php echo $orders_list->lRowIndex ?>_lesson" title="<?php echo $orders->lesson->FldTitle() ?>"<?php echo $orders->lesson->EditAttributes() ?>>
<?php
if (is_array($orders->lesson->EditValue)) {
	$arwrk = $orders->lesson->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($orders->lesson->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
if (@$emptywrk) $orders->lesson->OldValue = "";
?>
</select>
<?php } ?>
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_lesson" id="o<?php echo $orders_list->lRowIndex ?>_lesson" value="<?php echo ew_HtmlEncode($orders->lesson->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit record ?>
<?php if ($orders->lesson->getSessionValue() <> "") { ?>
<div<?php echo $orders->lesson->ViewAttributes() ?>>
<?php if ($orders->lesson->HrefValue <> "" || $orders->lesson->TooltipValue <> "" || $orders->note->ViewValue <> "") { ?>
<a href="javascript:void(0);" onmouseover="ew_ShowTooltip(this, 'tt_orders_x<?php echo $orders_list->lRowCnt ?>_lesson');" onmouseout="ew_HideTooltip();"><?php echo $orders->lesson->ListViewValue() ?></a>
<?php } else { ?>
<?php echo $orders->lesson->ListViewValue() ?>
<?php } ?>
</div><div id="tt_orders_x<?php echo $orders_list->lRowCnt ?>_lesson" style="display: none">
<?php if ($orders->lesson->TooltipValue <> "") { ?>
<?php echo $orders->lesson->TooltipValue ?>
<?php } else { ?>
<div<?php echo $orders->note->ViewAttributes() ?>><?php echo $orders->note->ViewValue ?></div>
<?php } ?>
</div>
<input type="hidden" id="x<?php echo $orders_list->lRowIndex ?>_lesson" name="x<?php echo $orders_list->lRowIndex ?>_lesson" value="<?php echo ew_HtmlEncode($orders->lesson->CurrentValue) ?>">
<?php } else { ?>
<select id="x<?php echo $orders_list->lRowIndex ?>_lesson" name="x<?php echo $orders_list->lRowIndex ?>_lesson" title="<?php echo $orders->lesson->FldTitle() ?>"<?php echo $orders->lesson->EditAttributes() ?>>
<?php
if (is_array($orders->lesson->EditValue)) {
	$arwrk = $orders->lesson->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($orders->lesson->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
if (@$emptywrk) $orders->lesson->OldValue = "";
?>
</select>
<?php } ?>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_VIEW) { // View record ?>
<div<?php echo $orders->lesson->ViewAttributes() ?>>
<?php if ($orders->lesson->HrefValue <> "" || $orders->lesson->TooltipValue <> "" || $orders->note->ViewValue <> "") { ?>
<a href="javascript:void(0);" onmouseover="ew_ShowTooltip(this, 'tt_orders_x<?php echo $orders_list->lRowCnt ?>_lesson');" onmouseout="ew_HideTooltip();"><?php echo $orders->lesson->ListViewValue() ?></a>
<?php } else { ?>
<?php echo $orders->lesson->ListViewValue() ?>
<?php } ?>
</div><div id="tt_orders_x<?php echo $orders_list->lRowCnt ?>_lesson" style="display: none">
<?php if ($orders->lesson->TooltipValue <> "") { ?>
<?php echo $orders->lesson->TooltipValue ?>
<?php } else { ?>
<div<?php echo $orders->note->ViewAttributes() ?>><?php echo $orders->note->ViewValue ?></div>
<?php } ?>
</div>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_id" id="o<?php echo $orders_list->lRowIndex ?>_id" value="<?php echo ew_HtmlEncode($orders->id->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { ?>
<input type="hidden" name="x<?php echo $orders_list->lRowIndex ?>_id" id="x<?php echo $orders_list->lRowIndex ?>_id" value="<?php echo ew_HtmlEncode($orders->id->CurrentValue) ?>">
<?php } ?>
</td>
	<?php } ?>
	<?php if ($orders->title->Visible) { // title ?>
		<td<?php echo $orders->title->CellAttributes() ?>>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<input type="text" name="x<?php echo $orders_list->lRowIndex ?>_title" id="x<?php echo $orders_list->lRowIndex ?>_title" title="<?php echo $orders->title->FldTitle() ?>" size="30" maxlength="25" value="<?php echo $orders->title->EditValue ?>"<?php echo $orders->title->EditAttributes() ?>>
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_title" id="o<?php echo $orders_list->lRowIndex ?>_title" value="<?php echo ew_HtmlEncode($orders->title->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit record ?>
<input type="text" name="x<?php echo $orders_list->lRowIndex ?>_title" id="x<?php echo $orders_list->lRowIndex ?>_title" title="<?php echo $orders->title->FldTitle() ?>" size="30" maxlength="25" value="<?php echo $orders->title->EditValue ?>"<?php echo $orders->title->EditAttributes() ?>>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_VIEW) { // View record ?>
<div<?php echo $orders->title->ViewAttributes() ?>><?php echo $orders->title->ListViewValue() ?></div>
<?php } ?>
</td>
	<?php } ?>
	<?php if ($orders->room->Visible) { // room ?>
		<td<?php echo $orders->room->CellAttributes() ?>>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<?php if ($orders->room->getSessionValue() <> "") { ?>
<div<?php echo $orders->room->ViewAttributes() ?>><?php echo $orders->room->ListViewValue() ?></div>
<input type="hidden" id="x<?php echo $orders_list->lRowIndex ?>_room" name="x<?php echo $orders_list->lRowIndex ?>_room" value="<?php echo ew_HtmlEncode($orders->room->CurrentValue) ?>">
<?php } else { ?>
<select id="x<?php echo $orders_list->lRowIndex ?>_room" name="x<?php echo $orders_list->lRowIndex ?>_room" title="<?php echo $orders->room->FldTitle() ?>"<?php echo $orders->room->EditAttributes() ?>>
<?php
if (is_array($orders->room->EditValue)) {
	$arwrk = $orders->room->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($orders->room->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
if (@$emptywrk) $orders->room->OldValue = "";
?>
</select>
<?php } ?>
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_room" id="o<?php echo $orders_list->lRowIndex ?>_room" value="<?php echo ew_HtmlEncode($orders->room->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit record ?>
<?php if ($orders->room->getSessionValue() <> "") { ?>
<div<?php echo $orders->room->ViewAttributes() ?>><?php echo $orders->room->ListViewValue() ?></div>
<input type="hidden" id="x<?php echo $orders_list->lRowIndex ?>_room" name="x<?php echo $orders_list->lRowIndex ?>_room" value="<?php echo ew_HtmlEncode($orders->room->CurrentValue) ?>">
<?php } else { ?>
<select id="x<?php echo $orders_list->lRowIndex ?>_room" name="x<?php echo $orders_list->lRowIndex ?>_room" title="<?php echo $orders->room->FldTitle() ?>"<?php echo $orders->room->EditAttributes() ?>>
<?php
if (is_array($orders->room->EditValue)) {
	$arwrk = $orders->room->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($orders->room->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
if (@$emptywrk) $orders->room->OldValue = "";
?>
</select>
<?php } ?>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_VIEW) { // View record ?>
<div<?php echo $orders->room->ViewAttributes() ?>><?php echo $orders->room->ListViewValue() ?></div>
<?php } ?>
</td>
	<?php } ?>
	<?php if ($orders->order_date->Visible) { // order_date ?>
		<td<?php echo $orders->order_date->CellAttributes() ?>>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<input type="hidden" name="fo<?php echo $orders_list->lRowIndex ?>_order_date" id="fo<?php echo $orders_list->lRowIndex ?>_order_date" value="<?php echo ew_HtmlEncode(ew_FormatDateTime($orders->order_date->OldValue, 5)) ?>">
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_order_date" id="o<?php echo $orders_list->lRowIndex ?>_order_date" value="<?php echo ew_HtmlEncode($orders->order_date->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit record ?>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_VIEW) { // View record ?>
<div<?php echo $orders->order_date->ViewAttributes() ?>><?php echo $orders->order_date->ListViewValue() ?></div>
<?php } ?>
</td>
	<?php } ?>
	<?php if ($orders->request_date->Visible) { // request_date ?>
		<td<?php echo $orders->request_date->CellAttributes() ?>>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<input type="text" name="x<?php echo $orders_list->lRowIndex ?>_request_date" id="x<?php echo $orders_list->lRowIndex ?>_request_date" title="<?php echo $orders->request_date->FldTitle() ?>" value="<?php echo $orders->request_date->EditValue ?>"<?php echo $orders->request_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x<?php echo $orders_list->lRowIndex ?>_request_date" name="cal_x<?php echo $orders_list->lRowIndex ?>_request_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x<?php echo $orders_list->lRowIndex ?>_request_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x<?php echo $orders_list->lRowIndex ?>_request_date" // button id
});
</script>
<input type="hidden" name="fo<?php echo $orders_list->lRowIndex ?>_request_date" id="fo<?php echo $orders_list->lRowIndex ?>_request_date" value="<?php echo ew_HtmlEncode(ew_FormatDateTime($orders->request_date->OldValue, 5)) ?>">
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_request_date" id="o<?php echo $orders_list->lRowIndex ?>_request_date" value="<?php echo ew_HtmlEncode($orders->request_date->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit record ?>
<input type="text" name="x<?php echo $orders_list->lRowIndex ?>_request_date" id="x<?php echo $orders_list->lRowIndex ?>_request_date" title="<?php echo $orders->request_date->FldTitle() ?>" value="<?php echo $orders->request_date->EditValue ?>"<?php echo $orders->request_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x<?php echo $orders_list->lRowIndex ?>_request_date" name="cal_x<?php echo $orders_list->lRowIndex ?>_request_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x<?php echo $orders_list->lRowIndex ?>_request_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x<?php echo $orders_list->lRowIndex ?>_request_date" // button id
});
</script>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_VIEW) { // View record ?>
<div<?php echo $orders->request_date->ViewAttributes() ?>><?php echo $orders->request_date->ListViewValue() ?></div>
<?php } ?>
</td>
	<?php } ?>
	<?php if ($orders->return_date->Visible) { // return_date ?>
		<td<?php echo $orders->return_date->CellAttributes() ?>>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<input type="text" name="x<?php echo $orders_list->lRowIndex ?>_return_date" id="x<?php echo $orders_list->lRowIndex ?>_return_date" title="<?php echo $orders->return_date->FldTitle() ?>" value="<?php echo $orders->return_date->EditValue ?>"<?php echo $orders->return_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x<?php echo $orders_list->lRowIndex ?>_return_date" name="cal_x<?php echo $orders_list->lRowIndex ?>_return_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x<?php echo $orders_list->lRowIndex ?>_return_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x<?php echo $orders_list->lRowIndex ?>_return_date" // button id
});
</script>
<input type="hidden" name="fo<?php echo $orders_list->lRowIndex ?>_return_date" id="fo<?php echo $orders_list->lRowIndex ?>_return_date" value="<?php echo ew_HtmlEncode(ew_FormatDateTime($orders->return_date->OldValue, 5)) ?>">
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_return_date" id="o<?php echo $orders_list->lRowIndex ?>_return_date" value="<?php echo ew_HtmlEncode($orders->return_date->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit record ?>
<input type="text" name="x<?php echo $orders_list->lRowIndex ?>_return_date" id="x<?php echo $orders_list->lRowIndex ?>_return_date" title="<?php echo $orders->return_date->FldTitle() ?>" value="<?php echo $orders->return_date->EditValue ?>"<?php echo $orders->return_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x<?php echo $orders_list->lRowIndex ?>_return_date" name="cal_x<?php echo $orders_list->lRowIndex ?>_return_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x<?php echo $orders_list->lRowIndex ?>_return_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x<?php echo $orders_list->lRowIndex ?>_return_date" // button id
});
</script>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_VIEW) { // View record ?>
<div<?php echo $orders->return_date->ViewAttributes() ?>><?php echo $orders->return_date->ListViewValue() ?></div>
<?php } ?>
</td>
	<?php } ?>
	<?php if ($orders->teacher->Visible) { // teacher ?>
		<td<?php echo $orders->teacher->CellAttributes() ?>>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_teacher" id="o<?php echo $orders_list->lRowIndex ?>_teacher" value="<?php echo ew_HtmlEncode($orders->teacher->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit record ?>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_VIEW) { // View record ?>
<div<?php echo $orders->teacher->ViewAttributes() ?>><?php echo $orders->teacher->ListViewValue() ?></div>
<?php } ?>
</td>
	<?php } ?>
	<?php if ($orders->attachment->Visible) { // attachment ?>
		<td<?php echo $orders->attachment->CellAttributes() ?>>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { // Add record ?>
<input type="file" name="x<?php echo $orders_list->lRowIndex ?>_attachment" id="x<?php echo $orders_list->lRowIndex ?>_attachment" title="<?php echo $orders->attachment->FldTitle() ?>" size="30"<?php echo $orders->attachment->EditAttributes() ?>>
</div>
<input type="hidden" name="o<?php echo $orders_list->lRowIndex ?>_attachment" id="o<?php echo $orders_list->lRowIndex ?>_attachment" value="<?php echo ew_HtmlEncode($orders->attachment->OldValue) ?>">
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit record ?>
<div id="old_x<?php echo $orders_list->lRowIndex ?>_attachment">
<?php if ($orders->attachment->HrefValue <> "" || $orders->attachment->TooltipValue <> "") { ?>
<?php if (!empty($orders->attachment->Upload->DbValue)) { ?>
<a href="<?php echo $orders->attachment->HrefValue ?>"><?php echo $orders->attachment->EditValue ?></a>
<?php } elseif (!in_array($orders->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } else { ?>
<?php if (!empty($orders->attachment->Upload->DbValue)) { ?>
<?php echo $orders->attachment->EditValue ?>
<?php } elseif (!in_array($orders->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
</div>
<div id="new_x<?php echo $orders_list->lRowIndex ?>_attachment">
<?php if (!empty($orders->attachment->Upload->DbValue)) { ?>
<label><input type="radio" name="a<?php echo $orders_list->lRowIndex ?>_attachment" id="a<?php echo $orders_list->lRowIndex ?>_attachment" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?></label>&nbsp;
<label><input type="radio" name="a<?php echo $orders_list->lRowIndex ?>_attachment" id="a<?php echo $orders_list->lRowIndex ?>_attachment" value="2"><?php echo $Language->Phrase("Remove") ?></label>&nbsp;
<label><input type="radio" name="a<?php echo $orders_list->lRowIndex ?>_attachment" id="a<?php echo $orders_list->lRowIndex ?>_attachment" value="3"><?php echo $Language->Phrase("Replace") ?><br></label>
<?php $orders->attachment->EditAttrs["onchange"] = "this.form.a<?php echo $orders_list->lRowIndex ?>_attachment[2].checked=true;" . @$orders->attachment->EditAttrs["onchange"]; ?>
<?php } else { ?>
<input type="hidden" name="a<?php echo $orders_list->lRowIndex ?>_attachment" id="a<?php echo $orders_list->lRowIndex ?>_attachment" value="3">
<?php } ?>
<input type="file" name="x<?php echo $orders_list->lRowIndex ?>_attachment" id="x<?php echo $orders_list->lRowIndex ?>_attachment" title="<?php echo $orders->attachment->FldTitle() ?>" size="30"<?php echo $orders->attachment->EditAttributes() ?>>
</div>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_VIEW) { // View record ?>
<?php if ($orders->attachment->HrefValue <> "" || $orders->attachment->TooltipValue <> "") { ?>
<?php if (!empty($orders->attachment->Upload->DbValue)) { ?>
<a href="<?php echo $orders->attachment->HrefValue ?>"><?php echo $orders->attachment->ListViewValue() ?></a>
<?php } elseif (!in_array($orders->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } else { ?>
<?php if (!empty($orders->attachment->Upload->DbValue)) { ?>
<?php echo $orders->attachment->ListViewValue() ?>
<?php } elseif (!in_array($orders->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
<?php } ?>
</td>
	<?php } ?>
<?php

// Render list options (body, right)
$orders_list->ListOptions->Render("body", "right");
?>
	</tr>
<?php if ($orders->RowType == EW_ROWTYPE_ADD) { ?>
<?php } ?>
<?php if ($orders->RowType == EW_ROWTYPE_EDIT) { ?>
<?php } ?>
<?php
	}
	if ($orders->CurrentAction <> "gridadd")
		$rs->MoveNext();
}
?>
</tbody>
</table>
<?php } ?>
<?php if ($orders->CurrentAction == "gridadd") { ?>
<input type="hidden" name="a_list" id="a_list" value="gridinsert">
<input type="hidden" name="key_count" id="key_count" value="<?php echo $orders_list->lRowIndex ?>">
<?php } ?>
<?php if ($orders->CurrentAction == "gridedit") { ?>
<?php if ($orders->UpdateConflict == "U") { // Record already updated by other user ?>
<input type="hidden" name="a_list" id="a_list" value="gridoverwrite">
<?php } else { ?>
<input type="hidden" name="a_list" id="a_list" value="gridupdate">
<?php } ?>
<input type="hidden" name="key_count" id="key_count" value="<?php echo $orders_list->lRowIndex ?>">
<?php echo $orders_list->sMultiSelectKey ?>
<?php } ?>
</div>
</form>
<?php

// Close recordset
if ($rs)
	$rs->Close();
?>
<?php if ($orders_list->lTotalRecs > 0) { ?>
<?php if ($orders->Export == "") { ?>
<div class="ewGridLowerPanel">
<?php if ($orders->CurrentAction <> "gridadd" && $orders->CurrentAction <> "gridedit") { ?>
<form name="ewpagerform" id="ewpagerform" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
<table border="0" cellspacing="0" cellpadding="0" class="ewPager">
	<tr>
		<td nowrap>
<?php if (!isset($orders_list->Pager)) $orders_list->Pager = new cPrevNextPager($orders_list->lStartRec, $orders_list->lDisplayRecs, $orders_list->lTotalRecs) ?>
<?php if ($orders_list->Pager->RecordCount > 0) { ?>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpmaker"><?php echo $Language->Phrase("Page") ?>&nbsp;</span></td>
<!--first page button-->
	<?php if ($orders_list->Pager->FirstButton->Enabled) { ?>
	<td><a href="<?php echo $orders_list->PageUrl() ?>start=<?php echo $orders_list->Pager->FirstButton->Start ?>"><img src="images/first.gif" alt="<?php echo $Language->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></a></td>
	<?php } else { ?>
	<td><img src="images/firstdisab.gif" alt="<?php echo $Language->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></td>
	<?php } ?>
<!--previous page button-->
	<?php if ($orders_list->Pager->PrevButton->Enabled) { ?>
	<td><a href="<?php echo $orders_list->PageUrl() ?>start=<?php echo $orders_list->Pager->PrevButton->Start ?>"><img src="images/prev.gif" alt="<?php echo $Language->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></a></td>
	<?php } else { ?>
	<td><img src="images/prevdisab.gif" alt="<?php echo $Language->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></td>
	<?php } ?>
<!--current page number-->
	<td><input type="text" name="<?php echo EW_TABLE_PAGE_NO ?>" id="<?php echo EW_TABLE_PAGE_NO ?>" value="<?php echo $orders_list->Pager->CurrentPage ?>" size="4"></td>
<!--next page button-->
	<?php if ($orders_list->Pager->NextButton->Enabled) { ?>
	<td><a href="<?php echo $orders_list->PageUrl() ?>start=<?php echo $orders_list->Pager->NextButton->Start ?>"><img src="images/next.gif" alt="<?php echo $Language->Phrase("PagerNext") ?>" width="16" height="16" border="0"></a></td>	
	<?php } else { ?>
	<td><img src="images/nextdisab.gif" alt="<?php echo $Language->Phrase("PagerNext") ?>" width="16" height="16" border="0"></td>
	<?php } ?>
<!--last page button-->
	<?php if ($orders_list->Pager->LastButton->Enabled) { ?>
	<td><a href="<?php echo $orders_list->PageUrl() ?>start=<?php echo $orders_list->Pager->LastButton->Start ?>"><img src="images/last.gif" alt="<?php echo $Language->Phrase("PagerLast") ?>" width="16" height="16" border="0"></a></td>	
	<?php } else { ?>
	<td><img src="images/lastdisab.gif" alt="<?php echo $Language->Phrase("PagerLast") ?>" width="16" height="16" border="0"></td>
	<?php } ?>
	<td><span class="phpmaker">&nbsp;<?php echo $Language->Phrase("of") ?>&nbsp;<?php echo $orders_list->Pager->PageCount ?></span></td>
	</tr></table>
	</td>	
	<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<td>
	<span class="phpmaker"><?php echo $Language->Phrase("Record") ?>&nbsp;<?php echo $orders_list->Pager->FromIndex ?>&nbsp;<?php echo $Language->Phrase("To") ?>&nbsp;<?php echo $orders_list->Pager->ToIndex ?>&nbsp;<?php echo $Language->Phrase("Of") ?>&nbsp;<?php echo $orders_list->Pager->RecordCount ?></span>
<?php } else { ?>
	<?php if ($Security->CanList()) { ?>
	<?php if ($orders_list->sSrchWhere == "0=101") { ?>
	<span class="phpmaker"><?php echo $Language->Phrase("EnterSearchCriteria") ?></span>
	<?php } else { ?>
	<span class="phpmaker"><?php echo $Language->Phrase("NoRecord") ?></span>
	<?php } ?>
	<?php } else { ?>
	<span class="phpmaker"><?php echo $Language->Phrase("NoPermission") ?></span>
	<?php } ?>
<?php } ?>
		</td>
<?php if ($orders_list->lTotalRecs > 0) { ?>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td><table border="0" cellspacing="0" cellpadding="0"><tr><td><?php echo $Language->Phrase("RecordsPerPage") ?>&nbsp;</td><td>
<input type="hidden" id="t" name="t" value="orders">
<select name="<?php echo EW_TABLE_REC_PER_PAGE ?>" id="<?php echo EW_TABLE_REC_PER_PAGE ?>" onchange="this.form.submit();" class="phpmaker">
<option value="10"<?php if ($orders_list->lDisplayRecs == 10) { ?> selected="selected"<?php } ?>>10</option>
<option value="25"<?php if ($orders_list->lDisplayRecs == 25) { ?> selected="selected"<?php } ?>>25</option>
<option value="50"<?php if ($orders_list->lDisplayRecs == 50) { ?> selected="selected"<?php } ?>>50</option>
<option value="ALL"<?php if ($orders->getRecordsPerPage() == -1) { ?> selected="selected"<?php } ?>><?php echo $Language->Phrase("AllRecords") ?></option>
</select></td></tr></table>
		</td>
<?php } ?>
	</tr>
</table>
</form>
<?php } ?>
<?php //if ($orders_list->lTotalRecs > 0) { ?>
<span class="phpmaker">
<?php if ($orders->CurrentAction <> "gridadd" && $orders->CurrentAction <> "gridedit") { // Not grid add/edit mode ?>
<?php if ($Security->CanAdd()) { ?>
<a href="<?php echo $orders_list->AddUrl ?>"><?php echo $Language->Phrase("AddLink") ?></a>&nbsp;&nbsp;
<a href="<?php echo $orders_list->GridAddUrl ?>"><?php echo $Language->Phrase("GridAddLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php if ($Security->CanEdit()) { ?>
<?php if ($orders_list->lTotalRecs > 0) { ?>
<a href="<?php echo $orders_list->GridEditUrl ?>"><?php echo $Language->Phrase("GridEditLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php if ($orders_list->lTotalRecs > 0) { ?>
<?php if ($Security->CanDelete()) { ?>
<a href="" onclick="ew_SubmitSelected(document.forderslist, '<?php echo $orders_list->MultiDeleteUrl ?>');return false;"><?php echo $Language->Phrase("DeleteSelectedLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php } else { // Grid add/edit mode ?>
<?php if ($orders->CurrentAction == "gridadd") { ?>
<a href="" onclick="f=document.forderslist;if(orders_list.ValidateForm(f))f.submit();return false;"><?php echo $Language->Phrase("GridInsertLink") ?></a>&nbsp;&nbsp;
<a href="<?php echo $orders_list->PageUrl() ?>a=cancel"><?php echo $Language->Phrase("GridCancelLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php if ($orders->CurrentAction == "gridedit") { ?>
<?php if ($orders->UpdateConflict == "U") { // Record already updated by other user ?>
<a href="<?php echo $orders_list->GridEditUrl ?>"><?php echo $Language->Phrase("ReloadLink") ?></a>&nbsp;&nbsp;
<a href="" onclick="f=document.forderslist;if(orders_list.ValidateForm(f))f.submit();return false;"><?php echo $Language->Phrase("OverwriteLink") ?></a>&nbsp;&nbsp;
<a href="<?php echo $orders_list->PageUrl() ?>a=cancel"><?php echo $Language->Phrase("ConflictCancelLink") ?></a>&nbsp;&nbsp;
<?php } else { ?>
<a href="" onclick="f=document.forderslist;if(orders_list.ValidateForm(f))f.submit();return false;"><?php echo $Language->Phrase("GridSaveLink") ?></a>&nbsp;&nbsp;
<a href="<?php echo $orders_list->PageUrl() ?>a=cancel"><?php echo $Language->Phrase("GridCancelLink") ?></a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php } ?>
</span>
<?php //} ?>
</div>
<?php } ?>
<?php } ?>
</td></tr></table>
<?php if ($orders->Export == "" && $orders->CurrentAction == "") { ?>
<script type="text/javascript">
<!--
ew_ToggleSearchPanel(orders_list); // Init search panel as collapsed

//-->
</script>
<?php } ?>
<?php if ($orders->Export == "") { ?>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php } ?>
<?php include "footer.php" ?>
<?php
$orders_list->Page_Terminate();
?>
<?php

//
// Page class
//
class corders_list {

	// Page ID
	var $PageID = 'list';

	// Table name
	var $TableName = 'orders';

	// Page object name
	var $PageObjName = 'orders_list';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $orders;
		if ($orders->UseTokenInUrl) $PageUrl .= "t=" . $orders->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Page URLs
	var $AddUrl;
	var $EditUrl;
	var $CopyUrl;
	var $DeleteUrl;
	var $ViewUrl;
	var $ListUrl;

	// Export URLs
	var $ExportPrintUrl;
	var $ExportHtmlUrl;
	var $ExportExcelUrl;
	var $ExportWordUrl;
	var $ExportXmlUrl;
	var $ExportCsvUrl;

	// Update URLs
	var $InlineAddUrl;
	var $InlineCopyUrl;
	var $InlineEditUrl;
	var $GridAddUrl;
	var $GridEditUrl;
	var $MultiDeleteUrl;
	var $MultiUpdateUrl;

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage);
		if ($sMessage <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $orders;
		if ($orders->UseTokenInUrl) {
			if ($objForm)
				return ($orders->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($orders->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function corders_list() {
		global $conn, $Language;

		// Language object
		$Language = new cLanguage();

		// Table object (orders)
		$GLOBALS["orders"] = new corders();

		// Initialize URLs
		$this->ExportPrintUrl = $this->PageUrl() . "export=print";
		$this->ExportExcelUrl = $this->PageUrl() . "export=excel";
		$this->ExportWordUrl = $this->PageUrl() . "export=word";
		$this->ExportHtmlUrl = $this->PageUrl() . "export=html";
		$this->ExportXmlUrl = $this->PageUrl() . "export=xml";
		$this->ExportCsvUrl = $this->PageUrl() . "export=csv";
		$this->AddUrl = $GLOBALS["orders"]->AddUrl();
		$this->InlineAddUrl = $this->PageUrl() . "a=add";
		$this->GridAddUrl = $this->PageUrl() . "a=gridadd";
		$this->GridEditUrl = $this->PageUrl() . "a=gridedit";
		$this->MultiDeleteUrl = "ordersdelete.php";
		$this->MultiUpdateUrl = "ordersupdate.php";

		// Table object (order_detail)
		$GLOBALS['order_detail'] = new corder_detail();

		// Table object (rooms)
		$GLOBALS['rooms'] = new crooms();

		// Table object (useraccounts)
		$GLOBALS['useraccounts'] = new cuseraccounts();

		// Table object (lesson)
		$GLOBALS['lesson'] = new clesson();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'list', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'orders', TRUE);

		// Start timer
		$GLOBALS["gsTimer"] = new cTimer();

		// Open connection
		$conn = ew_Connect();

		// List options
		$this->ListOptions = new cListOptions();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
		global $orders;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		$Security->TablePermission_Loading();
		$Security->LoadCurrentUserLevel($this->TableName);
		$Security->TablePermission_Loaded();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		if (!$Security->CanList()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		$Security->UserID_Loading();
		if ($Security->IsLoggedIn()) $Security->LoadUserID();
		$Security->UserID_Loaded();
		if ($Security->IsLoggedIn() && $Security->CurrentUserID() == "") {
			$_SESSION[EW_SESSION_MESSAGE] = $Language->Phrase("NoPermission");
			$this->Page_Terminate();
		}

		// Create form object
		$objForm = new cFormObj();

		// Get export parameters
		if (@$_GET["export"] <> "") {
			$orders->Export = $_GET["export"];
		} elseif (ew_IsHttpPost()) {
			if (@$_POST["exporttype"] <> "")
				$orders->Export = $_POST["exporttype"];
		} else {
			$orders->setExportReturnUrl(ew_CurrentUrl());
		}
		$gsExport = $orders->Export; // Get export parameter, used in header
		$gsExportFile = $orders->TableVar; // Get export file, used in header
		if (in_array($orders->Export, array("html", "email", "excel", "word")))
			echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
		if ($orders->Export == "excel") {
			header('Content-Type: application/vnd.ms-excel;charset=utf-8');
			header('Content-Disposition: attachment; filename=' . $gsExportFile .'.xls');
		}
		if ($orders->Export == "word") {
			header('Content-Type: application/vnd.ms-word;charset=utf-8');
			header('Content-Disposition: attachment; filename=' . $gsExportFile .'.doc');
		}
		if ($orders->Export == "csv") {
			header('Content-Type: application/csv;charset=utf-8');
			header('Content-Disposition: attachment; filename=' . $gsExportFile .'.csv');
		}

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		$this->Page_Redirecting($url);
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}

	// Class variables
	var $ListOptions; // List options
	var $lDisplayRecs = 10;
	var $lStartRec;
	var $lStopRec;
	var $lTotalRecs = 0;
	var $lRecRange = 10;
	var $sSrchWhere = ""; // Search WHERE clause
	var $lRecCnt = 0; // Record count
	var $lEditRowCnt;
	var $lRowCnt;
	var $lRowIndex; // Row index
	var $lRecPerRow = 0;
	var $lColCnt = 0;
	var $sDbMasterFilter = ""; // Master filter
	var $sDbDetailFilter = ""; // Detail filter
	var $bMasterRecordExists;	
	var $sMultiSelectKey;
	var $RestoreSearch;
	var $HashValue; // Hash value
	var $lorder_detail_Count;

	//
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsSearchError, $Security, $orders;

		// Search filters
		$sSrchAdvanced = ""; // Advanced search filter
		$sSrchBasic = ""; // Basic search filter
		$sFilter = "";
		if ($this->IsPageRequest()) { // Validate request

			// Set up records per page
			$this->SetUpDisplayRecs();

			// Handle reset command
			$this->ResetCmd();

			// Set up master detail parameters
			$this->SetUpMasterDetail();

			// Check QueryString parameters
			if (@$_GET["a"] <> "") {
				$orders->CurrentAction = $_GET["a"];

				// Clear inline mode
				if ($orders->CurrentAction == "cancel")
					$this->ClearInlineMode();

				// Switch to grid edit mode
				if ($orders->CurrentAction == "gridedit")
					$this->GridEditMode();

				// Switch to grid add mode
				if ($orders->CurrentAction == "gridadd")
					$this->GridAddMode();
			} else {
				if (@$_POST["a_list"] <> "") {
					$orders->CurrentAction = $_POST["a_list"]; // Get action

					// Grid Update
					if (($orders->CurrentAction == "gridupdate" || $orders->CurrentAction == "gridoverwrite") && @$_SESSION[EW_SESSION_INLINE_MODE] == "gridedit")
						$this->GridUpdate();

					// Grid Insert
					if ($orders->CurrentAction == "gridinsert" && @$_SESSION[EW_SESSION_INLINE_MODE] == "gridadd")
						$this->GridInsert();
				}
			}

			// Set up list options
			$this->SetupListOptions();

			// Get basic search values
			$this->LoadBasicSearchValues();

			// Restore search parms from Session
			$this->RestoreSearchParms();

			// Call Recordset SearchValidated event
			$orders->Recordset_SearchValidated();

			// Set up sorting order
			$this->SetUpSortOrder();

			// Get basic search criteria
			if ($gsSearchError == "")
				$sSrchBasic = $this->BasicSearchWhere();
		}

		// Restore display records
		if ($orders->getRecordsPerPage() <> "") {
			$this->lDisplayRecs = $orders->getRecordsPerPage(); // Restore from Session
		} else {
			$this->lDisplayRecs = 10; // Load default
		}

		// Load Sorting Order
		$this->LoadSortOrder();

		// Build search criteria
		if ($sSrchAdvanced <> "")
			$this->sSrchWhere = ($this->sSrchWhere <> "") ? "(" . $this->sSrchWhere . ") AND (" . $sSrchAdvanced . ")" : $sSrchAdvanced;
		if ($sSrchBasic <> "")
			$this->sSrchWhere = ($this->sSrchWhere <> "") ? "(" . $this->sSrchWhere . ") AND (" . $sSrchBasic. ")" : $sSrchBasic;

		// Call Recordset_Searching event
		$orders->Recordset_Searching($this->sSrchWhere);

		// Save search criteria
		if ($this->sSrchWhere <> "") {
			if ($sSrchBasic == "")
				$this->ResetBasicSearchParms();
			$orders->setSearchWhere($this->sSrchWhere); // Save to Session
			if (!$this->RestoreSearch) {
				$this->lStartRec = 1; // Reset start record counter
				$orders->setStartRecordNumber($this->lStartRec);
			}
		} else {
			$this->sSrchWhere = $orders->getSearchWhere();
		}

		// Build filter
		$sFilter = "";
		if (!$Security->CanList())
			$sFilter = "(0=1)"; // Filter all records

		// Restore master/detail filter
		$this->sDbMasterFilter = $orders->getMasterFilter(); // Restore master filter
		$this->sDbDetailFilter = $orders->getDetailFilter(); // Restore detail filter

		// Add master User ID filter
		if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
			if ($orders->getCurrentMasterTable() == "lesson")
				$this->sDbMasterFilter = $orders->AddMasterUserIDFilter($this->sDbMasterFilter, "lesson"); // Add master User ID filter
			if ($orders->getCurrentMasterTable() == "rooms")
				$this->sDbMasterFilter = $orders->AddMasterUserIDFilter($this->sDbMasterFilter, "rooms"); // Add master User ID filter
			if ($orders->getCurrentMasterTable() == "useraccounts")
				$this->sDbMasterFilter = $orders->AddMasterUserIDFilter($this->sDbMasterFilter, "useraccounts"); // Add master User ID filter
		}
		if ($this->sDbDetailFilter <> "")
			$sFilter = ($sFilter <> "") ? "(" . $sFilter . ") AND (" . $this->sDbDetailFilter . ")" : $this->sDbDetailFilter;
		if ($this->sSrchWhere <> "")
			$sFilter = ($sFilter <> "") ? "(" . $sFilter . ") AND (". $this->sSrchWhere . ")" : $this->sSrchWhere;

		// Load master record
		if ($orders->getMasterFilter() <> "" && $orders->getCurrentMasterTable() == "lesson") {
			global $lesson;
			$rsmaster = $lesson->LoadRs($this->sDbMasterFilter);
			$this->bMasterRecordExists = ($rsmaster && !$rsmaster->EOF);
			if (!$this->bMasterRecordExists) {
				$orders->setMasterFilter(""); // Clear master filter
				$orders->setDetailFilter(""); // Clear detail filter
				$this->setMessage($Language->Phrase("NoRecord")); // Set no record found
				$this->Page_Terminate($orders->getReturnUrl()); // Return to caller
			} else {
				$lesson->LoadListRowValues($rsmaster);
				$lesson->RowType = EW_ROWTYPE_MASTER; // Master row
				$lesson->RenderListRow();
				$rsmaster->Close();
			}
		}

		// Load master record
		if ($orders->getMasterFilter() <> "" && $orders->getCurrentMasterTable() == "rooms") {
			global $rooms;
			$rsmaster = $rooms->LoadRs($this->sDbMasterFilter);
			$this->bMasterRecordExists = ($rsmaster && !$rsmaster->EOF);
			if (!$this->bMasterRecordExists) {
				$orders->setMasterFilter(""); // Clear master filter
				$orders->setDetailFilter(""); // Clear detail filter
				$this->setMessage($Language->Phrase("NoRecord")); // Set no record found
				$this->Page_Terminate($orders->getReturnUrl()); // Return to caller
			} else {
				$rooms->LoadListRowValues($rsmaster);
				$rooms->RowType = EW_ROWTYPE_MASTER; // Master row
				$rooms->RenderListRow();
				$rsmaster->Close();
			}
		}

		// Load master record
		if ($orders->getMasterFilter() <> "" && $orders->getCurrentMasterTable() == "useraccounts") {
			global $useraccounts;
			$rsmaster = $useraccounts->LoadRs($this->sDbMasterFilter);
			$this->bMasterRecordExists = ($rsmaster && !$rsmaster->EOF);
			if (!$this->bMasterRecordExists) {
				$orders->setMasterFilter(""); // Clear master filter
				$orders->setDetailFilter(""); // Clear detail filter
				$this->setMessage($Language->Phrase("NoRecord")); // Set no record found
				$this->Page_Terminate($orders->getReturnUrl()); // Return to caller
			} else {
				$useraccounts->LoadListRowValues($rsmaster);
				$useraccounts->RowType = EW_ROWTYPE_MASTER; // Master row
				$useraccounts->RenderListRow();
				$rsmaster->Close();
			}
		}

		// Set up filter in session
		$orders->setSessionWhere($sFilter);
		$orders->CurrentFilter = "";

		// Export data only
		if (in_array($orders->Export, array("html","word","excel","xml","csv","email"))) {
			$this->ExportData();
			if ($orders->Export <> "email")
				$this->Page_Terminate(); // Terminate response
			exit();
		}
	}

	// Set up number of records displayed per page
	function SetUpDisplayRecs() {
		global $orders;
		$sWrk = @$_GET[EW_TABLE_REC_PER_PAGE];
		if ($sWrk <> "") {
			if (is_numeric($sWrk)) {
				$this->lDisplayRecs = intval($sWrk);
			} else {
				if (strtolower($sWrk) == "all") { // Display all records
					$this->lDisplayRecs = -1;
				} else {
					$this->lDisplayRecs = 10; // Non-numeric, load default
				}
			}
			$orders->setRecordsPerPage($this->lDisplayRecs); // Save to Session

			// Reset start position
			$this->lStartRec = 1;
			$orders->setStartRecordNumber($this->lStartRec);
		}
	}

	//  Exit inline mode
	function ClearInlineMode() {
		global $orders;
		$orders->CurrentAction = ""; // Clear action
		$_SESSION[EW_SESSION_INLINE_MODE] = ""; // Clear inline mode
	}

	// Switch to Grid Add mode
	function GridAddMode() {
		$_SESSION[EW_SESSION_INLINE_MODE] = "gridadd"; // Enabled grid add
	}

	// Switch to Grid Edit mode
	function GridEditMode() {
		$_SESSION[EW_SESSION_INLINE_MODE] = "gridedit"; // Enable grid edit
	}

	// Perform update to grid
	function GridUpdate() {
		global $conn, $Language, $objForm, $gsFormError, $orders;
		$rowindex = 1;
		$bGridUpdate = TRUE;

		// Begin transaction
		$conn->BeginTrans();

		// Get old recordset
		$orders->CurrentFilter = $this->BuildKeyFilter();
		$sSql = $orders->SQL();
		if ($rs = $conn->Execute($sSql)) {
			$rsold = $rs->GetRows();
			$rs->Close();
		}
		$sKey = "";

		// Update row index and get row key
		$objForm->Index = $rowindex;
		$sThisKey = strval($objForm->GetValue("k_key"));

		// Update all rows based on key
		while ($sThisKey <> "") {

			// Load all values and keys
			$this->GetUploadFiles(); // Get upload files
			$this->LoadFormValues(); // Get form values

			// Validate form
			if (!$this->ValidateForm()) {
				$bGridUpdate = FALSE; // Form error, reset action
				$this->setMessage($gsFormError);
			} else {

				// Overwrite record, just reload hash value
				if ($orders->CurrentAction == "gridoverwrite")
					$this->LoadRowHash();
				if ($this->SetupKeyValues($sThisKey)) { // Set up key values
					$orders->SendEmail = FALSE; // Do not send email on update success
					$bGridUpdate = $this->EditRow(); // Update this row
				} else {
					$bGridUpdate = FALSE; // update failed
				}
			}
			if ($bGridUpdate) {
				if ($sKey <> "") $sKey .= ", ";
				$sKey .= $sThisKey;
			} else {
				break;
			}

			// Update row index and get row key
			$rowindex++; // next row
			$objForm->Index = $rowindex;
			$sThisKey = strval($objForm->GetValue("k_key"));
		}
		if ($bGridUpdate) {
			$conn->CommitTrans(); // Commit transaction

			// Get new recordset
			if ($rs = $conn->Execute($sSql)) {
				$rsnew = $rs->GetRows();
				$rs->Close();
			}
			$this->setMessage($Language->Phrase("UpdateSuccess")); // Set update success message
			$this->ClearInlineMode(); // Clear inline edit mode

			// Send notify email
			$sFn = "txt/notify.txt";
			$sTable = 'orders';
			$sSubject = $sTable . " " . $Language->Phrase("RecordUpdated");
			$sAction = $Language->Phrase("ActionUpdatedGridEdit");
			$Email = new cEmail();
			$Email->Load($sFn);
			$Email->ReplaceSender(EW_SENDER_EMAIL); // Replace Sender
			$Email->ReplaceRecipient(EW_RECIPIENT_EMAIL); // Replace Recipient
			$Email->ReplaceSubject($sSubject); // Replace Subject
			$Email->ReplaceContent("<!--table-->", $sTable);
			$Email->ReplaceContent("<!--key-->", $sKey);
			$Email->ReplaceContent("<!--action-->", $sAction);
			$Email->Charset = EW_EMAIL_CHARSET;
			$Args = array();
			$Args["rsold"] =& $rsold;
			$Args["rsnew"] =& $rsnew;
			$bEmailSent = FALSE;
			if ($orders->Email_Sending($Email, $Args))
				$bEmailSent = $Email->Send();

			// Set up error message
			if (!$bEmailSent)
				$this->setMessage($Email->SendErrDescription);
		} else {
			$conn->RollbackTrans(); // Rollback transaction
			if ($this->getMessage() == "")
				$this->setMessage($Language->Phrase("UpdateFailed")); // Set update failed message
			$orders->EventCancelled = TRUE; // Set event cancelled
			$orders->CurrentAction = "gridedit"; // Stay in Grid Edit mode
		}
	}

	// Build filter for all keys
	function BuildKeyFilter() {
		global $objForm, $orders;
		$sWrkFilter = "";

		// Update row index and get row key
		$rowindex = 1;
		$objForm->Index = $rowindex;
		$sThisKey = strval($objForm->GetValue("k_key"));
		while ($sThisKey <> "") {
			if ($this->SetupKeyValues($sThisKey)) {
				$sFilter = $orders->KeyFilter();
				if ($sWrkFilter <> "") $sWrkFilter .= " OR ";
				$sWrkFilter .= $sFilter;
			} else {
				$sWrkFilter = "0=1";
				break;
			}

			// Update row index and get row key
			$rowindex++; // next row
			$objForm->Index = $rowindex;
			$sThisKey = strval($objForm->GetValue("k_key"));
		}
		return $sWrkFilter;
	}

	// Set up key values
	function SetupKeyValues($key) {
		global $orders;
		$arrKeyFlds = explode(EW_COMPOSITE_KEY_SEPARATOR, $key);
		if (count($arrKeyFlds) >= 1) {
			$orders->id->setFormValue($arrKeyFlds[0]);
			if (!is_numeric($orders->id->FormValue))
				return FALSE;
		}
		return TRUE;
	}

	// Perform Grid Add
	function GridInsert() {
		global $conn, $Language, $objForm, $gsFormError, $orders;
		$rowindex = 1;
		$bGridInsert = FALSE;

		// Begin transaction
		$conn->BeginTrans();

		// Init key filter
		$sWrkFilter = "";
		$addcnt = 0;
		$sKey = "";

		// Get row count
		$objForm->Index = 0;
		$rowcnt = strval($objForm->GetValue("key_count"));
		if ($rowcnt == "" || !is_numeric($rowcnt))
			$rowcnt = 0;

		// Insert all rows
		for ($rowindex = 1; $rowindex <= $rowcnt; $rowindex++) {

			// Load current row values
			$objForm->Index = $rowindex;
			$this->GetUploadFiles(); // Get upload files
			$this->LoadFormValues(); // Get form values
			if (!$this->EmptyRow()) {
				$addcnt++;
				$orders->SendEmail = FALSE; // Do not send email on insert success

				// Validate form
				if (!$this->ValidateForm()) {
					$bGridInsert = FALSE; // Form error, reset action
					$this->setMessage($gsFormError);
				} else {
					$bGridInsert = $this->AddRow(); // Insert this row
				}
				if ($bGridInsert) {
					if ($sKey <> "") $sKey .= EW_COMPOSITE_KEY_SEPARATOR;
					$sKey .= $orders->id->CurrentValue;

					// Add filter for this record
					$sFilter = $orders->KeyFilter();
					if ($sWrkFilter <> "") $sWrkFilter .= " OR ";
					$sWrkFilter .= $sFilter;
				} else {
					break;
				}
			}
		}
		if ($bGridInsert) {
			$conn->CommitTrans(); // Commit transaction

			// Get new recordset
			$orders->CurrentFilter = $sWrkFilter;
			$sSql = $orders->SQL();
			if ($rs = $conn->Execute($sSql)) {
				$rsnew = $rs->GetRows();
				$rs->Close();
			}
			$this->setMessage($Language->Phrase("InsertSuccess")); // Set insert success message
			$this->ClearInlineMode(); // Clear grid add mode

			// Send notify email
			$sFn = "txt/notify.txt";
			$sTable = 'orders';
			$sSubject = $sTable . " " . $Language->Phrase("RecordInserted");
			$sAction = $Language->Phrase("ActionInsertedGridAdd");
			$Email = new cEmail();
			$Email->Load($sFn);
			$Email->ReplaceSender(EW_SENDER_EMAIL); // Replace Sender
			$Email->ReplaceRecipient(EW_RECIPIENT_EMAIL); // Replace Recipient
			$Email->ReplaceSubject($sSubject); // Replace Subject
			$Email->ReplaceContent("<!--table-->", $sTable);
			$Email->ReplaceContent("<!--key-->", $sKey);
			$Email->ReplaceContent("<!--action-->", $sAction);
			$Email->Charset = EW_EMAIL_CHARSET;
			$Args = array();
			$Args["rs"] =& $rsnew;
			$bEmailSent = FALSE;
			if ($orders->Email_Sending($Email, $Args))
				$bEmailSent = $Email->Send();
			if (!$bEmailSent)
				$this->setMessage($Email->SendErrDescription);
		} else {
			$conn->RollbackTrans(); // Rollback transaction
			if ($addcnt == 0) { // No record inserted
				$this->setMessage($Language->Phrase("NoAddRecord"));
			} elseif ($this->getMessage() == "") {
				$this->setMessage($Language->Phrase("InsertFailed")); // Set insert failed message
			}
			$orders->EventCancelled = TRUE; // Set event cancelled
			$orders->CurrentAction = "gridadd"; // Stay in gridadd mode
		}
	}

	// Check if empty row
	function EmptyRow() {
		global $orders;
		if ($orders->lesson->CurrentValue <> $orders->lesson->OldValue)
			return FALSE;
		if ($orders->title->CurrentValue <> $orders->title->OldValue)
			return FALSE;
		if ($orders->room->CurrentValue <> $orders->room->OldValue)
			return FALSE;
		if ($orders->request_date->CurrentValue <> $orders->request_date->OldValue)
			return FALSE;
		if ($orders->return_date->CurrentValue <> $orders->return_date->OldValue)
			return FALSE;
		if (!ew_Empty($orders->attachment->Upload->Value))
			return FALSE;
		return TRUE;
	}

	// Restore form values for current row
	function RestoreCurrentRowFormValues($idx) {
		global $objForm, $orders;

		// Get row based on current index
		$objForm->Index = $idx;
		if ($orders->CurrentAction == "gridadd")
			$this->LoadFormValues(); // Load form values
		if ($orders->CurrentAction == "gridedit") {
			$sKey = strval($objForm->GetValue("k_key"));
			$arrKeyFlds = explode(EW_COMPOSITE_KEY_SEPARATOR, $sKey);
			if (count($arrKeyFlds) >= 1) {
				if (strval($arrKeyFlds[0]) == strval($orders->id->CurrentValue)) {
					$this->LoadFormValues(); // Load form values
				}
			}
		}
	}

	// Return basic search SQL
	function BasicSearchSQL($Keyword) {
		global $orders;
		$sKeyword = ew_AdjustSql($Keyword);
		$sWhere = "";
		$this->BuildBasicSearchSQL($sWhere, $orders->title, $Keyword);
		$this->BuildBasicSearchSQL($sWhere, $orders->room, $Keyword);
		$this->BuildBasicSearchSQL($sWhere, $orders->teacher, $Keyword);
		$this->BuildBasicSearchSQL($sWhere, $orders->attachment, $Keyword);
		$this->BuildBasicSearchSQL($sWhere, $orders->note, $Keyword);
		return $sWhere;
	}

	// Build basic search SQL
	function BuildBasicSearchSql(&$Where, &$Fld, $Keyword) {
		$sFldExpression = ($Fld->FldVirtualExpression <> "") ? $Fld->FldVirtualExpression : $Fld->FldExpression;
		$lFldDataType = ($Fld->FldIsVirtual) ? EW_DATATYPE_STRING : $Fld->FldDataType;
		if ($lFldDataType == EW_DATATYPE_NUMBER) {
			$sWrk = $sFldExpression . " = " . ew_QuotedValue($Keyword, $lFldDataType);
		} else {
			$sWrk = $sFldExpression . " LIKE " . ew_QuotedValue("%" . $Keyword . "%", $lFldDataType);
		}
		if ($Where <> "") $Where .= " OR ";
		$Where .= $sWrk;
	}

	// Return basic search WHERE clause based on search keyword and type
	function BasicSearchWhere() {
		global $Security, $orders;
		$sSearchStr = "";
		if (!$Security->CanSearch()) return "";
		$sSearchKeyword = $orders->BasicSearchKeyword;
		$sSearchType = $orders->BasicSearchType;
		if ($sSearchKeyword <> "") {
			$sSearch = trim($sSearchKeyword);
			if ($sSearchType <> "") {
				while (strpos($sSearch, "  ") !== FALSE)
					$sSearch = str_replace("  ", " ", $sSearch);
				$arKeyword = explode(" ", trim($sSearch));
				foreach ($arKeyword as $sKeyword) {
					if ($sSearchStr <> "") $sSearchStr .= " " . $sSearchType . " ";
					$sSearchStr .= "(" . $this->BasicSearchSQL($sKeyword) . ")";
				}
			} else {
				$sSearchStr = $this->BasicSearchSQL($sSearch);
			}
		}
		if ($sSearchKeyword <> "") {
			$orders->setSessionBasicSearchKeyword($sSearchKeyword);
			$orders->setSessionBasicSearchType($sSearchType);
		}
		return $sSearchStr;
	}

	// Clear all search parameters
	function ResetSearchParms() {
		global $orders;

		// Clear search WHERE clause
		$this->sSrchWhere = "";
		$orders->setSearchWhere($this->sSrchWhere);

		// Clear basic search parameters
		$this->ResetBasicSearchParms();
	}

	// Clear all basic search parameters
	function ResetBasicSearchParms() {
		global $orders;
		$orders->setSessionBasicSearchKeyword("");
		$orders->setSessionBasicSearchType("");
	}

	// Restore all search parameters
	function RestoreSearchParms() {
		global $orders;
		$bRestore = TRUE;
		if (@$_GET[EW_TABLE_BASIC_SEARCH] <> "") $bRestore = FALSE;
		$this->RestoreSearch = $bRestore;
		if ($bRestore) {

			// Restore basic search values
			$orders->BasicSearchKeyword = $orders->getSessionBasicSearchKeyword();
			$orders->BasicSearchType = $orders->getSessionBasicSearchType();
		}
	}

	// Set up sort parameters
	function SetUpSortOrder() {
		global $orders;

		// Check for "order" parameter
		if (@$_GET["order"] <> "") {
			$orders->CurrentOrder = ew_StripSlashes(@$_GET["order"]);
			$orders->CurrentOrderType = @$_GET["ordertype"];
			$orders->UpdateSort($orders->lesson); // lesson
			$orders->UpdateSort($orders->title); // title
			$orders->UpdateSort($orders->room); // room
			$orders->UpdateSort($orders->order_date); // order_date
			$orders->UpdateSort($orders->request_date); // request_date
			$orders->UpdateSort($orders->return_date); // return_date
			$orders->UpdateSort($orders->teacher); // teacher
			$orders->UpdateSort($orders->attachment); // attachment
			$orders->setStartRecordNumber(1); // Reset start position
		}
	}

	// Load sort order parameters
	function LoadSortOrder() {
		global $orders;
		$sOrderBy = $orders->getSessionOrderBy(); // Get ORDER BY from Session
		if ($sOrderBy == "") {
			if ($orders->SqlOrderBy() <> "") {
				$sOrderBy = $orders->SqlOrderBy();
				$orders->setSessionOrderBy($sOrderBy);
				$orders->request_date->setSort("DESC");
				$orders->lesson->setSort("ASC");
				$orders->teacher->setSort("ASC");
			}
		}
	}

	// Reset command
	// cmd=reset (Reset search parameters)
	// cmd=resetall (Reset search and master/detail parameters)
	// cmd=resetsort (Reset sort parameters)
	function ResetCmd() {
		global $orders;

		// Get reset command
		if (@$_GET["cmd"] <> "") {
			$sCmd = $_GET["cmd"];

			// Reset search criteria
			if (strtolower($sCmd) == "reset" || strtolower($sCmd) == "resetall")
				$this->ResetSearchParms();

			// Reset master/detail keys
			if (strtolower($sCmd) == "resetall") {
				$orders->getCurrentMasterTable = ""; // Clear master table
				$orders->setMasterFilter(""); // Clear master filter
				$this->sDbMasterFilter = "";
				$orders->setDetailFilter(""); // Clear detail filter
				$this->sDbDetailFilter = "";
				$orders->lesson->setSessionValue("");
				$orders->room->setSessionValue("");
				$orders->teacher->setSessionValue("");
			}

			// Reset sorting order
			if (strtolower($sCmd) == "resetsort") {
				$sOrderBy = "";
				$orders->setSessionOrderBy($sOrderBy);
				$orders->lesson->setSort("");
				$orders->title->setSort("");
				$orders->room->setSort("");
				$orders->order_date->setSort("");
				$orders->request_date->setSort("");
				$orders->return_date->setSort("");
				$orders->teacher->setSort("");
				$orders->attachment->setSort("");
			}

			// Reset start position
			$this->lStartRec = 1;
			$orders->setStartRecordNumber($this->lStartRec);
		}
	}

	// Set up list options
	function SetupListOptions() {
		global $Security, $orders;

		// "view"
		$this->ListOptions->Add("view");
		$item =& $this->ListOptions->Items["view"];
		$item->CssStyle = "white-space: nowrap;";
		$item->Visible = $Security->CanView();
		$item->OnLeft = FALSE;

		// "edit"
		$this->ListOptions->Add("edit");
		$item =& $this->ListOptions->Items["edit"];
		$item->CssStyle = "white-space: nowrap;";
		$item->Visible = $Security->CanEdit();
		$item->OnLeft = FALSE;

		// "copy"
		$this->ListOptions->Add("copy");
		$item =& $this->ListOptions->Items["copy"];
		$item->CssStyle = "white-space: nowrap;";
		$item->Visible = $Security->CanAdd();
		$item->OnLeft = FALSE;

		// "detail_order_detail"
		$this->ListOptions->Add("detail_order_detail");
		$item =& $this->ListOptions->Items["detail_order_detail"];
		$item->CssStyle = "white-space: nowrap;";
		$item->Visible = $Security->AllowList('order_detail');
		$item->OnLeft = FALSE;

		// "checkbox"
		$this->ListOptions->Add("checkbox");
		$item =& $this->ListOptions->Items["checkbox"];
		$item->CssStyle = "white-space: nowrap;";
		$item->Visible = $Security->CanDelete();
		$item->OnLeft = FALSE;
		$item->Header = "<input type=\"checkbox\" name=\"key\" id=\"key\" class=\"phpmaker\" onclick=\"orders_list.SelectAllKey(this);\">";

		// Call ListOptions_Load event
		$this->ListOptions_Load();
		if ($orders->Export <> "" ||
			$orders->CurrentAction == "gridadd" ||
			$orders->CurrentAction == "gridedit")
			$this->ListOptions->HideAllOptions();
	}

	// Render list options
	function RenderListOptions() {
		global $Security, $Language, $orders;
		$this->ListOptions->LoadDefault();

		// "view"
		$oListOpt =& $this->ListOptions->Items["view"];
		if ($Security->CanView() && $this->ShowOptionLink() && $oListOpt->Visible)
			$oListOpt->Body = "<a href=\"" . $this->ViewUrl . "\">" . $Language->Phrase("ViewLink") . "</a>";

		// "edit"
		$oListOpt =& $this->ListOptions->Items["edit"];
		if ($Security->CanEdit() && $this->ShowOptionLink() && $oListOpt->Visible) {
			$oListOpt->Body = "<a href=\"" . $this->EditUrl . "\">" . $Language->Phrase("EditLink") . "</a>";
		}

		// "copy"
		$oListOpt =& $this->ListOptions->Items["copy"];
		if ($Security->CanAdd() && $this->ShowOptionLink() && $oListOpt->Visible) {
			$oListOpt->Body = "<a href=\"" . $this->CopyUrl . "\">" . $Language->Phrase("CopyLink") . "</a>";
		}

		// "detail_order_detail"
		$oListOpt =& $this->ListOptions->Items["detail_order_detail"];
		if ($Security->AllowList('order_detail') && $this->ShowOptionLink()) {
			$oListOpt->Body = $Language->Phrase("DetailLink") . $Language->TablePhrase("order_detail", "TblCaption");
			$oListOpt->Body .= str_replace("%c", $this->lorder_detail_Count, $Language->Phrase("DetailCount"));
			$oListOpt->Body = "<a href=\"order_detaillist.php?" . EW_TABLE_SHOW_MASTER . "=orders&id=" . urlencode(strval($orders->id->CurrentValue)) . "\">" . $oListOpt->Body . "</a>";
		}

		// "checkbox"
		$oListOpt =& $this->ListOptions->Items["checkbox"];
		if ($Security->CanDelete() && $this->ShowOptionLink() && $oListOpt->Visible)
			$oListOpt->Body = "<input type=\"checkbox\" name=\"key_m[]\" id=\"key_m[]\" value=\"" . ew_HtmlEncode($orders->id->CurrentValue) . "\" class=\"phpmaker\" onclick='ew_ClickMultiCheckbox(this);'>";
		if ($orders->CurrentAction == "gridedit")
			$this->sMultiSelectKey .= "<input type=\"hidden\" name=\"k" . $this->lRowIndex . "_key\" id=\"k" . $this->lRowIndex . "_key\" value=\"" . $orders->id->CurrentValue . "\">";
			$this->sMultiSelectKey .= "<input type=\"hidden\" name=\"k" . $this->lRowIndex . "_hash\" id=\"k" . $this->lRowIndex . "_hash\" value=\"" . $this->HashValue . "\">";
		$this->RenderListOptionsExt();

		// Call ListOptions_Rendered event
		$this->ListOptions_Rendered();
	}

	function RenderListOptionsExt() {
		global $Security, $Language, $orders;
	}

	// Set up starting record parameters
	function SetUpStartRec() {
		global $orders;
		if ($this->lDisplayRecs == 0)
			return;
		if ($this->IsPageRequest()) { // Validate request
			if (@$_GET[EW_TABLE_START_REC] <> "") { // Check for "start" parameter
				$this->lStartRec = $_GET[EW_TABLE_START_REC];
				$orders->setStartRecordNumber($this->lStartRec);
			} elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
				$this->nPageNo = $_GET[EW_TABLE_PAGE_NO];
				if (is_numeric($this->nPageNo)) {
					$this->lStartRec = ($this->nPageNo-1)*$this->lDisplayRecs+1;
					if ($this->lStartRec <= 0) {
						$this->lStartRec = 1;
					} elseif ($this->lStartRec >= intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1) {
						$this->lStartRec = intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1;
					}
					$orders->setStartRecordNumber($this->lStartRec);
				}
			}
		}
		$this->lStartRec = $orders->getStartRecordNumber();

		// Check if correct start record counter
		if (!is_numeric($this->lStartRec) || $this->lStartRec == "") { // Avoid invalid start record counter
			$this->lStartRec = 1; // Reset start record counter
			$orders->setStartRecordNumber($this->lStartRec);
		} elseif (intval($this->lStartRec) > intval($this->lTotalRecs)) { // Avoid starting record > total records
			$this->lStartRec = intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1; // Point to last page first record
			$orders->setStartRecordNumber($this->lStartRec);
		} elseif (($this->lStartRec-1) % $this->lDisplayRecs <> 0) {
			$this->lStartRec = intval(($this->lStartRec-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1; // Point to page boundary
			$orders->setStartRecordNumber($this->lStartRec);
		}
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm, $orders;

		// Get upload data
			$orders->attachment->Upload->Index = $objForm->Index;
			if ($orders->attachment->Upload->UploadFile()) {

				// No action required
			} else {
				echo $orders->attachment->Upload->Message;
				$this->Page_Terminate();
				exit();
			}
	}

	// Load default values
	function LoadDefaultValues() {
		global $orders;
	}

	// Load basic search values
	function LoadBasicSearchValues() {
		global $orders;
		$orders->BasicSearchKeyword = @$_GET[EW_TABLE_BASIC_SEARCH];
		$orders->BasicSearchType = @$_GET[EW_TABLE_BASIC_SEARCH_TYPE];
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $orders;
		$orders->lesson->setFormValue($objForm->GetValue("x_lesson"));
		$orders->lesson->setOldValue($objForm->GetValue("o_lesson"));
		$orders->title->setFormValue($objForm->GetValue("x_title"));
		$orders->title->setOldValue($objForm->GetValue("o_title"));
		$orders->room->setFormValue($objForm->GetValue("x_room"));
		$orders->room->setOldValue($objForm->GetValue("o_room"));
		$orders->order_date->setFormValue($objForm->GetValue("x_order_date"));
		$orders->order_date->CurrentValue = ew_UnFormatDateTime($orders->order_date->CurrentValue, 5);
		$orders->order_date->setOldValue($objForm->GetValue("o_order_date"));
		$orders->request_date->setFormValue($objForm->GetValue("x_request_date"));
		$orders->request_date->CurrentValue = ew_UnFormatDateTime($orders->request_date->CurrentValue, 5);
		$orders->request_date->setOldValue($objForm->GetValue("o_request_date"));
		$orders->return_date->setFormValue($objForm->GetValue("x_return_date"));
		$orders->return_date->CurrentValue = ew_UnFormatDateTime($orders->return_date->CurrentValue, 5);
		$orders->return_date->setOldValue($objForm->GetValue("o_return_date"));
		$orders->teacher->setFormValue($objForm->GetValue("x_teacher"));
		$orders->teacher->setOldValue($objForm->GetValue("o_teacher"));
		$orders->id->setFormValue($objForm->GetValue("x_id"));
		if ($orders->CurrentAction <> "overwrite")
			$this->HashValue = $objForm->GetValue("k_hash");
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $orders;
		$orders->id->CurrentValue = $orders->id->FormValue;
		$orders->lesson->CurrentValue = $orders->lesson->FormValue;
		$orders->title->CurrentValue = $orders->title->FormValue;
		$orders->room->CurrentValue = $orders->room->FormValue;
		$orders->order_date->CurrentValue = $orders->order_date->FormValue;
		$orders->order_date->CurrentValue = ew_UnFormatDateTime($orders->order_date->CurrentValue, 5);
		$orders->request_date->CurrentValue = $orders->request_date->FormValue;
		$orders->request_date->CurrentValue = ew_UnFormatDateTime($orders->request_date->CurrentValue, 5);
		$orders->return_date->CurrentValue = $orders->return_date->FormValue;
		$orders->return_date->CurrentValue = ew_UnFormatDateTime($orders->return_date->CurrentValue, 5);
		$orders->teacher->CurrentValue = $orders->teacher->FormValue;
		if ($orders->CurrentAction <> "overwrite")
			$this->HashValue = $objForm->GetValue("k_hash");
	}

	// Load recordset
	function LoadRecordset($offset = -1, $rowcnt = -1) {
		global $conn, $orders;

		// Call Recordset Selecting event
		$orders->Recordset_Selecting($orders->CurrentFilter);

		// Load List page SQL
		$sSql = $orders->SelectSQL();
		if ($offset > -1 && $rowcnt > -1)
			$sSql .= " LIMIT $offset, $rowcnt";

		// Load recordset
		$rs = ew_LoadRecordset($sSql);

		// Call Recordset Selected event
		$orders->Recordset_Selected($rs);
		return $rs;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $orders;
		$sFilter = $orders->KeyFilter();

		// Call Row Selecting event
		$orders->Row_Selecting($sFilter);

		// Load SQL based on filter
		$orders->CurrentFilter = $sFilter;
		$sSql = $orders->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values
			if (!$orders->EventCancelled)
				$this->HashValue = $this->GetRsHash($rs); // Get hash value for record

			// Call Row Selected event
			$orders->Row_Selected($rs);
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $orders;
		$orders->id->setDbValue($rs->fields('id'));
		$orders->lesson->setDbValue($rs->fields('lesson'));
		$orders->title->setDbValue($rs->fields('title'));
		$orders->room->setDbValue($rs->fields('room'));
		$orders->order_date->setDbValue($rs->fields('order_date'));
		$orders->request_date->setDbValue($rs->fields('request_date'));
		$orders->return_date->setDbValue($rs->fields('return_date'));
		$orders->teacher->setDbValue($rs->fields('teacher'));
		$orders->attachment->Upload->DbValue = $rs->fields('attachment');
		$orders->note->setDbValue($rs->fields('note'));
		$sDetailFilter = $GLOBALS["order_detail"]->SqlDetailFilter_orders();
		$sDetailFilter = str_replace("@order_id@", ew_AdjustSql($orders->id->DbValue), $sDetailFilter);
		$this->lorder_detail_Count = $GLOBALS["order_detail"]->LoadRecordCount($sDetailFilter);
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language, $orders;

		// Initialize URLs
		$this->ViewUrl = $orders->ViewUrl();
		$this->EditUrl = $orders->EditUrl();
		$this->InlineEditUrl = $orders->InlineEditUrl();
		$this->CopyUrl = $orders->CopyUrl();
		$this->InlineCopyUrl = $orders->InlineCopyUrl();
		$this->DeleteUrl = $orders->DeleteUrl();

		// Call Row_Rendering event
		$orders->Row_Rendering();

		// Common render codes for all row types
		// lesson

		$orders->lesson->CellCssStyle = ""; $orders->lesson->CellCssClass = "";
		$orders->lesson->CellAttrs = array(); $orders->lesson->ViewAttrs = array(); $orders->lesson->EditAttrs = array();

		// title
		$orders->title->CellCssStyle = ""; $orders->title->CellCssClass = "";
		$orders->title->CellAttrs = array(); $orders->title->ViewAttrs = array(); $orders->title->EditAttrs = array();

		// room
		$orders->room->CellCssStyle = ""; $orders->room->CellCssClass = "";
		$orders->room->CellAttrs = array(); $orders->room->ViewAttrs = array(); $orders->room->EditAttrs = array();

		// order_date
		$orders->order_date->CellCssStyle = ""; $orders->order_date->CellCssClass = "";
		$orders->order_date->CellAttrs = array(); $orders->order_date->ViewAttrs = array(); $orders->order_date->EditAttrs = array();

		// request_date
		$orders->request_date->CellCssStyle = ""; $orders->request_date->CellCssClass = "";
		$orders->request_date->CellAttrs = array(); $orders->request_date->ViewAttrs = array(); $orders->request_date->EditAttrs = array();

		// return_date
		$orders->return_date->CellCssStyle = ""; $orders->return_date->CellCssClass = "";
		$orders->return_date->CellAttrs = array(); $orders->return_date->ViewAttrs = array(); $orders->return_date->EditAttrs = array();

		// teacher
		$orders->teacher->CellCssStyle = ""; $orders->teacher->CellCssClass = "";
		$orders->teacher->CellAttrs = array(); $orders->teacher->ViewAttrs = array(); $orders->teacher->EditAttrs = array();

		// attachment
		$orders->attachment->CellCssStyle = ""; $orders->attachment->CellCssClass = "";
		$orders->attachment->CellAttrs = array(); $orders->attachment->ViewAttrs = array(); $orders->attachment->EditAttrs = array();
		if ($orders->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$orders->id->ViewValue = $orders->id->CurrentValue;
			$orders->id->CssStyle = "";
			$orders->id->CssClass = "";
			$orders->id->ViewCustomAttributes = "";

			// lesson
			if (strval($orders->lesson->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($orders->lesson->CurrentValue) . "";
			$sSqlWrk = "SELECT `name` FROM `lesson`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `id` Asc";
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$orders->lesson->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$orders->lesson->ViewValue = $orders->lesson->CurrentValue;
				}
			} else {
				$orders->lesson->ViewValue = NULL;
			}
			$orders->lesson->CssStyle = "";
			$orders->lesson->CssClass = "";
			$orders->lesson->ViewCustomAttributes = "";

			// title
			$orders->title->ViewValue = $orders->title->CurrentValue;
			$orders->title->CssStyle = "";
			$orders->title->CssClass = "";
			$orders->title->ViewCustomAttributes = "";

			// room
			if (strval($orders->room->CurrentValue) <> "") {
				$sFilterWrk = "`id` = '" . ew_AdjustSql($orders->room->CurrentValue) . "'";
			$sSqlWrk = "SELECT `name` FROM `rooms`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `name` Asc";
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$orders->room->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$orders->room->ViewValue = $orders->room->CurrentValue;
				}
			} else {
				$orders->room->ViewValue = NULL;
			}
			$orders->room->CssStyle = "";
			$orders->room->CssClass = "";
			$orders->room->ViewCustomAttributes = "";

			// order_date
			$orders->order_date->ViewValue = $orders->order_date->CurrentValue;
			$orders->order_date->ViewValue = ew_FormatDateTime($orders->order_date->ViewValue, 5);
			$orders->order_date->CssStyle = "";
			$orders->order_date->CssClass = "";
			$orders->order_date->ViewCustomAttributes = "";

			// request_date
			$orders->request_date->ViewValue = $orders->request_date->CurrentValue;
			$orders->request_date->ViewValue = ew_FormatDateTime($orders->request_date->ViewValue, 5);
			$orders->request_date->CssStyle = "";
			$orders->request_date->CssClass = "";
			$orders->request_date->ViewCustomAttributes = "";

			// return_date
			$orders->return_date->ViewValue = $orders->return_date->CurrentValue;
			$orders->return_date->ViewValue = ew_FormatDateTime($orders->return_date->ViewValue, 5);
			$orders->return_date->CssStyle = "";
			$orders->return_date->CssClass = "";
			$orders->return_date->ViewCustomAttributes = "";

			// teacher
			$orders->teacher->ViewValue = $orders->teacher->CurrentValue;
			$orders->teacher->CssStyle = "";
			$orders->teacher->CssClass = "";
			$orders->teacher->ViewCustomAttributes = "";

			// attachment
			if (!ew_Empty($orders->attachment->Upload->DbValue)) {
				$orders->attachment->ViewValue = $orders->attachment->Upload->DbValue;
			} else {
				$orders->attachment->ViewValue = "";
			}
			$orders->attachment->CssStyle = "";
			$orders->attachment->CssClass = "";
			$orders->attachment->ViewCustomAttributes = "";

			// lesson
			$orders->lesson->HrefValue = "";
			$orders->lesson->TooltipValue = $orders->note->CurrentValue;

			// title
			$orders->title->HrefValue = "";
			$orders->title->TooltipValue = "";

			// room
			$orders->room->HrefValue = "";
			$orders->room->TooltipValue = "";

			// order_date
			$orders->order_date->HrefValue = "";
			$orders->order_date->TooltipValue = "";

			// request_date
			$orders->request_date->HrefValue = "";
			$orders->request_date->TooltipValue = "";

			// return_date
			$orders->return_date->HrefValue = "";
			$orders->return_date->TooltipValue = "";

			// teacher
			$orders->teacher->HrefValue = "";
			$orders->teacher->TooltipValue = "";

			// attachment
			if (!ew_Empty($orders->attachment->Upload->DbValue)) {
				$orders->attachment->HrefValue = ew_UploadPathEx(FALSE, $orders->attachment->UploadPath) . ((!empty($orders->attachment->ViewValue)) ? $orders->attachment->ViewValue : $orders->attachment->CurrentValue);
				if ($orders->Export <> "") $orders->attachment->HrefValue = ew_ConvertFullUrl($orders->attachment->HrefValue);
			} else {
				$orders->attachment->HrefValue = "";
			}
			$orders->attachment->TooltipValue = "";
		} elseif ($orders->RowType == EW_ROWTYPE_ADD) { // Add row

			// lesson
			$orders->lesson->EditCustomAttributes = "";
			if ($orders->lesson->getSessionValue() <> "") {
				$orders->lesson->CurrentValue = $orders->lesson->getSessionValue();
				$orders->lesson->OldValue = $orders->lesson->CurrentValue;
			if (strval($orders->lesson->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($orders->lesson->CurrentValue) . "";
			$sSqlWrk = "SELECT `name` FROM `lesson`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `id` Asc";
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$orders->lesson->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$orders->lesson->ViewValue = $orders->lesson->CurrentValue;
				}
			} else {
				$orders->lesson->ViewValue = NULL;
			}
			$orders->lesson->CssStyle = "";
			$orders->lesson->CssClass = "";
			$orders->lesson->ViewCustomAttributes = "";
			} else {
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `lesson`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `id` Asc";
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$orders->lesson->EditValue = $arwrk;
			}

			// title
			$orders->title->EditCustomAttributes = "";
			$orders->title->EditValue = ew_HtmlEncode($orders->title->CurrentValue);

			// room
			$orders->room->EditCustomAttributes = "";
			if ($orders->room->getSessionValue() <> "") {
				$orders->room->CurrentValue = $orders->room->getSessionValue();
				$orders->room->OldValue = $orders->room->CurrentValue;
			if (strval($orders->room->CurrentValue) <> "") {
				$sFilterWrk = "`id` = '" . ew_AdjustSql($orders->room->CurrentValue) . "'";
			$sSqlWrk = "SELECT `name` FROM `rooms`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `name` Asc";
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$orders->room->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$orders->room->ViewValue = $orders->room->CurrentValue;
				}
			} else {
				$orders->room->ViewValue = NULL;
			}
			$orders->room->CssStyle = "";
			$orders->room->CssClass = "";
			$orders->room->ViewCustomAttributes = "";
			} else {
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `rooms`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `name` Asc";
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$orders->room->EditValue = $arwrk;
			}

			// order_date
			// request_date

			$orders->request_date->EditCustomAttributes = "";
			$orders->request_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($orders->request_date->CurrentValue, 5));

			// return_date
			$orders->return_date->EditCustomAttributes = "";
			$orders->return_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($orders->return_date->CurrentValue, 5));

			// teacher
			// attachment

			$orders->attachment->EditCustomAttributes = "";
			if (!ew_Empty($orders->attachment->Upload->DbValue)) {
				$orders->attachment->EditValue = $orders->attachment->Upload->DbValue;
			} else {
				$orders->attachment->EditValue = "";
			}
		} elseif ($orders->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// lesson
			$orders->lesson->EditCustomAttributes = "";
			if ($orders->lesson->getSessionValue() <> "") {
				$orders->lesson->CurrentValue = $orders->lesson->getSessionValue();
				$orders->lesson->OldValue = $orders->lesson->CurrentValue;
			if (strval($orders->lesson->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($orders->lesson->CurrentValue) . "";
			$sSqlWrk = "SELECT `name` FROM `lesson`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `id` Asc";
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$orders->lesson->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$orders->lesson->ViewValue = $orders->lesson->CurrentValue;
				}
			} else {
				$orders->lesson->ViewValue = NULL;
			}
			$orders->lesson->CssStyle = "";
			$orders->lesson->CssClass = "";
			$orders->lesson->ViewCustomAttributes = "";
			} else {
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `lesson`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `id` Asc";
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$orders->lesson->EditValue = $arwrk;
			}

			// title
			$orders->title->EditCustomAttributes = "";
			$orders->title->EditValue = ew_HtmlEncode($orders->title->CurrentValue);

			// room
			$orders->room->EditCustomAttributes = "";
			if ($orders->room->getSessionValue() <> "") {
				$orders->room->CurrentValue = $orders->room->getSessionValue();
				$orders->room->OldValue = $orders->room->CurrentValue;
			if (strval($orders->room->CurrentValue) <> "") {
				$sFilterWrk = "`id` = '" . ew_AdjustSql($orders->room->CurrentValue) . "'";
			$sSqlWrk = "SELECT `name` FROM `rooms`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `name` Asc";
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$orders->room->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$orders->room->ViewValue = $orders->room->CurrentValue;
				}
			} else {
				$orders->room->ViewValue = NULL;
			}
			$orders->room->CssStyle = "";
			$orders->room->CssClass = "";
			$orders->room->ViewCustomAttributes = "";
			} else {
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `rooms`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `name` Asc";
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$orders->room->EditValue = $arwrk;
			}

			// order_date
			// request_date

			$orders->request_date->EditCustomAttributes = "";
			$orders->request_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($orders->request_date->CurrentValue, 5));

			// return_date
			$orders->return_date->EditCustomAttributes = "";
			$orders->return_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($orders->return_date->CurrentValue, 5));

			// teacher
			// attachment

			$orders->attachment->EditCustomAttributes = "";
			if (!ew_Empty($orders->attachment->Upload->DbValue)) {
				$orders->attachment->EditValue = $orders->attachment->Upload->DbValue;
			} else {
				$orders->attachment->EditValue = "";
			}

			// Edit refer script
			// lesson

			$orders->lesson->HrefValue = "";

			// title
			$orders->title->HrefValue = "";

			// room
			$orders->room->HrefValue = "";

			// order_date
			$orders->order_date->HrefValue = "";

			// request_date
			$orders->request_date->HrefValue = "";

			// return_date
			$orders->return_date->HrefValue = "";

			// teacher
			$orders->teacher->HrefValue = "";

			// attachment
			if (!ew_Empty($orders->attachment->Upload->DbValue)) {
				$orders->attachment->HrefValue = ew_UploadPathEx(FALSE, $orders->attachment->UploadPath) . ((!empty($orders->attachment->EditValue)) ? $orders->attachment->EditValue : $orders->attachment->CurrentValue);
				if ($orders->Export <> "") $orders->attachment->HrefValue = ew_ConvertFullUrl($orders->attachment->HrefValue);
			} else {
				$orders->attachment->HrefValue = "";
			}
		}

		// Call Row Rendered event
		if ($orders->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$orders->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError, $orders;

		// Initialize form error message
		$gsFormError = "";
		if (!ew_CheckFileType($orders->attachment->Upload->FileName)) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("WrongFileType");
		}
		if ($orders->attachment->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $orders->attachment->Upload->FileSize > EW_MAX_FILE_SIZE) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
		}

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!is_null($orders->lesson->FormValue) && $orders->lesson->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $orders->lesson->FldCaption();
		}
		if (!is_null($orders->title->FormValue) && $orders->title->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $orders->title->FldCaption();
		}
		if (!is_null($orders->request_date->FormValue) && $orders->request_date->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $orders->request_date->FldCaption();
		}
		if (!ew_CheckDate($orders->request_date->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $orders->request_date->FldErrMsg();
		}
		if (!is_null($orders->return_date->FormValue) && $orders->return_date->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $orders->return_date->FldCaption();
		}
		if (!ew_CheckDate($orders->return_date->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $orders->return_date->FldErrMsg();
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $sFormCustomError;
		}
		return $ValidateForm;
	}

	// Update record based on key values
	function EditRow() {
		global $conn, $Security, $Language, $orders;
		$sFilter = $orders->KeyFilter();
		$orders->CurrentFilter = $sFilter;
		$sSql = $orders->SQL();
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE)
			return FALSE;
		if ($rs->EOF) {
			$EditRow = FALSE; // Update Failed
		} else {

			// Save old values
			$rsold =& $rs->fields;
			$rsnew = array();

			// lesson
			$orders->lesson->SetDbValueDef($rsnew, $orders->lesson->CurrentValue, 0, FALSE);

			// title
			$orders->title->SetDbValueDef($rsnew, $orders->title->CurrentValue, "", FALSE);

			// room
			$orders->room->SetDbValueDef($rsnew, $orders->room->CurrentValue, NULL, FALSE);

			// order_date
			$orders->order_date->SetDbValueDef($rsnew, ew_CurrentDate(), ew_CurrentDate());
			$rsnew['order_date'] =& $orders->order_date->DbValue;

			// request_date
			$orders->request_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($orders->request_date->CurrentValue, 5, FALSE), ew_CurrentDate());

			// return_date
			$orders->return_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($orders->return_date->CurrentValue, 5, FALSE), ew_CurrentDate());

			// teacher
			$orders->teacher->SetDbValueDef($rsnew, CurrentUserName(), "");
			$rsnew['teacher'] =& $orders->teacher->DbValue;

			// attachment
			$orders->attachment->Upload->SaveToSession(); // Save file value to Session
						if ($orders->attachment->Upload->Action == "2" || $orders->attachment->Upload->Action == "3") { // Update/Remove
			$orders->attachment->Upload->DbValue = $rs->fields('attachment'); // Get original value
			if (is_null($orders->attachment->Upload->Value)) {
				$rsnew['attachment'] = NULL;
			} else {
				if ($orders->attachment->Upload->FileName == $orders->attachment->Upload->DbValue) { // Upload file name same as old file name
					$rsnew['attachment'] = $orders->attachment->Upload->FileName;
				} else {
					$rsnew['attachment'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $orders->attachment->UploadPath), $orders->attachment->Upload->FileName);
				}
			}
			}

			// Check hash value
			$bRowHasConflict = ($this->GetRsHash($rs) <> $this->HashValue);

			// Call Row Update Conflict event
			if ($bRowHasConflict)
				$bRowHasConflict = $orders->Row_UpdateConflict($rsold, $rsnew);
			if ($bRowHasConflict) {
				$this->setMessage($Language->Phrase("RecordChangedByOtherUser"));
				$orders->UpdateConflict = "U";
				$rs->Close();
				return FALSE; // Update Failed
			}

			// Call Row Updating event
			$bUpdateRow = $orders->Row_Updating($rsold, $rsnew);
			if ($bUpdateRow) {
			if (!ew_Empty($orders->attachment->Upload->Value)) {
				if ($orders->attachment->Upload->FileName == $orders->attachment->Upload->DbValue) { // Overwrite if same file name
					$orders->attachment->Upload->SaveToFile($orders->attachment->UploadPath, $rsnew['attachment'], TRUE);
					$orders->attachment->Upload->DbValue = ""; // No need to delete any more
				} else {
					$orders->attachment->Upload->SaveToFile($orders->attachment->UploadPath, $rsnew['attachment'], FALSE);
				}
			}
			if ($orders->attachment->Upload->Action == "2" || $orders->attachment->Upload->Action == "3") { // Update/Remove
				if ($orders->attachment->Upload->DbValue <> "")
					@unlink(ew_UploadPathEx(TRUE, $orders->attachment->UploadPath) . $orders->attachment->Upload->DbValue);
			}
				$conn->raiseErrorFn = 'ew_ErrorFn';
				$EditRow = $conn->Execute($orders->UpdateSQL($rsnew));
				$conn->raiseErrorFn = '';
			} else {
				if ($orders->CancelMessage <> "") {
					$this->setMessage($orders->CancelMessage);
					$orders->CancelMessage = "";
				} else {
					$this->setMessage($Language->Phrase("UpdateCancelled"));
				}
				$EditRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($EditRow)
			$orders->Row_Updated($rsold, $rsnew);
		if ($EditRow) {
			if ($orders->SendEmail)
				$this->SendEmailOnEdit($rsold, $rsnew);
		}
		$rs->Close();

		// attachment
		$orders->attachment->Upload->RemoveFromSession(); // Remove file value from Session
		return $EditRow;
	}

	// Load row hash
	function LoadRowHash() {
		global $conn, $orders;
		$sFilter = $orders->KeyFilter();

		// Load SQL based on filter
		$orders->CurrentFilter = $sFilter;
		$sSql = $orders->SQL();
		$RsRow = $conn->Execute($sSql);
		$this->HashValue = ($RsRow && !$RsRow->EOF) ? $this->GetRsHash($RsRow) : ""; // Get hash value for record
		$RsRow->Close();
	}

	// Get Rs Hash
	function GetRsHash(&$rs) {
		if (!$rs)
			return "";
		$sHash = "";
		$sHash .= ew_GetRsHash($rs, 'lesson'); // lesson
		$sHash .= ew_GetRsHash($rs, 'title'); // title
		$sHash .= ew_GetRsHash($rs, 'room'); // room
		$sHash .= ew_GetRsHash($rs, 'order_date'); // order_date
		$sHash .= ew_GetRsHash($rs, 'request_date'); // request_date
		$sHash .= ew_GetRsHash($rs, 'return_date'); // return_date
		$sHash .= ew_GetRsHash($rs, 'teacher'); // teacher
		$sHash .= ew_GetRsHash($rs, 'attachment'); // attachment
		return md5($sHash);
	}

	// Add record
	function AddRow() {
		global $conn, $Language, $Security, $orders;

		// Check if valid key values for master user
		if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
			$sFilter = $orders->SqlMasterFilter_lesson();
			if (strval($orders->lesson->CurrentValue) <> "" &&
				$orders->getCurrentMasterTable() == "lesson") {
				$sFilter = str_replace("@id@", ew_AdjustSql($orders->lesson->CurrentValue), $sFilter);
			} else {
				$sFilter = "";
			}
			if ($sFilter <> "") {			
				$rsmaster = $GLOBALS["lesson"]->LoadRs($sFilter);
				$this->bMasterRecordExists = ($rsmaster && !$rsmaster->EOF);
				if (!$this->bMasterRecordExists) {
					$sMasterUserIdMsg = str_replace("%c", CurrentUserID(), $Language->Phrase("UnAuthorizedMasterUserID"));
					$sMasterUserIdMsg = str_replace("%f", $sFilter, $sMasterUserIdMsg);
					$this->setMessage($sMasterUserIdMsg);					
					return FALSE;
				} else {
					$rsmaster->Close();
				}
			}
			$sFilter = $orders->SqlMasterFilter_rooms();
			if (strval($orders->room->CurrentValue) <> "" &&
				$orders->getCurrentMasterTable() == "rooms") {
				$sFilter = str_replace("@id@", ew_AdjustSql($orders->room->CurrentValue), $sFilter);
			} else {
				$sFilter = "";
			}
			if ($sFilter <> "") {			
				$rsmaster = $GLOBALS["rooms"]->LoadRs($sFilter);
				$this->bMasterRecordExists = ($rsmaster && !$rsmaster->EOF);
				if (!$this->bMasterRecordExists) {
					$sMasterUserIdMsg = str_replace("%c", CurrentUserID(), $Language->Phrase("UnAuthorizedMasterUserID"));
					$sMasterUserIdMsg = str_replace("%f", $sFilter, $sMasterUserIdMsg);
					$this->setMessage($sMasterUserIdMsg);					
					return FALSE;
				} else {
					$rsmaster->Close();
				}
			}
			$sFilter = $orders->SqlMasterFilter_useraccounts();
			if (strval($orders->teacher->CurrentValue) <> "" &&
				$orders->getCurrentMasterTable() == "useraccounts") {
				$sFilter = str_replace("@username@", ew_AdjustSql($orders->teacher->CurrentValue), $sFilter);
			} else {
				$sFilter = "";
			}
			if ($sFilter <> "") {			
				$rsmaster = $GLOBALS["useraccounts"]->LoadRs($sFilter);
				$this->bMasterRecordExists = ($rsmaster && !$rsmaster->EOF);
				if (!$this->bMasterRecordExists) {
					$sMasterUserIdMsg = str_replace("%c", CurrentUserID(), $Language->Phrase("UnAuthorizedMasterUserID"));
					$sMasterUserIdMsg = str_replace("%f", $sFilter, $sMasterUserIdMsg);
					$this->setMessage($sMasterUserIdMsg);					
					return FALSE;
				} else {
					$rsmaster->Close();
				}
			}
		}
		$rsnew = array();

		// lesson
		$orders->lesson->SetDbValueDef($rsnew, $orders->lesson->CurrentValue, 0, FALSE);

		// title
		$orders->title->SetDbValueDef($rsnew, $orders->title->CurrentValue, "", FALSE);

		// room
		$orders->room->SetDbValueDef($rsnew, $orders->room->CurrentValue, NULL, FALSE);

		// order_date
		$orders->order_date->SetDbValueDef($rsnew, ew_CurrentDate(), ew_CurrentDate());
		$rsnew['order_date'] =& $orders->order_date->DbValue;

		// request_date
		$orders->request_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($orders->request_date->CurrentValue, 5, FALSE), ew_CurrentDate());

		// return_date
		$orders->return_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($orders->return_date->CurrentValue, 5, FALSE), ew_CurrentDate());

		// teacher
		$orders->teacher->SetDbValueDef($rsnew, CurrentUserName(), "");
		$rsnew['teacher'] =& $orders->teacher->DbValue;

		// attachment
		$orders->attachment->Upload->SaveToSession(); // Save file value to Session
		if (is_null($orders->attachment->Upload->Value)) {
			$rsnew['attachment'] = NULL;
		} else {
			$rsnew['attachment'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $orders->attachment->UploadPath), $orders->attachment->Upload->FileName);
		}

		// Call Row Inserting event
		$bInsertRow = $orders->Row_Inserting($rsnew);
		if ($bInsertRow) {
			if (!ew_Empty($orders->attachment->Upload->Value)) {
				if ($orders->attachment->Upload->FileName == $orders->attachment->Upload->DbValue) { // Overwrite if same file name
					$orders->attachment->Upload->SaveToFile($orders->attachment->UploadPath, $rsnew['attachment'], TRUE);
					$orders->attachment->Upload->DbValue = ""; // No need to delete any more
				} else {
					$orders->attachment->Upload->SaveToFile($orders->attachment->UploadPath, $rsnew['attachment'], FALSE);
				}
			}
			if ($orders->attachment->Upload->Action == "2" || $orders->attachment->Upload->Action == "3") { // Update/Remove
				if ($orders->attachment->Upload->DbValue <> "")
					@unlink(ew_UploadPathEx(TRUE, $orders->attachment->UploadPath) . $orders->attachment->Upload->DbValue);
			}
			$conn->raiseErrorFn = 'ew_ErrorFn';
			$AddRow = $conn->Execute($orders->InsertSQL($rsnew));
			$conn->raiseErrorFn = '';
		} else {
			if ($orders->CancelMessage <> "") {
				$this->setMessage($orders->CancelMessage);
				$orders->CancelMessage = "";
			} else {
				$this->setMessage($Language->Phrase("InsertCancelled"));
			}
			$AddRow = FALSE;
		}
		if ($AddRow) {
			$orders->id->setDbValue($conn->Insert_ID());
			$rsnew['id'] = $orders->id->DbValue;

			// Call Row Inserted event
			$orders->Row_Inserted($rsnew);
			if ($orders->SendEmail)
				$this->SendEmailOnAdd($rsnew);
		}

		// attachment
		$orders->attachment->Upload->RemoveFromSession(); // Remove file value from Session
		return $AddRow;
	}

	// Export data in HTML/CSV/Word/Excel/XML/Email format
	function ExportData() {
		global $orders;
		$utf8 = TRUE;
		$bSelectLimit = EW_SELECT_LIMIT;

		// Load recordset
		if ($bSelectLimit) {
			$this->lTotalRecs = $orders->SelectRecordCount();
		} else {
			if ($rs = $this->LoadRecordset())
				$this->lTotalRecs = $rs->RecordCount();
		}
		$this->lStartRec = 1;

		// Export all
		if ($orders->ExportAll) {
			$this->lDisplayRecs = $this->lTotalRecs;
			$this->lStopRec = $this->lTotalRecs;
		} else { // Export one page only
			$this->SetUpStartRec(); // Set up start record position

			// Set the last record to display
			if ($this->lDisplayRecs < 0) {
				$this->lStopRec = $this->lTotalRecs;
			} else {
				$this->lStopRec = $this->lStartRec + $this->lDisplayRecs - 1;
			}
		}
		if ($bSelectLimit)
			$rs = $this->LoadRecordset($this->lStartRec-1, $this->lDisplayRecs);
		if (!$rs) {
			header("Content-Type:"); // Remove header
			header("Content-Disposition:");
			$this->ShowMessage();
			return;
		}
		if ($orders->Export == "xml") {
			$XmlDoc = new cXMLDocument(EW_XML_ENCODING);
			$XmlDoc->AddRoot();
		} else {
			$ExportDoc = new cExportDocument($orders, "h");
			$ExportDoc->ExportHeader();
			if ($ExportDoc->Horizontal) { // Horizontal format, write header
				$ExportDoc->BeginExportRow();
				$ExportDoc->ExportCaption($orders->id);
				$ExportDoc->ExportCaption($orders->lesson);
				$ExportDoc->ExportCaption($orders->title);
				$ExportDoc->ExportCaption($orders->room);
				$ExportDoc->ExportCaption($orders->order_date);
				$ExportDoc->ExportCaption($orders->request_date);
				$ExportDoc->ExportCaption($orders->return_date);
				$ExportDoc->ExportCaption($orders->teacher);
				$ExportDoc->ExportCaption($orders->attachment);
				$ExportDoc->EndExportRow();
			}
		}

		// Move to first record
		$this->lRecCnt = $this->lStartRec - 1;
		if (!$rs->EOF) {
			$rs->MoveFirst();
			if (!$bSelectLimit && $this->lStartRec > 1)
				$rs->Move($this->lStartRec - 1);
		}
		while (!$rs->EOF && $this->lRecCnt < $this->lStopRec) {
			$this->lRecCnt++;
			if (intval($this->lRecCnt) >= intval($this->lStartRec)) {
				$this->LoadRowValues($rs);

				// Render row
				$orders->CssClass = "";
				$orders->CssStyle = "";
				$orders->RowType = EW_ROWTYPE_VIEW; // Render view
				$this->RenderRow();
				if ($orders->Export == "xml") {
					$XmlDoc->AddRow();
					$XmlDoc->AddField('id', $orders->id->ExportValue($orders->Export, $orders->ExportOriginalValue));
					$XmlDoc->AddField('lesson', $orders->lesson->ExportValue($orders->Export, $orders->ExportOriginalValue));
					$XmlDoc->AddField('title', $orders->title->ExportValue($orders->Export, $orders->ExportOriginalValue));
					$XmlDoc->AddField('room', $orders->room->ExportValue($orders->Export, $orders->ExportOriginalValue));
					$XmlDoc->AddField('order_date', $orders->order_date->ExportValue($orders->Export, $orders->ExportOriginalValue));
					$XmlDoc->AddField('request_date', $orders->request_date->ExportValue($orders->Export, $orders->ExportOriginalValue));
					$XmlDoc->AddField('return_date', $orders->return_date->ExportValue($orders->Export, $orders->ExportOriginalValue));
					$XmlDoc->AddField('teacher', $orders->teacher->ExportValue($orders->Export, $orders->ExportOriginalValue));
					$XmlDoc->AddField('attachment', $orders->attachment->ExportValue($orders->Export, $orders->ExportOriginalValue));
				} else {
					$ExportDoc->BeginExportRow(TRUE); // Allow CSS styles if enabled
					$ExportDoc->ExportField($orders->id);
					$ExportDoc->ExportField($orders->lesson);
					$ExportDoc->ExportField($orders->title);
					$ExportDoc->ExportField($orders->room);
					$ExportDoc->ExportField($orders->order_date);
					$ExportDoc->ExportField($orders->request_date);
					$ExportDoc->ExportField($orders->return_date);
					$ExportDoc->ExportField($orders->teacher);
					$ExportDoc->ExportField($orders->attachment);
					$ExportDoc->EndExportRow();
				}
			}
			$rs->MoveNext();
		}
		if ($orders->Export <> "xml")
			$ExportDoc->ExportFooter();

		// Close recordset
		$rs->Close();

		// Clean output buffer
		if (!EW_DEBUG_ENABLED && ob_get_length())
			ob_end_clean();

		// Write BOM if utf-8
		if ($utf8 && !in_array($orders->Export, array("email", "xml")))
			echo "\xEF\xBB\xBF";

		// Write debug message if enabled
		if (EW_DEBUG_ENABLED)
			echo ew_DebugMsg();

		// Output data
		if ($orders->Export == "xml") {
			header("Content-Type: text/xml");
			echo $XmlDoc->XML();
		} elseif ($orders->Export == "email") {
			$this->ExportEmail($ExportDoc->Text);
			$this->Page_Terminate($orders->ExportReturnUrl());
		} else {
			echo $ExportDoc->Text;
		}
	}

	// Export email
	function ExportEmail($EmailContent) {
		global $Language, $orders;
		$sSender = @$_GET["sender"];
		$sRecipient = @$_GET["recipient"];
		$sCc = @$_GET["cc"];
		$sBcc = @$_GET["bcc"];
		$sContentType = @$_GET["contenttype"];

		// Subject
		$sSubject = ew_StripSlashes(@$_GET["subject"]);
		$sEmailSubject = $sSubject;

		// Message
		$sContent = ew_StripSlashes(@$_GET["message"]);
		$sEmailMessage = $sContent;

		// Check sender
		if ($sSender == "") {
			$this->setMessage($Language->Phrase("EnterSenderEmail"));
			return;
		}
		if (!ew_CheckEmail($sSender)) {
			$this->setMessage($Language->Phrase("EnterProperSenderEmail"));
			return;
		}

		// Check recipient
		if (!ew_CheckEmailList($sRecipient, EW_MAX_EMAIL_RECIPIENT)) {
			$this->setMessage($Language->Phrase("EnterProperRecipientEmail"));
			return;
		}

		// Check cc
		if (!ew_CheckEmailList($sCc, EW_MAX_EMAIL_RECIPIENT)) {
			$this->setMessage($Language->Phrase("EnterProperCcEmail"));
			return;
		}

		// Check bcc
		if (!ew_CheckEmailList($sBcc, EW_MAX_EMAIL_RECIPIENT)) {
			$this->setMessage($Language->Phrase("EnterProperBccEmail"));
			return;
		}

		// Check email sent count
		if (!isset($_SESSION[EW_EXPORT_EMAIL_COUNTER]))
			$_SESSION[EW_EXPORT_EMAIL_COUNTER] = 0;
		if (intval($_SESSION[EW_EXPORT_EMAIL_COUNTER]) > EW_MAX_EMAIL_SENT_COUNT) {
			$this->setMessage($Language->Phrase("ExceedMaxEmailExport"));
			return;
		}
		if ($sEmailMessage <> "") {
			$sEmailMessage = ew_RemoveXSS($sEmailMessage);
			$sEmailMessage .= ($sContentType == "url") ? "\r\n\r\n" : "<br><br>";
		}
		if ($sContentType == "url") {
			$sUrl = ew_ConvertFullUrl(ew_CurrentPage() . "?" . $this->ExportQueryString());
			$sEmailMessage .= $sUrl; // send URL only
		} else {
			$sEmailMessage .= $EmailContent; // send HTML
		}

		// Send email
		$Email = new cEmail();
		$Email->Sender = $sSender; // Sender
		$Email->Recipient = $sRecipient; // Recipient
		$Email->Cc = $sCc; // Cc
		$Email->Bcc = $sBcc; // Bcc
		$Email->Subject = $sEmailSubject; // Subject
		$Email->Content = $sEmailMessage; // Content
		$Email->Format = ($sContentType == "url") ? "text" : "html";
		$Email->Charset = EW_EMAIL_CHARSET;
		$EventArgs = array();
		$bEmailSent = FALSE;
		if ($orders->Email_Sending($Email, $EventArgs))
			$bEmailSent = $Email->Send();

		// Check email sent status
		if ($bEmailSent) {

			// Update email sent count
			$_SESSION[EW_EXPORT_EMAIL_COUNTER]++;

			// Sent email success
			$this->setMessage($Language->Phrase("SendEmailSuccess"));
		} else {

			// Sent email failure
			$this->setMessage($Email->SendErrDescription);
		}
	}

	// Export QueryString
	function ExportQueryString() {
		global $orders;

		// Initialize
		$sQry = "export=html";

		// Build QueryString for search
		if ($orders->getSessionBasicSearchKeyword() <> "") {
			$sQry .= "&" . EW_TABLE_BASIC_SEARCH . "=" . $orders->getSessionBasicSearchKeyword() . "&" . EW_TABLE_BASIC_SEARCH_TYPE . "=" . $orders->getSessionBasicSearchType();
		}

		// Build QueryString for pager
		$sQry .= "&" . EW_TABLE_REC_PER_PAGE . "=" . $orders->getRecordsPerPage() . "&" . EW_TABLE_START_REC . "=" . $orders->getStartRecordNumber();
		return $sQry;
	}

	// Add search QueryString
	function AddSearchQueryString(&$Qry, &$Fld) {
		global $orders;
		$FldParm = substr($Fld->FldVar, 2);
		$FldSearchValue = $orders->GetAdvancedSearch("x_" . $FldParm);
		if (strval($FldSearchValue) <> "") {
			$Qry .= "&x_" . $FldParm . "=" . FldSearchValue .
				"&z_" . $FldParm . "=" . $orders->GetAdvancedSearch("z_" . $FldParm);
		}
		$FldSearchValue2 = $orders->GetAdvancedSearch("y_" . $FldParm);
		if (strval($FldSearchValue2) <> "") {
			$Qry .= "&v_" . $FldParm . "=" . $orders->GetAdvancedSearch("v_" . $FldParm) .
				"&y_" . $FldParm . "=" . $FldSearchValue2 .
				"&w_" . $FldParm . "=" . $orders->GetAdvancedSearch("w_" . $FldParm);
		}
	}

	// Show link optionally based on User ID
	function ShowOptionLink() {
		global $Security, $orders;
		if ($Security->IsLoggedIn()) {
			if (!$Security->IsAdmin()) {
				return $Security->IsValidUserID($orders->teacher->CurrentValue);
			}
		}
		return TRUE;
	}

	// Set up master/detail based on QueryString
	function SetUpMasterDetail() {
		global $orders;
		$bValidMaster = FALSE;

		// Get the keys for master table
		if (@$_GET[EW_TABLE_SHOW_MASTER] <> "") {
			$sMasterTblVar = $_GET[EW_TABLE_SHOW_MASTER];
			if ($sMasterTblVar == "") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = "";
				$this->sDbDetailFilter = "";
			}
			if ($sMasterTblVar == "lesson") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $orders->SqlMasterFilter_lesson();
				$this->sDbDetailFilter = $orders->SqlDetailFilter_lesson();
				if (@$_GET["id"] <> "") {
					$GLOBALS["lesson"]->id->setQueryStringValue($_GET["id"]);
					$orders->lesson->setQueryStringValue($GLOBALS["lesson"]->id->QueryStringValue);
					$orders->lesson->setSessionValue($orders->lesson->QueryStringValue);
					if (!is_numeric($GLOBALS["lesson"]->id->QueryStringValue)) $bValidMaster = FALSE;
					$this->sDbMasterFilter = str_replace("@id@", ew_AdjustSql($GLOBALS["lesson"]->id->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@lesson@", ew_AdjustSql($GLOBALS["lesson"]->id->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
			if ($sMasterTblVar == "rooms") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $orders->SqlMasterFilter_rooms();
				$this->sDbDetailFilter = $orders->SqlDetailFilter_rooms();
				if (@$_GET["id"] <> "") {
					$GLOBALS["rooms"]->id->setQueryStringValue($_GET["id"]);
					$orders->room->setQueryStringValue($GLOBALS["rooms"]->id->QueryStringValue);
					$orders->room->setSessionValue($orders->room->QueryStringValue);
					$this->sDbMasterFilter = str_replace("@id@", ew_AdjustSql($GLOBALS["rooms"]->id->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@room@", ew_AdjustSql($GLOBALS["rooms"]->id->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
			if ($sMasterTblVar == "useraccounts") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $orders->SqlMasterFilter_useraccounts();
				$this->sDbDetailFilter = $orders->SqlDetailFilter_useraccounts();
				if (@$_GET["username"] <> "") {
					$GLOBALS["useraccounts"]->username->setQueryStringValue($_GET["username"]);
					$orders->teacher->setQueryStringValue($GLOBALS["useraccounts"]->username->QueryStringValue);
					$orders->teacher->setSessionValue($orders->teacher->QueryStringValue);
					$this->sDbMasterFilter = str_replace("@username@", ew_AdjustSql($GLOBALS["useraccounts"]->username->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@teacher@", ew_AdjustSql($GLOBALS["useraccounts"]->username->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
		}
		if ($bValidMaster) {

			// Save current master table
			$orders->setCurrentMasterTable($sMasterTblVar);

			// Reset start record counter (new master key)
			$this->lStartRec = 1;
			$orders->setStartRecordNumber($this->lStartRec);
			$orders->setMasterFilter($this->sDbMasterFilter); // Set up master filter
			$orders->setDetailFilter($this->sDbDetailFilter); // Set up detail filter

			// Clear previous master key from Session
			if ($sMasterTblVar <> "lesson") {
				if ($orders->lesson->QueryStringValue == "") $orders->lesson->setSessionValue("");
			}
			if ($sMasterTblVar <> "rooms") {
				if ($orders->room->QueryStringValue == "") $orders->room->setSessionValue("");
			}
			if ($sMasterTblVar <> "useraccounts") {
				if ($orders->teacher->QueryStringValue == "") $orders->teacher->setSessionValue("");
			}
		} else {
			$this->sDbMasterFilter = $orders->getMasterFilter(); //  Restore master filter
			$this->sDbDetailFilter = $orders->getDetailFilter(); // Restore detail filter
		}
	}

	// Send email after add success
	function SendEmailOnAdd(&$rs) {
		global $Language, $orders;
		$sFn = "txt/notify.txt";
		$sTable = 'orders';
		$sSubject = $sTable . " " . $Language->Phrase("RecordInserted");
		$sAction = $Language->Phrase("ActionInserted");

		// Get key value
		$sKey = "";
		if ($sKey <> "") $sKey .= EW_COMPOSITE_KEY_SEPARATOR;
		$sKey .= $rs['id'];
		$Email = new cEmail();
		$Email->Load($sFn);
		$Email->ReplaceSender(EW_SENDER_EMAIL); // Replace Sender
		$Email->ReplaceRecipient(EW_RECIPIENT_EMAIL); // Replace Recipient
		$Email->ReplaceSubject($sSubject); // Replace Subject
		$Email->ReplaceContent("<!--table-->", $sTable);
		$Email->ReplaceContent("<!--key-->", $sKey);
		$Email->ReplaceContent("<!--action-->", $sAction);
		$Email->Charset = EW_EMAIL_CHARSET;
		$Args = array("rs" => $rs);
		$bEmailSent = FALSE;
		if ($orders->Email_Sending($Email, $Args))
			$bEmailSent = $Email->Send();

		// Send email failed
		if (!$bEmailSent)
			$this->setMessage($Email->SendErrDescription);
	}

	// Send email after update success
	function SendEmailOnEdit(&$rsold, &$rsnew) {
		global $Language, $orders;
		$sFn = "txt/notify.txt";
		$sTable = 'orders';
		$sSubject = $sTable . " ". $Language->Phrase("RecordUpdated");
		$sAction = $Language->Phrase("ActionUpdated");

		// Get key value
		$sKey = "";
		if ($sKey <> "") $sKey .= EW_COMPOSITE_KEY_SEPARATOR;
		$sKey .= $rsold['id'];
		$Email = new cEmail();
		$Email->Load($sFn);
		$Email->ReplaceSender(EW_SENDER_EMAIL); // Replace Sender
		$Email->ReplaceRecipient(EW_RECIPIENT_EMAIL); // Replace Recipient
		$Email->ReplaceSubject($sSubject); // Replace Subject
		$Email->ReplaceContent("<!--table-->", $sTable);
		$Email->ReplaceContent("<!--key-->", $sKey);
		$Email->ReplaceContent("<!--action-->", $sAction);
		$Email->Charset = EW_EMAIL_CHARSET;
		$Args = array();
		$Args["rsold"] =& $rsold;
		$Args["rsnew"] =& $rsnew;
		$bEmailSent = FALSE;
		if ($orders->Email_Sending($Email, $Args))
			$bEmailSent = $Email->Send();

		// Send email failed
		if (!$bEmailSent)
			$this->setMessage($Email->SendErrDescription);
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	function Message_Showing(&$msg) {

		// Example:
		//$msg = "your new message";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}

	// ListOptions Load event
	function ListOptions_Load() {

		// Example: 
		//$this->ListOptions->Add("new");
		//$this->ListOptions->Items["new"]->OnLeft = TRUE; // Link on left
		//$this->ListOptions->MoveItem("new", 0); // Move to first column

	}

	// ListOptions Rendered event
	function ListOptions_Rendered() {

		// Example: 
		//$this->ListOptions->Items["new"]->Body = "xxx";

	}
}
?>
Return current item: Science Lab Inventory & Order Management