Messages now displayed as on other pages in messagebox.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 10 Nov 2008 22:28:34 +0000 (22:28 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 10 Nov 2008 22:28:34 +0000 (22:28 +0000)
admin/backups.php

index e653757977360e8a2af23eaf32c78617f572773f..76c595a4a36fdb67dbb96f619924e8d1ea6bb250 100644 (file)
@@ -18,7 +18,7 @@ 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"), false, false, '', '', true);
 
@@ -70,7 +70,6 @@ echo "
        </script>
        <center>
        <table cellpadding=2 cellspacing=2 border=0>
-       <tr><td colspan=2 style='color:darkred'><b>$msg</b>&nbsp;</td></tr>
        <tr>
                <td style='padding-right:30px'>" . _("Backup scripts") . "</td>
        </tr>
@@ -109,94 +108,75 @@ end_page();
 
 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.")."&nbsp;&nbsp;&nbsp;";
+                       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.")."&nbsp;&nbsp;&nbsp;";
+                       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.")."&nbsp;&nbsp;&nbsp;";
-                       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='')
@@ -255,7 +235,7 @@ function download_file($filename)
 {
     if (empty($filename) || !file_exists($filename))
     {
-        return FALSE;
+        return false;
     }
     $saveasname = basename($filename);
     header('Content-type: application/octet-stream');