Can choose the color of banana tree branches.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 5 Jul 2008 11:13:03 +0000 (13:13 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 5 Jul 2008 11:13:03 +0000 (13:13 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
include/banana/forum.inc.php
include/banana/ml.inc.php
templates/banana/index.tpl
upgrade/0.9.17/05_forums.sql [new file with mode: 0644]

index 89fa0c9..99f002f 100644 (file)
@@ -68,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 = 'b';
+            $read   = 'dg';
         }
         if ($maj) {
             $time = time();
@@ -95,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)) {
@@ -176,9 +181,15 @@ class ForumsBanana extends Banana
     {
         global $page, $globals;
 
-        if (Post::has('action') && Post::has('banananame') && Post::has('bananasig')
-                && Post::has('bananadisplay') && Post::has('bananamail')
-                && Post::has('bananaupdate') && Post::v('action')=="Enregistrer" ) {
+        $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');
@@ -189,11 +200,15 @@ class ForumsBanana extends Banana
             if (Post::b('bananaxface')) {
                 $flags->addFlag('xface');
             }
-            if (XDB::execute("REPLACE INTO  forums.profils (uid, sig, mail, nom, flags)
-                                VALUES  ({?}, {?}, {?}, {?}, {?})",
-                         S::v('uid'), Post::v('bananasig'),
-                         Post::v('bananamail'), Post::v('banananame'),
-                         $flags)) {
+            $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");
@@ -204,16 +219,20 @@ class ForumsBanana extends Banana
             SELECT  nom, mail, sig,
                     FIND_IN_SET('threads', flags),
                     FIND_IN_SET('automaj', flags),
-                    FIND_IN_SET('xface', 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) = $req->fetchOneRow())) {
+        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 = 'b';
+            $read  = 'dg';
         }
         $page->assign('nom' ,  $nom);
         $page->assign('mail',  $mail);
@@ -221,6 +240,8 @@ class ForumsBanana extends Banana
         $page->assign('disp',  $disp);
         $page->assign('maj',   $maj);
         $page->assign('xface', $xface);
+        $page->assign('unread', $unread);
+        $page->assign('read', $read);
         return null;
     }
 }
index 1a5413f..39dacf6 100644 (file)
@@ -79,6 +79,17 @@ class MLBanana extends Banana
         $sig  = $nom . ' (' . S::v('promo') . ')';
         Banana::$msgedit_headers['X-Org-Mail'] = S::v('forlife') . '@' . $globals->mail->domain;
 
+        // Tree color
+        $req = XDB::query("SELECT  tree_unread, tree_read
+                             FROM  {$globals->banana->table_prefix}profils
+                            WHERE  uid={?}", S::i('uid'));
+        if (!(list($unread, $read) = $req->fetchOneRow())) {
+            $unread = 'b';
+            $read = 'dg';
+        }
+        Banana::$tree_unread = $unread;
+        Banana::$tree_read = $read;
+
         // Build user profile
         Banana::$profile['headers']['From']         = "$nom <$mail>";
         Banana::$profile['headers']['Organization'] = make_Organization();
index 0e811d5..e865ee2 100644 (file)
@@ -38,6 +38,7 @@
 </p>
 
 <form action="banana/profile" method="post">
+  {xsrf_token_field}
   <table class="bicol" cellpadding="3" cellspacing="0" summary="Configuration de Banana">
     <tr>
       <th colspan="2">Profil Banana</th>
       </td>
     </tr>
     <tr class="pair">
+      <td class="titre">Aspect de l'arborescence</td>
+      <td>
+        {foreach from=$colors item=color}
+          <label>non-lu <input type="radio" name="unread" value="{$color}" {if $unread eq $color}checked="checked"{/if} /></label>
+          <img src="images/banana/m2{$color}.gif" alt="{$color}" />
+          <label><input type="radio" name="read" value="{$color}" {if $read eq $color}checked="checked"{/if} /> lu</label>
+          <br />
+        {/foreach}
+      </td>
+    </tr>
+    <tr class="pair">
       <td class="titre">Mise à jour des messages non lus</td>
       <td>
         <input type="radio" name="bananaupdate" value="1"
diff --git a/upgrade/0.9.17/05_forums.sql b/upgrade/0.9.17/05_forums.sql
new file mode 100644 (file)
index 0000000..0efa06c
--- /dev/null
@@ -0,0 +1,9 @@
+use forums;
+
+alter table profils
+ add column tree_unread varchar(8) not null default 'b',
+ add column tree_read varchar(8) not null default 'dg';
+
+use x4dat;
+
+# vim:set syntax=mysql: