From fd77672af03a95b0d016c0c1cd76c0441a8857d1 Mon Sep 17 00:00:00 2001 From: paulr Date: Mon, 8 Aug 2011 05:11:01 +1000 Subject: [PATCH] moved the config bit over... awesome --- libglcas/config.php | 128 +++++++++++++++++++++++++++++------------- libglcas/config_new.php | 140 ----------------------------------------------- libglcas/config_old.php | 92 +++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+), 180 deletions(-) delete mode 100644 libglcas/config_new.php create mode 100644 libglcas/config_old.php diff --git a/libglcas/config.php b/libglcas/config.php index 2009823..6498046 100644 --- a/libglcas/config.php +++ b/libglcas/config.php @@ -6,74 +6,121 @@ class GLCASConfig { { $this->configPath = ""; $this->config = ""; + $this->dbobject = false; } function loadConfig($configpath) { error_log("loadConfig $configpath"); $this->configPath = $configpath; - $flt = file_get_contents($configpath); - $this->config = unserialize(base64_decode($flt)); + try { + $this->dbobject = new PDO("sqlite:".$this->configPath); + } catch(PDOException $exep) { + error_log("execpt on db open"); + return false; + } + $this->setupTables(); } - function getConfigVar($var) + function setConfig($configname, $configval) { - if(isset($this->config["$var"])) { - return $this->config["$var"]; - } else return false; + $sql = "delete from config where configname='$configname'"; + $this->dbobject->query($sql); + $sql = "insert into config values ('$configname', '$configval')"; + $this->dbobject->query($sql); } - function setConfigVar($var, $value) + function getConfig($configname) { - if(is_array($this->config)) { - foreach($this->config as $vkey => $val) { - if($vkey == "$var") { - error_log("reset config of $var to $value"); - $this->config[$var] = $value; - return true; - } - } - } else error_log("config isnt array"); + $sql = "select configvar from config where configname='$configname'"; + $res = $this->dbobject->query($sql); + $val = null; + foreach($res as $row) { + $val = $row[0]; + error_log("foreach, $val\n"); + } - // otherwise, set it - error_log("set config of $var to $value"); - $this->config[$var] = $value; - + return $val; } - function delConfigVar($var) + function delConfig($configname) { - if(is_array($this->config)) { - foreach($this->config as $vkey => $val) { - if($vkey == "$var") { - error_log("remove config of $var to $value"); - unset($this->config[$var]); - return true; - } - } - } else error_log("config isnt array"); + $sql = "delete from config where configname='$configname'"; + $this->dbobject->query($sql); + + return true; + } + + function addData($configType, $configName, $configVal) + { + $sql = "insert into datatable values (NULL, '$configType', '$configName', '$configVal')"; + $this->dbobject->query($sql); + + } + + function getData($configType, $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'"; + } + $res = $this->dbobject->query($sql); + + foreach($res as $row) { + $ret[$nret]["val"] = $row[0]; + if($configName == "") $ret[$nret]["name"] = $row[1]; + $nret++; + } + + return $ret; } - function saveConfig() + function delData($configType, $configName, $configVal) { - file_put_contents($this->configPath, base64_encode(serialize($this->config))); + $sql = "delete from datatable where data_type='$configType' and data_name='$configName' and data_val='$configVal')"; + $this->dbobject->query($sql); } - function debug() + function delAllDAta($configType, $configName) { - echo "
";
-		echo "path: ".$this->configPath."\n";
-		print_r($this->config);
-		echo "
"; + $sql = "delete from datatable where data_type='$configType' and data_name='$configName'"; + //echo "sql is $sql\n"; + $this->dbobject->query($sql); + } + + function setupTables() + { + $sql = "SELECT count(name) FROM sqlite_master WHERE type='table' AND name='config';"; + $res = $this->dbobject->query($sql); + + foreach($res as $row) { + if($row[0] > 0) { + echo "Tables exist\n"; + return; + } + } + + + $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);'; + $this->dbobject->query($sql); + + $sql = 'CREATE TABLE sqlite_sequence(name,seq);'; + $this->dbobject->query($sql); } private $configPath; - private $config; + private $dbobject; } - + function glcas_getWebConfigPath() { global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; @@ -88,5 +135,6 @@ function glcas_getWebConfigPath() //return false; } + -?> \ No newline at end of file +?> diff --git a/libglcas/config_new.php b/libglcas/config_new.php deleted file mode 100644 index da53ed6..0000000 --- a/libglcas/config_new.php +++ /dev/null @@ -1,140 +0,0 @@ -configPath = ""; - $this->config = ""; - $this->dbobject = false; - } - - function loadConfig($configpath) - { - error_log("loadConfig $configpath"); - $this->configPath = $configpath.".db"; - - try { - $this->dbobject = new PDO("sqlite:".$this->configPath); - } catch(PDOException $exep) { - error_log("execpt on db open"); - return false; - } - - $this->setupTables(); - } - - function setConfig($configname, $configval) - { - $sql = "delete from config where configname='$configname'"; - $this->dbobject->query($sql); - $sql = "insert into config values ('$configname', '$configval')"; - $this->dbobject->query($sql); - } - - function getConfig($configname) - { - $sql = "select configvar from config where configname='$configname'"; - $res = $this->dbobject->query($sql); - $val = null; - foreach($res as $row) { - $val = $row[0]; - error_log("foreach, $val\n"); - } - - return $val; - } - - function delConfig($configname) - { - $sql = "delete from config where configname='$configname'"; - $this->dbobject->query($sql); - - return true; - } - - function addData($configType, $configName, $configVal) - { - $sql = "insert into datatable values (NULL, '$configType', '$configName', '$configVal')"; - $this->dbobject->query($sql); - - } - - function getData($configType, $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'"; - } - $res = $this->dbobject->query($sql); - - foreach($res as $row) { - $ret[$nret]["val"] = $row[0]; - if($configName == "") $ret[$nret]["name"] = $row[1]; - $nret++; - } - - return $ret; - } - - function delData($configType, $configName, $configVal) - { - $sql = "delete from datatable where data_type='$configType' and data_name='$configName' and data_val='$configVal')"; - $this->dbobject->query($sql); - } - - function delAllDAta($configType, $configName) - { - $sql = "delete from datatable where data_type='$configType' and data_name='$configName'"; - //echo "sql is $sql\n"; - $this->dbobject->query($sql); - } - - function setupTables() - { - $sql = "SELECT count(name) FROM sqlite_master WHERE type='table' AND name='config';"; - $res = $this->dbobject->query($sql); - - foreach($res as $row) { - if($row[0] > 0) { - echo "Tables exist\n"; - return; - } - } - - - $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);'; - $this->dbobject->query($sql); - - $sql = 'CREATE TABLE sqlite_sequence(name,seq);'; - $this->dbobject->query($sql); - } - - private $configPath; - private $dbobject; - -} - -function glcas_getWebConfigPath() -{ - global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; - - // if you wish to add more places to find webconfig, add them here. - $configpath = false; - if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) return realpath($WEB_ROOT_FS."/../var/glcas/webconfig"); - if(file_exists("/var/lib/glcas/webconfig")) return realpath("/var/lib/glcas/webconfig"); - if(file_exists("/var/run/glcas/webconfig")) return realpath("/var/run/glcas/webconfig"); - - return $configpath; - //return false; -} - - - -?> diff --git a/libglcas/config_old.php b/libglcas/config_old.php new file mode 100644 index 0000000..2009823 --- /dev/null +++ b/libglcas/config_old.php @@ -0,0 +1,92 @@ +configPath = ""; + $this->config = ""; + } + + function loadConfig($configpath) + { + error_log("loadConfig $configpath"); + $this->configPath = $configpath; + $flt = file_get_contents($configpath); + $this->config = unserialize(base64_decode($flt)); + + + } + + function getConfigVar($var) + { + if(isset($this->config["$var"])) { + return $this->config["$var"]; + } else return false; + } + + function setConfigVar($var, $value) + { + if(is_array($this->config)) { + foreach($this->config as $vkey => $val) { + if($vkey == "$var") { + error_log("reset config of $var to $value"); + $this->config[$var] = $value; + return true; + } + } + } else error_log("config isnt array"); + + // otherwise, set it + error_log("set config of $var to $value"); + $this->config[$var] = $value; + + } + + function delConfigVar($var) + { + if(is_array($this->config)) { + foreach($this->config as $vkey => $val) { + if($vkey == "$var") { + error_log("remove config of $var to $value"); + unset($this->config[$var]); + return true; + } + } + } else error_log("config isnt array"); + } + + function saveConfig() + { + file_put_contents($this->configPath, base64_encode(serialize($this->config))); + } + + function debug() + { + echo "
";
+		echo "path: ".$this->configPath."\n";
+		print_r($this->config);
+		echo "
"; + } + + private $configPath; + private $config; + +} + +function glcas_getWebConfigPath() +{ + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + + // if you wish to add more places to find webconfig, add them here. + $configpath = false; + if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) return realpath($WEB_ROOT_FS."/../var/glcas/webconfig"); + if(file_exists("/var/lib/glcas/webconfig")) return realpath("/var/lib/glcas/webconfig"); + if(file_exists("/var/run/glcas/webconfig")) return realpath("/var/run/glcas/webconfig"); + + return $configpath; + //return false; +} + + +?> \ No newline at end of file -- 1.7.0.4