PageRenderTime 383ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/osj-osj2dusersadd.php

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