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);
65 // stub function for old config method reverse compatability
68 function getData($configType, $configCat="", $configName="")
73 if($configCat != "") {
75 $wheredata = "where data_category='$configCat'";
78 if($configName != "") {
80 $wheredata .= " and data_name='$configName'";
82 $wheredata = "where data_name='$configName'";
86 $sql = "select data_val,data_category,data_name from datatable $wheredata";
87 $res = $this->dbobject->query($sql);
89 foreach($res as $row) {
90 $ret[$nret]["val"] = $row[0];
91 $ret[$nret]["cat"] = $row[1];
92 $ret[$nret]["name"] = $row[2];
99 function delData($configType, $configName, $configVal)
101 $sql = "delete from datatable where data_type='$configType' and data_name='$configName' and data_val='$configVal')";
102 $this->dbobject->query($sql);
105 function delAllDAta($configType, $configCat)
107 $sql = "delete from datatable where data_type='$configType' and data_name='$configName'";
108 //echo "sql is $sql\n";
109 $this->dbobject->query($sql);
112 function setupTables()
114 $sql = "SELECT count(name) FROM sqlite_master WHERE type='table' AND name='config';";
115 $res = $this->dbobject->query($sql);
117 foreach($res as $row) {
119 //echo "Tables exist\n";
125 $sql = 'CREATE TABLE "config" ( "configname" TEXT,"configvar" TEXT);';
126 $this->dbobject->query($sql);
128 $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_category" TEXT,"data_type" TEXT,"data_name" TEXT,"data_val" TEXT);';
129 $this->dbobject->query($sql);
131 $sql = 'CREATE TABLE sqlite_sequence(name,seq);';
132 $this->dbobject->query($sql);
140 function glcas_getWebConfigPath()
142 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
144 // if you wish to add more places to find webconfig, add them here.
146 if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) return realpath($WEB_ROOT_FS."/../var/glcas/webconfig");
147 if(file_exists("/var/lib/glcas/webconfig")) return realpath("/var/lib/glcas/webconfig");
148 if(file_exists("/var/run/glcas/webconfig")) return realpath("/var/run/glcas/webconfig");