PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/osj-osj2duser_detailedit.php

http://osjobber.googlecode.com/
PHP | 516 lines | 388 code | 61 blank | 67 comment | 60 complexity | d574ce75f22c6538740cafc99f030929 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
  1. <?php
  2. define("EW_PAGE_ID", "edit", TRUE); // Page ID
  3. define("EW_TABLE_NAME", 'osj-user_detail', TRUE);
  4. ?>
  5. <?php
  6. session_start(); // Initialize session data
  7. ob_start(); // Turn on output buffering
  8. ?>
  9. <?php include "osj-ewcfg50.php" ?>
  10. <?php include "osj-ewmysql50.php" ?>
  11. <?php include "osj-phpfn50.php" ?>
  12. <?php include "osj-osj2duser_detailinfo.php" ?>
  13. <?php include "osj-userfn50.php" ?>
  14. <?php include "osj-osj2dusersinfo.php" ?>
  15. <?php
  16. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  17. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
  18. header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
  19. header("Cache-Control: post-check=0, pre-check=0", false);
  20. header("Pragma: no-cache"); // HTTP/1.0
  21. ?>
  22. <?php
  23. // Open connection to the database
  24. $conn = ew_Connect();
  25. ?>
  26. <?php
  27. $Security = new cAdvancedSecurity();
  28. ?>
  29. <?php
  30. if (!$Security->IsLoggedIn()) $Security->AutoLogin();
  31. $Security->LoadCurrentUserLevel('osj-user_detail');
  32. if (!$Security->IsLoggedIn()) {
  33. $Security->SaveLastUrl();
  34. Page_Terminate("osj-login.php");
  35. }
  36. if (!$Security->CanEdit()) {
  37. $Security->SaveLastUrl();
  38. Page_Terminate("osj-osj2duser_detaillist.php");
  39. }
  40. if ($Security->IsLoggedIn() && $Security->CurrentUserID() == "") {
  41. $_SESSION[EW_SESSION_MESSAGE] = "You do not have the right permission to view the page";
  42. Page_Terminate("osj-login.php");
  43. }
  44. ?>
  45. <?php
  46. // Common page loading event (in userfn*.php)
  47. Page_Loading();
  48. ?>
  49. <?php
  50. // Page load event, used in current page
  51. Page_Load();
  52. ?>
  53. <?php
  54. $osj2Duser_detail->Export = @$_GET["export"]; // Get export parameter
  55. $sExport = $osj2Duser_detail->Export; // Get export parameter, used in header
  56. $sExportFile = $osj2Duser_detail->TableVar; // Get export file, used in header
  57. ?>
  58. <?php
  59. // Load key from QueryString
  60. if (@$_GET["user_detail_id"] <> "") {
  61. $osj2Duser_detail->user_detail_id->setQueryStringValue($_GET["user_detail_id"]);
  62. }
  63. // Create form object
  64. $objForm = new cFormObj();
  65. if (@$_POST["a_edit"] <> "") {
  66. $osj2Duser_detail->CurrentAction = $_POST["a_edit"]; // Get action code
  67. LoadFormValues(); // Get form values
  68. } else {
  69. $osj2Duser_detail->CurrentAction = "I"; // Default action is display
  70. }
  71. // Check if valid key
  72. if ($osj2Duser_detail->user_detail_id->CurrentValue == "") Page_Terminate($osj2Duser_detail->getReturnUrl()); // Invalid key, exit
  73. switch ($osj2Duser_detail->CurrentAction) {
  74. case "I": // Get a record to display
  75. if (!LoadRow()) { // Load Record based on key
  76. $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // No record found
  77. Page_Terminate($osj2Duser_detail->getReturnUrl()); // Return to caller
  78. }
  79. break;
  80. Case "U": // Update
  81. $osj2Duser_detail->SendEmail = TRUE; // Send email on update success
  82. if (EditRow()) { // Update Record based on key
  83. $_SESSION[EW_SESSION_MESSAGE] = "Update successful"; // Update success
  84. Page_Terminate($osj2Duser_detail->getReturnUrl()); // Return to caller
  85. } else {
  86. RestoreFormValues(); // Restore form values if update failed
  87. }
  88. }
  89. // Render the record
  90. $osj2Duser_detail->RowType = EW_ROWTYPE_EDIT; // Render as edit
  91. RenderRow();
  92. ?>
  93. <?php include "osj-header.php" ?>
  94. <script type="text/javascript">
  95. <!--
  96. var EW_PAGE_ID = "edit"; // Page id
  97. var EW_SHOW_HIGHLIGHT = "Show highlight";
  98. var EW_HIDE_HIGHLIGHT = "Hide highlight";
  99. //-->
  100. </script>
  101. <script type="text/javascript">
  102. <!--
  103. function ew_ValidateForm(fobj) {
  104. if (fobj.a_confirm && fobj.a_confirm.value == "F")
  105. return true;
  106. var i, elm, aelm, infix;
  107. var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
  108. for (i=0; i<rowcnt; i++) {
  109. infix = (fobj.key_count) ? String(i+1) : "";
  110. elm = fobj.elements["x" + infix + "_user_first_name"];
  111. if (elm && !ew_HasValue(elm)) {
  112. if (!ew_OnError(elm, "Please enter required field - First Name"))
  113. return false;
  114. }
  115. elm = fobj.elements["x" + infix + "_user_last_name"];
  116. if (elm && !ew_HasValue(elm)) {
  117. if (!ew_OnError(elm, "Please enter required field - Last Name"))
  118. return false;
  119. }
  120. }
  121. return true;
  122. }
  123. //-->
  124. </script>
  125. <script type="text/javascript">
  126. <!--
  127. var ew_DHTMLEditors = [];
  128. //-->
  129. </script>
  130. <script type="text/javascript">
  131. <!--
  132. // js for Popup Calendar
  133. //-->
  134. </script>
  135. <script type="text/javascript">
  136. <!--
  137. var ew_MultiPagePage = "Page"; // multi-page Page Text
  138. var ew_MultiPageOf = "of"; // multi-page Of Text
  139. var ew_MultiPagePrev = "Prev"; // multi-page Prev Text
  140. var ew_MultiPageNext = "Next"; // multi-page Next Text
  141. //-->
  142. </script>
  143. <script language="JavaScript" type="text/javascript">
  144. <!--
  145. // Write your client script here, no need to add script tags.
  146. // To include another .js script, use:
  147. // ew_ClientScriptInclude("my_javascript.js");
  148. //-->
  149. </script>
  150. <p><span class="phpmaker">Edit TABLE: User Details<br><br><a href="<?php echo $osj2Duser_detail->getReturnUrl() ?>">Go Back</a></span></p>
  151. <?php
  152. if (@$_SESSION[EW_SESSION_MESSAGE] <> "") {
  153. ?>
  154. <p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
  155. <?php
  156. $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message
  157. }
  158. ?>
  159. <form name="fosj2Duser_detailedit" id="fosj2Duser_detailedit" action="osj-osj2duser_detailedit.php" method="post" onSubmit="return ew_ValidateForm(this);">
  160. <p>
  161. <input type="hidden" name="a_edit" id="a_edit" value="U">
  162. <table class="ewTable">
  163. <input type="hidden" name="x_user_detail_id" id="x_user_detail_id" value="<?php echo ew_HtmlEncode($osj2Duser_detail->user_detail_id->CurrentValue) ?>">
  164. <tr class="ewTableRow">
  165. <td class="ewTableHeader">First Name<span class='ewmsg'>&nbsp;*</span></td>
  166. <td<?php echo $osj2Duser_detail->user_first_name->CellAttributes() ?>><span id="cb_x_user_first_name">
  167. <input type="text" name="x_user_first_name" id="x_user_first_name" size="30" maxlength="255" value="<?php echo $osj2Duser_detail->user_first_name->EditValue ?>"<?php echo $osj2Duser_detail->user_first_name->EditAttributes() ?>>
  168. </span></td>
  169. </tr>
  170. <tr class="ewTableAltRow">
  171. <td class="ewTableHeader">Last Name<span class='ewmsg'>&nbsp;*</span></td>
  172. <td<?php echo $osj2Duser_detail->user_last_name->CellAttributes() ?>><span id="cb_x_user_last_name">
  173. <input type="text" name="x_user_last_name" id="x_user_last_name" size="30" maxlength="255" value="<?php echo $osj2Duser_detail->user_last_name->EditValue ?>"<?php echo $osj2Duser_detail->user_last_name->EditAttributes() ?>>
  174. </span></td>
  175. </tr>
  176. <tr class="ewTableRow">
  177. <td class="ewTableHeader">Description<span class='ewmsg'>&nbsp;*</span></td>
  178. <td<?php echo $osj2Duser_detail->user_description->CellAttributes() ?>><span id="cb_x_user_description">
  179. <textarea name="x_user_description" id="x_user_description" cols="35" rows="4"<?php echo $osj2Duser_detail->user_description->EditAttributes() ?>><?php echo $osj2Duser_detail->user_description->EditValue ?></textarea>
  180. </span></td>
  181. </tr>
  182. <tr class="ewTableAltRow">
  183. <td class="ewTableHeader">Company<span class='ewmsg'>&nbsp;*</span></td>
  184. <td<?php echo $osj2Duser_detail->user_company->CellAttributes() ?>><span id="cb_x_user_company">
  185. <input type="text" name="x_user_company" id="x_user_company" size="30" maxlength="255" value="<?php echo $osj2Duser_detail->user_company->EditValue ?>"<?php echo $osj2Duser_detail->user_company->EditAttributes() ?>>
  186. </span></td>
  187. </tr>
  188. </table>
  189. <p>
  190. <input type="submit" name="btnAction" id="btnAction" value=" Edit ">
  191. </form>
  192. <script language="JavaScript" type="text/javascript">
  193. <!--
  194. // Write your table-specific startup script here
  195. // document.write("page loaded");
  196. //-->
  197. </script>
  198. <?php include "osj-footer.php" ?>
  199. <?php
  200. // If control is passed here, simply terminate the page without redirect
  201. Page_Terminate();
  202. // -----------------------------------------------------------------
  203. // Subroutine Page_Terminate
  204. // - called when exit page
  205. // - clean up connection and objects
  206. // - if url specified, redirect to url, otherwise end response
  207. function Page_Terminate($url = "") {
  208. global $conn;
  209. // Page unload event, used in current page
  210. Page_Unload();
  211. // Global page unloaded event (in userfn*.php)
  212. Page_Unloaded();
  213. // Close Connection
  214. $conn->Close();
  215. // Go to url if specified
  216. if ($url <> "") {
  217. ob_end_clean();
  218. header("Location: $url");
  219. }
  220. exit();
  221. }
  222. ?>
  223. <?php
  224. // Load form values
  225. function LoadFormValues() {
  226. // Load from form
  227. global $objForm, $osj2Duser_detail;
  228. $osj2Duser_detail->user_detail_id->setFormValue($objForm->GetValue("x_user_detail_id"));
  229. $osj2Duser_detail->user_first_name->setFormValue($objForm->GetValue("x_user_first_name"));
  230. $osj2Duser_detail->user_last_name->setFormValue($objForm->GetValue("x_user_last_name"));
  231. $osj2Duser_detail->user_description->setFormValue($objForm->GetValue("x_user_description"));
  232. $osj2Duser_detail->user_company->setFormValue($objForm->GetValue("x_user_company"));
  233. }
  234. // Restore form values
  235. function RestoreFormValues() {
  236. global $osj2Duser_detail;
  237. $osj2Duser_detail->user_detail_id->CurrentValue = $osj2Duser_detail->user_detail_id->FormValue;
  238. $osj2Duser_detail->user_first_name->CurrentValue = $osj2Duser_detail->user_first_name->FormValue;
  239. $osj2Duser_detail->user_last_name->CurrentValue = $osj2Duser_detail->user_last_name->FormValue;
  240. $osj2Duser_detail->user_description->CurrentValue = $osj2Duser_detail->user_description->FormValue;
  241. $osj2Duser_detail->user_company->CurrentValue = $osj2Duser_detail->user_company->FormValue;
  242. }
  243. ?>
  244. <?php
  245. // Load row based on key values
  246. function LoadRow() {
  247. global $conn, $Security, $osj2Duser_detail;
  248. $sFilter = $osj2Duser_detail->SqlKeyFilter();
  249. if (!is_numeric($osj2Duser_detail->user_detail_id->CurrentValue)) {
  250. return FALSE; // Invalid key, exit
  251. }
  252. $sFilter = str_replace("@user_detail_id@", ew_AdjustSql($osj2Duser_detail->user_detail_id->CurrentValue), $sFilter); // Replace key value
  253. if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
  254. $sFilter = $osj2Duser_detail->AddUserIDFilter($sFilter, $Security->CurrentUserID()); // Add User ID filter
  255. }
  256. // Call Row Selecting event
  257. $osj2Duser_detail->Row_Selecting($sFilter);
  258. // Load sql based on filter
  259. $osj2Duser_detail->CurrentFilter = $sFilter;
  260. $sSql = $osj2Duser_detail->SQL();
  261. if ($rs = $conn->Execute($sSql)) {
  262. if ($rs->EOF) {
  263. $LoadRow = FALSE;
  264. } else {
  265. $LoadRow = TRUE;
  266. $rs->MoveFirst();
  267. LoadRowValues($rs); // Load row values
  268. // Call Row Selected event
  269. $osj2Duser_detail->Row_Selected($rs);
  270. }
  271. $rs->Close();
  272. } else {
  273. $LoadRow = FALSE;
  274. }
  275. return $LoadRow;
  276. }
  277. // Load row values from recordset
  278. function LoadRowValues(&$rs) {
  279. global $osj2Duser_detail;
  280. $osj2Duser_detail->user_detail_id->setDbValue($rs->fields('user_detail_id'));
  281. $osj2Duser_detail->user_id->setDbValue($rs->fields('user_id'));
  282. $osj2Duser_detail->user_detail_creation_date->setDbValue($rs->fields('user_detail_creation_date'));
  283. $osj2Duser_detail->user_detail_edit_date->setDbValue($rs->fields('user_detail_edit_date'));
  284. $osj2Duser_detail->user_first_name->setDbValue($rs->fields('user_first_name'));
  285. $osj2Duser_detail->user_last_name->setDbValue($rs->fields('user_last_name'));
  286. $osj2Duser_detail->user_description->setDbValue($rs->fields('user_description'));
  287. $osj2Duser_detail->user_company->setDbValue($rs->fields('user_company'));
  288. }
  289. ?>
  290. <?php
  291. // Render row values based on field settings
  292. function RenderRow() {
  293. global $conn, $Security, $osj2Duser_detail;
  294. // Call Row Rendering event
  295. $osj2Duser_detail->Row_Rendering();
  296. // Common render codes for all row types
  297. // user_first_name
  298. $osj2Duser_detail->user_first_name->CellCssStyle = "";
  299. $osj2Duser_detail->user_first_name->CellCssClass = "";
  300. // user_last_name
  301. $osj2Duser_detail->user_last_name->CellCssStyle = "";
  302. $osj2Duser_detail->user_last_name->CellCssClass = "";
  303. // user_description
  304. $osj2Duser_detail->user_description->CellCssStyle = "";
  305. $osj2Duser_detail->user_description->CellCssClass = "";
  306. // user_company
  307. $osj2Duser_detail->user_company->CellCssStyle = "";
  308. $osj2Duser_detail->user_company->CellCssClass = "";
  309. if ($osj2Duser_detail->RowType == EW_ROWTYPE_VIEW) { // View row
  310. } elseif ($osj2Duser_detail->RowType == EW_ROWTYPE_ADD) { // Add row
  311. } elseif ($osj2Duser_detail->RowType == EW_ROWTYPE_EDIT) { // Edit row
  312. // user_first_name
  313. $osj2Duser_detail->user_first_name->EditCustomAttributes = "";
  314. $osj2Duser_detail->user_first_name->EditValue = ew_HtmlEncode($osj2Duser_detail->user_first_name->CurrentValue);
  315. // user_last_name
  316. $osj2Duser_detail->user_last_name->EditCustomAttributes = "";
  317. $osj2Duser_detail->user_last_name->EditValue = ew_HtmlEncode($osj2Duser_detail->user_last_name->CurrentValue);
  318. // user_description
  319. $osj2Duser_detail->user_description->EditCustomAttributes = "";
  320. $osj2Duser_detail->user_description->EditValue = ew_HtmlEncode($osj2Duser_detail->user_description->CurrentValue);
  321. // user_company
  322. $osj2Duser_detail->user_company->EditCustomAttributes = "";
  323. $osj2Duser_detail->user_company->EditValue = ew_HtmlEncode($osj2Duser_detail->user_company->CurrentValue);
  324. } elseif ($osj2Duser_detail->RowType == EW_ROWTYPE_SEARCH) { // Search row
  325. }
  326. // Call Row Rendered event
  327. $osj2Duser_detail->Row_Rendered();
  328. }
  329. ?>
  330. <?php
  331. // Update record based on key values
  332. function EditRow() {
  333. global $conn, $Security, $osj2Duser_detail;
  334. $sFilter = $osj2Duser_detail->SqlKeyFilter();
  335. if (!is_numeric($osj2Duser_detail->user_detail_id->CurrentValue)) {
  336. return FALSE;
  337. }
  338. $sFilter = str_replace("@user_detail_id@", ew_AdjustSql($osj2Duser_detail->user_detail_id->CurrentValue), $sFilter); // Replace key value
  339. if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
  340. $sFilter = $osj2Duser_detail->AddUserIDFilter($sFilter, $Security->CurrentUserID()); // Add User ID filter
  341. $osj2Duser_detail->CurrentFilter = $sFilter;
  342. }
  343. $osj2Duser_detail->CurrentFilter = $sFilter;
  344. $sSql = $osj2Duser_detail->SQL();
  345. $conn->raiseErrorFn = 'ew_ErrorFn';
  346. $rs = $conn->Execute($sSql);
  347. $conn->raiseErrorFn = '';
  348. if ($rs === FALSE)
  349. return FALSE;
  350. if ($rs->EOF) {
  351. $EditRow = FALSE; // Update Failed
  352. } else {
  353. // Save old values
  354. $rsold =& $rs->fields;
  355. $rsnew = array();
  356. // Field user_first_name
  357. $osj2Duser_detail->user_first_name->SetDbValueDef($osj2Duser_detail->user_first_name->CurrentValue, "");
  358. $rsnew['user_first_name'] =& $osj2Duser_detail->user_first_name->DbValue;
  359. // Field user_last_name
  360. $osj2Duser_detail->user_last_name->SetDbValueDef($osj2Duser_detail->user_last_name->CurrentValue, "");
  361. $rsnew['user_last_name'] =& $osj2Duser_detail->user_last_name->DbValue;
  362. // Field user_description
  363. $osj2Duser_detail->user_description->SetDbValueDef($osj2Duser_detail->user_description->CurrentValue, "");
  364. $rsnew['user_description'] =& $osj2Duser_detail->user_description->DbValue;
  365. // Field user_company
  366. $osj2Duser_detail->user_company->SetDbValueDef($osj2Duser_detail->user_company->CurrentValue, "");
  367. $rsnew['user_company'] =& $osj2Duser_detail->user_company->DbValue;
  368. // Call Row Updating event
  369. $bUpdateRow = $osj2Duser_detail->Row_Updating($rsold, $rsnew);
  370. if ($bUpdateRow) {
  371. $conn->raiseErrorFn = 'ew_ErrorFn';
  372. $EditRow = $conn->Execute($osj2Duser_detail->UpdateSQL($rsnew));
  373. $conn->raiseErrorFn = '';
  374. } else {
  375. if ($osj2Duser_detail->CancelMessage <> "") {
  376. $_SESSION[EW_SESSION_MESSAGE] = $osj2Duser_detail->CancelMessage;
  377. $osj2Duser_detail->CancelMessage = "";
  378. } else {
  379. $_SESSION[EW_SESSION_MESSAGE] = "Update cancelled";
  380. }
  381. $EditRow = FALSE;
  382. }
  383. }
  384. // Call Row Updated event
  385. if ($EditRow) {
  386. $osj2Duser_detail->Row_Updated($rsold, $rsnew);
  387. }
  388. if ($EditRow) {
  389. WriteAuditTrailOnEdit($rsold, $rsnew);
  390. }
  391. $rs->Close();
  392. return $EditRow;
  393. }
  394. ?>
  395. <?php
  396. // Write Audit Trail start/end for grid update
  397. function WriteAuditTrailDummy($typ) {
  398. $table = 'osj-user_detail';
  399. // Write Audit Trail
  400. $filePfx = "log";
  401. $curDate = date("Y/m/d");
  402. $curTime = date("H:i:s");
  403. $id = ew_ScriptName();
  404. $user = CurrentUserID();
  405. $action = $typ;
  406. ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, "", "", "", "");
  407. }
  408. ?>
  409. <?php
  410. // Write Audit Trail (edit page)
  411. function WriteAuditTrailOnEdit(&$rsold, &$rsnew) {
  412. global $osj2Duser_detail;
  413. $table = 'osj-user_detail';
  414. // Get key value
  415. $key = "";
  416. if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
  417. $key .= $rsold['user_detail_id'];
  418. // Write Audit Trail
  419. $filePfx = "log";
  420. $curDate = date("Y/m/d");
  421. $curTime = date("H:i:s");
  422. $id = ew_ScriptName();
  423. $user = CurrentUserID();
  424. $action = "U";
  425. foreach (array_keys($rsnew) as $fldname) {
  426. if ($osj2Duser_detail->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
  427. if ($osj2Duser_detail->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // DateTime Field
  428. $modified = (ew_FormatDateTime($rsold[$fldname], 0) <> ew_FormatDateTime($rsnew[$fldname], 0));
  429. } else {
  430. $modified = ($rsold[$fldname] <> $rsnew[$fldname]);
  431. }
  432. if ($modified) {
  433. if ($osj2Duser_detail->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // Memo Field
  434. $oldvalue = "<MEMO>";
  435. $newvalue = "<MEMO>";
  436. } else {
  437. $oldvalue = $rsold[$fldname];
  438. $newvalue = $rsnew[$fldname];
  439. }
  440. ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, $fldname, $key, $oldvalue, $newvalue);
  441. }
  442. }
  443. }
  444. }
  445. ?>
  446. <?php
  447. // Page Load event
  448. function Page_Load() {
  449. //echo "Page Load";
  450. }
  451. // Page Unload event
  452. function Page_Unload() {
  453. //echo "Page Unload";
  454. }
  455. ?>