Convert miniwiki of the freetext to text in the vcards.
[platal.git] / include / banana / forum.inc.php
index 7195d1e..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   *
@@ -49,7 +49,10 @@ class ForumsBanana extends Banana
         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()
@@ -65,15 +68,18 @@ 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')."@" . $globals->mail->domain;
             $sig  = $nom." (".S::v('promo').")";
             $disp = 0;
             $maj  = 1;
+            $unread = 'o';
+            $read   = 'dg';
         }
         if ($maj) {
             $time = time();
@@ -92,6 +98,8 @@ class ForumsBanana extends Banana
         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"
         if (!is_null($time)) {
@@ -116,8 +124,13 @@ class ForumsBanana extends Banana
             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)
@@ -163,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: