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