7 $this->configPath = "";
9 $this->dbobject = false;
12 function loadConfig($configpath)
14 error_log("loadConfig $configpath");
15 $this->configPath = $configpath;
18 $this->dbobject = new PDO("sqlite:$configpath");
19 } catch(PDOException $exep) {
20 error_log("execpt on db open");
27 function setConfig($configname, $configval)
29 $sql = "delete from config where configname='$configname'";
30 $this->dbobject->query($sql);
31 $sql = "insert into config values ('$configname', '$configval')";
32 $this->dbobject->query($sql);
35 function getConfig($configname)
37 $sql = "select configvar from config where configname='$configname'";
38 $res = $this->dbobject->query($sql);
40 foreach($res as $row) {
42 error_log("foreach, $val\n");
48 function delConfig($configname)
50 $sql = "delete from config where configname='$configname'";
51 $this->dbobject->query($sql);
56 function addData($configType, $configCat, $configName, $configVal)
58 $sql = "insert into datatable values (NULL, '$configType', '$configCat', '$configName', '$configVal')";
59 $this->dbobject->query($sql);
60 //error_log("CONFIG: adddata as $sql");
65 // stub function for old config method reverse compatability
68 function getData($configType, $configCat="", $configName="")
74 $wheredata = "where data_type='$configType'";
75 if($configCat != "") {
76 $wheredata .= " and data_category='$configCat'";
79 if($configName != "") {
80 $wheredata .= " and data_name='$configName'";
83 $sql = "select data_category,data_name,data_val from datatable $wheredata";
84 //error_log("CONFIG: get via $sql");
86 $res = $this->dbobject->query($sql);
88 foreach($res as $row) {
89 $ret[$nret]["val"] = $row[2];
90 $ret[$nret]["category"] = $row[0];
91 $ret[$nret]["name"] = $row[1];
94 if($nret == 0) return false;
99 function delData($configType, $configCat, $configName="", $configVal="")
102 if($configName != "") {
103 $extrawhere = " and data_name='$configName'";
105 if($configVal != "") {
106 $extrawhere .= " and data_val='$configVal'";
108 $sql = "delete from datatable where data_type='$configType' and data_category='$configCat' $extrawhere";
109 $this->dbobject->query($sql);
111 //error_log("del all data was $sql");
114 function delAllDAta($configType, $configCat)
116 $sql = "delete from datatable where data_type='$configType' and data_category='$configCat'";
117 //echo "sql is $sql\n";
118 $this->dbobject->query($sql);
119 //error_log("del all data was $sql");
122 function setupTables()
124 $sql = "SELECT count(name) FROM sqlite_master WHERE type='table' AND name='config';";
125 $res = $this->dbobject->query($sql);
127 foreach($res as $row) {
129 //echo "Tables exist\n";
135 $sql = 'CREATE TABLE "config" ( "configname" TEXT,"configvar" TEXT);';
136 $this->dbobject->query($sql);
138 $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_type" TEXT,"data_category" TEXT,"data_name" TEXT,"data_val" TEXT);';
139 $this->dbobject->query($sql);
141 $sql = 'CREATE TABLE sqlite_sequence(name,seq);';
142 $this->dbobject->query($sql);
150 function glcas_getWebConfigPath()
152 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
154 // if you wish to add more places to find webconfig, add them here.
156 if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) return realpath($WEB_ROOT_FS."/../var/glcas/webconfig");
157 if(file_exists("/var/lib/glcas/webconfig")) return realpath("/var/lib/glcas/webconfig");
158 if(file_exists("/var/run/glcas/webconfig")) return realpath("/var/run/glcas/webconfig");