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