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')
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)
54 global $data_dir, $username, $icon_theme_path;
61 $mailbox = $boxes->mailboxname_full
;
62 $mailboxURL = urlencode($mailbox);
65 $box['MailboxFullName'] = $mailbox;
66 $box['MailboxName'] = $boxes->mailboxname_sub
;
67 $box['MessageCount'] = !empty($boxes->total
) ?
$boxes->total
: 0;
68 $box['UnreadCount'] = !empty($boxes->unseen
) ?
$boxes->unseen
: 0;
70 // Needed in case user enables cummulative message counts
71 $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total');
72 $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen');
74 $box['ViewLink'] = array( 'Target' => 'right',
75 'URL' => 'right_main.php?PG_SHOWALL=0&startMessage=1&mailbox='.$mailboxURL
78 $box['IsRecent'] = isset($boxes->recent
) && $boxes->recent
;
79 $box['IsSpecial'] = isset($boxes->is_special
) && $boxes->is_special
;
80 $box['IsRoot'] = isset($boxes->is_root
) && $boxes->is_root
;
81 $box['IsNoSelect'] = isset($boxes->is_noselect
) && $boxes->is_noselect
;
83 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
84 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
85 $collapse = (int)$collapse == SM_BOX_COLLAPSED
;
86 $box['IsCollapsed'] = $collapse;
89 * Check for an image needed here. If the file exists in $icon_theme_path
90 * assume the template provides all icons. If not, we will use the
91 * SQM default images. If icons have been disabled, $icon_theme_path
95 $text_icon = $box['IsCollapsed'] ?
'+' : '-';
96 $icon_file = $box['IsCollapsed'] ?
'plus.png' : 'minus.png';
97 $icon_alt = $box['IsCollapsed'] ?
'Expand Box' : 'Collapse Box';
98 $icon = getIcon($icon_theme_path, $icon_file, $text_icon, $icon_alt);
100 $box['CollapseLink'] = array ( 'Target' => 'left',
101 'URL' => 'left_main.php?'.($box['IsCollapsed'] ?
'unfold' : 'fold') .'='.$mailboxURL,
102 'Icon' => $icon .' '
105 $box['ChildBoxes'] = array();
106 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
107 $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs
[$i]);