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