Location: PHPKode > projects > Science Lab Inventory & Order Management > sciencelabinv/storesedit.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 "storesinfo.php" ?>
<?php include "roomsinfo.php" ?>
<?php include "useraccountsinfo.php" ?>
<?php include "userfn7.php" ?>
<?php

// Create page object
$stores_edit = new cstores_edit();
$Page =& $stores_edit;

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

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

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

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

// extend page with ValidateForm function
stores_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 + "_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($stores->id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_name"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($stores->name->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_room_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($stores->room_id->FldCaption()) ?>");

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

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

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

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

//-->
</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 $stores->TableCaption() ?><br><br>
<a href="<?php echo $stores->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$stores_edit->ShowMessage();
?>
<form name="fstoresedit" id="fstoresedit" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return stores_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="stores">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($stores->id->Visible) { // id ?>
	<tr<?php echo $stores->id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $stores->id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $stores->id->CellAttributes() ?>><span id="el_id">
<div<?php echo $stores->id->ViewAttributes() ?>><?php echo $stores->id->EditValue ?></div><input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($stores->id->CurrentValue) ?>">
</span><?php echo $stores->id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stores->name->Visible) { // name ?>
	<tr<?php echo $stores->name->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $stores->name->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $stores->name->CellAttributes() ?>><span id="el_name">
<input type="text" name="x_name" id="x_name" title="<?php echo $stores->name->FldTitle() ?>" size="30" maxlength="25" value="<?php echo $stores->name->EditValue ?>"<?php echo $stores->name->EditAttributes() ?>>
</span><?php echo $stores->name->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stores->lock_no->Visible) { // lock_no ?>
	<tr<?php echo $stores->lock_no->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $stores->lock_no->FldCaption() ?></td>
		<td<?php echo $stores->lock_no->CellAttributes() ?>><span id="el_lock_no">
<input type="text" name="x_lock_no" id="x_lock_no" title="<?php echo $stores->lock_no->FldTitle() ?>" size="30" maxlength="10" value="<?php echo $stores->lock_no->EditValue ?>"<?php echo $stores->lock_no->EditAttributes() ?>>
</span><?php echo $stores->lock_no->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stores->room_id->Visible) { // room_id ?>
	<tr<?php echo $stores->room_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $stores->room_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $stores->room_id->CellAttributes() ?>><span id="el_room_id">
<?php if ($stores->room_id->getSessionValue() <> "") { ?>
<div<?php echo $stores->room_id->ViewAttributes() ?>><?php echo $stores->room_id->ViewValue ?></div>
<input type="hidden" id="x_room_id" name="x_room_id" value="<?php echo ew_HtmlEncode($stores->room_id->CurrentValue) ?>">
<?php } else { ?>
<select id="x_room_id" name="x_room_id" title="<?php echo $stores->room_id->FldTitle() ?>"<?php echo $stores->room_id->EditAttributes() ?>>
<?php
if (is_array($stores->room_id->EditValue)) {
	$arwrk = $stores->room_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($stores->room_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 } ?>
</span><?php echo $stores->room_id->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
</form>
<script language="JavaScript" type="text/javascript">
<!--

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

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

//
// Page class
//
class cstores_edit {

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

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

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

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

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

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

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

		// Table object (stores)
		$GLOBALS["stores"] = new cstores();

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

		// 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", 'stores', 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 $stores;

		// 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("storeslist.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;

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

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

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

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

		// Check if valid key
		if ($stores->id->CurrentValue == "")
			$this->Page_Terminate("storeslist.php"); // Invalid key, return to list
		switch ($stores->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("storeslist.php"); // No matching record, return to list
				}
				break;
			Case "U": // Update
				$stores->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					$this->setMessage($Language->Phrase("UpdateSuccess")); // Update success
					$sReturnUrl = $stores->getReturnUrl();
					if (ew_GetPageName($sReturnUrl) == "storesview.php")
						$sReturnUrl = $stores->ViewUrl(); // View paging, return to View page directly
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$stores->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed
				}
		}

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

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

		// Get upload data
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $stores;
		$stores->id->setFormValue($objForm->GetValue("x_id"));
		$stores->name->setFormValue($objForm->GetValue("x_name"));
		$stores->lock_no->setFormValue($objForm->GetValue("x_lock_no"));
		$stores->room_id->setFormValue($objForm->GetValue("x_room_id"));
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $stores;
		$this->LoadRow();
		$stores->id->CurrentValue = $stores->id->FormValue;
		$stores->name->CurrentValue = $stores->name->FormValue;
		$stores->lock_no->CurrentValue = $stores->lock_no->FormValue;
		$stores->room_id->CurrentValue = $stores->room_id->FormValue;
	}

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

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

		// Load SQL based on filter
		$stores->CurrentFilter = $sFilter;
		$sSql = $stores->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values

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

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $stores;
		$stores->id->setDbValue($rs->fields('id'));
		$stores->name->setDbValue($rs->fields('name'));
		$stores->lock_no->setDbValue($rs->fields('lock_no'));
		$stores->room_id->setDbValue($rs->fields('room_id'));
	}

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

		// Initialize URLs
		// Call Row_Rendering event

		$stores->Row_Rendering();

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

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

		// name
		$stores->name->CellCssStyle = ""; $stores->name->CellCssClass = "";
		$stores->name->CellAttrs = array(); $stores->name->ViewAttrs = array(); $stores->name->EditAttrs = array();

		// lock_no
		$stores->lock_no->CellCssStyle = ""; $stores->lock_no->CellCssClass = "";
		$stores->lock_no->CellAttrs = array(); $stores->lock_no->ViewAttrs = array(); $stores->lock_no->EditAttrs = array();

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

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

			// name
			$stores->name->ViewValue = $stores->name->CurrentValue;
			$stores->name->CssStyle = "";
			$stores->name->CssClass = "";
			$stores->name->ViewCustomAttributes = "";

			// lock_no
			$stores->lock_no->ViewValue = $stores->lock_no->CurrentValue;
			$stores->lock_no->CssStyle = "";
			$stores->lock_no->CssClass = "";
			$stores->lock_no->ViewCustomAttributes = "";

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

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

			// name
			$stores->name->HrefValue = "";
			$stores->name->TooltipValue = "";

			// lock_no
			$stores->lock_no->HrefValue = "";
			$stores->lock_no->TooltipValue = "";

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

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

			// name
			$stores->name->EditCustomAttributes = "";
			$stores->name->EditValue = ew_HtmlEncode($stores->name->CurrentValue);

			// lock_no
			$stores->lock_no->EditCustomAttributes = "";
			$stores->lock_no->EditValue = ew_HtmlEncode($stores->lock_no->CurrentValue);

			// room_id
			$stores->room_id->EditCustomAttributes = "";
			if ($stores->room_id->getSessionValue() <> "") {
				$stores->room_id->CurrentValue = $stores->room_id->getSessionValue();
			if (strval($stores->room_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = '" . ew_AdjustSql($stores->room_id->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
					$stores->room_id->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$stores->room_id->ViewValue = $stores->room_id->CurrentValue;
				}
			} else {
				$stores->room_id->ViewValue = NULL;
			}
			$stores->room_id->CssStyle = "";
			$stores->room_id->CssClass = "";
			$stores->room_id->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")));
			$stores->room_id->EditValue = $arwrk;
			}

			// Edit refer script
			// id

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

			// name
			$stores->name->HrefValue = "";

			// lock_no
			$stores->lock_no->HrefValue = "";

			// room_id
			$stores->room_id->HrefValue = "";
		}

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

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

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

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!is_null($stores->id->FormValue) && $stores->id->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $stores->id->FldCaption();
		}
		if (!is_null($stores->name->FormValue) && $stores->name->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $stores->name->FldCaption();
		}
		if (!is_null($stores->room_id->FormValue) && $stores->room_id->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $stores->room_id->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, $stores;
		$sFilter = $stores->KeyFilter();
		$stores->CurrentFilter = $sFilter;
		$sSql = $stores->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();

			// id
			// name

			$stores->name->SetDbValueDef($rsnew, $stores->name->CurrentValue, "", FALSE);

			// lock_no
			$stores->lock_no->SetDbValueDef($rsnew, $stores->lock_no->CurrentValue, NULL, FALSE);

			// room_id
			$stores->room_id->SetDbValueDef($rsnew, $stores->room_id->CurrentValue, "", FALSE);

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

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

	// Set up master/detail based on QueryString
	function SetUpMasterDetail() {
		global $stores;
		$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 == "rooms") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $stores->SqlMasterFilter_rooms();
				$this->sDbDetailFilter = $stores->SqlDetailFilter_rooms();
				if (@$_GET["id"] <> "") {
					$GLOBALS["rooms"]->id->setQueryStringValue($_GET["id"]);
					$stores->room_id->setQueryStringValue($GLOBALS["rooms"]->id->QueryStringValue);
					$stores->room_id->setSessionValue($stores->room_id->QueryStringValue);
					$this->sDbMasterFilter = str_replace("@id@", ew_AdjustSql($GLOBALS["rooms"]->id->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@room_id@", ew_AdjustSql($GLOBALS["rooms"]->id->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
		}
		if ($bValidMaster) {

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

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

			// Clear previous master key from Session
			if ($sMasterTblVar <> "rooms") {
				if ($stores->room_id->QueryStringValue == "") $stores->room_id->setSessionValue("");
			}
		} else {
			$this->sDbMasterFilter = $stores->getMasterFilter(); //  Restore master filter
			$this->sDbDetailFilter = $stores->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