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