PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/companyadd.php

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