Lots of changes for variable initialization - clean up, really,
[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 $key = $_COOKIE['key'];
508 $onetimepad = $_SESSION['onetimepad'];
509 $username = $_SESSION['username'];
510 $delimiter = $_SESSION['delimiter'];
511
512 if (isset($_GET['fold'])) {
513 $fold = $_GET['fold'];
514 }
515 if (isset($_GET['unfold'])) {
516 $unfold = $_GET['unfold'];
517 }
518
519 // open a connection on the imap port (143)
520 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
521
522 /**
523 * Using stristr since older preferences may contain "None" and "none".
524 */
525 if (isset($left_refresh) && ($left_refresh != '') &&
526 !stristr($left_refresh, 'none')){
527 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
528 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
529 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
530 } else {
531 $xtra = '';
532 }
533
534 /**
535 * $advanced_tree and $oldway are boolean vars which are default set to default
536 * SM behaviour.
537 * Setting $oldway to false causes left_main.php to use the new experimental
538 * way of getting the mailbox-tree.
539 * Setting $advanced tree to true causes SM to display a experimental
540 * mailbox-tree with dhtml behaviour.
541 * It only works on browsers which supports css and javascript. The used
542 * javascript is experimental and doesn't support all browsers. It is tested on
543 * IE6 an Konquerer 3.0.0-2.
544 * In the function ListAdvancedBoxes there is another var $use_folder_images.
545 * setting this to true is only usefull if the images exists in ../images.
546 *
547 * Feel free to experiment with the code and report bugs and enhancements
548 * to marc@its-projects.nl
549 **/
550
551 $advanced_tree = false; /* set this to true if you want to see a nicer mailboxtree */
552 $oldway = true; /* default SM behaviour */
553
554 if ($advanced_tree) {
555 $xtra .= <<<ECHO
556 <script language="Javascript" TYPE="text/javascript">
557
558 <!--
559
560 function hidechilds(el) {
561 id = el.id+".0000";
562 form_id = "mbx[" + el.id +"F]";
563 if (document.all) {
564 ele = document.all[id];
565 if (ele) {
566 if(ele.style.display == "none") {
567 ele.style.display = "block";
568 ele.style.visibility = "visible"
569 el.src="../images/minus.gif";
570 document.all[form_id].value=0;
571 } else {
572 ele.style.display = "none";
573 ele.style.visibility = "hidden"
574 el.src="../images/plus.gif";
575 document.all[form_id].value=1;
576 }
577 }
578 } else if (document.getElementById) {
579 ele = document.getElementById(id);
580 if (ele) {
581 if(ele.style.display == "none") {
582 ele.style.display = "block";
583 ele.style.visibility = "visible"
584 el.src="../images/minus.gif";
585 document.getElementById(form_id).value=0;
586 } else {
587 ele.style.display = "none";
588 ele.style.visibility = "hidden"
589 el.src="../images/plus.gif";
590 document.getElementById(form_id).value=1;
591 }
592 }
593 }
594 }
595
596 function preload() {
597 if (!document.images) return;
598 var ar = new Array();
599 var arguments = preload.arguments;
600 for (var i = 0; i<arguments.length; i++) {
601 ar[i] = new Image();
602 ar[i].src = arguments[i];
603 }
604 }
605
606 function buttonover(el,on) {
607 if (!on) {
608 el.style.borderColor="blue";}
609 else {
610 el.style.borderColor="orange";}
611 }
612
613 function buttonclick(el,on) {
614 if (!on) {
615 el.style.border="groove"}
616 else {
617 el.style.border="ridge";}
618 }
619
620 function hideframe(hide) {
621
622 ECHO;
623 $xtra .= " left_size = \"$left_size\";\n";
624 $xtra .= <<<ECHO
625 if (document.all) {
626 masterf = window.parent.document.all["fs1"];
627 leftf = window.parent.document.all["left"];
628 leftcontent = document.all["leftframe"];
629 leftbutton = document.all["showf"];
630 } else if (document.getElementById) {
631 masterf = window.parent.document.getElementById("fs1");
632 leftf = window.parent.document.getElementById("left");
633 leftcontent = document.getElementById("leftframe");
634 leftbutton = document.getElementById("showf");
635 } else {
636 return false;
637 }
638 if(hide) {
639 new_col = calc_col("20");
640 masterf.cols = new_col;
641 document.body.scrollLeft=0;
642 document.body.style.overflow='hidden';
643 leftcontent.style.display = 'none';
644 leftbutton.style.display='block';
645 } else {
646 masterf.cols = calc_col(left_size);
647 document.body.style.overflow='';
648 leftbutton.style.display='none';
649 leftcontent.style.display='block';
650
651 }
652 }
653
654 function calc_col(c_w) {
655
656 ECHO;
657 if ($location_of_bar == 'right') {
658 $xtra .= ' right=true;';
659 } else {
660 $xtra .= ' right=false;';
661 }
662 $xtra .= "\n";
663 $xtra .= <<<ECHO
664 if (right) {
665 new_col = '*,'+c_w;
666 } else {
667 new_col = c_w+',*';
668 }
669 return new_col;
670 }
671
672 function resizeframe(direction) {
673 if (document.all) {
674 masterf = window.parent.document.all["fs1"];
675 } else if (document.getElementById) {
676 window.parent.document.getElementById("fs1");
677 } else {
678 return false;
679 }
680
681 ECHO;
682 if ($location_of_bar == 'right') {
683 $xtra .= ' colPat=/^\*,(\d+)$/;';
684 } else {
685 $xtra .= ' colPat=/^(\d+),.*$/;';
686 }
687 $xtra .= "\n";
688
689 $xtra .= <<<ECHO
690 old_col = masterf.cols;
691 colPat.exec(old_col);
692
693 if (direction) {
694 new_col_width = parseInt(RegExp.$1) + 25;
695
696 } else {
697 if (parseInt(RegExp.$1) > 35) {
698 new_col_width = parseInt(RegExp.$1) - 25;
699 }
700 }
701 masterf.cols = calc_col(new_col_width);
702 }
703
704 //-->
705
706 </script>
707
708 ECHO;
709
710 /* style definitions */
711
712 $xtra .= <<<ECHO
713
714 <style type="text/css">
715 <!--
716 body {
717 margin: 0px 0px 0px 0px;
718 padding: 5px 5px 5px 5px;
719 }
720
721 .button {
722 border:outset;
723 border-color:blue;
724 background:white;
725 width:99%;
726 heigth:99%;
727 }
728
729 .mbx_par {
730 font-size:0.8em;
731 margin-left:4px;
732 margin-right:0px;
733 }
734
735 a.mbx_link {
736 text-decoration: none;
737 background-color: $color[0];
738 display: inline;
739 }
740
741 a:hover.mbx_link {
742 background-color: $color[9];
743 }
744
745 a.mbx_link img {
746 border-style: none;
747 }
748
749 .mbx_sub {
750 padding-left:5px;
751 padding-right:0px;
752 margin-left:4px;
753 margin-right:0px;
754 font-size:0.7em;
755 }
756
757 .par_area {
758 margin-top:0px;
759 margin-left:4px;
760 margin-right:0px;
761 padding-left:10px;
762 padding-bottom:5px;
763 border-left: solid;
764 border-left-width:0.1em;
765 border-left-color:blue;
766 border-bottom: solid;
767 border-bottom-width:0.1em;
768 border-bottom-color:blue;
769 display: block;
770 }
771
772 .mailboxes {
773 padding-bottom:3px;
774 margin-right:4px;
775 padding-right:4px;
776 margin-left:4px;
777 padding-left:4px;
778 border: groove;
779 border-width:0.1em;
780 border-color:green;
781 background: $color[0];
782 }
783
784 -->
785
786 </style>
787
788 ECHO;
789
790 }
791
792
793
794
795 displayHtmlHeader( 'SquirrelMail', $xtra );
796
797 /* If requested and not yet complete, attempt to autocreate folders. */
798 if ($auto_create_special && !isset($auto_create_done)) {
799 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
800 foreach( $autocreate as $folder ) {
801 if (($folder != '') && ($folder != 'none')) {
802 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
803 sqimap_mailbox_create($imapConnection, $folder, '');
804 } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
805 sqimap_subscribe($imapConnection, $folder);
806 }
807 }
808 }
809
810 /* Let the world know that autocreation is complete! Hurrah! */
811 $auto_create_done = TRUE;
812 sqsession_register($auto_create_done, 'auto_create_done');
813 }
814
815 echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
816
817 do_hook('left_main_before');
818 if ($advanced_tree) {
819 /* nice future feature, needs layout !! volunteers? */
820 $right_pos = $left_size - 20;
821 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>';
822 echo '<div ID="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
823 echo '<div ID="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
824 echo '<div ID="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
825 echo '<div ID="leftframe"><br /><br />';
826 }
827
828 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
829 html_tag( 'tr' ) .
830 html_tag( 'td', '', 'left' ) .
831 '<center><font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
832
833 if ($date_format != 6) {
834 /* First, display the clock. */
835 if ($hour_format == 1) {
836 $hr = 'G:i';
837 if ($date_format == 4) {
838 $hr .= ':s';
839 }
840 } else {
841 if ($date_format == 4) {
842 $hr = 'g:i:s a';
843 } else {
844 $hr = 'g:i a';
845 }
846 }
847
848 switch( $date_format ) {
849 case 1:
850 $clk = date('m/d/y '.$hr, time());
851 break;
852 case 2:
853 $clk = date('d/m/y '.$hr, time());
854 break;
855 case 4:
856 case 5:
857 $clk = date($hr, time());
858 break;
859 default:
860 $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() );
861 }
862 $clk = str_replace(' ','&nbsp;',$clk);
863
864 echo '<center><small>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
865 ": $clk</small></center>";
866 }
867
868 /* Next, display the refresh button. */
869 echo '<small>(<a href="../src/left_main.php" target="left">'.
870 _("refresh folder list") . '</a>)</small></center><br />';
871
872 /* Lastly, display the folder list. */
873 if ( $collapse_folders ) {
874 /* If directed, collapse or uncollapse a folder. */
875 if (isset($fold)) {
876 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
877 } else if (isset($unfold)) {
878 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
879 }
880 }
881
882 if ($oldway) { /* normal behaviour SM */
883
884 $boxes = sqimap_mailbox_list($imapConnection);
885 /* Prepare do do out collapsedness and visibility computation. */
886 $curbox = 0;
887 $boxcount = count($boxes);
888
889 /* Compute the collapsedness and visibility of each box. */
890
891 while ($curbox < $boxcount) {
892 $boxes[$curbox]['visible'] = TRUE;
893 compute_folder_children($curbox, $boxcount);
894 }
895
896
897 for ($i = 0; $i < count($boxes); $i++) {
898 if ( $boxes[$i]['visible'] ) {
899 $mailbox = $boxes[$i]['formatted'];
900 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
901
902 /* Create the prefix for the folder name and link. */
903 $prefix = str_repeat(' ',$mblevel);
904 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
905 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
906 create_collapse_link($i) . '&nbsp;';
907 } else {
908 $prefix = str_replace(' ','&nbsp;',$prefix);
909 }
910 $line = "<nobr><tt>$prefix</tt>";
911
912 /* Add the folder name and link. */
913 if (! isset($color[15])) {
914 $color[15] = $color[6];
915 }
916
917 if (in_array('noselect', $boxes[$i]['flags'])) {
918 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
919 $line .= "<font color=\"$color[11]\">";
920 } else {
921 $line .= "<font color=\"$color[15]\">";
922 }
923 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
924 $mailbox = str_replace('&nbsp;','',$mailbox);
925 $line .= str_replace(' ', '&nbsp;', $mailbox);
926 }
927 $line .= '</font>';
928 } else {
929 $line .= formatMailboxName($imapConnection, $boxes[$i]);
930 }
931
932 /* Put the final touches on our folder line. */
933 $line .= "</nobr><br>\n";
934
935 /* Output the line for this folder. */
936 echo $line;
937 }
938 }
939 } else { /* expiremental code */
940 $boxes = sqimap_mailbox_tree($imapConnection);
941 if (isset($advanced_tree) && $advanced_tree) {
942 echo '<form name="collapse" action="left_main.php" method="post" ' .
943 'enctype="multipart/form-data"'."\n";
944 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 />';
945 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
946 if (!isset($mbx)) $mbx=NULL;
947 ListAdvancedBoxes($boxes, $mbx);
948 echo '</div></small>'."\n";
949 echo '</form>'."\n";
950 } else {
951 ListBoxes($boxes);
952 }
953 } /* if ($oldway) else ... */
954 do_hook('left_main_after');
955 sqimap_logout($imapConnection);
956
957 echo '</td></tr></table>' . "\n".
958 "</div></body></html>\n";
959
960 ?>