]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/includes/cfg/config.class.php
bacula-web: Replaced Get_human_file_size() function by Utils::Get_Human_Size
[bacula/bacula] / gui / bacula-web / includes / cfg / config.class.php
1 <?php
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright 2010-2011, Davide Franco                                              |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+ 
16 */
17  class BW_Config {
18  
19         private $config_params;
20         private $config;
21         private $catalogs = array();
22         
23         function __construct()
24         {
25                 global $config;
26                 $this->config = $config;
27         }
28         
29         public function Check_Config_file()
30         {
31                 // Check if config file exist and is readable
32                 return is_readable( CONFIG_FILE );
33         }
34         
35         public function Load_Config()
36         {
37                 global $config;
38                 
39                 if( $this->Check_Config_file() )
40                         include_once( CONFIG_FILE );
41                 else
42                         die( "Configuration file not found" );
43                 
44                 if( is_array($config) && !empty($config) ) {
45                         // Loading database connection information
46                         foreach( $config as $parameter => $value )
47                         {
48                                 if( is_array($value) )          // Parsing database section
49                                         array_push( $this->catalogs, $value );
50                         }
51                         return true;
52                 }else {
53                         return false;           
54                 }
55         }
56         
57         public function Get_Config_Param( $param )
58         {
59                 if( isset( $config[$param] ) )
60                         return $config[$param];
61         }
62         
63         public function Get_Catalogs()
64         {
65                 $result = array();
66                 foreach( $this->catalogs as $db )
67                         array_push( $result, $db['label']);
68                 
69                 return $result;
70         }
71         
72         public function Count_Catalogs()
73         {
74                 return count( $this->catalogs );
75         }
76         
77         public function Get_Dsn( $catalog_id )
78         {
79                 // Construct a valid dsn
80                 $dsn = array();
81         $dsn['hostspec'] = $this->catalogs[$catalog_id]["host"];
82         $dsn['username'] = $this->catalogs[$catalog_id]["login"];
83                 $dsn['password'] = $this->catalogs[$catalog_id]["password"];
84                 $dsn['database'] = $this->catalogs[$catalog_id]["db_name"];
85                 $dsn['phptype']  = $this->catalogs[$catalog_id]["db_type"];
86                 return $dsn;
87         }
88                 
89         function __destruct()
90         {
91                 
92         }
93         
94  } // end classe BW_Config
95  
96 ?>