59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * left_main.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This is the code for the left bar. The left bar shows the folders |
10 | * available, and has cookie information. |
11 | * |
12 | * $Id$ |
1c52ba77 |
13 | */ |
35586184 |
14 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
17 | |
18 | /* SquirrelMail required files. */ |
08185f2a |
19 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
20 | require_once(SM_PATH . 'functions/imap.php'); |
21 | require_once(SM_PATH . 'functions/plugin.php'); |
22 | require_once(SM_PATH . 'functions/page_header.php'); |
23 | require_once(SM_PATH . 'functions/html.php'); |
142499d4 |
24 | |
95e93571 |
25 | /* These constants are used for folder stuff. */ |
26 | define('SM_BOX_UNCOLLAPSED', 0); |
27 | define('SM_BOX_COLLAPSED', 1); |
a6d2e0de |
28 | |
2d367c68 |
29 | /* --------------------- FUNCTIONS ------------------------- */ |
525b7ae6 |
30 | |
95e93571 |
31 | function formatMailboxName($imapConnection, $box_array) { |
1c52ba77 |
32 | |
90de1755 |
33 | global $folder_prefix, $trash_folder, $sent_folder, |
34 | $color, $move_to_sent, $move_to_trash, |
35 | $unseen_notify, $unseen_type, $collapse_folders, |
36 | $draft_folder, $save_as_draft, |
37 | $use_special_folder_color; |
94f3a73b |
38 | |
95e93571 |
39 | $real_box = $box_array['unformatted']; |
40 | $mailbox = str_replace(' ','',$box_array['formatted']); |
41 | $mailboxURL = urlencode($real_box); |
21c3249f |
42 | |
95e93571 |
43 | /* Strip down the mailbox name. */ |
44 | if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) { |
45 | $mailbox = $regs[2]; |
46 | } |
ae012102 |
47 | $unseen = 0; |
48 | $status = array(); |
49 | if (($unseen_notify == 2 && $real_box == 'INBOX') || |
50 | $unseen_notify == 3) { |
51 | $status = create_unseen_string($real_box, $box_array, $imapConnection, $unseen_type ); |
52 | if ($status !== false) { |
53 | list($unseen_string, $unseen) = $status; |
54 | } else { |
55 | list($unseen_string, $unseen) = array(_("Not available"),''); |
56 | } |
474fc5fa |
57 | } else { |
ae012102 |
58 | list($unseen_string, $unseen) = array('',''); |
474fc5fa |
59 | } |
ffb1a3d9 |
60 | $special_color = ($use_special_folder_color && isSpecialMailbox($real_box)); |
f7b1b3b1 |
61 | |
95e93571 |
62 | /* Start off with a blank line. */ |
63 | $line = ''; |
235a65d5 |
64 | |
95e93571 |
65 | /* If there are unseen message, bold the line. */ |
66 | if ($unseen > 0) { $line .= '<B>'; } |
a6d2e0de |
67 | |
fb0ca797 |
68 | /* Create the link for this folder. */ |
474fc5fa |
69 | if ($status !== false) { |
70 | $line .= '<a href="right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox='. |
71 | $mailboxURL.'" TARGET="right" STYLE="text-decoration:none">'; |
72 | } |
1c52ba77 |
73 | if ($special_color) { |
3fde693b |
74 | $line .= "<font color=\"$color[11]\">"; |
1c52ba77 |
75 | } |
a551489c |
76 | if ( $mailbox == 'INBOX' ) { |
77 | $line .= _("INBOX"); |
78 | } else { |
79 | $line .= str_replace(' ',' ',$mailbox); |
80 | } |
90de1755 |
81 | if ($special_color == TRUE) |
3fde693b |
82 | $line .= '</font>'; |
474fc5fa |
83 | if ($status !== false) { |
84 | $line .= '</a>'; |
85 | } |
a6d2e0de |
86 | |
95e93571 |
87 | /* If there are unseen message, close bolding. */ |
88 | if ($unseen > 0) { $line .= "</B>"; } |
2d367c68 |
89 | |
95e93571 |
90 | /* Print unseen information. */ |
ffb1a3d9 |
91 | if ($unseen_string != '') { |
95e93571 |
92 | $line .= " <SMALL>$unseen_string</SMALL>"; |
2016e645 |
93 | } |
94 | |
1c52ba77 |
95 | if (($move_to_trash) && ($real_box == $trash_folder)) { |
95e93571 |
96 | if (! isset($numMessages)) { |
97 | $numMessages = sqimap_get_num_messages($imapConnection, $real_box); |
a6d2e0de |
98 | } |
a6d2e0de |
99 | |
95e93571 |
100 | if ($numMessages > 0) { |
101 | $urlMailbox = urlencode($real_box); |
102 | $line .= "\n<small>\n" . |
eb3b5319 |
103 | " (<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A>)" . |
7fb54066 |
104 | "</small>"; |
a6d2e0de |
105 | } |
106 | } |
a6d2e0de |
107 | |
95e93571 |
108 | /* Return the final product. */ |
109 | return ($line); |
110 | } |
a6d2e0de |
111 | |
95e93571 |
112 | /** |
113 | * Recursive function that computes the collapsed status and parent |
114 | * (or not parent) status of this box, and the visiblity and collapsed |
115 | * status and parent (or not parent) status for all children boxes. |
116 | */ |
117 | function compute_folder_children(&$parbox, $boxcount) { |
118 | global $boxes, $data_dir, $username, $collapse_folders; |
119 | $nextbox = $parbox + 1; |
120 | |
121 | /* Retreive the name for the parent box. */ |
122 | $parbox_name = $boxes[$parbox]['unformatted']; |
123 | |
124 | /* 'Initialize' this parent box to childless. */ |
1c52ba77 |
125 | $boxes[$parbox]['parent'] = FALSE; |
95e93571 |
126 | |
127 | /* Compute the collapse status for this box. */ |
128 | if( isset($collapse_folders) && $collapse_folders ) { |
129 | $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name); |
130 | $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); |
131 | } else { |
132 | $collapse = SM_BOX_UNCOLLAPSED; |
a6d2e0de |
133 | } |
95e93571 |
134 | $boxes[$parbox]['collapse'] = $collapse; |
2d367c68 |
135 | |
95e93571 |
136 | /* Otherwise, get the name of the next box. */ |
1c52ba77 |
137 | if (isset($boxes[$nextbox]['unformatted'])) { |
95e93571 |
138 | $nextbox_name = $boxes[$nextbox]['unformatted']; |
1c52ba77 |
139 | } else { |
95e93571 |
140 | $nextbox_name = ''; |
1c52ba77 |
141 | } |
a6d2e0de |
142 | |
95e93571 |
143 | /* Compute any children boxes for this box. */ |
144 | while (($nextbox < $boxcount) && |
145 | (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) { |
a6d2e0de |
146 | |
95e93571 |
147 | /* Note that this 'parent' box has at least one child. */ |
1c52ba77 |
148 | $boxes[$parbox]['parent'] = TRUE; |
a6d2e0de |
149 | |
95e93571 |
150 | /* Compute the visiblity of this box. */ |
1c52ba77 |
151 | $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] && |
152 | ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)); |
a6d2e0de |
153 | |
95e93571 |
154 | /* Compute the visibility of any child boxes. */ |
155 | compute_folder_children($nextbox, $boxcount); |
156 | } |
2d367c68 |
157 | |
95e93571 |
158 | /* Set the parent box to the current next box. */ |
159 | $parbox = $nextbox; |
160 | } |
2d367c68 |
161 | |
95e93571 |
162 | /** |
163 | * Create the link for a parent folder that will allow that |
164 | * parent folder to either be collapsed or expaned, as is |
165 | * currently appropriate. |
166 | */ |
167 | function create_collapse_link($boxnum) { |
70bf5a7f |
168 | global $boxes, $imapConnection, $unseen_notify, $color; |
95e93571 |
169 | $mailbox = urlencode($boxes[$boxnum]['unformatted']); |
70bf5a7f |
170 | |
95e93571 |
171 | /* Create the link for this collapse link. */ |
90de1755 |
172 | $link = '<a target="left" style="text-decoration:none" ' . |
173 | 'href="left_main.php?'; |
95e93571 |
174 | if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED) { |
ffb1a3d9 |
175 | $link .= "unfold=$mailbox\">+"; |
176 | } else { |
177 | $link .= "fold=$mailbox\">-"; |
178 | } |
179 | $link .= '</a>'; |
180 | |
181 | /* Return the finished product. */ |
182 | return ($link); |
183 | } |
184 | |
185 | /** |
186 | * create_unseen_string: |
187 | * |
188 | * Create unseen and total message count for both this folder and |
189 | * it's subfolders. |
190 | * |
191 | * @param string $boxName name of the current mailbox |
192 | * @param array $boxArray array for the current mailbox |
193 | * @param $imapConnection current imap connection in use |
194 | * @return array[0] unseen message string (for display) |
195 | * @return array[1] unseen message count |
196 | */ |
ae012102 |
197 | function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) { |
474fc5fa |
198 | global $boxes, $unseen_type, $color, $unseen_cum; |
ffb1a3d9 |
199 | |
200 | /* Initialize the return value. */ |
0210ab4d |
201 | $result = array(0,0); |
ffb1a3d9 |
202 | |
203 | /* Initialize the counts for this folder. */ |
204 | $boxUnseenCount = 0; |
205 | $boxMessageCount = 0; |
206 | $totalUnseenCount = 0; |
207 | $totalMessageCount = 0; |
208 | |
209 | /* Collect the counts for this box alone. */ |
474fc5fa |
210 | $status = sqimap_status_messages($imapConnection, $boxName); |
211 | $boxUnseenCount = $status['UNSEEN']; |
212 | if ($boxUnseenCount === false) { |
213 | return false; |
214 | } |
ffb1a3d9 |
215 | if ($unseen_type == 2) { |
474fc5fa |
216 | $boxMessageCount = $status['MESSAGES']; |
ffb1a3d9 |
217 | } |
70bf5a7f |
218 | |
22986991 |
219 | /* Initialize the total counts. */ |
220 | |
474fc5fa |
221 | if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) { |
ffb1a3d9 |
222 | /* Collect the counts for this boxes subfolders. */ |
223 | $curBoxLength = strlen($boxName); |
224 | $boxCount = count($boxes); |
22986991 |
225 | |
ffb1a3d9 |
226 | for ($i = 0; $i < $boxCount; ++$i) { |
227 | /* Initialize the counts for this subfolder. */ |
228 | $subUnseenCount = 0; |
229 | $subMessageCount = 0; |
230 | |
231 | /* Collect the counts for this subfolder. */ |
232 | if (($boxName != $boxes[$i]['unformatted']) |
233 | && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName) |
234 | && !in_array('noselect', $boxes[$i]['flags'])) { |
474fc5fa |
235 | $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']); |
236 | $subUnseenCount = $status['UNSEEN']; |
ffb1a3d9 |
237 | if ($unseen_type == 2) { |
474fc5fa |
238 | $subMessageCount = $status['MESSAGES'];; |
70bf5a7f |
239 | } |
22986991 |
240 | /* Add the counts for this subfolder to the total. */ |
241 | $totalUnseenCount += $subUnseenCount; |
242 | $totalMessageCount += $subMessageCount; |
243 | } |
70bf5a7f |
244 | } |
22986991 |
245 | |
246 | /* Add the counts for all subfolders to that of the box. */ |
247 | $boxUnseenCount += $totalUnseenCount; |
248 | $boxMessageCount += $totalMessageCount; |
ffb1a3d9 |
249 | } |
250 | |
251 | /* And create the magic unseen count string. */ |
252 | /* Really a lot more then just the unseen count. */ |
253 | if (($unseen_type == 1) && ($boxUnseenCount > 0)) { |
22986991 |
254 | $result[0] = "($boxUnseenCount)"; |
ffb1a3d9 |
255 | } else if ($unseen_type == 2) { |
22986991 |
256 | $result[0] = "($boxUnseenCount/$boxMessageCount)"; |
ffb1a3d9 |
257 | $result[0] = "<font color=\"$color[11]\">$result[0]</font>"; |
70bf5a7f |
258 | } |
ffb1a3d9 |
259 | |
22986991 |
260 | /* Set the unseen count to return to the outside world. */ |
ffb1a3d9 |
261 | $result[1] = $boxUnseenCount; |
2d367c68 |
262 | |
ffb1a3d9 |
263 | /* Return our happy result. */ |
264 | return ($result); |
95e93571 |
265 | } |
266 | |
267 | /** |
268 | * This simple function checks if a box is another box's parent. |
269 | */ |
270 | function is_parent_box($curbox_name, $parbox_name) { |
271 | global $delimiter; |
272 | |
273 | /* Extract the name of the parent of the current box. */ |
274 | $curparts = explode($delimiter, $curbox_name); |
275 | $curname = array_pop($curparts); |
276 | $actual_parname = implode($delimiter, $curparts); |
277 | $actual_parname = substr($actual_parname,0,strlen($parbox_name)); |
278 | |
279 | /* Compare the actual with the given parent name. */ |
280 | return ($parbox_name == $actual_parname); |
281 | } |
282 | |
f23f6a3a |
283 | function listBoxes ($boxes, $j=0 ) { |
284 | global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type, |
285 | $move_to_trash, $trash_folder, $collapse_folders; |
286 | $pre = ''; |
287 | $end = ''; |
288 | $collapse = false; |
289 | if ($boxes) { |
290 | $mailbox = $boxes->mailboxname_full; |
291 | $leader = ''; |
292 | for ($k = 0; $k < $j; $k++) { |
293 | $leader.= '   '; |
294 | } |
295 | $mailboxURL = urlencode($mailbox); |
296 | |
297 | /* get unseen/total messages information */ |
298 | if ($boxes->unseen) { |
299 | $unseen = $boxes->unseen; |
300 | $unseen_string = "($unseen)"; |
301 | if ($unseen>0) $unseen_found = TRUE; |
302 | if ($boxes->total) { |
303 | $numMessages = $boxes->total; |
304 | $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>"; |
305 | } |
306 | } else $unseen = 0; |
307 | |
308 | |
309 | |
310 | if (isset($boxes->mbxs[0]) && $collapse_folders) { |
311 | $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox); |
312 | $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); |
313 | |
314 | $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?'; |
315 | if ($collapse) { |
316 | $link .= "unfold=$mailboxURL\">$leader + "; |
317 | } else { |
318 | $link .= "fold=$mailboxURL\">$leader - "; |
319 | } |
320 | $link .= '</a>'; |
321 | $pre .= $link; |
322 | } else { |
323 | $pre.= $leader . '   '; |
324 | } |
325 | |
326 | |
327 | /* If there are unseen message, bold the line. */ |
328 | if ($unseen > 0) { $pre .= '<B>'; } |
329 | |
330 | if (($move_to_trash) && ($mailbox == $trash_folder)) { |
331 | if (! isset($numMessages)) { |
474fc5fa |
332 | $status = sqimap_status_messages($imapConnection, $mailbox); |
333 | $numMessages = $status['MESSAGES']; |
f23f6a3a |
334 | } |
335 | |
336 | if ($numMessages > 0) { |
337 | $urlMailbox = urlencode($mailbox); |
338 | $pre .= "\n<small>\n" . |
339 | " (<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A>)" . |
340 | "</small>"; |
341 | } |
342 | } else { |
343 | if (!$boxes->is_noselect) { |
c8fa94cf |
344 | $pre .= "<a HREF=\"right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\">"; |
f23f6a3a |
345 | $end .= '</a>'; |
346 | } |
347 | } |
348 | |
349 | /* If there are unseen message, close bolding. */ |
350 | if ($unseen > 0) { $end .= "</B>"; } |
351 | |
352 | /* Print unseen information. */ |
353 | if (isset($unseen_found) && $unseen_found) { |
354 | $end .= " <SMALL>$unseen_string</SMALL>"; |
355 | } |
356 | |
357 | $font = ''; |
358 | $fontend = ''; |
359 | if ($boxes->is_special) { |
360 | $font = "<FONT COLOR=\"$color[11]\">"; |
361 | $fontend = "</FONT>"; |
362 | } |
363 | |
364 | if (!$boxes->is_root) { |
365 | echo "" . $pre .$font. $boxes->mailboxname_sub .$fontend . $end. '<br>'; |
366 | $j++; |
367 | } |
368 | if (!$collapse || $boxes->is_root) { |
369 | for ($i = 0; $i <count($boxes->mbxs); $i++) { |
370 | listBoxes($boxes->mbxs[$i],$j); |
371 | } |
372 | } |
373 | |
374 | } |
375 | } |
376 | |
c8fa94cf |
377 | function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) { |
f23f6a3a |
378 | global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type, |
379 | $move_to_trash, $trash_folder, $collapse_folders; |
380 | |
381 | /* use_folder_images only works if the images exist in ../images */ |
c8fa94cf |
382 | $use_folder_images = true; |
f23f6a3a |
383 | |
384 | $pre = ''; |
385 | $end = ''; |
386 | $collapse = false; |
387 | |
388 | if ($boxes) { |
389 | $mailbox = $boxes->mailboxname_full; |
390 | $mailboxURL = urlencode($mailbox); |
391 | |
392 | /* get unseen/total messages information */ |
393 | if ($boxes->unseen) { |
394 | $unseen = $boxes->unseen; |
395 | $unseen_string = "($unseen)"; |
396 | if ($unseen>0) $unseen_found = TRUE; |
397 | if ($boxes->total) { |
398 | $numMessages = $boxes->total; |
399 | $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>"; |
400 | } |
401 | } else $unseen = 0; |
402 | |
f23f6a3a |
403 | /* If there are unseen message, bold the line. */ |
404 | if ($unseen > 0) { $pre .= '<B>'; } |
405 | |
c8fa94cf |
406 | /* color special boxes */ |
407 | if ($boxes->is_special) { |
408 | $pre .= "<FONT COLOR=\"$color[11]\">"; |
409 | $end .= "</FONT>"; |
410 | } |
411 | |
412 | /* If there are unseen message, close bolding. */ |
413 | if ($unseen > 0) { $end .= "</B>"; } |
414 | |
415 | /* Print unseen information. */ |
416 | if (isset($unseen_found) && $unseen_found) { |
417 | $end .= " $unseen_string"; |
418 | } |
419 | |
f23f6a3a |
420 | if (($move_to_trash) && ($mailbox == $trash_folder)) { |
421 | if (! isset($numMessages)) { |
422 | $numMessages = $boxes->total; |
423 | } |
424 | if ($numMessages > 0) { |
425 | $urlMailbox = urlencode($mailbox); |
426 | $pre .= "\n<small>\n" . |
c8fa94cf |
427 | " (<a class=\"mbx_link\" HREF=\"empty_trash.php\">"._("purge")."</a>)" . |
f23f6a3a |
428 | "</small>"; |
429 | } |
430 | } else { |
431 | if (!$boxes->is_noselect) { /* \Noselect boxes can't be selected */ |
c8fa94cf |
432 | $pre .= "<a class=\"mbx_link\" HREF=\"right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\">"; |
f23f6a3a |
433 | $end .= '</a>'; |
434 | } |
435 | } |
436 | |
f23f6a3a |
437 | if (!$boxes->is_root) { |
438 | if ($use_folder_images) { |
439 | if ($boxes->is_inbox) { |
440 | $folder_img = '../images/inbox.gif'; |
441 | } else if ($boxes->is_sent) { |
442 | $folder_img = '../images/senti.gif'; |
443 | } else if ($boxes->is_trash) { |
444 | $folder_img = '../images/delitem.gif'; |
445 | } else if ($boxes->is_draft) { |
446 | $folder_img = '../images/draft.gif'; |
447 | } else $folder_img = '../images/folder.gif'; |
c8fa94cf |
448 | $folder_img = ' <img src="'.$folder_img.'" height="15" valign="center"> '; |
f23f6a3a |
449 | } else $folder_img = ''; |
450 | if (!isset($boxes->mbxs[0])) { |
3fde693b |
451 | echo ' ' . html_tag( 'div', |
c8fa94cf |
452 | $pre . $folder_img . $boxes->mailboxname_sub . $end , |
453 | 'left', '', 'class="mbx_sub" id="' .$j. '"' ) |
3fde693b |
454 | . "\n"; |
f23f6a3a |
455 | } else { |
456 | /* get collapse information */ |
457 | if ($collapse_folders) { |
458 | $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?'; |
459 | $form_entry = $j.'F'; |
460 | if (isset($mbx) && isset($mbx[$form_entry])) { |
461 | $collapse = $mbx[$form_entry]; |
462 | if ($collapse) { |
463 | setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , SM_BOX_COLLAPSED); |
464 | } else { |
465 | setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , SM_BOX_UNCOLLAPSED); |
466 | } |
467 | } else { |
468 | $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox); |
469 | $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); |
470 | } |
471 | if ($collapse) { |
599038d5 |
472 | $link = '<a href="javascript:void(0)">'." <img src=\"../images/plus.gif\" border=\"1\" id=$j onclick=\"hidechilds(this)\"></A>"; |
f23f6a3a |
473 | } else { |
599038d5 |
474 | $link = '<a href="javascript:void(0)">'."<img src=\"../images/minus.gif\" border=\"1\" id=$j onclick=\"hidechilds(this)\"></a>"; |
f23f6a3a |
475 | } |
476 | $collapse_link = $link; |
477 | } else $collapse_link=''; |
3fde693b |
478 | echo ' ' . html_tag( 'div', |
c8fa94cf |
479 | $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub . $end , |
480 | 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) |
3fde693b |
481 | . "\n"; |
c8fa94cf |
482 | echo ' <INPUT TYPE="hidden" name=mbx['.$j. 'F] value="'.$collapse.'" id="mbx['.$j.'F]">'."\n"; |
f23f6a3a |
483 | } |
484 | } |
485 | if ($collapse) { |
486 | $visible = ' STYLE="display:none;"'; |
487 | } else { |
386e556f |
488 | $visible = ' STYLE="display:block;"'; |
f23f6a3a |
489 | } |
490 | |
491 | if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */ |
c8fa94cf |
492 | echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n"; |
3fde693b |
493 | |
c8fa94cf |
494 | if ($j !='ID.0000') { |
495 | $j = $j .'.0000'; |
f23f6a3a |
496 | } |
497 | for ($i = 0; $i <count($boxes->mbxs); $i++) { |
498 | $j++; |
499 | listAdvancedBoxes($boxes->mbxs[$i],$mbx,$j); |
500 | } |
501 | if (isset($boxes->mbxs[0]) && !$boxes->is_root ) echo '</div>'."\n\n"; |
502 | } |
503 | } |
504 | |
505 | |
506 | |
95e93571 |
507 | |
508 | /* -------------------- MAIN ------------------------ */ |
509 | |
a32985a5 |
510 | $key = $_COOKIE['key']; |
511 | $onetimepad = $_SESSION['onetimepad']; |
512 | $username = $_SESSION['username']; |
513 | $delimiter = $_SESSION['delimiter']; |
514 | |
515 | if (isset($_GET['fold'])) { |
516 | $fold = $_GET['fold']; |
517 | } |
518 | if (isset($_GET['unfold'])) { |
519 | $unfold = $_GET['unfold']; |
520 | } |
95e93571 |
521 | |
522 | // open a connection on the imap port (143) |
523 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output |
524 | |
f43c35f8 |
525 | /** |
526 | * Using stristr since older preferences may contain "None" and "none". |
527 | */ |
528 | if (isset($left_refresh) && ($left_refresh != '') && |
529 | !stristr($left_refresh, "none")){ |
95e93571 |
530 | $xtra = "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" . |
531 | "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n". |
532 | "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n"; |
533 | } else { |
534 | $xtra = ''; |
535 | } |
536 | |
f23f6a3a |
537 | /** |
538 | * $advanced_tree and $oldway are boolean vars which are default set to default |
539 | * SM behaviour. |
540 | * Setting $oldway to false causes left_main.php to use the new experimental |
541 | * way of getting the mailbox-tree. |
542 | * Setting $advanced tree to true causes SM to display a experimental |
543 | * mailbox-tree with dhtml behaviour. |
544 | * It only works on browsers which supports css and javascript. The used |
545 | * javascript is experimental and doesn't support all browsers. It is tested on |
546 | * IE6 an Konquerer 3.0.0-2. |
547 | * In the function ListAdvancedBoxes there is another var $use_folder_images. |
548 | * setting this to true is only usefull if the images exists in ../images. |
549 | * |
550 | * Feel free to experiment with the code and report bugs and enhancements |
551 | * to marc@its-projects.nl |
552 | **/ |
553 | |
554 | $advanced_tree = false; /* set this to true if you want to see a nicer mailboxtree */ |
555 | $oldway = true; /* default SM behaviour */ |
556 | |
557 | if ($advanced_tree) { |
558 | $xtra .= <<<ECHO |
599038d5 |
559 | <script language="Javascript" TYPE="text/javascript"> |
f23f6a3a |
560 | |
599038d5 |
561 | <!-- |
f23f6a3a |
562 | |
563 | function hidechilds(el) { |
c8fa94cf |
564 | id = el.id+".0000"; |
f23f6a3a |
565 | form_id = "mbx[" + el.id +"F]"; |
566 | if (document.all) { |
567 | ele = document.all[id]; |
599038d5 |
568 | if (ele) { |
569 | if(ele.style.display == "none") { |
570 | ele.style.display = "block"; |
571 | ele.style.visibility = "visible" |
c8fa94cf |
572 | el.src="../images/minus.gif"; |
599038d5 |
573 | document.all[form_id].value=0; |
574 | } else { |
575 | ele.style.display = "none"; |
576 | ele.style.visibility = "hidden" |
c8fa94cf |
577 | el.src="../images/plus.gif"; |
599038d5 |
578 | document.all[form_id].value=1; |
579 | } |
f23f6a3a |
580 | } |
581 | } else if (document.getElementById) { |
f23f6a3a |
582 | ele = document.getElementById(id); |
599038d5 |
583 | if (ele) { |
584 | if(ele.style.display == "none") { |
585 | ele.style.display = "block"; |
586 | ele.style.visibility = "visible" |
c8fa94cf |
587 | el.src="../images/minus.gif"; |
599038d5 |
588 | document.getElementById(form_id).value=0; |
589 | } else { |
590 | ele.style.display = "none"; |
591 | ele.style.visibility = "hidden" |
c8fa94cf |
592 | el.src="../images/plus.gif"; |
599038d5 |
593 | document.getElementById(form_id).value=1; |
594 | } |
595 | } |
f23f6a3a |
596 | } |
597 | } |
598 | |
599 | function preload() { |
600 | if (!document.images) return; |
601 | var ar = new Array(); |
602 | var arguments = preload.arguments; |
603 | for (var i = 0; i<arguments.length; i++) { |
604 | ar[i] = new Image(); |
605 | ar[i].src = arguments[i]; |
606 | } |
607 | } |
608 | |
f23f6a3a |
609 | function buttonover(el,on) { |
610 | if (!on) { |
611 | el.style.borderColor="blue";} |
612 | else { |
613 | el.style.borderColor="orange";} |
614 | } |
615 | |
616 | function buttonclick(el,on) { |
617 | if (!on) { |
618 | el.style.border="groove"} |
619 | else { |
620 | el.style.border="ridge";} |
621 | } |
599038d5 |
622 | |
623 | function hideframe(hide) { |
624 | |
625 | ECHO; |
626 | $xtra .= " left_size = \"$left_size\";\n"; |
627 | $xtra .= <<<ECHO |
628 | if (document.all) { |
629 | masterf = window.parent.document.all["fs1"]; |
630 | leftf = window.parent.document.all["left"]; |
631 | leftcontent = document.all["leftframe"]; |
632 | leftbutton = document.all["showf"]; |
633 | } else if (document.getElementById) { |
634 | masterf = window.parent.document.getElementById("fs1"); |
635 | leftf = window.parent.document.getElementById("left"); |
386e556f |
636 | leftcontent = document.getElementById("leftframe"); |
637 | leftbutton = document.getElementById("showf"); |
599038d5 |
638 | } else { |
639 | return false; |
640 | } |
641 | if(hide) { |
642 | new_col = calc_col("20"); |
643 | masterf.cols = new_col; |
644 | document.body.scrollLeft=0; |
645 | document.body.style.overflow='hidden'; |
646 | leftcontent.style.display = 'none'; |
647 | leftbutton.style.display='block'; |
648 | } else { |
649 | masterf.cols = calc_col(left_size); |
650 | document.body.style.overflow=''; |
651 | leftbutton.style.display='none'; |
652 | leftcontent.style.display='block'; |
653 | |
654 | } |
655 | } |
656 | |
657 | function calc_col(c_w) { |
658 | |
659 | ECHO; |
660 | if ($location_of_bar == 'right') { |
661 | $xtra .= ' right=true;'; |
662 | } else { |
663 | $xtra .= ' right=false;'; |
664 | } |
665 | $xtra .= "\n"; |
666 | $xtra .= <<<ECHO |
667 | if (right) { |
668 | new_col = '*,'+c_w; |
669 | } else { |
670 | new_col = c_w+',*'; |
671 | } |
672 | return new_col; |
673 | } |
674 | |
675 | function resizeframe(direction) { |
676 | if (document.all) { |
677 | masterf = window.parent.document.all["fs1"]; |
678 | } else if (document.getElementById) { |
679 | window.parent.document.getElementById("fs1"); |
680 | } else { |
681 | return false; |
682 | } |
683 | |
684 | ECHO; |
685 | if ($location_of_bar == 'right') { |
686 | $xtra .= ' colPat=/^\*,(\d+)$/;'; |
687 | } else { |
688 | $xtra .= ' colPat=/^(\d+),.*$/;'; |
689 | } |
690 | $xtra .= "\n"; |
691 | |
692 | $xtra .= <<<ECHO |
693 | old_col = masterf.cols; |
694 | colPat.exec(old_col); |
695 | |
696 | if (direction) { |
697 | new_col_width = parseInt(RegExp.$1) + 25; |
698 | |
699 | } else { |
700 | if (parseInt(RegExp.$1) > 35) { |
701 | new_col_width = parseInt(RegExp.$1) - 25; |
702 | } |
703 | } |
704 | masterf.cols = calc_col(new_col_width); |
705 | } |
706 | |
707 | //--> |
f23f6a3a |
708 | |
709 | </script> |
710 | |
711 | ECHO; |
712 | |
713 | /* style definitions */ |
386e556f |
714 | |
f23f6a3a |
715 | $xtra .= <<<ECHO |
716 | |
c8fa94cf |
717 | <STYLE TYPE="text/css"> |
f23f6a3a |
718 | <!-- |
599038d5 |
719 | body { |
720 | margin: 0px 0px 0px 0px; |
721 | padding: 5px 5px 5px 5px; |
722 | } |
c8fa94cf |
723 | |
f23f6a3a |
724 | .button { |
725 | border:outset; |
726 | border-color:blue; |
599038d5 |
727 | background:white; |
f23f6a3a |
728 | width:99%; |
729 | heigth:99%; |
730 | } |
731 | |
732 | .mbx_par { |
f23f6a3a |
733 | font-size:0.8em; |
599038d5 |
734 | margin-left:4px; |
735 | margin-right:0px; |
c8fa94cf |
736 | } |
599038d5 |
737 | |
c8fa94cf |
738 | a.mbx_link { |
739 | text-decoration: none; |
740 | background-color: $color[0]; |
741 | display: inline; |
742 | } |
743 | |
744 | a:hover.mbx_link { |
745 | background-color: $color[9]; |
746 | } |
747 | |
748 | a.mbx_link img { |
749 | border-style: none; |
f23f6a3a |
750 | } |
751 | |
752 | .mbx_sub { |
f23f6a3a |
753 | padding-left:5px; |
599038d5 |
754 | padding-right:0px; |
f23f6a3a |
755 | margin-left:4px; |
599038d5 |
756 | margin-right:0px; |
f23f6a3a |
757 | font-size:0.7em; |
758 | } |
759 | |
760 | .par_area { |
599038d5 |
761 | margin-top:0px; |
762 | margin-left:4px; |
763 | margin-right:0px; |
f23f6a3a |
764 | padding-left:10px; |
599038d5 |
765 | padding-bottom:5px; |
f23f6a3a |
766 | border-left: solid; |
767 | border-left-width:0.1em; |
768 | border-left-color:blue; |
769 | border-bottom: solid; |
770 | border-bottom-width:0.1em; |
771 | border-bottom-color:blue; |
c8fa94cf |
772 | display: block; |
f23f6a3a |
773 | } |
774 | |
775 | .mailboxes { |
f23f6a3a |
776 | padding-bottom:3px; |
599038d5 |
777 | margin-right:4px; |
778 | padding-right:4px; |
779 | margin-left:4px; |
780 | padding-left:4px; |
f23f6a3a |
781 | border: groove; |
782 | border-width:0.1em; |
783 | border-color:green; |
c8fa94cf |
784 | background: $color[0]; |
f23f6a3a |
785 | } |
786 | |
787 | --> |
788 | |
789 | </STYLE> |
790 | |
791 | ECHO; |
792 | |
793 | } |
794 | |
795 | |
796 | |
797 | |
95e93571 |
798 | displayHtmlHeader( 'SquirrelMail', $xtra ); |
799 | |
800 | /* If requested and not yet complete, attempt to autocreate folders. */ |
801 | if ($auto_create_special && !isset($auto_create_done)) { |
a3439b27 |
802 | $autocreate = array($sent_folder, $trash_folder, $draft_folder); |
95e93571 |
803 | foreach( $autocreate as $folder ) { |
a3439b27 |
804 | if (($folder != '') && ($folder != 'none')) { |
95e93571 |
805 | if ( !sqimap_mailbox_exists($imapConnection, $folder)) { |
806 | sqimap_mailbox_create($imapConnection, $folder, ''); |
a3439b27 |
807 | } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) { |
95e93571 |
808 | sqimap_subscribe($imapConnection, $folder); |
2d367c68 |
809 | } |
ebf18afa |
810 | } |
2d367c68 |
811 | } |
a6d2e0de |
812 | |
95e93571 |
813 | /* Let the world know that autocreation is complete! Hurrah! */ |
90de1755 |
814 | $auto_create_done = TRUE; |
a32985a5 |
815 | sqsession_register($auto_create_done, 'auto_create_done'); |
95e93571 |
816 | } |
a6d2e0de |
817 | |
95e93571 |
818 | echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n"; |
a6d2e0de |
819 | |
95e93571 |
820 | do_hook('left_main_before'); |
1053f1e5 |
821 | if ($advanced_tree) { |
599038d5 |
822 | /* nice future feature, needs layout !! volunteers? */ |
823 | $right_pos = $left_size - 20; |
824 | echo '<div style="position:absolute;top:0;border=solid;border-width:0.1em;border-color:blue;"><div ID="hidef" style="width=20;font-size:12"><A HREF="javascript:hideframe(true)"><b><<</b></a></div>'; |
825 | echo '<div ID="showf" style="width=20;font-size:12;display:none;"><A HREF="javascript:hideframe(false)"><b>>></b></a></div>'; |
826 | echo '<div ID="incrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(true)"><b>></b></a></div>'; |
827 | echo '<div ID="decrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(false)"><b><</b></a></div></div>'; |
828 | echo '<div ID="leftframe"><br><br>'; |
829 | } |
2d367c68 |
830 | |
ee5b92f2 |
831 | echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) . |
3fde693b |
832 | html_tag( 'tr' ) . |
833 | html_tag( 'td', '', 'left' ) . |
834 | '<center><font size="4"><b>'. _("Folders") . "</b><br></font>\n\n"; |
a6d2e0de |
835 | |
95e93571 |
836 | if ($date_format != 6) { |
837 | /* First, display the clock. */ |
838 | if ($hour_format == 1) { |
839 | $hr = 'G:i'; |
840 | if ($date_format == 4) { |
841 | $hr .= ':s'; |
a6d2e0de |
842 | } |
95e93571 |
843 | } else { |
844 | if ($date_format == 4) { |
845 | $hr = 'g:i:s a'; |
846 | } else { |
847 | $hr = 'g:i a'; |
2d367c68 |
848 | } |
849 | } |
850 | |
95e93571 |
851 | switch( $date_format ) { |
852 | case 1: |
853 | $clk = date('m/d/y '.$hr, time()); |
854 | break; |
855 | case 2: |
856 | $clk = date('d/m/y '.$hr, time()); |
857 | break; |
858 | case 4: |
859 | case 5: |
860 | $clk = date($hr, time()); |
861 | break; |
862 | default: |
fc6f062a |
863 | $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() ); |
2d367c68 |
864 | } |
95e93571 |
865 | $clk = str_replace(' ',' ',$clk); |
866 | |
3fde693b |
867 | echo '<center><small>' . str_replace(' ',' ',_("Last Refresh")) . |
868 | ": $clk</small></center>"; |
95e93571 |
869 | } |
870 | |
871 | /* Next, display the refresh button. */ |
3fde693b |
872 | echo '<small>(<a href="../src/left_main.php" target="left">'. |
873 | _("refresh folder list") . '</a>)</small></center><br>'; |
95e93571 |
874 | |
875 | /* Lastly, display the folder list. */ |
876 | if ( $collapse_folders ) { |
877 | /* If directed, collapse or uncollapse a folder. */ |
878 | if (isset($fold)) { |
879 | setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED); |
880 | } else if (isset($unfold)) { |
881 | setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED); |
882 | } |
883 | } |
884 | |
f23f6a3a |
885 | if ($oldway) { /* normal behaviour SM */ |
886 | |
887 | $boxes = sqimap_mailbox_list($imapConnection); |
95e93571 |
888 | /* Prepare do do out collapsedness and visibility computation. */ |
889 | $curbox = 0; |
890 | $boxcount = count($boxes); |
891 | |
892 | /* Compute the collapsedness and visibility of each box. */ |
90de1755 |
893 | |
95e93571 |
894 | while ($curbox < $boxcount) { |
895 | $boxes[$curbox]['visible'] = TRUE; |
896 | compute_folder_children($curbox, $boxcount); |
897 | } |
898 | |
90de1755 |
899 | |
1c52ba77 |
900 | for ($i = 0; $i < count($boxes); $i++) { |
95e93571 |
901 | if ( $boxes[$i]['visible'] ) { |
902 | $mailbox = $boxes[$i]['formatted']; |
903 | $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1; |
904 | |
905 | /* Create the prefix for the folder name and link. */ |
906 | $prefix = str_repeat(' ',$mblevel); |
907 | if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) { |
908 | $prefix = str_replace(' ',' ',substr($prefix,0,strlen($prefix)-2)). |
909 | create_collapse_link($i) . ' '; |
910 | } else { |
911 | $prefix = str_replace(' ',' ',$prefix); |
912 | } |
913 | $line = "<NOBR><TT>$prefix</TT>"; |
914 | |
915 | /* Add the folder name and link. */ |
1c52ba77 |
916 | if (! isset($color[15])) { |
05611cba |
917 | $color[15] = $color[6]; |
1c52ba77 |
918 | } |
90de1755 |
919 | |
95e93571 |
920 | if (in_array('noselect', $boxes[$i]['flags'])) { |
1c52ba77 |
921 | if( isSpecialMailbox( $boxes[$i]['unformatted']) ) { |
922 | $line .= "<FONT COLOR=\"$color[11]\">"; |
923 | } else { |
924 | $line .= "<FONT COLOR=\"$color[15]\">"; |
925 | } |
95e93571 |
926 | if (ereg("^( *)([^ ]*)", $mailbox, $regs)) { |
927 | $mailbox = str_replace(' ','',$mailbox); |
928 | $line .= str_replace(' ', ' ', $mailbox); |
2d367c68 |
929 | } |
95e93571 |
930 | $line .= '</FONT>'; |
931 | } else { |
932 | $line .= formatMailboxName($imapConnection, $boxes[$i]); |
933 | } |
2d367c68 |
934 | |
95e93571 |
935 | /* Put the final touches on our folder line. */ |
936 | $line .= "</NOBR><BR>\n"; |
2d367c68 |
937 | |
95e93571 |
938 | /* Output the line for this folder. */ |
939 | echo $line; |
2d367c68 |
940 | } |
95e93571 |
941 | } |
f23f6a3a |
942 | } else { /* expiremental code */ |
943 | $boxes = sqimap_mailbox_tree($imapConnection); |
944 | if (isset($advanced_tree) && $advanced_tree) { |
639ed047 |
945 | echo '<FORM name=collapse action="left_main.php" METHOD=POST ' . |
f23f6a3a |
946 | 'ENCTYPE="multipart/form-data"'."\n"; |
947 | echo '<small><button type="submit" class="button" onmouseover="buttonover(this,true)" onmouseout="buttonover(this,false)" onmousedown="buttonclick(this,true)" onmouseup="buttonclick(this,false)">'. _("Save folder tree") .'</button><br><br>'; |
948 | echo '<DIV ID=mailboxes CLASS=mailboxes>'."\n\n"; |
949 | if (!isset($mbx)) $mbx=NULL; |
950 | ListAdvancedBoxes($boxes, $mbx); |
951 | echo '</div></small>'."\n"; |
952 | echo '</FORM>'."\n"; |
953 | } else { |
954 | ListBoxes($boxes); |
955 | } |
956 | } /* if ($oldway) else ... */ |
95e93571 |
957 | do_hook('left_main_after'); |
76b684a5 |
958 | sqimap_logout($imapConnection); |
2d367c68 |
959 | |
3fde693b |
960 | echo '</td></tr></table>' . "\n". |
961 | "</div></body></html>\n"; |
2d367c68 |
962 | |
7fb54066 |
963 | ?> |