<?php
/* This file is part of the FiForms Framework
Copyright (C) 2003-2008 by Daniel McFeeters,
Licensed under the GNU GPL.
See LICENSE.txt for details.
*/
require_once('authenticate.php');
$basedir = $FIFORMS_CONFIG['APP_BASE'];
if($_POST['export'] == 'Download Database')
{
$database = $FIFORMS_CONFIG['AVAILABLE_APP_INFO'][$FIFORMS_CONFIG['APP_NAME']]['appdatabase'];
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "a")
);
$mdump = proc_open($FIFORMS_CONFIG['MYSQLDUMP']." --databases $database -u ".$auth->username." -p",$descriptorspec, $pipes);
if (is_resource($mdump)) {
fwrite($pipes[0], $auth->passwd);
fclose($pipes[0]);
while (!feof($pipes[1])) {
$dump .= fgets($pipes[1], 1024);
}
fclose($pipes[1]);
while (!feof($pipes[2])) {
$error .= fgets($pipes[2], 1024);
if(!$error)
{
break;
}
}
fclose($pipes[2]);
if(proc_close($mdump))
{
echo "<b>There was an error dumping the database:</b><br/><br/>";
echo $error;
}
else
{
header('Content-type: application/binary-octet-stream');
header('Content-disposition: inline; filename='.$database.'.sql');
echo $dump;
}
}
}
?>