6 * Provides some functions for use in left_main.php and templates. Do not echo
7 * output from these functions!
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
13 * @subpackage templates
17 * Recursively iterates a mailboxes object to get the cummulative count of
18 * messages for all folderes below the current mailbox.
20 * @param object $boxes Object of the class mailboxes
21 * @param string $type Whether to fetch unseen only or all messages
25 function getMessageCount ($boxes, $type='total') {
26 // The Trash folder isn't counted...
27 if ($boxes->mailboxname_full
== $GLOBALS['trash_folder'])
31 if (strtolower($type) == 'unseen')
33 else $field = 'total';
36 $count +
= !empty($boxes->{$field}) ?
$boxes->{$field} : 0;
37 for ($j = 0; $j <count($boxes->mbxs
); $j++
) {
38 $count +
= getMessageCount($boxes->mbxs
[$j], $type);
45 * Recursively iterates a mailboxes object to build a data structure that is
46 * easy for template authors to work with.
48 * @param object $boxes Object of the class mailboxes
52 function getBoxStructure ($boxes) {
53 global $data_dir, $username, $icon_theme_path;
60 $mailbox = $boxes->mailboxname_full
;
61 $mailboxURL = urlencode($mailbox);
64 $box['MailboxFullName'] = $mailbox;
65 $box['MailboxName'] = $boxes->mailboxname_sub
;
66 $box['MessageCount'] = !empty($boxes->total
) ?
$boxes->total
: 0;
67 $box['UnreadCount'] = !empty($boxes->unseen
) ?
$boxes->unseen
: 0;
69 // Needed in case user enables cummulative message counts
70 $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total');
71 $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen');
73 $box['ViewLink'] = array( 'Target' => 'right',
74 'URL' => 'right_main.php?PG_SHOWALL=0&startMessage=1&mailbox='.$mailboxURL
77 $box['IsRecent'] = isset($boxes->recent
) && $boxes->recent
;
78 $box['IsSpecial'] = isset($boxes->is_special
) && $boxes->is_special
;
79 $box['IsRoot'] = isset($boxes->is_root
) && $boxes->is_root
;
80 $box['IsNoSelect'] = isset($boxes->is_noselect
) && $boxes->is_noselect
;
82 $box['IsInbox'] = isset($boxes->is_inbox
) && $boxes->is_inbox
;
83 $box['IsSent'] = isset($boxes->is_sent
) && $boxes->is_sent
;
84 $box['IsTrash'] = isset($boxes->is_trash
) && $boxes->is_trash
;
85 $box['IsDraft'] = isset($boxes->is_draft
) && $boxes->is_draft
;
86 $box['IsNoInferiors'] = isset($boxes->is_noinferiors
) && $boxes->is_noinferiors
;
88 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
89 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
90 $collapse = (int)$collapse == SM_BOX_COLLAPSED
;
91 $box['IsCollapsed'] = $collapse;
94 * Check for an image needed here. If the file exists in $icon_theme_path
95 * assume the template provides all icons. If not, we will use the
96 * SQM default images. If icons have been disabled, $icon_theme_path
100 $text_icon = $box['IsCollapsed'] ?
'+' : '-';
101 $icon_file = $box['IsCollapsed'] ?
'plus.png' : 'minus.png';
102 $icon_alt = $box['IsCollapsed'] ?
'Expand Box' : 'Collapse Box';
103 $icon = getIcon($icon_theme_path, $icon_file, $text_icon, $icon_alt);
105 $box['CollapseLink'] = array ( 'Target' => 'left',
106 'URL' => 'left_main.php?'.($box['IsCollapsed'] ?
'unfold' : 'fold') .'='.$mailboxURL,
107 'Icon' => $icon .' '
110 $box['ChildBoxes'] = array();
111 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
112 $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs
[$i]);