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