" .$valid_paths); end_page(); exit; } $db_name = $_SESSION["wa_current_user"]->company; handle_form($db_connections[$db_name]); page(_("Backup and Restore Database"), false, false, '', '', true); //------------------------------------------------------------------------------- start_form(true, true); $cmb = get_backup_file_combo(); $compr = get_compr_combo(); echo "
" . _("Backup scripts") . "
$cmb
" . _("Compression") . "  $compr
 
 
 
 
" . _("Comments") . " (" . _("Create Backup") . ")
"; end_form(); //------------------------------------------------------------------------------------------------- end_page(); function handle_form($conn) { if(isset($_GET['c'])) switch($_GET['c']) { case 'g': //Generate Only $filename = generate_backup($conn, $_GET['comp'], $_GET['comm']); header("Location: backups.php?c=gs&fn=" . urlencode($filename)); break; case 'gd': //Generate and download $filename = generate_backup($conn); header("Location: backups.php?c=ds&fn=" . urlencode($filename)); break; case 'd': //Download the file download_file(BACKUP_PATH . $_GET['fn']); exit; case 'df': //Delete the file $filename = $_GET['fn']; @unlink(BACKUP_PATH . $filename); header("Location: backups.php?c=dff&fn=" . urlencode($filename)); break; case 'dff': $msg = _("File successfully deleted.")." "; $msg .= _("Filename") . " = " . $_GET['fn']; display_notification($msg); break; case 'ds': //Write JS script to open download window $filename = urlencode($_GET['fn']); display_notification(_("Backup is being downloaded...")); add_js_source(""); break; case 'gs': //Print backup success message $msg = _("Backup successfully generated."). ' '; $msg .= _("Filename") . " = " . $_GET['fn']; 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)); break; 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) ) display_notification(_("Uploaded file has been restored.")); else display_error(_("Database restore failed.")); } else { display_error(_("Backup was not uploaded into the system.")); } } } function generate_backup($conn, $ext='no', $comm='') { if ($conn['tbpref'] != "") $filename = $conn['dbname'] . "_" . $conn['tbpref'] . date("Ymd_Hi") . ".sql"; else $filename = $conn['dbname'] . "_" . date("Ymd_Hi") . ".sql"; $filename = db_export($conn, $filename, $ext, $comm); return $filename; } function restore_backup($filename, $conn) { return db_import($filename, $conn); } function get_backup_file_combo() { global $path_to_root; $ar_files = array(); default_focus('cmb_backups'); $dh = opendir(BACKUP_PATH); while (($file = readdir($dh)) !== false) $ar_files[] = $file; closedir($dh); rsort($ar_files); $opt_files = ""; foreach ($ar_files as $file) if (strpos($file, ".sql") || strpos($file, ".sql")) $opt_files .= ""; return ""; } function get_compr_combo() { $ar_comps = array(); $ar_comps[] = _("No"); if (function_exists("gzcompress")) $ar_comps[] = "zip"; if (function_exists("gzopen")) $ar_comps[] = "gzip"; $opt_comps = ""; foreach ($ar_comps as $file) $opt_comps .= ""; return ""; } function download_file($filename) { if (empty($filename) || !file_exists($filename)) { 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; } function valid_paths() { global $path_to_root; $st = ""; if (!file_exists(BACKUP_PATH)) $st .= "   - " . _("cannot find backup directory") . " - " . BACKUP_PATH . "
"; return $st; } ?>