Improves Banana profile form behavious and use FlagSet to store the flags.
[platal.git] / include / globals.inc.php.in
index b511006..f052c6b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -43,6 +43,7 @@ class PlatalGlobals
 
     /** paths */
     public $baseurl;
+    public $baseurl_http;
     public $spoolroot;
 
     public $locale;
@@ -56,7 +57,8 @@ class PlatalGlobals
         $this->read_config();
         if (isset($_SERVER) && isset($_SERVER['SERVER_NAME'])) {
             $base = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
-            $this->baseurl   = @trim($base.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
+            $this->baseurl      = @trim($base    .$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
+            $this->baseurl_http = @trim('http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
         }
 
         $this->setlocale();
@@ -87,9 +89,11 @@ class PlatalGlobals
     {
         $this->read_ini_file($this->spoolroot.'/configs/platal.ini');
         $this->read_ini_file($this->spoolroot.'/configs/platal.conf');
-        $this->read_ini_file($this->spoolroot.'/spool/conf/platal.dynamic.conf');
+        if (file_exists($this->spoolroot.'/spool/conf/platal.dynamic.conf')) {
+            $this->read_ini_file($this->spoolroot.'/spool/conf/platal.dynamic.conf');
+        }
     }
-    
+
     /** Writes an ini file separated in categories
      * @param filename the name of the file to write (overwrite existing)
      * @param categories an array of categories (array of keys and values)
@@ -110,7 +114,7 @@ class PlatalGlobals
         fwrite($f, '; vim:set syntax=dosini foldmethod=marker:'."\n");
         fclose($f);
     }
-    
+
     /** Change dynamic config file
      * @param conf array of keys and values to add or replace
      * @param category name of category to change
@@ -121,7 +125,11 @@ class PlatalGlobals
     public function change_dynamic_config($conf, $category = 'Core')
     {
         $dynamicfile = $this->spoolroot.'/spool/conf/platal.dynamic.conf';
-        $array = parse_ini_file($dynamicfile, true);
+        if (file_exists($dynamicfile)) {
+            $array = parse_ini_file($dynamicfile, true);
+        } else {
+            $array = null;
+        }
         if (!is_array($array)) {
             // dynamic conf is empty
             $array = array($category => $conf);
@@ -165,6 +173,21 @@ class PlatalGlobals
         $this->read_ini_file($dynamicfile);
     }
 
+    public function bootstrap($conf, $callback, $category = 'Core')
+    {
+        $bootstrap = false;
+        $category = strtolower($category);
+        foreach ($conf as $key) {
+            if (!isset($this->$category->$key)) {
+                $bootstrap = true;
+                break;
+            }
+        }
+        if ($bootstrap) {
+            call_user_func($callback);
+        }
+    }
+
     private function setlocale()
     {
         setlocale(LC_MESSAGES, $this->locale);
@@ -185,7 +208,9 @@ class PlatalGlobals
             }
 
             if ($gp) {
-                $res = XDB::query('SELECT  a.*, d.nom AS domnom, FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc
+                $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);