X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fbackups.php;h=f13531931b06bdf62a1b4817208f6324a458276c;hb=67d97bfd7398b932698e254d937f905943412561;hp=dd73be6d899ef0d73ba8974255dfdb95e1bd5eb6;hpb=da8311619dd73feae101d246a1957b972e00cbd2;p=fa-stable.git diff --git a/admin/backups.php b/admin/backups.php index dd73be6d..f1353193 100644 --- a/admin/backups.php +++ b/admin/backups.php @@ -1,5 +1,14 @@ . +***********************************************************************/ $page_security = 15; $path_to_root=".."; @@ -9,7 +18,7 @@ include_once($path_to_root . "/admin/db/maintenance_db.inc"); $valid_paths = valid_paths(); //$valid_paths = ''; -if ($valid_paths != "") +if ($valid_paths != "") { page(_("Backup and Restore Database - Error")); display_error (_("Backup paths have not been set correctly.") ."   " . _("Please contact System Administrator.") . "
" .$valid_paths); @@ -18,9 +27,9 @@ if ($valid_paths != "") } $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")); +page(_("Backup and Restore Database"), false, false, '', '', true); //------------------------------------------------------------------------------- start_form(true, true); @@ -31,11 +40,13 @@ $compr = get_compr_combo(); echo "
- - + - + - + - +
$msg 
" . _("Backup scripts") . "" . _("Backup scripts") . "
$cmb$cmb - - - - - - - + + + + + + +
" . _("Compression") . "  $compr
 
 
 
 
" . _("Compression") . "  $compr
 
 
 
 
" . _("Comments") . " (" . _("Create Backup") . ")" . _("Comments") . " (" . _("Create Backup") . ")
"; @@ -106,118 +118,102 @@ end_form(); end_page(); -function handle_form($conn) +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') - { - download_file($path_to_root . BACKUP_PATH . $_GET['fn']); + 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($path_to_root . BACKUP_PATH . $filename); + @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 .= ""; - return $msg; - } - //Print backup success message - if ($_GET['c']=='gs') - { - $msg = _("Backup successfully generated.")."   "; + display_notification(_("Backup is being downloaded...")); + + add_js_source(""); + 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']; - restore_backup($path_to_root . 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; - } + if( restore_backup(BACKUP_PATH . $filename, $conn) ) + header("Location: backups.php?c=rs&fn=" . urlencode($filename)); + 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 (is_uploaded_file ($filename)) { - restore_backup($filename, $conn); - $msg = _("Uploaded file has been restored."); - } - else + if( restore_backup($filename, $conn) ) + display_notification(_("Uploaded file has been restored.")); + else + 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='') +function generate_backup($conn, $ext='no', $comm='') { if ($conn['tbpref'] != "") $filename = $conn['dbname'] . "_" . $conn['tbpref'] . date("Ymd_Hi") . ".sql"; - else + else $filename = $conn['dbname'] . "_" . date("Ymd_Hi") . ".sql"; - - $filename = db_export($conn, $filename, $ext, $comm); - + + $filename = db_export($conn, $filename, $ext, $comm); + return $filename; } -function restore_backup($filename, $conn) +function restore_backup($filename, $conn) { return db_import($filename, $conn); -} +} -function get_backup_file_combo() +function get_backup_file_combo() { global $path_to_root; $ar_files = array(); - - $dh = opendir($path_to_root . BACKUP_PATH); + default_focus('cmb_backups'); + $dh = opendir(BACKUP_PATH); while (($file = readdir($dh)) !== false) $ar_files[] = $file; closedir($dh); @@ -225,33 +221,33 @@ function get_backup_file_combo() rsort($ar_files); $opt_files = ""; foreach ($ar_files as $file) - if (strpos($file, ".sql") || strpos($file, ".sql")) + if (strpos($file, ".sql") || strpos($file, ".sql")) $opt_files .= ""; - return ""; + return ""; } -function get_compr_combo() +function get_compr_combo() { $ar_comps = array(); - + $ar_comps[] = _("No"); - if (function_exists("gzcompress")) + if (function_exists("gzcompress")) $ar_comps[] = "zip"; - if (function_exists("gzopen")) + if (function_exists("gzopen")) $ar_comps[] = "gzip"; $opt_comps = ""; foreach ($ar_comps as $file) $opt_comps .= ""; return ""; -} - -function download_file($filename) +} + +function download_file($filename) { - if (empty($filename) || !file_exists($filename)) + if (empty($filename) || !file_exists($filename)) { - return FALSE; + return false; } $saveasname = basename($filename); header('Content-type: application/octet-stream'); @@ -261,13 +257,13 @@ function download_file($filename) return true; } -function valid_paths() +function valid_paths() { global $path_to_root; - + $st = ""; - if (!file_exists($path_to_root . BACKUP_PATH)) - $st .= "   - " . _("cannot find backup directory") . " - " . $path_to_root . BACKUP_PATH . "
"; + if (!file_exists(BACKUP_PATH)) + $st .= "   - " . _("cannot find backup directory") . " - " . BACKUP_PATH . "
"; return $st; }