/companyedit.php
PHP | 1152 lines | 799 code | 154 blank | 199 comment | 181 complexity | cecd8868252a4272d9bad49bd9c572e9 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- if (session_id() == "") session_start(); // Initialize Session data
- ob_start(); // Turn on output buffering
- ?>
- <?php include_once "ewcfg8.php" ?>
- <?php include_once "ewmysql8.php" ?>
- <?php include_once "phpfn8.php" ?>
- <?php include_once "companyinfo.php" ?>
- <?php include_once "userinfo.php" ?>
- <?php include_once "userfn8.php" ?>
- <?php ew_Header(FALSE) ?>
- <?php
-
- // Create page object
- $company_edit = new ccompany_edit();
- $Page =& $company_edit;
-
- // Page init
- $company_edit->Page_Init();
-
- // Page main
- $company_edit->Page_Main();
- ?>
- <?php include_once "header.php" ?>
- <script type="text/javascript">
- <!--
-
- // Create page object
- var company_edit = new ew_Page("company_edit");
-
- // page properties
- company_edit.PageID = "edit"; // page ID
- company_edit.FormID = "fcompanyedit"; // form ID
- var EW_PAGE_ID = company_edit.PageID; // for backward compatibility
-
- // extend page with ValidateForm function
- company_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 = 1;
- for (i=0; i<rowcnt; i++) {
- infix = "";
- elm = fobj.elements["x" + infix + "_id"];
- if (elm && !ew_CheckInteger(elm.value))
- return ew_OnError(this, elm, "<?php echo ew_JsEncode2($company->id->FldErrMsg()) ?>");
- elm = fobj.elements["x" + infix + "_name"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->name->FldCaption()) ?>");
- /*elm = fobj.elements["x" + infix + "_address"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->address->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_mobileno"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->mobileno->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_city"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->city->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_province"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->province->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_telno"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->telno->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_faxno"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->faxno->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_zemail"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->zemail->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_contact"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($company->contact->FldCaption()) ?>");
- */
- // Set up row object
- var row = {};
- row["index"] = infix;
- for (var j = 0; j < fobj.elements.length; j++) {
- var el = fobj.elements[j];
- var len = infix.length + 2;
- if (el.name.substr(0, len) == "x" + infix + "_") {
- var elname = "x_" + el.name.substr(len);
- if (ewLang.isObject(row[elname])) { // already exists
- if (ewLang.isArray(row[elname])) {
- row[elname][row[elname].length] = el; // add to array
- } else {
- row[elname] = [row[elname], el]; // convert to array
- }
- } else {
- row[elname] = el;
- }
- }
- }
- fobj.row = row;
-
- // Call Form Custom Validate event
- if (!this.Form_CustomValidate(fobj)) return false;
- }
-
- // Process detail page
- var detailpage = (fobj.detailpage) ? fobj.detailpage.value : "";
- if (detailpage != "") {
- return eval(detailpage+".ValidateForm(fobj)");
- }
- return true;
- }
-
- // extend page with Form_CustomValidate function
- company_edit.Form_CustomValidate =
- function(fobj) { // DO NOT CHANGE THIS LINE!
-
- // Your custom validation code here, return false if invalid.
- return true;
- }
- <?php if (EW_CLIENT_VALIDATE) { ?>
- company_edit.ValidateRequired = true; // uses JavaScript validation
- <?php } else { ?>
- company_edit.ValidateRequired = false; // no JavaScript validation
- <?php } ?>
-
- //-->
- </script>
- <script language="JavaScript" type="text/javascript">
- <!--
-
- // Write your client script here, no need to add script tags.
- //-->
-
- </script>
- <p class="phpmaker ewTitle"><?php echo $Language->Phrase("Edit") ?> <?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $company->TableCaption() ?></p>
- <p class="phpmaker"><a href="<?php echo $company->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></p>
- <?php $company_edit->ShowPageHeader(); ?>
- <?php
- $company_edit->ShowMessage();
- ?>
- <form name="fcompanyedit" id="fcompanyedit" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return company_edit.ValidateForm(this);">
- <p>
- <input type="hidden" name="a_table" id="a_table" value="company">
- <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 ($company->id->Visible) { // id ?>
- <tr id="r_id"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->id->FldCaption() ?></td>
- <td<?php echo $company->id->CellAttributes() ?>><span id="el_id">
- <div<?php echo $company->id->ViewAttributes() ?>><?php echo $company->id->EditValue ?></div>
- <input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($company->id->CurrentValue) ?>">
- </span><?php echo $company->id->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->name->Visible) { // name ?>
- <tr id="r_name"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->name->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
- <td<?php echo $company->name->CellAttributes() ?>><span id="el_name">
- <input type="text" name="x_name" id="x_name" size="30" maxlength="60" value="<?php echo $company->name->EditValue ?>"<?php echo $company->name->EditAttributes() ?>>
- </span><?php echo $company->name->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->address->Visible) { // address ?>
- <tr id="r_address"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->address->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $company->address->CellAttributes() ?>><span id="el_address">
- <textarea name="x_address" id="x_address" cols="35" rows="4"<?php echo $company->address->EditAttributes() ?>><?php echo $company->address->EditValue ?></textarea>
- </span><?php echo $company->address->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->city->Visible) { // city ?>
- <tr id="r_city"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->city->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $company->city->CellAttributes() ?>><span id="el_city">
- <select id="x_city" name="x_city"<?php echo $company->city->EditAttributes() ?>>
- <?php
- if (is_array($company->city->EditValue)) {
- $arwrk = $company->city->EditValue;
- $rowswrk = count($arwrk);
- $emptywrk = TRUE;
- for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
- $selwrk = (strval($company->city->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 $company->city->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->province->Visible) { // province ?>
- <tr id="r_province"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->province->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $company->province->CellAttributes() ?>><span id="el_province">
- <select id="x_province" name="x_province"<?php echo $company->province->EditAttributes() ?>>
- <?php
- if (is_array($company->province->EditValue)) {
- $arwrk = $company->province->EditValue;
- $rowswrk = count($arwrk);
- $emptywrk = TRUE;
- for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
- $selwrk = (strval($company->province->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 $company->province->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->telno->Visible) { // telno ?>
- <tr id="r_telno"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->telno->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $company->telno->CellAttributes() ?>><span id="el_telno">
- <input type="text" name="x_telno" id="x_telno" size="30" maxlength="20" value="<?php echo $company->telno->EditValue ?>"<?php echo $company->telno->EditAttributes() ?>>
- </span><?php echo $company->telno->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->mobileno->Visible) { // mobileno ?>
- <tr id="r_mobileno"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->mobileno->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $company->mobileno->CellAttributes() ?>><span id="el_mobileno">
- <input type="text" name="x_mobileno" id="x_mobileno" size="30" maxlength="20" value="<?php echo $company->mobileno->EditValue ?>"<?php echo $company->mobileno->EditAttributes() ?>>
- </span><?php echo $company->mobileno->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->faxno->Visible) { // faxno ?>
- <tr id="r_faxno"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->faxno->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $company->faxno->CellAttributes() ?>><span id="el_faxno">
- <input type="text" name="x_faxno" id="x_faxno" size="30" maxlength="20" value="<?php echo $company->faxno->EditValue ?>"<?php echo $company->faxno->EditAttributes() ?>>
- </span><?php echo $company->faxno->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->zemail->Visible) { // email ?>
- <tr id="r_zemail"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->zemail->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $company->zemail->CellAttributes() ?>><span id="el_zemail">
- <input type="text" name="x_zemail" id="x_zemail" size="30" maxlength="60" value="<?php echo $company->zemail->EditValue ?>"<?php echo $company->zemail->EditAttributes() ?>>
- </span><?php echo $company->zemail->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($company->contact->Visible) { // contact ?>
- <tr id="r_contact"<?php echo $company->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $company->contact->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $company->contact->CellAttributes() ?>><span id="el_contact">
- <input type="text" name="x_contact" id="x_contact" size="30" maxlength="60" value="<?php echo $company->contact->EditValue ?>"<?php echo $company->contact->EditAttributes() ?>>
- </span><?php echo $company->contact->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>
- <?php
- $company_edit->ShowPageFooter();
- if (EW_DEBUG_ENABLED)
- echo ew_DebugMsg();
- ?>
- <script language="JavaScript" type="text/javascript">
- <!--
-
- // Write your table-specific startup script here
- // document.write("page loaded");
- //-->
-
- </script>
- <?php include_once "footer.php" ?>
- <?php
- $company_edit->Page_Terminate();
- ?>
- <?php
-
- //
- // Page class
- //
- class ccompany_edit {
-
- // Page ID
- var $PageID = 'edit';
-
- // Table name
- var $TableName = 'company';
-
- // Page object name
- var $PageObjName = 'company_edit';
-
- // Page name
- function PageName() {
- return ew_CurrentPage();
- }
-
- // Page URL
- function PageUrl() {
- $PageUrl = ew_CurrentPage() . "?";
- global $company;
- if ($company->UseTokenInUrl) $PageUrl .= "t=" . $company->TableVar . "&"; // Add page token
- return $PageUrl;
- }
-
- // Message
- function getMessage() {
- return @$_SESSION[EW_SESSION_MESSAGE];
- }
-
- function setMessage($v) {
- ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
- }
-
- function getFailureMessage() {
- return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
- }
-
- function setFailureMessage($v) {
- ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
- }
-
- function getSuccessMessage() {
- return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
- }
-
- function setSuccessMessage($v) {
- ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
- }
-
- // Show message
- function ShowMessage() {
- $sMessage = $this->getMessage();
- $this->Message_Showing($sMessage, "");
- if ($sMessage <> "") { // Message in Session, display
- echo "<p class=\"ewMessage\">" . $sMessage . "</p>";
- $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
- }
-
- // Success message
- $sSuccessMessage = $this->getSuccessMessage();
- $this->Message_Showing($sSuccessMessage, "success");
- if ($sSuccessMessage <> "") { // Message in Session, display
- echo "<p class=\"ewSuccessMessage\">" . $sSuccessMessage . "</p>";
- $_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
- }
-
- // Failure message
- $sErrorMessage = $this->getFailureMessage();
- $this->Message_Showing($sErrorMessage, "failure");
- if ($sErrorMessage <> "") { // Message in Session, display
- echo "<p class=\"ewErrorMessage\">" . $sErrorMessage . "</p>";
- $_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
- }
- }
- var $PageHeader;
- var $PageFooter;
-
- // Show Page Header
- function ShowPageHeader() {
- $sHeader = $this->PageHeader;
- $this->Page_DataRendering($sHeader);
- if ($sHeader <> "") { // Header exists, display
- echo "<p class=\"phpmaker\">" . $sHeader . "</p>";
- }
- }
-
- // Show Page Footer
- function ShowPageFooter() {
- $sFooter = $this->PageFooter;
- $this->Page_DataRendered($sFooter);
- if ($sFooter <> "") { // Fotoer exists, display
- echo "<p class=\"phpmaker\">" . $sFooter . "</p>";
- }
- }
-
- // Validate page request
- function IsPageRequest() {
- global $objForm, $company;
- if ($company->UseTokenInUrl) {
- if ($objForm)
- return ($company->TableVar == $objForm->GetValue("t"));
- if (@$_GET["t"] <> "")
- return ($company->TableVar == $_GET["t"]);
- } else {
- return TRUE;
- }
- }
-
- //
- // Page class constructor
- //
- function ccompany_edit() {
- global $conn, $Language;
-
- // Language object
- if (!isset($Language)) $Language = new cLanguage();
-
- // Table object (company)
- if (!isset($GLOBALS["company"])) {
- $GLOBALS["company"] = new ccompany();
- $GLOBALS["Table"] =& $GLOBALS["company"];
- }
-
- // Table object (user)
- if (!isset($GLOBALS['user'])) $GLOBALS['user'] = new cuser();
-
- // 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", 'company', TRUE);
-
- // Start timer
- if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();
-
- // Open connection
- if (!isset($conn)) $conn = ew_Connect();
- }
-
- //
- // Page_Init
- //
- function Page_Init() {
- global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
- global $company;
-
- // 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("companylist.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();
- $this->Page_Redirecting($url);
-
- // Close connection
- $conn->Close();
-
- // Go to URL if specified
- if ($url <> "") {
- if (!EW_DEBUG_ENABLED && ob_get_length())
- ob_end_clean();
- header("Location: " . $url);
- }
- exit();
- }
- var $DbMasterFilter;
- var $DbDetailFilter;
-
- //
- // Page main
- //
- function Page_Main() {
- global $objForm, $Language, $gsFormError, $company;
-
- // Load key from QueryString
- if (@$_GET["id"] <> "")
- $company->id->setQueryStringValue($_GET["id"]);
- if (@$_POST["a_edit"] <> "") {
- $company->CurrentAction = $_POST["a_edit"]; // Get action code
- $this->LoadFormValues(); // Get form values
-
- // Validate form
- if (!$this->ValidateForm()) {
- $company->CurrentAction = ""; // Form error, reset action
- $this->setFailureMessage($gsFormError);
- $company->EventCancelled = TRUE; // Event cancelled
- $this->RestoreFormValues();
- }
- } else {
- $company->CurrentAction = "I"; // Default action is display
- }
-
- // Check if valid key
- if ($company->id->CurrentValue == "")
- $this->Page_Terminate("companylist.php"); // Invalid key, return to list
- switch ($company->CurrentAction) {
- case "I": // Get a record to display
- if (!$this->LoadRow()) { // Load record based on key
- $this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
- $this->Page_Terminate("companylist.php"); // No matching record, return to list
- }
- break;
- Case "U": // Update
- $company->SendEmail = TRUE; // Send email on update success
- if ($this->EditRow()) { // Update record based on key
- $this->setSuccessMessage($Language->Phrase("UpdateSuccess")); // Update success
- $sReturnUrl = $company->getReturnUrl();
- if (ew_GetPageName($sReturnUrl) == "companyview.php")
- $sReturnUrl = $company->ViewUrl(); // View paging, return to View page directly
- $this->Page_Terminate($sReturnUrl); // Return to caller
- } else {
- $company->EventCancelled = TRUE; // Event cancelled
- $this->RestoreFormValues(); // Restore form values if update failed
- }
- }
-
- // Render the record
- $company->RowType = EW_ROWTYPE_EDIT; // Render as Edit
- $company->ResetAttrs();
- $this->RenderRow();
- }
-
- // Get upload files
- function GetUploadFiles() {
- global $objForm, $company;
-
- // Get upload data
- $index = $objForm->Index; // Save form index
- $objForm->Index = 0;
- $confirmPage = (strval($objForm->GetValue("a_confirm")) <> "");
- $objForm->Index = $index; // Restore form index
- }
-
- // Load form values
- function LoadFormValues() {
-
- // Load from form
- global $objForm, $company;
- if (!$company->id->FldIsDetailKey)
- $company->id->setFormValue($objForm->GetValue("x_id"));
- if (!$company->name->FldIsDetailKey) {
- $company->name->setFormValue($objForm->GetValue("x_name"));
- }
- if (!$company->address->FldIsDetailKey) {
- $company->address->setFormValue($objForm->GetValue("x_address"));
- }
- if (!$company->city->FldIsDetailKey) {
- $company->city->setFormValue($objForm->GetValue("x_city"));
- }
- if (!$company->province->FldIsDetailKey) {
- $company->province->setFormValue($objForm->GetValue("x_province"));
- }
- if (!$company->telno->FldIsDetailKey) {
- $company->telno->setFormValue($objForm->GetValue("x_telno"));
- }
- if (!$company->mobileno->FldIsDetailKey) {
- $company->mobileno->setFormValue($objForm->GetValue("x_mobileno"));
- }
- if (!$company->faxno->FldIsDetailKey) {
- $company->faxno->setFormValue($objForm->GetValue("x_faxno"));
- }
- if (!$company->zemail->FldIsDetailKey) {
- $company->zemail->setFormValue($objForm->GetValue("x_zemail"));
- }
- if (!$company->contact->FldIsDetailKey) {
- $company->contact->setFormValue($objForm->GetValue("x_contact"));
- }
- }
-
- // Restore form values
- function RestoreFormValues() {
- global $objForm, $company;
- $this->LoadRow();
- $company->id->CurrentValue = $company->id->FormValue;
- $company->name->CurrentValue = $company->name->FormValue;
- $company->address->CurrentValue = $company->address->FormValue;
- $company->city->CurrentValue = $company->city->FormValue;
- $company->province->CurrentValue = $company->province->FormValue;
- $company->telno->CurrentValue = $company->telno->FormValue;
- $company->mobileno->CurrentValue = $company->mobileno->FormValue;
- $company->faxno->CurrentValue = $company->faxno->FormValue;
- $company->zemail->CurrentValue = $company->zemail->FormValue;
- $company->contact->CurrentValue = $company->contact->FormValue;
- }
-
- // Load row based on key values
- function LoadRow() {
- global $conn, $Security, $company;
- $sFilter = $company->KeyFilter();
-
- // Call Row Selecting event
- $company->Row_Selecting($sFilter);
-
- // Load SQL based on filter
- $company->CurrentFilter = $sFilter;
- $sSql = $company->SQL();
- $res = FALSE;
- $rs = ew_LoadRecordset($sSql);
- if ($rs && !$rs->EOF) {
- $res = TRUE;
- $this->LoadRowValues($rs); // Load row values
- $rs->Close();
- }
- return $res;
- }
-
- // Load row values from recordset
- function LoadRowValues(&$rs) {
- global $conn, $company;
- if (!$rs || $rs->EOF) return;
-
- // Call Row Selected event
- $row =& $rs->fields;
- $company->Row_Selected($row);
- $company->id->setDbValue($rs->fields('id'));
- $company->name->setDbValue($rs->fields('name'));
- $company->address->setDbValue($rs->fields('address'));
- $company->city->setDbValue($rs->fields('city'));
- $company->province->setDbValue($rs->fields('province'));
- $company->telno->setDbValue($rs->fields('telno'));
- $company->mobileno->setDbValue($rs->fields('mobileno'));
- $company->faxno->setDbValue($rs->fields('faxno'));
- $company->zemail->setDbValue($rs->fields('email'));
- $company->contact->setDbValue($rs->fields('contact'));
- $company->zuserid->setDbValue($rs->fields('userid'));
- $company->timestamp->setDbValue($rs->fields('timestamp'));
- }
-
- // Render row values based on field settings
- function RenderRow() {
- global $conn, $Security, $Language, $company;
-
- // Initialize URLs
- // Call Row_Rendering event
-
- $company->Row_Rendering();
-
- // Common render codes for all row types
- // id
- // name
- // address
- // city
- // province
- // telno
- // mobileno
- // faxno
- // email
- // contact
- // userid
- // timestamp
-
- if ($company->RowType == EW_ROWTYPE_VIEW) { // View row
-
- // id
- $company->id->ViewValue = $company->id->CurrentValue;
- $company->id->ViewCustomAttributes = "";
-
- // name
- $company->name->ViewValue = $company->name->CurrentValue;
- $company->name->ViewCustomAttributes = "";
-
- // address
- $company->address->ViewValue = $company->address->CurrentValue;
- $company->address->ViewCustomAttributes = "";
-
- // city
- if (strval($company->city->CurrentValue) <> "") {
- $sFilterWrk = "`id` = " . ew_AdjustSql($company->city->CurrentValue) . "";
- $sSqlWrk = "SELECT `city` FROM `city`";
- $sWhereWrk = "";
- if ($sFilterWrk <> "") {
- if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
- $sWhereWrk .= "(" . $sFilterWrk . ")";
- }
- if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
- $rswrk = $conn->Execute($sSqlWrk);
- if ($rswrk && !$rswrk->EOF) { // Lookup values found
- $company->city->ViewValue = $rswrk->fields('city');
- $rswrk->Close();
- } else {
- $company->city->ViewValue = $company->city->CurrentValue;
- }
- } else {
- $company->city->ViewValue = NULL;
- }
- $company->city->ViewCustomAttributes = "";
-
- // province
- if (strval($company->province->CurrentValue) <> "") {
- $sFilterWrk = "`id` = " . ew_AdjustSql($company->province->CurrentValue) . "";
- $sSqlWrk = "SELECT `province` FROM `province`";
- $sWhereWrk = "";
- if ($sFilterWrk <> "") {
- if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
- $sWhereWrk .= "(" . $sFilterWrk . ")";
- }
- if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
- $rswrk = $conn->Execute($sSqlWrk);
- if ($rswrk && !$rswrk->EOF) { // Lookup values found
- $company->province->ViewValue = $rswrk->fields('province');
- $rswrk->Close();
- } else {
- $company->province->ViewValue = $company->province->CurrentValue;
- }
- } else {
- $company->province->ViewValue = NULL;
- }
- $company->province->ViewCustomAttributes = "";
-
- // telno
- $company->telno->ViewValue = $company->telno->CurrentValue;
- $company->telno->ViewCustomAttributes = "";
-
- // mobileno
- $company->mobileno->ViewValue = $company->mobileno->CurrentValue;
- $company->mobileno->ViewCustomAttributes = "";
-
- // faxno
- $company->faxno->ViewValue = $company->faxno->CurrentValue;
- $company->faxno->ViewCustomAttributes = "";
-
- // email
- $company->zemail->ViewValue = $company->zemail->CurrentValue;
- $company->zemail->ViewCustomAttributes = "";
-
- // contact
- $company->contact->ViewValue = $company->contact->CurrentValue;
- $company->contact->ViewCustomAttributes = "";
-
- // userid
- $company->zuserid->ViewValue = $company->zuserid->CurrentValue;
- $company->zuserid->ViewCustomAttributes = "";
-
- // timestamp
- $company->timestamp->ViewValue = $company->timestamp->CurrentValue;
- $company->timestamp->ViewValue = ew_FormatDateTime($company->timestamp->ViewValue, 9);
- $company->timestamp->ViewCustomAttributes = "";
-
- // id
- $company->id->LinkCustomAttributes = "";
- $company->id->HrefValue = "";
- $company->id->TooltipValue = "";
-
- // name
- $company->name->LinkCustomAttributes = "";
- $company->name->HrefValue = "";
- $company->name->TooltipValue = "";
-
- // address
- $company->address->LinkCustomAttributes = "";
- $company->address->HrefValue = "";
- $company->address->TooltipValue = "";
-
- // city
- $company->city->LinkCustomAttributes = "";
- $company->city->HrefValue = "";
- $company->city->TooltipValue = "";
-
- // province
- $company->province->LinkCustomAttributes = "";
- $company->province->HrefValue = "";
- $company->province->TooltipValue = "";
-
- // telno
- $company->telno->LinkCustomAttributes = "";
- $company->telno->HrefValue = "";
- $company->telno->TooltipValue = "";
-
- // mobileno
- $company->mobileno->LinkCustomAttributes = "";
- $company->mobileno->HrefValue = "";
- $company->mobileno->TooltipValue = "";
-
- // faxno
- $company->faxno->LinkCustomAttributes = "";
- $company->faxno->HrefValue = "";
- $company->faxno->TooltipValue = "";
-
- // email
- $company->zemail->LinkCustomAttributes = "";
- $company->zemail->HrefValue = "";
- $company->zemail->TooltipValue = "";
-
- // contact
- $company->contact->LinkCustomAttributes = "";
- $company->contact->HrefValue = "";
- $company->contact->TooltipValue = "";
- } elseif ($company->RowType == EW_ROWTYPE_EDIT) { // Edit row
-
- // id
- $company->id->EditCustomAttributes = "";
- $company->id->EditValue = $company->id->CurrentValue;
- $company->id->ViewCustomAttributes = "";
-
- // name
- $company->name->EditCustomAttributes = "";
- $company->name->EditValue = ew_HtmlEncode($company->name->CurrentValue);
-
- // address
- $company->address->EditCustomAttributes = "";
- $company->address->EditValue = ew_HtmlEncode($company->address->CurrentValue);
-
- // city
- $company->city->EditCustomAttributes = "";
- $sFilterWrk = "";
- $sSqlWrk = "SELECT `id`, `city` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld` FROM `city`";
- $sWhereWrk = "";
- if ($sFilterWrk <> "") {
- if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
- $sWhereWrk .= "(" . $sFilterWrk . ")";
- }
- if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
- $rswrk = $conn->Execute($sSqlWrk);
- $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
- if ($rswrk) $rswrk->Close();
- array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
- $company->city->EditValue = $arwrk;
-
- // province
- $company->province->EditCustomAttributes = "";
- $sFilterWrk = "";
- $sSqlWrk = "SELECT `id`, `province` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld` FROM `province`";
- $sWhereWrk = "";
- if ($sFilterWrk <> "") {
- if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
- $sWhereWrk .= "(" . $sFilterWrk . ")";
- }
- if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
- $rswrk = $conn->Execute($sSqlWrk);
- $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
- if ($rswrk) $rswrk->Close();
- array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
- $company->province->EditValue = $arwrk;
-
- // telno
- $company->telno->EditCustomAttributes = "";
- $company->telno->EditValue = ew_HtmlEncode($company->telno->CurrentValue);
-
- // mobileno
- $company->mobileno->EditCustomAttributes = "";
- $company->mobileno->EditValue = ew_HtmlEncode($company->mobileno->CurrentValue);
-
- // faxno
- $company->faxno->EditCustomAttributes = "";
- $company->faxno->EditValue = ew_HtmlEncode($company->faxno->CurrentValue);
-
- // email
- $company->zemail->EditCustomAttributes = "";
- $company->zemail->EditValue = ew_HtmlEncode($company->zemail->CurrentValue);
-
- // contact
- $company->contact->EditCustomAttributes = "";
- $company->contact->EditValue = ew_HtmlEncode($company->contact->CurrentValue);
-
- // Edit refer script
- // id
-
- $company->id->HrefValue = "";
-
- // name
- $company->name->HrefValue = "";
-
- // address
- $company->address->HrefValue = "";
-
- // city
- $company->city->HrefValue = "";
-
- // province
- $company->province->HrefValue = "";
-
- // telno
- $company->telno->HrefValue = "";
-
- // mobileno
- $company->mobileno->HrefValue = "";
-
- // faxno
- $company->faxno->HrefValue = "";
-
- // email
- $company->zemail->HrefValue = "";
-
- // contact
- $company->contact->HrefValue = "";
- }
- if ($company->RowType == EW_ROWTYPE_ADD ||
- $company->RowType == EW_ROWTYPE_EDIT ||
- $company->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
- $company->SetupFieldTitles();
- }
-
- // Call Row Rendered event
- if ($company->RowType <> EW_ROWTYPE_AGGREGATEINIT)
- $company->Row_Rendered();
- }
-
- // Validate form
- function ValidateForm() {
- global $Language, $gsFormError, $company;
-
- // Initialize form error message
- $gsFormError = "";
-
- // Check if validation required
- if (!EW_SERVER_VALIDATE)
- return ($gsFormError == "");
- if (!ew_CheckInteger($company->id->FormValue)) {
- ew_AddMessage($gsFormError, $company->id->FldErrMsg());
- }
- if (!is_null($company->name->FormValue) && $company->name->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->name->FldCaption());
- }
- if (!is_null($company->address->FormValue) && $company->address->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->address->FldCaption());
- }
- if (!is_null($company->city->FormValue) && $company->city->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->city->FldCaption());
- }
- if (!is_null($company->province->FormValue) && $company->province->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->province->FldCaption());
- }
- if (!is_null($company->telno->FormValue) && $company->telno->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->telno->FldCaption());
- }
- if (!is_null($company->mobileno->FormValue) && $company->mobileno->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->mobileno->FldCaption());
- }
- if (!is_null($company->faxno->FormValue) && $company->faxno->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->faxno->FldCaption());
- }
- if (!is_null($company->zemail->FormValue) && $company->zemail->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->zemail->FldCaption());
- }
- if (!is_null($company->contact->FormValue) && $company->contact->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $company->contact->FldCaption());
- }
-
- // Return validate result
- $ValidateForm = ($gsFormError == "");
-
- // Call Form_CustomValidate event
- $sFormCustomError = "";
- $ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
- if ($sFormCustomError <> "") {
- ew_AddMessage($gsFormError, $sFormCustomError);
- }
- return $ValidateForm;
- }
-
- // Update record based on key values
- function EditRow() {
- global $conn, $Security, $Language, $company;
- $sFilter = $company->KeyFilter();
- $company->CurrentFilter = $sFilter;
- $sSql = $company->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
- $company->name->SetDbValueDef($rsnew, $company->name->CurrentValue, "", $company->name->ReadOnly);
-
- // address
- $company->address->SetDbValueDef($rsnew, $company->address->CurrentValue, "", $company->address->ReadOnly);
-
- // city
- $company->city->SetDbValueDef($rsnew, $company->city->CurrentValue, 0, $company->city->ReadOnly);
-
- // province
- $company->province->SetDbValueDef($rsnew, $company->province->CurrentValue, 0, $company->province->ReadOnly);
-
- // telno
- $company->telno->SetDbValueDef($rsnew, $company->telno->CurrentValue, "", $company->telno->ReadOnly);
-
- // mobileno
- $company->mobileno->SetDbValueDef($rsnew, $company->mobileno->CurrentValue, "", $company->mobileno->ReadOnly);
-
- // faxno
- $company->faxno->SetDbValueDef($rsnew, $company->faxno->CurrentValue, "", $company->faxno->ReadOnly);
-
- // email
- $company->zemail->SetDbValueDef($rsnew, $company->zemail->CurrentValue, "", $company->zemail->ReadOnly);
-
- // contact
- $company->contact->SetDbValueDef($rsnew, $company->contact->CurrentValue, "", $company->contact->ReadOnly);
-
- // Call Row Updating event
- $bUpdateRow = $company->Row_Updating($rsold, $rsnew);
- if ($bUpdateRow) {
- $conn->raiseErrorFn = 'ew_ErrorFn';
- if (count($rsnew) > 0)
- $EditRow = $conn->Execute($company->UpdateSQL($rsnew));
- else
- $EditRow = TRUE; // No field to update
- $conn->raiseErrorFn = '';
- } else {
- if ($company->CancelMessage <> "") {
- $this->setFailureMessage($company->CancelMessage);
- $company->CancelMessage = "";
- } else {
- $this->setFailureMessage($Language->Phrase("UpdateCancelled"));
- }
- $EditRow = FALSE;
- }
- }
-
- // Call Row_Updated event
- if ($EditRow)
- $company->Row_Updated($rsold, $rsnew);
- if ($EditRow) {
- $this->WriteAuditTrailOnEdit($rsold, $rsnew);
- }
- $rs->Close();
- return $EditRow;
- }
- // Write Audit Trail start/end for grid update
- function WriteAuditTrailDummy($typ) {
- $table = 'company';
- $usr = CurrentUserName();
- ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $typ, $table, "", "", "", "");
- }
-
- // Write Audit Trail (edit page)
- function WriteAuditTrailOnEdit(&$rsold, &$rsnew) {
- global $company;
- $table = 'company';
-
- // Get key value
- $key = "";
- if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
- $key .= $rsold['id'];
-
- // Write Audit Trail
- $dt = ew_StdCurrentDateTime();
- $id = ew_ScriptName();
- $usr = CurrentUserName();
- foreach (array_keys($rsnew) as $fldname) {
- if ($company->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore BLOB fields
- if ($company->fields[$fldname]->FldDataType == EW_DATATYPE_DATE) { // DateTime field
- $modified = (ew_FormatDateTime($rsold[$fldname], 0) <> ew_FormatDateTime($rsnew[$fldname], 0));
- } else {
- $modified = !ew_CompareValue($rsold[$fldname], $rsnew[$fldname]);
- }
- if ($modified) {
- if ($company->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // Memo field
- if (EW_AUDIT_TRAIL_TO_DATABASE) {
- $oldvalue = $rsold[$fldname];
- $newvalue = $rsnew[$fldname];
- } else {
- $oldvalue = "[MEMO]";
- $newvalue = "[MEMO]";
- }
- } elseif ($company->fields[$fldname]->FldDataType == EW_DATATYPE_XML) { // XML field
- $oldvalue = "[XML]";
- $newvalue = "[XML]";
- } else {
- $oldvalue = $rsold[$fldname];
- $newvalue = $rsnew[$fldname];
- }
- ew_WriteAuditTrail("log", $dt, $id, $usr, "U", $table, $fldname, $key, $oldvalue, $newvalue);
- }
- }
- }
- }
-
- // 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
- // $type = ''|'success'|'failure'
- function Message_Showing(&$msg, $type) {
-
- // Example:
- //if ($type == 'success') $msg = "your success message";
-
- }
-
- // Page Data Rendering event
- function Page_DataRendering(&$header) {
-
- // Example:
- //$header = "your header";
-
- }
-
- // Page Data Rendered event
- function Page_DataRendered(&$footer) {
-
- // Example:
- //$footer = "your footer";
-
- }
-
- // Form Custom Validate event
- function Form_CustomValidate(&$CustomError) {
-
- // Return error message in CustomError
- return TRUE;
- }
- }
- ?>