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