e7f9f559d606cdebc1bfb9e6f75ff0b41b8227d6
[platal.git] / include / globals.inc.php.in
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 class PlatalGlobals
23 {
24 public $session;
25
26 /** The x.org version */
27 public $version = '@VERSION@';
28 public $debug = 0;
29 public $mode = 'rw'; // 'rw' => read/write,
30 // 'r' => read/only
31 // '' => site down
32
33 /** db params */
34 public $dbdb = 'x4dat';
35 public $dbhost = 'localhost';
36 public $dbuser = 'x4dat';
37 public $dbpwd = 'x4dat';
38 public $dbcharset = 'utf8';
39
40 /** default skin */
41 public $skin;
42 public $register_skin;
43
44 /** paths */
45 public $baseurl;
46 public $spoolroot;
47
48 public $locale;
49 public $timezone;
50
51 public function __construct($sess)
52 {
53 $this->session = $sess;
54
55 $base = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
56 $this->baseurl = @trim($base.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
57 $this->spoolroot = dirname(dirname(__FILE__));
58
59 $this->read_config();
60 $this->setlocale();
61 }
62
63 private function read_ini_file($filename)
64 {
65 $array = parse_ini_file($filename, true);
66 if (!is_array($array)) {
67 return;
68 }
69 foreach ($array as $cat => $conf) {
70 $c = strtolower($cat);
71 foreach ($conf as $k => $v) {
72 if ($c == 'core' && property_exists($this, $k)) {
73 $this->$k=$v;
74 } else {
75 if (!isset($this->$c)) {
76 $this->$c = new stdClass;
77 }
78 $this->$c->$k = $v;
79 }
80 }
81 }
82 }
83
84 private function read_config()
85 {
86 $this->read_ini_file($this->spoolroot.'/configs/platal.ini');
87 $this->read_ini_file($this->spoolroot.'/configs/platal.conf');
88 }
89
90 private function setlocale()
91 {
92 setlocale(LC_MESSAGES, $this->locale);
93 setlocale(LC_TIME, $this->locale);
94 setlocale(LC_CTYPE, $this->locale);
95 date_default_timezone_set($this->timezone);
96 mb_internal_encoding("UTF-8");
97 }
98
99 public function asso($key=null)
100 {
101 static $aid = null;
102
103 if (is_null($aid)) {
104 $gp = Get::v('n');
105 if ($p = strpos($gp, '/')) {
106 $gp = substr($gp, 0, $p);
107 }
108
109 if ($gp) {
110 $res = XDB::query('SELECT a.*, d.nom AS domnom
111 FROM groupex.asso AS a
112 LEFT JOIN groupex.dom AS d ON d.id = a.dom
113 WHERE diminutif = {?}', $gp);
114 if (!($aid = $res->fetchOneAssoc())) {
115 $aid = array();
116 }
117 } else {
118 $aid = array();
119 }
120 }
121 if (empty($key)) {
122 return $aid;
123 } elseif ( isset($aid[$key]) ) {
124 return $aid[$key];
125 } else {
126 return null;
127 }
128 }
129 }
130
131 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
132 ?>