diff --git a/e107_admin/history.php b/e107_admin/history.php index 1c0e0e9c1..78d93ad98 100644 --- a/e107_admin/history.php +++ b/e107_admin/history.php @@ -75,7 +75,7 @@ class admin_history_ui extends e_admin_ui 'history_table' => array ( 'title' => 'Table', 'type' => 'text', 'data' => 'safestr', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left',), 'history_record_id' => array ( 'title' => LAN_ID, 'type' => 'number', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left',), 'history_action' => array ( 'title' => 'Action', 'type' => 'dropdown', 'data' => 'int', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left', 'batch' => false,), - 'history_data' => array ( 'title' => 'Data', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'history-data left', 'thclass' => 'left', 'filter' => false, 'batch' => false,), + 'history_data' => array ( 'title' => 'Changed Data', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'history-data left', 'thclass' => 'left', 'filter' => false, 'batch' => false,), 'history_user_id' => array ( 'title' => LAN_USER, 'type' => 'user', 'data' => 'int', 'width' => '5%', 'filter' => true, 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left',), 'history_restored' => array ( 'title' => "Restored", 'type' => 'datestamp', 'data' => 'int', 'width' => '5%', 'filter' => true, 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'center', 'thclass' => 'center',), @@ -94,7 +94,8 @@ class admin_history_ui extends e_admin_ui { $this->fields['history_action']['writeParms']['optArray'] = [ 'delete' => "". LAN_DELETE."", - 'update' => "". LAN_UPDATE."" + 'update' => "". LAN_UPDATE."", + 'restore' => "Restore" ]; @@ -134,16 +135,24 @@ class admin_history_ui extends e_admin_ui $pid = $historyRow['history_pid']; $recordId = $historyRow['history_record_id']; + + if (!empty($originalTable) && !empty($originalData) && !empty($pid) && !empty($recordId)) { - if($action === 'insert') { $originalData[$pid] = (int) $recordId; $result = $db->replace($originalTable, $originalData); } - else + else // update { + $backup = $db->retrieve($originalTable, '*', $pid. ' = '.(int) $recordId); + if($changes = array_diff_assoc($originalData, $backup)) + { + $old_changed_data = array_intersect_key($backup, $changes); + $this->backupToHistory($originalTable, $pid, $recordId, 'restore', $old_changed_data, false); + } + $originalData['WHERE'] = $pid .' = '. (int) $recordId; $result = $db->update($originalTable, $originalData); } @@ -153,6 +162,10 @@ class admin_history_ui extends e_admin_ui $message->addSuccess("The record (ID: $id) has been successfully restored to the $originalTable table.", 'default', true); $db->update('admin_history', "history_restored = ".time()." WHERE history_id = $id"); } + elseif($result === 0) + { + $message->addInfo("No changes made", 'default', true); + } else { $message->addError("Failed to restore the record (ID: $id) to the $originalTable table.", 'default', true); @@ -325,7 +338,7 @@ class admin_history_form_ui extends e_admin_form_ui $text .= ""; } - $att['readParms']['editClass'] = 999; // disable it. + $att['readParms']['editClass'] = 999; // disable it. $text .= $this->renderValue('options', $value, $att, $id); // End options group diff --git a/e107_core/sql/core_sql.php b/e107_core/sql/core_sql.php index efc188ddb..cd3fe5007 100755 --- a/e107_core/sql/core_sql.php +++ b/e107_core/sql/core_sql.php @@ -216,7 +216,7 @@ history_id int(10) unsigned NOT NULL auto_increment, history_table varchar(64) NOT NULL default '', history_pid varchar(64) NOT NULL default '', history_record_id int(10) unsigned NOT NULL default '0', -history_action enum('delete','update') NOT NULL, +history_action enum('delete','restore','update') NOT NULL, history_data JSON DEFAULT NULL, history_user_id int(10) unsigned NOT NULL default '0', history_datestamp int(10) unsigned NOT NULL default '0', diff --git a/e107_core/templates/admin_icons_template.php b/e107_core/templates/admin_icons_template.php index 7b0d69cce..14d228f9e 100644 --- a/e107_core/templates/admin_icons_template.php +++ b/e107_core/templates/admin_icons_template.php @@ -124,6 +124,9 @@ $ADMIN_ICONS_TEMPLATE['E_16_PLUGIN'] = ""; +$ADMIN_ICONS_TEMPLATE['E_32_UNDO'] = ""; + $ADMIN_ICONS_TEMPLATE['ADMIN_WARNING_ICON'] = ""; $ADMIN_ICONS_TEMPLATE['ADMIN_GRID_ICON'] = ""; $ADMIN_ICONS_TEMPLATE['ADMIN_LIST_ICON'] = ""; diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index 11a3b1c23..5162eb9e8 100755 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -4587,15 +4587,19 @@ class e_admin_controller_ui extends e_admin_controller * @param int $id The ID of the specific record being backed up. * @param string $action The action performed on the record (e.g., 'update' or 'delete'). * @param array $data An associative array of field data to be included in the history record. + * @param bool $posted Whether the data has been posted and requires additional filter based on current $fields values or not. * @return bool True on successful creation of the backup record, false on failure. */ - protected function backupToHistory($table, $pid, $id, $action, $data) + protected function backupToHistory($table, $pid, $id, $action, $data, $posted = true) { - foreach($data as $field=>$var) + if($posted) { - if(empty($this->fields[$field]['data'])) // exclude data not in the table. + foreach($data as $field=>$var) { - unset($data[$field]); + if(empty($this->fields[$field]['data'])) // exclude data not in the table. + { + unset($data[$field]); + } } } diff --git a/e107_handlers/sitelinks_class.php b/e107_handlers/sitelinks_class.php index be96dc35b..7f8acc164 100644 --- a/e107_handlers/sitelinks_class.php +++ b/e107_handlers/sitelinks_class.php @@ -960,6 +960,8 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; } // 7 => array(e_ADMIN.'download.php', ADLAN_24, ADLAN_25, 'R', 3, E_16_DOWNL, E_32_DOWNL), 8 => array(e_ADMIN_ABS.'emoticon.php', ADLAN_58, ADLAN_59, 'F', 1, E_16_EMOTE, E_32_EMOTE), // 9 => array(e_ADMIN.'filemanager.php', ADLAN_30, ADLAN_31, '6', 5, E_16_FILE, E_32_FILE), // replaced by media-manager + 9 => array(e_ADMIN.'history.php', LAN_HISTORY, LAN_HISTORY, '7', 4, E_16_UNDO, E_32_UNDO), + 10 => array(e_ADMIN_ABS.'frontpage.php', ADLAN_60, ADLAN_61, 'G', 1, E_16_FRONT, E_32_FRONT), 11 => array(e_ADMIN_ABS.'image.php', LAN_MEDIAMANAGER, LAN_MEDIAMANAGER, 'A', 5, E_16_IMAGES, E_32_IMAGES), 12 => array(e_ADMIN_ABS.'links.php', LAN_NAVIGATION, ADLAN_139, 'I', 1, E_16_LINKS, E_32_LINKS), diff --git a/e107_handlers/user_handler.php b/e107_handlers/user_handler.php index f56626738..b9e0e06bc 100644 --- a/e107_handlers/user_handler.php +++ b/e107_handlers/user_handler.php @@ -1964,11 +1964,13 @@ class e_userperms // Tools "Y" => array(ADLAN_147,E_16_INSPECT, E_32_INSPECT), // File inspector + "7" => array(defset('LAN_HISTORY', 'History'), E_16_UNDO, E_32_UNDO), // History/Undo "9" => array(ADLAN_40, E_16_MAINTAIN, E_32_MAINTAIN), // Take Down site for Maintenance "O" => array(ADLAN_149,E_16_NOTIFY, E_32_NOTIFY), // Notify "U" => array(ADLAN_157,E_16_CRON, E_32_CRON), // Schedule Tasks "S" => array(ADLAN_155,E_16_ADMINLOG, E_32_ADMINLOG), // System Logging + // Manage "B" => array(LAN_COMMENTMAN,E_16_COMMENT, E_32_COMMENT), // Moderate Comments "6" => array(LAN_MEDIAMANAGER,E_16_FILE, E_32_FILE), // File-Manager - Upload /manage files - diff --git a/e107_languages/English/admin/lan_admin.php b/e107_languages/English/admin/lan_admin.php index 17da2b82a..ca0f08acc 100644 --- a/e107_languages/English/admin/lan_admin.php +++ b/e107_languages/English/admin/lan_admin.php @@ -601,4 +601,6 @@ define("LAN_META_DESCRIPTION", "Meta Description"); define("LAN_SYSTEM_NOTIFICATIONS_X", "[x] System Notification(s)"); define("LAN_PHP_OUTDATED", "Your website is currently running an [outdated version of PHP], which may pose a security risk. If your plugins will allow it, we recommend upgrading to [x] to ensure that your website is secure and up-to-date."); -define("LAN_DATABASE_UPDATE", "An update is available for your database. We recommend [running this update] as soon as possible to ensure that your database is secure and up-to-date."); \ No newline at end of file +define("LAN_DATABASE_UPDATE", "An update is available for your database. We recommend [running this update] as soon as possible to ensure that your database is secure and up-to-date."); + +define("LAN_HISTORY", "History");