diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php index 8443d106b1b9c8e3b75bbec659165f9f8c10b50f..c4764cb5558539bed8e990b4418798ef24833d77 100644 --- a/interface/lib/classes/db_mysql.inc.php +++ b/interface/lib/classes/db_mysql.inc.php @@ -759,6 +759,9 @@ class db $old_rec = array(); $index_value = $this->insertID(); + if(!$index_value && isset($insert_data[$index_field])) { + $index_value = $insert_data[$index_field]; + } $new_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value); $this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec); diff --git a/interface/web/monitor/dataloghistory_undo.php b/interface/web/monitor/dataloghistory_undo.php index 5ff08faa0aa2a49fef1518c2262dc21861aad5d5..455f8c9d0dd8dc83cae5a9fe48fb6e59a8ca188e 100644 --- a/interface/web/monitor/dataloghistory_undo.php +++ b/interface/web/monitor/dataloghistory_undo.php @@ -50,18 +50,36 @@ $dbidx = explode(':', $record['dbidx']); $old_record = $app->db->queryOneRecord('SELECT * FROM ?? WHERE ??=?', $record['dbtable'], $dbidx[0], $dbidx[1]); -if (is_array($old_record)) { - if(!$data = unserialize(stripslashes($record['data']))) { - $data = unserialize($record['data']); +if($record['action'] === 'u') { + if (is_array($old_record)) { + if(!$data = unserialize(stripslashes($record['data']))) { + $data = unserialize($record['data']); + } + + $new_record = $data['old']; + + $app->db->datalogUpdate($record['dbtable'], $new_record, $dbidx[0], $dbidx[1]); + + $app->tpl->setVar('success', true); + } else { + $app->tpl->setVar('success', false); } +} elseif($record['action'] === 'd') { + if(is_array($old_record)) { + $app->tpl->setVar('success', false); + $app->tpl->setVar('error_txt', $wb['error_undelete_txt']); + } else { + if(!$data = unserialize(stripslashes($record['data']))) { + $data = unserialize($record['data']); + } - $new_record = $data['old']; + $new_record = $data['old']; + /* TODO: maybe check some data, e. g. server_id -> server still there?, sys_groupid -> sys_group/sys_user still there? */ - $app->db->datalogUpdate($record['dbtable'], $new_record, $dbidx[0], $dbidx[1]); + $app->db->datalogInsert($record['dbtable'], $new_record, $dbidx[0]); - $app->tpl->setVar('success', true); -} else { - $app->tpl->setVar('success', false); + $app->tpl->setVar('success', true); + } } $app->tpl_defaults(); diff --git a/interface/web/monitor/dataloghistory_view.php b/interface/web/monitor/dataloghistory_view.php index e3b5e7b63c24b89bfc7bf75b6607c4d549f545cb..2b5ea1e0323c4dbe135baaacaef6f26a7ed1ef54 100644 --- a/interface/web/monitor/dataloghistory_view.php +++ b/interface/web/monitor/dataloghistory_view.php @@ -109,6 +109,7 @@ switch ($record['action']) { } $app->tpl->setVar($out); +$app->tpl->setVar('can_undo', ($out['action_char'] === 'u' || $out['action_char'] === 'd')); $app->tpl_defaults(); $app->tpl->pparse(); diff --git a/interface/web/monitor/lib/lang/de_dataloghistory_undo.lng b/interface/web/monitor/lib/lang/de_dataloghistory_undo.lng index 306f7c5eac0d7de9b3bd8b676a368af67a018fbc..9bae987d50ac7cc5356db635a5eb71660f01a85d 100644 --- a/interface/web/monitor/lib/lang/de_dataloghistory_undo.lng +++ b/interface/web/monitor/lib/lang/de_dataloghistory_undo.lng @@ -2,5 +2,6 @@ $wb['list_head_txt'] = 'Datalog-History-Eintrag'; $wb['success_txt'] = 'Erfolgreich zurückgesetzt'; $wb['error_txt'] = 'Fehler beim Zurücksetzen: Eintrag existiert nicht mehr'; +$wb['error_undelete_txt'] = 'Fehler beim Wiederherstellen: Eintrag mit dieser Id existiert bereits'; $wb['btn_cancel_txt'] = 'Zurück'; ?> diff --git a/interface/web/monitor/lib/lang/en_dataloghistory_undo.lng b/interface/web/monitor/lib/lang/en_dataloghistory_undo.lng index 258d8866966c781d0302373230bd7e5b2f0391b9..0e040a3e77d48b89a779f7c7d3fb4198df0fe02e 100644 --- a/interface/web/monitor/lib/lang/en_dataloghistory_undo.lng +++ b/interface/web/monitor/lib/lang/en_dataloghistory_undo.lng @@ -2,5 +2,6 @@ $wb['list_head_txt'] = 'Data Log History Entry'; $wb['success_txt'] = 'Undo successful'; $wb['error_txt'] = 'Error during undo: Record does not exist anymore'; +$wb['error_undelete_txt'] = 'Error during undelete: Record with primary id already existing.'; $wb['btn_cancel_txt'] = 'Back'; ?> diff --git a/interface/web/monitor/templates/dataloghistory_view.htm b/interface/web/monitor/templates/dataloghistory_view.htm index 0ce595e2652c90709d649bc0881210ca3856d5e0..4ba82bbf052a8aa7375d780a7b1c440c7cd2a8e0 100644 --- a/interface/web/monitor/templates/dataloghistory_view.htm +++ b/interface/web/monitor/templates/dataloghistory_view.htm @@ -116,7 +116,7 @@
- + {tmpl_var name='undo_txt'}