/osj-osj2duser_leveledit.php
PHP | 494 lines | 378 code | 55 blank | 61 comment | 85 complexity | 6bfdab6eaae4a2bbab90362fd46d0ca9 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
- <?php
- define("EW_PAGE_ID", "edit", TRUE); // Page ID
- define("EW_TABLE_NAME", 'osj-user_level', TRUE);
- ?>
- <?php
- session_start(); // Initialize session data
- ob_start(); // Turn on output buffering
- ?>
- <?php include "osj-ewcfg50.php" ?>
- <?php include "osj-ewmysql50.php" ?>
- <?php include "osj-phpfn50.php" ?>
- <?php include "osj-osj2duser_levelinfo.php" ?>
- <?php include "osj-userfn50.php" ?>
- <?php include "osj-osj2dusersinfo.php" ?>
- <?php
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
- header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
- header("Cache-Control: post-check=0, pre-check=0", false);
- header("Pragma: no-cache"); // HTTP/1.0
- ?>
- <?php
-
- // Open connection to the database
- $conn = ew_Connect();
- ?>
- <?php
- $Security = new cAdvancedSecurity();
- ?>
- <?php
- if (!$Security->IsLoggedIn()) $Security->AutoLogin();
- $Security->LoadCurrentUserLevel('osj-user_level');
- if (!$Security->CanAdmin()) {
- $Security->SaveLastUrl();
- Page_Terminate("osj-login.php");
- }
- ?>
- <?php
-
- // Common page loading event (in userfn*.php)
- Page_Loading();
- ?>
- <?php
-
- // Page load event, used in current page
- Page_Load();
- ?>
- <?php
- $osj2Duser_level->Export = @$_GET["export"]; // Get export parameter
- $sExport = $osj2Duser_level->Export; // Get export parameter, used in header
- $sExportFile = $osj2Duser_level->TableVar; // Get export file, used in header
- ?>
- <?php
-
- // Load key from QueryString
- if (@$_GET["user_level_id"] <> "") {
- $osj2Duser_level->user_level_id->setQueryStringValue($_GET["user_level_id"]);
- }
-
- // Create form object
- $objForm = new cFormObj();
- if (@$_POST["a_edit"] <> "") {
- $osj2Duser_level->CurrentAction = $_POST["a_edit"]; // Get action code
- LoadFormValues(); // Get form values
- } else {
- $osj2Duser_level->CurrentAction = "I"; // Default action is display
- }
-
- // Check if valid key
- if ($osj2Duser_level->user_level_id->CurrentValue == "") Page_Terminate($osj2Duser_level->getReturnUrl()); // Invalid key, exit
- switch ($osj2Duser_level->CurrentAction) {
- case "I": // Get a record to display
- if (!LoadRow()) { // Load Record based on key
- $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // No record found
- Page_Terminate($osj2Duser_level->getReturnUrl()); // Return to caller
- }
- break;
- Case "U": // Update
- $osj2Duser_level->SendEmail = TRUE; // Send email on update success
- if (EditRow()) { // Update Record based on key
- $_SESSION[EW_SESSION_MESSAGE] = "Update successful"; // Update success
- Page_Terminate($osj2Duser_level->getReturnUrl()); // Return to caller
- } else {
- RestoreFormValues(); // Restore form values if update failed
- }
- }
-
- // Render the record
- $osj2Duser_level->RowType = EW_ROWTYPE_EDIT; // Render as edit
- RenderRow();
- ?>
- <?php include "osj-header.php" ?>
- <script type="text/javascript">
- <!--
- var EW_PAGE_ID = "edit"; // Page id
- var EW_SHOW_HIGHLIGHT = "Show highlight";
- var EW_HIDE_HIGHLIGHT = "Hide highlight";
-
- //-->
- </script>
- <script type="text/javascript">
- <!--
-
- function ew_ValidateForm(fobj) {
- if (fobj.a_confirm && fobj.a_confirm.value == "F")
- return true;
- var i, elm, aelm, infix;
- var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
- for (i=0; i<rowcnt; i++) {
- infix = (fobj.key_count) ? String(i+1) : "";
- elm = fobj.elements["x" + infix + "_user_level_id"];
- if (elm && !ew_HasValue(elm)) {
- if (!ew_OnError(elm, "Please enter required field - user level id"))
- return false;
- }
- elm = fobj.elements["x" + infix + "_user_level_id"];
- if (elm && !ew_CheckInteger(elm.value)) {
- if (!ew_OnError(elm, "Incorrect integer - user level id"))
- return false;
- }
- elm = fobj.elements["x" + infix + "_user_level_name"];
- if (elm && !ew_HasValue(elm)) {
- if (!ew_OnError(elm, "Please enter required field - user level name"))
- return false;
- }
- elmId = fobj.elements["x" + infix + "_user_level_id"];
- elmName = fobj.elements["x" + infix + "_user_level_name"];
- if (elmId && elmName) {
- elmId.value = elmId.value.replace(/^\s+|\s+$/, '');
- elmName.value = elmName.value.replace(/^\s+|\s+$/, '');
- if (elmId && !ew_CheckInteger(elmId.value)) {
- if (!ew_OnError(elmId, "User Level ID must be integer"))
- return false;
- }
- var level = parseInt(elmId.value);
- if (level == 0) {
- if (elmName.value.toLowerCase() != "default") {
- if (!ew_OnError(elmName, "User level name for user level 0 must be 'Default'"))
- return false;
- }
- } else if (level == -1) {
- if (elmName.value.toLowerCase() != "administrator") {
- if (!ew_OnError(elmName, "User level name for user level -1 must be 'Administrator'"))
- return false;
- }
- } else if (level < -1) {
- if (!ew_OnError(elmId, "User defined User Level ID must be larger than 0"))
- return false;
- } else if (level > 0) {
- if (elmName.value.toLowerCase() == "administrator" || elmName.value.toLowerCase() == "default") {
- if (!ew_OnError(elmName, "User defined User Level name cannot be 'Administrator' or 'Default'"))
- return false;
- }
- }
- }
- }
- return true;
- }
-
- //-->
- </script>
- <script type="text/javascript">
- <!--
- var ew_DHTMLEditors = [];
-
- //-->
- </script>
- <script type="text/javascript">
- <!--
-
- // js for Popup Calendar
- //-->
-
- </script>
- <script type="text/javascript">
- <!--
- var ew_MultiPagePage = "Page"; // multi-page Page Text
- var ew_MultiPageOf = "of"; // multi-page Of Text
- var ew_MultiPagePrev = "Prev"; // multi-page Prev Text
- var ew_MultiPageNext = "Next"; // multi-page Next Text
-
- //-->
- </script>
- <script language="JavaScript" type="text/javascript">
- <!--
-
- // Write your client script here, no need to add script tags.
- // To include another .js script, use:
- // ew_ClientScriptInclude("my_javascript.js");
- //-->
-
- </script>
- <p><span class="phpmaker">Edit TABLE: User Levels<br><br><a href="<?php echo $osj2Duser_level->getReturnUrl() ?>">Go Back</a></span></p>
- <?php
- if (@$_SESSION[EW_SESSION_MESSAGE] <> "") {
- ?>
- <p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
- <?php
- $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message
- }
- ?>
- <form name="fosj2Duser_leveledit" id="fosj2Duser_leveledit" action="osj-osj2duser_leveledit.php" method="post" onSubmit="return ew_ValidateForm(this);">
- <p>
- <input type="hidden" name="a_edit" id="a_edit" value="U">
- <table class="ewTable">
- <tr class="ewTableRow">
- <td class="ewTableHeader">user level id<span class='ewmsg'> *</span></td>
- <td<?php echo $osj2Duser_level->user_level_id->CellAttributes() ?>><span id="cb_x_user_level_id">
- <div<?php echo $osj2Duser_level->user_level_id->ViewAttributes() ?>><?php echo $osj2Duser_level->user_level_id->EditValue ?></div>
- <input type="hidden" name="x_user_level_id" id="x_user_level_id" value="<?php echo ew_HtmlEncode($osj2Duser_level->user_level_id->CurrentValue) ?>">
- </span></td>
- </tr>
- <tr class="ewTableAltRow">
- <td class="ewTableHeader">user level name<span class='ewmsg'> *</span></td>
- <td<?php echo $osj2Duser_level->user_level_name->CellAttributes() ?>><span id="cb_x_user_level_name">
- <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() ?>>
- </span></td>
- </tr>
- </table>
- <p>
- <input type="submit" name="btnAction" id="btnAction" value=" Edit ">
- </form>
- <script language="JavaScript" type="text/javascript">
- <!--
-
- // Write your table-specific startup script here
- // document.write("page loaded");
- //-->
-
- </script>
- <?php include "osj-footer.php" ?>
- <?php
-
- // If control is passed here, simply terminate the page without redirect
- Page_Terminate();
-
- // -----------------------------------------------------------------
- // Subroutine Page_Terminate
- // - called when exit page
- // - clean up connection and objects
- // - if url specified, redirect to url, otherwise end response
- function Page_Terminate($url = "") {
- global $conn;
-
- // Page unload event, used in current page
- Page_Unload();
-
- // Global page unloaded event (in userfn*.php)
- Page_Unloaded();
-
- // Close Connection
- $conn->Close();
-
- // Go to url if specified
- if ($url <> "") {
- ob_end_clean();
- header("Location: $url");
- }
- exit();
- }
- ?>
- <?php
-
- // Load form values
- function LoadFormValues() {
-
- // Load from form
- global $objForm, $osj2Duser_level;
- $osj2Duser_level->user_level_id->setFormValue($objForm->GetValue("x_user_level_id"));
- $osj2Duser_level->user_level_name->setFormValue($objForm->GetValue("x_user_level_name"));
- }
-
- // Restore form values
- function RestoreFormValues() {
- global $osj2Duser_level;
- $osj2Duser_level->user_level_id->CurrentValue = $osj2Duser_level->user_level_id->FormValue;
- $osj2Duser_level->user_level_name->CurrentValue = $osj2Duser_level->user_level_name->FormValue;
- }
- ?>
- <?php
-
- // Load row based on key values
- function LoadRow() {
- global $conn, $Security, $osj2Duser_level;
- $sFilter = $osj2Duser_level->SqlKeyFilter();
- if (!is_numeric($osj2Duser_level->user_level_id->CurrentValue)) {
- return FALSE; // Invalid key, exit
- }
- $sFilter = str_replace("@user_level_id@", ew_AdjustSql($osj2Duser_level->user_level_id->CurrentValue), $sFilter); // Replace key value
-
- // Call Row Selecting event
- $osj2Duser_level->Row_Selecting($sFilter);
-
- // Load sql based on filter
- $osj2Duser_level->CurrentFilter = $sFilter;
- $sSql = $osj2Duser_level->SQL();
- if ($rs = $conn->Execute($sSql)) {
- if ($rs->EOF) {
- $LoadRow = FALSE;
- } else {
- $LoadRow = TRUE;
- $rs->MoveFirst();
- LoadRowValues($rs); // Load row values
-
- // Call Row Selected event
- $osj2Duser_level->Row_Selected($rs);
- }
- $rs->Close();
- } else {
- $LoadRow = FALSE;
- }
- return $LoadRow;
- }
-
- // Load row values from recordset
- function LoadRowValues(&$rs) {
- global $osj2Duser_level;
- $osj2Duser_level->user_level_id->setDbValue($rs->fields('user_level_id'));
- if (is_null($osj2Duser_level->user_level_id->CurrentValue)) {
- $osj2Duser_level->user_level_id->CurrentValue = 0;
- } else {
- $osj2Duser_level->user_level_id->CurrentValue = intval($osj2Duser_level->user_level_id->CurrentValue);
- }
- $osj2Duser_level->user_level_name->setDbValue($rs->fields('user_level_name'));
- }
- ?>
- <?php
-
- // Render row values based on field settings
- function RenderRow() {
- global $conn, $Security, $osj2Duser_level;
-
- // Call Row Rendering event
- $osj2Duser_level->Row_Rendering();
-
- // Common render codes for all row types
- // user_level_id
-
- $osj2Duser_level->user_level_id->CellCssStyle = "";
- $osj2Duser_level->user_level_id->CellCssClass = "";
-
- // user_level_name
- $osj2Duser_level->user_level_name->CellCssStyle = "";
- $osj2Duser_level->user_level_name->CellCssClass = "";
- if ($osj2Duser_level->RowType == EW_ROWTYPE_VIEW) { // View row
- } elseif ($osj2Duser_level->RowType == EW_ROWTYPE_ADD) { // Add row
- } elseif ($osj2Duser_level->RowType == EW_ROWTYPE_EDIT) { // Edit row
-
- // user_level_id
- $osj2Duser_level->user_level_id->EditCustomAttributes = "";
- $osj2Duser_level->user_level_id->EditValue = $osj2Duser_level->user_level_id->CurrentValue;
- $osj2Duser_level->user_level_id->CssStyle = "";
- $osj2Duser_level->user_level_id->CssClass = "";
- $osj2Duser_level->user_level_id->ViewCustomAttributes = "";
-
- // user_level_name
- $osj2Duser_level->user_level_name->EditCustomAttributes = "";
- $osj2Duser_level->user_level_name->EditValue = ew_HtmlEncode($osj2Duser_level->user_level_name->CurrentValue);
- } elseif ($osj2Duser_level->RowType == EW_ROWTYPE_SEARCH) { // Search row
- }
-
- // Call Row Rendered event
- $osj2Duser_level->Row_Rendered();
- }
- ?>
- <?php
-
- // Update record based on key values
- function EditRow() {
- global $conn, $Security, $osj2Duser_level;
- $sFilter = $osj2Duser_level->SqlKeyFilter();
- if (!is_numeric($osj2Duser_level->user_level_id->CurrentValue)) {
- return FALSE;
- }
- $sFilter = str_replace("@user_level_id@", ew_AdjustSql($osj2Duser_level->user_level_id->CurrentValue), $sFilter); // Replace key value
- $osj2Duser_level->CurrentFilter = $sFilter;
- $sSql = $osj2Duser_level->SQL();
- $conn->raiseErrorFn = 'ew_ErrorFn';
- $rs = $conn->Execute($sSql);
- $conn->raiseErrorFn = '';
- if ($rs === FALSE)
- return FALSE;
- if ($rs->EOF) {
- $EditRow = FALSE; // Update Failed
- } else {
-
- // Save old values
- $rsold =& $rs->fields;
- $rsnew = array();
-
- // Field user_level_id
- // Field user_level_name
-
- $osj2Duser_level->user_level_name->SetDbValueDef($osj2Duser_level->user_level_name->CurrentValue, "");
- $rsnew['user_level_name'] =& $osj2Duser_level->user_level_name->DbValue;
-
- // Call Row Updating event
- $bUpdateRow = $osj2Duser_level->Row_Updating($rsold, $rsnew);
- if ($bUpdateRow) {
- $conn->raiseErrorFn = 'ew_ErrorFn';
- $EditRow = $conn->Execute($osj2Duser_level->UpdateSQL($rsnew));
- $conn->raiseErrorFn = '';
- } else {
- if ($osj2Duser_level->CancelMessage <> "") {
- $_SESSION[EW_SESSION_MESSAGE] = $osj2Duser_level->CancelMessage;
- $osj2Duser_level->CancelMessage = "";
- } else {
- $_SESSION[EW_SESSION_MESSAGE] = "Update cancelled";
- }
- $EditRow = FALSE;
- }
- }
-
- // Call Row Updated event
- if ($EditRow) {
- $osj2Duser_level->Row_Updated($rsold, $rsnew);
- }
- if ($EditRow) {
- WriteAuditTrailOnEdit($rsold, $rsnew);
- }
- $rs->Close();
- return $EditRow;
- }
- ?>
- <?php
-
- // Write Audit Trail start/end for grid update
- function WriteAuditTrailDummy($typ) {
- $table = 'osj-user_level';
-
- // Write Audit Trail
- $filePfx = "log";
- $curDate = date("Y/m/d");
- $curTime = date("H:i:s");
- $id = ew_ScriptName();
- $user = CurrentUserID();
- $action = $typ;
- ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, "", "", "", "");
- }
- ?>
- <?php
-
- // Write Audit Trail (edit page)
- function WriteAuditTrailOnEdit(&$rsold, &$rsnew) {
- global $osj2Duser_level;
- $table = 'osj-user_level';
-
- // Get key value
- $key = "";
- if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
- $key .= $rsold['user_level_id'];
-
- // Write Audit Trail
- $filePfx = "log";
- $curDate = date("Y/m/d");
- $curTime = date("H:i:s");
- $id = ew_ScriptName();
- $user = CurrentUserID();
- $action = "U";
- foreach (array_keys($rsnew) as $fldname) {
- if ($osj2Duser_level->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
- if ($osj2Duser_level->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // DateTime Field
- $modified = (ew_FormatDateTime($rsold[$fldname], 0) <> ew_FormatDateTime($rsnew[$fldname], 0));
- } else {
- $modified = ($rsold[$fldname] <> $rsnew[$fldname]);
- }
- if ($modified) {
- if ($osj2Duser_level->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // Memo Field
- $oldvalue = "<MEMO>";
- $newvalue = "<MEMO>";
- } else {
- $oldvalue = $rsold[$fldname];
- $newvalue = $rsnew[$fldname];
- }
- ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, $fldname, $key, $oldvalue, $newvalue);
- }
- }
- }
- }
- ?>
- <?php
-
- // Page Load event
- function Page_Load() {
-
- //echo "Page Load";
- }
-
- // Page Unload event
- function Page_Unload() {
-
- //echo "Page Unload";
- }
- ?>