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

// Create page object
$items_edit = new citems_edit();
$Page =& $items_edit;

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

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

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

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

// extend page with ValidateForm function
items_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 + "_type_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($items->type_id->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($items->room_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_store_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($items->store_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_quantity"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($items->quantity->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_consumption"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($items->consumption->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_arrived"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($items->arrived->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_expires"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($items->expires->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_image"];
		if (elm && !ew_CheckFileType(elm.value))
			return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));

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

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

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

// multi page properties
items_edit.MultiPage = new ew_MultiPage();
items_edit.MultiPage.AddElement("x_id", 1);
items_edit.MultiPage.AddElement("x_name", 1);
items_edit.MultiPage.AddElement("x_type_id", 1);
items_edit.MultiPage.AddElement("x_room_id", 1);
items_edit.MultiPage.AddElement("x_store_id", 1);
items_edit.MultiPage.AddElement("x_unit", 1);
items_edit.MultiPage.AddElement("x_quantity", 1);
items_edit.MultiPage.AddElement("x_consumption", 1);
items_edit.MultiPage.AddElement("x_vendor", 1);
items_edit.MultiPage.AddElement("x_catno", 1);
items_edit.MultiPage.AddElement("x_arrived", 1);
items_edit.MultiPage.AddElement("x_expires", 1);
items_edit.MultiPage.AddElement("x_image", 2);
items_edit.MultiPage.AddElement("x_comments", 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>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
<!--

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

</script>
<p><span class="phpmaker"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $items->TableCaption() ?><br><br>
<a href="<?php echo $items->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$items_edit->ShowMessage();
?>
<form name="fitemsedit" id="fitemsedit" action="<?php echo ew_CurrentPage() ?>" method="post" enctype="multipart/form-data" onsubmit="return items_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="items">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table cellspacing="0" cellpadding="0"><tr><td>
<div id="items_edit" class="yui-navset">
	<ul class="yui-nav">
		<li class="selected"><a href="#tab_items_1"><em><span class="phpmaker"><?php echo $items->PageCaption(1) ?></span></em></a></li>
		<li><a href="#tab_items_2"><em><span class="phpmaker"><?php echo $items->PageCaption(2) ?></span></em></a></li>
	</ul>            
	<div class="yui-content">
		<div id="tab_items_1">
<table cellspacing="0" class="ewGrid" style="width: 100%"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($items->id->Visible) { // id ?>
	<tr<?php echo $items->id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->id->FldCaption() ?></td>
		<td<?php echo $items->id->CellAttributes() ?>><span id="el_id">
<div<?php echo $items->id->ViewAttributes() ?>>
<?php if ($items->id->HrefValue <> "" || $items->id->TooltipValue <> "" || $items->comments->ViewValue <> "") { ?>
<a href="javascript:void(0);" onmouseover="ew_ShowTooltip(this, 'tt_items_x_id');" onmouseout="ew_HideTooltip();"><?php echo $items->id->EditValue ?></a>
<?php } else { ?>
<?php echo $items->id->EditValue ?>
<?php } ?>
</div><div id="tt_items_x_id" style="display: none">
<?php if ($items->id->TooltipValue <> "") { ?>
<?php echo $items->id->TooltipValue ?>
<?php } else { ?>
<div<?php echo $items->comments->ViewAttributes() ?>><?php echo $items->comments->ViewValue ?></div>
<?php } ?>
</div><input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($items->id->CurrentValue) ?>">
</span><?php echo $items->id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->name->Visible) { // name ?>
	<tr<?php echo $items->name->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->name->FldCaption() ?></td>
		<td<?php echo $items->name->CellAttributes() ?>><span id="el_name">
<input type="text" name="x_name" id="x_name" title="<?php echo $items->name->FldTitle() ?>" size="30" maxlength="100" value="<?php echo $items->name->EditValue ?>"<?php echo $items->name->EditAttributes() ?>>
</span><?php echo $items->name->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->type_id->Visible) { // type_id ?>
	<tr<?php echo $items->type_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->type_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $items->type_id->CellAttributes() ?>><span id="el_type_id">
<?php if ($items->type_id->getSessionValue() <> "") { ?>
<div<?php echo $items->type_id->ViewAttributes() ?>><?php echo $items->type_id->ViewValue ?></div>
<input type="hidden" id="x_type_id" name="x_type_id" value="<?php echo ew_HtmlEncode($items->type_id->CurrentValue) ?>">
<?php } else { ?>
<select id="x_type_id" name="x_type_id" title="<?php echo $items->type_id->FldTitle() ?>"<?php echo $items->type_id->EditAttributes() ?>>
<?php
if (is_array($items->type_id->EditValue)) {
	$arwrk = $items->type_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($items->type_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 if (AllowAdd("types")) { ?>
&nbsp;<a name="aol_x_type_id" id="aol_x_type_id" href="javascript:void(0);" onclick="ew_AddOptDialogShow({pg:items_edit,lnk:'aol_x_type_id',el:'x_type_id',hdr:this.innerHTML, url:'typesaddopt.php',lf:'x_id',df:'x_name',df2:'',pf:'',ff:''});"><?php echo $Language->Phrase("AddLink") ?>&nbsp;<?php echo $items->type_id->FldCaption() ?></a>
<?php } ?>
<?php } ?>
</span><?php echo $items->type_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->room_id->Visible) { // room_id ?>
	<tr<?php echo $items->room_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->room_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $items->room_id->CellAttributes() ?>><span id="el_room_id">
<?php $items->room_id->EditAttrs["onchange"] = "ew_UpdateOpt('x_store_id','x_room_id',items_edit.ar_x_store_id); " . @$items->room_id->EditAttrs["onchange"]; ?>
<select id="x_room_id" name="x_room_id" title="<?php echo $items->room_id->FldTitle() ?>"<?php echo $items->room_id->EditAttributes() ?>>
<?php
if (is_array($items->room_id->EditValue)) {
	$arwrk = $items->room_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($items->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>
</span><?php echo $items->room_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->store_id->Visible) { // store_id ?>
	<tr<?php echo $items->store_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->store_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $items->store_id->CellAttributes() ?>><span id="el_store_id">
<?php if ($items->store_id->getSessionValue() <> "") { ?>
<div<?php echo $items->store_id->ViewAttributes() ?>><?php echo $items->store_id->ViewValue ?></div>
<input type="hidden" id="x_store_id" name="x_store_id" value="<?php echo ew_HtmlEncode($items->store_id->CurrentValue) ?>">
<?php } else { ?>
<select id="x_store_id" name="x_store_id" title="<?php echo $items->store_id->FldTitle() ?>"<?php echo $items->store_id->EditAttributes() ?>>
<?php
if (is_array($items->store_id->EditValue)) {
	$arwrk = $items->store_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($items->store_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
$jswrk = "";
if (is_array($items->store_id->EditValue)) {
	$arwrk = $items->store_id->EditValue;
	$arwrkcnt = count($arwrk);
	for ($rowcntwrk = 1; $rowcntwrk < $arwrkcnt; $rowcntwrk++) {
		if ($jswrk <> "") $jswrk .= ",";
		$jswrk .= "['" . ew_JsEncode($arwrk[$rowcntwrk][0]) . "',"; // Value
		$jswrk .= "'" . ew_JsEncode($arwrk[$rowcntwrk][1]) . "',"; // Display field 1
		$jswrk .= "'" . ew_JsEncode($arwrk[$rowcntwrk][2]) . "',"; // Display field 2
		$jswrk .= "'" . ew_JsEncode($arwrk[$rowcntwrk][3]) . "']"; // Filter field
	}
}
?>
<script type="text/javascript">
<!--
items_edit.ar_x_store_id = [<?php echo $jswrk ?>];

//-->
</script>
<?php } ?>
</span><?php echo $items->store_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->unit->Visible) { // unit ?>
	<tr<?php echo $items->unit->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->unit->FldCaption() ?></td>
		<td<?php echo $items->unit->CellAttributes() ?>><span id="el_unit">
<?php if ($items->unit->getSessionValue() <> "") { ?>
<div<?php echo $items->unit->ViewAttributes() ?>><?php echo $items->unit->ViewValue ?></div>
<input type="hidden" id="x_unit" name="x_unit" value="<?php echo ew_HtmlEncode($items->unit->CurrentValue) ?>">
<?php } else { ?>
<select id="x_unit" name="x_unit" title="<?php echo $items->unit->FldTitle() ?>"<?php echo $items->unit->EditAttributes() ?>>
<?php
if (is_array($items->unit->EditValue)) {
	$arwrk = $items->unit->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($items->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 $items->unit->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->quantity->Visible) { // quantity ?>
	<tr<?php echo $items->quantity->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->quantity->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $items->quantity->CellAttributes() ?>><span id="el_quantity">
<input type="text" name="x_quantity" id="x_quantity" title="<?php echo $items->quantity->FldTitle() ?>" size="30" value="<?php echo $items->quantity->EditValue ?>"<?php echo $items->quantity->EditAttributes() ?>>
</span><?php echo $items->quantity->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->consumption->Visible) { // consumption ?>
	<tr<?php echo $items->consumption->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->consumption->FldCaption() ?></td>
		<td<?php echo $items->consumption->CellAttributes() ?>><span id="el_consumption">
<input type="text" name="x_consumption" id="x_consumption" title="<?php echo $items->consumption->FldTitle() ?>" size="30" value="<?php echo $items->consumption->EditValue ?>"<?php echo $items->consumption->EditAttributes() ?>>
</span><?php echo $items->consumption->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->vendor->Visible) { // vendor ?>
	<tr<?php echo $items->vendor->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->vendor->FldCaption() ?></td>
		<td<?php echo $items->vendor->CellAttributes() ?>><span id="el_vendor">
<input type="text" name="x_vendor" id="x_vendor" title="<?php echo $items->vendor->FldTitle() ?>" size="30" maxlength="50" value="<?php echo $items->vendor->EditValue ?>"<?php echo $items->vendor->EditAttributes() ?>>
</span><?php echo $items->vendor->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->catno->Visible) { // catno ?>
	<tr<?php echo $items->catno->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->catno->FldCaption() ?></td>
		<td<?php echo $items->catno->CellAttributes() ?>><span id="el_catno">
<input type="text" name="x_catno" id="x_catno" title="<?php echo $items->catno->FldTitle() ?>" size="30" maxlength="50" value="<?php echo $items->catno->EditValue ?>"<?php echo $items->catno->EditAttributes() ?>>
</span><?php echo $items->catno->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->arrived->Visible) { // arrived ?>
	<tr<?php echo $items->arrived->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->arrived->FldCaption() ?></td>
		<td<?php echo $items->arrived->CellAttributes() ?>><span id="el_arrived">
<input type="text" name="x_arrived" id="x_arrived" title="<?php echo $items->arrived->FldTitle() ?>" value="<?php echo $items->arrived->EditValue ?>"<?php echo $items->arrived->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_arrived" name="cal_x_arrived" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_arrived", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_arrived" // button id
});
</script>
</span><?php echo $items->arrived->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->expires->Visible) { // expires ?>
	<tr<?php echo $items->expires->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->expires->FldCaption() ?></td>
		<td<?php echo $items->expires->CellAttributes() ?>><span id="el_expires">
<input type="text" name="x_expires" id="x_expires" title="<?php echo $items->expires->FldTitle() ?>" value="<?php echo $items->expires->EditValue ?>"<?php echo $items->expires->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_expires" name="cal_x_expires" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_expires", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_expires" // button id
});
</script>
</span><?php echo $items->expires->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
		</div>
		<div id="tab_items_2">
<table cellspacing="0" class="ewGrid" style="width: 100%"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($items->image->Visible) { // image ?>
	<tr<?php echo $items->image->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->image->FldCaption() ?></td>
		<td<?php echo $items->image->CellAttributes() ?>><span id="el_image">
<div id="old_x_image">
<?php if ($items->image->HrefValue <> "" || $items->image->TooltipValue <> "") { ?>
<?php if (!empty($items->image->Upload->DbValue)) { ?>
<img src="<?php echo ew_UploadPathEx(FALSE, $items->image->UploadPath) . $items->image->Upload->DbValue ?>" border=0<?php echo $items->image->ViewAttributes() ?>>
<?php } elseif (!in_array($items->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } else { ?>
<?php if (!empty($items->image->Upload->DbValue)) { ?>
<img src="<?php echo ew_UploadPathEx(FALSE, $items->image->UploadPath) . $items->image->Upload->DbValue ?>" border=0<?php echo $items->image->ViewAttributes() ?>>
<?php } elseif (!in_array($items->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
</div>
<div id="new_x_image">
<?php if (!empty($items->image->Upload->DbValue)) { ?>
<label><input type="radio" name="a_image" id="a_image" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?></label>&nbsp;
<label><input type="radio" name="a_image" id="a_image" value="2"><?php echo $Language->Phrase("Remove") ?></label>&nbsp;
<label><input type="radio" name="a_image" id="a_image" value="3"><?php echo $Language->Phrase("Replace") ?><br></label>
<?php $items->image->EditAttrs["onchange"] = "this.form.a_image[2].checked=true;" . @$items->image->EditAttrs["onchange"]; ?>
<?php } else { ?>
<input type="hidden" name="a_image" id="a_image" value="3">
<?php } ?>
<input type="file" name="x_image" id="x_image" title="<?php echo $items->image->FldTitle() ?>" size="30"<?php echo $items->image->EditAttributes() ?>>
</div>
</span><?php echo $items->image->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($items->comments->Visible) { // comments ?>
	<tr<?php echo $items->comments->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $items->comments->FldCaption() ?></td>
		<td<?php echo $items->comments->CellAttributes() ?>><span id="el_comments">
<textarea name="x_comments" id="x_comments" title="<?php echo $items->comments->FldTitle() ?>" cols="35" rows="4"<?php echo $items->comments->EditAttributes() ?>><?php echo $items->comments->EditValue ?></textarea>
<script type="text/javascript">
<!--
ew_DHTMLEditors.push(new ew_DHTMLEditor("x_comments", function() {
	var oCKeditor = CKEDITOR.replace('x_comments', { width: 35*_width_multiplier, height: 4*_height_multiplier, autoUpdateElement: false, baseHref: 'ckeditor/'});
	this.active = true;
}));
-->
</script>
</span><?php echo $items->comments->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
		</div>
	</div>
</div>
</td></tr></table>
<script type="text/javascript">
<!--
ew_TabView(items_edit);

//-->
</script>	
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
</form>
<script language="JavaScript" type="text/javascript">
<!--
ew_UpdateOpts([['x_store_id','x_room_id',items_edit.ar_x_store_id]]);

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

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

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

//
// Page class
//
class citems_edit {

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

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

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

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

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

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

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

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

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

		// Table object (types)
		$GLOBALS['types'] = new ctypes();

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

		// 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("itemslist.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, $items;

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

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

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

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

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

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

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

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

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $items;
		$items->id->setFormValue($objForm->GetValue("x_id"));
		$items->name->setFormValue($objForm->GetValue("x_name"));
		$items->type_id->setFormValue($objForm->GetValue("x_type_id"));
		$items->room_id->setFormValue($objForm->GetValue("x_room_id"));
		$items->store_id->setFormValue($objForm->GetValue("x_store_id"));
		$items->unit->setFormValue($objForm->GetValue("x_unit"));
		$items->quantity->setFormValue($objForm->GetValue("x_quantity"));
		$items->consumption->setFormValue($objForm->GetValue("x_consumption"));
		$items->vendor->setFormValue($objForm->GetValue("x_vendor"));
		$items->catno->setFormValue($objForm->GetValue("x_catno"));
		$items->arrived->setFormValue($objForm->GetValue("x_arrived"));
		$items->arrived->CurrentValue = ew_UnFormatDateTime($items->arrived->CurrentValue, 5);
		$items->expires->setFormValue($objForm->GetValue("x_expires"));
		$items->expires->CurrentValue = ew_UnFormatDateTime($items->expires->CurrentValue, 5);
		$items->comments->setFormValue($objForm->GetValue("x_comments"));
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $items;
		$this->LoadRow();
		$items->id->CurrentValue = $items->id->FormValue;
		$items->name->CurrentValue = $items->name->FormValue;
		$items->type_id->CurrentValue = $items->type_id->FormValue;
		$items->room_id->CurrentValue = $items->room_id->FormValue;
		$items->store_id->CurrentValue = $items->store_id->FormValue;
		$items->unit->CurrentValue = $items->unit->FormValue;
		$items->quantity->CurrentValue = $items->quantity->FormValue;
		$items->consumption->CurrentValue = $items->consumption->FormValue;
		$items->vendor->CurrentValue = $items->vendor->FormValue;
		$items->catno->CurrentValue = $items->catno->FormValue;
		$items->arrived->CurrentValue = $items->arrived->FormValue;
		$items->arrived->CurrentValue = ew_UnFormatDateTime($items->arrived->CurrentValue, 5);
		$items->expires->CurrentValue = $items->expires->FormValue;
		$items->expires->CurrentValue = ew_UnFormatDateTime($items->expires->CurrentValue, 5);
		$items->comments->CurrentValue = $items->comments->FormValue;
	}

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

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

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

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

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $items;
		$items->id->setDbValue($rs->fields('id'));
		$items->name->setDbValue($rs->fields('name'));
		$items->type_id->setDbValue($rs->fields('type_id'));
		$items->room_id->setDbValue($rs->fields('room_id'));
		$items->store_id->setDbValue($rs->fields('store_id'));
		$items->unit->setDbValue($rs->fields('unit'));
		$items->quantity->setDbValue($rs->fields('quantity'));
		$items->consumption->setDbValue($rs->fields('consumption'));
		$items->vendor->setDbValue($rs->fields('vendor'));
		$items->catno->setDbValue($rs->fields('catno'));
		$items->arrived->setDbValue($rs->fields('arrived'));
		$items->expires->setDbValue($rs->fields('expires'));
		$items->image->Upload->DbValue = $rs->fields('image');
		$items->comments->setDbValue($rs->fields('comments'));
	}

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

		// Initialize URLs
		// Call Row_Rendering event

		$items->Row_Rendering();

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

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

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

		// type_id
		$items->type_id->CellCssStyle = ""; $items->type_id->CellCssClass = "";
		$items->type_id->CellAttrs = array(); $items->type_id->ViewAttrs = array(); $items->type_id->EditAttrs = array();

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

		// store_id
		$items->store_id->CellCssStyle = ""; $items->store_id->CellCssClass = "";
		$items->store_id->CellAttrs = array(); $items->store_id->ViewAttrs = array(); $items->store_id->EditAttrs = array();

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

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

		// consumption
		$items->consumption->CellCssStyle = ""; $items->consumption->CellCssClass = "";
		$items->consumption->CellAttrs = array(); $items->consumption->ViewAttrs = array(); $items->consumption->EditAttrs = array();

		// vendor
		$items->vendor->CellCssStyle = ""; $items->vendor->CellCssClass = "";
		$items->vendor->CellAttrs = array(); $items->vendor->ViewAttrs = array(); $items->vendor->EditAttrs = array();

		// catno
		$items->catno->CellCssStyle = ""; $items->catno->CellCssClass = "";
		$items->catno->CellAttrs = array(); $items->catno->ViewAttrs = array(); $items->catno->EditAttrs = array();

		// arrived
		$items->arrived->CellCssStyle = ""; $items->arrived->CellCssClass = "";
		$items->arrived->CellAttrs = array(); $items->arrived->ViewAttrs = array(); $items->arrived->EditAttrs = array();

		// expires
		$items->expires->CellCssStyle = ""; $items->expires->CellCssClass = "";
		$items->expires->CellAttrs = array(); $items->expires->ViewAttrs = array(); $items->expires->EditAttrs = array();

		// image
		$items->image->CellCssStyle = ""; $items->image->CellCssClass = "";
		$items->image->CellAttrs = array(); $items->image->ViewAttrs = array(); $items->image->EditAttrs = array();

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

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

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

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

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

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

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

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

			// consumption
			$items->consumption->ViewValue = $items->consumption->CurrentValue;
			$items->consumption->CssStyle = "";
			$items->consumption->CssClass = "";
			$items->consumption->ViewCustomAttributes = "";

			// vendor
			$items->vendor->ViewValue = $items->vendor->CurrentValue;
			$items->vendor->CssStyle = "";
			$items->vendor->CssClass = "";
			$items->vendor->ViewCustomAttributes = "";

			// catno
			$items->catno->ViewValue = $items->catno->CurrentValue;
			$items->catno->CssStyle = "";
			$items->catno->CssClass = "";
			$items->catno->ViewCustomAttributes = "";

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

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

			// image
			if (!ew_Empty($items->image->Upload->DbValue)) {
				$items->image->ViewValue = $items->image->Upload->DbValue;
				$items->image->ImageAlt = $items->image->FldAlt();
			} else {
				$items->image->ViewValue = "";
			}
			$items->image->CssStyle = "";
			$items->image->CssClass = "";
			$items->image->ViewCustomAttributes = "";

			// comments
			$items->comments->ViewValue = $items->comments->CurrentValue;
			$items->comments->CssStyle = "";
			$items->comments->CssClass = "";
			$items->comments->ViewCustomAttributes = "";

			// id
			$items->id->HrefValue = "";
			$items->id->TooltipValue = $items->comments->CurrentValue;

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

			// type_id
			$items->type_id->HrefValue = "";
			$items->type_id->TooltipValue = "";

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

			// store_id
			$items->store_id->HrefValue = "";
			$items->store_id->TooltipValue = "";

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

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

			// consumption
			$items->consumption->HrefValue = "";
			$items->consumption->TooltipValue = "";

			// vendor
			$items->vendor->HrefValue = "";
			$items->vendor->TooltipValue = "";

			// catno
			$items->catno->HrefValue = "";
			$items->catno->TooltipValue = "";

			// arrived
			$items->arrived->HrefValue = "";
			$items->arrived->TooltipValue = "";

			// expires
			$items->expires->HrefValue = "";
			$items->expires->TooltipValue = "";

			// image
			$items->image->HrefValue = "";
			$items->image->TooltipValue = "";

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

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

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

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

			// room_id
			$items->room_id->EditCustomAttributes = "";
				$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")));
			$items->room_id->EditValue = $arwrk;

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

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

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

			// consumption
			$items->consumption->EditCustomAttributes = "";
			$items->consumption->EditValue = ew_HtmlEncode($items->consumption->CurrentValue);

			// vendor
			$items->vendor->EditCustomAttributes = "";
			$items->vendor->EditValue = ew_HtmlEncode($items->vendor->CurrentValue);

			// catno
			$items->catno->EditCustomAttributes = "";
			$items->catno->EditValue = ew_HtmlEncode($items->catno->CurrentValue);

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

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

			// image
			$items->image->EditCustomAttributes = "";
			if (!ew_Empty($items->image->Upload->DbValue)) {
				$items->image->EditValue = $items->image->Upload->DbValue;
				$items->image->ImageAlt = $items->image->FldAlt();
			} else {
				$items->image->EditValue = "";
			}

			// comments
			$items->comments->EditCustomAttributes = "";
			$items->comments->EditValue = ew_HtmlEncode($items->comments->CurrentValue);

			// Edit refer script
			// id

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

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

			// type_id
			$items->type_id->HrefValue = "";

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

			// store_id
			$items->store_id->HrefValue = "";

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

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

			// consumption
			$items->consumption->HrefValue = "";

			// vendor
			$items->vendor->HrefValue = "";

			// catno
			$items->catno->HrefValue = "";

			// arrived
			$items->arrived->HrefValue = "";

			// expires
			$items->expires->HrefValue = "";

			// image
			$items->image->HrefValue = "";

			// comments
			$items->comments->HrefValue = "";
		}

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

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

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

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!is_null($items->type_id->FormValue) && $items->type_id->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $items->type_id->FldCaption();
		}
		if (!is_null($items->room_id->FormValue) && $items->room_id->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $items->room_id->FldCaption();
		}
		if (!is_null($items->store_id->FormValue) && $items->store_id->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $items->store_id->FldCaption();
		}
		if (!ew_CheckNumber($items->quantity->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $items->quantity->FldErrMsg();
		}
		if (!ew_CheckNumber($items->consumption->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $items->consumption->FldErrMsg();
		}
		if (!ew_CheckDate($items->arrived->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $items->arrived->FldErrMsg();
		}
		if (!ew_CheckDate($items->expires->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $items->expires->FldErrMsg();
		}

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

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

	// Update record based on key values
	function EditRow() {
		global $conn, $Security, $Language, $items;
		$sFilter = $items->KeyFilter();
		$items->CurrentFilter = $sFilter;
		$sSql = $items->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();

			// name
			$items->name->SetDbValueDef($rsnew, $items->name->CurrentValue, NULL, FALSE);

			// type_id
			$items->type_id->SetDbValueDef($rsnew, $items->type_id->CurrentValue, 0, FALSE);

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

			// store_id
			$items->store_id->SetDbValueDef($rsnew, $items->store_id->CurrentValue, "", FALSE);

			// unit
			$items->unit->SetDbValueDef($rsnew, $items->unit->CurrentValue, NULL, FALSE);

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

			// consumption
			$items->consumption->SetDbValueDef($rsnew, $items->consumption->CurrentValue, NULL, FALSE);

			// vendor
			$items->vendor->SetDbValueDef($rsnew, $items->vendor->CurrentValue, NULL, FALSE);

			// catno
			$items->catno->SetDbValueDef($rsnew, $items->catno->CurrentValue, NULL, FALSE);

			// arrived
			$items->arrived->SetDbValueDef($rsnew, ew_UnFormatDateTime($items->arrived->CurrentValue, 5, FALSE), NULL);

			// expires
			$items->expires->SetDbValueDef($rsnew, ew_UnFormatDateTime($items->expires->CurrentValue, 5, FALSE), NULL);

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

			// comments
			$items->comments->SetDbValueDef($rsnew, $items->comments->CurrentValue, NULL, FALSE);

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

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

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

	// Set up master/detail based on QueryString
	function SetUpMasterDetail() {
		global $items;
		$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 == "stores") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $items->SqlMasterFilter_stores();
				$this->sDbDetailFilter = $items->SqlDetailFilter_stores();
				if (@$_GET["id"] <> "") {
					$GLOBALS["stores"]->id->setQueryStringValue($_GET["id"]);
					$items->store_id->setQueryStringValue($GLOBALS["stores"]->id->QueryStringValue);
					$items->store_id->setSessionValue($items->store_id->QueryStringValue);
					$this->sDbMasterFilter = str_replace("@id@", ew_AdjustSql($GLOBALS["stores"]->id->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@store_id@", ew_AdjustSql($GLOBALS["stores"]->id->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
			if ($sMasterTblVar == "types") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $items->SqlMasterFilter_types();
				$this->sDbDetailFilter = $items->SqlDetailFilter_types();
				if (@$_GET["id"] <> "") {
					$GLOBALS["types"]->id->setQueryStringValue($_GET["id"]);
					$items->type_id->setQueryStringValue($GLOBALS["types"]->id->QueryStringValue);
					$items->type_id->setSessionValue($items->type_id->QueryStringValue);
					if (!is_numeric($GLOBALS["types"]->id->QueryStringValue)) $bValidMaster = FALSE;
					$this->sDbMasterFilter = str_replace("@id@", ew_AdjustSql($GLOBALS["types"]->id->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@type_id@", ew_AdjustSql($GLOBALS["types"]->id->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
			if ($sMasterTblVar == "unit") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $items->SqlMasterFilter_unit();
				$this->sDbDetailFilter = $items->SqlDetailFilter_unit();
				if (@$_GET["unit"] <> "") {
					$GLOBALS["unit"]->unit->setQueryStringValue($_GET["unit"]);
					$items->unit->setQueryStringValue($GLOBALS["unit"]->unit->QueryStringValue);
					$items->unit->setSessionValue($items->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 ($bValidMaster) {

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

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

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