<?php
/*
* ARBS - Advanced Resource Booking System
* Copyright (C) 2005-2007 ITMC der TU Dortmund
* Based on MRBS by Daniel Gardner <http://mrbs.sourceforge.net/>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
include_once("glob_inc.inc.php");
if(!getAuthorised(getUserName(), getUserPassword(), 1)){
showAccessDenied($day, $month, $year, $area);
exit;
}
?>
<html><head><title><?php echo(_("History and database-recovery")); ?></title>
<style rel=stylesheet type=text/css>
body{
font-size:10pt;
font-family:verdana,arial;
}
#box{
clear:both;
width:700px;
background-color:#ffcc33;
margin:10px;
padding:3px;
}
#title{
background-color:#ffffff;
width:80px;
margin:5px;
font-weight:bold;
font-size:12px;
text-align:center;
float:left;
}
#detail{
background-color:#ffffff;
width:180px;
margin:5px;
float:right;
}
#topper{
clear:both;
}
#con{
background-color:#ff3333;
clear:both;
}
#value{
clear:both;
background-color:#ccffcc;
}
#query{
background-color:#ccccff;
clear:both;
}
input{
background-color:#000000;
color:#ffffff;
}
</style>
</head>
<body>
<form method=POST action=mod_history.php>
<input type=hidden name=execute value=1>
<?php
$sel=$_POST["sel"];
$execute=$_POST["execute"]==1;
$file = $instance."/history.xml";
$depth = 0;
$id=0;
$start=0;
$executeNext=false;
$querys="";
function xmlstartElement($parser, $name, $attrs) {
global $depth,$start,$id,$execute,$sel,$executeNext;
$depth++;
if($depth==1){
$start=$attrs["START"];
}
if($depth==2){
$id++;
echo "<div id=box><div id=topper><div id=title><input type=checkbox value=$id checked name=sel[]> $name</div><div id=detail>".date("d.m.Y h:i",$attrs["CREATED"])."</div><div id=detail>".$attrs["SCRIPT"]."</div><div id=detail>", _("Table"), ":".$attrs["TABLE"]."</div><div id=detail>",_("Marked rows:"), " ", $attrs["ROWS"];
echo "</div></div>";
}
elseif($depth==3){
if($name=="VALUE"){
echo "<div id=value><b>".$attrs["FIELD"].":</b> ";
}
elseif($name=="WHERE"){
echo "<div id=con><b>", _("Conditional:"), "</b> ";
}
elseif($name=="QUERY"){
echo "<div id=query><b>", _("Query:"), "</b> ";
if($execute&&in_array($id,$sel)){
$executeNext=true;
echo _("(was executed)"), " ";
}
}
}
}
function xmlendElement($parser, $name){
global $depth;
$depth--;
if($depth>=1)
echo "</div>";
}
function xmlvalue($parser,$chars){
global $executeNext,$querys;
echo "<b>".xmldecode($chars)."</b><br>";
if($executeNext){
$querys.=xmldecode($chars).";\n";
$executeNext=false;
}
}
$xml_parser = xml_parser_create("UTF-8");
xml_set_element_handler($xml_parser, "xmlstartElement", "xmlendElement");
xml_set_character_data_handler($xml_parser,"xmlvalue");
if (!(@$fp = fopen($file, "r"))) {
die(sprintf(_("For security reasons, the file has to get reading permissions first (chmod 666 %s).<br><b>Afterwards, don't forget chmod 222!</b>"), "$instance/history.xml"));
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, false)) {
die(sprintf(_("XML Error: %s in line %d"), xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
}
#add closing history tag, this isnt in the file
if (!xml_parse($xml_parser, "</history>", true)) {
die(sprintf(_("XML Error: %s in line %d"), xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
if($execute){
createNewHistory();
echo _("The selected commands can be executed with thid commands:"), "<hr/><textarea rows=30 cols=80>",$querys,"</textarea>";
exit;
}
?>
<hr noshade><b><?php echo(_("CAUTION: AT FIRST RECOVER THE LAST BACKUP")); ?> (<?php echo(date("d.m.Y h:i",$start)); ?>)</b><br>
<input type=submit value="<?php echo(_("Add the following entries into the database")); ?>">
</form>
</body></html>