Location: PHPKode > projects > Science Lab Inventory & Order Management > sciencelabinv/ordersview.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_view = new corders_view();
$Page =& $orders_view;

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

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

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

// page properties
orders_view.PageID = "view"; // page ID
orders_view.FormID = "fordersview"; // form ID
var EW_PAGE_ID = orders_view.PageID; // for backward compatibility

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

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

// multi page properties
orders_view.MultiPage = new ew_MultiPage();
orders_view.MultiPage.AddElement("x_id", 1);
orders_view.MultiPage.AddElement("x_lesson", 1);
orders_view.MultiPage.AddElement("x_title", 1);
orders_view.MultiPage.AddElement("x_room", 1);
orders_view.MultiPage.AddElement("x_request_date", 1);
orders_view.MultiPage.AddElement("x_return_date", 1);
orders_view.MultiPage.AddElement("x_attachment", 2);
orders_view.MultiPage.AddElement("x_note", 2);

//-->
</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 } ?>
<p><span class="phpmaker"><?php echo $Language->Phrase("View") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $orders->TableCaption() ?>
<br><br>
<?php if ($orders->Export == "") { ?>
<a href="<?php echo $orders_view->ListUrl ?>"><?php echo $Language->Phrase("BackToList") ?></a>&nbsp;
<?php if ($Security->CanAdd()) { ?>
<?php if ($orders_view->ShowOptionLink()) { ?>
<a href="<?php echo $orders_view->AddUrl ?>"><?php echo $Language->Phrase("ViewPageAddLink") ?></a>&nbsp;
<?php } ?>
<?php } ?>
<?php if ($Security->CanEdit()) { ?>
<?php if ($orders_view->ShowOptionLink()) { ?>
<a href="<?php echo $orders_view->EditUrl ?>"><?php echo $Language->Phrase("ViewPageEditLink") ?></a>&nbsp;
<?php } ?>
<?php } ?>
<?php if ($Security->CanAdd()) { ?>
<?php if ($orders_view->ShowOptionLink()) { ?>
<a href="<?php echo $orders_view->CopyUrl ?>"><?php echo $Language->Phrase("ViewPageCopyLink") ?></a>&nbsp;
<?php } ?>
<?php } ?>
<?php if ($Security->CanDelete()) { ?>
<?php if ($orders_view->ShowOptionLink()) { ?>
<a href="<?php echo $orders_view->DeleteUrl ?>"><?php echo $Language->Phrase("ViewPageDeleteLink") ?></a>&nbsp;
<?php } ?>
<?php } ?>
<?php if ($Security->AllowList('order_detail')) { ?>
<?php if ($orders_view->ShowOptionLink()) { ?>
<a href="order_detaillist.php?<?php echo EW_TABLE_SHOW_MASTER ?>=orders&id=<?php echo urlencode(strval($orders->id->CurrentValue)) ?>"><?php echo $Language->Phrase("ViewPageDetailLink") ?><?php echo $Language->TablePhrase("order_detail", "TblCaption") ?>
<?php echo str_replace("%c", $orders_view->lorder_detail_Count, $Language->Phrase("DetailCount")) ?>
</a>
&nbsp;
<?php } ?>
<?php } ?>
<?php } ?>
</span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$orders_view->ShowMessage();
?>
<p>
<?php if ($orders->Export == "") { ?>
<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_view->Pager)) $orders_view->Pager = new cPrevNextPager($orders_view->lStartRec, $orders_view->lDisplayRecs, $orders_view->lTotalRecs) ?>
<?php if ($orders_view->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_view->Pager->FirstButton->Enabled) { ?>
	<td><a href="<?php echo $orders_view->PageUrl() ?>start=<?php echo $orders_view->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_view->Pager->PrevButton->Enabled) { ?>
	<td><a href="<?php echo $orders_view->PageUrl() ?>start=<?php echo $orders_view->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_view->Pager->CurrentPage ?>" size="4"></td>
<!--next page button-->
	<?php if ($orders_view->Pager->NextButton->Enabled) { ?>
	<td><a href="<?php echo $orders_view->PageUrl() ?>start=<?php echo $orders_view->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_view->Pager->LastButton->Enabled) { ?>
	<td><a href="<?php echo $orders_view->PageUrl() ?>start=<?php echo $orders_view->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_view->Pager->PageCount ?></span></td>
	</tr></table>
<?php } else { ?>
	<?php if ($Security->CanList()) { ?>
	<?php if ($orders_view->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>
	</tr>
</table>
</form>
<br>
<?php } ?>
<?php if ($orders->Export == "") { ?>
<table cellspacing="0" cellpadding="0"><tr><td>
<div id="orders_view" class="yui-navset">
	<ul class="yui-nav">
		<li class="selected"><a href="#tab_orders_1"><em><?php echo $orders->PageCaption(1) ?></em></a></li>
		<li><a href="#tab_orders_2"><em><?php echo $orders->PageCaption(2) ?></em></a></li>
	</ul>            
	<div class="yui-content">
<?php } ?>
		<div id="tab_orders_1">
<table cellspacing="0" class="ewGrid" style="width: 100%"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($orders->id->Visible) { // id ?>
	<tr<?php echo $orders->id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->id->FldCaption() ?></td>
		<td<?php echo $orders->id->CellAttributes() ?>>
<div<?php echo $orders->id->ViewAttributes() ?>><?php echo $orders->id->ViewValue ?></div></td>
	</tr>
<?php } ?>
<?php if ($orders->lesson->Visible) { // lesson ?>
	<tr<?php echo $orders->lesson->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->lesson->FldCaption() ?></td>
		<td<?php echo $orders->lesson->CellAttributes() ?>>
<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_lesson');" onmouseout="ew_HideTooltip();"><?php echo $orders->lesson->ViewValue ?></a>
<?php } else { ?>
<?php echo $orders->lesson->ViewValue ?>
<?php } ?>
</div><div id="tt_orders_x_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></td>
	</tr>
<?php } ?>
<?php if ($orders->title->Visible) { // title ?>
	<tr<?php echo $orders->title->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->title->FldCaption() ?></td>
		<td<?php echo $orders->title->CellAttributes() ?>>
<div<?php echo $orders->title->ViewAttributes() ?>><?php echo $orders->title->ViewValue ?></div></td>
	</tr>
<?php } ?>
<?php if ($orders->room->Visible) { // room ?>
	<tr<?php echo $orders->room->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->room->FldCaption() ?></td>
		<td<?php echo $orders->room->CellAttributes() ?>>
<div<?php echo $orders->room->ViewAttributes() ?>><?php echo $orders->room->ViewValue ?></div></td>
	</tr>
<?php } ?>
<?php if ($orders->order_date->Visible) { // order_date ?>
	<tr<?php echo $orders->order_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->order_date->FldCaption() ?></td>
		<td<?php echo $orders->order_date->CellAttributes() ?>>
<div<?php echo $orders->order_date->ViewAttributes() ?>><?php echo $orders->order_date->ViewValue ?></div></td>
	</tr>
<?php } ?>
<?php if ($orders->request_date->Visible) { // request_date ?>
	<tr<?php echo $orders->request_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->request_date->FldCaption() ?></td>
		<td<?php echo $orders->request_date->CellAttributes() ?>>
<div<?php echo $orders->request_date->ViewAttributes() ?>><?php echo $orders->request_date->ViewValue ?></div></td>
	</tr>
<?php } ?>
<?php if ($orders->return_date->Visible) { // return_date ?>
	<tr<?php echo $orders->return_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->return_date->FldCaption() ?></td>
		<td<?php echo $orders->return_date->CellAttributes() ?>>
<div<?php echo $orders->return_date->ViewAttributes() ?>><?php echo $orders->return_date->ViewValue ?></div></td>
	</tr>
<?php } ?>
<?php if ($orders->teacher->Visible) { // teacher ?>
	<tr<?php echo $orders->teacher->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->teacher->FldCaption() ?></td>
		<td<?php echo $orders->teacher->CellAttributes() ?>>
<div<?php echo $orders->teacher->ViewAttributes() ?>><?php echo $orders->teacher->ViewValue ?></div></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
		</div>
		<div id="tab_orders_2">
<table cellspacing="0" class="ewGrid" style="width: 100%"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($orders->attachment->Visible) { // attachment ?>
	<tr<?php echo $orders->attachment->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->attachment->FldCaption() ?></td>
		<td<?php echo $orders->attachment->CellAttributes() ?>>
<?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->ViewValue ?></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->ViewValue ?>
<?php } elseif (!in_array($orders->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
</td>
	</tr>
<?php } ?>
<?php if ($orders->note->Visible) { // note ?>
	<tr<?php echo $orders->note->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $orders->note->FldCaption() ?></td>
		<td<?php echo $orders->note->CellAttributes() ?>>
<div<?php echo $orders->note->ViewAttributes() ?>><?php echo $orders->note->ViewValue ?></div></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
		</div>
<?php if ($orders->Export == "") { ?>
	</div>
</div>
</td></tr></table>
<?php } ?>
<?php if ($orders->Export == "") { ?>
<script type="text/javascript">
<!--
ew_TabView(orders_view);

//-->
</script>
<?php } ?>
<?php if ($orders->Export == "") { ?>
<br>
<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_view->Pager)) $orders_view->Pager = new cPrevNextPager($orders_view->lStartRec, $orders_view->lDisplayRecs, $orders_view->lTotalRecs) ?>
<?php if ($orders_view->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_view->Pager->FirstButton->Enabled) { ?>
	<td><a href="<?php echo $orders_view->PageUrl() ?>start=<?php echo $orders_view->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_view->Pager->PrevButton->Enabled) { ?>
	<td><a href="<?php echo $orders_view->PageUrl() ?>start=<?php echo $orders_view->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_view->Pager->CurrentPage ?>" size="4"></td>
<!--next page button-->
	<?php if ($orders_view->Pager->NextButton->Enabled) { ?>
	<td><a href="<?php echo $orders_view->PageUrl() ?>start=<?php echo $orders_view->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_view->Pager->LastButton->Enabled) { ?>
	<td><a href="<?php echo $orders_view->PageUrl() ?>start=<?php echo $orders_view->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_view->Pager->PageCount ?></span></td>
	</tr></table>
<?php } else { ?>
	<?php if ($Security->CanList()) { ?>
	<?php if ($orders_view->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>
	</tr>
</table>
</form>
<?php } ?>
<p>
<?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_view->Page_Terminate();
?>
<?php

//
// Page class
//
class corders_view {

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

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

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

	// 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_view() {
		global $conn, $Language;

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

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

		// 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", 'view', 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();
	}

	// 
	//  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->CanView()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("orderslist.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("orderslist.php");
		}

		// 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();
	}
	var $lDisplayRecs = 1;
	var $lStartRec;
	var $lStopRec;
	var $lTotalRecs = 0;
	var $lRecRange = 10;
	var $lRecCnt;
	var $arRecKey = array();
	var $lorder_detail_Count;

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

		// Load current record
		$bLoadCurrentRecord = FALSE;
		$sReturnUrl = "";
		$bMatchRecord = FALSE;
		if ($this->IsPageRequest()) { // Validate request
			if (@$_GET["id"] <> "") {
				$orders->id->setQueryStringValue($_GET["id"]);
				$this->arRecKey["id"] = $orders->id->QueryStringValue;
			} else {
				$bLoadCurrentRecord = TRUE;
			}

			// Get action
			$orders->CurrentAction = "I"; // Display form
			switch ($orders->CurrentAction) {
				case "I": // Get a record to display
					$this->lStartRec = 1; // Initialize start position
					if ($rs = $this->LoadRecordset()) // Load records
						$this->lTotalRecs = $rs->RecordCount(); // Get record count
					if ($this->lTotalRecs <= 0) { // No record found
						$this->setMessage($Language->Phrase("NoRecord")); // Set no record message
						$this->Page_Terminate("orderslist.php"); // Return to list page
					} elseif ($bLoadCurrentRecord) { // Load current record position
						$this->SetUpStartRec(); // Set up start record position

						// Point to current record
						if (intval($this->lStartRec) <= intval($this->lTotalRecs)) {
							$bMatchRecord = TRUE;
							$rs->Move($this->lStartRec-1);
						}
					} else { // Match key values
						while (!$rs->EOF) {
							if (strval($orders->id->CurrentValue) == strval($rs->fields('id'))) {
								$orders->setStartRecordNumber($this->lStartRec); // Save record position
								$bMatchRecord = TRUE;
								break;
							} else {
								$this->lStartRec++;
								$rs->MoveNext();
							}
						}
					}
					if (!$bMatchRecord) {
						$this->setMessage($Language->Phrase("NoRecord")); // Set no record message
						$sReturnUrl = "orderslist.php"; // No matching record, return to list
					} else {
						$this->LoadRowValues($rs); // Load row values
					}
			}
		} else {
			$sReturnUrl = "orderslist.php"; // Not page request, return to list
		}
		if ($sReturnUrl <> "")
			$this->Page_Terminate($sReturnUrl);

		// Render row
		$orders->RowType = EW_ROWTYPE_VIEW;
		$this->RenderRow();
	}

	// 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);
		}
	}

	// 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

			// 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->ExportPrintUrl = $this->PageUrl() . "export=print&" . "id=" . urlencode($orders->id->CurrentValue);
		$this->ExportHtmlUrl = $this->PageUrl() . "export=html&" . "id=" . urlencode($orders->id->CurrentValue);
		$this->ExportExcelUrl = $this->PageUrl() . "export=excel&" . "id=" . urlencode($orders->id->CurrentValue);
		$this->ExportWordUrl = $this->PageUrl() . "export=word&" . "id=" . urlencode($orders->id->CurrentValue);
		$this->ExportXmlUrl = $this->PageUrl() . "export=xml&" . "id=" . urlencode($orders->id->CurrentValue);
		$this->ExportCsvUrl = $this->PageUrl() . "export=csv&" . "id=" . urlencode($orders->id->CurrentValue);
		$this->AddUrl = $orders->AddUrl();
		$this->EditUrl = $orders->EditUrl();
		$this->CopyUrl = $orders->CopyUrl();
		$this->DeleteUrl = $orders->DeleteUrl();
		$this->ListUrl = $orders->ListUrl();

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

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

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

		// 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();

		// note
		$orders->note->CellCssStyle = ""; $orders->note->CellCssClass = "";
		$orders->note->CellAttrs = array(); $orders->note->ViewAttrs = array(); $orders->note->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 = "";

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

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

			// 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 = "";

			// note
			$orders->note->HrefValue = "";
			$orders->note->TooltipValue = "";
		}

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

	// 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;
	}

	// 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";

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