more options that are changed in config
[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
3170c448 288function ListBoxes ($boxes, $j=0 ) {
f23f6a3a 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 }
3170c448 385 /* Print unseen information. */
386 if (isset($unseen_found) && $unseen_found) {
387 $end .= "&nbsp;<small>$unseen_string</small>";
388 }
a6172cd5 389 $end .= "\n<small>\n" .
390 "&nbsp;&nbsp;(<a href=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</a>)" .
391 "</small>";
392 }
e4c5976a 393 } else {
3be3cf5c 394 if (!$boxes->is_noselect) {
e4c5976a 395 if ($unseen > 0) {
396 $pre .= '<b>';
397 }
398 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
399 if ($unseen > 0) {
400 $end .= '</b>';
401 }
402 $end .= '</a>';
403 }
3170c448 404 /* Print unseen information. */
405 if (isset($unseen_found) && $unseen_found) {
406 $end .= "&nbsp;<small>$unseen_string</small>";
407 }
a6172cd5 408
e4c5976a 409 }
a6172cd5 410
e4c5976a 411 $font = '';
412 $fontend = '';
413 if ($boxes->is_special) {
a6172cd5 414 $font = "<font color=\"$color[11]\">";
e4c5976a 415 $fontend = "</font>";
416 }
417 $end .= '</nobr>';
39027844 418
419 if (!$boxes->is_root) {
420 echo "" . $pre .$font. $boxes->mailboxname_sub .$fontend . $end. '<br />' . "\n";
421 $j++;
422 }
423
e4c5976a 424 if (!$collapse || $boxes->is_root) {
a6172cd5 425 for ($i = 0; $i <count($boxes->mbxs); $i++) {
e4c5976a 426 listBoxes($boxes->mbxs[$i],$j);
a6172cd5 427 }
e4c5976a 428 }
f23f6a3a 429 }
430}
431
c8fa94cf 432function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
f23f6a3a 433 global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type,
78e5377d 434 $move_to_trash, $trash_folder, $collapse_folders, $oldway, $advanced_tree;
f23f6a3a 435
4bdcd5e0 436 if (!$boxes)
437 return;
438
f23f6a3a 439 /* use_folder_images only works if the images exist in ../images */
c8fa94cf 440 $use_folder_images = true;
f23f6a3a 441
442 $pre = '';
443 $end = '';
444 $collapse = false;
6c8fee24 445 $unseen_found = false;
446 $unseen = 0;
a6172cd5 447
a6172cd5 448 $mailbox = $boxes->mailboxname_full;
449 $mailboxURL = urlencode($mailbox);
f23f6a3a 450
6c8fee24 451 /* Only need to display info when option is set */
51ea258b 452 if (isset($unseen_notify) && ($unseen_notify > 1) && (($boxes->unseen !== false) || ($boxes->total !== false))) {
6c8fee24 453
51ea258b 454 if ($boxes->unseen !== false)
6c8fee24 455 $unseen = $boxes->unseen;
6c8fee24 456
457 /*
458 Should only display unseen info if the folder is inbox
459 or you set the option for all folders
460 */
461
462 if ((strtolower($mailbox) == 'inbox') || ($unseen_notify == 3)) {
463 $unseen_string = $unseen;
464
6c8fee24 465 /* If users requests, display message count too */
51ea258b 466 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total !== false))
467 $unseen_string .= '/' . $boxes->total;
6c8fee24 468
469 $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
470
471 /*
472 Finally allow the script to display the values by setting a boolean.
473 This can only occur if the unseen count is great than 0 (if you have
474 unseen count only), or you have the message count too.
475 */
476 if (($unseen > 0) || (isset($unseen_type) && ($unseen_type ==2))) {
477 $unseen_found = true;
478 }
479
480 }
481
482 }
a6172cd5 483
484 /* If there are unseen message, bold the line. */
485 if ($unseen > 0) { $pre .= '<b>'; }
486
487 /* color special boxes */
488 if ($boxes->is_special) {
4bdcd5e0 489 $pre .= "<font color=\"$color[11]\">";
a6172cd5 490 $end .= '</font>';
491 }
492
493 /* If there are unseen message, close bolding. */
494 if ($unseen > 0) { $end .= '</b>'; }
495
496 /* Print unseen information. */
6c8fee24 497 if (isset($unseen_found) && $unseen_found) {
a6172cd5 498 $end .= "&nbsp;$unseen_string";
499 }
500
501 if (($move_to_trash) && ($mailbox == $trash_folder)) {
4bdcd5e0 502 if (! isset($numMessages)) {
a6172cd5 503 $numMessages = $boxes->total;
4bdcd5e0 504 }
505 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">" . $pre;
506 $end .= '</a>';
507 if ($numMessages > 0) {
a6172cd5 508 $urlMailbox = urlencode($mailbox);
d1dbd575 509 $end .= "\n<small>\n" .
a6172cd5 510 "&nbsp;&nbsp;(<a class=\"mbx_link\" href=\"empty_trash.php\">"._("purge")."</a>)" .
511 "</small>";
4bdcd5e0 512 }
a6172cd5 513 } else {
514 if (!$boxes->is_noselect) { /* \Noselect boxes can't be selected */
4bdcd5e0 515 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">" . $pre;
516 $end .= '</a>';
a6172cd5 517 }
518 }
519
520 if (!$boxes->is_root) {
521 if ($use_folder_images) {
522 if ($boxes->is_inbox) {
f0537f93 523 $folder_img = '../images/inbox.png';
a6172cd5 524 } else if ($boxes->is_sent) {
f0537f93 525 $folder_img = '../images/senti.png';
a6172cd5 526 } else if ($boxes->is_trash) {
f0537f93 527 $folder_img = '../images/delitem.png';
a6172cd5 528 } else if ($boxes->is_draft) {
f0537f93 529 $folder_img = '../images/draft.png';
b6d26135 530 } else if ($boxes->is_noinferiors) {
531 $folder_img = '../images/folder_noinf.png';
f0537f93 532 } else $folder_img = '../images/folder.png';
a6172cd5 533 $folder_img = '&nbsp;<img src="'.$folder_img.'" height="15" valign="center" />&nbsp;';
534 } else $folder_img = '';
535 if (!isset($boxes->mbxs[0])) {
536 echo ' ' . html_tag( 'div',
3be3cf5c 537 '<tt>'. $pre . $folder_img . '</tt>'. $boxes->mailboxname_sub . $end,
3170c448 538 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
539 }
540 else {
a6172cd5 541 /* get collapse information */
3170c448 542 if ($collapse_folders) {
543 $form_entry = $j.'F';
544 if (isset($mbx) && isset($mbx[$form_entry])) {
545 $collapse = $mbx[$form_entry];
546 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , $collapse ? SM_BOX_COLLAPSED : SM_BOX_UNCOLLAPSED);
547 }
548 else {
549 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
550 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
551 }
552 $img_src = ($collapse ? '../images/plus.png' : '../images/minus.png');
553 $collapse_link = '<a href="javascript:void(0)">'." <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
554 }
555 else
556 $collapse_link='';
557 echo ' ' . html_tag( 'div',
a6172cd5 558 $collapse_link . $pre . $folder_img . '&nbsp;'. $boxes->mailboxname_sub . $end ,
3170c448 559 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
560 echo ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
a6172cd5 561 }
562 }
a6172cd5 563
4bdcd5e0 564 $visible = ($collapse ? ' style="display:none"' : ' style="display:block"');
565 if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */
566 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
a6172cd5 567
4bdcd5e0 568 if ($j !='ID.0000')
569 $j = $j .'.0000';
570 for ($i = 0; $i <count($boxes->mbxs); $i++) {
571 $j++;
572 ListAdvancedBoxes($boxes->mbxs[$i],$mbx,$j);
f23f6a3a 573 }
4bdcd5e0 574 if (isset($boxes->mbxs[0]) && !$boxes->is_root)
575 echo '</div>'."\n\n";
f23f6a3a 576}
577
578
579
95e93571 580
581/* -------------------- MAIN ------------------------ */
582
f38b7cf0 583/* get globals */
584sqgetGlobalVar('username', $username, SQ_SESSION);
585sqgetGlobalVar('key', $key, SQ_COOKIE);
586sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
587sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
a32985a5 588
f38b7cf0 589sqgetGlobalVar('fold', $fold, SQ_GET);
590sqgetGlobalVar('unfold', $unfold, SQ_GET);
591
592/* end globals */
95e93571 593
594// open a connection on the imap port (143)
595$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
596
f43c35f8 597/**
598 * Using stristr since older preferences may contain "None" and "none".
599 */
600if (isset($left_refresh) && ($left_refresh != '') &&
d68323ff 601 !stristr($left_refresh, 'none')){
602 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
603 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
604 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
95e93571 605} else {
606 $xtra = '';
607}
608
f23f6a3a 609/**
a6172cd5 610 * $advanced_tree and $oldway are boolean vars which are default set to default
611 * SM behaviour.
c72be5a6 612 * Setting $oldway to false causes left_main.php to use the new experimental
f23f6a3a 613 * way of getting the mailbox-tree.
a6172cd5 614 * Setting $advanced tree to true causes SM to display a experimental
f23f6a3a 615 * mailbox-tree with dhtml behaviour.
a6172cd5 616 * It only works on browsers which supports css and javascript. The used
c72be5a6 617 * javascript is experimental and doesn't support all browsers.
618 * It has been tested on IE6 an Konquerer 3.0.0-2.
619 * It is now tested and working on: (please test and update this list)
620 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
621 * XWindow: ?
622 * Mac: ?
f23f6a3a 623 * In the function ListAdvancedBoxes there is another var $use_folder_images.
624 * setting this to true is only usefull if the images exists in ../images.
a6172cd5 625 *
f23f6a3a 626 * Feel free to experiment with the code and report bugs and enhancements
627 * to marc@its-projects.nl
a6172cd5 628 **/
f23f6a3a 629
78e5377d 630/* set this to true if you want to see a nicer mailboxtree */
631if (! isset($advanced_tree) || $advanced_tree=="" ) {
632 $advanced_tree=false; }
633/* default SM behaviour */
634if (! isset($oldway) || $oldway=="" ) {
635 $oldway=false; }
f23f6a3a 636
637if ($advanced_tree) {
638$xtra .= <<<ECHO
599038d5 639<script language="Javascript" TYPE="text/javascript">
f23f6a3a 640
599038d5 641<!--
f23f6a3a 642
51ea258b 643 function preload() {
644 if (document.images) {
645 var treeImages = new Array;
646 var arguments = preload.arguments;
647 for (var i = 0; i<arguments.length; i++) {
648 treeImages[i] = new Image();
649 treeImages[i].src = arguments[i];
650 }
651 }
652 }
653
99034855 654var vTreeImg;
655var vTreeDiv;
656var vTreeSrc;
657
658 function fTreeTimeout() {
659 if (vTreeDiv.readyState == "complete")
660 vTreeImg.src = vTreeSrc;
661 else
662 setTimeout("fTreeTimeout()", 100);
663 }
664
665 function hidechilds(img) {
666 id = img.id + ".0000";
667 form_id = "mbx[" + img.id +"F]";
c72be5a6 668 if (document.all) { //IE, Opera7
99034855 669 div = document.all[id];
670 if (div) {
671 if (div.style.display == "none") {
672 vTreeSrc = "../images/minus.png";
673 style = "block";
674 value = 0;
675 }
676 else {
677 vTreeSrc = "../images/plus.png";
678 style = "none";
679 value = 1;
a6172cd5 680 }
99034855 681 vTreeImg = img;
682 vTreeDiv = div;
c72be5a6 683 if (typeof vTreeDiv.readyState != "undefined") //IE
684 setTimeout("fTreeTimeout()",100);
685 else //Non IE
686 vTreeImg.src = vTreeSrc;
99034855 687 div.style.display = style;
688 document.all[form_id].value = value;
a6172cd5 689 }
99034855 690 }
c72be5a6 691 else if (document.getElementById) { //Gecko
99034855 692 div = document.getElementById(id);
693 if (div) {
694 if (div.style.display == "none") {
695 src = "../images/minus.png";
696 style = "block";
697 value = 0;
698 }
699 else {
700 src = "../images/plus.png";
701 style = "none";
702 value = 1;
a6172cd5 703 }
99034855 704 div.style.display = style;
705 img.src = src;
706 document.getElementById(form_id).value = value;
a6172cd5 707 }
51ea258b 708 }
a6172cd5 709 }
a6172cd5 710
f23f6a3a 711 function buttonover(el,on) {
712 if (!on) {
c72be5a6 713// el.style.borderColor="$color[9]";}
714 el.style.background="$color[0]";}
f23f6a3a 715 else {
c72be5a6 716 el.style.background="$color[9]";}
f23f6a3a 717 }
718
719 function buttonclick(el,on) {
a6172cd5 720 if (!on) {
c72be5a6 721 el.style.border="groove";}
f23f6a3a 722 else {
723 el.style.border="ridge";}
724 }
599038d5 725
726 function hideframe(hide) {
a6172cd5 727
599038d5 728ECHO;
729$xtra .= " left_size = \"$left_size\";\n";
730$xtra .= <<<ECHO
731 if (document.all) {
a6172cd5 732 masterf = window.parent.document.all["fs1"];
733 leftf = window.parent.document.all["left"];
734 leftcontent = document.all["leftframe"];
735 leftbutton = document.all["showf"];
599038d5 736 } else if (document.getElementById) {
a6172cd5 737 masterf = window.parent.document.getElementById("fs1");
738 leftf = window.parent.document.getElementById("left");
739 leftcontent = document.getElementById("leftframe");
740 leftbutton = document.getElementById("showf");
599038d5 741 } else {
742 return false;
a6172cd5 743 }
599038d5 744 if(hide) {
745 new_col = calc_col("20");
746 masterf.cols = new_col;
a6172cd5 747 document.body.scrollLeft=0;
748 document.body.style.overflow='hidden';
749 leftcontent.style.display = 'none';
750 leftbutton.style.display='block';
599038d5 751 } else {
752 masterf.cols = calc_col(left_size);
a6172cd5 753 document.body.style.overflow='';
754 leftbutton.style.display='none';
755 leftcontent.style.display='block';
756
599038d5 757 }
758 }
a6172cd5 759
599038d5 760 function calc_col(c_w) {
761
762ECHO;
763 if ($location_of_bar == 'right') {
764 $xtra .= ' right=true;';
a6172cd5 765 } else {
599038d5 766 $xtra .= ' right=false;';
767 }
768 $xtra .= "\n";
769$xtra .= <<<ECHO
770 if (right) {
771 new_col = '*,'+c_w;
772 } else {
773 new_col = c_w+',*';
774 }
775 return new_col;
a6172cd5 776 }
777
599038d5 778 function resizeframe(direction) {
779 if (document.all) {
a6172cd5 780 masterf = window.parent.document.all["fs1"];
599038d5 781 } else if (document.getElementById) {
a6172cd5 782 window.parent.document.getElementById("fs1");
599038d5 783 } else {
784 return false;
785 }
a6172cd5 786
599038d5 787ECHO;
788 if ($location_of_bar == 'right') {
789 $xtra .= ' colPat=/^\*,(\d+)$/;';
a6172cd5 790 } else {
599038d5 791 $xtra .= ' colPat=/^(\d+),.*$/;';
792 }
793 $xtra .= "\n";
a6172cd5 794
599038d5 795$xtra .= <<<ECHO
796 old_col = masterf.cols;
797 colPat.exec(old_col);
a6172cd5 798
599038d5 799 if (direction) {
800 new_col_width = parseInt(RegExp.$1) + 25;
a6172cd5 801
599038d5 802 } else {
803 if (parseInt(RegExp.$1) > 35) {
804 new_col_width = parseInt(RegExp.$1) - 25;
805 }
806 }
a6172cd5 807 masterf.cols = calc_col(new_col_width);
599038d5 808 }
809
810//-->
a6172cd5 811
f23f6a3a 812</script>
813
814ECHO;
815
816/* style definitions */
386e556f 817
f23f6a3a 818$xtra .= <<<ECHO
819
d68323ff 820<style type="text/css">
f23f6a3a 821<!--
599038d5 822 body {
823 margin: 0px 0px 0px 0px;
824 padding: 5px 5px 5px 5px;
825 }
c8fa94cf 826
f23f6a3a 827 .button {
828 border:outset;
c72be5a6 829 border-color: $color[9];
830 background:$color[0];
831 color:$color[6];
f23f6a3a 832 width:99%;
833 heigth:99%;
834 }
835
836 .mbx_par {
d1dbd575 837 font-size:1.0em;
599038d5 838 margin-left:4px;
839 margin-right:0px;
c8fa94cf 840 }
599038d5 841
c8fa94cf 842 a.mbx_link {
843 text-decoration: none;
844 background-color: $color[0];
845 display: inline;
846 }
847
848 a:hover.mbx_link {
849 background-color: $color[9];
850 }
851
852 a.mbx_link img {
853 border-style: none;
f23f6a3a 854 }
855
856 .mbx_sub {
f23f6a3a 857 padding-left:5px;
599038d5 858 padding-right:0px;
f23f6a3a 859 margin-left:4px;
599038d5 860 margin-right:0px;
d1dbd575 861 font-size:0.9em;
f23f6a3a 862 }
863
864 .par_area {
599038d5 865 margin-top:0px;
866 margin-left:4px;
867 margin-right:0px;
f23f6a3a 868 padding-left:10px;
599038d5 869 padding-bottom:5px;
f23f6a3a 870 border-left: solid;
871 border-left-width:0.1em;
51ea258b 872 border-left-color:$color[9];
f23f6a3a 873 border-bottom: solid;
874 border-bottom-width:0.1em;
51ea258b 875 border-bottom-color:$color[9];
c8fa94cf 876 display: block;
f23f6a3a 877 }
878
879 .mailboxes {
f23f6a3a 880 padding-bottom:3px;
599038d5 881 margin-right:4px;
882 padding-right:4px;
883 margin-left:4px;
884 padding-left:4px;
f23f6a3a 885 border: groove;
886 border-width:0.1em;
c72be5a6 887 border-color:$color[9];
c8fa94cf 888 background: $color[0];
f23f6a3a 889 }
890
891-->
892
d68323ff 893</style>
f23f6a3a 894
895ECHO;
896
897}
898
899
900
901
95e93571 902displayHtmlHeader( 'SquirrelMail', $xtra );
903
904/* If requested and not yet complete, attempt to autocreate folders. */
905if ($auto_create_special && !isset($auto_create_done)) {
a3439b27 906 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
95e93571 907 foreach( $autocreate as $folder ) {
a3439b27 908 if (($folder != '') && ($folder != 'none')) {
95e93571 909 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
910 sqimap_mailbox_create($imapConnection, $folder, '');
a3439b27 911 } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
95e93571 912 sqimap_subscribe($imapConnection, $folder);
2d367c68 913 }
ebf18afa 914 }
2d367c68 915 }
a6d2e0de 916
95e93571 917 /* Let the world know that autocreation is complete! Hurrah! */
90de1755 918 $auto_create_done = TRUE;
a32985a5 919 sqsession_register($auto_create_done, 'auto_create_done');
95e93571 920}
a6d2e0de 921
51ea258b 922if ($advanced_tree)
923 echo "\n<body" .
924 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
925 " bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
926else
927 echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
a6d2e0de 928
95e93571 929do_hook('left_main_before');
1053f1e5 930if ($advanced_tree) {
a6172cd5 931 /* nice future feature, needs layout !! volunteers? */
599038d5 932 $right_pos = $left_size - 20;
b6d26135 933/* 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 934 echo '<div ID="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
935 echo '<div ID="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
936 echo '<div ID="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
b6d26135 937 echo '<div ID="leftframe"><br /><br />';*/
599038d5 938}
2d367c68 939
a6172cd5 940echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
941 html_tag( 'tr' ) .
942 html_tag( 'td', '', 'left' ) .
d68323ff 943 '<center><font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
a6d2e0de 944
95e93571 945if ($date_format != 6) {
946 /* First, display the clock. */
947 if ($hour_format == 1) {
948 $hr = 'G:i';
949 if ($date_format == 4) {
950 $hr .= ':s';
a6d2e0de 951 }
95e93571 952 } else {
953 if ($date_format == 4) {
954 $hr = 'g:i:s a';
955 } else {
956 $hr = 'g:i a';
2d367c68 957 }
958 }
959
95e93571 960 switch( $date_format ) {
961 case 1:
962 $clk = date('m/d/y '.$hr, time());
963 break;
964 case 2:
965 $clk = date('d/m/y '.$hr, time());
966 break;
967 case 4:
968 case 5:
969 $clk = date($hr, time());
970 break;
971 default:
67eb95d7 972 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
2d367c68 973 }
95e93571 974 $clk = str_replace(' ','&nbsp;',$clk);
975
3fde693b 976 echo '<center><small>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
977 ": $clk</small></center>";
95e93571 978}
979
980/* Next, display the refresh button. */
3fde693b 981echo '<small>(<a href="../src/left_main.php" target="left">'.
d68323ff 982 _("refresh folder list") . '</a>)</small></center><br />';
95e93571 983
984/* Lastly, display the folder list. */
985if ( $collapse_folders ) {
986 /* If directed, collapse or uncollapse a folder. */
987 if (isset($fold)) {
988 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
989 } else if (isset($unfold)) {
990 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
991 }
992}
993
f23f6a3a 994if ($oldway) { /* normal behaviour SM */
a6172cd5 995
f23f6a3a 996$boxes = sqimap_mailbox_list($imapConnection);
95e93571 997/* Prepare do do out collapsedness and visibility computation. */
998$curbox = 0;
999$boxcount = count($boxes);
1000
1001/* Compute the collapsedness and visibility of each box. */
90de1755 1002
95e93571 1003while ($curbox < $boxcount) {
1004 $boxes[$curbox]['visible'] = TRUE;
1005 compute_folder_children($curbox, $boxcount);
1006}
1007
1c52ba77 1008for ($i = 0; $i < count($boxes); $i++) {
95e93571 1009 if ( $boxes[$i]['visible'] ) {
1010 $mailbox = $boxes[$i]['formatted'];
1011 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
1012
1013 /* Create the prefix for the folder name and link. */
1014 $prefix = str_repeat(' ',$mblevel);
1015 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
1016 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
1017 create_collapse_link($i) . '&nbsp;';
1018 } else {
1019 $prefix = str_replace(' ','&nbsp;',$prefix);
1020 }
d68323ff 1021 $line = "<nobr><tt>$prefix</tt>";
95e93571 1022
1023 /* Add the folder name and link. */
1c52ba77 1024 if (! isset($color[15])) {
05611cba 1025 $color[15] = $color[6];
1c52ba77 1026 }
90de1755 1027
95e93571 1028 if (in_array('noselect', $boxes[$i]['flags'])) {
1c52ba77 1029 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
d68323ff 1030 $line .= "<font color=\"$color[11]\">";
1c52ba77 1031 } else {
d68323ff 1032 $line .= "<font color=\"$color[15]\">";
1c52ba77 1033 }
95e93571 1034 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
1035 $mailbox = str_replace('&nbsp;','',$mailbox);
1036 $line .= str_replace(' ', '&nbsp;', $mailbox);
2d367c68 1037 }
d68323ff 1038 $line .= '</font>';
95e93571 1039 } else {
1040 $line .= formatMailboxName($imapConnection, $boxes[$i]);
1041 }
2d367c68 1042
95e93571 1043 /* Put the final touches on our folder line. */
d68323ff 1044 $line .= "</nobr><br>\n";
2d367c68 1045
95e93571 1046 /* Output the line for this folder. */
1047 echo $line;
2d367c68 1048 }
95e93571 1049}
a6172cd5 1050} else { /* expiremental code */
f23f6a3a 1051 $boxes = sqimap_mailbox_tree($imapConnection);
1052 if (isset($advanced_tree) && $advanced_tree) {
e4c5976a 1053 echo '<form name="collapse" action="left_main.php" method="post" ' .
1054 'enctype="multipart/form-data"'."\n";
b6d26135 1055 echo '<small>';
4bdcd5e0 1056 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 1057 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
3170c448 1058 sqgetGlobalVar('mbx', $mbx, SQ_POST);
e4c5976a 1059 if (!isset($mbx)) $mbx=NULL;
a6172cd5 1060 ListAdvancedBoxes($boxes, $mbx);
3170c448 1061 echo '</div>';
1062 echo '</small>';
e4c5976a 1063 echo '</form>'."\n";
f23f6a3a 1064 } else {
0654bd86 1065 //sqimap_get_status_mbx_tree($imap_stream,$boxes)
e4c5976a 1066 ListBoxes($boxes);
f23f6a3a 1067 }
1068} /* if ($oldway) else ... */
95e93571 1069do_hook('left_main_after');
76b684a5 1070sqimap_logout($imapConnection);
2d367c68 1071
3fde693b 1072echo '</td></tr></table>' . "\n".
1073 "</div></body></html>\n";
2d367c68 1074
7fb54066 1075?>