fix bug du send_bug qui ouvre une page inexistante sur xnet
[platal.git] / include / globals.inc.php.in
CommitLineData
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 22class 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
d941feeb 40 var $locale;
1a013db7 41 var $timezone;
d941feeb 42
0337d704 43 function PlatalGlobals($sess)
44 {
72542de0 45 $this->session = $sess;
46
47 $base = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
f5c2e9c6 48 $this->baseurl = trim($base.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
67952900 49 $this->spoolroot = dirname(dirname(__FILE__));
0337d704 50
ea6398d1 51 $this->read_config();
52
53 $this->dbconnect();
54 $this->setlocale();
f1ca33de 55 }
56
d941feeb 57 function read_ini_file($filename)
0337d704 58 {
d941feeb 59 $array = parse_ini_file($filename, true);
0337d704 60 if (!is_array($array)) {
61 return;
62 }
d941feeb 63 foreach ($array as $cat => $conf) {
0337d704 64 $c = strtolower($cat);
d941feeb 65 foreach ($conf as $k => $v) {
1a013db7 66 if ($c == 'core' && property_exists($this, $k)) {
d941feeb 67 $this->$k=$v;
0337d704 68 } else {
d941feeb 69 if (!isset($this->$c)) {
70 $this->$c = new stdClass;
71 }
72 $this->$c->$k = $v;
0337d704 73 }
74 }
75 }
76 }
77
d941feeb 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
ea6398d1 85 function dbconnect()
86 {
87 @mysql_connect($this->dbhost, $this->dbuser, $this->dbpwd);
88 @mysql_select_db($this->dbdb);
89 }
90
0337d704 91 function setlocale()
92 {
d941feeb 93 setlocale(LC_MESSAGES, $this->locale);
94 setlocale(LC_TIME, $this->locale);
95 setlocale(LC_CTYPE, $this->locale);
1a013db7 96 date_default_timezone_set($this->timezone);
0337d704 97 }
ea6398d1 98
99 function asso($key=null)
100 {
101 static $aid = null;
102
103 if (is_null($aid)) {
104 $gp = Get::v('n');
105 $gp = substr($gp, 0, strpos($gp, '/'));
106
107 if ($gp) {
108 $res = XDB::query('SELECT a.*, d.nom AS domnom
109 FROM groupex.asso AS a
110 LEFT JOIN groupex.dom AS d ON d.id = a.dom
111 WHERE diminutif = {?}', $gp);
112 if (!($aid = $res->fetchOneAssoc())) {
113 $aid = array();
114 }
115 } else {
116 $aid = array();
117 }
118 }
119 if (empty($key)) {
120 return $aid;
121 } elseif ( isset($aid[$key]) ) {
122 return $aid[$key];
123 } else {
124 return null;
125 }
126 }
0337d704 127}
128
0337d704 129// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
130?>