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