query ("SELECT id, status FROM {prefix}config WHERE section='$section' AND name='$name'")) { if ($db['status'] != self::STATUS_SET) { $id = $db['id']; if ($set_history) { $history = new History ("config set"); $history->storeOld ($id, "config", false); } $db->query ("UPDATE {prefix}config SET value='$value', status=".self::STATUS_PRESET." WHERE id=$id"); if ($set_history) { $history->store ($id, "config", false); } self::$cache[$section][self::STATUS_PRESET][$name] = $value; } } else { $db->query ("INSERT INTO {prefix}config (value, status) VALUES ('', ".self::STATUS_ERASED.")"); $id = $db->rowid; if ($set_history) { $history = new History ("config set"); $history->storeOld ($id, "config", false); } $db->query ("UPDATE {prefix}config SET section='$section', name='$name', value='$value', status=".self::STATUS_PRESET." WHERE id=$id"); if ($set_history) { $history->store ($id, "config", false); } self::$cache[$section][self::STATUS_PRESET][$name] = $value; } } public static function checkDb () { if (self::get ("db", "version") != self::VERSION_DB) { // Datenbank nicht ok User::logout (); return false; } return true; } /** * Setzt eine Einstellung \n * Der gesetzte Wert wird nicht durch initialise überschrieben * * \param section Sektion in der gespeichert werden soll * \param name Name unter dem gespeichert werden soll * \param value Wert der gespeichert werden soll * \param set_history wenn true dann wird die Änderung in der History vermerkt, andernfalls wird kein History Eintrag erstellt */ public static function set ($section, $name, $value, $set_history=true) { $section = Database::escape ($section); switch ($section) { case "config": self::get ("config"); switch ($name) { case "documentUrl": self::$config['document_url'] = $value; break; case "configName": Base::session_open (); $_SESSION['cms']['config_name'] = $value; Base::session_close (); self::$config = null; break; default: self::$config[$name] = $value; } break; default: $db = new Database (); $name = Database::escape ($name); $value = Database::escape ($value); if ($db->query ("SELECT id FROM {prefix}config WHERE section='$section' AND name='$name'")) { $id = $db['id']; } else { $db->query ("INSERT INTO {prefix}config (value, status) VALUES ('', ".self::STATUS_ERASED.")"); $id = $db->rowid; } if ($set_history) { $history = new History ("config set"); $history->storeOld ($id, "config", false); } $db->query ("UPDATE {prefix}config SET section='$section', name='$name', value='$value', status=".self::STATUS_SET." WHERE id=$id"); self::$cache[$section][self::STATUS_SET][$name] = $value; if ($set_history) { $history->store ($id, "config", false); } } } /** * Liefert den Wert einer Einstellung * * \param section Sektion in der gesucht werden soll ('config' lifert werte aus der Konfigurationsdatei) * \param name Name unter dem gesucht werden soll * \param defaultvalue Wert der zurückgeliefert werden soll, wenn die gesuchte Einstellun nicht existiert * * \return Wert der gesuchten Einstellung, oder defaultvalue wenn bisher nicht gesetzt */ public static function get ($section, $name="", $defaultvalue="", $initialise=false) { switch ($section) { case "config": switch ($name) { case "configFile": return realpath (dirname (__FILE__) . "/../") . "/config.inc.php"; case "configName": Base::session_init (); return isset ($_SESSION['cms']['config_name']) ? $_SESSION['cms']['config_name'] : "cms"; } if (!self::$config) { // Config Datei einlesen $config = array (); @include self::get ('config', 'configFile'); $configName = self::get ('config', 'configName'); self::$config = isset ($config[$configName]) ? $config[$configName] : Array (); self::$config['document_root'] = !empty (self::$config['document_root']) ? self::$config['document_root'] : realpath ($_SERVER['DOCUMENT_ROOT']); self::$config['cms_path'] = !empty (self::$config['cms_path']) ? self::$config['cms_path'] : str_replace ('\\', '/', (strstr(__FILE__, self::$config['document_root']) ? str_replace (self::$config['document_root'], '', realpath (dirname(__FILE__)."/../")) : "cms")."/"); self::$config['file_path'] = !empty (self::$config['file_path']) ? self::$config['file_path'] : "/files/"; self::$config['log_file'] = !empty (self::$config['log_file']) ? self::$config['log_file'] : "/cms_log.txt"; self::$config['document_url'] = ($_SERVER['PHP_SELF'] . (!empty ($_SERVER['QUERY_STRING']) ? ("?" . $_SERVER['QUERY_STRING']) : "")); } switch ($name) { case "documentUrl": return self::$config['document_url']; case "documentRoot": return self::$config['document_root']; case "cmsPath": return self::$config['cms_path']; case "filePathRel": return self::$config['file_path']; case "filePath": return self::$config['document_root'] . self::$config['file_path']; case "logfile": return self::$config['document_root'] . self::$config['log_file']; default: return isset (self::$config[$name]) ? self::$config[$name] : $defaultvalue; } default: if (!isset(self::$cache[$section])) { self::$cache[$section] = array(); $section = Database::escape ($section); $db = new Database ("", null, true); if ($db->query ("SELECT name, value, status FROM {prefix}config WHERE section='$section' AND status!=".self::STATUS_ERASED, true)) { foreach ($db as $row) { self::$cache[$section][$row['status']][$row['name']] = $row['value']; } } } if (isset(self::$cache[$section])) { if ($name) { if (isset(self::$cache[$section][self::STATUS_SET][$name])) { return self::$cache[$section][self::STATUS_SET][$name]; } else if (isset(self::$cache[$section][self::STATUS_PRESET][$name]) && (!$initialise || self::$cache[$section][self::STATUS_PRESET][$name] == $defaultvalue)) { return self::$cache[$section][self::STATUS_PRESET][$name]; } if ($initialise) { self::initialise ($section, $name, $defaultvalue, false); } return $defaultvalue; } else { $values = ($defaultvalue) ? $defaultvalue : Array (); if (isset(self::$cache[$section][self::STATUS_SET])) { $values = array_merge($values, self::$cache[$section][self::STATUS_SET]); } if (isset(self::$cache[$section][self::STATUS_PRESET]) && !$initialise) { $values = array_merge($values, self::$cache[$section][self::STATUS_PRESET]); } if ($initialise && $defaultvalue) { foreach ($values as $name => $value) { self::initialise ($section, $name, $value, false); } } return $values; } } } } /** * Löscht eine Einstellung * * \param section Sektion in der gelelöscht werden soll ('config' lifert werte aus der Konfigurationsdatei) * \param name Name der gelelöscht werden soll * \param set_history wenn true dann wird die Änderung in der History vermerkt, andernfalls wird kein History Eintrag erstellt */ public static function del ($section, $name, $set_history=true) { $section = Database::escape ($section); switch ($section) { case "config": switch ($name) { case "documentUrl": self::set ('config', 'documentUrl', ($_SERVER['PHP_SELF'] . (($_SERVER['QUERY_STRING']) ? ("?" . $_SERVER['QUERY_STRING']) : ""))); break; case "configName": self::set ('config', 'configName', "cms"); break; } break; default: $db = new Database (); $name = Database::escape ($name); if ($db->query ("SELECT id FROM {prefix}config WHERE section='$section' AND name='$name'")) { $id = $db['id']; if ($set_history) { $history = new History ("config del"); $history->storeOld ($id, "config", false); } $db->query ("UPDATE {prefix}config SET status='".self::STATUS_ERASED."' WHERE id=$id"); unset(self::$cache[$section][self::STATUS_SET][$name]); unset(self::$cache[$section][self::STATUS_PRESET][$name]); if ($set_history) { $history->store ($id, "config", false); } } } } /** * Liefert alle IDs zur angegebenen Einstellung \n * Wird z.B. zum suchen nach History Einträgen zu den Einstellungen benötigt * * \param section Sektion in der gesucht werden soll ('config' lifert werte aus der Konfigurationsdatei) * \param name Name unter dem gesucht werden soll * * \return Array mit IDs zum gesuchten Bereich */ public static function getIds ($section, $name="") { $section = Database::escape ($section); $ids = array (); switch ($section) { case "config": break; default: // Aus DB lesen $name = Database::escape ($name); $db = new Database (); if ($db->query ("SELECT id FROM {prefix}config WHERE section='$section' AND ('$name'='' OR name='$name') ORDER BY id DESC")) { foreach ($db as $row) { $ids[] = $row['id']; } } } return $ids; } } /** * Speichern von Daten aus der Website heraus \n * Abfragen und speichern von Werten * * \author Claus Muus * \date 2007-11-15 */ class Storage { private static $group = "site"; //< section unter der in den Settings gespeichert werden soll /** * setzt die Gruppe in der gespeichert werden soll * * \param group Gruppe in der gespeichert werden soll */ public static function setGroup ($name="") { self::$group = "site" . ($name ? "/$name" : ""); } /** * speichert einen Wert (Maximal 4kB pro eintrag) * * \param name Name unter dem gespeichert werden soll * \param value Wert der gespeichert werden soll. Er darf von beliebigem Typ sein */ public static function set ($name, $value) { Setting::set (self::$group, $name, serialize ($value), false); } /** * holt einen gespeicherten Wert * * \param name Name unter dem der Wert gespeichert wurde, oder alle Werte wenn kein Name angegeben wurde * \param defaultvalue Wert der zurückgeliefert werden soll, wenn bisher nichts gespeichert war */ public static function get ($name="", $defaultvalue="") { if (!$name) { $values = array (); foreach (Setting::get (self::$group, $name) as $key => $value) { $values[$key] = unserialize ($value); } } else { $values = unserialize (Setting::get (self::$group, $name, serialize ($defaultvalue))); } return $values; } } ?>