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