Location: PHPKode > projects > Science Lab Inventory & Order Management > sciencelabinv/useraccountsadd.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_add = new cuseraccounts_add();
$Page =& $useraccounts_add;

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

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

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

// page properties
useraccounts_add.PageID = "add"; // page ID
useraccounts_add.FormID = "fuseraccountsadd"; // form ID
var EW_PAGE_ID = useraccounts_add.PageID; // for backward compatibility

// extend page with ValidateForm function
useraccounts_add.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_add.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
useraccounts_add.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
	ew_ClickAll(elem);
}
<?php if (EW_CLIENT_VALIDATE) { ?>
useraccounts_add.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
useraccounts_add.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("Add") ?>&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_add->ShowMessage();
?>
<form name="fuseraccountsadd" id="fuseraccountsadd" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return useraccounts_add.ValidateForm(this);">
<p>
<input type="hidden" name="t" id="t" value="useraccounts">
<input type="hidden" name="a_add" id="a_add" value="A">
<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">
<?php if (!$Security->IsAdmin() && $Security->IsLoggedIn()) { // Non system admin ?>
<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) ?>">
<?php } else { ?>
<input type="text" name="x_username" id="x_username" title="<?php echo $useraccounts->username->FldTitle() ?>" size="30" maxlength="50" value="<?php echo $useraccounts->username->EditValue ?>"<?php echo $useraccounts->username->EditAttributes() ?>>
<?php } ?>
</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() ?>" 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("AddBtn")) ?>">
</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_add->Page_Terminate();
?>
<?php

//
// Page class
//
class cuseraccounts_add {

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

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

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

	// 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_add() {
		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", 'add', 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->CanAdd()) {
			$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 = "";
	var $lPriv = 0;

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

		// Load key values from QueryString
		$bCopy = TRUE;
		if (@$_GET["username"] != "") {
		  $useraccounts->username->setQueryStringValue($_GET["username"]);
		} else {
		  $bCopy = FALSE;
		}

		// Process form if post back
		if (@$_POST["a_add"] <> "") {
		   $useraccounts->CurrentAction = $_POST["a_add"]; // Get form action
		  $this->LoadFormValues(); // Load form values

			// Validate form
			if (!$this->ValidateForm()) {
				$useraccounts->CurrentAction = "I"; // Form error, reset action
				$this->setMessage($gsFormError);
			}
		} else { // Not post back
		  if ($bCopy) {
		    $useraccounts->CurrentAction = "C"; // Copy record
		  } else {
		    $useraccounts->CurrentAction = "I"; // Display blank record
		    $this->LoadDefaultValues(); // Load default values
		  }
		}

		// Perform action based on action code
		switch ($useraccounts->CurrentAction) {
		  case "I": // Blank record, no action required
				break;
		  case "C": // Copy an existing record
		   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 "A": // ' Add new record
				$useraccounts->SendEmail = TRUE; // Send email on add success
		    if ($this->AddRow()) { // Add successful
		      $this->setMessage($Language->Phrase("AddSuccess")); // Set up success message
					$sReturnUrl = $useraccounts->getReturnUrl();
					if (ew_GetPageName($sReturnUrl) == "useraccountsview.php")
						$sReturnUrl = $useraccounts->ViewUrl(); // View paging, return to view page with keyurl directly
					$this->Page_Terminate($sReturnUrl); // Clean up and return
		    } else {
		      $this->RestoreFormValues(); // Add failed, restore form values
		    }
		}

		// Render row based on row type
		$useraccounts->RowType = EW_ROWTYPE_ADD;  // Render add type

		// Render row
		$this->RenderRow();
	}

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

		// Get upload data
	}

	// Load default values
	function LoadDefaultValues() {
		global $useraccounts;
		$useraccounts->userlevel->CurrentValue = 7;
		$useraccounts->Activated->CurrentValue = "N";
	}

	// 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;
		$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_ADD) { // Add row

			// username
			$useraccounts->username->EditCustomAttributes = "";
			if (!$Security->IsAdmin() && $Security->IsLoggedIn()) { // Non system admin
				$useraccounts->username->CurrentValue = $Security->CurrentUserID();
			$useraccounts->username->EditValue = $useraccounts->username->CurrentValue;
			$useraccounts->username->CssStyle = "";
			$useraccounts->username->CssClass = "";
			$useraccounts->username->ViewCustomAttributes = "";
			} else {
			$useraccounts->username->EditValue = ew_HtmlEncode($useraccounts->username->CurrentValue);
			}

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

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

	// Add record
	function AddRow() {
		global $conn, $Language, $Security, $useraccounts;

		// Check if valid User ID
		$bValidUser = FALSE;
		if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
			$bValidUser = $Security->IsValidUserID($useraccounts->username->CurrentValue);
			if (!$bValidUser) {
				$sUserIdMsg = str_replace("%c", CurrentUserID(), $Language->Phrase("UnAuthorizedUserID"));
				$sUserIdMsg = str_replace("%u", $useraccounts->username->CurrentValue, $sUserIdMsg);
				$this->setMessage($sUserIdMsg);				
				return FALSE;
			}
		}

		// Check if key value entered
		if ($useraccounts->username->CurrentValue == "") {
			$this->setMessage($Language->Phrase("InvalidKeyValue"));
			return FALSE;
		}

		// Check for duplicate key
		$bCheckKey = TRUE;
		$sFilter = $useraccounts->KeyFilter();
		if ($bCheckKey) {
			$rsChk = $useraccounts->LoadRs($sFilter);
			if ($rsChk && !$rsChk->EOF) {
				$sKeyErrMsg = str_replace("%f", $sFilter, $Language->Phrase("DupKey"));
				$this->setMessage($sKeyErrMsg);
				$rsChk->Close();
				return FALSE;
			}
		}
		$rsnew = array();

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

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

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

		// 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", TRUE);

		// Call Row Inserting event
		$bInsertRow = $useraccounts->Row_Inserting($rsnew);
		if ($bInsertRow) {
			$conn->raiseErrorFn = 'ew_ErrorFn';
			$AddRow = $conn->Execute($useraccounts->InsertSQL($rsnew));
			$conn->raiseErrorFn = '';
		} else {
			if ($useraccounts->CancelMessage <> "") {
				$this->setMessage($useraccounts->CancelMessage);
				$useraccounts->CancelMessage = "";
			} else {
				$this->setMessage($Language->Phrase("InsertCancelled"));
			}
			$AddRow = FALSE;
		}
		if ($AddRow) {

			// Call Row Inserted event
			$useraccounts->Row_Inserted($rsnew);
			if ($useraccounts->SendEmail)
				$this->SendEmailOnAdd($rsnew);
		}
		return $AddRow;
	}

	// Send email after add success
	function SendEmailOnAdd(&$rs) {
		global $Language, $useraccounts;
		$sFn = "txt/notify.txt";
		$sTable = 'useraccounts';
		$sSubject = $sTable . " " . $Language->Phrase("RecordInserted");
		$sAction = $Language->Phrase("ActionInserted");

		// Get key value
		$sKey = "";
		if ($sKey <> "") $sKey .= EW_COMPOSITE_KEY_SEPARATOR;
		$sKey .= $rs['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("rs" => $rs);
		$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