add purge link when folder contains subfolders.
[squirrelmail.git] / templates / default / left_main.tpl
index 7991cd0..becdde5 100644 (file)
@@ -2,40 +2,37 @@
 /**
  * left_main.tpl
  *
- * Basic template to the left main window.  The following variables are 
- * avilable in this template:
+ * Basic template to the left main window.  
+ * 
+ * The following variables are avilable in this template:
  *      $clock           - formatted string containing last refresh
- *      $mailbox_listing - string containing HTML to display default mailbox tree
- *      $location_of_bar - string "left" or "right" indicating where the frame
- *                         is located.  Currently only used in
- *                         left_main_advanced.tpl
- *      $left_size       - width of left column in pixels.  Currently only used
- *                         in left_main_advanced.tpl
- *      $imapConnection  - IMAP connection handle.  Needed to allow plugins to 
- *                         read the mailbox.
- *      $icon_theme_path - Path to the desired icon theme.  If no icon theme has
- *                         been chosen, this will be the template directory.  If
+ *      $settings        - Array containing user perferences needed by this
+ *                         template.  Indexes are as follows:
+ *          $settings['imapConnection'] - IMAP connection handle.  Needed to
+ *                         allow plugins to read the mailbox.
+ *          $settings['iconThemePath'] - Path to the desired icon theme.  If
  *                         the user has disabled icons, this will be NULL.
+ *          $settings['templateDirectory'] - contains the path to the current
+ *                         template directory.  This may be needed by third
+ *                         party packages that don't integrate easily.
+ *          $settings['unreadNotificationEnabled'] - Boolean TRUE if the user
+ *                         wants to see unread message count on mailboxes
+ *          $settings['unreadNotificationCummulative'] - Boolean TRUE if the
+ *                         user has enabled cummulative message counts.
+ *          $settings['unreadNotificationAllFolders'] - Boolean TRUE if the
+ *                         user wants to see unread message count on ALL
+ *                         folders or just the Inbox.
+ *          $settings['unreadNotificationDisplayTotal'] - Boolean TRUE if the
+ *                         user wants to see the total number of messages in
+ *                         addition to the unread message count.
+ *          $settings['collapsableFoldersEnabled'] - Boolean TRUE if the user
+ *                         has enabled collapsable folders.
+ *          $settings['useSpecialFolderColor'] - Boolean TRUE if the use has
+ *                         chosen to tag "Special" folders in a different color
+ *          $settings['messageRecyclingEnabled'] - Boolean TRUE if messages
+ *                         that get deleted go to the Trash folder.  FALSE if
+ *                          they are permanently deleted.
  *
- *      $unread_notification_enabled - Boolean TRUE if the user wants to see unread 
- *                             message count on mailboxes
- *      $unread_notification_cummulative - Boolean TRUE if the user has enabled
- *                             cummulative message counts.
- *      $unread_notification_allFolders - Boolean TRUE if the user wants to see
- *                             unread message count on ALL folders or just the
- *                             mailbox.
- *      $unread_notification_displayTotal - Boolean TRUE if the user wants to
- *                             see the total number of messages in addition to
- *                             the unread message count.
- *      $collapsable_folders_enabled - Boolean TRUE if the user has enabled collapsable
- *                             folders.
- *      $use_special_folder_color - Boolean TRUE if the use has chosen to tag
- *                             "Special" folders in a different color.
- *      $message_recycling_enabled - Boolean TRUE if messages that get deleted go to
- *                             the Trash folder.  FALSE if they are permanently
- *                             deleted.
- *      $trash_folder_name   - Name of the Trash folder.
- * 
  *      $mailboxes       - Associative array of current mailbox structure.
  *                         Provided so template authors know what they have to
  *                         work with when building a custom mailbox tree.
  *                                  'Icon'   = the icon to use, based on user prefs
  *          $a['ChildBoxes']    = array containing this same data structure for
  *                                each child folder/mailbox of the current
- *                                mailbox. 
+ *                                mailbox.
  *          $a['CummulativeMessageCount']   = integer of total messages in all
  *                                            folders in this mailbox, exlcuding
  *                                            trash folders.
  *          $a['CummulativeUnreadCount']    = integer of total unseen messages
  *                                            in all folders in this mailbox,
  *                                            excluding trash folders.
- *  
  *
  * @copyright © 1999-2006 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  * @subpackage templates
+ * @author Steve Brown
  */
 
-// include required files
+/** include required files */
 include_once(SM_PATH . 'templates/util_global.php');
 
 /*
  * Recursively parse the mailbox structure to build the navigation tree.
- * 
+ *
  * @since 1.5.2
  */
 function buildMailboxTree ($box, $settings, $indent_factor=0) {
@@ -90,7 +87,6 @@ function buildMailboxTree ($box, $settings, $indent_factor=0) {
         return '';
     }
 
-#    echo '<b>'.$box['MailboxName'].':</b> '.dump_array($box).'<hr>';
     $pre = '<span style="white-space: nowrap;">';
     $end = '';
     $indent = str_repeat('&nbsp;&nbsp;',$indent_factor);
@@ -99,25 +95,29 @@ function buildMailboxTree ($box, $settings, $indent_factor=0) {
     $unseen_str = '';
     if ($settings['unreadNotificationEnabled'])   {
         // We only display the unread count if we on the Inbox or we are told
-        // to display it on all folders
-        if ( $settings['unreadNotificationAllFolders'] || 
-             (!$settings['unreadNotifictionAllFolders'] && strtolower($box['MailboxFullName'])=='inbox') 
+        // to display it on all folders AND there is more than 1 unread message
+        if ( $settings['unreadNotificationAllFolders'] ||
+             (!$settings['unreadNotificationAllFolders'] && strtolower($box['MailboxFullName'])=='inbox')
            )  {
-            $unseen_str = $settings['unreadNotificationCummulative'] ? 
-                            $box['CummulativeUnreadCount'] : 
+            $unseen = $settings['unreadNotificationCummulative'] ?
+                            $box['CummulativeUnreadCount'] :
                             $box['UnreadCount'];
             
-            // Add the total messages if desired
-            if ($settings['unreadNotificationDisplayTotal'])    {
-                $unseen_str .= '/' . ($settings['unreadNotificationCummulative'] ?
-                                        $box['CummulativeMessageCount'] :
-                                        $box['MessageCount']);
+            if (!$box['IsNoSelect'] && ($unseen > 0 || $settings['unreadNotificationDisplayTotal'])) {
+                $unseen_str = $unseen;
+    
+                // Add the total messages if desired
+                if ($settings['unreadNotificationDisplayTotal'])    {
+                    $unseen_str .= '/' . ($settings['unreadNotificationCummulative'] ?
+                                            $box['CummulativeMessageCount'] :
+                                            $box['MessageCount']);
+                }
+
+                $unseen_str = '<span class="'.
+                              ($box['IsRecent'] ? 'leftrecent' : 'leftunseen') .
+                              '">' . $unseen_str .
+                              '</span>';
             }
-            
-            $unseen_str = '<span class="'. 
-                          ($box['IsRecent'] ? 'leftrecent' : 'leftunseen') .
-                          '">' . $unseen_str .
-                          '</span>';
         }
     }
 
@@ -126,20 +126,48 @@ function buildMailboxTree ($box, $settings, $indent_factor=0) {
      * we need to output the expand/collapse link.
      */
     if (sizeof($box['ChildBoxes'])>0 && $settings['collapsableFoldersEnabled'])    {
-        $link = $indent . 
+        $link = $indent .
                 '<a href="'.$box['CollapseLink']['URL'].'" ' .
                 'target="'.$box['CollapseLink']['Target'].'" ' .
                 'style="text-decoration:none" ' .
-#                'alt="'.$box['CollapseLink']['Alt'].'" ' .
-#                'title="'.$box['CollapseLink']['Alt'].'">' .
-                '>' .   
-                $box['CollapseLink']['Icon'] . 
-                '</a>';   
-        $pre .= $link;   
-    } else { 
+                '>' .
+                $box['CollapseLink']['Icon'] .
+                '</a>';
+        $pre .= $link;
+    } else {
         $pre .= $indent . '&nbsp;&nbsp;';
     }
-      
+
+    /**
+     * Add folder icon.  Template authors may choose to display a different
+     * image based on whatever logic they see fit here.
+     */
+    $folder_icon = '';
+    if (!is_null($settings['iconThemePath'])) {
+        switch (true) {
+            case $box['IsInbox']:
+                $folder_icon = getIcon($settings['iconThemePath'], 'inbox.png', '', $box['MailboxName']);
+                break; 
+            case $box['IsSent']:
+                $folder_icon = getIcon($settings['iconThemePath'], 'senti.png', '', $box['MailboxName']);
+                break; 
+            case $box['IsTrash']:
+                $folder_icon = getIcon($settings['iconThemePath'], 'delitem.png', '', $box['MailboxName']);
+                break; 
+            case $box['IsDraft']:
+                $folder_icon = getIcon($settings['iconThemePath'], 'draft.png', '', $box['MailboxName']);
+                break; 
+            case $box['IsNoInferiors']:
+                $folder_icon = getIcon($settings['iconThemePath'], 'folder_noinf.png', '', $box['MailboxName']);
+                break;
+            default: 
+                $folder_icon = getIcon($settings['iconThemePath'], 'folder.png', '', $box['MailboxName']);
+                break;
+        }
+        $folder_icon .= '&nbsp;';
+    }
+    $pre .= $folder_icon;
+
     /*
      * The Trash folder should only be displayed if message recycling has
      * been enabled, i.e. when deleted is a message moved to the trash or
@@ -148,8 +176,8 @@ function buildMailboxTree ($box, $settings, $indent_factor=0) {
     $view_link = '<a href="'.$box['ViewLink']['URL'].'" ' .
                  'target="'.$box['ViewLink']['Target'].'" ' .
                  'style="text-decoration:none">';
-     
-    if ($settings['messageRecyclingEnabled'] && $box['MailboxFullName'] == $settings['trashFolderName']) {
+
+    if ($settings['messageRecyclingEnabled'] && $box['IsTrash']) {
         $pre .= $view_link;
 
         // Boxes with unread messages should be emphasized
@@ -158,9 +186,9 @@ function buildMailboxTree ($box, $settings, $indent_factor=0) {
             $end .= '</em>';
         }
         $end .= '</a>';
-        
+
         // Print unread info
-        if ($box['UnreadCount'] > 0) {
+        if ($box['MessageCount'] > 0 || count($box['ChildBoxes'])) {
             if (!empty($unseen_str)) {
                 $end .= '&nbsp;<small>('.$unseen_str.')</small>';
             }
@@ -172,7 +200,7 @@ function buildMailboxTree ($box, $settings, $indent_factor=0) {
         // Add a few other things for all other folders...
         if (!$box['IsNoSelect']) {
             $pre .= $view_link;
-    
+
             // Boxes with unread messages should be emphasized
             if ($box['UnreadCount'] > 0) {
                 $pre .= '<em>';
@@ -180,13 +208,13 @@ function buildMailboxTree ($box, $settings, $indent_factor=0) {
             }
             $end .= '</a>';
         }
-        
+
         // Display unread info...
         if (!empty($unseen_str)) {
             $end .= '&nbsp;<small>('.$unseen_str.')</small>';
         }
     }
-     
+
     $span = '';
     $spanend = '';
     if ($settings['useSpecialFolderColor'] && $box['IsSpecial']) {
@@ -220,28 +248,12 @@ function buildMailboxTree ($box, $settings, $indent_factor=0) {
             $out .= buildMailboxTree($box['ChildBoxes'][$i], $settings, $indent_factor);
         }
     }
-    
+
     return $out;
 }
 
 // Retrieve the template vars
 extract($t);
-  
-/*
- * Build an array to pass user prefs to the function that builds the tree in
- * order to avoid using globals, which are dirty, filthy things in templates. :)
- */         
-$settings = array();
-$settings['imapConnection'] = $imapConnection;
-$settings['iconThemePath'] = $icon_theme_path;
-$settings['unreadNotificationEnabled'] = $unread_notification_enabled;
-$settings['unreadNotificationAllFolders'] = $unread_notification_allFolders;
-$settings['unreadNotificationDisplayTotal'] = $unread_notification_displayTotal;
-$settings['unreadNotificationCummulative'] = $unread_notification_cummulative;
-$settings['useSpecialFolderColor'] = $use_special_folder_color;
-$settings['messageRecyclingEnabled'] = $message_recycling_enabled;
-$settings['trashFolderName'] = $trash_folder_name;
-$settings['collapsableFoldersEnabled'] = $collapsable_folders_enabled;
 
 ?>
 <body class="sqm_leftMain">
@@ -255,14 +267,14 @@ $settings['collapsableFoldersEnabled'] = $collapsable_folders_enabled;
      <td style="text-align:center">
       <span class="sqm_folderHeader"><?php echo _("Folders"); ?></span><br />
       <span class="sqm_clock"><?php echo $clock; ?></span>
-      <span class="sqm_refreshButton"><small>[<a href="../src/left_main.php" target="left"><?php echo _("Check Mail"); ?></a>]</small></span>
+      <span class="sqm_refreshButton"><small>[<a href="../src/left_main.php" target="left"><?php echo _("Check mail"); ?></a>]</small></span>
      </td>
     </tr>
    </table>
    <br />
    <?php echo buildMailboxTree($mailboxes, $settings); ?>
-  </tr>
- </td>
+  </td>
+ </tr>
 </table>
 <?php do_hook('left_main_after'); ?>
 </div>