X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fbackups.php;h=4011a2a5423eafddedb376cd8eab233d14ecd99e;hb=a0a0a0e1318042034fe5652caa69b034200c8a90;hp=cf2ef1cf3e4a4a1b5a48a86372d165a2ff9711fa;hpb=bc426821d8ae6319bd9394ac275bb700e6394fc3;p=fa-stable.git
diff --git a/admin/backups.php b/admin/backups.php
index cf2ef1cf..4011a2a5 100644
--- a/admin/backups.php
+++ b/admin/backups.php
@@ -1,222 +1,76 @@
.
+***********************************************************************/
+$page_security = 'SA_BACKUP';
$path_to_root="..";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/admin/db/maintenance_db.inc");
-$valid_paths = valid_paths();
-//$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);
- end_page();
- exit;
-}
-
-$db_name = $_SESSION["wa_current_user"]->company;
-$msg = handle_form($db_connections[$db_name]);
-
-page(_("Backup and Restore Database"));
-
-//-------------------------------------------------------------------------------
-start_form(true, true);
-
-$cmb = get_backup_file_combo();
-$compr = get_compr_combo();
-
-echo "
-
-
-
- $msg
-
- " . _("Backup scripts") . "
-
-
- $cmb
-
-
-
-
-
-
- " . _("Comments") . " (" . _("Create Backup") . ")
-
-
-
-
-
";
-
-end_form();
-
-//-------------------------------------------------------------------------------------------------
+};
+if (get_post('download')) {
+ download_file(BACKUP_PATH . get_post('backups'));
+ exit;
+}
-end_page();
+page(_($help_context = "Backup and Restore Database"), false, false, '', '');
+check_paths();
-function handle_form($conn)
+function check_paths()
{
- 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 = _("File successfully deleted.")." ";
- $msg .= _("Filename") . " = " . $_GET['fn'];
- return $msg;
- }
- //Write JS script to open download window
- if ($_GET['c']=='ds')
- {
- $filename = urlencode($_GET['fn']);
- $msg = _("Backup is being downloaded...");
- $msg .= "";
- return $msg;
- }
- //Print backup success message
- if ($_GET['c']=='gs')
- {
- $msg = _("Backup successfully generated.")." ";
- $msg .= _("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 = _("Restore backup completed.")." ";
- return $msg;
- }
-
- if ($_GET['c']=='u')
- {
- $filename = $_FILES['uploadfile']['tmp_name'];
- if (is_uploaded_file ($filename))
- {
- restore_backup($filename, $conn);
- $msg = _("Uploaded file has been restored.");
- }
- else
- {
- $msg = _("Backup was not uploaded into the system.");
- }
- return $msg;
- }
+ if (!file_exists(BACKUP_PATH)) {
+ display_error (_("Backup paths have not been set correctly.")
+ ._("Please contact System Administrator.")." "
+ . _("cannot find backup directory") . " - " . BACKUP_PATH . " ");
+ end_page();
+ exit;
}
- return "";
}
function generate_backup($conn, $ext='no', $comm='')
{
- if ($conn['tbpref'] != "")
- $filename = $conn['dbname'] . "_" . $conn['tbpref'] . date("Ymd_Hi") . ".sql";
+ $filename = db_backup($conn, $ext, $comm);
+ if ($filename)
+ display_notification(_("Backup successfully generated."). ' '
+ . _("Filename") . ": " . $filename);
else
- $filename = $conn['dbname'] . "_" . date("Ymd_Hi") . ".sql";
-
- $filename = db_export($conn, $filename, $ext, $comm);
-
+ display_error(_("Database backup failed."));
+
return $filename;
}
-function restore_backup($filename, $conn)
-{
- return db_import($filename, $conn);
-}
function get_backup_file_combo()
{
- global $path_to_root;
+ global $path_to_root, $Ajax;
+
$ar_files = array();
- default_focus('cmb_backups');
+ default_focus('backups');
$dh = opendir(BACKUP_PATH);
while (($file = readdir($dh)) !== false)
$ar_files[] = $file;
@@ -225,50 +79,118 @@ function get_backup_file_combo()
rsort($ar_files);
$opt_files = "";
foreach ($ar_files as $file)
- if (strpos($file, ".sql") || strpos($file, ".sql"))
+ if (preg_match("/.sql(.zip|.gz)?$/", $file))
$opt_files .= "$file ";
- return "$opt_files ";
+ $selector = "$opt_files ";
+
+ $Ajax->addUpdate('backups', "_backups_sel", $selector);
+ $selector = "".$selector." \n";
+
+ return $selector;
}
-function get_compr_combo()
+function compress_list_row($label, $name, $value=null)
{
- $ar_comps = array();
+ $ar_comps = array('no'=>_("No"));
- $ar_comps[] = _("No");
if (function_exists("gzcompress"))
- $ar_comps[] = "zip";
+ $ar_comps['zip'] = "zip";
if (function_exists("gzopen"))
- $ar_comps[] = "gzip";
- $opt_comps = "";
- foreach ($ar_comps as $file)
- $opt_comps .= "$file ";
+ $ar_comps['gzip'] = "gzip";
- return "$opt_comps ";
+ echo "$label ";
+ echo array_selector('comp', $value, $ar_comps);
+ echo " ";
}
function download_file($filename)
{
if (empty($filename) || !file_exists($filename))
{
- return FALSE;
+ 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.'"');
+ header('Content-Length: '.filesize($filename));
+ header('Content-Disposition: attachment; filename="'.$saveasname.'"');
readfile($filename);
+
return true;
}
-function valid_paths()
-{
- global $path_to_root;
+$db_name = $_SESSION["wa_current_user"]->company;
+$conn = $db_connections[$db_name];
+
+if (get_post('creat')) {
+ generate_backup($conn, get_post('comp'), get_post('comments'));
+ $Ajax->activate('backups');
+};
+
+if (get_post('restore')) {
+ if (db_import(BACKUP_PATH . get_post('backups'), $conn))
+ display_notification(_("Restore backup completed."));
+}
+
+if (get_post('deldump')) {
+ if (unlink(BACKUP_PATH . get_post('backups'))) {
+ display_notification(_("File successfully deleted.")." "
+ . _("Filename") . ": " . get_post('backups'));
+ $Ajax->activate('backups');
+ }
+ else
+ display_error(_("Can't delete backup file."));
+};
- $st = "";
- if (!file_exists(BACKUP_PATH))
- $st .= " - " . _("cannot find backup directory") . " - " . BACKUP_PATH . " ";
- return $st;
+if (get_post('upload'))
+{
+ $tmpname = $_FILES['uploadfile']['tmp_name'];
+ $fname = $_FILES['uploadfile']['name'];
+
+ if (!preg_match("/.sql(.zip|.gz)?$/", $fname))
+ display_error(_("You can only upload *.sql backup files"));
+ elseif (is_uploaded_file($tmpname)) {
+ rename($tmpname, BACKUP_PATH . $fname);
+ display_notification( "File uploaded to backup directory");
+ $Ajax->activate('backups');
+ } else
+ display_error(_("File was not uploaded into the system."));
}
+//-------------------------------------------------------------------------------
+start_form(true, true);
+start_outer_table(TABLESTYLE2);
+table_section(1);
+table_section_title(_("Create backup"));
+ textarea_row(_("Comments:"), 'comments', null, 30, 8);
+ compress_list_row(_("Compression:"),'comp');
+ vertical_space("height='20px'");
+ submit_row('creat',_("Create Backup"), false, "colspan=2 align='center'", '', 'process');
+table_section(2);
+table_section_title(_("Backup scripts maintenance"));
+
+ start_row();
+ echo "".get_backup_file_combo()." ";
+ echo "";
+ start_table();
+ submit_row('view',_("View Backup"), false, '', '', true);
+ submit_row('download',_("Download Backup"), false, '', '', false);
+ submit_row('restore',_("Restore Backup"), false, '','', 'process');
+ submit_js_confirm('restore',_("You are about to restore database from backup file.\nDo you want to continue?"));
+
+ submit_row('deldump', _("Delete Backup"), false, '','', true);
+ // don't use 'delete' name or IE js errors appear
+ submit_js_confirm('deldump', sprintf(_("You are about to remove selected backup file.\nDo you want to continue ?")));
+ end_table();
+ echo " ";
+ end_row();
+start_row();
+echo " ";
+ submit_cells('upload',_("Upload file"),'', '', true);
+end_row();
+end_outer_table();
-?>
\ No newline at end of file
+end_form();
+
+end_page();
+?>