PageRenderTime 71ms CodeModel.GetById 62ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/cityadd.php

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