42a29eee9794357ec78e6482dde3b67638babe72
[squirrelmail.git] / functions / template / folder_list_util.php
1 <?php
2
3 /**
4 * folder_list_util.php
5 *
6 * Provides some functions for use in left_main.php and templates. Do not echo
7 * output from these functions!
8 *
9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 * @subpackage templates
14 */
15
16 /**
17 * Recursively iterates a mailboxes object to get the cummulative count of
18 * messages for all folderes below the current mailbox.
19 *
20 * @param object $boxes Object of the class mailboxes
21 * @param string $type Whether to fetch unseen only or all messages
22 * @author Steve Brown
23 * @since 1.5.2
24 */
25 function getMessageCount ($boxes, $type='total') {
26
27 global $trash_folder;
28
29 // The Trash folder isn't counted...
30 if ($boxes->mailboxname_full == $trash_folder)
31 return 0;
32
33 $count = 0;
34 if (strtolower($type) == 'unseen')
35 $field = 'unseen';
36 else $field = 'total';
37
38
39 $count += !empty($boxes->{$field}) ? $boxes->{$field} : 0;
40 for ($j = 0; $j <count($boxes->mbxs); $j++) {
41 $count += getMessageCount($boxes->mbxs[$j], $type);
42 }
43
44 return $count;
45 }
46
47 /**
48 * Recursively iterates a mailboxes object to build a data structure that is
49 * easy for template authors to work with.
50 *
51 * @param object $boxes Object of the class mailboxes
52 * @author Steve Brown
53 * @since 1.5.2
54 */
55 function getBoxStructure ($boxes) {
56 global $data_dir, $username, $icon_theme_path;
57
58 // Stop condition
59 if (empty($boxes)) {
60 return array();
61 }
62
63 $mailbox = $boxes->mailboxname_full;
64 $mailboxURL = urlencode($mailbox);
65 $box = array();
66
67 $box['MailboxFullName'] = $mailbox;
68 $box['MailboxName'] = $boxes->mailboxname_sub;
69 $box['MessageCount'] = !empty($boxes->total) ? $boxes->total : 0;
70 $box['UnreadCount'] = !empty($boxes->unseen) ? $boxes->unseen : 0;
71
72 // Needed in case user enables cummulative message counts
73 $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total');
74 $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen');
75
76 $box['ViewLink'] = array( 'Target' => 'right',
77 'URL' => 'right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox='.$mailboxURL
78 );
79
80 $box['IsRecent'] = isset($boxes->recent) && $boxes->recent;
81 $box['IsSpecial'] = isset($boxes->is_special) && $boxes->is_special;
82 $box['IsRoot'] = isset($boxes->is_root) && $boxes->is_root;
83 $box['IsNoSelect'] = isset($boxes->is_noselect) && $boxes->is_noselect;
84
85 $box['IsInbox'] = isset($boxes->is_inbox) && $boxes->is_inbox;
86 $box['IsSent'] = isset($boxes->is_sent) && $boxes->is_sent;
87 $box['IsTrash'] = isset($boxes->is_trash) && $boxes->is_trash;
88 $box['IsDraft'] = isset($boxes->is_draft) && $boxes->is_draft;
89 $box['IsNoInferiors'] = isset($boxes->is_noinferiors) && $boxes->is_noinferiors;
90
91 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
92 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
93 $collapse = (int)$collapse == SM_BOX_COLLAPSED;
94 $box['IsCollapsed'] = $collapse;
95
96 /*
97 * Check for an image needed here. If the file exists in $icon_theme_path
98 * assume the template provides all icons. If not, we will use the
99 * SQM default images. If icons have been disabled, $icon_theme_path
100 * will be NULL.
101 */
102
103 $text_icon = $box['IsCollapsed'] ? '+' : '-';
104 $icon_file = $box['IsCollapsed'] ? 'plus.png' : 'minus.png';
105 $icon_alt = $box['IsCollapsed'] ? 'Expand Box' : 'Collapse Box';
106 $icon = getIcon($icon_theme_path, $icon_file, $text_icon, $icon_alt);
107
108 $box['CollapseLink'] = array ( 'Target' => 'left',
109 'URL' => 'left_main.php?'.($box['IsCollapsed'] ? 'unfold' : 'fold') .'='.$mailboxURL,
110 'Icon' => $icon .'&nbsp;'
111 );
112
113 $box['ChildBoxes'] = array();
114 for ($i = 0; $i <count($boxes->mbxs); $i++) {
115 $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs[$i]);
116 }
117
118 return $box;
119 }