Moving template util file
[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 // The Trash folder isn't counted...
27 if ($boxes->mailboxname_full == $GLOBALS['trash_folder'])
28 return 0;
29
30 $count = 0;
31 if (strtolower($type) == 'unseen')
32 $field = 'unseen';
33 else $field = 'total';
34
35
36 $count += !empty($boxes->{$field}) ? $boxes->{$field} : 0;
37 for ($j = 0; $j <count($boxes->mbxs); $j++) {
38 $count += getMessageCount($boxes->mbxs[$j], $type);
39 }
40
41 return $count;
42 }
43
44 /**
45 * Recursively iterates a mailboxes object to build a data structure that is
46 * easy for template authors to work with.
47 *
48 * @param object $boxes Object of the class mailboxes
49 * @author Steve Brown
50 * @since 1.5.2
51 */
52 function getBoxStructure ($boxes) {
53 global $data_dir, $username, $icon_theme_path;
54
55 // Stop condition
56 if (empty($boxes)) {
57 return array();
58 }
59
60 $mailbox = $boxes->mailboxname_full;
61 $mailboxURL = urlencode($mailbox);
62 $box = array();
63
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;
68
69 // Needed in case user enables cummulative message counts
70 $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total');
71 $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen');
72
73 $box['ViewLink'] = array( 'Target' => 'right',
74 'URL' => 'right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox='.$mailboxURL
75 );
76
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;
81
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;
87
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;
92
93 /*
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
97 * will be NULL.
98 */
99
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);
104
105 $box['CollapseLink'] = array ( 'Target' => 'left',
106 'URL' => 'left_main.php?'.($box['IsCollapsed'] ? 'unfold' : 'fold') .'='.$mailboxURL,
107 'Icon' => $icon .'&nbsp;'
108 );
109
110 $box['ChildBoxes'] = array();
111 for ($i = 0; $i <count($boxes->mbxs); $i++) {
112 $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs[$i]);
113 }
114
115 return $box;
116 }