}
$db_name = $_SESSION["wa_current_user"]->company;
-$msg = handle_form($db_connections[$db_name]);
+handle_form($db_connections[$db_name]);
page(_("Backup and Restore Database"), false, false, '', '', true);
</script>
<center>
<table cellpadding=2 cellspacing=2 border=0>
- <tr><td colspan=2 style='color:darkred'><b>$msg</b> </td></tr>
<tr>
<td style='padding-right:30px'>" . _("Backup scripts") . "</td>
</tr>
function handle_form($conn)
{
- global $path_to_root;
- //Generate Only
- if (isset($_GET['c']))
+if(isset($_GET['c']))
+ switch($_GET['c'])
{
- if ($_GET['c']=='g')
- {
+ case 'g': //Generate Only
$filename = generate_backup($conn, $_GET['comp'], $_GET['comm']);
header("Location: backups.php?c=gs&fn=" . urlencode($filename));
- return "";
- }
- //Generate and download
- if ($_GET['c']=='gd')
- {
+ break;
+
+ case 'gd': //Generate and download
$filename = generate_backup($conn);
header("Location: backups.php?c=ds&fn=" . urlencode($filename));
- return "";
- }
- //Download the file
- if ($_GET['c']=='d')
- {
+ break;
+
+ case 'd': //Download the file
download_file(BACKUP_PATH . $_GET['fn']);
exit;
- }
- //Delete the file
- if ($_GET['c']=='df')
- {
+
+ case 'df': //Delete the file
$filename = $_GET['fn'];
@unlink(BACKUP_PATH . $filename);
header("Location: backups.php?c=dff&fn=" . urlencode($filename));
- return "";
- }
- if ($_GET['c']=='dff')
- {
- $msg = _("File successfully deleted.")." ";
+ break;
+
+ case 'dff':
+ $msg = _("File successfully deleted.")." ";
$msg .= _("Filename") . " = " . $_GET['fn'];
- return $msg;
- }
- //Write JS script to open download window
- if ($_GET['c']=='ds')
- {
+ display_notification($msg);
+ break;
+
+ case 'ds': //Write JS script to open download window
$filename = urlencode($_GET['fn']);
- $msg = _("Backup is being downloaded...");
- $msg .= "<script language='javascript'>";
- $msg .= "function download_file() {location.href ='backups.php?c=d&fn=$filename'};
- Behaviour.addLoadEvent(download_file);";
- $msg .= "</script>";
- return $msg;
- }
- //Print backup success message
- if ($_GET['c']=='gs')
- {
- $msg = _("Backup successfully generated.")." ";
+ display_notification(_("Backup is being downloaded..."));
+
+ add_js_source("<script language='javascript'>
+ function download_file() {location.href ='backups.php?c=d&fn=$filename'};
+ Behaviour.addLoadEvent(download_file);
+ </script>");
+ break;
+
+ case 'gs': //Print backup success message
+ $msg = _("Backup successfully generated."). ' ';
$msg .= _("Filename") . " = " . $_GET['fn'];
- return $msg;
- }
- //Restore backup
- if ($_GET['c']=='r')
- {
+ display_notification($msg);
+ break;
+
+ case 'r': //Restore backup
$filename=$_GET['fn'];
if( restore_backup(BACKUP_PATH . $filename, $conn) )
header("Location: backups.php?c=rs&fn=" . urlencode($filename));
- return "";
- }
- //Print restore success message
- if ($_GET['c']=='rs')
- {
- $msg = _("Restore backup completed.")." ";
- return $msg;
- }
+ break;
- if ($_GET['c']=='u')
- {
+ case 'rs': //Print restore success message
+ display_notification(_("Restore backup completed."));
+ break;
+
+ case 'u':
$filename = $_FILES['uploadfile']['tmp_name'];
if (is_uploaded_file ($filename))
{
if( restore_backup($filename, $conn) )
- $msg = _("Uploaded file has been restored.");
+ display_notification(_("Uploaded file has been restored."));
else
- $msg = _("Database restore failed.");
+ display_error(_("Database restore failed."));
}
else
{
- $msg = _("Backup was not uploaded into the system.");
+ display_error(_("Backup was not uploaded into the system."));
}
- return $msg;
}
- }
- return "";
}
function generate_backup($conn, $ext='no', $comm='')
{
if (empty($filename) || !file_exists($filename))
{
- return FALSE;
+ return false;
}
$saveasname = basename($filename);
header('Content-type: application/octet-stream');