Example #1
0
        display_error(_('Select backup file first.'));
        return false;
    }
    $saveasname = basename($filename);
    header('Content-type: application/octet-stream');
    header('Content-Length: ' . filesize($filename));
    header('Content-Disposition: attachment; filename="' . $saveasname . '"');
    readfile($filename);
    return true;
}
$db_name = $_SESSION["wa_current_user"]->company;
$conn = $db_connections[$db_name];
$backup_name = clean_file_name(get_post('backups'));
$backup_path = BACKUP_PATH . $backup_name;
if (get_post('creat')) {
    generate_backup($conn, get_post('comp'), get_post('comments'));
    $Ajax->activate('backups');
}
if (get_post('restore')) {
    if ($backup_name) {
        if (db_import($backup_path, $conn)) {
            display_notification(_("Restore backup completed."));
        }
        refresh_sys_prefs();
        // re-read system setup
    } else {
        display_error(_("Select backup file first."));
    }
}
if (get_post('deldump')) {
    if ($backup_name) {
Example #2
0
function handle_form($conn)
{
    global $path_to_root;
    //Generate Only
    if (isset($_GET['c'])) {
        if ($_GET['c'] == 'g') {
            $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') {
            $filename = generate_backup($conn);
            header("Location: backups.php?c=ds&fn=" . urlencode($filename));
            return "";
        }
        //Download the file
        if ($_GET['c'] == 'd') {
            download_file(BACKUP_PATH . $_GET['fn']);
            exit;
        }
        //Delete the file
        if ($_GET['c'] == 'df') {
            $filename = $_GET['fn'];
            @unlink(BACKUP_PATH . $filename);
            header("Location: backups.php?c=dff&fn=" . urlencode($filename));
            return "";
        }
        if ($_GET['c'] == 'dff') {
            $msg = tr("File successfully deleted.") . "   ";
            $msg .= tr("Filename") . " = " . $_GET['fn'];
            return $msg;
        }
        //Write JS script to open download window
        if ($_GET['c'] == 'ds') {
            $filename = urlencode($_GET['fn']);
            $msg = tr("Backup is being downloaded...");
            $msg .= "<script language='javascript'>";
            $msg .= "function download_file() {location.href ='backups.php?c=d&fn={$filename}'}; window.onload=download_file";
            $msg .= "</script>";
            return $msg;
        }
        //Print backup success message
        if ($_GET['c'] == 'gs') {
            $msg = tr("Backup successfully generated.") . "&nbsp;&nbsp;&nbsp;";
            $msg .= tr("Filename") . " = " . $_GET['fn'];
            return $msg;
        }
        //Restore backup
        if ($_GET['c'] == 'r') {
            $filename = $_GET['fn'];
            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 = tr("Restore backup completed.") . "&nbsp;&nbsp;&nbsp;";
            return $msg;
        }
        if ($_GET['c'] == 'u') {
            $filename = $_FILES['uploadfile']['tmp_name'];
            if (is_uploaded_file($filename)) {
                restore_backup($filename, $conn);
                $msg = tr("Uploaded file has been restored.");
            } else {
                $msg = tr("Backup was not uploaded into the system.");
            }
            return $msg;
        }
    }
    return "";
}