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