Moving to GitHub.
[platal.git] / classes / platalglobals.php.in
CommitLineData
0337d704 1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 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
4a28e567 22class PlatalGlobals extends PlGlobals
0337d704 23{
5b98acfa
FB
24 const DEBUG_NOCACHE = DEBUG_USERBASE;
25
0337d704 26 /** The x.org version */
612a2d8a 27 public $version = '@VERSION@';
0337d704 28
29 /** db params */
900f65fb 30 public $dbdb = null;
00112b2e 31 public $dbprefix = '';
612a2d8a 32 public $dbhost = 'localhost';
900f65fb
FB
33 public $dbuser = null;
34 public $dbpwd = null;
612a2d8a 35 public $dbcharset = 'utf8';
72542de0 36
25962601 37 /** default skin */
38 public $skin;
39 public $register_skin;
40
47fa97fe 41 public function __construct()
0337d704 42 {
4a28e567 43 parent::__construct(array('platal.ini', 'platal.conf'));
6cd1e622
FB
44 if (isset($GLOBALS['IS_XNET_SITE'])) {
45 $this->core->sitename = 'Polytechnique.net';
46 }
14a76559
FB
47 }
48
49 public function init()
50 {
ebfdf077
FB
51 $this->bootstrap(array('NbIns'), array($this, 'updateNbIns'));
52 $this->bootstrap(array('NbValid'), array($this, 'updateNbValid'));
0337d704 53 }
ea6398d1 54
34ade5a6 55 public function asso($key = null)
ea6398d1 56 {
edcea678 57 static $fetched = false;
ea6398d1 58 static $aid = null;
59
edcea678 60 if (isset($GLOBALS['IS_XNET_SITE']) && !$fetched) {
ea6398d1 61 $gp = Get::v('n');
27ae65e3 62 if ($p = strpos($gp, '/')) {
63 $gp = substr($gp, 0, $p);
64 }
ea6398d1 65
34ade5a6 66 $aid = Group::get($gp);
edcea678 67 $fetched = true;
ea6398d1 68 }
69 if (empty($key)) {
70 return $aid;
34ade5a6
FB
71 } elseif (isset($aid->$key) ) {
72 return $aid->$key;
ea6398d1 73 } else {
74 return null;
75 }
76 }
ebfdf077 77
ebfdf077
FB
78 public function updateNbIns()
79 {
9c77b36a
SJ
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));
ebfdf077
FB
86 }
87
88 public function updateNbValid()
89 {
90 $res = XDB::query("SELECT COUNT(*)
91 FROM requests");
92 $this->changeDynamicConfig(array('NbValid' => $res->fetchOneCell()));
93 }
0337d704 94
5b98acfa
FB
95 public function cacheEnabled()
96 {
97 return ($this->debug & self::DEBUG_NOCACHE) == 0;
98 }
99}
ebfdf077
FB
100
101/******************************************************************************
102 * Dynamic configuration update/edition stuff
103 *****************************************************************************/
104
448c8cdc 105// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
0337d704 106?>