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