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

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

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

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

// page properties
register.PageID = "register"; // page ID
register.FormID = "fuseraccountsregister"; // form ID
var EW_PAGE_ID = register.PageID; // for backward compatibility

// extend page with ValidateForm function
register.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()) ?>");
		if (fobj.x_username && !ew_HasValue(fobj.x_username))
			return ew_OnError(this, fobj.x_username, ewLanguage.Phrase("EnterUserName"));
		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()) ?>");
		if (fobj.x_password && !ew_HasValue(fobj.x_password))
			return ew_OnError(this, fobj.x_password, ewLanguage.Phrase("EnterPassword"));
		if (fobj.c_password.value != fobj.x_password.value)
			return ew_OnError(this, fobj.c_password, ewLanguage.Phrase("MismatchPassword"));
		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
register.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
register.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
	ew_ClickAll(elem);
}
<?php if (EW_CLIENT_VALIDATE) { ?>
register.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
register.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("RegisterPage") ?><br><br>
<a href="login.php"><?php echo $Language->Phrase("BackToLogin") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$register->ShowMessage();
?>
<form name="fuseraccountsregister" id="fuseraccountsregister" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return register.ValidateForm(this);">
<p>
<input type="hidden" name="t" id="t" value="useraccounts">
<input type="hidden" name="a_register" id="a_register" value="A">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table class="ewTable">
	<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">
<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() ?>>
</span><?php echo $useraccounts->username->CustomMsg ?></td>
	</tr>
	<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>
	<tr<?php echo $useraccounts->password->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $Language->Phrase("Confirm") ?>&nbsp;<?php echo $useraccounts->password->FldCaption() ?></td>
		<td<?php echo $useraccounts->password->CellAttributes() ?>>
<input type="password" name="c_password" id="c_password" title="<?php echo $useraccounts->password->FldTitle() ?>" size="30" maxlength="35"<?php echo $useraccounts->password->EditAttributes() ?>>
</td>
	</tr>
	<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>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("RegisterBtn")) ?>">
</form>
<script language="JavaScript" type="text/javascript">
<!--

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

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

//
// Page class
//
class cregister {

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

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

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

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		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() {
		return TRUE;
	}

	//
	// Page class constructor
	//
	function cregister() {
		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", 'register', 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();

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

	//
	// Page main
	//
	function Page_Main() {
		global $conn, $Security, $Language, $gsFormError, $objForm, $useraccounts;
		$bUserExists = FALSE;
		if (@$_POST["a_register"] <> "") {

			// Get action
			$useraccounts->CurrentAction = $_POST["a_register"];
			$this->LoadFormValues(); // Get form values

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

		// Handle email activation
		if (@$_GET["action"] <> "") {
			$sAction = $_GET["action"];
			$sEmail = @$_GET["email"];
			$qs = new cQueryString();
			$sApprovalCode = $qs->getValue("code");
			if ($sEmail == TEAdecrypt($sApprovalCode, EW_RANDOM_KEY)) {
				if (strtolower($sAction) == "confirm") { // Email activation
					if ($this->ActivateEmail($sEmail)) { // Activate this email
						$this->setMessage($Language->Phrase("ActivateAccount")); // Set message acount activated

						// Auto login user from cookie values
						$sUsr = TEAdecrypt(@$_COOKIE[EW_PROJECT_NAME]['Username'], EW_RANDOM_KEY);
						$sPwd = TEAdecrypt(@$_COOKIE[EW_PROJECT_NAME]['Password'], EW_RANDOM_KEY);
						if ($Security->ValidateUser($sUsr, $sPwd, TRUE))
							$this->Page_Terminate("index.php"); // Go to return page
					}
				}
			}
			if ($this->getMessage() == "")
				$this->setMessage($Language0>Phrase("ActivateFailed")); // Set activate failed message
			$this->Page_Terminate("login.php"); // Go to login page
		}
		switch ($useraccounts->CurrentAction) {
			case "I": // Blank record, no action required
				break;
			case "A": // Add

				// Check for duplicate User ID
				$sFilter = str_replace("%u", ew_AdjustSql($useraccounts->username->CurrentValue), EW_USER_NAME_FILTER);

				// Set up filter (SQL WHERE clause) and get return SQL
				// SQL constructor in useraccounts class, useraccountsinfo.php

				$useraccounts->CurrentFilter = $sFilter;
				$sUserSql = $useraccounts->SQL();
				if ($rs = $conn->Execute($sUserSql)) {
					if (!$rs->EOF) {
						$bUserExists = TRUE;
						$this->RestoreFormValues(); // Restore form values
						$this->setMessage($Language->Phrase("UserExists")); // Set user exist message
					}
					$rs->Close();
				}
				if (!$bUserExists) {
					$useraccounts->SendEmail = TRUE; // Send email on add success
					if ($this->AddRow()) { // Add record

						// Load user email
						$sReceiverEmail = $useraccounts->zemail->CurrentValue;
						if ($sReceiverEmail == "") { // Send to recipient directly
							$sReceiverEmail = EW_RECIPIENT_EMAIL;
							$sBccEmail = "";
						} else { // Bcc recipient
							$sBccEmail = EW_RECIPIENT_EMAIL;
						}

						// Set up email content
						if ($sReceiverEmail <> "") {
							$Email = new cEmail;
							$Email->Load("txt/register.txt");
							$Email->ReplaceSender(EW_SENDER_EMAIL); // Replace Sender
							$Email->ReplaceRecipient($sReceiverEmail); // Replace Recipient
							if ($sBccEmail <> "") $Email->AddBcc($sBccEmail); // Add Bcc
							$Email->ReplaceContent('<!--FieldCaption_username-->', $useraccounts->username->FldCaption());
							$Email->ReplaceContent('<!--username-->', strval($useraccounts->username->CurrentValue));
							$Email->ReplaceContent('<!--FieldCaption_password-->', $useraccounts->password->FldCaption());
							$Email->ReplaceContent('<!--password-->', strval($useraccounts->password->CurrentValue));
							$Email->ReplaceContent('<!--FieldCaption_userlevel-->', $useraccounts->userlevel->FldCaption());
							$Email->ReplaceContent('<!--userlevel-->', strval($useraccounts->userlevel->CurrentValue));
							$Email->ReplaceContent('<!--FieldCaption_email-->', $useraccounts->zemail->FldCaption());
							$Email->ReplaceContent('<!--email-->', strval($useraccounts->zemail->CurrentValue));
							$sActivateLink = ew_FullUrl() . "?action=confirm";
							$sActivateLink .= "&email=" . $useraccounts->zemail->CurrentValue;
							$sActivateLink .= "&code=" . TEAencrypt($useraccounts->zemail->CurrentValue, EW_RANDOM_KEY);
							$Email->ReplaceContent("<!--ActivateLink-->", $sActivateLink);
							setcookie(EW_PROJECT_NAME . '[Username]', TEAencrypt($useraccounts->username->CurrentValue, EW_RANDOM_KEY), EW_COOKIE_EXPIRY_TIME); // Set up user name cookies
							setcookie(EW_PROJECT_NAME . '[Password]', TEAencrypt($useraccounts->password->FormValue, EW_RANDOM_KEY), EW_COOKIE_EXPIRY_TIME); // Set up password cookies
							$Email->Charset = EW_EMAIL_CHARSET;

							// Get new recordset
							$useraccounts->CurrentFilter = $useraccounts->KeyFilter();
							$sSql = $useraccounts->SQL();
							$rsnew = $conn->Execute($sSql);
							$Args = array();
							$Args["rs"] =& $rsnew;
							$bEmailSent = FALSE;
							if ($this->Email_Sending($Email, $Args))
								$bEmailSent = $Email->Send();

							// Send email failed
							if (!$bEmailSent)
								$this->setMessage($Email->SendErrDescription);
						}
						$this->setMessage($Language->Phrase("RegisterSuccessActivate")); // Activate success
						$this->Page_Terminate("index.php"); // Return
					} else {
						$this->RestoreFormValues(); // Restore form values
					}
				}
		}

		// Render row
		$useraccounts->RowType = EW_ROWTYPE_ADD; // Render add
		$this->RenderRow();
	}

	// Activate account based on email
	function ActivateEmail($email) {
		global $conn, $Language, $useraccounts;
		$sFilter = str_replace("%e", ew_AdjustSql($email), EW_USER_EMAIL_FILTER);
		$sSql = $useraccounts->GetSQL($sFilter, "");
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if (!$rs)
			return FALSE;
		if (!$rs->EOF) {
			$rsnew = $rs->fields;
			$rs->Close();
			$rsact = array('Activated' => "Y"); // Auto register
			$useraccounts->CurrentFilter = $sFilter;
			$res = $conn->Execute($useraccounts->UpdateSQL($rsact));
			if ($res) { // Call User Activated event
				$rsnew['Activated'] = "Y";
				$this->User_Activated($rsnew);
			}
			return $res;
		} else {
			$this->setMessage($Language->Phrase("NoRecord"));
			$rs->Close();
			return FALSE;
		}
	}

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

		// Get upload data
	}

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

	// 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->password->ConfirmValue = $objForm->GetValue("c_password");
		$useraccounts->userlevel->setFormValue($objForm->GetValue("x_userlevel"));
		$useraccounts->zemail->setFormValue($objForm->GetValue("x_zemail"));
	}

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

	// 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();
		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 = "";
		} elseif ($useraccounts->RowType == EW_ROWTYPE_ADD) { // Add row

			// username
			$useraccounts->username->EditCustomAttributes = "";
			$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);
		}

		// 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 ($useraccounts->username->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterUserName");
		}
		if (!is_null($useraccounts->password->FormValue) && $useraccounts->password->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $useraccounts->password->FldCaption();
		}
		if ($useraccounts->password->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterPassword");
		}
		if ($useraccounts->password->ConfirmValue <> $useraccounts->password->FormValue) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("MismatchPassword");
		}
		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
		$rsnew['userlevel'] = 7; // Set default User Level

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

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

			// Call User Registered event
			$this->User_Registered($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";

	}

	// Email Sending event
	function Email_Sending(&$Email, &$Args) {

		//var_dump($Email); var_dump($Args); exit();
		return TRUE;
	}

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

		// Return error message in CustomError
		return TRUE;
	}

	// User Registered event
	function User_Registered(&$rs) {

	  //echo "User_Registered";
	}

	// User Activated event
	function User_Activated(&$s) {

	  //echo "User_Activated";
	}
}
?>
Return current item: Science Lab Inventory & Order Management