and back in sync again
[squirrelmail.git] / src / left_main.php
index f2106085ba41827c3178e1cf3c359f7665aadf47..71fb702868f5373e4f11e46d59a4257c064fd489 100644 (file)
@@ -99,6 +99,9 @@ function formatMailboxName($imapConnection, $box_array) {
             $line .= "\n<small>\n" .
                     "&nbsp;&nbsp;(<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A>)" .
                     "</small>";
+        } else {
+          $line .= concat_hook_function('left_main_after_each_folder',
+                 array(isset($numMessages) ? $numMessages : '',$real_box,$imapConnection));
         }
     }
 
@@ -280,96 +283,120 @@ function is_parent_box($curbox_name, $parbox_name) {
 function listBoxes ($boxes, $j=0 ) {
     global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type,
     $move_to_trash, $trash_folder, $collapse_folders, $imapConnection;
-    $pre = '';
+    $pre = '<nobr>';
     $end = '';
     $collapse = false;
-    if ($boxes) {
-    $mailbox = $boxes->mailboxname_full;
-    $leader = '';
-    for ($k = 0; $k < $j; $k++) {
-        $leader.= '&nbsp;&nbsp;&nbsp;';
-    }
-    $mailboxURL = urlencode($mailbox);
-
-    /* get unseen/total messages information */
-        if ($boxes->unseen) {
-        $unseen = $boxes->unseen;
+    $unseen_type = 1;
+    $unseen_notify = 0;
+
+    /* Get unseen/total display prefs */
+    $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
+    $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
+
+    if (isset($boxes) && !empty($boxes)) {
+        $mailbox = $boxes->mailboxname_full;
+        $leader = '<tt>';
+        $leader .= str_repeat('&nbsp;&nbsp;',$j);
+        $mailboxURL = urlencode($mailbox);
+        /* get unseen/total messages information */
+        if ($boxes->unseen !== false || $boxes->total !== false) {
+            $unseen = $boxes->unseen;
             $unseen_string = "($unseen)";
-        if ($unseen>0) $unseen_found = TRUE;
-            if ($boxes->total) {
-        $numMessages = $boxes->total;
-            $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
+            if ($unseen>0||$boxes->total>0) {
+                $unseen_found = TRUE;
+            }
+            $unseen_before = '<font color="' . $color[11] . '">';
+            $unseen_after = '</font>';
+            if ((($unseen_notify == 2) && (strtolower($mailbox) == 'inbox')) || ($unseen_notify == 3)) {
+                $unseen_string = '(' . $unseen;
+        
+                if ($unseen_type > 1) {
+                    $unseen_string .= '/' . $boxes->total;
+                }
+                $unseen_string .= ')';
+                $unseen_string = $unseen_before . $unseen_string . $unseen_after;
+            }
+        } else {
+            $unseen = 0;
         }
-    } else $unseen = 0;
 
-
-
-    if (isset($boxes->mbxs[0]) && $collapse_folders) {
-        $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
+        if (isset($boxes->mbxs[0]) && $collapse_folders) {
+            $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
             $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
 
-        $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
-        if ($collapse) {
-            $link .= "unfold=$mailboxURL\">$leader +&nbsp;";
+            $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
+            if ($collapse) {
+                $link .= "unfold=$mailboxURL\">$leader+&nbsp;</tt>";
+            } else {
+                $link .= "fold=$mailboxURL\">$leader-&nbsp;</tt>";
+            }
+            $link .= '</a>';
+            $pre .= $link;
         } else {
-            $link .= "fold=$mailboxURL\">$leader -&nbsp;";
+            $pre.= $leader . '&nbsp;&nbsp;</tt>';
         }
-        $link .= '</a>';
-        $pre .= $link;
-    } else {
-        $pre.= $leader . '&nbsp;&nbsp;&nbsp;';
-    }
-
-
-    /* If there are unseen message, bold the line. */
-    if ($unseen > 0) { $pre .= '<B>'; }
 
-    if (($move_to_trash) && ($mailbox == $trash_folder)) {
-            if (! isset($numMessages)) {
-                $status = sqimap_status_messages($imapConnection, $mailbox);
-                $numMessages = $status['MESSAGES'];
+        /* If there are unseen message, bold the line. */
+        if (($move_to_trash) && ($mailbox == $trash_folder)) {
+            if (! isset($boxes->total)) {
+                $boxes->total = sqimap_status_messages($imapConnection, $mailbox);
+            }
+            if ($unseen > 0) {
+                $pre .= '<b>';
+            }
+            $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
+            if ($unseen > 0) {
+                $end .= '</b>';
             }
-
-            $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">";
             $end .= '</a>';
-            if ($numMessages > 0) {
-                $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">";
+            if ($boxes->total > 0) {
+                if ($unseen > 0) {
+                    $pre .= '<b>';
+                }
+                $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
+                if ($unseen > 0) {
+                    $end .= '</b>';
+                }
                 $end .= "\n<small>\n" .
                         "&nbsp;&nbsp;(<a href=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</a>)" .
                         "</small>";
             }
-    } else {
-        if (!$boxes->is_noselect) {
-        $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">";
-        $end .= '</a>';
+        } else {
+            if (!$boxes->is_noselect) {
+                if ($unseen > 0) {
+                    $pre .= '<b>';
+                }
+                $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
+                if ($unseen > 0) {
+                    $end .= '</b>';
+                }
+                $end .= '</a>';
+            }
         }
-    }
 
-    /* If there are unseen message, close bolding. */
-    if ($unseen > 0) { $end .= "</b>"; }
-
-    /* Print unseen information. */
-    if (isset($unseen_found) && $unseen_found) {
+        /* Print unseen information. */
+        if (isset($unseen_found) && $unseen_found) {
             $end .= "&nbsp;<small>$unseen_string</small>";
-    }
+        }
 
-    $font = '';
-    $fontend = '';
-    if ($boxes->is_special) {
+        $font = '';
+        $fontend = '';
+        if ($boxes->is_special) {
             $font = "<font color=\"$color[11]\">";
-        $fontend = "</font>";
-    }
+            $fontend = "</font>";
+        }
+        $end .= '</nobr>';
 
-    if (!$boxes->is_root) {
-        echo "" . $pre .$font. $boxes->mailboxname_sub .$fontend . $end. '<br />' . "\n";
-        $j++;
-    }
-    if (!$collapse || $boxes->is_root) {
+        if (!$boxes->is_root) {
+            echo "" . $pre .$font. $boxes->mailboxname_sub .$fontend . $end. '<br />' . "\n";
+            $j++;
+        }
+
+        if (!$collapse || $boxes->is_root) {
             for ($i = 0; $i <count($boxes->mbxs); $i++) {
-            listBoxes($boxes->mbxs[$i],$j);
+                listBoxes($boxes->mbxs[$i],$j);
             }
-    }
-
+        }
     }
 }
 
@@ -389,12 +416,12 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
     $mailboxURL = urlencode($mailbox);
 
     /* get unseen/total messages information */
-        if ($boxes->unseen) {
+    if ($boxes->unseen !== false) {
         $unseen = $boxes->unseen;
-            $unseen_string = "($unseen)";
+        $unseen_string = "($unseen)";
         if ($unseen>0) $unseen_found = TRUE;
-            if ($boxes->total) {
-        $numMessages = $boxes->total;
+        if ($boxes->total) {
+            $numMessages = $boxes->total;
             $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
         }
     } else $unseen = 0;
@@ -550,7 +577,7 @@ if (isset($left_refresh) && ($left_refresh != '') &&
  **/
 
 $advanced_tree = false; /* set this to true if you want to see a nicer mailboxtree */
-$oldway = false; /* default SM behaviour */
+$oldway = false;        /* default SM behaviour */
 
 if ($advanced_tree) {
 $xtra .= <<<ECHO
@@ -939,16 +966,17 @@ for ($i = 0; $i < count($boxes); $i++) {
 } else {  /* expiremental code */
     $boxes = sqimap_mailbox_tree($imapConnection);
     if (isset($advanced_tree) && $advanced_tree) {
-    echo '<form name="collapse" action="left_main.php" method="post" ' .
-            'enctype="multipart/form-data"'."\n";
-    echo '<small><button type="submit" class="button" onmouseover="buttonover(this,true)" onmouseout="buttonover(this,false)" onmousedown="buttonclick(this,true)" onmouseup="buttonclick(this,false)">'. _("Save folder tree") .'</button><br /><br />';
-    echo '<div id="mailboxes" class="mailboxes">'."\n\n";
-    if (!isset($mbx)) $mbx=NULL;
+        echo '<form name="collapse" action="left_main.php" method="post" ' .
+             'enctype="multipart/form-data"'."\n";
+        echo '<small><button type="submit" class="button" onmouseover="buttonover(this,true)" onmouseout="buttonover(this,false)" onmousedown="buttonclick(this,true)" onmouseup="buttonclick(this,false)">'. _("Save folder tree") .'</button><br /><br />';
+        echo '<div id="mailboxes" class="mailboxes">'."\n\n";
+        if (!isset($mbx)) $mbx=NULL;
         ListAdvancedBoxes($boxes, $mbx);
-    echo '</div></small>'."\n";
-    echo '</form>'."\n";
+        echo '</div></small>'."\n";
+        echo '</form>'."\n";
     } else {
-    ListBoxes($boxes);
+        //sqimap_get_status_mbx_tree($imap_stream,$boxes)    
+        ListBoxes($boxes);
     }
 } /* if ($oldway) else ... */
 do_hook('left_main_after');