/osj-osj2duser_detailadd.php
PHP | 560 lines | 414 code | 70 blank | 76 comment | 57 complexity | a8bf8e5139e2f51f76a8bdb9e1041c01 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
- <?php
- define("EW_PAGE_ID", "add", TRUE); // Page ID
- define("EW_TABLE_NAME", 'osj-user_detail', 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_detailinfo.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_detail');
- if (!$Security->IsLoggedIn()) {
- $Security->SaveLastUrl();
- Page_Terminate("osj-login.php");
- }
- if (!$Security->CanAdd()) {
- $Security->SaveLastUrl();
- Page_Terminate("osj-osj2duser_detaillist.php");
- }
- if ($Security->IsLoggedIn() && $Security->CurrentUserID() == "") {
- $_SESSION[EW_SESSION_MESSAGE] = "You do not have the right permission to view the page";
- 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_detail->Export = @$_GET["export"]; // Get export parameter
- $sExport = $osj2Duser_detail->Export; // Get export parameter, used in header
- $sExportFile = $osj2Duser_detail->TableVar; // Get export file, used in header
- ?>
- <?php
-
- // Load key values from QueryString
- $bCopy = TRUE;
- if (@$_GET["user_detail_id"] != "") {
- $osj2Duser_detail->user_detail_id->setQueryStringValue($_GET["user_detail_id"]);
- } else {
- $bCopy = FALSE;
- }
-
- // Create form object
- $objForm = new cFormObj();
-
- // Process form if post back
- if (@$_POST["a_add"] <> "") {
- $osj2Duser_detail->CurrentAction = $_POST["a_add"]; // Get form action
- LoadFormValues(); // Load form values
- } else { // Not post back
- if ($bCopy) {
- $osj2Duser_detail->CurrentAction = "C"; // Copy Record
- } else {
- $osj2Duser_detail->CurrentAction = "I"; // Display Blank Record
- LoadDefaultValues(); // Load default values
- }
- }
-
- // Perform action based on action code
- switch ($osj2Duser_detail->CurrentAction) {
- case "I": // Blank record, no action required
- break;
- case "C": // Copy an existing record
- if (!LoadRow()) { // Load record based on key
- $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // No record found
- Page_Terminate($osj2Duser_detail->getReturnUrl()); // Clean up and return
- }
- break;
- case "A": // ' Add new record
- $osj2Duser_detail->SendEmail = TRUE; // Send email on add success
- if (AddRow()) { // Add successful
- $_SESSION[EW_SESSION_MESSAGE] = "Add New Record Successful"; // Set up success message
- Page_Terminate($osj2Duser_detail->KeyUrl($osj2Duser_detail->getReturnUrl())); // Clean up and return
- } else {
- RestoreFormValues(); // Add failed, restore form values
- }
- }
-
- // Render row based on row type
- $osj2Duser_detail->RowType = EW_ROWTYPE_ADD; // Render add type
- RenderRow();
- ?>
- <?php include "osj-header.php" ?>
- <script type="text/javascript">
- <!--
- var EW_PAGE_ID = "add"; // 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_first_name"];
- if (elm && !ew_HasValue(elm)) {
- if (!ew_OnError(elm, "Please enter required field - First Name"))
- return false;
- }
- elm = fobj.elements["x" + infix + "_user_last_name"];
- if (elm && !ew_HasValue(elm)) {
- if (!ew_OnError(elm, "Please enter required field - Last Name"))
- 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">Add to TABLE: User Details<br><br><a href="<?php echo $osj2Duser_detail->getReturnUrl() ?>">Go Back</a></span></p>
- <?php
- if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Mesasge in Session, display
- ?>
- <p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
- <?php
- $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
- }
- ?>
- <form name="fosj2Duser_detailadd" id="fosj2Duser_detailadd" action="osj-osj2duser_detailadd.php" method="post" onSubmit="return ew_ValidateForm(this);">
- <p>
- <input type="hidden" name="a_add" id="a_add" value="A">
- <table class="ewTable">
- <tr class="ewTableRow">
- <td class="ewTableHeader">detail edit date</td>
- <td<?php echo $osj2Duser_detail->user_detail_edit_date->CellAttributes() ?>><span id="cb_x_user_detail_edit_date">
- </span></td>
- </tr>
- <tr class="ewTableAltRow">
- <td class="ewTableHeader">First Name<span class='ewmsg'> *</span></td>
- <td<?php echo $osj2Duser_detail->user_first_name->CellAttributes() ?>><span id="cb_x_user_first_name">
- <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() ?>>
- </span></td>
- </tr>
- <tr class="ewTableRow">
- <td class="ewTableHeader">Last Name<span class='ewmsg'> *</span></td>
- <td<?php echo $osj2Duser_detail->user_last_name->CellAttributes() ?>><span id="cb_x_user_last_name">
- <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() ?>>
- </span></td>
- </tr>
- <tr class="ewTableAltRow">
- <td class="ewTableHeader">Description<span class='ewmsg'> *</span></td>
- <td<?php echo $osj2Duser_detail->user_description->CellAttributes() ?>><span id="cb_x_user_description">
- <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>
- </span></td>
- </tr>
- <tr class="ewTableRow">
- <td class="ewTableHeader">Company<span class='ewmsg'> *</span></td>
- <td<?php echo $osj2Duser_detail->user_company->CellAttributes() ?>><span id="cb_x_user_company">
- <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() ?>>
- </span></td>
- </tr>
- </table>
- <p>
- <input type="submit" name="btnAction" id="btnAction" value=" Add ">
- </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 default values
- function LoadDefaultValues() {
- global $osj2Duser_detail;
- $osj2Duser_detail->user_id->CurrentValue = 0;
- $osj2Duser_detail->user_detail_creation_date->CurrentValue = "0000-00-00 00:00:00";
- $osj2Duser_detail->user_detail_edit_date->CurrentValue = "CURRENT_TIMESTAMP";
- }
- ?>
- <?php
-
- // Load form values
- function LoadFormValues() {
-
- // Load from form
- global $objForm, $osj2Duser_detail;
- $osj2Duser_detail->user_id->setFormValue($objForm->GetValue("x_user_id"));
- $osj2Duser_detail->user_detail_creation_date->setFormValue($objForm->GetValue("x_user_detail_creation_date"));
- $osj2Duser_detail->user_detail_creation_date->CurrentValue = ew_UnFormatDateTime($osj2Duser_detail->user_detail_creation_date->CurrentValue, 6);
- $osj2Duser_detail->user_detail_edit_date->setFormValue($objForm->GetValue("x_user_detail_edit_date"));
- $osj2Duser_detail->user_detail_edit_date->CurrentValue = ew_UnFormatDateTime($osj2Duser_detail->user_detail_edit_date->CurrentValue, 6);
- $osj2Duser_detail->user_first_name->setFormValue($objForm->GetValue("x_user_first_name"));
- $osj2Duser_detail->user_last_name->setFormValue($objForm->GetValue("x_user_last_name"));
- $osj2Duser_detail->user_description->setFormValue($objForm->GetValue("x_user_description"));
- $osj2Duser_detail->user_company->setFormValue($objForm->GetValue("x_user_company"));
- }
-
- // Restore form values
- function RestoreFormValues() {
- global $osj2Duser_detail;
- $osj2Duser_detail->user_id->CurrentValue = $osj2Duser_detail->user_id->FormValue;
- $osj2Duser_detail->user_detail_creation_date->CurrentValue = $osj2Duser_detail->user_detail_creation_date->FormValue;
- $osj2Duser_detail->user_detail_creation_date->CurrentValue = ew_UnFormatDateTime($osj2Duser_detail->user_detail_creation_date->CurrentValue, 6);
- $osj2Duser_detail->user_detail_edit_date->CurrentValue = $osj2Duser_detail->user_detail_edit_date->FormValue;
- $osj2Duser_detail->user_detail_edit_date->CurrentValue = ew_UnFormatDateTime($osj2Duser_detail->user_detail_edit_date->CurrentValue, 6);
- $osj2Duser_detail->user_first_name->CurrentValue = $osj2Duser_detail->user_first_name->FormValue;
- $osj2Duser_detail->user_last_name->CurrentValue = $osj2Duser_detail->user_last_name->FormValue;
- $osj2Duser_detail->user_description->CurrentValue = $osj2Duser_detail->user_description->FormValue;
- $osj2Duser_detail->user_company->CurrentValue = $osj2Duser_detail->user_company->FormValue;
- }
- ?>
- <?php
-
- // Load row based on key values
- function LoadRow() {
- global $conn, $Security, $osj2Duser_detail;
- $sFilter = $osj2Duser_detail->SqlKeyFilter();
- if (!is_numeric($osj2Duser_detail->user_detail_id->CurrentValue)) {
- return FALSE; // Invalid key, exit
- }
- $sFilter = str_replace("@user_detail_id@", ew_AdjustSql($osj2Duser_detail->user_detail_id->CurrentValue), $sFilter); // Replace key value
- if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
- $sFilter = $osj2Duser_detail->AddUserIDFilter($sFilter, $Security->CurrentUserID()); // Add User ID filter
- }
-
- // Call Row Selecting event
- $osj2Duser_detail->Row_Selecting($sFilter);
-
- // Load sql based on filter
- $osj2Duser_detail->CurrentFilter = $sFilter;
- $sSql = $osj2Duser_detail->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_detail->Row_Selected($rs);
- }
- $rs->Close();
- } else {
- $LoadRow = FALSE;
- }
- return $LoadRow;
- }
-
- // Load row values from recordset
- function LoadRowValues(&$rs) {
- global $osj2Duser_detail;
- $osj2Duser_detail->user_detail_id->setDbValue($rs->fields('user_detail_id'));
- $osj2Duser_detail->user_id->setDbValue($rs->fields('user_id'));
- $osj2Duser_detail->user_detail_creation_date->setDbValue($rs->fields('user_detail_creation_date'));
- $osj2Duser_detail->user_detail_edit_date->setDbValue($rs->fields('user_detail_edit_date'));
- $osj2Duser_detail->user_first_name->setDbValue($rs->fields('user_first_name'));
- $osj2Duser_detail->user_last_name->setDbValue($rs->fields('user_last_name'));
- $osj2Duser_detail->user_description->setDbValue($rs->fields('user_description'));
- $osj2Duser_detail->user_company->setDbValue($rs->fields('user_company'));
- }
- ?>
- <?php
-
- // Render row values based on field settings
- function RenderRow() {
- global $conn, $Security, $osj2Duser_detail;
-
- // Call Row Rendering event
- $osj2Duser_detail->Row_Rendering();
-
- // Common render codes for all row types
- // user_id
-
- $osj2Duser_detail->user_id->CellCssStyle = "";
- $osj2Duser_detail->user_id->CellCssClass = "";
-
- // user_detail_creation_date
- $osj2Duser_detail->user_detail_creation_date->CellCssStyle = "";
- $osj2Duser_detail->user_detail_creation_date->CellCssClass = "";
-
- // user_detail_edit_date
- $osj2Duser_detail->user_detail_edit_date->CellCssStyle = "";
- $osj2Duser_detail->user_detail_edit_date->CellCssClass = "";
-
- // user_first_name
- $osj2Duser_detail->user_first_name->CellCssStyle = "";
- $osj2Duser_detail->user_first_name->CellCssClass = "";
-
- // user_last_name
- $osj2Duser_detail->user_last_name->CellCssStyle = "";
- $osj2Duser_detail->user_last_name->CellCssClass = "";
-
- // user_description
- $osj2Duser_detail->user_description->CellCssStyle = "";
- $osj2Duser_detail->user_description->CellCssClass = "";
-
- // user_company
- $osj2Duser_detail->user_company->CellCssStyle = "";
- $osj2Duser_detail->user_company->CellCssClass = "";
- if ($osj2Duser_detail->RowType == EW_ROWTYPE_VIEW) { // View row
- } elseif ($osj2Duser_detail->RowType == EW_ROWTYPE_ADD) { // Add row
-
- // user_detail_edit_date
- $osj2Duser_detail->user_detail_edit_date->EditCustomAttributes = "";
-
- // user_first_name
- $osj2Duser_detail->user_first_name->EditCustomAttributes = "";
- $osj2Duser_detail->user_first_name->EditValue = ew_HtmlEncode($osj2Duser_detail->user_first_name->CurrentValue);
-
- // user_last_name
- $osj2Duser_detail->user_last_name->EditCustomAttributes = "";
- $osj2Duser_detail->user_last_name->EditValue = ew_HtmlEncode($osj2Duser_detail->user_last_name->CurrentValue);
-
- // user_description
- $osj2Duser_detail->user_description->EditCustomAttributes = "";
- $osj2Duser_detail->user_description->EditValue = ew_HtmlEncode($osj2Duser_detail->user_description->CurrentValue);
-
- // user_company
- $osj2Duser_detail->user_company->EditCustomAttributes = "";
- $osj2Duser_detail->user_company->EditValue = ew_HtmlEncode($osj2Duser_detail->user_company->CurrentValue);
- } elseif ($osj2Duser_detail->RowType == EW_ROWTYPE_EDIT) { // Edit row
- } elseif ($osj2Duser_detail->RowType == EW_ROWTYPE_SEARCH) { // Search row
- }
-
- // Call Row Rendered event
- $osj2Duser_detail->Row_Rendered();
- }
- ?>
- <?php
-
- // Add record
- function AddRow() {
- global $conn, $Security, $osj2Duser_detail;
-
- // Check for duplicate key
- $bCheckKey = TRUE;
- $sFilter = $osj2Duser_detail->SqlKeyFilter();
- if (trim(strval($osj2Duser_detail->user_detail_id->CurrentValue)) == "") {
- $bCheckKey = FALSE;
- } else {
- $sFilter = str_replace("@user_detail_id@", ew_AdjustSql($osj2Duser_detail->user_detail_id->CurrentValue), $sFilter); // Replace key value
- }
- if (!is_numeric($osj2Duser_detail->user_detail_id->CurrentValue)) {
- $bCheckKey = FALSE;
- }
- if ($bCheckKey) {
- $rsChk = $osj2Duser_detail->LoadRs($sFilter);
- if ($rsChk && !$rsChk->EOF) {
- $_SESSION[EW_SESSION_MESSAGE] = "Duplicate value for primary key";
- $rsChk->Close();
- return FALSE;
- }
- }
- $rsnew = array();
-
- // Field user_id
- $osj2Duser_detail->user_id->SetDbValueDef(CurrentUserID(), 0);
- $rsnew['user_id'] =& $osj2Duser_detail->user_id->DbValue;
-
- // Field user_detail_creation_date
- $osj2Duser_detail->user_detail_creation_date->SetDbValueDef(ew_CurrentDateTime(), ew_CurrentDate());
- $rsnew['user_detail_creation_date'] =& $osj2Duser_detail->user_detail_creation_date->DbValue;
-
- // Field user_detail_edit_date
- $osj2Duser_detail->user_detail_edit_date->SetDbValueDef(ew_UnFormatDateTime($osj2Duser_detail->user_detail_edit_date->CurrentValue, 6), NULL);
- $rsnew['user_detail_edit_date'] =& $osj2Duser_detail->user_detail_edit_date->DbValue;
-
- // Field user_first_name
- $osj2Duser_detail->user_first_name->SetDbValueDef($osj2Duser_detail->user_first_name->CurrentValue, "");
- $rsnew['user_first_name'] =& $osj2Duser_detail->user_first_name->DbValue;
-
- // Field user_last_name
- $osj2Duser_detail->user_last_name->SetDbValueDef($osj2Duser_detail->user_last_name->CurrentValue, "");
- $rsnew['user_last_name'] =& $osj2Duser_detail->user_last_name->DbValue;
-
- // Field user_description
- $osj2Duser_detail->user_description->SetDbValueDef($osj2Duser_detail->user_description->CurrentValue, "");
- $rsnew['user_description'] =& $osj2Duser_detail->user_description->DbValue;
-
- // Field user_company
- $osj2Duser_detail->user_company->SetDbValueDef($osj2Duser_detail->user_company->CurrentValue, "");
- $rsnew['user_company'] =& $osj2Duser_detail->user_company->DbValue;
-
- // Call Row Inserting event
- $bInsertRow = $osj2Duser_detail->Row_Inserting($rsnew);
- if ($bInsertRow) {
- $conn->raiseErrorFn = 'ew_ErrorFn';
- $AddRow = $conn->Execute($osj2Duser_detail->InsertSQL($rsnew));
- $conn->raiseErrorFn = '';
- } else {
- if ($osj2Duser_detail->CancelMessage <> "") {
- $_SESSION[EW_SESSION_MESSAGE] = $osj2Duser_detail->CancelMessage;
- $osj2Duser_detail->CancelMessage = "";
- } else {
- $_SESSION[EW_SESSION_MESSAGE] = "Insert cancelled";
- }
- $AddRow = FALSE;
- }
- if ($AddRow) {
- $osj2Duser_detail->user_detail_id->setDbValue($conn->Insert_ID());
- $rsnew['user_detail_id'] =& $osj2Duser_detail->user_detail_id->DbValue;
-
- // Call Row Inserted event
- $osj2Duser_detail->Row_Inserted($rsnew);
- WriteAuditTrailOnAdd($rsnew);
- }
- return $AddRow;
- }
- ?>
- <?php
-
- // Write Audit Trail start/end for grid update
- function WriteAuditTrailDummy($typ) {
- $table = 'osj-user_detail';
-
- // 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 (add page)
- function WriteAuditTrailOnAdd(&$rs) {
- global $osj2Duser_detail;
- $table = 'osj-user_detail';
-
- // Get key value
- $key = "";
- if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
- $key .= $rs['user_detail_id'];
-
- // Write Audit Trail
- $filePfx = "log";
- $curDate = date("Y/m/d");
- $curTime = date("H:i:s");
- $id = ew_ScriptName();
- $user = CurrentUserID();
- $action = "A";
- $oldvalue = "";
- foreach (array_keys($rs) as $fldname) {
- if ($osj2Duser_detail->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
- $newvalue = ($osj2Duser_detail->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) ? "<MEMO>" : $rs[$fldname]; // Memo Field
- 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";
- }
- ?>