<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$dbname='khadidb';
$dumpfname = $dbname . "_" . date("Y-m-d_H-i-s").".sql";
$command = "C:\\wamp\\mysql\\bin\\mysqldump --add-drop-table --host=$hostname
    --user=$username ";
if ($password)
        $command.= "--password=". $password ." ";
$command.= $dbname;
$command.= " > " . $dumpfname;
system($command);

// zip the dump file
$zipfname = $dbname . "_" . date("Y-m-d_H-i-s").".zip";
$zip = new ZipArchive();
if($zip->open($zipfname,ZIPARCHIVE::CREATE))
{
   $zip->addFile($dumpfname,$dumpfname);
   $zip->close();
}

// read zip file and send it to standard output
if (file_exists($zipfname)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($zipfname));
    flush();
    readfile($zipfname);
    exit;
}
?>
<script>
resizeTo(500,550);
</script>
<link rel="stylesheet" href="css/form.css" type="text/css" />
<script>
function validate()
{
	var p1=document.f1.brpass1.value
	var p2=document.f1.brpass2.value
	submit="true";
 	if(document.f1.brname.value.length<3)
  	{submit="false"; alert('Invalid branch name');}
	if(document.f1.brpass1.value.length<=0)
  	{submit="false"; alert('Invalid Password');}

 if(document.f1.brpass2.value.length<=0)
  {submit="false"; alert('Invalid Password2');}
 if(p1!=p2)
  {submit="false"; alert('Passwords does not match');}

 if(submit=="false")
  return false;
}
</script>

<body bgcolor=fcfff1>
<font color=green>
<h3>Backup Database</h3></font>
<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return validate()">
<input type=hidden name=code value=''>
<table border=1  cellspacing=2 cellpadding=5 class=form>
<tr><td>Select Destination</td><td><input type=text name='brname' size=40 value=''></td></tr>


<tr><td colspan=2 align=center><input type=submit name='submit' value='S A V E'> <input type=button value='C A N C E L' onClick='window.location=""'></td></tr>
</table>
</form>


