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