PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/barangayadd.php

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