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