PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/barangayedit.php

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