/osj-osj2dusersdelete.php
PHP | 622 lines | 461 code | 76 blank | 85 comment | 72 complexity | 9a10d6ba7afc82b506ad4c607f7e7db1 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
- <?php
- define("EW_PAGE_ID", "delete", TRUE); // Page ID
- define("EW_TABLE_NAME", 'osj-users', 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-osj2dusersinfo.php" ?>
- <?php include "osj-userfn50.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-users');
- if (!$Security->IsLoggedIn()) {
- $Security->SaveLastUrl();
- Page_Terminate("osj-login.php");
- }
- if (!$Security->CanDelete()) {
- $Security->SaveLastUrl();
- Page_Terminate("osj-osj2duserslist.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
- $osj2Dusers->Export = @$_GET["export"]; // Get export parameter
- $sExport = $osj2Dusers->Export; // Get export parameter, used in header
- $sExportFile = $osj2Dusers->TableVar; // Get export file, used in header
- ?>
- <?php
-
- // Load Key Parameters
- $sKey = "";
- $bSingleDelete = TRUE; // Initialize as single delete
- $arRecKeys = array();
- $nKeySelected = 0; // Initialize selected key count
- $sFilter = "";
- if (@$_GET["user_id"] <> "") {
- $osj2Dusers->user_id->setQueryStringValue($_GET["user_id"]);
- if (!is_numeric($osj2Dusers->user_id->QueryStringValue)) {
- Page_Terminate($osj2Dusers->getReturnUrl()); // Prevent sql injection, exit
- }
- $sKey .= $osj2Dusers->user_id->QueryStringValue;
- } else {
- $bSingleDelete = FALSE;
- }
- if ($bSingleDelete) {
- $nKeySelected = 1; // Set up key selected count
- $arRecKeys[0] = $sKey;
- } else {
- if (isset($_POST["key_m"])) { // Key in form
- $nKeySelected = count($_POST["key_m"]); // Set up key selected count
- $arRecKeys = ew_StripSlashes($_POST["key_m"]);
- }
- }
- if ($nKeySelected <= 0) Page_Terminate($osj2Dusers->getReturnUrl()); // No key specified, exit
-
- // Build filter
- foreach ($arRecKeys as $sKey) {
- $sFilter .= "(";
-
- // Set up key field
- $sKeyFld = $sKey;
- if (!is_numeric($sKeyFld)) {
- Page_Terminate($osj2Dusers->getReturnUrl()); // Prevent sql injection, exit
- }
- $sFilter .= "`user_id`=" . ew_AdjustSql($sKeyFld) . " AND ";
- if (substr($sFilter, -5) == " AND ") $sFilter = substr($sFilter, 0, strlen($sFilter)-5) . ") OR ";
- }
- if (substr($sFilter, -4) == " OR ") $sFilter = substr($sFilter, 0, strlen($sFilter)-4);
-
- // Set up filter (Sql Where Clause) and get Return Sql
- // Sql constructor in osj2Dusers class, osj2Dusersinfo.php
-
- $osj2Dusers->CurrentFilter = $sFilter;
-
- // Get action
- if (@$_POST["a_delete"] <> "") {
- $osj2Dusers->CurrentAction = $_POST["a_delete"];
- } else {
- $osj2Dusers->CurrentAction = "I"; // Display record
- }
- switch ($osj2Dusers->CurrentAction) {
- case "D": // Delete
- $osj2Dusers->SendEmail = TRUE; // Send email on delete success
- if (DeleteRows()) { // delete rows
- $_SESSION[EW_SESSION_MESSAGE] = "Delete Successful"; // Set up success message
- Page_Terminate($osj2Dusers->getReturnUrl()); // Return to caller
- }
- }
-
- // Load records for display
- $rs = LoadRecordset();
- $nTotalRecs = $rs->RecordCount(); // Get record count
- if ($nTotalRecs <= 0) { // No record found, exit
- $rs->Close();
- Page_Terminate($osj2Dusers->getReturnUrl()); // Return to caller
- }
- ?>
- <?php include "osj-header.php" ?>
- <script type="text/javascript">
- <!--
- var EW_PAGE_ID = "delete"; // Page id
- var EW_SHOW_HIGHLIGHT = "Show highlight";
- var EW_HIDE_HIGHLIGHT = "Hide highlight";
-
- //-->
- </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">Delete from TABLE: Users<br><br><a href="<?php echo $osj2Dusers->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 action="osj-osj2dusersdelete.php" method="post">
- <p>
- <input type="hidden" name="a_delete" id="a_delete" value="D">
- <?php foreach ($arRecKeys as $sKey) { ?>
- <input type="hidden" name="key_m[]" id="key_m[]" value="<?php echo ew_HtmlEncode($sKey) ?>">
- <?php } ?>
- <table class="ewTable">
- <tr class="ewTableHeader">
- <td valign="top">User ID</td>
- <td valign="top">Creation Date</td>
- <td valign="top">Edit Date</td>
- <td valign="top">Email</td>
- <td valign="top">Password</td>
- <td valign="top">User Level</td>
- <td valign="top">User Status</td>
- </tr>
- <?php
- $nRecCount = 0;
- $i = 0;
- while (!$rs->EOF) {
- $nRecCount++;
-
- // Set row class and style
- $osj2Dusers->CssClass = "ewTableRow";
- $osj2Dusers->CssStyle = "";
-
- // Display alternate color for rows
- if ($nRecCount % 2 <> 1) {
- $osj2Dusers->CssClass = "ewTableAltRow";
- }
-
- // Get the field contents
- LoadRowValues($rs);
-
- // Render row value
- $osj2Dusers->RowType = EW_ROWTYPE_VIEW; // view
- RenderRow();
- ?>
- <tr<?php echo $osj2Dusers->DisplayAttributes() ?>>
- <td<?php echo $osj2Dusers->user_id->CellAttributes() ?>>
- </td>
- <td<?php echo $osj2Dusers->user_creation_date->CellAttributes() ?>>
- </td>
- <td<?php echo $osj2Dusers->user_edit_date->CellAttributes() ?>>
- </td>
- <td<?php echo $osj2Dusers->user_email->CellAttributes() ?>>
- <div<?php echo $osj2Dusers->user_email->ViewAttributes() ?>><?php echo $osj2Dusers->user_email->ViewValue ?></div>
- </td>
- <td<?php echo $osj2Dusers->user_password->CellAttributes() ?>>
- <div<?php echo $osj2Dusers->user_password->ViewAttributes() ?>><?php echo $osj2Dusers->user_password->ViewValue ?></div>
- </td>
- <td<?php echo $osj2Dusers->user_level->CellAttributes() ?>>
- <div<?php echo $osj2Dusers->user_level->ViewAttributes() ?>><?php echo $osj2Dusers->user_level->ViewValue ?></div>
- </td>
- <td<?php echo $osj2Dusers->user_status->CellAttributes() ?>>
- <div<?php echo $osj2Dusers->user_status->ViewAttributes() ?>><?php echo $osj2Dusers->user_status->ViewValue ?></div>
- </td>
- </tr>
- <?php
- $rs->MoveNext();
- }
- $rs->Close();
- ?>
- </table>
- <p>
- <input type="submit" name="Action" id="Action" value="Confirm Delete">
- </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
-
- // ------------------------------------------------
- // Function DeleteRows
- // - Delete Records based on current filter
- function DeleteRows() {
- global $conn, $Security, $osj2Dusers;
- $DeleteRows = TRUE;
- $sWrkFilter = $osj2Dusers->CurrentFilter;
- if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
- $sWrkFilter = $osj2Dusers->AddUserIDFilter($sWrkFilter, $Security->CurrentUserID()); // Add User ID filter
- }
-
- // Set up filter (Sql Where Clause) and get Return Sql
- // Sql constructor in osj2Dusers class, osj2Dusersinfo.php
-
- $osj2Dusers->CurrentFilter = $sWrkFilter;
- $sSql = $osj2Dusers->SQL();
- $conn->raiseErrorFn = 'ew_ErrorFn';
- $rs = $conn->Execute($sSql);
- $conn->raiseErrorFn = '';
- if ($rs === FALSE) {
- return FALSE;
- } elseif ($rs->EOF) {
- $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // No record found
- $rs->Close();
- return FALSE;
- }
- $conn->BeginTrans();
- WriteAuditTrailDummy("*** batch delete begin ***"); // Batch delete begin
-
- // Clone old rows
- $rsold = ($rs) ? $rs->GetRows() : array();
- if ($rs) $rs->Close();
-
- // Call row deleting event
- if ($DeleteRows) {
- foreach ($rsold as $row) {
- $DeleteRows = $osj2Dusers->Row_Deleting($row);
- if (!$DeleteRows) break;
- }
- }
- if ($DeleteRows) {
- $sKey = "";
- foreach ($rsold as $row) {
- $sThisKey = "";
- if ($sThisKey <> "") $sThisKey .= EW_COMPOSITE_KEY_SEPARATOR;
- $sThisKey .= $row['user_id'];
- $conn->raiseErrorFn = 'ew_ErrorFn';
- $DeleteRows = $conn->Execute($osj2Dusers->DeleteSQL($row)); // Delete
- $conn->raiseErrorFn = '';
- if ($DeleteRows === FALSE)
- break;
- if ($sKey <> "") $sKey .= ", ";
- $sKey .= $sThisKey;
- }
- } else {
-
- // Set up error message
- if ($osj2Dusers->CancelMessage <> "") {
- $_SESSION[EW_SESSION_MESSAGE] = $osj2Dusers->CancelMessage;
- $osj2Dusers->CancelMessage = "";
- } else {
- $_SESSION[EW_SESSION_MESSAGE] = "Delete cancelled";
- }
- }
- if ($DeleteRows) {
- $conn->CommitTrans(); // Commit the changes
- if ($DeleteRows) {
- foreach ($rsold as $row) {
- WriteAuditTrailOnDelete($row);
- }
- }
- WriteAuditTrailDummy("*** batch delete success ***"); // Batch delete success
- } else {
- $conn->RollbackTrans(); // Rollback changes
- WriteAuditTrailDummy("*** batch delete rollback ***"); // Batch delete rollback
- }
-
- // Call recordset deleted event
- if ($DeleteRows) {
- foreach ($rsold as $row) {
- $osj2Dusers->Row_Deleted($row);
- }
- }
- return $DeleteRows;
- }
- ?>
- <?php
-
- // Load recordset
- function LoadRecordset($offset = -1, $rowcnt = -1) {
- global $conn, $osj2Dusers;
-
- // Call Recordset Selecting event
- $osj2Dusers->Recordset_Selecting($osj2Dusers->CurrentFilter);
-
- // Load list page sql
- $sSql = $osj2Dusers->SelectSQL();
- if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";
-
- // Load recordset
- $conn->raiseErrorFn = 'ew_ErrorFn';
- $rs = $conn->Execute($sSql);
- $conn->raiseErrorFn = '';
-
- // Call Recordset Selected event
- $osj2Dusers->Recordset_Selected($rs);
- return $rs;
- }
- ?>
- <?php
-
- // Load row based on key values
- function LoadRow() {
- global $conn, $Security, $osj2Dusers;
- $sFilter = $osj2Dusers->SqlKeyFilter();
- if (!is_numeric($osj2Dusers->user_id->CurrentValue)) {
- return FALSE; // Invalid key, exit
- }
- $sFilter = str_replace("@user_id@", ew_AdjustSql($osj2Dusers->user_id->CurrentValue), $sFilter); // Replace key value
- if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
- $sFilter = $osj2Dusers->AddUserIDFilter($sFilter, $Security->CurrentUserID()); // Add User ID filter
- }
-
- // Call Row Selecting event
- $osj2Dusers->Row_Selecting($sFilter);
-
- // Load sql based on filter
- $osj2Dusers->CurrentFilter = $sFilter;
- $sSql = $osj2Dusers->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
- $osj2Dusers->Row_Selected($rs);
- }
- $rs->Close();
- } else {
- $LoadRow = FALSE;
- }
- return $LoadRow;
- }
-
- // Load row values from recordset
- function LoadRowValues(&$rs) {
- global $osj2Dusers;
- $osj2Dusers->user_id->setDbValue($rs->fields('user_id'));
- $osj2Dusers->user_creation_date->setDbValue($rs->fields('user_creation_date'));
- $osj2Dusers->user_edit_date->setDbValue($rs->fields('user_edit_date'));
- $osj2Dusers->user_email->setDbValue($rs->fields('user_email'));
- $osj2Dusers->user_password->setDbValue($rs->fields('user_password'));
- $osj2Dusers->user_level->setDbValue($rs->fields('user_level'));
- $osj2Dusers->user_status->setDbValue($rs->fields('user_status'));
- }
- ?>
- <?php
-
- // Render row values based on field settings
- function RenderRow() {
- global $conn, $Security, $osj2Dusers;
-
- // Call Row Rendering event
- $osj2Dusers->Row_Rendering();
-
- // Common render codes for all row types
- // user_id
-
- $osj2Dusers->user_id->CellCssStyle = "";
- $osj2Dusers->user_id->CellCssClass = "";
-
- // user_creation_date
- $osj2Dusers->user_creation_date->CellCssStyle = "";
- $osj2Dusers->user_creation_date->CellCssClass = "";
-
- // user_edit_date
- $osj2Dusers->user_edit_date->CellCssStyle = "";
- $osj2Dusers->user_edit_date->CellCssClass = "";
-
- // user_email
- $osj2Dusers->user_email->CellCssStyle = "";
- $osj2Dusers->user_email->CellCssClass = "";
-
- // user_password
- $osj2Dusers->user_password->CellCssStyle = "";
- $osj2Dusers->user_password->CellCssClass = "";
-
- // user_level
- $osj2Dusers->user_level->CellCssStyle = "";
- $osj2Dusers->user_level->CellCssClass = "";
-
- // user_status
- $osj2Dusers->user_status->CellCssStyle = "";
- $osj2Dusers->user_status->CellCssClass = "";
- if ($osj2Dusers->RowType == EW_ROWTYPE_VIEW) { // View row
-
- // user_id
- $osj2Dusers->user_id->CssStyle = "";
- $osj2Dusers->user_id->CssClass = "";
- $osj2Dusers->user_id->ViewCustomAttributes = "";
-
- // user_creation_date
- $osj2Dusers->user_creation_date->ViewValue = ew_FormatDateTime($osj2Dusers->user_creation_date->ViewValue, 6);
- $osj2Dusers->user_creation_date->CssStyle = "";
- $osj2Dusers->user_creation_date->CssClass = "";
- $osj2Dusers->user_creation_date->ViewCustomAttributes = "";
-
- // user_edit_date
- $osj2Dusers->user_edit_date->ViewValue = ew_FormatDateTime($osj2Dusers->user_edit_date->ViewValue, 6);
- $osj2Dusers->user_edit_date->CssStyle = "";
- $osj2Dusers->user_edit_date->CssClass = "";
- $osj2Dusers->user_edit_date->ViewCustomAttributes = "";
-
- // user_email
- $osj2Dusers->user_email->ViewValue = $osj2Dusers->user_email->CurrentValue;
- $osj2Dusers->user_email->CssStyle = "";
- $osj2Dusers->user_email->CssClass = "";
- $osj2Dusers->user_email->ViewCustomAttributes = "";
-
- // user_password
- $osj2Dusers->user_password->ViewValue = "********";
- $osj2Dusers->user_password->CssStyle = "";
- $osj2Dusers->user_password->CssClass = "";
- $osj2Dusers->user_password->ViewCustomAttributes = "";
-
- // user_level
- if ($Security->CanAdmin()) { // System admin
- if (!is_null($osj2Dusers->user_level->CurrentValue)) {
- $sSqlWrk = "SELECT `user_level_name` FROM `osj-user_level` WHERE `user_level_id` = " . ew_AdjustSql($osj2Dusers->user_level->CurrentValue) . "";
- $sSqlWrk .= " AND (" . "`user_level_name` != 'Default' AND `user_level_name`!= 'Administrator'" . ")";
- $rswrk = $conn->Execute($sSqlWrk);
- if ($rswrk) {
- if (!$rswrk->EOF) {
- $osj2Dusers->user_level->ViewValue = $rswrk->fields('user_level_name');
- }
- $rswrk->Close();
- } else {
- $osj2Dusers->user_level->ViewValue = $osj2Dusers->user_level->CurrentValue;
- }
- } else {
- $osj2Dusers->user_level->ViewValue = NULL;
- }
- } else {
- $osj2Dusers->user_level->ViewValue = "********";
- }
- $osj2Dusers->user_level->CssStyle = "";
- $osj2Dusers->user_level->CssClass = "";
- $osj2Dusers->user_level->ViewCustomAttributes = "";
-
- // user_status
- if (!is_null($osj2Dusers->user_status->CurrentValue)) {
- switch ($osj2Dusers->user_status->CurrentValue) {
- case "0":
- $osj2Dusers->user_status->ViewValue = "Inactive";
- break;
- case "1":
- $osj2Dusers->user_status->ViewValue = "Active";
- break;
- default:
- $osj2Dusers->user_status->ViewValue = $osj2Dusers->user_status->CurrentValue;
- }
- } else {
- $osj2Dusers->user_status->ViewValue = NULL;
- }
- $osj2Dusers->user_status->CssStyle = "";
- $osj2Dusers->user_status->CssClass = "";
- $osj2Dusers->user_status->ViewCustomAttributes = "";
-
- // user_id
- $osj2Dusers->user_id->HrefValue = "";
-
- // user_creation_date
- $osj2Dusers->user_creation_date->HrefValue = "";
-
- // user_edit_date
- $osj2Dusers->user_edit_date->HrefValue = "";
-
- // user_email
- $osj2Dusers->user_email->HrefValue = "";
-
- // user_password
- $osj2Dusers->user_password->HrefValue = "";
-
- // user_level
- $osj2Dusers->user_level->HrefValue = "";
-
- // user_status
- $osj2Dusers->user_status->HrefValue = "";
- } elseif ($osj2Dusers->RowType == EW_ROWTYPE_ADD) { // Add row
- } elseif ($osj2Dusers->RowType == EW_ROWTYPE_EDIT) { // Edit row
- } elseif ($osj2Dusers->RowType == EW_ROWTYPE_SEARCH) { // Search row
- }
-
- // Call Row Rendered event
- $osj2Dusers->Row_Rendered();
- }
- ?>
- <?php
-
- // Write Audit Trail start/end for grid update
- function WriteAuditTrailDummy($typ) {
- $table = 'osj-users';
-
- // 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 (delete page)
- function WriteAuditTrailOnDelete(&$rs) {
- global $osj2Dusers;
- $table = 'osj-users';
-
- // Get key value
- $key = "";
- if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
- $key .= $rs['user_id'];
-
- // Write Audit Trail
- $filePfx = "log";
- $curDate = date("Y/m/d");
- $curTime = date("H:i:s");
- $id = ew_ScriptName();
- $user = CurrentUserID();
- $action = "D";
- $newvalue = "";
- foreach (array_keys($rs) as $fldname) {
- if ($osj2Dusers->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
- $oldvalue = ($osj2Dusers->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";
- }
- ?>