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