| 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 | var $dbcharset = 'utf8'; |
| 36 | |
| 37 | /** paths */ |
| 38 | var $baseurl; |
| 39 | var $spoolroot; |
| 40 | |
| 41 | var $locale; |
| 42 | var $timezone; |
| 43 | |
| 44 | function PlatalGlobals($sess) |
| 45 | { |
| 46 | $this->session = $sess; |
| 47 | |
| 48 | $base = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; |
| 49 | $this->baseurl = trim($base.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/'); |
| 50 | $this->spoolroot = dirname(dirname(__FILE__)); |
| 51 | |
| 52 | $this->read_config(); |
| 53 | $this->setlocale(); |
| 54 | } |
| 55 | |
| 56 | function read_ini_file($filename) |
| 57 | { |
| 58 | $array = parse_ini_file($filename, true); |
| 59 | if (!is_array($array)) { |
| 60 | return; |
| 61 | } |
| 62 | foreach ($array as $cat => $conf) { |
| 63 | $c = strtolower($cat); |
| 64 | foreach ($conf as $k => $v) { |
| 65 | if ($c == 'core' && property_exists($this, $k)) { |
| 66 | $this->$k=$v; |
| 67 | } else { |
| 68 | if (!isset($this->$c)) { |
| 69 | $this->$c = new stdClass; |
| 70 | } |
| 71 | $this->$c->$k = $v; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | function read_config() |
| 78 | { |
| 79 | $this->read_ini_file($this->spoolroot.'/configs/platal.ini'); |
| 80 | |
| 81 | $this->read_ini_file($this->spoolroot.'/configs/platal.conf'); |
| 82 | } |
| 83 | |
| 84 | function setlocale() |
| 85 | { |
| 86 | setlocale(LC_MESSAGES, $this->locale); |
| 87 | setlocale(LC_TIME, $this->locale); |
| 88 | setlocale(LC_CTYPE, $this->locale); |
| 89 | date_default_timezone_set($this->timezone); |
| 90 | } |
| 91 | |
| 92 | function asso($key=null) |
| 93 | { |
| 94 | static $aid = null; |
| 95 | |
| 96 | if (is_null($aid)) { |
| 97 | $gp = Get::v('n'); |
| 98 | if ($p = strpos($gp, '/')) { |
| 99 | $gp = substr($gp, 0, $p); |
| 100 | } |
| 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 | } |
| 122 | } |
| 123 | |
| 124 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 125 | ?> |