[2418] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
| 12 | /** |
---|
[2429] | 13 | * General settings class. This class should be used to centralize all settings |
---|
| 14 | * used by the module. |
---|
[2418] | 15 | * |
---|
| 16 | * @package Settings |
---|
| 17 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 18 | * @author Pedro Eugênio Rocha - pedro.eugenio.rocha@gmail.com |
---|
| 19 | */ |
---|
| 20 | class Settings { |
---|
| 21 | |
---|
| 22 | /** |
---|
| 23 | * @var array $_configs Here we should define which settings we are able |
---|
| 24 | * to get. The settings not defined here will throw |
---|
| 25 | * an exception when someone asks for it. |
---|
| 26 | * @access private |
---|
[2429] | 27 | * @static |
---|
[2418] | 28 | */ |
---|
| 29 | private static $_configs = array( |
---|
| 30 | 'workflow' => array( |
---|
[2492] | 31 | 'db_processes' => array( |
---|
[2418] | 32 | 'name' => '', |
---|
| 33 | 'host' => '', |
---|
| 34 | 'port' => '', |
---|
| 35 | 'admin_user' => '', |
---|
| 36 | 'admin_password' => '', |
---|
| 37 | 'type' => '' |
---|
| 38 | ), |
---|
[2492] | 39 | 'db_module' => array( |
---|
| 40 | 'name' => '', |
---|
| 41 | 'host' => '', |
---|
| 42 | 'port' => '', |
---|
| 43 | 'user' => '', |
---|
| 44 | 'password' => '', |
---|
| 45 | 'type' => '' |
---|
[2418] | 46 | ), |
---|
| 47 | 'ldap' => array( |
---|
| 48 | 'host' => '', |
---|
| 49 | 'user' => '', |
---|
| 50 | 'password' => '', |
---|
[2492] | 51 | 'follow_referrals' => '', |
---|
| 52 | 'user_context' => '', |
---|
| 53 | 'group_context' => '' |
---|
[2418] | 54 | ), |
---|
[2492] | 55 | 'preferences' => array( |
---|
| 56 | 'startpage' => '', |
---|
| 57 | 'ui_items_per_page' => '', |
---|
| 58 | 'show_activity_complete_page' => '' |
---|
| 59 | ), |
---|
| 60 | 'intranet_subnetworks' => '', |
---|
| 61 | 'user_can_clean_instances' => '' |
---|
[2418] | 62 | ), |
---|
| 63 | 'expresso' => array( |
---|
| 64 | 'db' => array( |
---|
| 65 | 'name' => '', |
---|
| 66 | 'host' => '', |
---|
| 67 | 'port' => '', |
---|
| 68 | 'user' => '', |
---|
| 69 | 'password' => '', |
---|
| 70 | 'type' => '' |
---|
| 71 | ), |
---|
| 72 | 'ldap' => array( |
---|
[2492] | 73 | 'host' => '', |
---|
| 74 | 'user_context' => '', |
---|
| 75 | 'group_context' => '' |
---|
[2418] | 76 | ), |
---|
[2492] | 77 | 'user' => array( |
---|
| 78 | 'account_id' => '', |
---|
| 79 | 'account_lid' => '', |
---|
| 80 | 'account_dn' => '', |
---|
| 81 | 'userid' => '', |
---|
| 82 | 'passwd' => '', |
---|
| 83 | 'email' => '' |
---|
| 84 | ), |
---|
| 85 | 'preferences' => array( |
---|
| 86 | 'lang' => '' |
---|
| 87 | ), |
---|
| 88 | 'webserver_url' => '' |
---|
[2418] | 89 | ) |
---|
| 90 | ); |
---|
| 91 | |
---|
[2429] | 92 | /** |
---|
| 93 | * @var boolean $_isLoaded Stores whether the settings are loaded or not. |
---|
| 94 | * @access private |
---|
| 95 | * @static |
---|
| 96 | */ |
---|
| 97 | private static $_isLoaded = false; |
---|
[2418] | 98 | |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * Constructor. Just disabling direct instantiation. |
---|
| 102 | * |
---|
| 103 | * @access public |
---|
| 104 | * @return void |
---|
| 105 | */ |
---|
| 106 | public function __construct() { |
---|
| 107 | throw new Exception("Oops! Static only class."); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | /** |
---|
[2492] | 112 | * Returns settings. If the hole path has not be setted, return the hole |
---|
| 113 | * hierarchy under it. |
---|
[2418] | 114 | * |
---|
| 115 | * @param string $args A variable number of parameters which specify the scope |
---|
| 116 | * and the configuration to be retrieved. |
---|
| 117 | * @access public |
---|
| 118 | * @return string |
---|
| 119 | * @static |
---|
| 120 | */ |
---|
| 121 | public static function get() { |
---|
| 122 | |
---|
| 123 | /* getting the variable number of parameters */ |
---|
| 124 | $args = func_get_args(); |
---|
| 125 | |
---|
[2492] | 126 | /* checking if the key exists */ |
---|
| 127 | self::_keyExists($args); |
---|
[2418] | 128 | |
---|
[2429] | 129 | /* check if we already load the settings */ |
---|
| 130 | if (!self::$_isLoaded) |
---|
| 131 | self::_load(); |
---|
[2418] | 132 | |
---|
| 133 | /* retrieving the setting. More 'for' programming. */ |
---|
| 134 | for ($i=0, $value=&self::$_configs; $i<count($args); $value=&$value[$args[$i++]]); |
---|
| 135 | |
---|
| 136 | return $value; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[2492] | 140 | public static function set() { |
---|
| 141 | |
---|
| 142 | /* getting the variable number of parameters */ |
---|
| 143 | $args = func_get_args(); |
---|
| 144 | |
---|
| 145 | /* the last position is always the value that we are trying to set, so pop it */ |
---|
| 146 | $value = array_pop($args); |
---|
| 147 | |
---|
| 148 | /* checking if the key exists */ |
---|
| 149 | self::_keyExists($args); |
---|
| 150 | |
---|
| 151 | /* check if we already load the settings */ |
---|
| 152 | if (!self::$_isLoaded) |
---|
| 153 | self::_load(); |
---|
| 154 | |
---|
| 155 | /* retrieving the setting. More 'for' programming. */ |
---|
| 156 | for ($i=0, $key=&self::$_configs; $i<count($args); $key=&$key[$args[$i++]]); |
---|
| 157 | |
---|
| 158 | /* updating the value. p.s: $key is a pointer to a $_config node */ |
---|
| 159 | $key = $value; |
---|
| 160 | return true; |
---|
| 161 | } |
---|
| 162 | |
---|
[2429] | 163 | /** |
---|
[2492] | 164 | * Here we check if the configuration was defined into $_configs array. |
---|
| 165 | * If it does not, an exception will be thrown. |
---|
| 166 | * |
---|
| 167 | * @param string $args A variable number of parameters which specify the scope |
---|
| 168 | * and the configuration to be retrieved. |
---|
| 169 | * @access private |
---|
| 170 | * @return boolean |
---|
| 171 | * @static |
---|
| 172 | */ |
---|
| 173 | private static function _keyExists($path) { |
---|
| 174 | |
---|
| 175 | /** |
---|
| 176 | * p.s: Do not try to understand this piece of code. Just fave faith! It works... |
---|
| 177 | */ |
---|
| 178 | for ($i=0, $sub_array=&self::$_configs; $i<count($path); $sub_array=&$sub_array[$path[$i++]]) { |
---|
| 179 | if (!array_key_exists($path[$i], $sub_array)) |
---|
| 180 | throw new Exception("Sorry! Setting '".implode("->", $path)."' do not exists."); |
---|
| 181 | } |
---|
| 182 | return true; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | /** |
---|
[2429] | 187 | * Loads settings into $_configs private array. |
---|
| 188 | * |
---|
| 189 | * @access private |
---|
| 190 | * @return void |
---|
| 191 | * @static |
---|
| 192 | */ |
---|
| 193 | private static function _load() { |
---|
[2418] | 194 | |
---|
[2429] | 195 | /* loading global variables into $_configs */ |
---|
[2418] | 196 | self::$_configs['expresso']['db']['name'] = $GLOBALS['phpgw_info']['server']['db_name']; |
---|
| 197 | self::$_configs['expresso']['db']['host'] = $GLOBALS['phpgw_info']['server']['db_host']; |
---|
| 198 | self::$_configs['expresso']['db']['port'] = $GLOBALS['phpgw_info']['server']['db_port']; |
---|
| 199 | self::$_configs['expresso']['db']['user'] = $GLOBALS['phpgw_info']['server']['db_user']; |
---|
| 200 | self::$_configs['expresso']['db']['password'] = $GLOBALS['phpgw_info']['server']['db_pass']; |
---|
| 201 | self::$_configs['expresso']['db']['type'] = $GLOBALS['phpgw_info']['server']['db_type']; |
---|
| 202 | |
---|
[2492] | 203 | /* current user information */ |
---|
| 204 | self::$_configs['expresso']['user']['account_id'] = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 205 | self::$_configs['expresso']['user']['account_lid'] = $GLOBALS['phpgw_info']['user']['account_lid']; |
---|
| 206 | self::$_configs['expresso']['user']['account_dn'] = $GLOBALS['phpgw_info']['user']['account_dn']; |
---|
| 207 | self::$_configs['expresso']['user']['userid'] = $GLOBALS['phpgw_info']['user']['userid']; |
---|
| 208 | self::$_configs['expresso']['user']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd']; |
---|
| 209 | self::$_configs['expresso']['user']['email'] = $GLOBALS['phpgw_info']['user']['email']; |
---|
| 210 | |
---|
[2418] | 211 | self::$_configs['expresso']['ldap']['host'] = $GLOBALS['phpgw_info']['server']['ldap_host']; |
---|
[2492] | 212 | self::$_configs['expresso']['ldap']['user_context'] = $GLOBALS['phpgw_info']['server']['ldap_user_context']; |
---|
| 213 | self::$_configs['expresso']['ldap']['group_context'] = $GLOBALS['phpgw_info']['server']['ldap_group_context']; |
---|
[2418] | 214 | |
---|
[2492] | 215 | /* workflow specific preferences */ |
---|
| 216 | self::$_configs['workflow']['preferences']['startpage'] = $GLOBALS['phpgw_info']['user']['preferences']['workflow']['startpage']; |
---|
| 217 | self::$_configs['workflow']['preferences']['ui_items_per_page'] = $GLOBALS['phpgw_info']['user']['preferences']['workflow']['ui_items_per_page']; |
---|
| 218 | self::$_configs['workflow']['preferences']['show_activity_complete_page'] = $GLOBALS['phpgw_info']['user']['preferences']['workflow']['show_activity_complete_page']; |
---|
| 219 | |
---|
| 220 | /*expresso preferences */ |
---|
| 221 | self::$_configs['expresso']['preferences']['lang'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; |
---|
| 222 | |
---|
| 223 | self::$_configs['expresso']['webserver_url'] = $GLOBALS['phpgw_info']['server']['webserver_url']; |
---|
| 224 | |
---|
[2429] | 225 | /* loading database settings */ |
---|
| 226 | $config = &Factory::newInstance('config', 'workflow'); |
---|
| 227 | $values = $config->read_repository(); |
---|
[2418] | 228 | |
---|
| 229 | self::$_configs['workflow']['intranet_subnetworks'] = $values['intranet_subnetworks']; |
---|
| 230 | |
---|
[2492] | 231 | self::$_configs['workflow']['db_processes']['name'] = $values['database_name']; |
---|
| 232 | self::$_configs['workflow']['db_processes']['host'] = $values['database_host']; |
---|
| 233 | self::$_configs['workflow']['db_processes']['port'] = $values['database_port']; |
---|
| 234 | self::$_configs['workflow']['db_processes']['admin_user'] = $values['database_admin_user']; |
---|
| 235 | self::$_configs['workflow']['db_processes']['admin_password'] = $values['database_admin_password']; |
---|
| 236 | self::$_configs['workflow']['db_processes']['type'] = $values['database_type']; |
---|
[2418] | 237 | |
---|
[2492] | 238 | self::$_configs['workflow']['db_module']['name'] = $values['workflow_database_name']; |
---|
| 239 | self::$_configs['workflow']['db_module']['host'] = $values['workflow_database_host']; |
---|
| 240 | self::$_configs['workflow']['db_module']['port'] = $values['workflow_database_port']; |
---|
| 241 | self::$_configs['workflow']['db_module']['user'] = $values['workflow_database_user']; |
---|
| 242 | self::$_configs['workflow']['db_module']['password'] = $values['workflow_database_password']; |
---|
| 243 | self::$_configs['workflow']['db_module']['type'] = $values['workflow_database_type']; |
---|
[2418] | 244 | |
---|
| 245 | self::$_configs['workflow']['ldap']['host'] = $values['ldap_host']; |
---|
| 246 | self::$_configs['workflow']['ldap']['user'] = $values['ldap_user']; |
---|
| 247 | self::$_configs['workflow']['ldap']['password'] = $values['ldap_password']; |
---|
| 248 | self::$_configs['workflow']['ldap']['follow_referrals'] = $values['ldap_follow_referrals']; |
---|
[2492] | 249 | self::$_configs['workflow']['ldap']['user_context'] = $values['ldap_user_context']; |
---|
| 250 | self::$_configs['workflow']['ldap']['group_context'] = $values['ldap_group_context']; |
---|
[2418] | 251 | |
---|
[2429] | 252 | /* the settings are already loaded. No need to call this method again. */ |
---|
| 253 | self::$_isLoaded = true; |
---|
[2418] | 254 | } |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | ?> |
---|