fe0a2ff7bbb855cb1a828c8f3f8635debb5675ee
[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\">";
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\">";
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.0000' ) {
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 = true;
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 /* If there are unseen message, bold the line. */
316 if ($unseen > 0) { $pre .= '<B>'; }
317
318 /* color special boxes */
319 if ($boxes->is_special) {
320 $pre .= "<FONT COLOR=\"$color[11]\">";
321 $end .= "</FONT>";
322 }
323
324 /* If there are unseen message, close bolding. */
325 if ($unseen > 0) { $end .= "</B>"; }
326
327 /* Print unseen information. */
328 if (isset($unseen_found) && $unseen_found) {
329 $end .= "&nbsp;$unseen_string";
330 }
331
332 if (($move_to_trash) && ($mailbox == $trash_folder)) {
333 if (! isset($numMessages)) {
334 $numMessages = $boxes->total;
335 }
336 if ($numMessages > 0) {
337 $urlMailbox = urlencode($mailbox);
338 $pre .= "\n<small>\n" .
339 "&nbsp;&nbsp;(<a class=\"mbx_link\" HREF=\"empty_trash.php\">"._("purge")."</a>)" .
340 "</small>";
341 }
342 } else {
343 if (!$boxes->is_noselect) { /* \Noselect boxes can't be selected */
344 $pre .= "<a class=\"mbx_link\" HREF=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" TARGET=\"right\">";
345 $end .= '</a>';
346 }
347 }
348
349 if (!$boxes->is_root) {
350 if ($use_folder_images) {
351 if ($boxes->is_inbox) {
352 $folder_img = '../images/inbox.gif';
353 } else if ($boxes->is_sent) {
354 $folder_img = '../images/senti.gif';
355 } else if ($boxes->is_trash) {
356 $folder_img = '../images/delitem.gif';
357 } else if ($boxes->is_draft) {
358 $folder_img = '../images/draft.gif';
359 } else $folder_img = '../images/folder.gif';
360 $folder_img = '&nbsp;<img src="'.$folder_img.'" height="15" valign="center">&nbsp;';
361 } else $folder_img = '';
362 if (!isset($boxes->mbxs[0])) {
363 echo ' ' . html_tag( 'div',
364 $pre . $folder_img . $boxes->mailboxname_sub . $end ,
365 'left', '', 'class="mbx_sub" id="' .$j. '"' )
366 . "\n";
367 } else {
368 /* get collapse information */
369 if ($collapse_folders) {
370 $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
371 $form_entry = $j.'F';
372 if (isset($mbx) && isset($mbx[$form_entry])) {
373 $collapse = $mbx[$form_entry];
374 if ($collapse) {
375 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , SM_BOX_COLLAPSED);
376 } else {
377 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , SM_BOX_UNCOLLAPSED);
378 }
379 } else {
380 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
381 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
382 }
383 if ($collapse) {
384 $link = '<a href="javascript:void(0)">'." <img src=\"../images/plus.gif\" border=\"1\" id=$j onclick=\"hidechilds(this)\"></A>";
385 } else {
386 $link = '<a href="javascript:void(0)">'."<img src=\"../images/minus.gif\" border=\"1\" id=$j onclick=\"hidechilds(this)\"></a>";
387 }
388 $collapse_link = $link;
389 } else $collapse_link='';
390 echo ' ' . html_tag( 'div',
391 $collapse_link . $pre . $folder_img . '&nbsp;'. $boxes->mailboxname_sub . $end ,
392 'left', '', 'class="mbx_par" id="' .$j. 'P"' )
393 . "\n";
394 echo ' <INPUT TYPE="hidden" name=mbx['.$j. 'F] value="'.$collapse.'" id="mbx['.$j.'F]">'."\n";
395 }
396 }
397 if ($collapse) {
398 $visible = ' STYLE="display:none;"';
399 } else {
400 $visible = ' STYLE="display:block;"';
401 }
402
403 if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */
404 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
405
406 if ($j !='ID.0000') {
407 $j = $j .'.0000';
408 }
409 for ($i = 0; $i <count($boxes->mbxs); $i++) {
410 $j++;
411 listAdvancedBoxes($boxes->mbxs[$i],$mbx,$j);
412 }
413 if (isset($boxes->mbxs[0]) && !$boxes->is_root ) echo '</div>'."\n\n";
414 }
415 }
416
417
418
419
420 /* -------------------- MAIN ------------------------ */
421
422 global $delimiter, $default_folder_prefix, $left_size;
423
424 // open a connection on the imap port (143)
425 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
426
427 /**
428 * Using stristr since older preferences may contain "None" and "none".
429 */
430 if (isset($left_refresh) && ($left_refresh != '') &&
431 !stristr($left_refresh, "none")){
432 $xtra = "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" .
433 "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n".
434 "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
435 } else {
436 $xtra = '';
437 }
438
439 /**
440 * $advanced_tree and $oldway are boolean vars which are default set to default
441 * SM behaviour.
442 * Setting $oldway to false causes left_main.php to use the new experimental
443 * way of getting the mailbox-tree.
444 * Setting $advanced tree to true causes SM to display a experimental
445 * mailbox-tree with dhtml behaviour.
446 * It only works on browsers which supports css and javascript. The used
447 * javascript is experimental and doesn't support all browsers. It is tested on
448 * IE6 an Konquerer 3.0.0-2.
449 * In the function ListAdvancedBoxes there is another var $use_folder_images.
450 * setting this to true is only usefull if the images exists in ../images.
451 *
452 * Feel free to experiment with the code and report bugs and enhancements
453 * to marc@its-projects.nl
454 **/
455
456 $advanced_tree = false; /* set this to true if you want to see a nicer mailboxtree */
457 $oldway = true; /* default SM behaviour */
458
459 if ($advanced_tree) {
460 $xtra .= <<<ECHO
461 <script language="Javascript" TYPE="text/javascript">
462
463 <!--
464
465 function hidechilds(el) {
466 id = el.id+".0000";
467 form_id = "mbx[" + el.id +"F]";
468 if (document.all) {
469 ele = document.all[id];
470 if (ele) {
471 if(ele.style.display == "none") {
472 ele.style.display = "block";
473 ele.style.visibility = "visible"
474 el.src="../images/minus.gif";
475 document.all[form_id].value=0;
476 } else {
477 ele.style.display = "none";
478 ele.style.visibility = "hidden"
479 el.src="../images/plus.gif";
480 document.all[form_id].value=1;
481 }
482 }
483 } else if (document.getElementById) {
484 ele = document.getElementById(id);
485 if (ele) {
486 if(ele.style.display == "none") {
487 ele.style.display = "block";
488 ele.style.visibility = "visible"
489 el.src="../images/minus.gif";
490 document.getElementById(form_id).value=0;
491 } else {
492 ele.style.display = "none";
493 ele.style.visibility = "hidden"
494 el.src="../images/plus.gif";
495 document.getElementById(form_id).value=1;
496 }
497 }
498 }
499 }
500
501 function preload() {
502 if (!document.images) return;
503 var ar = new Array();
504 var arguments = preload.arguments;
505 for (var i = 0; i<arguments.length; i++) {
506 ar[i] = new Image();
507 ar[i].src = arguments[i];
508 }
509 }
510
511 function buttonover(el,on) {
512 if (!on) {
513 el.style.borderColor="blue";}
514 else {
515 el.style.borderColor="orange";}
516 }
517
518 function buttonclick(el,on) {
519 if (!on) {
520 el.style.border="groove"}
521 else {
522 el.style.border="ridge";}
523 }
524
525 function hideframe(hide) {
526
527 ECHO;
528 $xtra .= " left_size = \"$left_size\";\n";
529 $xtra .= <<<ECHO
530 if (document.all) {
531 masterf = window.parent.document.all["fs1"];
532 leftf = window.parent.document.all["left"];
533 leftcontent = document.all["leftframe"];
534 leftbutton = document.all["showf"];
535 } else if (document.getElementById) {
536 masterf = window.parent.document.getElementById("fs1");
537 leftf = window.parent.document.getElementById("left");
538 leftcontent = document.getElementById("leftframe");
539 leftbutton = document.getElementById("showf");
540 } else {
541 return false;
542 }
543 if(hide) {
544 new_col = calc_col("20");
545 masterf.cols = new_col;
546 document.body.scrollLeft=0;
547 document.body.style.overflow='hidden';
548 leftcontent.style.display = 'none';
549 leftbutton.style.display='block';
550 } else {
551 masterf.cols = calc_col(left_size);
552 document.body.style.overflow='';
553 leftbutton.style.display='none';
554 leftcontent.style.display='block';
555
556 }
557 }
558
559 function calc_col(c_w) {
560
561 ECHO;
562 if ($location_of_bar == 'right') {
563 $xtra .= ' right=true;';
564 } else {
565 $xtra .= ' right=false;';
566 }
567 $xtra .= "\n";
568 $xtra .= <<<ECHO
569 if (right) {
570 new_col = '*,'+c_w;
571 } else {
572 new_col = c_w+',*';
573 }
574 return new_col;
575 }
576
577 function resizeframe(direction) {
578 if (document.all) {
579 masterf = window.parent.document.all["fs1"];
580 } else if (document.getElementById) {
581 window.parent.document.getElementById("fs1");
582 } else {
583 return false;
584 }
585
586 ECHO;
587 if ($location_of_bar == 'right') {
588 $xtra .= ' colPat=/^\*,(\d+)$/;';
589 } else {
590 $xtra .= ' colPat=/^(\d+),.*$/;';
591 }
592 $xtra .= "\n";
593
594 $xtra .= <<<ECHO
595 old_col = masterf.cols;
596 colPat.exec(old_col);
597
598 if (direction) {
599 new_col_width = parseInt(RegExp.$1) + 25;
600
601 } else {
602 if (parseInt(RegExp.$1) > 35) {
603 new_col_width = parseInt(RegExp.$1) - 25;
604 }
605 }
606 masterf.cols = calc_col(new_col_width);
607 }
608
609 //-->
610
611 </script>
612
613 ECHO;
614
615 /* style definitions */
616
617 $xtra .= <<<ECHO
618
619 <STYLE TYPE="text/css">
620 <!--
621 body {
622 margin: 0px 0px 0px 0px;
623 padding: 5px 5px 5px 5px;
624 }
625
626 .button {
627 border:outset;
628 border-color:blue;
629 background:white;
630 width:99%;
631 heigth:99%;
632 }
633
634 .mbx_par {
635 font-size:0.8em;
636 margin-left:4px;
637 margin-right:0px;
638 }
639
640 a.mbx_link {
641 text-decoration: none;
642 background-color: $color[0];
643 display: inline;
644 }
645
646 a:hover.mbx_link {
647 background-color: $color[9];
648 }
649
650 a.mbx_link img {
651 border-style: none;
652 }
653
654 .mbx_sub {
655 padding-left:5px;
656 padding-right:0px;
657 margin-left:4px;
658 margin-right:0px;
659 font-size:0.7em;
660 }
661
662 .par_area {
663 margin-top:0px;
664 margin-left:4px;
665 margin-right:0px;
666 padding-left:10px;
667 padding-bottom:5px;
668 border-left: solid;
669 border-left-width:0.1em;
670 border-left-color:blue;
671 border-bottom: solid;
672 border-bottom-width:0.1em;
673 border-bottom-color:blue;
674 display: block;
675 }
676
677 .mailboxes {
678 padding-bottom:3px;
679 margin-right:4px;
680 padding-right:4px;
681 margin-left:4px;
682 padding-left:4px;
683 border: groove;
684 border-width:0.1em;
685 border-color:green;
686 background: $color[0];
687 }
688
689 -->
690
691 </STYLE>
692
693 ECHO;
694
695 }
696
697
698
699
700 displayHtmlHeader( 'SquirrelMail', $xtra );
701
702 /* If requested and not yet complete, attempt to autocreate folders. */
703 if ($auto_create_special && !isset($auto_create_done)) {
704 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
705 foreach( $autocreate as $folder ) {
706 if (($folder != '') && ($folder != 'none')) {
707 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
708 sqimap_mailbox_create($imapConnection, $folder, '');
709 } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
710 sqimap_subscribe($imapConnection, $folder);
711 }
712 }
713 }
714
715 /* Let the world know that autocreation is complete! Hurrah! */
716 $auto_create_done = TRUE;
717 session_register('auto_create_done');
718 }
719
720 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
721
722 do_hook('left_main_before');
723 if ($advanced_tree && $advanced_tree_frame_ctrl) {
724 /* nice future feature, needs layout !! volunteers? */
725 $right_pos = $left_size - 20;
726 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>';
727 echo '<div ID="showf" style="width=20;font-size:12;display:none;"><A HREF="javascript:hideframe(false)"><b>>></b></a></div>';
728 echo '<div ID="incrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(true)"><b>></b></a></div>';
729 echo '<div ID="decrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(false)"><b><</b></a></div></div>';
730 echo '<div ID="leftframe"><br><br>';
731 }
732
733 echo "\n\n" . html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0" width="100%"' ) .
734 html_tag( 'tr' ) .
735 html_tag( 'td', '', 'left' ) .
736 '<center><font size="4"><b>'. _("Folders") . "</b><br></font>\n\n";
737
738 if ($date_format != 6) {
739 /* First, display the clock. */
740 if ($hour_format == 1) {
741 $hr = 'G:i';
742 if ($date_format == 4) {
743 $hr .= ':s';
744 }
745 } else {
746 if ($date_format == 4) {
747 $hr = 'g:i:s a';
748 } else {
749 $hr = 'g:i a';
750 }
751 }
752
753 switch( $date_format ) {
754 case 1:
755 $clk = date('m/d/y '.$hr, time());
756 break;
757 case 2:
758 $clk = date('d/m/y '.$hr, time());
759 break;
760 case 4:
761 case 5:
762 $clk = date($hr, time());
763 break;
764 default:
765 $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() );
766 }
767 $clk = str_replace(' ','&nbsp;',$clk);
768
769 echo '<center><small>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
770 ": $clk</small></center>";
771 }
772
773 /* Next, display the refresh button. */
774 echo '<small>(<a href="../src/left_main.php" target="left">'.
775 _("refresh folder list") . '</a>)</small></center><br>';
776
777 /* Lastly, display the folder list. */
778 if ( $collapse_folders ) {
779 /* If directed, collapse or uncollapse a folder. */
780 if (isset($fold)) {
781 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
782 } else if (isset($unfold)) {
783 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
784 }
785 }
786
787 if ($oldway) { /* normal behaviour SM */
788
789 $boxes = sqimap_mailbox_list($imapConnection);
790 /* Prepare do do out collapsedness and visibility computation. */
791 $curbox = 0;
792 $boxcount = count($boxes);
793
794 /* Compute the collapsedness and visibility of each box. */
795
796 while ($curbox < $boxcount) {
797 $boxes[$curbox]['visible'] = TRUE;
798 compute_folder_children($curbox, $boxcount);
799 }
800
801
802 for ($i = 0; $i < count($boxes); $i++) {
803 if ( $boxes[$i]['visible'] ) {
804 $mailbox = $boxes[$i]['formatted'];
805 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
806
807 /* Create the prefix for the folder name and link. */
808 $prefix = str_repeat(' ',$mblevel);
809 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
810 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
811 create_collapse_link($i) . '&nbsp;';
812 } else {
813 $prefix = str_replace(' ','&nbsp;',$prefix);
814 }
815 $line = "<NOBR><TT>$prefix</TT>";
816
817 /* Add the folder name and link. */
818 if (! isset($color[15])) {
819 $color[15] = $color[6];
820 }
821
822 if (in_array('noselect', $boxes[$i]['flags'])) {
823 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
824 $line .= "<FONT COLOR=\"$color[11]\">";
825 } else {
826 $line .= "<FONT COLOR=\"$color[15]\">";
827 }
828 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
829 $mailbox = str_replace('&nbsp;','',$mailbox);
830 $line .= str_replace(' ', '&nbsp;', $mailbox);
831 }
832 $line .= '</FONT>';
833 } else {
834 $line .= formatMailboxName($imapConnection, $boxes[$i]);
835 }
836
837 /* Put the final touches on our folder line. */
838 $line .= "</NOBR><BR>\n";
839
840 /* Output the line for this folder. */
841 echo $line;
842 }
843 }
844 } else { /* expiremental code */
845 $boxes = sqimap_mailbox_tree($imapConnection);
846 if (isset($advanced_tree) && $advanced_tree) {
847 echo '<FORM name=collapse action="left_main.php" METHOD=POST' .
848 'ENCTYPE="multipart/form-data"'."\n";
849 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>';
850 echo '<DIV ID=mailboxes CLASS=mailboxes>'."\n\n";
851 if (!isset($mbx)) $mbx=NULL;
852 ListAdvancedBoxes($boxes, $mbx);
853 echo '</div></small>'."\n";
854 echo '</FORM>'."\n";
855 } else {
856 ListBoxes($boxes);
857 }
858 } /* if ($oldway) else ... */
859 do_hook('left_main_after');
860 sqimap_logout($imapConnection);
861
862 echo '</td></tr></table>' . "\n".
863 "</div></body></html>\n";
864
865 ?>