Bunzo, go to sleep 8-)
[squirrelmail.git] / src / left_main.php
1 <?php
2 /**
3 ** left_main.php
4 ** Copyright (c) 1999-2000 The SquirrelMail development team
5 ** Licensed under the GNU GPL. For full terms see the file COPYING.
6 **
7 ** This is the code for the left bar. The left bar shows the folders
8 ** available, and has cookie information.
9 **
10 ** $Id$
11 **/
12
13 require_once('../src/validate.php');
14 require_once('../functions/array.php');
15 require_once('../functions/imap.php');
16 require_once('../functions/plugin.php');
17
18 // open a connection on the imap port (143)
19 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
20
21 displayHtmlHeader();
22
23 if ($auto_create_special && ! isset($auto_create_done)) {
24 if (isset ($sent_folder) && $sent_folder != "none") {
25 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
26 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
27 } else if (! sqimap_mailbox_is_subscribed($imapConnection, $sent_folder)) {
28 sqimap_subscribe($imapConnection, $sent_folder);
29 }
30 }
31 if (isset ($trash_folder) && $trash_folder != "none") {
32 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)) {
33 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
34 } else if (! sqimap_mailbox_is_subscribed($imapConnection, $trash_folder)) {
35 sqimap_subscribe($imapConnection, $trash_folder);
36 }
37 }
38 $auto_create_done = true;
39 session_register('auto_create_done');
40 }
41
42 function formatMailboxName($imapConnection, $box_array, $delimeter) {
43 global $folder_prefix, $trash_folder, $sent_folder;
44 global $color, $move_to_sent, $move_to_trash;
45 global $unseen_notify, $unseen_type, $collapse_folders;
46
47 $real_box = $box_array['unformatted'];
48 $mailbox = str_replace('&nbsp;',' ',$box_array['formatted']);
49 $mailboxURL = urlencode($real_box);
50
51 $unseen = 0;
52
53 if (($unseen_notify == 2 && $real_box == "INBOX") ||
54 $unseen_notify == 3) {
55 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
56 if ($unseen_type == 1 && $unseen > 0) {
57 $unseen_string = "($unseen)";
58 $unseen_found = true;
59 } else if ($unseen_type == 2) {
60 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
61 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
62 $unseen_found = true;
63 }
64 }
65
66 $special_color = false;
67 if ((strtolower($real_box) == "inbox") ||
68 (($real_box == $trash_folder) && ($move_to_trash)) ||
69 (($real_box == $sent_folder) && ($move_to_sent)))
70 $special_color = true;
71
72 $spaces = '';
73 $line = "<NOBR>";
74 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
75 $spaces = $regs[1];
76 $mailbox = $regs[2];
77 }
78
79 if ($unseen > 0)
80 $line .= '&nbsp;<B>';
81 $line .= str_replace(' ', '&nbsp;', $spaces);
82
83 if ($collapse_folders) {
84 if (isset($box_array['parent']))
85 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
86 else
87 $line .= '<tt>&nbsp;</tt>&nbsp;&nbsp;';
88 }
89
90 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
91 if ($special_color == true)
92 $line .= "<FONT COLOR=\"$color[11]\">";
93 $line .= str_replace(' ','&nbsp;',$mailbox);
94 if ($special_color == true)
95 $line .= "</font>";
96 $line .= '</a>';
97
98 if ($unseen > 0)
99 $line .= "</B>";
100
101 if (isset($unseen_found) && $unseen_found) {
102 $line .= "&nbsp;<small>$unseen_string</small>";
103 }
104
105 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
106 if (! isset($numMessages))
107 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
108
109 if ($numMessages > 0)
110 {
111 $urlMailbox = urlencode($real_box);
112 $line .= "\n<small>\n";
113 $line .= " &nbsp; (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
114 $line .= "\n</small>\n";
115 }
116 }
117 $line .= "</NOBR>";
118 return $line;
119 }
120
121 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
122 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
123 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
124 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
125 }
126
127 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
128
129 do_hook("left_main_before");
130
131 $boxes = sqimap_mailbox_list($imapConnection);
132
133 echo "<CENTER><FONT SIZE=4><B>";
134 echo _("Folders") . "</B><BR></FONT>\n\n";
135
136 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
137 echo _("refresh folder list");
138 echo "</A>)</small></CENTER><BR>";
139 $delimeter = sqimap_get_delimiter($imapConnection);
140
141 if (isset($collapse_folders) && $collapse_folders) {
142 if (isset($fold))
143 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
144 if (isset($unfold))
145 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
146 $IAmAParent = array();
147 for ($i = 0; $i < count($boxes); $i ++) {
148 $parts = explode($delimeter, $boxes[$i]['unformatted']);
149 $box_name = array_pop($parts);
150 $box_parent = implode($delimeter, $parts);
151 $hidden = 0;
152 if (isset($box_parent)) {
153 $hidden = getPref($data_dir, $username,
154 'collapse_folder_' . $box_parent);
155 $IAmAParent[$box_parent] = $hidden;
156 }
157 $boxes[$i]['folded'] = $hidden;
158 }
159 }
160
161 for ($i = 0;$i < count($boxes); $i++) {
162 if (! isset($boxes[$i]['folded']) || ! $boxes[$i]['folded'])
163 {
164 $line = "";
165 $mailbox = $boxes[$i]["formatted"];
166
167 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
168 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
169 }
170
171 if (in_array('noselect', $boxes[$i]['flags'])) {
172 $line .= "<FONT COLOR=\"$color[10]\">";
173 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
174 $line .= str_replace(' ', '&nbsp;', $mailbox);
175 if (isset($boxes[$i]['parent']))
176 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
177 elseif ($collapse_folders)
178 $line .= '<tt>&nbsp;</tt>&nbsp;';
179 }
180 $line .= '</FONT>';
181 } else {
182 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
183 }
184 echo "$line<BR>\n";
185 }
186 }
187 sqimap_logout($imapConnection);
188 do_hook("left_main_after");
189
190 function FoldLink($mailbox, $folded) {
191 $mailbox = urlencode($mailbox);
192 $link = '&nbsp;<tt><a target="left" style="text-decoration:none" ';
193 $link .= 'href="left_main.php?';
194 if ($folded)
195 $link .= "unfold=$mailbox\">+";
196 else
197 $link .= "fold=$mailbox\">-";
198 $link .= '</a></tt>&nbsp;';
199 return ($link);
200 }
201
202 ?>
203 </BODY></HTML>