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