]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved catalog selection trough PHP session variable
authorDavide Franco <bacula-dev@dflc.ch>
Mon, 27 Jun 2011 13:56:50 +0000 (15:56 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:49:17 +0000 (14:49 +0200)
gui/bacula-web/includes/bweb.inc.php
gui/bacula-web/index.php
gui/bacula-web/templates/header.tpl

index 52b26875858fa805affc61b6ff85e3488d2630ef..992b175fafbfc6a3e774bf6b5baf672111bbde6d 100644 (file)
@@ -26,6 +26,7 @@ class Bweb extends DB
        private $config;                                                // Loaded config from bacula.conf
        private $catalogs = array();                    // Catalog array
        public  $catalog_nb;
+       private $catalog_current_id;
        private $bwcfg;
 
     function __construct()
@@ -37,11 +38,27 @@ class Bweb extends DB
                $this->bwcfg->Load_Config();
                $this->catalog_nb = $this->bwcfg->Count_Catalogs();
                
-               // Select which catalog to connect to
-               if( isset( $_POST['catalog_id'] ) )
-                       $dsn = $this->bwcfg->Get_Dsn( $_POST['catalog_id'] );
-               else
-                       $dsn = $this->bwcfg->Get_Dsn( 0 );
+               // Initialize smarty template classe
+               $this->init_tpl();
+               // Initialize smarty gettext function
+               $this->init_gettext();
+               
+               // Check catalog id
+               if( isset($_POST['catalog_id']) ) {
+                       $this->catalog_current_id = $_POST['catalog_id'];
+                       $_SESSION['catalog_id'] = $this->catalog_current_id;
+               }
+               elseif( isset( $_SESSION['catalog_id'] ) )
+                       $this->catalog_current_id = $_SESSION['catalog_id'];
+               else {
+                       $this->catalog_current_id = 0;
+                       $_SESSION['catalog_id'] = $this->catalog_current_id;
+               }
+
+               $this->tpl->assign( 'catalog_current_id', $this->catalog_current_id );
+               
+               // Get DSN
+               $dsn = $this->bwcfg->Get_Dsn( $this->catalog_current_id );
                
                // Connect to the database
                $options = array( 'portability' => DB_PORTABILITY_ALL );
@@ -55,18 +72,12 @@ class Bweb extends DB
                        $this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
                }
                
-               // Initialize smarty template classe
-               $this->init_tpl();
-               // Initialize smarty gettext function
-               $this->init_gettext();
-               
                // Catalog selection            
                if( $this->catalog_nb > 1 ) {
-                       // Set current catalog in header template
-                       if(isset( $_POST['catalog_id'] ) )
-                               $this->tpl->assign( 'catalog_current', $_POST['catalog_id'] );
-                       
+                       // Catalogs list
                        $this->tpl->assign( 'catalogs', $this->bwcfg->Get_Catalogs() );                 
+                       // Catalogs count
+                       $this->tpl->assign( 'catalog_nb', $this->catalog_nb );
                }
        }
                 
index a89bed4e743a3690f83e44f830ff466a569cefa9..15a66510b39915c7694f376c37dedbcb402ea508 100644 (file)
@@ -20,9 +20,6 @@ include_once( 'config.inc.php' );
 
 $dbSql = new Bweb();
 
-// How many catalog configured
-$dbSql->tpl->assign( 'catalog_nb', $dbSql->catalog_nb );
-
 // Stored files number 
 $dbSql->tpl->assign('stored_files', $dbSql->GetStoredFiles( ALL ) );
   
index d4b833545e86b6b6ddea2417349f0109b610870e..190b9a1b12fb1a7f62e065c353fd66f04de5d441 100644 (file)
@@ -14,7 +14,7 @@
                <form method="post" action="index.php">
                        Catalog&nbsp;
                        <select name="catalog_id" OnChange="submit()">
-                               {html_options options=$catalogs selected=$smarty.post.catalog_id} 
+                               {html_options options=$catalogs selected=$catalog_current_id}
                        </select>
                </form>
        </li>