somehow url vars with &amp are not picked up by PHP
[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 global $delimiter, $default_folder_prefix, $left_size;
493
494 // open a connection on the imap port (143)
495 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
496
497 /**
498 * Using stristr since older preferences may contain "None" and "none".
499 */
500 if (isset($left_refresh) && ($left_refresh != '') &&
501 !stristr($left_refresh, "none")){
502 $xtra = "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" .
503 "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n".
504 "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
505 } else {
506 $xtra = '';
507 }
508
509 /**
510 * $advanced_tree and $oldway are boolean vars which are default set to default
511 * SM behaviour.
512 * Setting $oldway to false causes left_main.php to use the new experimental
513 * way of getting the mailbox-tree.
514 * Setting $advanced tree to true causes SM to display a experimental
515 * mailbox-tree with dhtml behaviour.
516 * It only works on browsers which supports css and javascript. The used
517 * javascript is experimental and doesn't support all browsers. It is tested on
518 * IE6 an Konquerer 3.0.0-2.
519 * In the function ListAdvancedBoxes there is another var $use_folder_images.
520 * setting this to true is only usefull if the images exists in ../images.
521 *
522 * Feel free to experiment with the code and report bugs and enhancements
523 * to marc@its-projects.nl
524 **/
525
526 $advanced_tree = false; /* set this to true if you want to see a nicer mailboxtree */
527 $oldway = true; /* default SM behaviour */
528
529 if ($advanced_tree) {
530 $xtra .= <<<ECHO
531 <script language="Javascript" TYPE="text/javascript">
532
533 <!--
534
535 function hidechilds(el) {
536 id = el.id+".0000";
537 form_id = "mbx[" + el.id +"F]";
538 if (document.all) {
539 ele = document.all[id];
540 if (ele) {
541 if(ele.style.display == "none") {
542 ele.style.display = "block";
543 ele.style.visibility = "visible"
544 el.src="../images/minus.gif";
545 document.all[form_id].value=0;
546 } else {
547 ele.style.display = "none";
548 ele.style.visibility = "hidden"
549 el.src="../images/plus.gif";
550 document.all[form_id].value=1;
551 }
552 }
553 } else if (document.getElementById) {
554 ele = document.getElementById(id);
555 if (ele) {
556 if(ele.style.display == "none") {
557 ele.style.display = "block";
558 ele.style.visibility = "visible"
559 el.src="../images/minus.gif";
560 document.getElementById(form_id).value=0;
561 } else {
562 ele.style.display = "none";
563 ele.style.visibility = "hidden"
564 el.src="../images/plus.gif";
565 document.getElementById(form_id).value=1;
566 }
567 }
568 }
569 }
570
571 function preload() {
572 if (!document.images) return;
573 var ar = new Array();
574 var arguments = preload.arguments;
575 for (var i = 0; i<arguments.length; i++) {
576 ar[i] = new Image();
577 ar[i].src = arguments[i];
578 }
579 }
580
581 function buttonover(el,on) {
582 if (!on) {
583 el.style.borderColor="blue";}
584 else {
585 el.style.borderColor="orange";}
586 }
587
588 function buttonclick(el,on) {
589 if (!on) {
590 el.style.border="groove"}
591 else {
592 el.style.border="ridge";}
593 }
594
595 function hideframe(hide) {
596
597 ECHO;
598 $xtra .= " left_size = \"$left_size\";\n";
599 $xtra .= <<<ECHO
600 if (document.all) {
601 masterf = window.parent.document.all["fs1"];
602 leftf = window.parent.document.all["left"];
603 leftcontent = document.all["leftframe"];
604 leftbutton = document.all["showf"];
605 } else if (document.getElementById) {
606 masterf = window.parent.document.getElementById("fs1");
607 leftf = window.parent.document.getElementById("left");
608 leftcontent = document.getElementById("leftframe");
609 leftbutton = document.getElementById("showf");
610 } else {
611 return false;
612 }
613 if(hide) {
614 new_col = calc_col("20");
615 masterf.cols = new_col;
616 document.body.scrollLeft=0;
617 document.body.style.overflow='hidden';
618 leftcontent.style.display = 'none';
619 leftbutton.style.display='block';
620 } else {
621 masterf.cols = calc_col(left_size);
622 document.body.style.overflow='';
623 leftbutton.style.display='none';
624 leftcontent.style.display='block';
625
626 }
627 }
628
629 function calc_col(c_w) {
630
631 ECHO;
632 if ($location_of_bar == 'right') {
633 $xtra .= ' right=true;';
634 } else {
635 $xtra .= ' right=false;';
636 }
637 $xtra .= "\n";
638 $xtra .= <<<ECHO
639 if (right) {
640 new_col = '*,'+c_w;
641 } else {
642 new_col = c_w+',*';
643 }
644 return new_col;
645 }
646
647 function resizeframe(direction) {
648 if (document.all) {
649 masterf = window.parent.document.all["fs1"];
650 } else if (document.getElementById) {
651 window.parent.document.getElementById("fs1");
652 } else {
653 return false;
654 }
655
656 ECHO;
657 if ($location_of_bar == 'right') {
658 $xtra .= ' colPat=/^\*,(\d+)$/;';
659 } else {
660 $xtra .= ' colPat=/^(\d+),.*$/;';
661 }
662 $xtra .= "\n";
663
664 $xtra .= <<<ECHO
665 old_col = masterf.cols;
666 colPat.exec(old_col);
667
668 if (direction) {
669 new_col_width = parseInt(RegExp.$1) + 25;
670
671 } else {
672 if (parseInt(RegExp.$1) > 35) {
673 new_col_width = parseInt(RegExp.$1) - 25;
674 }
675 }
676 masterf.cols = calc_col(new_col_width);
677 }
678
679 //-->
680
681 </script>
682
683 ECHO;
684
685 /* style definitions */
686
687 $xtra .= <<<ECHO
688
689 <STYLE TYPE="text/css">
690 <!--
691 body {
692 margin: 0px 0px 0px 0px;
693 padding: 5px 5px 5px 5px;
694 }
695
696 .button {
697 border:outset;
698 border-color:blue;
699 background:white;
700 width:99%;
701 heigth:99%;
702 }
703
704 .mbx_par {
705 font-size:0.8em;
706 margin-left:4px;
707 margin-right:0px;
708 }
709
710 a.mbx_link {
711 text-decoration: none;
712 background-color: $color[0];
713 display: inline;
714 }
715
716 a:hover.mbx_link {
717 background-color: $color[9];
718 }
719
720 a.mbx_link img {
721 border-style: none;
722 }
723
724 .mbx_sub {
725 padding-left:5px;
726 padding-right:0px;
727 margin-left:4px;
728 margin-right:0px;
729 font-size:0.7em;
730 }
731
732 .par_area {
733 margin-top:0px;
734 margin-left:4px;
735 margin-right:0px;
736 padding-left:10px;
737 padding-bottom:5px;
738 border-left: solid;
739 border-left-width:0.1em;
740 border-left-color:blue;
741 border-bottom: solid;
742 border-bottom-width:0.1em;
743 border-bottom-color:blue;
744 display: block;
745 }
746
747 .mailboxes {
748 padding-bottom:3px;
749 margin-right:4px;
750 padding-right:4px;
751 margin-left:4px;
752 padding-left:4px;
753 border: groove;
754 border-width:0.1em;
755 border-color:green;
756 background: $color[0];
757 }
758
759 -->
760
761 </STYLE>
762
763 ECHO;
764
765 }
766
767
768
769
770 displayHtmlHeader( 'SquirrelMail', $xtra );
771
772 /* If requested and not yet complete, attempt to autocreate folders. */
773 if ($auto_create_special && !isset($auto_create_done)) {
774 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
775 foreach( $autocreate as $folder ) {
776 if (($folder != '') && ($folder != 'none')) {
777 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
778 sqimap_mailbox_create($imapConnection, $folder, '');
779 } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
780 sqimap_subscribe($imapConnection, $folder);
781 }
782 }
783 }
784
785 /* Let the world know that autocreation is complete! Hurrah! */
786 $auto_create_done = TRUE;
787 session_register('auto_create_done');
788 }
789
790 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
791
792 do_hook('left_main_before');
793 if ($advanced_tree) {
794 /* nice future feature, needs layout !! volunteers? */
795 $right_pos = $left_size - 20;
796 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>';
797 echo '<div ID="showf" style="width=20;font-size:12;display:none;"><A HREF="javascript:hideframe(false)"><b>>></b></a></div>';
798 echo '<div ID="incrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(true)"><b>></b></a></div>';
799 echo '<div ID="decrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(false)"><b><</b></a></div></div>';
800 echo '<div ID="leftframe"><br><br>';
801 }
802
803 echo "\n\n" . html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0" width="100%"' ) .
804 html_tag( 'tr' ) .
805 html_tag( 'td', '', 'left' ) .
806 '<center><font size="4"><b>'. _("Folders") . "</b><br></font>\n\n";
807
808 if ($date_format != 6) {
809 /* First, display the clock. */
810 if ($hour_format == 1) {
811 $hr = 'G:i';
812 if ($date_format == 4) {
813 $hr .= ':s';
814 }
815 } else {
816 if ($date_format == 4) {
817 $hr = 'g:i:s a';
818 } else {
819 $hr = 'g:i a';
820 }
821 }
822
823 switch( $date_format ) {
824 case 1:
825 $clk = date('m/d/y '.$hr, time());
826 break;
827 case 2:
828 $clk = date('d/m/y '.$hr, time());
829 break;
830 case 4:
831 case 5:
832 $clk = date($hr, time());
833 break;
834 default:
835 $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() );
836 }
837 $clk = str_replace(' ','&nbsp;',$clk);
838
839 echo '<center><small>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
840 ": $clk</small></center>";
841 }
842
843 /* Next, display the refresh button. */
844 echo '<small>(<a href="../src/left_main.php" target="left">'.
845 _("refresh folder list") . '</a>)</small></center><br>';
846
847 /* Lastly, display the folder list. */
848 if ( $collapse_folders ) {
849 /* If directed, collapse or uncollapse a folder. */
850 if (isset($fold)) {
851 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
852 } else if (isset($unfold)) {
853 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
854 }
855 }
856
857 if ($oldway) { /* normal behaviour SM */
858
859 $boxes = sqimap_mailbox_list($imapConnection);
860 /* Prepare do do out collapsedness and visibility computation. */
861 $curbox = 0;
862 $boxcount = count($boxes);
863
864 /* Compute the collapsedness and visibility of each box. */
865
866 while ($curbox < $boxcount) {
867 $boxes[$curbox]['visible'] = TRUE;
868 compute_folder_children($curbox, $boxcount);
869 }
870
871
872 for ($i = 0; $i < count($boxes); $i++) {
873 if ( $boxes[$i]['visible'] ) {
874 $mailbox = $boxes[$i]['formatted'];
875 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
876
877 /* Create the prefix for the folder name and link. */
878 $prefix = str_repeat(' ',$mblevel);
879 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
880 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
881 create_collapse_link($i) . '&nbsp;';
882 } else {
883 $prefix = str_replace(' ','&nbsp;',$prefix);
884 }
885 $line = "<NOBR><TT>$prefix</TT>";
886
887 /* Add the folder name and link. */
888 if (! isset($color[15])) {
889 $color[15] = $color[6];
890 }
891
892 if (in_array('noselect', $boxes[$i]['flags'])) {
893 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
894 $line .= "<FONT COLOR=\"$color[11]\">";
895 } else {
896 $line .= "<FONT COLOR=\"$color[15]\">";
897 }
898 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
899 $mailbox = str_replace('&nbsp;','',$mailbox);
900 $line .= str_replace(' ', '&nbsp;', $mailbox);
901 }
902 $line .= '</FONT>';
903 } else {
904 $line .= formatMailboxName($imapConnection, $boxes[$i]);
905 }
906
907 /* Put the final touches on our folder line. */
908 $line .= "</NOBR><BR>\n";
909
910 /* Output the line for this folder. */
911 echo $line;
912 }
913 }
914 } else { /* expiremental code */
915 $boxes = sqimap_mailbox_tree($imapConnection);
916 if (isset($advanced_tree) && $advanced_tree) {
917 echo '<FORM name=collapse action="left_main.php" METHOD=POST' .
918 'ENCTYPE="multipart/form-data"'."\n";
919 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>';
920 echo '<DIV ID=mailboxes CLASS=mailboxes>'."\n\n";
921 if (!isset($mbx)) $mbx=NULL;
922 ListAdvancedBoxes($boxes, $mbx);
923 echo '</div></small>'."\n";
924 echo '</FORM>'."\n";
925 } else {
926 ListBoxes($boxes);
927 }
928 } /* if ($oldway) else ... */
929 do_hook('left_main_after');
930 sqimap_logout($imapConnection);
931
932 echo '</td></tr></table>' . "\n".
933 "</div></body></html>\n";
934
935 ?>