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