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