PageRenderTime 44ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/osj-osj2dusersedit.php

http://osjobber.googlecode.com/
PHP | 632 lines | 599 code | 16 blank | 17 comment | 42 complexity | 7c192e38c11642f6a2e8403d2cac8c92 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-users', 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-osj2dusersinfo.php" ?>
  13. <?php include "osj-userfn50.php" ?>
  14. <?php
  15. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  16. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
  17. header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
  18. header("Cache-Control: post-check=0, pre-check=0", false);
  19. header("Pragma: no-cache"); // HTTP/1.0
  20. ?>
  21. <?php
  22. // Open connection to the database
  23. $conn = ew_Connect();
  24. ?>
  25. <?php
  26. $Security = new cAdvancedSecurity();
  27. ?>
  28. <?php
  29. if (!$Security->IsLoggedIn()) $Security->AutoLogin();
  30. $Security->LoadCurrentUserLevel('osj-users');
  31. if (!$Security->IsLoggedIn()) {
  32. $Security->SaveLastUrl();
  33. Page_Terminate("osj-login.php");
  34. }
  35. if (!$Security->CanEdit()) {
  36. $Security->SaveLastUrl();
  37. Page_Terminate("osj-osj2duserslist.php");
  38. }
  39. if ($Security->IsLoggedIn() && $Security->CurrentUserID() == "") {
  40. $_SESSION[EW_SESSION_MESSAGE] = "You do not have the right permission to view the page";
  41. Page_Terminate("osj-login.php");
  42. }
  43. ?>
  44. <?php
  45. // Common page loading event (in userfn*.php)
  46. Page_Loading();
  47. ?>
  48. <?php
  49. // Page load event, used in current page
  50. Page_Load();
  51. ?>
  52. <?php
  53. $osj2Dusers->Export = @$_GET["export"]; // Get export parameter
  54. $sExport = $osj2Dusers->Export; // Get export parameter, used in header
  55. $sExportFile = $osj2Dusers->TableVar; // Get export file, used in header
  56. ?>
  57. <?php
  58. // Load key from QueryString
  59. if (@$_GET["user_id"] <> "") {
  60. $osj2Dusers->user_id->setQueryStringValue($_GET["user_id"]);
  61. }
  62. // Create form object
  63. $objForm = new cFormObj();
  64. if (@$_POST["a_edit"] <> "") {
  65. $osj2Dusers->CurrentAction = $_POST["a_edit"]; // Get action code
  66. LoadFormValues(); // Get form values
  67. } else {
  68. $osj2Dusers->CurrentAction = "I"; // Default action is display
  69. }
  70. // Check if valid key
  71. if ($osj2Dusers->user_id->CurrentValue == "") Page_Terminate($osj2Dusers->getReturnUrl()); // Invalid key, exit
  72. switch ($osj2Dusers->CurrentAction) {
  73. case "I": // Get a record to display
  74. if (!LoadRow()) { // Load Record based on key
  75. $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // No record found
  76. Page_Terminate($osj2Dusers->getReturnUrl()); // Return to caller
  77. }
  78. break;
  79. Case "U": // Update
  80. $osj2Dusers->SendEmail = TRUE; // Send email on update success
  81. if (EditRow()) { // Update Record based on key
  82. $_SESSION[EW_SESSION_MESSAGE] = "Update successful"; // Update success
  83. Page_Terminate($osj2Dusers->getReturnUrl()); // Return to caller
  84. } else {
  85. RestoreFormValues(); // Restore form values if update failed
  86. }
  87. }
  88. // Render the record
  89. $osj2Dusers->RowType = EW_ROWTYPE_EDIT; // Render as edit
  90. RenderRow();
  91. ?>
  92. <?php include "osj-header.php" ?>
  93. <script type="text/javascript">
  94. <!--
  95. var EW_PAGE_ID = "edit"; // Page id
  96. var EW_SHOW_HIGHLIGHT = "Show highlight";
  97. var EW_HIDE_HIGHLIGHT = "Hide highlight";
  98. //-->
  99. </script>
  100. <script type="text/javascript">
  101. <!--
  102. function ew_ValidateForm(fobj) {
  103. if (fobj.a_confirm && fobj.a_confirm.value == "F")
  104. return true;
  105. var i, elm, aelm, infix;
  106. var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
  107. for (i=0; i<rowcnt; i++) {
  108. infix = (fobj.key_count) ? String(i+1) : "";
  109. elm = fobj.elements["x" + infix + "_user_email"];
  110. if (elm && !ew_HasValue(elm)) {
  111. if (!ew_OnError(elm, "Please enter required field - Email"))
  112. return false;
  113. }
  114. elm = fobj.elements["x" + infix + "_user_email"];
  115. if (elm && !ew_CheckEmail(elm.value)) {
  116. if (!ew_OnError(elm, "Users must provide a valid email address."))
  117. return false;
  118. }
  119. elm = fobj.elements["x" + infix + "_user_password"];
  120. if (elm && !ew_HasValue(elm)) {
  121. if (!ew_OnError(elm, "Please enter required field - Password"))
  122. return false;
  123. }
  124. elm = fobj.elements["x" + infix + "_user_level"];
  125. if (elm && !ew_HasValue(elm)) {
  126. if (!ew_OnError(elm, "Please enter required field - User Level"))
  127. return false;
  128. }
  129. elm = fobj.elements["x" + infix + "_user_status"];
  130. if (elm && !ew_HasValue(elm)) {
  131. if (!ew_OnError(elm, "Please enter required field - User Status"))
  132. return false;
  133. }
  134. }
  135. return true;
  136. }
  137. //-->
  138. </script>
  139. <script type="text/javascript">
  140. <!--
  141. var ew_DHTMLEditors = [];
  142. //-->
  143. </script>
  144. <script type="text/javascript">
  145. <!--
  146. // js for Popup Calendar
  147. //-->
  148. </script>
  149. <script type="text/javascript">
  150. <!--
  151. var ew_MultiPagePage = "Page"; // multi-page Page Text
  152. var ew_MultiPageOf = "of"; // multi-page Of Text
  153. var ew_MultiPagePrev = "Prev"; // multi-page Prev Text
  154. var ew_MultiPageNext = "Next"; // multi-page Next Text
  155. //-->
  156. </script>
  157. <script language="JavaScript" type="text/javascript">
  158. <!--
  159. // Write your client script here, no need to add script tags.
  160. // To include another .js script, use:
  161. // ew_ClientScriptInclude("my_javascript.js");
  162. //-->
  163. </script>
  164. <p><span class="phpmaker">Edit TABLE: Users<br><br><a href="<?php echo $osj2Dusers->getReturnUrl() ?>">Go Back</a></span></p>
  165. <?php
  166. if (@$_SESSION[EW_SESSION_MESSAGE] <> "") {
  167. ?>
  168. <p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
  169. <?php
  170. $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message
  171. }
  172. ?>
  173. <form name="fosj2Dusersedit" id="fosj2Dusersedit" action="osj-osj2dusersedit.php" method="post" onSubmit="return ew_ValidateForm(this);">
  174. <p>
  175. <input type="hidden" name="a_edit" id="a_edit" value="U">
  176. <table class="ewTable">
  177. <input type="hidden" name="x_user_id" id="x_user_id" value="<?php echo ew_HtmlEncode($osj2Dusers->user_id->CurrentValue) ?>">
  178. <tr class="ewTableRow">
  179. <td class="ewTableHeader">Email<span class='ewmsg'>&nbsp;*</span></td>
  180. <td<?php echo $osj2Dusers->user_email->CellAttributes() ?>><span id="cb_x_user_email">
  181. <input type="text" name="x_user_email" id="x_user_email" title="Email" size="30" maxlength="255" value="<?php echo $osj2Dusers->user_email->EditValue ?>"<?php echo $osj2Dusers->user_email->EditAttributes() ?>>
  182. </span></td>
  183. </tr>
  184. <tr class="ewTableAltRow">
  185. <td class="ewTableHeader">Password<span class='ewmsg'>&nbsp;*</span></td>
  186. <td<?php echo $osj2Dusers->user_password->CellAttributes() ?>><span id="cb_x_user_password">
  187. <input type="password" name="x_user_password" id="x_user_password" title="Password" value="<?php echo $osj2Dusers->user_password->EditValue ?>" size="30" maxlength="255"<?php echo $osj2Dusers->user_password->EditAttributes() ?>>
  188. </span></td>
  189. </tr>
  190. <tr class="ewTableRow">
  191. <td class="ewTableHeader">User Level<span class='ewmsg'>&nbsp;*</span></td>
  192. <td<?php echo $osj2Dusers->user_level->CellAttributes() ?>><span id="cb_x_user_level">
  193. <?php if (!$Security->IsAdmin() && $Security->IsLoggedIn()) { // Non system admin ?>
  194. <div<?php echo $osj2Dusers->user_level->ViewAttributes() ?>><?php echo $osj2Dusers->user_level->EditValue ?></div>
  195. <?php } else { ?>
  196. <select id="x_user_level" name="x_user_level"<?php echo $osj2Dusers->user_level->EditAttributes() ?>>
  197. <!--option value="">Please Select</option-->
  198. <?php
  199. if (is_array($osj2Dusers->user_level->EditValue)) {
  200. $arwrk = $osj2Dusers->user_level->EditValue;
  201. $rowswrk = count($arwrk);
  202. for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
  203. $selwrk = (strval($osj2Dusers->user_level->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";
  204. ?>
  205. <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
  206. <?php echo $arwrk[$rowcntwrk][1] ?>
  207. </option>
  208. <?php
  209. }
  210. }
  211. ?>
  212. </select>
  213. <?php
  214. $sSqlWrk = "SELECT `user_level_id`, `user_level_name` FROM `osj-user_level`";
  215. $sSqlWrk .= " WHERE (" . "`user_level_name` != 'Default' AND `user_level_name`!= 'Administrator'" . ")";
  216. $sSqlWrk = TEAencrypt($sSqlWrk, EW_RANDOM_KEY);
  217. ?>
  218. <input type="hidden" name="s_x_user_level" id="s_x_user_level" value="<?php echo $sSqlWrk ?>"><input type="hidden" name="lc_x_user_level" id="lc_x_user_level" value="2"><input type="hidden" name="ld1_x_user_level" id="ld1_x_user_level" value="1"><input type="hidden" name="ld2_x_user_level" id="ld2_x_user_level" value="-1"><input type="hidden" name="lft_x_user_level" id="lft_x_user_level" value="1">
  219. &nbsp;<a href="javascript:void(0);" onclick="ew_ShowAddOption('x_user_level');">Add User Level</a>
  220. </span><span>
  221. <div id="ao_x_user_level" style="display: none;">
  222. <input type="hidden" id="ltn_x_user_level" value="osj-user_level">
  223. <input type="hidden" id="lfn_x_user_level" value="user_level_id">
  224. <input type="hidden" id="dfn_x_user_level" value="user_level_name">
  225. <input type="hidden" id="lfm_x_user_level" value="Please enter required field - user level id">
  226. <input type="hidden" id="dfm_x_user_level" value="Please enter required field - user level name">
  227. <input type="hidden" id="lfq_x_user_level" value="">
  228. <input type="hidden" id="dfq_x_user_level" value="'">
  229. <table class="ewAddOption">
  230. <tr><td><span>user level id</span></td><td><input type="text" id="lf_x_user_level" size="30"></td></tr>
  231. <tr><td><span>user level name</span></td><td><input type="text" id="df_x_user_level" size="30" maxlength="50"></td></tr>
  232. <tr><td colspan="2" align="right"><input type="button" value="Add" onClick="ew_PostNewOption('x_user_level')"><input type="button" value="Cancel" onClick="ew_HideAddOption('x_user_level')"></td></tr>
  233. </table>
  234. </div>
  235. <?php } ?>
  236. </span></td>
  237. </tr>
  238. <tr class="ewTableAltRow">
  239. <td class="ewTableHeader">User Status<span class='ewmsg'>&nbsp;*</span></td>
  240. <td<?php echo $osj2Dusers->user_status->CellAttributes() ?>><span id="cb_x_user_status">
  241. <select id="x_user_status" name="x_user_status"<?php echo $osj2Dusers->user_status->EditAttributes() ?>>
  242. <!--option value="">Please Select</option-->
  243. <?php
  244. if (is_array($osj2Dusers->user_status->EditValue)) {
  245. $arwrk = $osj2Dusers->user_status->EditValue;
  246. $rowswrk = count($arwrk);
  247. for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
  248. $selwrk = (strval($osj2Dusers->user_status->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";
  249. ?>
  250. <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
  251. <?php echo $arwrk[$rowcntwrk][1] ?>
  252. </option>
  253. <?php
  254. }
  255. }
  256. ?>
  257. </select>
  258. </span></td>
  259. </tr>
  260. </table>
  261. <p>
  262. <input type="submit" name="btnAction" id="btnAction" value=" Edit ">
  263. </form>
  264. <script language="JavaScript">
  265. <!--
  266. var f = document.fosj2Dusersedit;
  267. ew_AjaxUpdateOpt(f.x_user_level, f.x_user_level, false);
  268. //-->
  269. </script>
  270. <script language="JavaScript" type="text/javascript">
  271. <!--
  272. // Write your table-specific startup script here
  273. // document.write("page loaded");
  274. //-->
  275. </script>
  276. <?php include "osj-footer.php" ?>
  277. <?php
  278. // If control is passed here, simply terminate the page without redirect
  279. Page_Terminate();
  280. // -----------------------------------------------------------------
  281. // Subroutine Page_Terminate
  282. // - called when exit page
  283. // - clean up connection and objects
  284. // - if url specified, redirect to url, otherwise end response
  285. function Page_Terminate($url = "") {
  286. global $conn;
  287. // Page unload event, used in current page
  288. Page_Unload();
  289. // Global page unloaded event (in userfn*.php)
  290. Page_Unloaded();
  291. // Close Connection
  292. $conn->Close();
  293. // Go to url if specified
  294. if ($url <> "") {
  295. ob_end_clean();
  296. header("Location: $url");
  297. }
  298. exit();
  299. }
  300. ?>
  301. <?php
  302. // Load form values
  303. function LoadFormValues() {
  304. // Load from form
  305. global $objForm, $osj2Dusers;
  306. $osj2Dusers->user_id->setFormValue($objForm->GetValue("x_user_id"));
  307. $osj2Dusers->user_email->setFormValue($objForm->GetValue("x_user_email"));
  308. $osj2Dusers->user_password->setFormValue($objForm->GetValue("x_user_password"));
  309. $osj2Dusers->user_level->setFormValue($objForm->GetValue("x_user_level"));
  310. $osj2Dusers->user_status->setFormValue($objForm->GetValue("x_user_status"));
  311. }
  312. // Restore form values
  313. function RestoreFormValues() {
  314. global $osj2Dusers;
  315. $osj2Dusers->user_id->CurrentValue = $osj2Dusers->user_id->FormValue;
  316. $osj2Dusers->user_email->CurrentValue = $osj2Dusers->user_email->FormValue;
  317. $osj2Dusers->user_password->CurrentValue = $osj2Dusers->user_password->FormValue;
  318. $osj2Dusers->user_level->CurrentValue = $osj2Dusers->user_level->FormValue;
  319. $osj2Dusers->user_status->CurrentValue = $osj2Dusers->user_status->FormValue;
  320. }
  321. ?>
  322. <?php
  323. // Load row based on key values
  324. function LoadRow() {
  325. global $conn, $Security, $osj2Dusers;
  326. $sFilter = $osj2Dusers->SqlKeyFilter();
  327. if (!is_numeric($osj2Dusers->user_id->CurrentValue)) {
  328. return FALSE; // Invalid key, exit
  329. }
  330. $sFilter = str_replace("@user_id@", ew_AdjustSql($osj2Dusers->user_id->CurrentValue), $sFilter); // Replace key value
  331. if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
  332. $sFilter = $osj2Dusers->AddUserIDFilter($sFilter, $Security->CurrentUserID()); // Add User ID filter
  333. }
  334. // Call Row Selecting event
  335. $osj2Dusers->Row_Selecting($sFilter);
  336. // Load sql based on filter
  337. $osj2Dusers->CurrentFilter = $sFilter;
  338. $sSql = $osj2Dusers->SQL();
  339. if ($rs = $conn->Execute($sSql)) {
  340. if ($rs->EOF) {
  341. $LoadRow = FALSE;
  342. } else {
  343. $LoadRow = TRUE;
  344. $rs->MoveFirst();
  345. LoadRowValues($rs); // Load row values
  346. // Call Row Selected event
  347. $osj2Dusers->Row_Selected($rs);
  348. }
  349. $rs->Close();
  350. } else {
  351. $LoadRow = FALSE;
  352. }
  353. return $LoadRow;
  354. }
  355. // Load row values from recordset
  356. function LoadRowValues(&$rs) {
  357. global $osj2Dusers;
  358. $osj2Dusers->user_id->setDbValue($rs->fields('user_id'));
  359. $osj2Dusers->user_creation_date->setDbValue($rs->fields('user_creation_date'));
  360. $osj2Dusers->user_edit_date->setDbValue($rs->fields('user_edit_date'));
  361. $osj2Dusers->user_email->setDbValue($rs->fields('user_email'));
  362. $osj2Dusers->user_password->setDbValue($rs->fields('user_password'));
  363. $osj2Dusers->user_level->setDbValue($rs->fields('user_level'));
  364. $osj2Dusers->user_status->setDbValue($rs->fields('user_status'));
  365. }
  366. ?>
  367. <?php
  368. // Render row values based on field settings
  369. function RenderRow() {
  370. global $conn, $Security, $osj2Dusers;
  371. // Call Row Rendering event
  372. $osj2Dusers->Row_Rendering();
  373. // Common render codes for all row types
  374. // user_email
  375. $osj2Dusers->user_email->CellCssStyle = "";
  376. $osj2Dusers->user_email->CellCssClass = "";
  377. // user_password
  378. $osj2Dusers->user_password->CellCssStyle = "";
  379. $osj2Dusers->user_password->CellCssClass = "";
  380. // user_level
  381. $osj2Dusers->user_level->CellCssStyle = "";
  382. $osj2Dusers->user_level->CellCssClass = "";
  383. // user_status
  384. $osj2Dusers->user_status->CellCssStyle = "";
  385. $osj2Dusers->user_status->CellCssClass = "";
  386. if ($osj2Dusers->RowType == EW_ROWTYPE_VIEW) { // View row
  387. } elseif ($osj2Dusers->RowType == EW_ROWTYPE_ADD) { // Add row
  388. } elseif ($osj2Dusers->RowType == EW_ROWTYPE_EDIT) { // Edit row
  389. // user_email
  390. $osj2Dusers->user_email->EditCustomAttributes = "";
  391. $osj2Dusers->user_email->EditValue = ew_HtmlEncode($osj2Dusers->user_email->CurrentValue);
  392. // user_password
  393. $osj2Dusers->user_password->EditCustomAttributes = "";
  394. $osj2Dusers->user_password->EditValue = ew_HtmlEncode($osj2Dusers->user_password->CurrentValue);
  395. // user_level
  396. $osj2Dusers->user_level->EditCustomAttributes = "";
  397. if (!$Security->CanAdmin()) { // System admin
  398. $osj2Dusers->user_level->EditValue = "********";
  399. } else {
  400. $sSqlWrk = "SELECT `user_level_id`, `user_level_name` FROM `osj-user_level`";
  401. if (trim(strval($osj2Dusers->user_level->CurrentValue)) == "") {
  402. $sSqlWrk .= " WHERE 0=1";
  403. } else {
  404. $sSqlWrk .= " WHERE `user_level_id` = " . ew_AdjustSql($osj2Dusers->user_level->CurrentValue) . "";
  405. }
  406. $sSqlWrk .= " AND (" . "`user_level_name` != 'Default' AND `user_level_name`!= 'Administrator'" . ")";
  407. $rswrk = $conn->Execute($sSqlWrk);
  408. $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
  409. if ($rswrk) $rswrk->Close();
  410. array_unshift($arwrk, array("", "Please Select"));
  411. $osj2Dusers->user_level->EditValue = $arwrk;
  412. }
  413. // user_status
  414. $osj2Dusers->user_status->EditCustomAttributes = "";
  415. $arwrk = array();
  416. $arwrk[] = array("0", "Inactive");
  417. $arwrk[] = array("1", "Active");
  418. array_unshift($arwrk, array("", "Please Select"));
  419. $osj2Dusers->user_status->EditValue = $arwrk;
  420. } elseif ($osj2Dusers->RowType == EW_ROWTYPE_SEARCH) { // Search row
  421. }
  422. // Call Row Rendered event
  423. $osj2Dusers->Row_Rendered();
  424. }
  425. ?>
  426. <?php
  427. // Update record based on key values
  428. function EditRow() {
  429. global $conn, $Security, $osj2Dusers;
  430. $sFilter = $osj2Dusers->SqlKeyFilter();
  431. if (!is_numeric($osj2Dusers->user_id->CurrentValue)) {
  432. return FALSE;
  433. }
  434. $sFilter = str_replace("@user_id@", ew_AdjustSql($osj2Dusers->user_id->CurrentValue), $sFilter); // Replace key value
  435. if ($osj2Dusers->user_email->CurrentValue <> "") { // Check field with unique index
  436. $sFilterChk = "(`user_email` = '" . ew_AdjustSql($osj2Dusers->user_email->CurrentValue) . "')";
  437. $sFilterChk .= " AND NOT (" . $sFilter . ")";
  438. $osj2Dusers->CurrentFilter = $sFilterChk;
  439. $sSqlChk = $osj2Dusers->SQL();
  440. $conn->raiseErrorFn = 'ew_ErrorFn';
  441. $rsChk = $conn->Execute($sSqlChk);
  442. $conn->raiseErrorFn = '';
  443. if ($rsChk === FALSE) {
  444. return FALSE;
  445. } elseif (!$rsChk->EOF) {
  446. $_SESSION[EW_SESSION_MESSAGE] = "Duplicate value for index or primary key -- `user_email`, value = " . $osj2Dusers->user_email->CurrentValue;
  447. $rsChk->Close();
  448. return FALSE;
  449. }
  450. $rsChk->Close();
  451. }
  452. if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
  453. $sFilter = $osj2Dusers->AddUserIDFilter($sFilter, $Security->CurrentUserID()); // Add User ID filter
  454. $osj2Dusers->CurrentFilter = $sFilter;
  455. }
  456. $osj2Dusers->CurrentFilter = $sFilter;
  457. $sSql = $osj2Dusers->SQL();
  458. $conn->raiseErrorFn = 'ew_ErrorFn';
  459. $rs = $conn->Execute($sSql);
  460. $conn->raiseErrorFn = '';
  461. if ($rs === FALSE)
  462. return FALSE;
  463. if ($rs->EOF) {
  464. $EditRow = FALSE; // Update Failed
  465. } else {
  466. // Save old values
  467. $rsold =& $rs->fields;
  468. $rsnew = array();
  469. // Field user_email
  470. $osj2Dusers->user_email->SetDbValueDef($osj2Dusers->user_email->CurrentValue, "");
  471. $rsnew['user_email'] =& $osj2Dusers->user_email->DbValue;
  472. // Field user_password
  473. $osj2Dusers->user_password->SetDbValueDef($osj2Dusers->user_password->CurrentValue, "");
  474. $rsnew['user_password'] =& $osj2Dusers->user_password->DbValue;
  475. // Field user_level
  476. if ($Security->CanAdmin()) { // System admin
  477. $osj2Dusers->user_level->SetDbValueDef($osj2Dusers->user_level->CurrentValue, 0);
  478. $rsnew['user_level'] =& $osj2Dusers->user_level->DbValue;
  479. }
  480. // Field user_status
  481. $osj2Dusers->user_status->SetDbValueDef($osj2Dusers->user_status->CurrentValue, 0);
  482. $rsnew['user_status'] =& $osj2Dusers->user_status->DbValue;
  483. // Call Row Updating event
  484. $bUpdateRow = $osj2Dusers->Row_Updating($rsold, $rsnew);
  485. if ($bUpdateRow) {
  486. $conn->raiseErrorFn = 'ew_ErrorFn';
  487. $EditRow = $conn->Execute($osj2Dusers->UpdateSQL($rsnew));
  488. $conn->raiseErrorFn = '';
  489. } else {
  490. if ($osj2Dusers->CancelMessage <> "") {
  491. $_SESSION[EW_SESSION_MESSAGE] = $osj2Dusers->CancelMessage;
  492. $osj2Dusers->CancelMessage = "";
  493. } else {
  494. $_SESSION[EW_SESSION_MESSAGE] = "Update cancelled";
  495. }
  496. $EditRow = FALSE;
  497. }
  498. }
  499. // Call Row Updated event
  500. if ($EditRow) {
  501. $osj2Dusers->Row_Updated($rsold, $rsnew);
  502. }
  503. if ($EditRow) {
  504. WriteAuditTrailOnEdit($rsold, $rsnew);
  505. }
  506. $rs->Close();
  507. return $EditRow;
  508. }
  509. ?>
  510. <?php
  511. // Write Audit Trail start/end for grid update
  512. function WriteAuditTrailDummy($typ) {
  513. $table = 'osj-users';
  514. // Write Audit Trail
  515. $filePfx = "log";
  516. $curDate = date("Y/m/d");
  517. $curTime = date("H:i:s");
  518. $id = ew_ScriptName();
  519. $user = CurrentUserID();
  520. $action = $typ;
  521. ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, "", "", "", "");
  522. }
  523. ?>
  524. <?php
  525. // Write Audit Trail (edit page)
  526. function WriteAuditTrailOnEdit(&$rsold, &$rsnew) {
  527. global $osj2Dusers;
  528. $table = 'osj-users';
  529. // Get key value
  530. $key = "";
  531. if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
  532. $key .= $rsold['user_id'];
  533. // Write Audit Trail
  534. $filePfx = "log";
  535. $curDate = date("Y/m/d");
  536. $curTime = date("H:i:s");
  537. $id = ew_ScriptName();
  538. $user = CurrentUserID();
  539. $action = "U";
  540. foreach (array_keys($rsnew) as $fldname) {
  541. if ($osj2Dusers->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
  542. if ($osj2Dusers->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // DateTime Field
  543. $modified = (ew_FormatDateTime($rsold[$fldname], 0) <> ew_FormatDateTime($rsnew[$fldname], 0));
  544. } else {
  545. $modified = ($rsold[$fldname] <> $rsnew[$fldname]);
  546. }
  547. if ($modified) {
  548. if ($osj2Dusers->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // Memo Field
  549. $oldvalue = "<MEMO>";
  550. $newvalue = "<MEMO>";
  551. } else {
  552. $oldvalue = $rsold[$fldname];
  553. $newvalue = $rsnew[$fldname];
  554. }
  555. ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, $fldname, $key, $oldvalue, $newvalue);
  556. }
  557. }
  558. }
  559. }
  560. ?>
  561. <?php
  562. // Page Load event
  563. function Page_Load() {
  564. //echo "Page Load";
  565. }
  566. // Page Unload event
  567. function Page_Unload() {
  568. //echo "Page Unload";
  569. }
  570. ?>