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