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