00001 <?php
00031
00032 include("/etc/cmskey/config." . $_SERVER['HTTP_HOST'] . ".php");
00033
00077 class Config {
00078 const CMSKEY_VERSION = "0.9.5-devel";
00079 const DEFAULT_AREA_ID = 1;
00080
00086 private $areaid = Config::DEFAULT_AREA_ID;
00087
00093 private $config = array();
00094
00100
00101
00107
00108
00114 function __construct() {
00115
00116 if (defined("ID_AREA")) { $this->areaid = ID_AREA; }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 $this->initConfig();
00141 }
00142
00148 private function getHostName() {
00149 return (isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']);
00150 }
00151
00159 public function getBaseURL() {
00160 $url = "http://" . $this->getHostName();
00161 if (substr($url, strlen($url) - 1, 1) <> "/") { $url .= "/"; }
00162 return $url;
00163 }
00164
00172 public function initConfig($id_area = 0) {
00173 if ($id_area > 0) { $this->areaid = $id_area; }
00174
00175 $res = mysql_query("SELECT * FROM config WHERE id_area = " . $this->areaid);
00176 while ($line = mysql_fetch_assoc($res)) {
00177 $this->config[$line['name']] = $line['value'];
00178 }
00179 mysql_free_result($res);
00180
00181
00182 if ($this->config['LAST_VER_CHECKED'] <> Config::CMSKEY_VERSION) {
00183 global $db;
00184 if ($db->checkTables()) {
00185 $this->config['LAST_VER_CHECKED'] = Config::CMSKEY_VERSION;
00186 $sql = "UPDATE config SET value = '" . Config::CMSKEY_VERSION . "' WHERE (name = 'LAST_VER_CHECKED') AND (id_area = " . $this->areaid . ")";
00187 mysql_query($sql);
00188 }
00189 }
00190 }
00191
00198 public function getConfig($varname) {
00199 return $this->config[$varname];
00200 }
00201
00208 public function setConfig($varname, $value) {
00209 $this->config[$varname] = $value;
00210 }
00211
00217 public function saveConfig() {
00218
00219 mysql_query("DELETE FROM config WHERE visible AND id_area = " . $this->areaid);
00220
00221 foreach ($this->config AS $name => $value) {
00222 mysql_query("INSERT INTO config (id_area, name, value, visible) VALUES (" . $this->areaid . ", '" . $name . "', '" . $value . "', 1)");
00223 }
00224 }
00225
00231
00232
00233
00234
00240 public function getAreaId() {
00241 return $this->areaid;
00242 }
00243 }
00244 ?>