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

// Create page object
$useraccounts_edit = new cuseraccounts_edit();
$Page =& $useraccounts_edit;

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

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

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

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

// extend page with ValidateForm function
useraccounts_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 + "_username"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($useraccounts->username->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_password"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($useraccounts->password->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_zemail"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($useraccounts->zemail->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_zemail"];
		if (elm && !ew_CheckEmail(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($useraccounts->zemail->FldErrMsg()) ?>");

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

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

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
useraccounts_edit.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
	ew_ClickAll(elem);
}
<?php if (EW_CLIENT_VALIDATE) { ?>
useraccounts_edit.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
useraccounts_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 $useraccounts->TableCaption() ?><br><br>
<a href="<?php echo $useraccounts->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$useraccounts_edit->ShowMessage();
?>
<form name="fuseraccountsedit" id="fuseraccountsedit" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return useraccounts_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="useraccounts">
<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 ($useraccounts->username->Visible) { // username ?>
	<tr<?php echo $useraccounts->username->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $useraccounts->username->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $useraccounts->username->CellAttributes() ?>><span id="el_username">
<div<?php echo $useraccounts->username->ViewAttributes() ?>><?php echo $useraccounts->username->EditValue ?></div><input type="hidden" name="x_username" id="x_username" value="<?php echo ew_HtmlEncode($useraccounts->username->CurrentValue) ?>">
</span><?php echo $useraccounts->username->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($useraccounts->password->Visible) { // password ?>
	<tr<?php echo $useraccounts->password->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $useraccounts->password->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $useraccounts->password->CellAttributes() ?>><span id="el_password">
<input type="password" name="x_password" id="x_password" title="<?php echo $useraccounts->password->FldTitle() ?>" value="<?php echo $useraccounts->password->EditValue ?>" size="30" maxlength="35"<?php echo $useraccounts->password->EditAttributes() ?>>
</span><?php echo $useraccounts->password->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($useraccounts->userlevel->Visible) { // userlevel ?>
	<tr<?php echo $useraccounts->userlevel->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $useraccounts->userlevel->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $useraccounts->userlevel->CellAttributes() ?>><span id="el_userlevel">
<?php if (!$Security->IsAdmin() && $Security->IsLoggedIn()) { // Non system admin ?>
<div<?php echo $useraccounts->userlevel->ViewAttributes() ?>><?php echo $useraccounts->userlevel->EditValue ?></div>
<?php } else { ?>
<select id="x_userlevel" name="x_userlevel" title="<?php echo $useraccounts->userlevel->FldTitle() ?>"<?php echo $useraccounts->userlevel->EditAttributes() ?>>
<?php
if (is_array($useraccounts->userlevel->EditValue)) {
	$arwrk = $useraccounts->userlevel->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($useraccounts->userlevel->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 $useraccounts->userlevel->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($useraccounts->zemail->Visible) { // email ?>
	<tr<?php echo $useraccounts->zemail->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $useraccounts->zemail->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $useraccounts->zemail->CellAttributes() ?>><span id="el_zemail">
<input type="text" name="x_zemail" id="x_zemail" title="<?php echo $useraccounts->zemail->FldTitle() ?>" size="30" maxlength="50" value="<?php echo $useraccounts->zemail->EditValue ?>"<?php echo $useraccounts->zemail->EditAttributes() ?>>
</span><?php echo $useraccounts->zemail->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($useraccounts->Activated->Visible) { // Activated ?>
	<tr<?php echo $useraccounts->Activated->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $useraccounts->Activated->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $useraccounts->Activated->CellAttributes() ?>><span id="el_Activated">
<?php
$selwrk = (ew_ConvertToBool($useraccounts->Activated->CurrentValue)) ? " checked=\"checked\"" : "";
?>
<input type="checkbox" name="x_Activated[]" id="x_Activated[]" title="<?php echo $useraccounts->Activated->FldTitle() ?>" value="1"<?php echo $selwrk ?><?php echo $useraccounts->Activated->EditAttributes() ?>>
</span><?php echo $useraccounts->Activated->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
$useraccounts_edit->Page_Terminate();
?>
<?php

//
// Page class
//
class cuseraccounts_edit {

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

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

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

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

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

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

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

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

		// 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("useraccountslist.php");
		}
		$Security->UserID_Loading();
		if ($Security->IsLoggedIn()) $Security->LoadUserID();
		$Security->UserID_Loaded();
		if ($Security->IsLoggedIn() && $Security->CurrentUserID() == "") {
			$_SESSION[EW_SESSION_MESSAGE] = $Language->Phrase("NoPermission");
			$this->Page_Terminate("useraccountslist.php");
		}

		// 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, $useraccounts;

		// Load key from QueryString
		if (@$_GET["username"] <> "")
			$useraccounts->username->setQueryStringValue($_GET["username"]);
		if (@$_POST["a_edit"] <> "") {
			$useraccounts->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->LoadFormValues(); // Get form values

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

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

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

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

		// Get upload data
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $useraccounts;
		$useraccounts->username->setFormValue($objForm->GetValue("x_username"));
		$useraccounts->password->setFormValue($objForm->GetValue("x_password"));
		$useraccounts->userlevel->setFormValue($objForm->GetValue("x_userlevel"));
		$useraccounts->zemail->setFormValue($objForm->GetValue("x_zemail"));
		$useraccounts->Activated->setFormValue($objForm->GetValue("x_Activated"));
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $useraccounts;
		$this->LoadRow();
		$useraccounts->username->CurrentValue = $useraccounts->username->FormValue;
		$useraccounts->password->CurrentValue = $useraccounts->password->FormValue;
		$useraccounts->userlevel->CurrentValue = $useraccounts->userlevel->FormValue;
		$useraccounts->zemail->CurrentValue = $useraccounts->zemail->FormValue;
		$useraccounts->Activated->CurrentValue = $useraccounts->Activated->FormValue;
	}

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

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

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

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

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $useraccounts;
		$useraccounts->username->setDbValue($rs->fields('username'));
		$useraccounts->password->setDbValue($rs->fields('password'));
		$useraccounts->userlevel->setDbValue($rs->fields('userlevel'));
		$useraccounts->zemail->setDbValue($rs->fields('email'));
		$useraccounts->Activated->setDbValue($rs->fields('Activated'));
	}

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

		// Initialize URLs
		// Call Row_Rendering event

		$useraccounts->Row_Rendering();

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

		$useraccounts->username->CellCssStyle = ""; $useraccounts->username->CellCssClass = "";
		$useraccounts->username->CellAttrs = array(); $useraccounts->username->ViewAttrs = array(); $useraccounts->username->EditAttrs = array();

		// password
		$useraccounts->password->CellCssStyle = ""; $useraccounts->password->CellCssClass = "";
		$useraccounts->password->CellAttrs = array(); $useraccounts->password->ViewAttrs = array(); $useraccounts->password->EditAttrs = array();

		// userlevel
		$useraccounts->userlevel->CellCssStyle = ""; $useraccounts->userlevel->CellCssClass = "";
		$useraccounts->userlevel->CellAttrs = array(); $useraccounts->userlevel->ViewAttrs = array(); $useraccounts->userlevel->EditAttrs = array();

		// email
		$useraccounts->zemail->CellCssStyle = ""; $useraccounts->zemail->CellCssClass = "";
		$useraccounts->zemail->CellAttrs = array(); $useraccounts->zemail->ViewAttrs = array(); $useraccounts->zemail->EditAttrs = array();

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

			// username
			$useraccounts->username->ViewValue = $useraccounts->username->CurrentValue;
			$useraccounts->username->CssStyle = "";
			$useraccounts->username->CssClass = "";
			$useraccounts->username->ViewCustomAttributes = "";

			// password
			$useraccounts->password->ViewValue = "********";
			$useraccounts->password->CssStyle = "";
			$useraccounts->password->CssClass = "";
			$useraccounts->password->ViewCustomAttributes = "";

			// userlevel
			if ($Security->CanAdmin()) { // System admin
			if (strval($useraccounts->userlevel->CurrentValue) <> "") {
				switch ($useraccounts->userlevel->CurrentValue) {
					case "-1":
						$useraccounts->userlevel->ViewValue = "Administrator";
						break;
					case "0":
						$useraccounts->userlevel->ViewValue = "Default";
						break;
					default:
						$useraccounts->userlevel->ViewValue = $useraccounts->userlevel->CurrentValue;
				}
			} else {
				$useraccounts->userlevel->ViewValue = NULL;
			}
			} else {
				$useraccounts->userlevel->ViewValue = "********";
			}
			$useraccounts->userlevel->CssStyle = "";
			$useraccounts->userlevel->CssClass = "";
			$useraccounts->userlevel->ViewCustomAttributes = "";

			// email
			$useraccounts->zemail->ViewValue = $useraccounts->zemail->CurrentValue;
			$useraccounts->zemail->CssStyle = "";
			$useraccounts->zemail->CssClass = "";
			$useraccounts->zemail->ViewCustomAttributes = "";

			// Activated
			if (ew_ConvertToBool($useraccounts->Activated->CurrentValue)) {
				$useraccounts->Activated->ViewValue = "Y";
			} else {
				$useraccounts->Activated->ViewValue = "N";
			}
			$useraccounts->Activated->CssStyle = "";
			$useraccounts->Activated->CssClass = "";
			$useraccounts->Activated->ViewCustomAttributes = "";

			// username
			$useraccounts->username->HrefValue = "";
			$useraccounts->username->TooltipValue = "";

			// password
			$useraccounts->password->HrefValue = "";
			$useraccounts->password->TooltipValue = "";

			// userlevel
			$useraccounts->userlevel->HrefValue = "";
			$useraccounts->userlevel->TooltipValue = "";

			// email
			$useraccounts->zemail->HrefValue = "";
			$useraccounts->zemail->TooltipValue = "";

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

			// username
			$useraccounts->username->EditCustomAttributes = "";
			$useraccounts->username->EditValue = $useraccounts->username->CurrentValue;
			$useraccounts->username->CssStyle = "";
			$useraccounts->username->CssClass = "";
			$useraccounts->username->ViewCustomAttributes = "";

			// password
			$useraccounts->password->EditCustomAttributes = "";
			$useraccounts->password->EditValue = ew_HtmlEncode($useraccounts->password->CurrentValue);

			// userlevel
			$useraccounts->userlevel->EditCustomAttributes = "";
			if (!$Security->CanAdmin()) { // System admin
				$useraccounts->userlevel->EditValue = "********";
			} else {
			$arwrk = array();
			$arwrk[] = array("-1", "Administrator");
			$arwrk[] = array("0", "Default");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$useraccounts->userlevel->EditValue = $arwrk;
			}

			// email
			$useraccounts->zemail->EditCustomAttributes = "";
			$useraccounts->zemail->EditValue = ew_HtmlEncode($useraccounts->zemail->CurrentValue);

			// Activated
			$useraccounts->Activated->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("Y", "Y");
			$arwrk[] = array("N", "N");
			$useraccounts->Activated->EditValue = $arwrk;

			// Edit refer script
			// username

			$useraccounts->username->HrefValue = "";

			// password
			$useraccounts->password->HrefValue = "";

			// userlevel
			$useraccounts->userlevel->HrefValue = "";

			// email
			$useraccounts->zemail->HrefValue = "";

			// Activated
			$useraccounts->Activated->HrefValue = "";
		}

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

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

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

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

			// username
			// password

						if ($rs->fields('password') <> $useraccounts->password->CurrentValue) {
			$useraccounts->password->SetDbValueDef($rsnew, $useraccounts->password->CurrentValue, "", FALSE);
			}

			// userlevel
						if ($Security->CanAdmin()) { // System admin
			$useraccounts->userlevel->SetDbValueDef($rsnew, $useraccounts->userlevel->CurrentValue, 0, FALSE);
			}

			// email
			$useraccounts->zemail->SetDbValueDef($rsnew, $useraccounts->zemail->CurrentValue, "", FALSE);

			// Activated
			$tmpBool = $useraccounts->Activated->CurrentValue;
			if ($tmpBool <> "Y" && $tmpBool <> "N")
				$tmpBool = (!empty($tmpBool)) ? "Y" : "N";
			$useraccounts->Activated->SetDbValueDef($rsnew, $tmpBool, "N", FALSE);

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

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

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

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

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

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

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

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

	}

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

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

	}

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

		// Return error message in CustomError
		return TRUE;
	}
}
?>
Return current item: Science Lab Inventory & Order Management