Skip to content
Snippets Groups Projects
Commit fcfeb806 authored by Marius Burkard's avatar Marius Burkard
Browse files

- added datalog undelete to viewer

parent 28bfeb97
No related branches found
No related tags found
No related merge requests found
...@@ -759,6 +759,9 @@ class db ...@@ -759,6 +759,9 @@ class db
$old_rec = array(); $old_rec = array();
$index_value = $this->insertID(); $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); $new_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
$this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec); $this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec);
......
...@@ -50,18 +50,36 @@ $dbidx = explode(':', $record['dbidx']); ...@@ -50,18 +50,36 @@ $dbidx = explode(':', $record['dbidx']);
$old_record = $app->db->queryOneRecord('SELECT * FROM ?? WHERE ??=?', $record['dbtable'], $dbidx[0], $dbidx[1]); $old_record = $app->db->queryOneRecord('SELECT * FROM ?? WHERE ??=?', $record['dbtable'], $dbidx[0], $dbidx[1]);
if (is_array($old_record)) { if($record['action'] === 'u') {
if(!$data = unserialize(stripslashes($record['data']))) { if (is_array($old_record)) {
$data = unserialize($record['data']); 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); $app->tpl->setVar('success', true);
} else { }
$app->tpl->setVar('success', false);
} }
$app->tpl_defaults(); $app->tpl_defaults();
......
...@@ -109,6 +109,7 @@ switch ($record['action']) { ...@@ -109,6 +109,7 @@ switch ($record['action']) {
} }
$app->tpl->setVar($out); $app->tpl->setVar($out);
$app->tpl->setVar('can_undo', ($out['action_char'] === 'u' || $out['action_char'] === 'd'));
$app->tpl_defaults(); $app->tpl_defaults();
$app->tpl->pparse(); $app->tpl->pparse();
......
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
$wb['list_head_txt'] = 'Datalog-History-Eintrag'; $wb['list_head_txt'] = 'Datalog-History-Eintrag';
$wb['success_txt'] = 'Erfolgreich zurückgesetzt'; $wb['success_txt'] = 'Erfolgreich zurückgesetzt';
$wb['error_txt'] = 'Fehler beim Zurücksetzen: Eintrag existiert nicht mehr'; $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'; $wb['btn_cancel_txt'] = 'Zurück';
?> ?>
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
$wb['list_head_txt'] = 'Data Log History Entry'; $wb['list_head_txt'] = 'Data Log History Entry';
$wb['success_txt'] = 'Undo successful'; $wb['success_txt'] = 'Undo successful';
$wb['error_txt'] = 'Error during undo: Record does not exist anymore'; $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'; $wb['btn_cancel_txt'] = 'Back';
?> ?>
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
<div class="clear"> <div class="clear">
<div class="right"> <div class="right">
<tmpl_if name='action_char' value='u'> <tmpl_if name='can_undo'>
<a class="btn btn-default formbutton-danger formbutton-narrow" href="javascript: ISPConfig.confirm_action('monitor/dataloghistory_undo.php?id={tmpl_var name='id'}','{tmpl_var name='undo_confirmation_txt'}');"> {tmpl_var name='undo_txt'}</a> <a class="btn btn-default formbutton-danger formbutton-narrow" href="javascript: ISPConfig.confirm_action('monitor/dataloghistory_undo.php?id={tmpl_var name='id'}','{tmpl_var name='undo_confirmation_txt'}');"> {tmpl_var name='undo_txt'}</a>
</tmpl_if> </tmpl_if>
<button class="btn btn-default formbutton-default" type="button" value="{tmpl_var name='btn_cancel_txt'}" data-load-content="monitor/dataloghistory_list.php">{tmpl_var name='btn_cancel_txt'}</button> <button class="btn btn-default formbutton-default" type="button" value="{tmpl_var name='btn_cancel_txt'}" data-load-content="monitor/dataloghistory_list.php">{tmpl_var name='btn_cancel_txt'}</button>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment