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

View file

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