Location: PHPKode > projects > Science Lab Inventory & Order Management > sciencelabinv/order_detailedit.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 "order_detailinfo.php" ?>
<?php include "ordersinfo.php" ?>
<?php include "itemsinfo.php" ?>
<?php include "unitinfo.php" ?>
<?php include "useraccountsinfo.php" ?>
<?php include "userfn7.php" ?>
<?php

// Create page object
$order_detail_edit = new corder_detail_edit();
$Page =& $order_detail_edit;

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

// Page main
$order_detail_edit->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--

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

// page properties
order_detail_edit.PageID = "edit"; // page ID
order_detail_edit.FormID = "forder_detailedit"; // form ID
var EW_PAGE_ID = order_detail_edit.PageID; // for backward compatibility

// extend page with ValidateForm function
order_detail_edit.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;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_order_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($order_detail->order_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_item_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($order_detail->item_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_quantity"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($order_detail->quantity->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_quantity"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($order_detail->quantity->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_unit"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($order_detail->unit->FldCaption()) ?>");

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}
	return true;
}

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

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

// multi page properties
order_detail_edit.MultiPage = new ew_MultiPage();
order_detail_edit.MultiPage.AddElement("x_id", 1);
order_detail_edit.MultiPage.AddElement("x_order_id", 1);
order_detail_edit.MultiPage.AddElement("x_item_id", 1);
order_detail_edit.MultiPage.AddElement("x_quantity", 1);
order_detail_edit.MultiPage.AddElement("x_unit", 1);
order_detail_edit.MultiPage.AddElement("x_concentration", 1);
order_detail_edit.MultiPage.AddElement("x_note", 2);

//-->
</script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
<!--
_width_multiplier = 20;
_height_multiplier = 60;
var ew_DHTMLEditors = [];

// update value from editor to textarea
function ew_UpdateTextArea() {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {			
		var inst;			
		for (inst in CKEDITOR.instances)
			CKEDITOR.instances[inst].updateElement();
	}
}

// update value from textarea to editor
function ew_UpdateDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];		
		if (inst)
			inst.setData(inst.element.value);
	}
}

// focus editor
function ew_FocusDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];	
		if (inst)
			inst.focus();
	}
}

//-->
</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>
<p><span class="phpmaker"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $order_detail->TableCaption() ?><br><br>
<a href="<?php echo $order_detail->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$order_detail_edit->ShowMessage();
?>
<form name="forder_detailedit" id="forder_detailedit" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return order_detail_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="order_detail">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<input type="hidden" name="k_hash" id="k_hash" value="<?php echo $order_detail_edit->HashValue ?>">
<table cellspacing="0" cellpadding="0"><tr><td>
<div id="order_detail_edit" class="yui-navset">
	<ul class="yui-nav">
		<li class="selected"><a href="#tab_order_detail_1"><em><span class="phpmaker"><?php echo $order_detail->PageCaption(1) ?></span></em></a></li>
		<li><a href="#tab_order_detail_2"><em><span class="phpmaker"><?php echo $order_detail->PageCaption(2) ?></span></em></a></li>
	</ul>            
	<div class="yui-content">
		<div id="tab_order_detail_1">
<table cellspacing="0" class="ewGrid" style="width: 100%"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($order_detail->id->Visible) { // id ?>
	<tr<?php echo $order_detail->id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $order_detail->id->FldCaption() ?></td>
		<td<?php echo $order_detail->id->CellAttributes() ?>><span id="el_id">
<div<?php echo $order_detail->id->ViewAttributes() ?>><?php echo $order_detail->id->EditValue ?></div><input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($order_detail->id->CurrentValue) ?>">
</span><?php echo $order_detail->id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($order_detail->order_id->Visible) { // order_id ?>
	<tr<?php echo $order_detail->order_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $order_detail->order_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $order_detail->order_id->CellAttributes() ?>><span id="el_order_id">
<?php if ($order_detail->order_id->getSessionValue() <> "") { ?>
<div<?php echo $order_detail->order_id->ViewAttributes() ?>><?php echo $order_detail->order_id->ViewValue ?></div>
<input type="hidden" id="x_order_id" name="x_order_id" value="<?php echo ew_HtmlEncode($order_detail->order_id->CurrentValue) ?>">
<?php } else { ?>
<select id="x_order_id" name="x_order_id" title="<?php echo $order_detail->order_id->FldTitle() ?>"<?php echo $order_detail->order_id->EditAttributes() ?>>
<?php
if (is_array($order_detail->order_id->EditValue)) {
	$arwrk = $order_detail->order_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($order_detail->order_id->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] ?>
<?php if ($arwrk[$rowcntwrk][2] <> "") { ?>
<?php echo ew_ValueSeparator($rowcntwrk) ?><?php echo $arwrk[$rowcntwrk][2] ?>
<?php } ?>
</option>
<?php
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `id`, `teacher`, `lesson` FROM `orders`";
$sWhereWrk = "";
$sWhereWrk = $GLOBALS["orders"]->AddUserIDFilter($sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
$sSqlWrk .= " ORDER BY `request_date` Desc";
$sSqlWrk = TEAencrypt($sSqlWrk, EW_RANDOM_KEY);
?>
<input type="hidden" name="s_x_order_id" id="s_x_order_id" value="<?php echo $sSqlWrk; ?>">
<input type="hidden" name="lft_x_order_id" id="lft_x_order_id" value="">
<?php } ?>
</span><?php echo $order_detail->order_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($order_detail->item_id->Visible) { // item_id ?>
	<tr<?php echo $order_detail->item_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $order_detail->item_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $order_detail->item_id->CellAttributes() ?>><span id="el_item_id">
<?php if ($order_detail->item_id->getSessionValue() <> "") { ?>
<div<?php echo $order_detail->item_id->ViewAttributes() ?>>
<?php if ($order_detail->item_id->HrefValue <> "" || $order_detail->item_id->TooltipValue <> "" || $order_detail->note->ViewValue <> "") { ?>
<a href="javascript:void(0);" onmouseover="ew_ShowTooltip(this, 'tt_order_detail_x_item_id');" onmouseout="ew_HideTooltip();"><?php echo $order_detail->item_id->ViewValue ?></a>
<?php } else { ?>
<?php echo $order_detail->item_id->ViewValue ?>
<?php } ?>
</div><div id="tt_order_detail_x_item_id" style="display: none">
<?php if ($order_detail->item_id->TooltipValue <> "") { ?>
<?php echo $order_detail->item_id->TooltipValue ?>
<?php } else { ?>
<div<?php echo $order_detail->note->ViewAttributes() ?>><?php echo $order_detail->note->ViewValue ?></div>
<?php } ?>
</div>
<input type="hidden" id="x_item_id" name="x_item_id" value="<?php echo ew_HtmlEncode($order_detail->item_id->CurrentValue) ?>">
<?php } else { ?>
<?php $order_detail->item_id->EditAttrs["onchange"] = "ew_AjaxAutoFill(this); " . @$order_detail->item_id->EditAttrs["onchange"]; ?>
<select id="x_item_id" name="x_item_id" title="<?php echo $order_detail->item_id->FldTitle() ?>"<?php echo $order_detail->item_id->EditAttributes() ?>>
<?php
if (is_array($order_detail->item_id->EditValue)) {
	$arwrk = $order_detail->item_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($order_detail->item_id->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
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `room_id` AS FIELD0, `store_id` AS FIELD1 FROM `items`";
$sWhereWrk = "(`id` = {query_value})";
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
$sSqlWrk .= " ORDER BY `name` Asc";
$sSqlWrk = TEAencrypt($sSqlWrk, EW_RANDOM_KEY);
?>
<input type="hidden" name="sf_x_item_id" id="sf_x_item_id" value="<?php echo $sSqlWrk ?>">
<input type="hidden" name="ln_x_item_id" id="ln_x_item_id" value="x_room_id,x_store_id">
<?php } ?>
</span><?php echo $order_detail->item_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($order_detail->quantity->Visible) { // quantity ?>
	<tr<?php echo $order_detail->quantity->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $order_detail->quantity->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $order_detail->quantity->CellAttributes() ?>><span id="el_quantity">
<input type="text" name="x_quantity" id="x_quantity" title="<?php echo $order_detail->quantity->FldTitle() ?>" size="30" value="<?php echo $order_detail->quantity->EditValue ?>"<?php echo $order_detail->quantity->EditAttributes() ?>>
</span><?php echo $order_detail->quantity->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($order_detail->unit->Visible) { // unit ?>
	<tr<?php echo $order_detail->unit->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $order_detail->unit->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $order_detail->unit->CellAttributes() ?>><span id="el_unit">
<?php if ($order_detail->unit->getSessionValue() <> "") { ?>
<div<?php echo $order_detail->unit->ViewAttributes() ?>><?php echo $order_detail->unit->ViewValue ?></div>
<input type="hidden" id="x_unit" name="x_unit" value="<?php echo ew_HtmlEncode($order_detail->unit->CurrentValue) ?>">
<?php } else { ?>
<select id="x_unit" name="x_unit" title="<?php echo $order_detail->unit->FldTitle() ?>"<?php echo $order_detail->unit->EditAttributes() ?>>
<?php
if (is_array($order_detail->unit->EditValue)) {
	$arwrk = $order_detail->unit->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($order_detail->unit->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
	}
}
?>
</select>
<?php } ?>
</span><?php echo $order_detail->unit->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($order_detail->concentration->Visible) { // concentration ?>
	<tr<?php echo $order_detail->concentration->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $order_detail->concentration->FldCaption() ?></td>
		<td<?php echo $order_detail->concentration->CellAttributes() ?>><span id="el_concentration">
<input type="text" name="x_concentration" id="x_concentration" title="<?php echo $order_detail->concentration->FldTitle() ?>" size="30" maxlength="25" value="<?php echo $order_detail->concentration->EditValue ?>"<?php echo $order_detail->concentration->EditAttributes() ?>>
</span><?php echo $order_detail->concentration->CustomMsg ?></td>
	</tr>
<?php } ?>
<input type="hidden" name="x_room_id" id="x_room_id" value="<?php echo ew_HtmlEncode($order_detail->room_id->CurrentValue) ?>">
<input type="hidden" name="x_store_id" id="x_store_id" value="<?php echo ew_HtmlEncode($order_detail->store_id->CurrentValue) ?>">
</table>
</div>
</td></tr></table>
		</div>
		<div id="tab_order_detail_2">
<table cellspacing="0" class="ewGrid" style="width: 100%"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($order_detail->note->Visible) { // note ?>
	<tr<?php echo $order_detail->note->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $order_detail->note->FldCaption() ?></td>
		<td<?php echo $order_detail->note->CellAttributes() ?>><span id="el_note">
<textarea name="x_note" id="x_note" title="<?php echo $order_detail->note->FldTitle() ?>" cols="35" rows="4"<?php echo $order_detail->note->EditAttributes() ?>><?php echo $order_detail->note->EditValue ?></textarea>
<script type="text/javascript">
<!--
ew_DHTMLEditors.push(new ew_DHTMLEditor("x_note", function() {
	var oCKeditor = CKEDITOR.replace('x_note', { width: 35*_width_multiplier, height: 4*_height_multiplier, autoUpdateElement: false, baseHref: 'ckeditor/'});
	this.active = true;
}));
-->
</script>
</span><?php echo $order_detail->note->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
		</div>
	</div>
</div>
</td></tr></table>
<script type="text/javascript">
<!--
ew_TabView(order_detail_edit);

//-->
</script>	
<p>
<?php if ($order_detail->UpdateConflict == "U") { // Record already updated by other user ?>
<input type="submit" name="btnReload" id="btnReload" value="<?php echo ew_BtnCaption($Language->Phrase("ReloadBtn")) ?>" onclick="this.form.a_edit.value='I';">
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("OverwriteBtn")) ?>" onclick="this.form.a_edit.value='overwrite';">
<?php } else { ?>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
<?php } ?>
</form>
<script language="JavaScript" type="text/javascript">
<!--
ew_UpdateOpts([['x_order_id','x_order_id',false]]);

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

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

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

//
// Page class
//
class corder_detail_edit {

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

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

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

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

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $order_detail;
		if ($order_detail->UseTokenInUrl) $PageUrl .= "t=" . $order_detail->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, $order_detail;
		if ($order_detail->UseTokenInUrl) {
			if ($objForm)
				return ($order_detail->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($order_detail->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

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

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

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

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

		// Table object (items)
		$GLOBALS['items'] = new citems();

		// Table object (unit)
		$GLOBALS['unit'] = new cunit();

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

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

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'order_detail', 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 $order_detail;

		// 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->CanEdit()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("order_detaillist.php");
		}
		$Security->UserID_Loading();
		if ($Security->IsLoggedIn()) $Security->LoadUserID();
		$Security->UserID_Loaded();

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

		// 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 $sDbMasterFilter;
	var $sDbDetailFilter;
	var $HashValue; // Hash Value

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError, $order_detail;

		// Load key from QueryString
		if (@$_GET["id"] <> "")
			$order_detail->id->setQueryStringValue($_GET["id"]);

		// Set up master detail parameters
		$this->SetUpMasterDetail();
		if (@$_POST["a_edit"] <> "") {
			$order_detail->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->LoadFormValues(); // Get form values

			// Overwrite record, reload hash value
			if ($order_detail->CurrentAction == "overwrite") {
				$this->LoadRowHash();
				$order_detail->CurrentAction = "U";
			}

			// Validate form
			if (!$this->ValidateForm()) {
				$order_detail->CurrentAction = ""; // Form error, reset action
				$this->setMessage($gsFormError);
				$order_detail->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues();
			}
		} else {
			$order_detail->CurrentAction = "I"; // Default action is display
		}

		// Check if valid key
		if ($order_detail->id->CurrentValue == "")
			$this->Page_Terminate("order_detaillist.php"); // Invalid key, return to list
		switch ($order_detail->CurrentAction) {
			case "I": // Get a record to display
				if (!$this->LoadRow()) { // Load record based on key
					$this->setMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("order_detaillist.php"); // No matching record, return to list
				}
				break;
			Case "U": // Update
				$order_detail->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					$this->setMessage($Language->Phrase("UpdateSuccess")); // Update success
					$sReturnUrl = $order_detail->getReturnUrl();
					if (ew_GetPageName($sReturnUrl) == "order_detailview.php")
						$sReturnUrl = $order_detail->ViewUrl(); // View paging, return to View page directly
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$order_detail->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed
				}
		}

		// Render the record
		$order_detail->RowType = EW_ROWTYPE_EDIT; // Render as Edit
		$this->RenderRow();
	}

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

		// Get upload data
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $order_detail;
		$order_detail->id->setFormValue($objForm->GetValue("x_id"));
		$order_detail->order_id->setFormValue($objForm->GetValue("x_order_id"));
		$order_detail->item_id->setFormValue($objForm->GetValue("x_item_id"));
		$order_detail->quantity->setFormValue($objForm->GetValue("x_quantity"));
		$order_detail->unit->setFormValue($objForm->GetValue("x_unit"));
		$order_detail->concentration->setFormValue($objForm->GetValue("x_concentration"));
		$order_detail->note->setFormValue($objForm->GetValue("x_note"));
		$order_detail->room_id->setFormValue($objForm->GetValue("x_room_id"));
		$order_detail->store_id->setFormValue($objForm->GetValue("x_store_id"));
		if ($order_detail->CurrentAction <> "overwrite")
			$this->HashValue = $objForm->GetValue("k_hash");
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $order_detail;
		$this->LoadRow();
		$order_detail->id->CurrentValue = $order_detail->id->FormValue;
		$order_detail->order_id->CurrentValue = $order_detail->order_id->FormValue;
		$order_detail->item_id->CurrentValue = $order_detail->item_id->FormValue;
		$order_detail->quantity->CurrentValue = $order_detail->quantity->FormValue;
		$order_detail->unit->CurrentValue = $order_detail->unit->FormValue;
		$order_detail->concentration->CurrentValue = $order_detail->concentration->FormValue;
		$order_detail->note->CurrentValue = $order_detail->note->FormValue;
		$order_detail->room_id->CurrentValue = $order_detail->room_id->FormValue;
		$order_detail->store_id->CurrentValue = $order_detail->store_id->FormValue;
		if ($order_detail->CurrentAction <> "overwrite")
			$this->HashValue = $objForm->GetValue("k_hash");
	}

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

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

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

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

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $order_detail;
		$order_detail->id->setDbValue($rs->fields('id'));
		$order_detail->order_id->setDbValue($rs->fields('order_id'));
		$order_detail->item_id->setDbValue($rs->fields('item_id'));
		$order_detail->quantity->setDbValue($rs->fields('quantity'));
		$order_detail->unit->setDbValue($rs->fields('unit'));
		$order_detail->concentration->setDbValue($rs->fields('concentration'));
		$order_detail->note->setDbValue($rs->fields('note'));
		$order_detail->room_id->setDbValue($rs->fields('room_id'));
		$order_detail->store_id->setDbValue($rs->fields('store_id'));
	}

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

		// Initialize URLs
		// Call Row_Rendering event

		$order_detail->Row_Rendering();

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

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

		// order_id
		$order_detail->order_id->CellCssStyle = ""; $order_detail->order_id->CellCssClass = "";
		$order_detail->order_id->CellAttrs = array(); $order_detail->order_id->ViewAttrs = array(); $order_detail->order_id->EditAttrs = array();

		// item_id
		$order_detail->item_id->CellCssStyle = ""; $order_detail->item_id->CellCssClass = "";
		$order_detail->item_id->CellAttrs = array(); $order_detail->item_id->ViewAttrs = array(); $order_detail->item_id->EditAttrs = array();

		// quantity
		$order_detail->quantity->CellCssStyle = ""; $order_detail->quantity->CellCssClass = "";
		$order_detail->quantity->CellAttrs = array(); $order_detail->quantity->ViewAttrs = array(); $order_detail->quantity->EditAttrs = array();

		// unit
		$order_detail->unit->CellCssStyle = ""; $order_detail->unit->CellCssClass = "";
		$order_detail->unit->CellAttrs = array(); $order_detail->unit->ViewAttrs = array(); $order_detail->unit->EditAttrs = array();

		// concentration
		$order_detail->concentration->CellCssStyle = ""; $order_detail->concentration->CellCssClass = "";
		$order_detail->concentration->CellAttrs = array(); $order_detail->concentration->ViewAttrs = array(); $order_detail->concentration->EditAttrs = array();

		// note
		$order_detail->note->CellCssStyle = ""; $order_detail->note->CellCssClass = "";
		$order_detail->note->CellAttrs = array(); $order_detail->note->ViewAttrs = array(); $order_detail->note->EditAttrs = array();

		// room_id
		$order_detail->room_id->CellCssStyle = ""; $order_detail->room_id->CellCssClass = "";
		$order_detail->room_id->CellAttrs = array(); $order_detail->room_id->ViewAttrs = array(); $order_detail->room_id->EditAttrs = array();

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

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

			// order_id
			if (strval($order_detail->order_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($order_detail->order_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `teacher`, `lesson` FROM `orders`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `request_date` Desc";
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$order_detail->order_id->ViewValue = $rswrk->fields('teacher');
					$order_detail->order_id->ViewValue .= ew_ValueSeparator(0) . $rswrk->fields('lesson');
					$rswrk->Close();
				} else {
					$order_detail->order_id->ViewValue = $order_detail->order_id->CurrentValue;
				}
			} else {
				$order_detail->order_id->ViewValue = NULL;
			}
			$order_detail->order_id->CssStyle = "font-weight:bold;";
			$order_detail->order_id->CssClass = "";
			$order_detail->order_id->ViewCustomAttributes = "";

			// item_id
			if (strval($order_detail->item_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($order_detail->item_id->CurrentValue) . "";
			$sSqlWrk = "SELECT DISTINCT `name` FROM `items`";
			$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
					$order_detail->item_id->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$order_detail->item_id->ViewValue = $order_detail->item_id->CurrentValue;
				}
			} else {
				$order_detail->item_id->ViewValue = NULL;
			}
			$order_detail->item_id->CssStyle = "";
			$order_detail->item_id->CssClass = "";
			$order_detail->item_id->ViewCustomAttributes = "";

			// quantity
			$order_detail->quantity->ViewValue = $order_detail->quantity->CurrentValue;
			$order_detail->quantity->CssStyle = "";
			$order_detail->quantity->CssClass = "";
			$order_detail->quantity->ViewCustomAttributes = "";

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

			// concentration
			$order_detail->concentration->ViewValue = $order_detail->concentration->CurrentValue;
			$order_detail->concentration->CssStyle = "";
			$order_detail->concentration->CssClass = "";
			$order_detail->concentration->ViewCustomAttributes = "";

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

			// room_id
			$order_detail->room_id->ViewValue = $order_detail->room_id->CurrentValue;
			$order_detail->room_id->CssStyle = "font-weight:bold;font-style:italic;";
			$order_detail->room_id->CssClass = "";
			$order_detail->room_id->ViewCustomAttributes = "";

			// store_id
			$order_detail->store_id->ViewValue = $order_detail->store_id->CurrentValue;
			$order_detail->store_id->CssStyle = "font-weight:bold;font-style:italic;";
			$order_detail->store_id->CssClass = "";
			$order_detail->store_id->ViewCustomAttributes = "";

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

			// order_id
			$order_detail->order_id->HrefValue = "";
			$order_detail->order_id->TooltipValue = "";

			// item_id
			$order_detail->item_id->HrefValue = "";
			$order_detail->item_id->TooltipValue = $order_detail->note->CurrentValue;

			// quantity
			$order_detail->quantity->HrefValue = "";
			$order_detail->quantity->TooltipValue = "";

			// unit
			$order_detail->unit->HrefValue = "";
			$order_detail->unit->TooltipValue = "";

			// concentration
			$order_detail->concentration->HrefValue = "";
			$order_detail->concentration->TooltipValue = "";

			// note
			$order_detail->note->HrefValue = "";
			$order_detail->note->TooltipValue = "";

			// room_id
			$order_detail->room_id->HrefValue = "";
			$order_detail->room_id->TooltipValue = "";

			// store_id
			$order_detail->store_id->HrefValue = "";
			$order_detail->store_id->TooltipValue = "";
		} elseif ($order_detail->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// id
			$order_detail->id->EditCustomAttributes = "";
			$order_detail->id->EditValue = $order_detail->id->CurrentValue;
			$order_detail->id->CssStyle = "";
			$order_detail->id->CssClass = "";
			$order_detail->id->ViewCustomAttributes = "";

			// order_id
			$order_detail->order_id->EditCustomAttributes = "";
			if ($order_detail->order_id->getSessionValue() <> "") {
				$order_detail->order_id->CurrentValue = $order_detail->order_id->getSessionValue();
			if (strval($order_detail->order_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($order_detail->order_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `teacher`, `lesson` FROM `orders`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `request_date` Desc";
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$order_detail->order_id->ViewValue = $rswrk->fields('teacher');
					$order_detail->order_id->ViewValue .= ew_ValueSeparator(0) . $rswrk->fields('lesson');
					$rswrk->Close();
				} else {
					$order_detail->order_id->ViewValue = $order_detail->order_id->CurrentValue;
				}
			} else {
				$order_detail->order_id->ViewValue = NULL;
			}
			$order_detail->order_id->CssStyle = "font-weight:bold;";
			$order_detail->order_id->CssClass = "";
			$order_detail->order_id->ViewCustomAttributes = "";
			} else {
			if (trim(strval($order_detail->order_id->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`id` = " . ew_AdjustSql($order_detail->order_id->CurrentValue) . "";
			}
			$sSqlWrk = "SELECT `id`, `teacher`, `lesson`, '' AS SelectFilterFld FROM `orders`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			$sWhereWrk = $GLOBALS["orders"]->AddUserIDFilter($sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$sSqlWrk .= " ORDER BY `request_date` Desc";
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), ""));
			$order_detail->order_id->EditValue = $arwrk;
			}

			// item_id
			$order_detail->item_id->EditCustomAttributes = "";
			if ($order_detail->item_id->getSessionValue() <> "") {
				$order_detail->item_id->CurrentValue = $order_detail->item_id->getSessionValue();
			if (strval($order_detail->item_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($order_detail->item_id->CurrentValue) . "";
			$sSqlWrk = "SELECT DISTINCT `name` FROM `items`";
			$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
					$order_detail->item_id->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$order_detail->item_id->ViewValue = $order_detail->item_id->CurrentValue;
				}
			} else {
				$order_detail->item_id->ViewValue = NULL;
			}
			$order_detail->item_id->CssStyle = "";
			$order_detail->item_id->CssClass = "";
			$order_detail->item_id->ViewCustomAttributes = "";
			} else {
				$sFilterWrk = "";
			$sSqlWrk = "SELECT DISTINCT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `items`";
			$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")));
			$order_detail->item_id->EditValue = $arwrk;
			}

			// quantity
			$order_detail->quantity->EditCustomAttributes = "";
			$order_detail->quantity->EditValue = ew_HtmlEncode($order_detail->quantity->CurrentValue);

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

			// concentration
			$order_detail->concentration->EditCustomAttributes = "";
			$order_detail->concentration->EditValue = ew_HtmlEncode($order_detail->concentration->CurrentValue);

			// note
			$order_detail->note->EditCustomAttributes = "";
			$order_detail->note->EditValue = ew_HtmlEncode($order_detail->note->CurrentValue);

			// room_id
			$order_detail->room_id->EditCustomAttributes = "";

			// store_id
			$order_detail->store_id->EditCustomAttributes = "";

			// Edit refer script
			// id

			$order_detail->id->HrefValue = "";

			// order_id
			$order_detail->order_id->HrefValue = "";

			// item_id
			$order_detail->item_id->HrefValue = "";

			// quantity
			$order_detail->quantity->HrefValue = "";

			// unit
			$order_detail->unit->HrefValue = "";

			// concentration
			$order_detail->concentration->HrefValue = "";

			// note
			$order_detail->note->HrefValue = "";

			// room_id
			$order_detail->room_id->HrefValue = "";

			// store_id
			$order_detail->store_id->HrefValue = "";
		}

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

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

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!is_null($order_detail->order_id->FormValue) && $order_detail->order_id->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $order_detail->order_id->FldCaption();
		}
		if (!is_null($order_detail->item_id->FormValue) && $order_detail->item_id->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $order_detail->item_id->FldCaption();
		}
		if (!is_null($order_detail->quantity->FormValue) && $order_detail->quantity->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $order_detail->quantity->FldCaption();
		}
		if (!ew_CheckNumber($order_detail->quantity->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $order_detail->quantity->FldErrMsg();
		}
		if (!is_null($order_detail->unit->FormValue) && $order_detail->unit->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $order_detail->unit->FldCaption();
		}

		// 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, $order_detail;
		$sFilter = $order_detail->KeyFilter();
		$order_detail->CurrentFilter = $sFilter;
		$sSql = $order_detail->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();

			// order_id
			$order_detail->order_id->SetDbValueDef($rsnew, $order_detail->order_id->CurrentValue, 0, FALSE);

			// item_id
			$order_detail->item_id->SetDbValueDef($rsnew, $order_detail->item_id->CurrentValue, 0, FALSE);

			// quantity
			$order_detail->quantity->SetDbValueDef($rsnew, $order_detail->quantity->CurrentValue, 0, FALSE);

			// unit
			$order_detail->unit->SetDbValueDef($rsnew, $order_detail->unit->CurrentValue, "", FALSE);

			// concentration
			$order_detail->concentration->SetDbValueDef($rsnew, $order_detail->concentration->CurrentValue, NULL, FALSE);

			// note
			$order_detail->note->SetDbValueDef($rsnew, $order_detail->note->CurrentValue, NULL, FALSE);

			// room_id
			$order_detail->room_id->SetDbValueDef($rsnew, $order_detail->room_id->CurrentValue, NULL, FALSE);

			// store_id
			$order_detail->store_id->SetDbValueDef($rsnew, $order_detail->store_id->CurrentValue, NULL, FALSE);

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

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

			// Call Row Updating event
			$bUpdateRow = $order_detail->Row_Updating($rsold, $rsnew);
			if ($bUpdateRow) {
				$conn->raiseErrorFn = 'ew_ErrorFn';
				$EditRow = $conn->Execute($order_detail->UpdateSQL($rsnew));
				$conn->raiseErrorFn = '';
			} else {
				if ($order_detail->CancelMessage <> "") {
					$this->setMessage($order_detail->CancelMessage);
					$order_detail->CancelMessage = "";
				} else {
					$this->setMessage($Language->Phrase("UpdateCancelled"));
				}
				$EditRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($EditRow)
			$order_detail->Row_Updated($rsold, $rsnew);
		$rs->Close();
		return $EditRow;
	}

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

		// Load SQL based on filter
		$order_detail->CurrentFilter = $sFilter;
		$sSql = $order_detail->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, 'order_id'); // order_id
		$sHash .= ew_GetRsHash($rs, 'item_id'); // item_id
		$sHash .= ew_GetRsHash($rs, 'quantity'); // quantity
		$sHash .= ew_GetRsHash($rs, 'unit'); // unit
		$sHash .= ew_GetRsHash($rs, 'concentration'); // concentration
		$sHash .= ew_GetRsHash($rs, 'note'); // note
		$sHash .= ew_GetRsHash($rs, 'room_id'); // room_id
		$sHash .= ew_GetRsHash($rs, 'store_id'); // store_id
		return md5($sHash);
	}

	// Set up master/detail based on QueryString
	function SetUpMasterDetail() {
		global $order_detail;
		$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 == "items") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $order_detail->SqlMasterFilter_items();
				$this->sDbDetailFilter = $order_detail->SqlDetailFilter_items();
				if (@$_GET["id"] <> "") {
					$GLOBALS["items"]->id->setQueryStringValue($_GET["id"]);
					$order_detail->item_id->setQueryStringValue($GLOBALS["items"]->id->QueryStringValue);
					$order_detail->item_id->setSessionValue($order_detail->item_id->QueryStringValue);
					if (!is_numeric($GLOBALS["items"]->id->QueryStringValue)) $bValidMaster = FALSE;
					$this->sDbMasterFilter = str_replace("@id@", ew_AdjustSql($GLOBALS["items"]->id->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@item_id@", ew_AdjustSql($GLOBALS["items"]->id->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
			if ($sMasterTblVar == "unit") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $order_detail->SqlMasterFilter_unit();
				$this->sDbDetailFilter = $order_detail->SqlDetailFilter_unit();
				if (@$_GET["unit"] <> "") {
					$GLOBALS["unit"]->unit->setQueryStringValue($_GET["unit"]);
					$order_detail->unit->setQueryStringValue($GLOBALS["unit"]->unit->QueryStringValue);
					$order_detail->unit->setSessionValue($order_detail->unit->QueryStringValue);
					$this->sDbMasterFilter = str_replace("@unit@", ew_AdjustSql($GLOBALS["unit"]->unit->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@unit@", ew_AdjustSql($GLOBALS["unit"]->unit->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
			if ($sMasterTblVar == "orders") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $order_detail->SqlMasterFilter_orders();
				$this->sDbDetailFilter = $order_detail->SqlDetailFilter_orders();
				if (@$_GET["id"] <> "") {
					$GLOBALS["orders"]->id->setQueryStringValue($_GET["id"]);
					$order_detail->order_id->setQueryStringValue($GLOBALS["orders"]->id->QueryStringValue);
					$order_detail->order_id->setSessionValue($order_detail->order_id->QueryStringValue);
					if (!is_numeric($GLOBALS["orders"]->id->QueryStringValue)) $bValidMaster = FALSE;
					$this->sDbMasterFilter = str_replace("@id@", ew_AdjustSql($GLOBALS["orders"]->id->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@order_id@", ew_AdjustSql($GLOBALS["orders"]->id->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
		}
		if ($bValidMaster) {

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

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

			// Clear previous master key from Session
			if ($sMasterTblVar <> "items") {
				if ($order_detail->item_id->QueryStringValue == "") $order_detail->item_id->setSessionValue("");
			}
			if ($sMasterTblVar <> "unit") {
				if ($order_detail->unit->QueryStringValue == "") $order_detail->unit->setSessionValue("");
			}
			if ($sMasterTblVar <> "orders") {
				if ($order_detail->order_id->QueryStringValue == "") $order_detail->order_id->setSessionValue("");
			}
		} else {
			$this->sDbMasterFilter = $order_detail->getMasterFilter(); //  Restore master filter
			$this->sDbDetailFilter = $order_detail->getDetailFilter(); // Restore detail filter
		}
	}

	// 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;
	}
}
?>
Return current item: Science Lab Inventory & Order Management