Location: PHPKode > scripts > BackItUp > backitup/index.php
<?php

/****************************************************************
*	BackItUp by Eirik Opsanger (hide@address.com)				*
*	Please contact me if you find any bugs or need help!		*
****************************************************************/		

//DO NOT change anyting in this file!

session_start();
include("var.php");
$link = mysql_connect("$host", "$user", "$pass");
$db_selected = mysql_select_db($db, $link);
print("<div align=\"center\"><h1> BackItUp</h1>");


if($_POST['passo'] == $passord) {
	$_SESSION['innlogget'] = $passord;
}
if($_SESSION['innlogget'] == $passord) {
?>

<style type="text/css">
.class1 {
	border: 2px solid #CCCCCC;
	border-right: 2px solid #999999;
	border-bottom: 2px solid #999999;
	background-color: #DDDDDD;
	color: #333333;
}
table {
	margin-left: auto;
	margin-right: auto;
}
</style>

<strong>Make backup</strong><br>
<table align="center" width="400">
	<form method="get" action="<?php print($PHP_SELF); ?>">
	<tr><td><input type="radio" name="bu" value="alt" CHECKED> Structure and data (Recommended)</td></tr>
	<tr><td><input type="radio" name="bu" value="data"> Data</td></tr>
	<tr><td><input type="radio" name="bu" value="struk"> Structure</td></tr>
	<tr><td><input type="submit" value="OK"></td></tr>
	<input type="hidden" name="action" value="backup">
	</form>
</table>
<br><br>
	</div>


<?php
if($_GET['action'] == "delete") {
	unlink('./files/'.$_GET['file']);
	print("<div align=\"center\"><strong>The file was deleted!</strong></div><br>");
}
if($_GET['action'] == "backup") {
	if($bu == "alt") {
		include("backup_all.php");
	}
	if($bu == "data") {
		include("data_backup.php");
	}
	if($bu == "struk") {
		include("struktur_backup.php");
	}
}
if($_GET['action'] == "gjennopprett" && $_GET['bekreft'] == "ja") {
	$file = file('./files/'.$_GET['file']);
	$data = "";
	foreach($file as $line) {
		$data .= $line;
	}
	$data_line = explode("**", $data);
	$l = 0;
	foreach ($data_line as $query) {
		mysql_query($query);
		$l++;
				
	} 
	print("<div align=\"center\">Databasen was restored!<br>$l queries used.</div><br>");
	
} elseif($_GET['action'] == "gjennopprett") {
	$date = explode("_", $_GET['file']);
	$date = date("d.m.Y H:i:s", $date[0]);
	print("<div align=\"center\">Are you sure you whant to overwrite current database with the selected file, dated $date?<br>");
	print("[<a href=\"$PHP_SELF?action=gjennopprett&file=$_GET[file]&bekreft=ja\">Yes</a>] [<a href=\"biu.php\">NO</a>]</div><br>");
}
	
$mappe = "./files";
if(!($dp  = opendir($mappe))) die ("Can not open $mappe.");
while($file = readdir($dp)) {
	if($file !=="." && $file !==".."){
		$filenames[] = $file;
	}
}
closedir($dp);
if(isset($filenames[0])) {

	print("<div align=\"center\"><strong>Backups saved in ./files:</a></strong></div>");
	print("<table align=\"center\" width=\"600\">
	<tr>
		<td class=\"class1\"><strong>Date:</strong></td>
		<td class=\"class1\"><strong>Contents:</strong></td>
		<td class=\"class1\"><strong>Delete:</strong></td>
		<td class=\"class1\"><strong>Download:</strong></td>
		<td class=\"class1\"><strong>Restore:</strong></td>
	</tr>");

	arsort($filenames);	
	$i = 0;
	foreach ($filenames as $files) {
		$data = explode("_-_", $files);
		$date = date("m.d.Y h:i:s a", $data[0]);
		print("<tr>");
			print("<td class=\"class1\">$date</td>");
			if($data[2] == "struk" && $data[3] == "data.inc") {
				print("<td class=\"class1\">Structure and data</td>");
				$i++;
				if($i > 1){
					print("<td align=\"center\" class=\"class1\"><a href=\"$PHP_SELF?action=delete&file=$files\"><img src=\"delete.jpg\" alt=\"delete\" border=\"0\"></a></td>");
				} else {
					print("<td class=\"class1\">&nbsp;</td>");
				}
			} elseif($data[2] == "struk.inc") {
				print("<td class=\"class1\">Structure only</td>");
				$j++;
				if($j > 1){
					print("<td align=\"center\" class=\"class1\"><a href=\"$PHP_SELF?action=delete&file=$files\"><img src=\"delete.jpg\" alt=\"delete\" border=\"0\"></a></td>");
				} else {
					print("<td class=\"class1\">&nbsp;</td>");
				}
			} elseif($data[2] == "data.inc") {
				print("<td class=\"class1\">Data only</td>");
				$k++;
				if($k > 1){
					print("<td align=\"center\" class=\"class1\"><a href=\"$PHP_SELF?action=delete&file=$files\"><img src=\"delete.jpg\" alt=\"delete\" border=\"0\"></a></td>");
				} else {
					print("<td class=\"class1\">&nbsp;</td>");
				}
			}
		
		print("<td class=\"class1\" align=\"center\"><a href=\"files/$files\"><img src=\"disk.jpg\" alt=\"Download\" border=\"0\"></a></td>");	
		print("<td class=\"class1\" align=\"center\"><a href=\"$PHP_SELF?action=gjennopprett&file=$files\"><img src=\"insert.jpg\" alt=\"Resotre with this file\" border=\"0\"></a></td>");
		print("</tr>");
		
	}
} else {
	print("<font color=\"red\" align=\"center\"><center>No backups made!</center></font><br>");
}

?>
</table>

<?php

} else {
	print("<form action=" . $PHP_SELF . " method=\"post\"><br>");
	print("<input name=\"passo\" type=\"password\" size=\"20\"><br>");
	print("<input name=\"submit\" type=\"submit\" value=\"Log in\">");
	print("</form>");
}
?>


<div align="center"><small>[Ver. 1.0] [By: <a href="mailto: hide@address.com">Eirik Opsanger</a>] [<a href="http://www.opsanger.com" target="_blank" alt="opsanger.com">www.opsanger.com</a>] [<a href="readme.txt">Readme</a>]</small></div>
Return current item: BackItUp