68cc1644818c64e142bd1dc8c518d4bc510e28f4
[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 var $session;
25
26 /** The x.org version */
27 var $version = '@VERSION@';
28 var $debug = 0;
29
30 /** db params */
31 var $dbdb = 'x4dat';
32 var $dbhost = 'localhost';
33 var $dbuser = 'x4dat';
34 var $dbpwd = 'x4dat';
35
36 /** paths */
37 var $baseurl;
38 var $spoolroot;
39
40 var $locale;
41 var $timezone;
42
43 function PlatalGlobals($sess)
44 {
45 $this->session = $sess;
46
47 $base = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
48 $this->baseurl = trim($base.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
49 $this->spoolroot = dirname(dirname(__FILE__));
50
51 $this->read_config();
52
53 $this->dbconnect();
54 $this->setlocale();
55 }
56
57 function read_ini_file($filename)
58 {
59 $array = parse_ini_file($filename, true);
60 if (!is_array($array)) {
61 return;
62 }
63 foreach ($array as $cat => $conf) {
64 $c = strtolower($cat);
65 foreach ($conf as $k => $v) {
66 if ($c == 'core' && property_exists($this, $k)) {
67 $this->$k=$v;
68 } else {
69 if (!isset($this->$c)) {
70 $this->$c = new stdClass;
71 }
72 $this->$c->$k = $v;
73 }
74 }
75 }
76 }
77
78 function read_config()
79 {
80 $this->read_ini_file($this->spoolroot.'/configs/platal.ini');
81
82 $this->read_ini_file($this->spoolroot.'/configs/platal.conf');
83 }
84
85 function dbconnect()
86 {
87 XDB::$connec = @mysqli_connect($this->dbhost, $this->dbuser, $this->dbpwd);
88 @mysqli_select_db(XDB::$connec, $this->dbdb);
89 mysqli_set_charset(XDB::$connec, 'utf8');
90 }
91
92 function setlocale()
93 {
94 setlocale(LC_MESSAGES, $this->locale);
95 setlocale(LC_TIME, $this->locale);
96 setlocale(LC_CTYPE, $this->locale);
97 date_default_timezone_set($this->timezone);
98 }
99
100 function asso($key=null)
101 {
102 static $aid = null;
103
104 if (is_null($aid)) {
105 $gp = Get::v('n');
106 if ($p = strpos($gp, '/')) {
107 $gp = substr($gp, 0, $p);
108 }
109
110 if ($gp) {
111 $res = XDB::query('SELECT a.*, d.nom AS domnom
112 FROM groupex.asso AS a
113 LEFT JOIN groupex.dom AS d ON d.id = a.dom
114 WHERE diminutif = {?}', $gp);
115 if (!($aid = $res->fetchOneAssoc())) {
116 $aid = array();
117 }
118 } else {
119 $aid = array();
120 }
121 }
122 if (empty($key)) {
123 return $aid;
124 } elseif ( isset($aid[$key]) ) {
125 return $aid[$key];
126 } else {
127 return null;
128 }
129 }
130 }
131
132 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
133 ?>