one less global

git-svn-id: file:///home/shish/svn/shimmie2/trunk@389 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-07-28 13:53:31 +00:00
parent f26bd31f7a
commit 86561be3ec
2 changed files with 13 additions and 14 deletions

View File

@ -1,28 +1,27 @@
<?php <?php
class Config { class Config {
var $values = array(); var $values = array();
var $database = null;
public function Config() { public function Config($database) {
global $database; $this->database = $database;
$this->values = $database->db->GetAssoc("SELECT name, value FROM config"); $this->values = $this->database->db->GetAssoc("SELECT name, value FROM config");
} }
public function save($name=null) { public function save($name=null) {
global $database;
if(is_null($name)) { if(is_null($name)) {
foreach($this->values as $name => $value) { foreach($this->values as $name => $value) {
// does "or update" work with sqlite / postgres? // does "or update" work with sqlite / postgres?
$database->db->StartTrans(); $this->database->db->StartTrans();
$database->Execute("DELETE FROM config WHERE name = ?", array($name)); $this->database->Execute("DELETE FROM config WHERE name = ?", array($name));
$database->Execute("INSERT INTO config VALUES (?, ?)", array($name, $value)); $this->database->Execute("INSERT INTO config VALUES (?, ?)", array($name, $value));
$database->db->CommitTrans(); $this->database->db->CommitTrans();
} }
} }
else { else {
$database->db->StartTrans(); $this->database->db->StartTrans();
$database->Execute("DELETE FROM config WHERE name = ?", array($name)); $this->database->Execute("DELETE FROM config WHERE name = ?", array($name));
$database->Execute("INSERT INTO config VALUES (?, ?)", array($name, $this->values[$name])); $this->database->Execute("INSERT INTO config VALUES (?, ?)", array($name, $this->values[$name]));
$database->db->CommitTrans(); $this->database->db->CommitTrans();
} }
} }

View File

@ -33,7 +33,7 @@ foreach($files as $filename) {
$database = new Database(); $database = new Database();
$database->db->fnExecute = '_count_execs'; $database->db->fnExecute = '_count_execs';
$config = new Config(); $config = new Config($database);
$_theme = $config->get_string("theme", "default"); $_theme = $config->get_string("theme", "default");
require_once "themes/$_theme/page.class.php"; require_once "themes/$_theme/page.class.php";
require_once "themes/$_theme/layout.class.php"; require_once "themes/$_theme/layout.class.php";