* added footer template which also takes care of displaying the error messages
[squirrelmail.git] / src / left_main.php
index 1272053f74bbab0d948a52ad6349b67272f2f18e..8e7e941ad34aa4a265e008fc06e127f1fa77f0f7 100644 (file)
@@ -3,12 +3,11 @@
 /**
  * left_main.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * This is the code for the left bar. The left bar shows the folders
  * available, and has cookie information.
  *
+ * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  */
@@ -20,7 +19,7 @@
 define('SM_PATH','../');
 
 /* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
+include_once(SM_PATH . 'include/validate.php');
 require_once(SM_PATH . 'functions/imap.php');
 require_once(SM_PATH . 'functions/plugin.php');
 require_once(SM_PATH . 'functions/page_header.php');
@@ -81,7 +80,7 @@ function ListBoxes ($boxes, $j=0 ) {
                 $unseen_string .= '/' . $boxes->total;
             }
 
-            $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
+            $unseen_string = "<span class=\"highlight\">($unseen_string)</span>";
 
             /*
                 Finally allow the script to display the values by setting a boolean.
@@ -120,9 +119,13 @@ function ListBoxes ($boxes, $j=0 ) {
 
     /* 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 ( !is_numeric($boxes->total) ) {
+            $result = sqimap_status_messages($imapConnection, $mailbox);
+            $boxes->total = $result['MESSAGES'];
+            $boxes->unseen = $result['UNSEEN'];
         }
+
         $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
         if ($unseen > 0) {
             $pre .= '<b>';
@@ -134,7 +137,7 @@ function ListBoxes ($boxes, $j=0 ) {
             if ($unseen_found) {
                 $end .= "&nbsp;<small>$unseen_string</small>";
             }
-            $end .= "\n\t<small>" .
+            $end .= "\n<small>" .
                  '&nbsp;&nbsp;[<a href="empty_trash.php">'._("Purge").'</a>]'.
                  '</small>';
         }
@@ -154,16 +157,17 @@ function ListBoxes ($boxes, $j=0 ) {
 
     }
 
-    $font = '';
-    $fontend = '';
+    $span = '';
+    $spanend = '';
     if ($use_special_folder_color && $boxes->is_special) {
-        $font = "<font color=\"$color[11]\">";
-        $fontend = "</font>";
+        $span = "<span class=\"leftspecial\">";
+        $spanend = "</span>";
     } elseif ( $boxes->is_noselect ) {
-        $font = "<font color=\"$color[15]\">";
-        $fontend = '</font>';
+        $span = "<span class=\"leftnoselect\">";
+        $spanend = '</span>';
     }
 
+
     // let plugins fiddle with end of line
     $end .= concat_hook_function('left_main_after_each_folder',
         array(isset($numMessages) ? $numMessages : '',
@@ -172,12 +176,12 @@ function ListBoxes ($boxes, $j=0 ) {
     $end .= '</span>';
 
     if (!$boxes->is_root) {
-        echo "" . $pre .$font.
+        echo "" . $span . $pre .
             str_replace(
                 array(' ','<','>'),
                 array('&nbsp;','&lt;','&gt;'),
                 $boxes->mailboxname_sub) .
-            $fontend . $end. '<br />' . "\n";
+            $end. $spanend .'<br />' . "\n";
         $j++;
     }
 
@@ -229,7 +233,7 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
                 $unseen_string .= '/' . $boxes->total;
             }
 
-            $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
+            $unseen_string = "<span class=\"highlight\">($unseen_string)</span>";
 
             /*
                 Finally allow the script to display the values by setting a boolean.
@@ -247,8 +251,8 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
 
     /* color special boxes */
     if ($use_special_folder_color && $boxes->is_special) {
-        $pre .= "<font color=\"$color[11]\">";
-        $end .= '</font>';
+        $pre .= "<span class=\"highlight\">";
+        $end .= '</span>';
     }
 
     /* If there are unseen message, close bolding. */
@@ -633,14 +637,19 @@ $xtra .= <<<HEREDOC
 HEREDOC;
 }
 
+// get mailbox list and cache it
+$mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
+
 displayHtmlHeader( 'SquirrelMail', $xtra );
+
 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION);
 /* If requested and not yet complete, attempt to autocreate folders. */
 if ($auto_create_special && !isset($auto_create_done)) {
     $autocreate = array($sent_folder, $trash_folder, $draft_folder);
     foreach( $autocreate as $folder ) {
         if (($folder != '') && ($folder != 'none')) {
-            if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
+            // use $mailboxes array for checking if mailbox exists
+            if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailboxes)) {
                 sqimap_mailbox_create($imapConnection, $folder, '');
             } else {
                 // check for subscription is useless and expensive, just
@@ -663,9 +672,9 @@ if ($auto_create_special && !isset($auto_create_done)) {
 if ($advanced_tree) {
     echo "\n<body" .
             ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
-            " bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
+            " class=\"leftmain\">\n<div class=\"leftmain\">\n";
 } else {
-    echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
+    echo "\n<body class=\"leftmain\">\n<div class=\"leftmain\">\n";
 }
 
 do_hook('left_main_before');
@@ -679,8 +688,13 @@ if ($advanced_tree) {
    echo '<div id="leftframe"><br /><br />';*/
 }
 
-echo "\n\n" .
-    '<center><font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
+echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
+    html_tag( 'tr' ) .
+    html_tag( 'td', '', 'left' ) .
+    html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0"' ) .
+    html_tag( 'tr' ) .
+    html_tag( 'td', '', 'center' ) .
+    '<font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
 
 if ($date_format != 6) {
     /* First, display the clock. */
@@ -723,11 +737,9 @@ if ($date_format != 6) {
 
 /* Next, display the refresh button. */
 echo '<div style="white-space: nowrap;"><small>[<a href="../src/left_main.php" target="left">'.
-     _("Check mail") . "</a>]</small></div></center><br />\n\n";
+     _("Check mail") . "</a>]</small></div></td></tr></table><br />\n\n";
 
 /* Lastly, display the folder list. */
-echo "<center><table><tr><td>\n";
-
 
 if ( $collapse_folders ) {
     /* If directed, collapse or uncollapse a folder. */
@@ -757,8 +769,12 @@ if (empty($unseen_notify)) {
         $unseen_notify = 0;
     }
 }
+/**
+ * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
+ * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
+ */
+$boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
 
-$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";
@@ -773,10 +789,12 @@ if (isset($advanced_tree) && $advanced_tree) {
     ListBoxes($boxes);
 }
 
-echo "</td></tr></table></center>\n";
-
 do_hook('left_main_after');
 sqimap_logout($imapConnection);
 
 ?>
-</body></html>
+</td></tr></table>
+</div>
+<?php
+$oTemplate->display('footer.tpl');
+?>
\ No newline at end of file