<?
class config {
	function config() {
		global $db, $settings;
		$all = $db->GetAll("SELECT * FROM ".$settings->config['settings_tablename']);
		foreach ($all as $value) {
			$this->settings[$value['var']] = $value['val'];
		}
		$this->settings['adminemail'] = "";
	}
	
	function set($var, $val) {
		global $db, $settings;
		$where = false;
		if ($val) {
			$recordExists = $db->GetOne("SELECT COUNT(*) FROM ".$settings->config['settings_tablename']." WHERE var = '".$var."'");
			if (!$recordExists) {
				$db->query("INSERT INTO ".$settings->config['settings_tablename']." SET val='".$val."', var='".$var."'");
			} else {
				$db->query("UPDATE ".$settings->config['settings_tablename']." SET val='".$val."' WHERE var='".$var."'");
			}
		} else {
			$rs = $db->query("DELETE FROM ".$settings->config['settings_tablename']." WHERE var = '".$var."'");
		}
		$this->settings[$var] = $val;
		return $rs;
	}
}
?>