New icon theming. Also added basic template for left_main.php
[squirrelmail.git] / templates / util_left_main.php
1 <?php
2 /**
3 * util_left_main.php
4 *
5 * Provides some functions for use in left_main.php and templates. Do not echo
6 * output from these functions!
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 * @subpackage templates
13 */
14
15 /**
16 * Recursively iterates a mailboxes object to get the cummulative count of
17 * messages for all folderes below the current mailbox.
18 *
19 * @param object $boxes Object of the class mailboxes
20 * @param string $type Whether to fetch unseen only or all messages
21 * @author Steve Brown
22 * @since 1.5.2
23 */
24 function getMessageCount ($boxes, $type='total')
25 {
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 {
54 global $data_dir, $username, $icon_theme_path;
55
56 // Stop condition
57 if (empty($boxes)) {
58 return array();
59 }
60
61 $mailbox = $boxes->mailboxname_full;
62 $mailboxURL = urlencode($mailbox);
63 $box = array();
64
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;
69
70 // Needed in case user enables cummulative message counts
71 $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total');
72 $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen');
73
74 $box['ViewLink'] = array( 'Target' => 'right',
75 'URL' => 'right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox='.$mailboxURL
76 );
77
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;
82
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;
87
88 /*
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
92 * will be NULL.
93 */
94
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);
99
100 $box['CollapseLink'] = array ( 'Target' => 'left',
101 'URL' => 'left_main.php?'.($box['IsCollapsed'] ? 'unfold' : 'fold') .'='.$mailboxURL,
102 'Icon' => $icon .'&nbsp;'
103 );
104
105 $box['ChildBoxes'] = array();
106 for ($i = 0; $i <count($boxes->mbxs); $i++) {
107 $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs[$i]);
108 }
109
110 return $box;
111 }
112
113
114 ?>