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