diff --git a/common.inc.php b/common.inc.php index 5e7c03f..40079fb 100644 --- a/common.inc.php +++ b/common.inc.php @@ -605,7 +605,7 @@ if(committee_auth_has_access("admin")) echo "
"; echo theme_icon($icon); echo " | ";
diff --git a/config/backuprestore.php b/config/backuprestore.php
new file mode 100644
index 0000000..d1af3e1
--- /dev/null
+++ b/config/backuprestore.php
@@ -0,0 +1,240 @@
+
+/*
+ This file is part of the 'Science Fair In A Box' project
+ SFIAB Website: http://www.sfiab.ca
+
+ Copyright (C) 2008 James Grant \n"; + echo " \n"; + do { + //hmm just some random filename + $tmpfilename=md5(rand().time().$_FILES['restore']['name']); + } while(file_exists("../data/backuprestore/$tmpfilename")); + + move_uploaded_file($_FILES['restore']['tmp_name'],"../data/backuprestore/$tmpfilename"); + + $fp=fopen("../data/backuprestore/$tmpfilename","r"); + + for($x=0;$x<4;$x++) { + $line=fgets($fp,1024); + $hdr[$x]=split(":",trim($line),2); + } + fclose($fp); + + if(trim($hdr[0][0])=="#SFIAB SQL BACKUP") { + + echo "
\n"; + if($err) { + echo error(i18n("Warning, there are discrepencies between the restore file and your current live system. Proceed at your own risk!")); + } + + echo "\n"; + echo " \n"; + echo ""; + echo i18n("If you are not going to proceed, please click here to clean up the temporary files which may contain confidential information!"); + echo "\n"; + } + else + { + echo error(i18n("This file is NOT a SFIAB SQL BACKUP file")); + echo i18n("Only backups created with the SFIAB Backup Creator can be used to restore from."); + echo " \n"; + } + + send_footer(); +} +else if($_POST['action']=="restoreproceed") { + echo send_header("Database Backup/Restore", + array('Committee Main' => 'committee_main.php', + 'SFIAB Configuration' => 'config/index.php') + ,"backup_restore" + ); + + //make sure the filename's good before we used it + if(ereg("^[a-z0-9]{32}$",$_POST['realfilename']) && file_exists("../data/backuprestore/".$_POST['realfilename'])) { + $filename=$_POST['realfilename']; + echo i18n("Proceeding with database restore from %1",array($_POST['filename']))."..."; + $lines=file("../data/backuprestore/$filename"); + $err=false; + echo " "; + foreach($lines AS $line) { + $line=trim($line); + if(ereg("^#TABLE: (.*)",$line,$args)) { + //empty out the table + $sql="TRUNCATE TABLE `".$args[1]."`"; + // echo $sql."\n"; + mysql_query($sql); + } + else if(ereg("^#",$line)) { + //just skip it + } + else + { + //insert the new data + mysql_query($line); + if(mysql_error()) { + echo $line."\n"; + echo mysql_error()."\n"; + $err=true; + } + } + } + echo ""; + if($err) { + echo error(i18n("An error occured while importing the restore database")); + } + else + echo happy(i18n("Database successfully restored")); + + unlink("../data/backuprestore/$filename"); + } + else + echo error(i18n("Invalid filename")); + + send_footer(); + +} +else +{ + echo send_header("Database Backup/Restore", + array('Committee Main' => 'committee_main.php', + 'SFIAB Configuration' => 'config/index.php') + ,"backup_restore" + ); + + + //we try to remove temp files every time we load this page, who knows, maybe they navigated away + //last time instead of clicking the link to come back here + $dh=opendir("../data/backuprestore"); + $removed=false; + while($fn=readdir($dh)) { + if(ereg("[a-z0-9]{32}",$fn)) { + unlink("../data/backuprestore/$fn"); + $removed=true; + } + } + closedir($dh); + + if($removed) { + echo happy(i18n("Temporary files successfully removed")); + } + + + echo " ".i18n("Backup Database")."\n"; + echo "".i18n("Create Database Backup File")."\n"; + echo " \n"; + echo " \n"; + + echo " ".i18n("Restore Database")."\n"; + echo i18n(error("WARNING: Importing a backup will completely DESTROY all data currently in the database and replace it with what is in the backup file")); + echo "\n"; + + + send_footer(); +} + +?> diff --git a/config/index.php b/config/index.php index 870d65c..e285fae 100644 --- a/config/index.php +++ b/config/index.php @@ -65,7 +65,7 @@ echo "
|