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