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