moved to an sqlite database for config rather then flat text file
[glcas.git] / libglcas / config.php
1 <?php
2
3 class GLCASConfig {
4         
5         function __construct()
6         {
7                 $this->configPath = "";
8                 $this->config = "";
9         }
10         
11         function loadConfig($configpath)
12         {
13                 error_log("loadConfig $configpath");
14                 $this->configPath = $configpath;
15                 $flt = file_get_contents($configpath);
16                 $this->config = unserialize(base64_decode($flt));
17                 
18                 
19         }
20         
21         function getConfigVar($var)
22         {
23                 if(isset($this->config["$var"])) {
24                         return $this->config["$var"];
25                 } else return false;
26         }
27         
28         function setConfigVar($var, $value)
29         {
30                 if(is_array($this->config)) {
31                         foreach($this->config as $vkey => $val) {
32                                 if($vkey == "$var") {
33                                         error_log("reset config of $var to $value");
34                                         $this->config[$var] = $value;
35                                         return true;
36                                 }
37                         }
38                 } else error_log("config isnt array");
39                 
40                 // otherwise, set it
41                 error_log("set config of $var to $value");
42                 $this->config[$var] = $value;
43
44         }
45         
46         function delConfigVar($var)
47         {
48                 if(is_array($this->config)) {
49                         foreach($this->config as $vkey => $val) {
50                                 if($vkey == "$var") {
51                                         error_log("remove config of $var to $value");
52                                         unset($this->config[$var]);
53                                         return true;
54                                 }
55                         }
56                 } else error_log("config isnt array");
57         }
58         
59         function saveConfig()
60         {
61                 file_put_contents($this->configPath, base64_encode(serialize($this->config)));
62         }
63         
64         function debug()
65         {
66                 echo "<pre>";
67                 echo "path: ".$this->configPath."\n";
68                 print_r($this->config);
69                 echo "</pre>";
70         }
71         
72         private $configPath;
73         private $config;
74         
75 }
76
77 function glcas_getWebConfigPath()
78 {
79         global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
80
81         // if you wish to add more places to find webconfig, add them here.
82         $configpath = false;
83         if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) return realpath($WEB_ROOT_FS."/../var/glcas/webconfig");
84         if(file_exists("/var/lib/glcas/webconfig")) return realpath("/var/lib/glcas/webconfig");
85         if(file_exists("/var/run/glcas/webconfig")) return realpath("/var/run/glcas/webconfig");
86         
87         return $configpath;
88         //return false; 
89 }
90
91
92 ?>