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