PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/companyedit.php

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