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