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