/cityedit.php
PHP | 1128 lines | 762 code | 155 blank | 211 comment | 173 complexity | 3d7161584cbc01b2044cdaa58791bdc5 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 "cityinfo.php" ?>
- <?php include_once "userinfo.php" ?>
- <?php include_once "userfn8.php" ?>
- <?php ew_Header(FALSE) ?>
- <?php
-
- // Create page object
- $city_edit = new ccity_edit();
- $Page =& $city_edit;
-
- // Page init
- $city_edit->Page_Init();
-
- // Page main
- $city_edit->Page_Main();
- ?>
- <?php include_once "header.php" ?>
- <script type="text/javascript">
- <!--
-
- // Create page object
- var city_edit = new ew_Page("city_edit");
-
- // page properties
- city_edit.PageID = "edit"; // page ID
- city_edit.FormID = "fcityedit"; // form ID
- var EW_PAGE_ID = city_edit.PageID; // for backward compatibility
-
- // extend page with ValidateForm function
- city_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_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->id->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_id"];
- if (elm && !ew_CheckInteger(elm.value))
- return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->id->FldErrMsg()) ?>");
- elm = fobj.elements["x" + infix + "_city_1"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->city_1->FldCaption()) ?>");
- /*elm = fobj.elements["x" + infix + "_citycontact"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->citycontact->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_cityhalladdress"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhalladdress->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_cityhalltelno"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhalltelno->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_cityhalllatitude"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhalllatitude->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_cityhalllatitude"];
- if (elm && !ew_CheckNumber(elm.value))
- return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->cityhalllatitude->FldErrMsg()) ?>");
- elm = fobj.elements["x" + infix + "_cityhalllongitude"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhalllongitude->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_cityhalllongitude"];
- if (elm && !ew_CheckNumber(elm.value))
- return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->cityhalllongitude->FldErrMsg()) ?>");
- elm = fobj.elements["x" + infix + "_cityhallaltitude"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhallaltitude->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_cityhallaltitude"];
- if (elm && !ew_CheckNumber(elm.value))
- return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->cityhallaltitude->FldErrMsg()) ?>");
- elm = fobj.elements["x" + infix + "_provinceid"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->provinceid->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_citycode"];
- if (elm && !ew_HasValue(elm))
- return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->citycode->FldCaption()) ?>");
- elm = fobj.elements["x" + infix + "_citycode"];
- if (elm && !ew_CheckInteger(elm.value))
- return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->citycode->FldErrMsg()) ?>");
- */
- // 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
- city_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) { ?>
- city_edit.ValidateRequired = true; // uses JavaScript validation
- <?php } else { ?>
- city_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 $city->TableCaption() ?></p>
- <p class="phpmaker"><a href="<?php echo $city->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></p>
- <?php $city_edit->ShowPageHeader(); ?>
- <?php
- $city_edit->ShowMessage();
- ?>
- <form name="fcityedit" id="fcityedit" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return city_edit.ValidateForm(this);">
- <p>
- <input type="hidden" name="a_table" id="a_table" value="city">
- <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 ($city->id->Visible) { // id ?>
- <tr id="r_id"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
- <td<?php echo $city->id->CellAttributes() ?>><span id="el_id">
- <div<?php echo $city->id->ViewAttributes() ?>><?php echo $city->id->EditValue ?></div>
- <input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($city->id->CurrentValue) ?>">
- </span><?php echo $city->id->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($city->city_1->Visible) { // city ?>
- <tr id="r_city_1"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->city_1->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
- <td<?php echo $city->city_1->CellAttributes() ?>><span id="el_city_1">
- <input type="text" name="x_city_1" id="x_city_1" size="30" maxlength="20" value="<?php echo $city->city_1->EditValue ?>"<?php echo $city->city_1->EditAttributes() ?>>
- </span><?php echo $city->city_1->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($city->citycontact->Visible) { // citycontact ?>
- <tr id="r_citycontact"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->citycontact->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $city->citycontact->CellAttributes() ?>><span id="el_citycontact">
- <input type="text" name="x_citycontact" id="x_citycontact" size="30" maxlength="20" value="<?php echo $city->citycontact->EditValue ?>"<?php echo $city->citycontact->EditAttributes() ?>>
- </span><?php echo $city->citycontact->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($city->cityhalladdress->Visible) { // cityhalladdress ?>
- <tr id="r_cityhalladdress"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->cityhalladdress->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $city->cityhalladdress->CellAttributes() ?>><span id="el_cityhalladdress">
- <textarea name="x_cityhalladdress" id="x_cityhalladdress" cols="35" rows="4"<?php echo $city->cityhalladdress->EditAttributes() ?>><?php echo $city->cityhalladdress->EditValue ?></textarea>
- </span><?php echo $city->cityhalladdress->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($city->cityhalltelno->Visible) { // cityhalltelno ?>
- <tr id="r_cityhalltelno"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->cityhalltelno->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $city->cityhalltelno->CellAttributes() ?>><span id="el_cityhalltelno">
- <input type="text" name="x_cityhalltelno" id="x_cityhalltelno" size="30" maxlength="20" value="<?php echo $city->cityhalltelno->EditValue ?>"<?php echo $city->cityhalltelno->EditAttributes() ?>>
- </span><?php echo $city->cityhalltelno->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($city->cityhalllatitude->Visible) { // cityhalllatitude ?>
- <tr id="r_cityhalllatitude"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->cityhalllatitude->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $city->cityhalllatitude->CellAttributes() ?>><span id="el_cityhalllatitude">
- <input type="text" name="x_cityhalllatitude" id="x_cityhalllatitude" size="30" value="<?php echo $city->cityhalllatitude->EditValue ?>"<?php echo $city->cityhalllatitude->EditAttributes() ?>>
- </span><?php echo $city->cityhalllatitude->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($city->cityhalllongitude->Visible) { // cityhalllongitude ?>
- <tr id="r_cityhalllongitude"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->cityhalllongitude->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $city->cityhalllongitude->CellAttributes() ?>><span id="el_cityhalllongitude">
- <input type="text" name="x_cityhalllongitude" id="x_cityhalllongitude" size="30" value="<?php echo $city->cityhalllongitude->EditValue ?>"<?php echo $city->cityhalllongitude->EditAttributes() ?>>
- </span><?php echo $city->cityhalllongitude->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($city->cityhallaltitude->Visible) { // cityhallaltitude ?>
- <tr id="r_cityhallaltitude"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->cityhallaltitude->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $city->cityhallaltitude->CellAttributes() ?>><span id="el_cityhallaltitude">
- <input type="text" name="x_cityhallaltitude" id="x_cityhallaltitude" size="30" value="<?php echo $city->cityhallaltitude->EditValue ?>"<?php echo $city->cityhallaltitude->EditAttributes() ?>>
- </span><?php echo $city->cityhallaltitude->CustomMsg ?></td>
- </tr>
- <?php } ?>
- <?php if ($city->provinceid->Visible) { // provinceid ?>
- <tr id="r_provinceid"<?php echo $city->RowAttributes() ?>>
- <td class="ewTableHeader"><?php echo $city->provinceid->FldCaption() ?><!-- Removed Required Field Indicator--></td>
- <td<?php echo $city->provinceid->CellAttributes() ?>><span id="el_provinceid">
- <select id="x_provinceid" name="x_provinceid"<?php echo $city->provinceid->EditAttributes() ?>>
- <?php
- if (is_array($city->provinceid->EditValue)) {
- $arwrk = $city->provinceid->EditValue;
- $rowswrk = count($arwrk);
- $emptywrk = TRUE;
- for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
- $selwrk = (strval($city->provinceid->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 $city->provinceid->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
- $city_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
- $city_edit->Page_Terminate();
- ?>
- <?php
-
- //
- // Page class
- //
- class ccity_edit {
-
- // Page ID
- var $PageID = 'edit';
-
- // Table name
- var $TableName = 'city';
-
- // Page object name
- var $PageObjName = 'city_edit';
-
- // Page name
- function PageName() {
- return ew_CurrentPage();
- }
-
- // Page URL
- function PageUrl() {
- $PageUrl = ew_CurrentPage() . "?";
- global $city;
- if ($city->UseTokenInUrl) $PageUrl .= "t=" . $city->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, $city;
- if ($city->UseTokenInUrl) {
- if ($objForm)
- return ($city->TableVar == $objForm->GetValue("t"));
- if (@$_GET["t"] <> "")
- return ($city->TableVar == $_GET["t"]);
- } else {
- return TRUE;
- }
- }
-
- //
- // Page class constructor
- //
- function ccity_edit() {
- global $conn, $Language;
-
- // Language object
- if (!isset($Language)) $Language = new cLanguage();
-
- // Table object (city)
- if (!isset($GLOBALS["city"])) {
- $GLOBALS["city"] = new ccity();
- $GLOBALS["Table"] =& $GLOBALS["city"];
- }
-
- // 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", 'city', 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 $city;
-
- // 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("citylist.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, $city;
-
- // Load key from QueryString
- if (@$_GET["id"] <> "")
- $city->id->setQueryStringValue($_GET["id"]);
- if (@$_POST["a_edit"] <> "") {
- $city->CurrentAction = $_POST["a_edit"]; // Get action code
- $this->LoadFormValues(); // Get form values
-
- // Validate form
- if (!$this->ValidateForm()) {
- $city->CurrentAction = ""; // Form error, reset action
- $this->setFailureMessage($gsFormError);
- $city->EventCancelled = TRUE; // Event cancelled
- $this->RestoreFormValues();
- }
- } else {
- $city->CurrentAction = "I"; // Default action is display
- }
-
- // Check if valid key
- if ($city->id->CurrentValue == "")
- $this->Page_Terminate("citylist.php"); // Invalid key, return to list
- switch ($city->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("citylist.php"); // No matching record, return to list
- }
- break;
- Case "U": // Update
- $city->SendEmail = TRUE; // Send email on update success
- if ($this->EditRow()) { // Update record based on key
- $this->setSuccessMessage($Language->Phrase("UpdateSuccess")); // Update success
- $sReturnUrl = $city->getReturnUrl();
- if (ew_GetPageName($sReturnUrl) == "cityview.php")
- $sReturnUrl = $city->ViewUrl(); // View paging, return to View page directly
- $this->Page_Terminate($sReturnUrl); // Return to caller
- } else {
- $city->EventCancelled = TRUE; // Event cancelled
- $this->RestoreFormValues(); // Restore form values if update failed
- }
- }
-
- // Render the record
- $city->RowType = EW_ROWTYPE_EDIT; // Render as Edit
- $city->ResetAttrs();
- $this->RenderRow();
- }
-
- // Get upload files
- function GetUploadFiles() {
- global $objForm, $city;
-
- // 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, $city;
- if (!$city->id->FldIsDetailKey)
- $city->id->setFormValue($objForm->GetValue("x_id"));
- if (!$city->city_1->FldIsDetailKey) {
- $city->city_1->setFormValue($objForm->GetValue("x_city_1"));
- }
- if (!$city->citycontact->FldIsDetailKey) {
- $city->citycontact->setFormValue($objForm->GetValue("x_citycontact"));
- }
- if (!$city->cityhalladdress->FldIsDetailKey) {
- $city->cityhalladdress->setFormValue($objForm->GetValue("x_cityhalladdress"));
- }
- if (!$city->cityhalltelno->FldIsDetailKey) {
- $city->cityhalltelno->setFormValue($objForm->GetValue("x_cityhalltelno"));
- }
- if (!$city->cityhalllatitude->FldIsDetailKey) {
- $city->cityhalllatitude->setFormValue($objForm->GetValue("x_cityhalllatitude"));
- }
- if (!$city->cityhalllongitude->FldIsDetailKey) {
- $city->cityhalllongitude->setFormValue($objForm->GetValue("x_cityhalllongitude"));
- }
- if (!$city->cityhallaltitude->FldIsDetailKey) {
- $city->cityhallaltitude->setFormValue($objForm->GetValue("x_cityhallaltitude"));
- }
- if (!$city->provinceid->FldIsDetailKey) {
- $city->provinceid->setFormValue($objForm->GetValue("x_provinceid"));
- }
- if (!$city->citycode->FldIsDetailKey) {
- $city->citycode->setFormValue($objForm->GetValue("x_citycode"));
- }
- }
-
- // Restore form values
- function RestoreFormValues() {
- global $objForm, $city;
- $this->LoadRow();
- $city->id->CurrentValue = $city->id->FormValue;
- $city->city_1->CurrentValue = $city->city_1->FormValue;
- $city->citycontact->CurrentValue = $city->citycontact->FormValue;
- $city->cityhalladdress->CurrentValue = $city->cityhalladdress->FormValue;
- $city->cityhalltelno->CurrentValue = $city->cityhalltelno->FormValue;
- $city->cityhalllatitude->CurrentValue = $city->cityhalllatitude->FormValue;
- $city->cityhalllongitude->CurrentValue = $city->cityhalllongitude->FormValue;
- $city->cityhallaltitude->CurrentValue = $city->cityhallaltitude->FormValue;
- $city->provinceid->CurrentValue = $city->provinceid->FormValue;
- $city->citycode->CurrentValue = $city->citycode->FormValue;
- }
-
- // Load row based on key values
- function LoadRow() {
- global $conn, $Security, $city;
- $sFilter = $city->KeyFilter();
-
- // Call Row Selecting event
- $city->Row_Selecting($sFilter);
-
- // Load SQL based on filter
- $city->CurrentFilter = $sFilter;
- $sSql = $city->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, $city;
- if (!$rs || $rs->EOF) return;
-
- // Call Row Selected event
- $row =& $rs->fields;
- $city->Row_Selected($row);
- $city->id->setDbValue($rs->fields('id'));
- $city->city_1->setDbValue($rs->fields('city'));
- $city->citycontact->setDbValue($rs->fields('citycontact'));
- $city->cityhalladdress->setDbValue($rs->fields('cityhalladdress'));
- $city->cityhalltelno->setDbValue($rs->fields('cityhalltelno'));
- $city->cityhalllatitude->setDbValue($rs->fields('cityhalllatitude'));
- $city->cityhalllongitude->setDbValue($rs->fields('cityhalllongitude'));
- $city->cityhallaltitude->setDbValue($rs->fields('cityhallaltitude'));
- $city->provinceid->setDbValue($rs->fields('provinceid'));
- $city->zuserid->setDbValue($rs->fields('userid'));
- $city->timestamp->setDbValue($rs->fields('timestamp'));
- $city->citycode->setDbValue($rs->fields('citycode'));
- }
-
- // Render row values based on field settings
- function RenderRow() {
- global $conn, $Security, $Language, $city;
-
- // Initialize URLs
- // Call Row_Rendering event
-
- $city->Row_Rendering();
-
- // Common render codes for all row types
- // id
- // city
- // citycontact
- // cityhalladdress
- // cityhalltelno
- // cityhalllatitude
- // cityhalllongitude
- // cityhallaltitude
- // provinceid
- // userid
- // timestamp
- // citycode
-
- if ($city->RowType == EW_ROWTYPE_VIEW) { // View row
-
- // id
- $city->id->ViewValue = $city->id->CurrentValue;
- $city->id->ViewCustomAttributes = "";
-
- // city
- $city->city_1->ViewValue = $city->city_1->CurrentValue;
- $city->city_1->ViewCustomAttributes = "";
-
- // citycontact
- $city->citycontact->ViewValue = $city->citycontact->CurrentValue;
- $city->citycontact->ViewCustomAttributes = "";
-
- // cityhalladdress
- $city->cityhalladdress->ViewValue = $city->cityhalladdress->CurrentValue;
- $city->cityhalladdress->ViewCustomAttributes = "";
-
- // cityhalltelno
- $city->cityhalltelno->ViewValue = $city->cityhalltelno->CurrentValue;
- $city->cityhalltelno->ViewCustomAttributes = "";
-
- // cityhalllatitude
- $city->cityhalllatitude->ViewValue = $city->cityhalllatitude->CurrentValue;
- $city->cityhalllatitude->ViewCustomAttributes = "";
-
- // cityhalllongitude
- $city->cityhalllongitude->ViewValue = $city->cityhalllongitude->CurrentValue;
- $city->cityhalllongitude->ViewCustomAttributes = "";
-
- // cityhallaltitude
- $city->cityhallaltitude->ViewValue = $city->cityhallaltitude->CurrentValue;
- $city->cityhallaltitude->ViewCustomAttributes = "";
-
- // provinceid
- if (strval($city->provinceid->CurrentValue) <> "") {
- $sFilterWrk = "`id` = " . ew_AdjustSql($city->provinceid->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
- $city->provinceid->ViewValue = $rswrk->fields('province');
- $rswrk->Close();
- } else {
- $city->provinceid->ViewValue = $city->provinceid->CurrentValue;
- }
- } else {
- $city->provinceid->ViewValue = NULL;
- }
- $city->provinceid->ViewCustomAttributes = "";
-
- // userid
- $city->zuserid->ViewValue = $city->zuserid->CurrentValue;
- $city->zuserid->ViewCustomAttributes = "";
-
- // timestamp
- $city->timestamp->ViewValue = $city->timestamp->CurrentValue;
- $city->timestamp->ViewValue = ew_FormatDateTime($city->timestamp->ViewValue, 9);
- $city->timestamp->ViewCustomAttributes = "";
-
- // citycode
- $city->citycode->ViewValue = $city->citycode->CurrentValue;
- $city->citycode->ViewCustomAttributes = "";
-
- // id
- $city->id->LinkCustomAttributes = "";
- $city->id->HrefValue = "";
- $city->id->TooltipValue = "";
-
- // city
- $city->city_1->LinkCustomAttributes = "";
- $city->city_1->HrefValue = "";
- $city->city_1->TooltipValue = "";
-
- // citycontact
- $city->citycontact->LinkCustomAttributes = "";
- $city->citycontact->HrefValue = "";
- $city->citycontact->TooltipValue = "";
-
- // cityhalladdress
- $city->cityhalladdress->LinkCustomAttributes = "";
- $city->cityhalladdress->HrefValue = "";
- $city->cityhalladdress->TooltipValue = "";
-
- // cityhalltelno
- $city->cityhalltelno->LinkCustomAttributes = "";
- $city->cityhalltelno->HrefValue = "";
- $city->cityhalltelno->TooltipValue = "";
-
- // cityhalllatitude
- $city->cityhalllatitude->LinkCustomAttributes = "";
- $city->cityhalllatitude->HrefValue = "";
- $city->cityhalllatitude->TooltipValue = "";
-
- // cityhalllongitude
- $city->cityhalllongitude->LinkCustomAttributes = "";
- $city->cityhalllongitude->HrefValue = "";
- $city->cityhalllongitude->TooltipValue = "";
-
- // cityhallaltitude
- $city->cityhallaltitude->LinkCustomAttributes = "";
- $city->cityhallaltitude->HrefValue = "";
- $city->cityhallaltitude->TooltipValue = "";
-
- // provinceid
- $city->provinceid->LinkCustomAttributes = "";
- $city->provinceid->HrefValue = "";
- $city->provinceid->TooltipValue = "";
-
- // citycode
- $city->citycode->LinkCustomAttributes = "";
- $city->citycode->HrefValue = "";
- $city->citycode->TooltipValue = "";
- } elseif ($city->RowType == EW_ROWTYPE_EDIT) { // Edit row
-
- // id
- $city->id->EditCustomAttributes = "";
- $city->id->EditValue = $city->id->CurrentValue;
- $city->id->ViewCustomAttributes = "";
-
- // city
- $city->city_1->EditCustomAttributes = "";
- $city->city_1->EditValue = ew_HtmlEncode($city->city_1->CurrentValue);
-
- // citycontact
- $city->citycontact->EditCustomAttributes = "";
- $city->citycontact->EditValue = ew_HtmlEncode($city->citycontact->CurrentValue);
-
- // cityhalladdress
- $city->cityhalladdress->EditCustomAttributes = "";
- $city->cityhalladdress->EditValue = ew_HtmlEncode($city->cityhalladdress->CurrentValue);
-
- // cityhalltelno
- $city->cityhalltelno->EditCustomAttributes = "";
- $city->cityhalltelno->EditValue = ew_HtmlEncode($city->cityhalltelno->CurrentValue);
-
- // cityhalllatitude
- $city->cityhalllatitude->EditCustomAttributes = "";
- $city->cityhalllatitude->EditValue = ew_HtmlEncode($city->cityhalllatitude->CurrentValue);
-
- // cityhalllongitude
- $city->cityhalllongitude->EditCustomAttributes = "";
- $city->cityhalllongitude->EditValue = ew_HtmlEncode($city->cityhalllongitude->CurrentValue);
-
- // cityhallaltitude
- $city->cityhallaltitude->EditCustomAttributes = "";
- $city->cityhallaltitude->EditValue = ew_HtmlEncode($city->cityhallaltitude->CurrentValue);
-
- // provinceid
- $city->provinceid->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")));
- $city->provinceid->EditValue = $arwrk;
-
- // citycode
- $city->citycode->EditCustomAttributes = "";
- $city->citycode->EditValue = ew_HtmlEncode($city->citycode->CurrentValue);
-
- // Edit refer script
- // id
-
- $city->id->HrefValue = "";
-
- // city
- $city->city_1->HrefValue = "";
-
- // citycontact
- $city->citycontact->HrefValue = "";
-
- // cityhalladdress
- $city->cityhalladdress->HrefValue = "";
-
- // cityhalltelno
- $city->cityhalltelno->HrefValue = "";
-
- // cityhalllatitude
- $city->cityhalllatitude->HrefValue = "";
-
- // cityhalllongitude
- $city->cityhalllongitude->HrefValue = "";
-
- // cityhallaltitude
- $city->cityhallaltitude->HrefValue = "";
-
- // provinceid
- $city->provinceid->HrefValue = "";
-
- // citycode
- $city->citycode->HrefValue = "";
- }
- if ($city->RowType == EW_ROWTYPE_ADD ||
- $city->RowType == EW_ROWTYPE_EDIT ||
- $city->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
- $city->SetupFieldTitles();
- }
-
- // Call Row Rendered event
- if ($city->RowType <> EW_ROWTYPE_AGGREGATEINIT)
- $city->Row_Rendered();
- }
-
- // Validate form
- function ValidateForm() {
- global $Language, $gsFormError, $city;
-
- // Initialize form error message
- $gsFormError = "";
-
- // Check if validation required
- if (!EW_SERVER_VALIDATE)
- return ($gsFormError == "");
- if (!is_null($city->id->FormValue) && $city->id->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->id->FldCaption());
- }
- if (!ew_CheckInteger($city->id->FormValue)) {
- ew_AddMessage($gsFormError, $city->id->FldErrMsg());
- }
- if (!is_null($city->city_1->FormValue) && $city->city_1->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->city_1->FldCaption());
- }
- if (!is_null($city->citycontact->FormValue) && $city->citycontact->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->citycontact->FldCaption());
- }
- if (!is_null($city->cityhalladdress->FormValue) && $city->cityhalladdress->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhalladdress->FldCaption());
- }
- if (!is_null($city->cityhalltelno->FormValue) && $city->cityhalltelno->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhalltelno->FldCaption());
- }
- if (!is_null($city->cityhalllatitude->FormValue) && $city->cityhalllatitude->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhalllatitude->FldCaption());
- }
- if (!ew_CheckNumber($city->cityhalllatitude->FormValue)) {
- ew_AddMessage($gsFormError, $city->cityhalllatitude->FldErrMsg());
- }
- if (!is_null($city->cityhalllongitude->FormValue) && $city->cityhalllongitude->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhalllongitude->FldCaption());
- }
- if (!ew_CheckNumber($city->cityhalllongitude->FormValue)) {
- ew_AddMessage($gsFormError, $city->cityhalllongitude->FldErrMsg());
- }
- if (!is_null($city->cityhallaltitude->FormValue) && $city->cityhallaltitude->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhallaltitude->FldCaption());
- }
- if (!ew_CheckNumber($city->cityhallaltitude->FormValue)) {
- ew_AddMessage($gsFormError, $city->cityhallaltitude->FldErrMsg());
- }
- if (!is_null($city->provinceid->FormValue) && $city->provinceid->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->provinceid->FldCaption());
- }
- if (!is_null($city->citycode->FormValue) && $city->citycode->FormValue == "") {
- ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->citycode->FldCaption());
- }
- if (!ew_CheckInteger($city->citycode->FormValue)) {
- ew_AddMessage($gsFormError, $city->citycode->FldErrMsg());
- }
-
- // 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, $city;
- $sFilter = $city->KeyFilter();
- $city->CurrentFilter = $sFilter;
- $sSql = $city->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();
-
- // city
- $city->city_1->SetDbValueDef($rsnew, $city->city_1->CurrentValue, "", $city->city_1->ReadOnly);
-
- // citycontact
- $city->citycontact->SetDbValueDef($rsnew, $city->citycontact->CurrentValue, "", $city->citycontact->ReadOnly);
-
- // cityhalladdress
- $city->cityhalladdress->SetDbValueDef($rsnew, $city->cityhalladdress->CurrentValue, "", $city->cityhalladdress->ReadOnly);
-
- // cityhalltelno
- $city->cityhalltelno->SetDbValueDef($rsnew, $city->cityhalltelno->CurrentValue, "", $city->cityhalltelno->ReadOnly);
-
- // cityhalllatitude
- $city->cityhalllatitude->SetDbValueDef($rsnew, $city->cityhalllatitude->CurrentValue, 0, $city->cityhalllatitude->ReadOnly);
-
- // cityhalllongitude
- $city->cityhalllongitude->SetDbValueDef($rsnew, $city->cityhalllongitude->CurrentValue, 0, $city->cityhalllongitude->ReadOnly);
-
- // cityhallaltitude
- $city->cityhallaltitude->SetDbValueDef($rsnew, $city->cityhallaltitude->CurrentValue, 0, $city->cityhallaltitude->ReadOnly);
-
- // provinceid
- $city->provinceid->SetDbValueDef($rsnew, $city->provinceid->CurrentValue, 0, $city->provinceid->ReadOnly);
-
- // citycode
- $city->citycode->SetDbValueDef($rsnew, $city->citycode->CurrentValue, 0, $city->citycode->ReadOnly);
-
- // Call Row Updating event
- $bUpdateRow = $city->Row_Updating($rsold, $rsnew);
- if ($bUpdateRow) {
- $conn->raiseErrorFn = 'ew_ErrorFn';
- if (count($rsnew) > 0)
- $EditRow = $conn->Execute($city->UpdateSQL($rsnew));
- else
- $EditRow = TRUE; // No field to update
- $conn->raiseErrorFn = '';
- } else {
- if ($city->CancelMessage <> "") {
- $this->setFailureMessage($city->CancelMessage);
- $city->CancelMessage = "";
- } else {
- $this->setFailureMessage($Language->Phrase("UpdateCancelled"));
- }
- $EditRow = FALSE;
- }
- }
-
- // Call Row_Updated event
- if ($EditRow)
- $city->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 = 'city';
- $usr = CurrentUserName();
- ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $typ, $table, "", "", "", "");
- }
-
- // Write Audit Trail (edit page)
- function WriteAuditTrailOnEdit(&$rsold, &$rsnew) {
- global $city;
- $table = 'city';
-
- // 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 ($city->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore BLOB fields
- if ($city->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 ($city->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 ($city->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;
- }
- }
- ?>