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