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