Convert miniwiki of the freetext to text in the vcards.
[platal.git] / include / banana / forum.inc.php
index 9dc0291..3e14a78 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   *
@@ -44,11 +44,15 @@ class ForumsBanana extends Banana
         if (S::has_perms()) {
             Banana::$msgshow_mimeparts[] = 'source';
         }
-        Banana::$debug_nntp = ($globals->debug & 1);
+        Banana::$debug_nntp = ($globals->debug & DEBUG_BT);
+        Banana::$debug_smarty = ($globals->debug & DEBUG_SMARTY);
         if (!S::v('core_rss_hash')) {
             Banana::$feed_active = false;
         }
-        parent::__construct($params);
+        parent::__construct($params, 'NNTP', 'PlatalBananaPage');
+        if (@$params['action'] == 'profile') {
+            Banana::$action = 'profile';
+        }
     }
 
     public function run()
@@ -64,35 +68,40 @@ class ForumsBanana extends Banana
 
         // Get user profile from SQL
         $req = XDB::query("SELECT  nom, mail, sig,
-                                   FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
+                                   FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags),
+                                   tree_unread, tree_read
                              FROM  {$globals->banana->table_prefix}profils
                             WHERE  uid={?}", S::i('uid'));
-        if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
+        if (!(list($nom, $mail, $sig, $disp, $maj, $unread, $read) = $req->fetchOneRow())) {
             $nom  = S::v('prenom')." ".S::v('nom');
-            $mail = S::v('forlife')."@polytechnique.org";
+            $mail = S::v('forlife')."@" . $globals->mail->domain;
             $sig  = $nom." (".S::v('promo').")";
             $disp = 0;
             $maj  = 1;
+            $unread = 'o';
+            $read   = 'dg';
         }
         if ($maj) {
             $time = time();
         }
 
         // Build user profile
-        $req = XDB::query("      
-                 SELECT  nom     
+        $req = XDB::query("
+                 SELECT  nom
                    FROM  {$globals->banana->table_prefix}abos
               LEFT JOIN  {$globals->banana->table_prefix}list ON list.fid=abos.fid
                   WHERE  uid={?}", S::i('uid'));
         Banana::$profile['headers']['From']         = "$nom <$mail>";
-        Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
+        Banana::$profile['headers']['Organization'] = make_Organization();
         Banana::$profile['signature']               = $sig;
         Banana::$profile['display']                 = $disp;
         Banana::$profile['autoup']                  = $maj;
         Banana::$profile['lastnews']                = S::v('banana_last');
         Banana::$profile['subscribe']               = $req->fetchColumn();
+        Banana::$tree_unread = $unread;
+        Banana::$tree_read = $read;
 
-        // Update the "unread limit" 
+        // Update the "unread limit"
         if (!is_null($time)) {
             XDB::execute("UPDATE  auth_user_quick
                              SET  banana_last = FROM_UNIXTIME({?})
@@ -104,19 +113,24 @@ class ForumsBanana extends Banana
             Banana::$page->killPage('forums');
             Banana::$page->killPage('subscribe');
             Banana::$spool_boxlist = false;
-        } else {            
+        } else {
             // Register custom Banana links and tabs
             if (!Banana::$profile['autoup']) {
                 Banana::$page->registerAction('<a href=\'javascript:dynpostkv("'
                                     . $platal->path . '", "updateall", ' . time() . ')\'>'
                                     . 'Marquer tous les messages comme lus'
                                     . '</a>', array('forums', 'thread', 'message'));
-            }   
+            }
             Banana::$page->registerPage('profile', 'Préférences', null);
         }
 
-        // Run Banana
-        return parent::run();
+        // Run Bananai
+        if (Banana::$action == 'profile') {
+            Banana::$page->run();
+            return $this->action_updateProfile();
+        } else {
+            return parent::run();
+        }
     }
 
     public function post($dest, $reply, $subject, $body)
@@ -129,7 +143,7 @@ class ForumsBanana extends Banana
                             WHERE  a.alias = {?}', $this->forlife);
         list($nom, $prenom, $promo, $bestalias) = $res->fetchOneRow();
         Banana::$profile['headers']['From']         = "$prenom $nom ($promo) <$bestalias@{$globals->mail->domain}>";
-        Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
+        Banana::$profile['headers']['Organization'] = make_Organization();
         return parent::post($dest, $reply, $subject, $body);
     }
 
@@ -162,6 +176,74 @@ class ForumsBanana extends Banana
             Banana::$profile['subscribe'][] = $g;
         }
     }
+
+    protected function action_updateProfile()
+    {
+        global $page, $globals;
+
+        $colors = glob(dirname(__FILE__) . '/../../htdocs/images/banana/m2*.gif');
+        foreach ($colors as $key=>$path) {
+            $path = basename($path, '.gif');
+            $colors[$key] = substr($path, 2);
+        }
+        $page->assign('colors', $colors);
+
+        if (Post::has('action') && Post::v('action') == 'Enregistrer') {
+            S::assert_xsrf_token();
+            $flags = new FlagSet();
+            if (Post::b('bananadisplay')) {
+                $flags->addFlag('threads');
+            }
+            if (Post::b('bananaupdate')) {
+                $flags->addFlag('automaj');
+            }
+            if (Post::b('bananaxface')) {
+                $flags->addFlag('xface');
+            }
+            $unread = Post::s('unread');
+            $read = Post::s('read');
+            if (!in_array($unread, $colors) || !in_array($read, $colors)) {
+                $page->trigError('Le choix de type pour l\'arborescence est invalide');
+            } elseif (XDB::execute("REPLACE INTO  forums.profils (uid, sig, mail, nom, flags, tree_unread, tree_read)
+                                           VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?})",
+                                    S::v('uid'), Post::v('bananasig'),
+                                    Post::v('bananamail'), Post::v('banananame'),
+                                    $flags, $unread, $read)) {
+                $page->trigSuccess("Ton profil a été enregistré avec succès.");
+            } else {
+                $page->trigError("Une erreur s'est produite lors de l'enregistrement de ton profil");
+            }
+        }
+
+        $req = XDB::query("
+            SELECT  nom, mail, sig,
+                    FIND_IN_SET('threads', flags),
+                    FIND_IN_SET('automaj', flags),
+                    FIND_IN_SET('xface', flags),
+                    tree_unread,
+                    tree_read
+              FROM  forums.profils
+             WHERE  uid = {?}", S::v('uid'));
+        if (!(list($nom, $mail, $sig, $disp, $maj, $xface, $unread, $read) = $req->fetchOneRow())) {
+            $nom   = S::v('prenom').' '.S::v('nom');
+            $mail  = S::v('forlife').'@'.$globals->mail->domain;
+            $sig   = $nom.' ('.S::v('promo').')';
+            $disp  = 0;
+            $maj   = 0;
+            $xface = 0;
+            $unread = 'o';
+            $read  = 'dg';
+        }
+        $page->assign('nom' ,  $nom);
+        $page->assign('mail',  $mail);
+        $page->assign('sig',   $sig);
+        $page->assign('disp',  $disp);
+        $page->assign('maj',   $maj);
+        $page->assign('xface', $xface);
+        $page->assign('unread', $unread);
+        $page->assign('read', $read);
+        return null;
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: