]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Class/ConfigurationManager.php
Add Baculum
[bacula/bacula] / gui / baculum / protected / Class / ConfigurationManager.php
1 <?php
2 /**
3  * Bacula® - The Network Backup Solution
4  * Baculum - Bacula web interface
5  *
6  * Copyright (C) 2013-2014 Marcin Haba
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The main author of Bacula is Kern Sibbald, with contributions from many
10  * others, a complete list can be found in the file AUTHORS.
11  *
12  * You may use this file and others of this release according to the
13  * license defined in the LICENSE file, which includes the Affero General
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and
15  * terms pursuant to its AGPLv3 Section 7.
16  *
17  * Bacula® is a registered trademark of Kern Sibbald.
18  */
19
20 Prado::using('Application.Class.Miscellaneous');
21
22 class ConfigurationManager extends TModule
23 {
24
25         /**
26          * Location o application configuration file.
27          */
28         const CONFIG_FILE = 'Application.Data.settings';
29
30         /**
31          * PostgreSQL default params.
32          */
33         const PGSQL = 'pgsql';
34         const PGSQL_NAME = 'PostgreSQL';
35         const PGSQL_PORT = 5432;
36
37         /**
38          * MySQL default params.
39          */
40         const MYSQL = 'mysql';
41         const MYSQL_NAME = 'MySQL';
42         const MYSQL_PORT = 3306;
43
44         /**
45          * SQLite default params.
46          */
47         const SQLITE = 'sqlite';
48         const SQLITE_NAME = 'SQLite';
49         const SQLITE_PORT = null;
50
51         /**
52          * Default language for application.
53          */
54         const DEFAULT_LANGUAGE = 'en';
55
56         public function getDbNameByType($type) {
57                 switch($type) {
58                         case self::PGSQL: $dbName = self::PGSQL_NAME; break;
59                         case self::MYSQL: $dbName = self::MYSQL_NAME; break;
60                         case self::SQLITE: $dbName = self::SQLITE_NAME; break;
61                         default: $dbName = null; break;
62                 }
63                 return $dbName;
64         }
65
66         public function getPostgreSQLType() {
67                 return self::PGSQL;
68         }
69
70         public function getMySQLType() {
71                 return self::MYSQL;
72         }
73
74         public function getSQLiteType() {
75                 return self::SQLITE;
76         }
77
78         public function isPostgreSQLType($type) {
79                 return ($type === self::PGSQL);
80         }
81
82         public function isMySQLType($type) {
83                 return ($type === self::MYSQL);
84         }
85
86         public function isSQLiteType($type) {
87                 return ($type === self::SQLITE);
88         }
89
90         public function getLanguage() {
91                 return $this->Application->Parameters['language'];
92         }
93
94         public function setLanguage($language) {
95                 
96         }
97
98         /**
99          * Saving application configuration.
100          * 
101          * @access public
102          * @param array $config structure of config file params
103          * @return boolean true if config save is successfully, false if config save is failure
104          */
105         public function setApplicationConfig(array $config) {
106                 $cfgFile = Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf');
107                 return ($this->Application->getModule('misc')->writeINIFile($cfgFile, $config) != false);
108         }
109
110         /**
111          * Getting application configuration.
112          * 
113          * @access public
114          * @return array application configuration
115          */
116         public static function getApplicationConfig() {
117                 $cfgFile = Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf');
118                 return Miscellaneous::parseINIFile($cfgFile);
119         }
120
121         /**
122          * Checking if application configuration file exists.
123          * 
124          * @access public
125          * @return boolean true if file exists, otherwise false
126          */
127         public function isApplicationConfig() {
128                 return file_exists(Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf'));
129         }
130 }
131 ?>