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