Moving to GitHub.
[platal.git] / classes / platalglobals.php.in
index 43140c6..6bd1518 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
 
 class PlatalGlobals extends PlGlobals
 {
+    const DEBUG_NOCACHE = DEBUG_USERBASE;
+
     /** The x.org version */
     public $version = '@VERSION@';
 
     /** db params */
-    public $dbdb               = 'x4dat';
+    public $dbdb               = null;
+    public $dbprefix           = '';
     public $dbhost             = 'localhost';
-    public $dbuser             = 'x4dat';
-    public $dbpwd              = 'x4dat';
+    public $dbuser             = null;
+    public $dbpwd              = null;
     public $dbcharset          = 'utf8';
 
     /** default skin */
@@ -38,6 +41,9 @@ class PlatalGlobals extends PlGlobals
     public function __construct()
     {
         parent::__construct(array('platal.ini', 'platal.conf'));
+        if (isset($GLOBALS['IS_XNET_SITE'])) {
+            $this->core->sitename = 'Polytechnique.net';
+        }
     }
 
     public function init()
@@ -46,47 +52,37 @@ class PlatalGlobals extends PlGlobals
         $this->bootstrap(array('NbValid'), array($this, 'updateNbValid'));
     }
 
-    public function asso($key=null)
+    public function asso($key = null)
     {
+        static $fetched = false;
         static $aid = null;
 
-        if (is_null($aid)) {
+        if (isset($GLOBALS['IS_XNET_SITE']) && !$fetched) {
             $gp = Get::v('n');
             if ($p = strpos($gp, '/')) {
                 $gp = substr($gp, 0, $p);
             }
 
-            if ($gp) {
-                $res = XDB::query('SELECT  a.*, d.nom AS domnom,
-                                           FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc,
-                                           FIND_IN_SET(\'notif_unsub\', a.flags) AS notif_unsub
-                                     FROM  groupex.asso AS a
-                                LEFT JOIN  groupex.dom  AS d ON d.id = a.dom
-                                    WHERE  diminutif = {?}', $gp);
-                if (!($aid = $res->fetchOneAssoc())) {
-                    $aid = array();
-                }
-            } else {
-                $aid = array();
-            }
+            $aid = Group::get($gp);
+            $fetched = true;
         }
         if (empty($key)) {
             return $aid;
-        } elseif ( isset($aid[$key]) ) {
-            return $aid[$key];
+        } elseif (isset($aid->$key) ) {
+            return $aid->$key;
         } else {
             return null;
         }
     }
 
-
     public function updateNbIns()
     {
-        $res = XDB::query("SELECT  COUNT(*)
-                             FROM  auth_user_md5
-                            WHERE  perms IN ('admin','user') AND deces=0");
-        $cnt = $res->fetchOneCell();
-        $this->changeDynamicConfig(array('NbIns' => $cnt));
+        $count = XDB::rawFetchOneCell("SELECT  COUNT(*)
+                                         FROM  accounts         AS a
+                                   INNER JOIN  account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
+                                   INNER JOIN  profiles         AS p  ON (ap.pid = p.pid)
+                                        WHERE  a.state = 'active' AND p.deathdate IS NULL");
+        $this->changeDynamicConfig(array('NbIns' => $count));
     }
 
     public function updateNbValid()
@@ -95,12 +91,16 @@ class PlatalGlobals extends PlGlobals
                              FROM  requests");
         $this->changeDynamicConfig(array('NbValid' => $res->fetchOneCell()));
     }
-}
 
+    public function cacheEnabled()
+    {
+        return ($this->debug & self::DEBUG_NOCACHE) == 0;
+    }
+}
 
 /******************************************************************************
  * Dynamic configuration update/edition stuff
  *****************************************************************************/
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>