|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | +Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com |
| 5 | +All rights reserved. |
| 6 | +
|
| 7 | +Redistribution and use in source and binary forms, with or without modification, |
| 8 | +are permitted provided that the following conditions are met: |
| 9 | +
|
| 10 | + * Redistributions of source code must retain the above copyright notice, |
| 11 | + this list of conditions and the following disclaimer. |
| 12 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + this list of conditions and the following disclaimer in the documentation |
| 14 | + and/or other materials provided with the distribution. |
| 15 | + * Neither the name of ISPConfig nor the names of its contributors |
| 16 | + may be used to endorse or promote products derived from this software without |
| 17 | + specific prior written permission. |
| 18 | +
|
| 19 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 20 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 | +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 23 | +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 24 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 26 | +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 28 | +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | +*/ |
| 30 | + |
| 31 | +require_once '../../lib/config.inc.php'; |
| 32 | +require_once '../../lib/app.inc.php'; |
| 33 | + |
| 34 | +//* Check permissions for module |
| 35 | +$app->auth->check_module_permissions('monitor'); |
| 36 | + |
| 37 | +$app->load('finediff'); |
| 38 | + |
| 39 | +// Loading the template |
| 40 | +$app->uses('tpl'); |
| 41 | +$app->tpl->newTemplate("form.tpl.htm"); |
| 42 | +$app->tpl->setInclude('content_tpl', 'templates/dataloghistory_view.htm'); |
| 43 | + |
| 44 | +$app->load_language_file('web/monitor/lib/lang/'.$_SESSION['s']['language'].'_dataloghistory_view.lng'); |
| 45 | +require('lib/lang/'.$_SESSION['s']['language'].'_dataloghistory_view.lng'); |
| 46 | +$app->tpl->setvar($wb); |
| 47 | + |
| 48 | +$id = intval($_GET['id']); |
| 49 | + |
| 50 | +$record = $app->db->queryOneRecord('SELECT * FROM sys_datalog WHERE datalog_id = ?', $id); |
| 51 | + |
| 52 | +$out['id'] = $id; |
| 53 | + |
| 54 | +$out['timestamp'] = date($app->lng('conf_format_datetime'), $record['tstamp']); |
| 55 | +$out['table'] = $record['dbtable']; |
| 56 | + |
| 57 | +$out['action_char'] = $record['action']; |
| 58 | +$out['action_name'] = $app->lng($record['action']); |
| 59 | + |
| 60 | +$out['session_id'] = $record['session_id']; |
| 61 | + |
| 62 | +if(!$data = unserialize(stripslashes($record['data']))) { |
| 63 | + $data = unserialize($record['data']); |
| 64 | +} |
| 65 | + |
| 66 | +switch ($record['action']) { |
| 67 | + case 'i': |
| 68 | + $inserts = array(); |
| 69 | + foreach ($data['new'] as $key=>$value) { |
| 70 | + $inserts[] = array( |
| 71 | + 'key' => $key, |
| 72 | + 'value' => nl2br($value), |
| 73 | + ); |
| 74 | + } |
| 75 | + $app->tpl->setLoop('inserts', $inserts); |
| 76 | + break; |
| 77 | + case 'u': |
| 78 | + $updates = array(); |
| 79 | + foreach ($data['new'] as $key=>$value) { |
| 80 | + if ($value != $data['old'][$key]) { |
| 81 | + $old = $data['old'][$key]; |
| 82 | + $new = $value; |
| 83 | + $changes = show_diff_if_needed($old, $new); |
| 84 | + $updates[] = array( |
| 85 | + 'key' => $key, |
| 86 | + 'is_diff' => $changes['is_diff'], |
| 87 | + 'old' => nl2br($changes['old']), |
| 88 | + 'new' => nl2br($changes['new']), |
| 89 | + 'diff' => nl2br($changes['diff']), |
| 90 | + ); |
| 91 | + } |
| 92 | + } |
| 93 | + if (count($updates) > 0) { |
| 94 | + $app->tpl->setLoop('updates', $updates); |
| 95 | + } else { |
| 96 | + $out['no_changes'] = true; |
| 97 | + } |
| 98 | + break; |
| 99 | + case 'd': |
| 100 | + $deletes = array(); |
| 101 | + foreach ($data['old'] as $key=>$value) { |
| 102 | + $deletes[] = array( |
| 103 | + 'key' => $key, |
| 104 | + 'value' => nl2br($value), |
| 105 | + ); |
| 106 | + } |
| 107 | + $app->tpl->setLoop('deletes', $deletes); |
| 108 | + break; |
| 109 | +} |
| 110 | + |
| 111 | +$app->tpl->setVar($out); |
| 112 | + |
| 113 | +$app->tpl_defaults(); |
| 114 | +$app->tpl->pparse(); |
| 115 | + |
| 116 | +function show_diff_if_needed($old, $new) { |
| 117 | + global $app; |
| 118 | + |
| 119 | + $diff_min_lines = 6; |
| 120 | + |
| 121 | + if (substr_count($old, "\n") >= $diff_min_lines || substr_count($new, "\n") >= $diff_min_lines) { |
| 122 | + $opcodes = FineDiff::getDiffOpcodes($old, $new); |
| 123 | + $html = FineDiff::renderUTF8DiffToHTMLFromOpcodes($old, $opcodes); |
| 124 | + return array('is_diff'=>true, 'old'=>'', 'new'=>'', 'diff'=>$html); |
| 125 | + } else { |
| 126 | + return array('is_diff'=>false, 'old'=>$old, 'new'=>$new, 'diff'=>''); |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +?> |
0 commit comments