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