X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=blobdiff_plain;f=libglcas%2Fconfig.php;fp=libglcas%2Fconfig.php;h=499c97b2b2cb7d3dc1c3fc6e2dab330e9ba16fc1;hp=649804651f372f3411e5c5de8ddf0b2d60b763d8;hb=37b5d51a06265cba25c1c92418223837c6d3ad2b;hpb=fd77672af03a95b0d016c0c1cd76c0441a8857d1 diff --git a/libglcas/config.php b/libglcas/config.php index 6498046..499c97b 100644 --- a/libglcas/config.php +++ b/libglcas/config.php @@ -15,7 +15,7 @@ class GLCASConfig { $this->configPath = $configpath; try { - $this->dbobject = new PDO("sqlite:".$this->configPath); + $this->dbobject = new PDO("sqlite:$configpath"); } catch(PDOException $exep) { error_log("execpt on db open"); return false; @@ -36,7 +36,7 @@ class GLCASConfig { { $sql = "select configvar from config where configname='$configname'"; $res = $this->dbobject->query($sql); - $val = null; + $val = false; foreach($res as $row) { $val = $row[0]; error_log("foreach, $val\n"); @@ -53,27 +53,43 @@ class GLCASConfig { return true; } - function addData($configType, $configName, $configVal) + function addData($configType, $configCat, $configName, $configVal) { - $sql = "insert into datatable values (NULL, '$configType', '$configName', '$configVal')"; + $sql = "insert into datatable values (NULL, '$configType', '$configCat', $configName', '$configVal')"; $this->dbobject->query($sql); } - function getData($configType, $configName="") + function saveConfig() + { + // stub function for old config method reverse compatability + } + + function getData($configType, $configCat="", $configName="") { $ret = null; $nret = 0; - if($configName == "") { - $sql = "select data_val,data_name from datatable where data_type='$configType'"; - } else { - $sql = "select data_val from datatable where data_type='$configType' and data_name='$configName'"; + $haveWhere = false; + if($configCat != "") { + $haveWhere = true; + $wheredata = "where data_category='$configCat'"; } + + if($configName != "") { + if($haveWhere) { + $wheredata .= " and data_name='$configName'"; + } else { + $wheredata = "where data_name='$configName'"; + } + } + + $sql = "select data_val,data_category,data_name from datatable $wheredata"; $res = $this->dbobject->query($sql); foreach($res as $row) { $ret[$nret]["val"] = $row[0]; - if($configName == "") $ret[$nret]["name"] = $row[1]; + $ret[$nret]["cat"] = $row[1]; + $ret[$nret]["name"] = $row[2]; $nret++; } @@ -86,7 +102,7 @@ class GLCASConfig { $this->dbobject->query($sql); } - function delAllDAta($configType, $configName) + function delAllDAta($configType, $configCat) { $sql = "delete from datatable where data_type='$configType' and data_name='$configName'"; //echo "sql is $sql\n"; @@ -100,7 +116,7 @@ class GLCASConfig { foreach($res as $row) { if($row[0] > 0) { - echo "Tables exist\n"; + //echo "Tables exist\n"; return; } } @@ -109,7 +125,7 @@ class GLCASConfig { $sql = 'CREATE TABLE "config" ( "configname" TEXT,"configvar" TEXT);'; $this->dbobject->query($sql); - $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_type" TEXT,"data_name" TEXT,"data_val" TEXT);'; + $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_category" TEXT,"data_type" TEXT,"data_name" TEXT,"data_val" TEXT);'; $this->dbobject->query($sql); $sql = 'CREATE TABLE sqlite_sequence(name,seq);';