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