PageRenderTime 43ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/osj-osj2duser_leveledit.php

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