PageRenderTime 32ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/cityedit.php

https://bitbucket.org/joemarmatulac/ebutton
PHP | 1128 lines | 762 code | 155 blank | 211 comment | 173 complexity | 3d7161584cbc01b2044cdaa58791bdc5 MD5 | raw file
   1<?php
   2if (session_id() == "") session_start(); // Initialize Session data
   3ob_start(); // Turn on output buffering
   4?>
   5<?php include_once "ewcfg8.php" ?>
   6<?php include_once "ewmysql8.php" ?>
   7<?php include_once "phpfn8.php" ?>
   8<?php include_once "cityinfo.php" ?>
   9<?php include_once "userinfo.php" ?>
  10<?php include_once "userfn8.php" ?>
  11<?php ew_Header(FALSE) ?>
  12<?php
  13
  14// Create page object
  15$city_edit = new ccity_edit();
  16$Page =& $city_edit;
  17
  18// Page init
  19$city_edit->Page_Init();
  20
  21// Page main
  22$city_edit->Page_Main();
  23?>
  24<?php include_once "header.php" ?>
  25<script type="text/javascript">
  26<!--
  27
  28// Create page object
  29var city_edit = new ew_Page("city_edit");
  30
  31// page properties
  32city_edit.PageID = "edit"; // page ID
  33city_edit.FormID = "fcityedit"; // form ID
  34var EW_PAGE_ID = city_edit.PageID; // for backward compatibility
  35
  36// extend page with ValidateForm function
  37city_edit.ValidateForm = function(fobj) {
  38	ew_PostAutoSuggest(fobj);
  39	if (!this.ValidateRequired)
  40		return true; // ignore validation
  41	if (fobj.a_confirm && fobj.a_confirm.value == "F")
  42		return true;
  43	var i, elm, aelm, infix;
  44	var rowcnt = 1;
  45	for (i=0; i<rowcnt; i++) {
  46		infix = "";
  47		elm = fobj.elements["x" + infix + "_id"];
  48		if (elm && !ew_HasValue(elm))
  49			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->id->FldCaption()) ?>");
  50		elm = fobj.elements["x" + infix + "_id"];
  51		if (elm && !ew_CheckInteger(elm.value))
  52			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->id->FldErrMsg()) ?>");
  53		elm = fobj.elements["x" + infix + "_city_1"];
  54		if (elm && !ew_HasValue(elm))
  55			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->city_1->FldCaption()) ?>");
  56		/*elm = fobj.elements["x" + infix + "_citycontact"];
  57		if (elm && !ew_HasValue(elm))
  58			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->citycontact->FldCaption()) ?>");
  59		elm = fobj.elements["x" + infix + "_cityhalladdress"];
  60		if (elm && !ew_HasValue(elm))
  61			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhalladdress->FldCaption()) ?>");
  62		elm = fobj.elements["x" + infix + "_cityhalltelno"];
  63		if (elm && !ew_HasValue(elm))
  64			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhalltelno->FldCaption()) ?>");
  65		elm = fobj.elements["x" + infix + "_cityhalllatitude"];
  66		if (elm && !ew_HasValue(elm))
  67			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhalllatitude->FldCaption()) ?>");
  68		elm = fobj.elements["x" + infix + "_cityhalllatitude"];
  69		if (elm && !ew_CheckNumber(elm.value))
  70			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->cityhalllatitude->FldErrMsg()) ?>");
  71		elm = fobj.elements["x" + infix + "_cityhalllongitude"];
  72		if (elm && !ew_HasValue(elm))
  73			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhalllongitude->FldCaption()) ?>");
  74		elm = fobj.elements["x" + infix + "_cityhalllongitude"];
  75		if (elm && !ew_CheckNumber(elm.value))
  76			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->cityhalllongitude->FldErrMsg()) ?>");
  77		elm = fobj.elements["x" + infix + "_cityhallaltitude"];
  78		if (elm && !ew_HasValue(elm))
  79			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->cityhallaltitude->FldCaption()) ?>");
  80		elm = fobj.elements["x" + infix + "_cityhallaltitude"];
  81		if (elm && !ew_CheckNumber(elm.value))
  82			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->cityhallaltitude->FldErrMsg()) ?>");
  83		elm = fobj.elements["x" + infix + "_provinceid"];
  84		if (elm && !ew_HasValue(elm))
  85			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->provinceid->FldCaption()) ?>");
  86		elm = fobj.elements["x" + infix + "_citycode"];
  87		if (elm && !ew_HasValue(elm))
  88			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($city->citycode->FldCaption()) ?>");
  89		elm = fobj.elements["x" + infix + "_citycode"];
  90		if (elm && !ew_CheckInteger(elm.value))
  91			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($city->citycode->FldErrMsg()) ?>");
  92		*/
  93		// Set up row object
  94		var row = {};
  95		row["index"] = infix;
  96		for (var j = 0; j < fobj.elements.length; j++) {
  97			var el = fobj.elements[j];
  98			var len = infix.length + 2;
  99			if (el.name.substr(0, len) == "x" + infix + "_") {
 100				var elname = "x_" + el.name.substr(len);
 101				if (ewLang.isObject(row[elname])) { // already exists
 102					if (ewLang.isArray(row[elname])) {
 103						row[elname][row[elname].length] = el; // add to array
 104					} else {
 105						row[elname] = [row[elname], el]; // convert to array
 106					}
 107				} else {
 108					row[elname] = el;
 109				}
 110			}
 111		}
 112		fobj.row = row;
 113
 114		// Call Form Custom Validate event
 115		if (!this.Form_CustomValidate(fobj)) return false;
 116	}
 117
 118	// Process detail page
 119	var detailpage = (fobj.detailpage) ? fobj.detailpage.value : "";
 120	if (detailpage != "") {
 121		return eval(detailpage+".ValidateForm(fobj)");
 122	}
 123	return true;
 124}
 125
 126// extend page with Form_CustomValidate function
 127city_edit.Form_CustomValidate =  
 128 function(fobj) { // DO NOT CHANGE THIS LINE!
 129
 130 	// Your custom validation code here, return false if invalid. 
 131 	return true;
 132 }
 133<?php if (EW_CLIENT_VALIDATE) { ?>
 134city_edit.ValidateRequired = true; // uses JavaScript validation
 135<?php } else { ?>
 136city_edit.ValidateRequired = false; // no JavaScript validation
 137<?php } ?>
 138
 139//-->
 140</script>
 141<script language="JavaScript" type="text/javascript">
 142<!--
 143
 144// Write your client script here, no need to add script tags.
 145//-->
 146
 147</script>
 148<p class="phpmaker ewTitle"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $city->TableCaption() ?></p>
 149<p class="phpmaker"><a href="<?php echo $city->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></p>
 150<?php $city_edit->ShowPageHeader(); ?>
 151<?php
 152$city_edit->ShowMessage();
 153?>
 154<form name="fcityedit" id="fcityedit" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return city_edit.ValidateForm(this);">
 155<p>
 156<input type="hidden" name="a_table" id="a_table" value="city">
 157<input type="hidden" name="a_edit" id="a_edit" value="U">
 158<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
 159<div class="ewGridMiddlePanel">
 160<table cellspacing="0" class="ewTable">
 161<?php if ($city->id->Visible) { // id ?>
 162	<tr id="r_id"<?php echo $city->RowAttributes() ?>>
 163		<td class="ewTableHeader"><?php echo $city->id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
 164		<td<?php echo $city->id->CellAttributes() ?>><span id="el_id">
 165<div<?php echo $city->id->ViewAttributes() ?>><?php echo $city->id->EditValue ?></div>
 166<input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($city->id->CurrentValue) ?>">
 167</span><?php echo $city->id->CustomMsg ?></td>
 168	</tr>
 169<?php } ?>
 170<?php if ($city->city_1->Visible) { // city ?>
 171	<tr id="r_city_1"<?php echo $city->RowAttributes() ?>>
 172		<td class="ewTableHeader"><?php echo $city->city_1->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
 173		<td<?php echo $city->city_1->CellAttributes() ?>><span id="el_city_1">
 174<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() ?>>
 175</span><?php echo $city->city_1->CustomMsg ?></td>
 176	</tr>
 177<?php } ?>
 178<?php if ($city->citycontact->Visible) { // citycontact ?>
 179	<tr id="r_citycontact"<?php echo $city->RowAttributes() ?>>
 180		<td class="ewTableHeader"><?php echo $city->citycontact->FldCaption() ?><!-- Removed Required Field Indicator--></td>
 181		<td<?php echo $city->citycontact->CellAttributes() ?>><span id="el_citycontact">
 182<input type="text" name="x_citycontact" id="x_citycontact" size="30" maxlength="20" value="<?php echo $city->citycontact->EditValue ?>"<?php echo $city->citycontact->EditAttributes() ?>>
 183</span><?php echo $city->citycontact->CustomMsg ?></td>
 184	</tr>
 185<?php } ?>
 186<?php if ($city->cityhalladdress->Visible) { // cityhalladdress ?>
 187	<tr id="r_cityhalladdress"<?php echo $city->RowAttributes() ?>>
 188		<td class="ewTableHeader"><?php echo $city->cityhalladdress->FldCaption() ?><!-- Removed Required Field Indicator--></td>
 189		<td<?php echo $city->cityhalladdress->CellAttributes() ?>><span id="el_cityhalladdress">
 190<textarea name="x_cityhalladdress" id="x_cityhalladdress" cols="35" rows="4"<?php echo $city->cityhalladdress->EditAttributes() ?>><?php echo $city->cityhalladdress->EditValue ?></textarea>
 191</span><?php echo $city->cityhalladdress->CustomMsg ?></td>
 192	</tr>
 193<?php } ?>
 194<?php if ($city->cityhalltelno->Visible) { // cityhalltelno ?>
 195	<tr id="r_cityhalltelno"<?php echo $city->RowAttributes() ?>>
 196		<td class="ewTableHeader"><?php echo $city->cityhalltelno->FldCaption() ?><!-- Removed Required Field Indicator--></td>
 197		<td<?php echo $city->cityhalltelno->CellAttributes() ?>><span id="el_cityhalltelno">
 198<input type="text" name="x_cityhalltelno" id="x_cityhalltelno" size="30" maxlength="20" value="<?php echo $city->cityhalltelno->EditValue ?>"<?php echo $city->cityhalltelno->EditAttributes() ?>>
 199</span><?php echo $city->cityhalltelno->CustomMsg ?></td>
 200	</tr>
 201<?php } ?>
 202<?php if ($city->cityhalllatitude->Visible) { // cityhalllatitude ?>
 203	<tr id="r_cityhalllatitude"<?php echo $city->RowAttributes() ?>>
 204		<td class="ewTableHeader"><?php echo $city->cityhalllatitude->FldCaption() ?><!-- Removed Required Field Indicator--></td>
 205		<td<?php echo $city->cityhalllatitude->CellAttributes() ?>><span id="el_cityhalllatitude">
 206<input type="text" name="x_cityhalllatitude" id="x_cityhalllatitude" size="30" value="<?php echo $city->cityhalllatitude->EditValue ?>"<?php echo $city->cityhalllatitude->EditAttributes() ?>>
 207</span><?php echo $city->cityhalllatitude->CustomMsg ?></td>
 208	</tr>
 209<?php } ?>
 210<?php if ($city->cityhalllongitude->Visible) { // cityhalllongitude ?>
 211	<tr id="r_cityhalllongitude"<?php echo $city->RowAttributes() ?>>
 212		<td class="ewTableHeader"><?php echo $city->cityhalllongitude->FldCaption() ?><!-- Removed Required Field Indicator--></td>
 213		<td<?php echo $city->cityhalllongitude->CellAttributes() ?>><span id="el_cityhalllongitude">
 214<input type="text" name="x_cityhalllongitude" id="x_cityhalllongitude" size="30" value="<?php echo $city->cityhalllongitude->EditValue ?>"<?php echo $city->cityhalllongitude->EditAttributes() ?>>
 215</span><?php echo $city->cityhalllongitude->CustomMsg ?></td>
 216	</tr>
 217<?php } ?>
 218<?php if ($city->cityhallaltitude->Visible) { // cityhallaltitude ?>
 219	<tr id="r_cityhallaltitude"<?php echo $city->RowAttributes() ?>>
 220		<td class="ewTableHeader"><?php echo $city->cityhallaltitude->FldCaption() ?><!-- Removed Required Field Indicator--></td>
 221		<td<?php echo $city->cityhallaltitude->CellAttributes() ?>><span id="el_cityhallaltitude">
 222<input type="text" name="x_cityhallaltitude" id="x_cityhallaltitude" size="30" value="<?php echo $city->cityhallaltitude->EditValue ?>"<?php echo $city->cityhallaltitude->EditAttributes() ?>>
 223</span><?php echo $city->cityhallaltitude->CustomMsg ?></td>
 224	</tr>
 225<?php } ?>
 226<?php if ($city->provinceid->Visible) { // provinceid ?>
 227	<tr id="r_provinceid"<?php echo $city->RowAttributes() ?>>
 228		<td class="ewTableHeader"><?php echo $city->provinceid->FldCaption() ?><!-- Removed Required Field Indicator--></td>
 229		<td<?php echo $city->provinceid->CellAttributes() ?>><span id="el_provinceid">
 230<select id="x_provinceid" name="x_provinceid"<?php echo $city->provinceid->EditAttributes() ?>>
 231<?php
 232if (is_array($city->provinceid->EditValue)) {
 233	$arwrk = $city->provinceid->EditValue;
 234	$rowswrk = count($arwrk);
 235	$emptywrk = TRUE;
 236	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
 237		$selwrk = (strval($city->provinceid->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
 238		if ($selwrk <> "") $emptywrk = FALSE;
 239?>
 240<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
 241<?php echo $arwrk[$rowcntwrk][1] ?>
 242</option>
 243<?php
 244	}
 245}
 246?>
 247</select>
 248</span><?php echo $city->provinceid->CustomMsg ?></td>
 249	</tr>
 250<?php } ?>
 251
 252</table>
 253</div>
 254</td></tr></table>
 255<p>
 256<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
 257</form>
 258<?php
 259$city_edit->ShowPageFooter();
 260if (EW_DEBUG_ENABLED)
 261	echo ew_DebugMsg();
 262?>
 263<script language="JavaScript" type="text/javascript">
 264<!--
 265
 266// Write your table-specific startup script here
 267// document.write("page loaded");
 268//-->
 269
 270</script>
 271<?php include_once "footer.php" ?>
 272<?php
 273$city_edit->Page_Terminate();
 274?>
 275<?php
 276
 277//
 278// Page class
 279//
 280class ccity_edit {
 281
 282	// Page ID
 283	var $PageID = 'edit';
 284
 285	// Table name
 286	var $TableName = 'city';
 287
 288	// Page object name
 289	var $PageObjName = 'city_edit';
 290
 291	// Page name
 292	function PageName() {
 293		return ew_CurrentPage();
 294	}
 295
 296	// Page URL
 297	function PageUrl() {
 298		$PageUrl = ew_CurrentPage() . "?";
 299		global $city;
 300		if ($city->UseTokenInUrl) $PageUrl .= "t=" . $city->TableVar . "&"; // Add page token
 301		return $PageUrl;
 302	}
 303
 304	// Message
 305	function getMessage() {
 306		return @$_SESSION[EW_SESSION_MESSAGE];
 307	}
 308
 309	function setMessage($v) {
 310		ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
 311	}
 312
 313	function getFailureMessage() {
 314		return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
 315	}
 316
 317	function setFailureMessage($v) {
 318		ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
 319	}
 320
 321	function getSuccessMessage() {
 322		return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
 323	}
 324
 325	function setSuccessMessage($v) {
 326		ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
 327	}
 328
 329	// Show message
 330	function ShowMessage() {
 331		$sMessage = $this->getMessage();
 332		$this->Message_Showing($sMessage, "");
 333		if ($sMessage <> "") { // Message in Session, display
 334			echo "<p class=\"ewMessage\">" . $sMessage . "</p>";
 335			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
 336		}
 337
 338		// Success message
 339		$sSuccessMessage = $this->getSuccessMessage();
 340		$this->Message_Showing($sSuccessMessage, "success");
 341		if ($sSuccessMessage <> "") { // Message in Session, display
 342			echo "<p class=\"ewSuccessMessage\">" . $sSuccessMessage . "</p>";
 343			$_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
 344		}
 345
 346		// Failure message
 347		$sErrorMessage = $this->getFailureMessage();
 348		$this->Message_Showing($sErrorMessage, "failure");
 349		if ($sErrorMessage <> "") { // Message in Session, display
 350			echo "<p class=\"ewErrorMessage\">" . $sErrorMessage . "</p>";
 351			$_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
 352		}
 353	}
 354	var $PageHeader;
 355	var $PageFooter;
 356
 357	// Show Page Header
 358	function ShowPageHeader() {
 359		$sHeader = $this->PageHeader;
 360		$this->Page_DataRendering($sHeader);
 361		if ($sHeader <> "") { // Header exists, display
 362			echo "<p class=\"phpmaker\">" . $sHeader . "</p>";
 363		}
 364	}
 365
 366	// Show Page Footer
 367	function ShowPageFooter() {
 368		$sFooter = $this->PageFooter;
 369		$this->Page_DataRendered($sFooter);
 370		if ($sFooter <> "") { // Fotoer exists, display
 371			echo "<p class=\"phpmaker\">" . $sFooter . "</p>";
 372		}
 373	}
 374
 375	// Validate page request
 376	function IsPageRequest() {
 377		global $objForm, $city;
 378		if ($city->UseTokenInUrl) {
 379			if ($objForm)
 380				return ($city->TableVar == $objForm->GetValue("t"));
 381			if (@$_GET["t"] <> "")
 382				return ($city->TableVar == $_GET["t"]);
 383		} else {
 384			return TRUE;
 385		}
 386	}
 387
 388	//
 389	// Page class constructor
 390	//
 391	function ccity_edit() {
 392		global $conn, $Language;
 393
 394		// Language object
 395		if (!isset($Language)) $Language = new cLanguage();
 396
 397		// Table object (city)
 398		if (!isset($GLOBALS["city"])) {
 399			$GLOBALS["city"] = new ccity();
 400			$GLOBALS["Table"] =& $GLOBALS["city"];
 401		}
 402
 403		// Table object (user)
 404		if (!isset($GLOBALS['user'])) $GLOBALS['user'] = new cuser();
 405
 406		// Page ID
 407		if (!defined("EW_PAGE_ID"))
 408			define("EW_PAGE_ID", 'edit', TRUE);
 409
 410		// Table name (for backward compatibility)
 411		if (!defined("EW_TABLE_NAME"))
 412			define("EW_TABLE_NAME", 'city', TRUE);
 413
 414		// Start timer
 415		if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();
 416
 417		// Open connection
 418		if (!isset($conn)) $conn = ew_Connect();
 419	}
 420
 421	// 
 422	//  Page_Init
 423	//
 424	function Page_Init() {
 425		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
 426		global $city;
 427
 428		// Security
 429		$Security = new cAdvancedSecurity();
 430		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
 431		if (!$Security->IsLoggedIn()) {
 432			$Security->SaveLastUrl();
 433			$this->Page_Terminate("login.php");
 434		}
 435		$Security->TablePermission_Loading();
 436		$Security->LoadCurrentUserLevel($this->TableName);
 437		$Security->TablePermission_Loaded();
 438		if (!$Security->IsLoggedIn()) {
 439			$Security->SaveLastUrl();
 440			$this->Page_Terminate("login.php");
 441		}
 442		if (!$Security->CanEdit()) {
 443			$Security->SaveLastUrl();
 444			$this->Page_Terminate("citylist.php");
 445		}
 446
 447		// Create form object
 448		$objForm = new cFormObj();
 449
 450		// Global Page Loading event (in userfn*.php)
 451		Page_Loading();
 452
 453		// Page Load event
 454		$this->Page_Load();
 455	}
 456
 457	//
 458	// Page_Terminate
 459	//
 460	function Page_Terminate($url = "") {
 461		global $conn;
 462
 463		// Page Unload event
 464		$this->Page_Unload();
 465
 466		// Global Page Unloaded event (in userfn*.php)
 467		Page_Unloaded();
 468		$this->Page_Redirecting($url);
 469
 470		 // Close connection
 471		$conn->Close();
 472
 473		// Go to URL if specified
 474		if ($url <> "") {
 475			if (!EW_DEBUG_ENABLED && ob_get_length())
 476				ob_end_clean();
 477			header("Location: " . $url);
 478		}
 479		exit();
 480	}
 481	var $DbMasterFilter;
 482	var $DbDetailFilter;
 483
 484	// 
 485	// Page main
 486	//
 487	function Page_Main() {
 488		global $objForm, $Language, $gsFormError, $city;
 489
 490		// Load key from QueryString
 491		if (@$_GET["id"] <> "")
 492			$city->id->setQueryStringValue($_GET["id"]);
 493		if (@$_POST["a_edit"] <> "") {
 494			$city->CurrentAction = $_POST["a_edit"]; // Get action code
 495			$this->LoadFormValues(); // Get form values
 496
 497			// Validate form
 498			if (!$this->ValidateForm()) {
 499				$city->CurrentAction = ""; // Form error, reset action
 500				$this->setFailureMessage($gsFormError);
 501				$city->EventCancelled = TRUE; // Event cancelled
 502				$this->RestoreFormValues();
 503			}
 504		} else {
 505			$city->CurrentAction = "I"; // Default action is display
 506		}
 507
 508		// Check if valid key
 509		if ($city->id->CurrentValue == "")
 510			$this->Page_Terminate("citylist.php"); // Invalid key, return to list
 511		switch ($city->CurrentAction) {
 512			case "I": // Get a record to display
 513				if (!$this->LoadRow()) { // Load record based on key
 514					$this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
 515					$this->Page_Terminate("citylist.php"); // No matching record, return to list
 516				}
 517				break;
 518			Case "U": // Update
 519				$city->SendEmail = TRUE; // Send email on update success
 520				if ($this->EditRow()) { // Update record based on key
 521					$this->setSuccessMessage($Language->Phrase("UpdateSuccess")); // Update success
 522					$sReturnUrl = $city->getReturnUrl();
 523					if (ew_GetPageName($sReturnUrl) == "cityview.php")
 524						$sReturnUrl = $city->ViewUrl(); // View paging, return to View page directly
 525					$this->Page_Terminate($sReturnUrl); // Return to caller
 526				} else {
 527					$city->EventCancelled = TRUE; // Event cancelled
 528					$this->RestoreFormValues(); // Restore form values if update failed
 529				}
 530		}
 531
 532		// Render the record
 533		$city->RowType = EW_ROWTYPE_EDIT; // Render as Edit
 534		$city->ResetAttrs();
 535		$this->RenderRow();
 536	}
 537
 538	// Get upload files
 539	function GetUploadFiles() {
 540		global $objForm, $city;
 541
 542		// Get upload data
 543		$index = $objForm->Index; // Save form index
 544		$objForm->Index = 0;
 545		$confirmPage = (strval($objForm->GetValue("a_confirm")) <> "");
 546		$objForm->Index = $index; // Restore form index
 547	}
 548
 549	// Load form values
 550	function LoadFormValues() {
 551
 552		// Load from form
 553		global $objForm, $city;
 554		if (!$city->id->FldIsDetailKey)
 555			$city->id->setFormValue($objForm->GetValue("x_id"));
 556		if (!$city->city_1->FldIsDetailKey) {
 557			$city->city_1->setFormValue($objForm->GetValue("x_city_1"));
 558		}
 559		if (!$city->citycontact->FldIsDetailKey) {
 560			$city->citycontact->setFormValue($objForm->GetValue("x_citycontact"));
 561		}
 562		if (!$city->cityhalladdress->FldIsDetailKey) {
 563			$city->cityhalladdress->setFormValue($objForm->GetValue("x_cityhalladdress"));
 564		}
 565		if (!$city->cityhalltelno->FldIsDetailKey) {
 566			$city->cityhalltelno->setFormValue($objForm->GetValue("x_cityhalltelno"));
 567		}
 568		if (!$city->cityhalllatitude->FldIsDetailKey) {
 569			$city->cityhalllatitude->setFormValue($objForm->GetValue("x_cityhalllatitude"));
 570		}
 571		if (!$city->cityhalllongitude->FldIsDetailKey) {
 572			$city->cityhalllongitude->setFormValue($objForm->GetValue("x_cityhalllongitude"));
 573		}
 574		if (!$city->cityhallaltitude->FldIsDetailKey) {
 575			$city->cityhallaltitude->setFormValue($objForm->GetValue("x_cityhallaltitude"));
 576		}
 577		if (!$city->provinceid->FldIsDetailKey) {
 578			$city->provinceid->setFormValue($objForm->GetValue("x_provinceid"));
 579		}
 580		if (!$city->citycode->FldIsDetailKey) {
 581			$city->citycode->setFormValue($objForm->GetValue("x_citycode"));
 582		}
 583	}
 584
 585	// Restore form values
 586	function RestoreFormValues() {
 587		global $objForm, $city;
 588		$this->LoadRow();
 589		$city->id->CurrentValue = $city->id->FormValue;
 590		$city->city_1->CurrentValue = $city->city_1->FormValue;
 591		$city->citycontact->CurrentValue = $city->citycontact->FormValue;
 592		$city->cityhalladdress->CurrentValue = $city->cityhalladdress->FormValue;
 593		$city->cityhalltelno->CurrentValue = $city->cityhalltelno->FormValue;
 594		$city->cityhalllatitude->CurrentValue = $city->cityhalllatitude->FormValue;
 595		$city->cityhalllongitude->CurrentValue = $city->cityhalllongitude->FormValue;
 596		$city->cityhallaltitude->CurrentValue = $city->cityhallaltitude->FormValue;
 597		$city->provinceid->CurrentValue = $city->provinceid->FormValue;
 598		$city->citycode->CurrentValue = $city->citycode->FormValue;
 599	}
 600
 601	// Load row based on key values
 602	function LoadRow() {
 603		global $conn, $Security, $city;
 604		$sFilter = $city->KeyFilter();
 605
 606		// Call Row Selecting event
 607		$city->Row_Selecting($sFilter);
 608
 609		// Load SQL based on filter
 610		$city->CurrentFilter = $sFilter;
 611		$sSql = $city->SQL();
 612		$res = FALSE;
 613		$rs = ew_LoadRecordset($sSql);
 614		if ($rs && !$rs->EOF) {
 615			$res = TRUE;
 616			$this->LoadRowValues($rs); // Load row values
 617			$rs->Close();
 618		}
 619		return $res;
 620	}
 621
 622	// Load row values from recordset
 623	function LoadRowValues(&$rs) {
 624		global $conn, $city;
 625		if (!$rs || $rs->EOF) return;
 626
 627		// Call Row Selected event
 628		$row =& $rs->fields;
 629		$city->Row_Selected($row);
 630		$city->id->setDbValue($rs->fields('id'));
 631		$city->city_1->setDbValue($rs->fields('city'));
 632		$city->citycontact->setDbValue($rs->fields('citycontact'));
 633		$city->cityhalladdress->setDbValue($rs->fields('cityhalladdress'));
 634		$city->cityhalltelno->setDbValue($rs->fields('cityhalltelno'));
 635		$city->cityhalllatitude->setDbValue($rs->fields('cityhalllatitude'));
 636		$city->cityhalllongitude->setDbValue($rs->fields('cityhalllongitude'));
 637		$city->cityhallaltitude->setDbValue($rs->fields('cityhallaltitude'));
 638		$city->provinceid->setDbValue($rs->fields('provinceid'));
 639		$city->zuserid->setDbValue($rs->fields('userid'));
 640		$city->timestamp->setDbValue($rs->fields('timestamp'));
 641		$city->citycode->setDbValue($rs->fields('citycode'));
 642	}
 643
 644	// Render row values based on field settings
 645	function RenderRow() {
 646		global $conn, $Security, $Language, $city;
 647
 648		// Initialize URLs
 649		// Call Row_Rendering event
 650
 651		$city->Row_Rendering();
 652
 653		// Common render codes for all row types
 654		// id
 655		// city
 656		// citycontact
 657		// cityhalladdress
 658		// cityhalltelno
 659		// cityhalllatitude
 660		// cityhalllongitude
 661		// cityhallaltitude
 662		// provinceid
 663		// userid
 664		// timestamp
 665		// citycode
 666
 667		if ($city->RowType == EW_ROWTYPE_VIEW) { // View row
 668
 669			// id
 670			$city->id->ViewValue = $city->id->CurrentValue;
 671			$city->id->ViewCustomAttributes = "";
 672
 673			// city
 674			$city->city_1->ViewValue = $city->city_1->CurrentValue;
 675			$city->city_1->ViewCustomAttributes = "";
 676
 677			// citycontact
 678			$city->citycontact->ViewValue = $city->citycontact->CurrentValue;
 679			$city->citycontact->ViewCustomAttributes = "";
 680
 681			// cityhalladdress
 682			$city->cityhalladdress->ViewValue = $city->cityhalladdress->CurrentValue;
 683			$city->cityhalladdress->ViewCustomAttributes = "";
 684
 685			// cityhalltelno
 686			$city->cityhalltelno->ViewValue = $city->cityhalltelno->CurrentValue;
 687			$city->cityhalltelno->ViewCustomAttributes = "";
 688
 689			// cityhalllatitude
 690			$city->cityhalllatitude->ViewValue = $city->cityhalllatitude->CurrentValue;
 691			$city->cityhalllatitude->ViewCustomAttributes = "";
 692
 693			// cityhalllongitude
 694			$city->cityhalllongitude->ViewValue = $city->cityhalllongitude->CurrentValue;
 695			$city->cityhalllongitude->ViewCustomAttributes = "";
 696
 697			// cityhallaltitude
 698			$city->cityhallaltitude->ViewValue = $city->cityhallaltitude->CurrentValue;
 699			$city->cityhallaltitude->ViewCustomAttributes = "";
 700
 701			// provinceid
 702			if (strval($city->provinceid->CurrentValue) <> "") {
 703				$sFilterWrk = "`id` = " . ew_AdjustSql($city->provinceid->CurrentValue) . "";
 704			$sSqlWrk = "SELECT `province` FROM `province`";
 705			$sWhereWrk = "";
 706			if ($sFilterWrk <> "") {
 707				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
 708				$sWhereWrk .= "(" . $sFilterWrk . ")";
 709			}
 710			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
 711				$rswrk = $conn->Execute($sSqlWrk);
 712				if ($rswrk && !$rswrk->EOF) { // Lookup values found
 713					$city->provinceid->ViewValue = $rswrk->fields('province');
 714					$rswrk->Close();
 715				} else {
 716					$city->provinceid->ViewValue = $city->provinceid->CurrentValue;
 717				}
 718			} else {
 719				$city->provinceid->ViewValue = NULL;
 720			}
 721			$city->provinceid->ViewCustomAttributes = "";
 722
 723			// userid
 724			$city->zuserid->ViewValue = $city->zuserid->CurrentValue;
 725			$city->zuserid->ViewCustomAttributes = "";
 726
 727			// timestamp
 728			$city->timestamp->ViewValue = $city->timestamp->CurrentValue;
 729			$city->timestamp->ViewValue = ew_FormatDateTime($city->timestamp->ViewValue, 9);
 730			$city->timestamp->ViewCustomAttributes = "";
 731
 732			// citycode
 733			$city->citycode->ViewValue = $city->citycode->CurrentValue;
 734			$city->citycode->ViewCustomAttributes = "";
 735
 736			// id
 737			$city->id->LinkCustomAttributes = "";
 738			$city->id->HrefValue = "";
 739			$city->id->TooltipValue = "";
 740
 741			// city
 742			$city->city_1->LinkCustomAttributes = "";
 743			$city->city_1->HrefValue = "";
 744			$city->city_1->TooltipValue = "";
 745
 746			// citycontact
 747			$city->citycontact->LinkCustomAttributes = "";
 748			$city->citycontact->HrefValue = "";
 749			$city->citycontact->TooltipValue = "";
 750
 751			// cityhalladdress
 752			$city->cityhalladdress->LinkCustomAttributes = "";
 753			$city->cityhalladdress->HrefValue = "";
 754			$city->cityhalladdress->TooltipValue = "";
 755
 756			// cityhalltelno
 757			$city->cityhalltelno->LinkCustomAttributes = "";
 758			$city->cityhalltelno->HrefValue = "";
 759			$city->cityhalltelno->TooltipValue = "";
 760
 761			// cityhalllatitude
 762			$city->cityhalllatitude->LinkCustomAttributes = "";
 763			$city->cityhalllatitude->HrefValue = "";
 764			$city->cityhalllatitude->TooltipValue = "";
 765
 766			// cityhalllongitude
 767			$city->cityhalllongitude->LinkCustomAttributes = "";
 768			$city->cityhalllongitude->HrefValue = "";
 769			$city->cityhalllongitude->TooltipValue = "";
 770
 771			// cityhallaltitude
 772			$city->cityhallaltitude->LinkCustomAttributes = "";
 773			$city->cityhallaltitude->HrefValue = "";
 774			$city->cityhallaltitude->TooltipValue = "";
 775
 776			// provinceid
 777			$city->provinceid->LinkCustomAttributes = "";
 778			$city->provinceid->HrefValue = "";
 779			$city->provinceid->TooltipValue = "";
 780
 781			// citycode
 782			$city->citycode->LinkCustomAttributes = "";
 783			$city->citycode->HrefValue = "";
 784			$city->citycode->TooltipValue = "";
 785		} elseif ($city->RowType == EW_ROWTYPE_EDIT) { // Edit row
 786
 787			// id
 788			$city->id->EditCustomAttributes = "";
 789			$city->id->EditValue = $city->id->CurrentValue;
 790			$city->id->ViewCustomAttributes = "";
 791
 792			// city
 793			$city->city_1->EditCustomAttributes = "";
 794			$city->city_1->EditValue = ew_HtmlEncode($city->city_1->CurrentValue);
 795
 796			// citycontact
 797			$city->citycontact->EditCustomAttributes = "";
 798			$city->citycontact->EditValue = ew_HtmlEncode($city->citycontact->CurrentValue);
 799
 800			// cityhalladdress
 801			$city->cityhalladdress->EditCustomAttributes = "";
 802			$city->cityhalladdress->EditValue = ew_HtmlEncode($city->cityhalladdress->CurrentValue);
 803
 804			// cityhalltelno
 805			$city->cityhalltelno->EditCustomAttributes = "";
 806			$city->cityhalltelno->EditValue = ew_HtmlEncode($city->cityhalltelno->CurrentValue);
 807
 808			// cityhalllatitude
 809			$city->cityhalllatitude->EditCustomAttributes = "";
 810			$city->cityhalllatitude->EditValue = ew_HtmlEncode($city->cityhalllatitude->CurrentValue);
 811
 812			// cityhalllongitude
 813			$city->cityhalllongitude->EditCustomAttributes = "";
 814			$city->cityhalllongitude->EditValue = ew_HtmlEncode($city->cityhalllongitude->CurrentValue);
 815
 816			// cityhallaltitude
 817			$city->cityhallaltitude->EditCustomAttributes = "";
 818			$city->cityhallaltitude->EditValue = ew_HtmlEncode($city->cityhallaltitude->CurrentValue);
 819
 820			// provinceid
 821			$city->provinceid->EditCustomAttributes = "";
 822				$sFilterWrk = "";
 823			$sSqlWrk = "SELECT `id`, `province` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld` FROM `province`";
 824			$sWhereWrk = "";
 825			if ($sFilterWrk <> "") {
 826				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
 827				$sWhereWrk .= "(" . $sFilterWrk . ")";
 828			}
 829			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
 830			$rswrk = $conn->Execute($sSqlWrk);
 831			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
 832			if ($rswrk) $rswrk->Close();
 833			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
 834			$city->provinceid->EditValue = $arwrk;
 835
 836			// citycode
 837			$city->citycode->EditCustomAttributes = "";
 838			$city->citycode->EditValue = ew_HtmlEncode($city->citycode->CurrentValue);
 839
 840			// Edit refer script
 841			// id
 842
 843			$city->id->HrefValue = "";
 844
 845			// city
 846			$city->city_1->HrefValue = "";
 847
 848			// citycontact
 849			$city->citycontact->HrefValue = "";
 850
 851			// cityhalladdress
 852			$city->cityhalladdress->HrefValue = "";
 853
 854			// cityhalltelno
 855			$city->cityhalltelno->HrefValue = "";
 856
 857			// cityhalllatitude
 858			$city->cityhalllatitude->HrefValue = "";
 859
 860			// cityhalllongitude
 861			$city->cityhalllongitude->HrefValue = "";
 862
 863			// cityhallaltitude
 864			$city->cityhallaltitude->HrefValue = "";
 865
 866			// provinceid
 867			$city->provinceid->HrefValue = "";
 868
 869			// citycode
 870			$city->citycode->HrefValue = "";
 871		}
 872		if ($city->RowType == EW_ROWTYPE_ADD ||
 873			$city->RowType == EW_ROWTYPE_EDIT ||
 874			$city->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
 875			$city->SetupFieldTitles();
 876		}
 877
 878		// Call Row Rendered event
 879		if ($city->RowType <> EW_ROWTYPE_AGGREGATEINIT)
 880			$city->Row_Rendered();
 881	}
 882
 883	// Validate form
 884	function ValidateForm() {
 885		global $Language, $gsFormError, $city;
 886
 887		// Initialize form error message
 888		$gsFormError = "";
 889
 890		// Check if validation required
 891		if (!EW_SERVER_VALIDATE)
 892			return ($gsFormError == "");
 893		if (!is_null($city->id->FormValue) && $city->id->FormValue == "") {
 894			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->id->FldCaption());
 895		}
 896		if (!ew_CheckInteger($city->id->FormValue)) {
 897			ew_AddMessage($gsFormError, $city->id->FldErrMsg());
 898		}
 899		if (!is_null($city->city_1->FormValue) && $city->city_1->FormValue == "") {
 900			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->city_1->FldCaption());
 901		}
 902		if (!is_null($city->citycontact->FormValue) && $city->citycontact->FormValue == "") {
 903			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->citycontact->FldCaption());
 904		}
 905		if (!is_null($city->cityhalladdress->FormValue) && $city->cityhalladdress->FormValue == "") {
 906			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhalladdress->FldCaption());
 907		}
 908		if (!is_null($city->cityhalltelno->FormValue) && $city->cityhalltelno->FormValue == "") {
 909			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhalltelno->FldCaption());
 910		}
 911		if (!is_null($city->cityhalllatitude->FormValue) && $city->cityhalllatitude->FormValue == "") {
 912			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhalllatitude->FldCaption());
 913		}
 914		if (!ew_CheckNumber($city->cityhalllatitude->FormValue)) {
 915			ew_AddMessage($gsFormError, $city->cityhalllatitude->FldErrMsg());
 916		}
 917		if (!is_null($city->cityhalllongitude->FormValue) && $city->cityhalllongitude->FormValue == "") {
 918			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhalllongitude->FldCaption());
 919		}
 920		if (!ew_CheckNumber($city->cityhalllongitude->FormValue)) {
 921			ew_AddMessage($gsFormError, $city->cityhalllongitude->FldErrMsg());
 922		}
 923		if (!is_null($city->cityhallaltitude->FormValue) && $city->cityhallaltitude->FormValue == "") {
 924			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->cityhallaltitude->FldCaption());
 925		}
 926		if (!ew_CheckNumber($city->cityhallaltitude->FormValue)) {
 927			ew_AddMessage($gsFormError, $city->cityhallaltitude->FldErrMsg());
 928		}
 929		if (!is_null($city->provinceid->FormValue) && $city->provinceid->FormValue == "") {
 930			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->provinceid->FldCaption());
 931		}
 932		if (!is_null($city->citycode->FormValue) && $city->citycode->FormValue == "") {
 933			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $city->citycode->FldCaption());
 934		}
 935		if (!ew_CheckInteger($city->citycode->FormValue)) {
 936			ew_AddMessage($gsFormError, $city->citycode->FldErrMsg());
 937		}
 938
 939		// Return validate result
 940		$ValidateForm = ($gsFormError == "");
 941
 942		// Call Form_CustomValidate event
 943		$sFormCustomError = "";
 944		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
 945		if ($sFormCustomError <> "") {
 946			ew_AddMessage($gsFormError, $sFormCustomError);
 947		}
 948		return $ValidateForm;
 949	}
 950
 951	// Update record based on key values
 952	function EditRow() {
 953		global $conn, $Security, $Language, $city;
 954		$sFilter = $city->KeyFilter();
 955		$city->CurrentFilter = $sFilter;
 956		$sSql = $city->SQL();
 957		$conn->raiseErrorFn = 'ew_ErrorFn';
 958		$rs = $conn->Execute($sSql);
 959		$conn->raiseErrorFn = '';
 960		if ($rs === FALSE)
 961			return FALSE;
 962		if ($rs->EOF) {
 963			$EditRow = FALSE; // Update Failed
 964		} else {
 965
 966			// Save old values
 967			$rsold =& $rs->fields;
 968			$rsnew = array();
 969
 970			// city
 971			$city->city_1->SetDbValueDef($rsnew, $city->city_1->CurrentValue, "", $city->city_1->ReadOnly);
 972
 973			// citycontact
 974			$city->citycontact->SetDbValueDef($rsnew, $city->citycontact->CurrentValue, "", $city->citycontact->ReadOnly);
 975
 976			// cityhalladdress
 977			$city->cityhalladdress->SetDbValueDef($rsnew, $city->cityhalladdress->CurrentValue, "", $city->cityhalladdress->ReadOnly);
 978
 979			// cityhalltelno
 980			$city->cityhalltelno->SetDbValueDef($rsnew, $city->cityhalltelno->CurrentValue, "", $city->cityhalltelno->ReadOnly);
 981
 982			// cityhalllatitude
 983			$city->cityhalllatitude->SetDbValueDef($rsnew, $city->cityhalllatitude->CurrentValue, 0, $city->cityhalllatitude->ReadOnly);
 984
 985			// cityhalllongitude
 986			$city->cityhalllongitude->SetDbValueDef($rsnew, $city->cityhalllongitude->CurrentValue, 0, $city->cityhalllongitude->ReadOnly);
 987
 988			// cityhallaltitude
 989			$city->cityhallaltitude->SetDbValueDef($rsnew, $city->cityhallaltitude->CurrentValue, 0, $city->cityhallaltitude->ReadOnly);
 990
 991			// provinceid
 992			$city->provinceid->SetDbValueDef($rsnew, $city->provinceid->CurrentValue, 0, $city->provinceid->ReadOnly);
 993
 994			// citycode
 995			$city->citycode->SetDbValueDef($rsnew, $city->citycode->CurrentValue, 0, $city->citycode->ReadOnly);
 996
 997			// Call Row Updating event
 998			$bUpdateRow = $city->Row_Updating($rsold, $rsnew);
 999			if ($bUpdateRow) {
1000				$conn->raiseErrorFn = 'ew_ErrorFn';
1001				if (count($rsnew) > 0)
1002					$EditRow = $conn->Execute($city->UpdateSQL($rsnew));
1003				else
1004					$EditRow = TRUE; // No field to update
1005				$conn->raiseErrorFn = '';
1006			} else {
1007				if ($city->CancelMessage <> "") {
1008					$this->setFailureMessage($city->CancelMessage);
1009					$city->CancelMessage = "";
1010				} else {
1011					$this->setFailureMessage($Language->Phrase("UpdateCancelled"));
1012				}
1013				$EditRow = FALSE;
1014			}
1015		}
1016
1017		// Call Row_Updated event
1018		if ($EditRow)
1019			$city->Row_Updated($rsold, $rsnew);
1020					if ($EditRow) {
1021			$this->WriteAuditTrailOnEdit($rsold, $rsnew);
1022		}
1023		$rs->Close();
1024		return $EditRow;
1025	}
1026// Write Audit Trail start/end for grid update
1027	function WriteAuditTrailDummy($typ) {
1028		$table = 'city';
1029	  $usr = CurrentUserName();
1030		ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $typ, $table, "", "", "", "");
1031	}
1032
1033	// Write Audit Trail (edit page)
1034	function WriteAuditTrailOnEdit(&$rsold, &$rsnew) {
1035		global $city;
1036		$table = 'city';
1037
1038		// Get key value
1039		$key = "";
1040		if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
1041		$key .= $rsold['id'];
1042
1043		// Write Audit Trail
1044		$dt = ew_StdCurrentDateTime();
1045		$id = ew_ScriptName();
1046	  $usr = CurrentUserName();
1047		foreach (array_keys($rsnew) as $fldname) {
1048			if ($city->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore BLOB fields
1049				if ($city->fields[$fldname]->FldDataType == EW_DATATYPE_DATE) { // DateTime field
1050					$modified = (ew_FormatDateTime($rsold[$fldname], 0) <> ew_FormatDateTime($rsnew[$fldname], 0));
1051				} else {
1052					$modified = !ew_CompareValue($rsold[$fldname], $rsnew[$fldname]);
1053				}
1054				if ($modified) {
1055					if ($city->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // Memo field
1056						if (EW_AUDIT_TRAIL_TO_DATABASE) {
1057							$oldvalue = $rsold[$fldname];
1058							$newvalue = $rsnew[$fldname];
1059						} else {
1060							$oldvalue = "[MEMO]";
1061							$newvalue = "[MEMO]";
1062						}
1063					} elseif ($city->fields[$fldname]->FldDataType == EW_DATATYPE_XML) { // XML field
1064						$oldvalue = "[XML]";
1065						$newvalue = "[XML]";
1066					} else {
1067						$oldvalue = $rsold[$fldname];
1068						$newvalue = $rsnew[$fldname];
1069					}
1070					ew_WriteAuditTrail("log", $dt, $id, $usr, "U", $table, $fldname, $key, $oldvalue, $newvalue);
1071				}
1072			}
1073		}
1074	}
1075
1076	// Page Load event
1077	function Page_Load() {
1078
1079		//echo "Page Load";
1080	}
1081
1082	// Page Unload event
1083	function Page_Unload() {
1084
1085		//echo "Page Unload";
1086	}
1087
1088	// Page Redirecting event
1089	function Page_Redirecting(&$url) {
1090
1091		// Example:
1092		//$url = "your URL";
1093
1094	}
1095
1096	// Message Showing event
1097	// $type = ''|'success'|'failure'
1098	function Message_Showing(&$msg, $type) {
1099
1100		// Example:
1101		//if ($type == 'success') $msg = "your success message";
1102
1103	}
1104
1105	// Page Data Rendering event
1106	function Page_DataRendering(&$header) {
1107
1108		// Example:
1109		//$header = "your header";
1110
1111	}
1112
1113	// Page Data Rendered event
1114	function Page_DataRendered(&$footer) {
1115
1116		// Example:
1117		//$footer = "your footer";
1118
1119	}
1120
1121	// Form Custom Validate event
1122	function Form_CustomValidate(&$CustomError) {
1123
1124		// Return error message in CustomError
1125		return TRUE;
1126	}
1127}
1128?>