config.php

Go to the documentation of this file.
00001 <?php
00031 /* include static configuration related to the current domain */
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 //  var $_containers = array();
00101 
00107 //  var $_typedefs = array();
00108 
00114     function __construct() {
00115         /* store area id if defined in the configuration file */
00116         if (defined("ID_AREA")) { $this->areaid = ID_AREA; }
00117 
00118         /* read content type definitions */
00119 //      $res = mysql_query("SELECT * FROM contenttypes ORDER BY id");
00120 //      while ($line = mysql_fetch_assoc($res)) {
00121 //          $item = $line;
00122 //          $res2 = mysql_query("SELECT field_name, field_type, field_caption, field_edit_tips FROM contenttypedefs WHERE id = " . $line['id'] . " ORDER BY id_field");
00123 //          $item['fielddefs'] = array();
00124 //          while ($line2 =mysql_fetch_assoc($res2)) {
00125 //              $item['fielddefs'][count($item['fielddefs'])] = $line2;
00126 //          }
00127 //          mysql_free_result($res2);
00128 //          $this->_typedefs[$line['id']] = $item;
00129 //      }
00130 //      mysql_free_result($res);
00131 
00132 //      /* read container names */
00133 //      $res = mysql_query("SELECT * FROM containers");
00134 //      while ($line = mysql_fetch_assoc($res)) {
00135 //          $this->_containers[$line['description']] = $line['id'];
00136 //      }
00137 //      mysql_free_result($res);
00138 
00139         /* read configuration values */
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();    // FIXME protocol schema (http/https) should be computed
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         /* check tables if version has changed */
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);      // error handling?
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         // TODO not tested yet
00219         mysql_query("DELETE FROM config WHERE visible AND id_area = " . $this->areaid);
00220         // BUG #0001 will overwrite setting vars visibility  
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 //  function getContainerIds() {
00232 //      return $this->_containers;
00233 //  }
00234 
00240     public function getAreaId() {
00241         return $this->areaid;
00242     }
00243 }
00244 ?>

Generated on Fri Feb 22 11:19:48 2008 for CMSkey by  doxygen 1.5.3