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