0337d704 |
1 | <?php |
2 | /*************************************************************************** |
50a40a33 |
3 | * Copyright (C) 2003-2006 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 | { |
0337d704 |
24 | var $session; |
0337d704 |
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'; |
72542de0 |
35 | |
0337d704 |
36 | /** paths */ |
72542de0 |
37 | var $baseurl; |
38 | var $spoolroot; |
0337d704 |
39 | |
40 | function PlatalGlobals($sess) |
41 | { |
72542de0 |
42 | $this->session = $sess; |
43 | |
44 | $base = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; |
f5c2e9c6 |
45 | $this->baseurl = trim($base.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/'); |
67952900 |
46 | $this->spoolroot = dirname(dirname(__FILE__)); |
0337d704 |
47 | |
ea6398d1 |
48 | $this->read_config(); |
49 | |
50 | $this->dbconnect(); |
51 | $this->setlocale(); |
f1ca33de |
52 | } |
53 | |
0337d704 |
54 | function read_config() |
55 | { |
a4eaaa7b |
56 | $array = parse_ini_file($this->spoolroot.'/configs/platal.ini', true); |
57 | foreach ($array as $cat => $conf) { |
58 | $c = strtolower($cat); |
59 | foreach ($conf as $k => $v) { |
60 | $this->$c->$k = $v; |
61 | } |
62 | } |
63 | |
72542de0 |
64 | $array = parse_ini_file($this->spoolroot.'/configs/platal.conf', true); |
0337d704 |
65 | if (!is_array($array)) { |
66 | return; |
67 | } |
68 | |
69 | foreach ($array as $cat=>$conf) { |
70 | $c = strtolower($cat); |
71 | foreach ($conf as $key=>$val) { |
72 | if ($c == 'core' && isset($this->$key)) { |
73 | $this->$key=$val; |
74 | } else { |
75 | $this->$c->$key = $val; |
76 | } |
77 | } |
78 | } |
79 | } |
80 | |
ea6398d1 |
81 | function dbconnect() |
82 | { |
83 | @mysql_connect($this->dbhost, $this->dbuser, $this->dbpwd); |
84 | @mysql_select_db($this->dbdb); |
85 | } |
86 | |
0337d704 |
87 | function setlocale() |
88 | { |
bd19fd65 |
89 | setlocale(LC_MESSAGES, $this->core->locale); |
90 | setlocale(LC_TIME, $this->core->locale); |
91 | setlocale(LC_CTYPE, $this->core->locale); |
0337d704 |
92 | } |
ea6398d1 |
93 | |
94 | function asso($key=null) |
95 | { |
96 | static $aid = null; |
97 | |
98 | if (is_null($aid)) { |
99 | $gp = Get::v('n'); |
100 | $gp = substr($gp, 0, strpos($gp, '/')); |
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 | |
0337d704 |
124 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
125 | ?> |