Moving to GitHub.
[platal.git] / classes / platalglobals.php.in
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2014 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 extends PlGlobals
23 {
24 const DEBUG_NOCACHE = DEBUG_USERBASE;
25
26 /** The x.org version */
27 public $version = '@VERSION@';
28
29 /** db params */
30 public $dbdb = null;
31 public $dbprefix = '';
32 public $dbhost = 'localhost';
33 public $dbuser = null;
34 public $dbpwd = null;
35 public $dbcharset = 'utf8';
36
37 /** default skin */
38 public $skin;
39 public $register_skin;
40
41 public function __construct()
42 {
43 parent::__construct(array('platal.ini', 'platal.conf'));
44 if (isset($GLOBALS['IS_XNET_SITE'])) {
45 $this->core->sitename = 'Polytechnique.net';
46 }
47 }
48
49 public function init()
50 {
51 $this->bootstrap(array('NbIns'), array($this, 'updateNbIns'));
52 $this->bootstrap(array('NbValid'), array($this, 'updateNbValid'));
53 }
54
55 public function asso($key = null)
56 {
57 static $fetched = false;
58 static $aid = null;
59
60 if (isset($GLOBALS['IS_XNET_SITE']) && !$fetched) {
61 $gp = Get::v('n');
62 if ($p = strpos($gp, '/')) {
63 $gp = substr($gp, 0, $p);
64 }
65
66 $aid = Group::get($gp);
67 $fetched = true;
68 }
69 if (empty($key)) {
70 return $aid;
71 } elseif (isset($aid->$key) ) {
72 return $aid->$key;
73 } else {
74 return null;
75 }
76 }
77
78 public function updateNbIns()
79 {
80 $count = XDB::rawFetchOneCell("SELECT COUNT(*)
81 FROM accounts AS a
82 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
83 INNER JOIN profiles AS p ON (ap.pid = p.pid)
84 WHERE a.state = 'active' AND p.deathdate IS NULL");
85 $this->changeDynamicConfig(array('NbIns' => $count));
86 }
87
88 public function updateNbValid()
89 {
90 $res = XDB::query("SELECT COUNT(*)
91 FROM requests");
92 $this->changeDynamicConfig(array('NbValid' => $res->fetchOneCell()));
93 }
94
95 public function cacheEnabled()
96 {
97 return ($this->debug & self::DEBUG_NOCACHE) == 0;
98 }
99 }
100
101 /******************************************************************************
102 * Dynamic configuration update/edition stuff
103 *****************************************************************************/
104
105 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
106 ?>