Stop error messages just in case CHMOD is disabled by PHP
[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) {
c72be5a6 551 $link = '<a href="javascript:void(0)">'." <img src=\"../images/plus.png\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
a6172cd5 552 } else {
c72be5a6 553 $link = '<a href="javascript:void(0)">'."<img src=\"../images/minus.png\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></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) {
c72be5a6 565 $visible = ' style="display:none"';
a6172cd5 566 } else {
c72be5a6 567 $visible = ' style="display:block"';
a6172cd5 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.
c72be5a6 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
c72be5a6 623 * javascript is experimental and doesn't support all browsers.
624 * It has been tested on IE6 an Konquerer 3.0.0-2.
625 * It is now tested and working on: (please test and update this list)
626 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
627 * XWindow: ?
628 * Mac: ?
f23f6a3a 629 * In the function ListAdvancedBoxes there is another var $use_folder_images.
630 * setting this to true is only usefull if the images exists in ../images.
a6172cd5 631 *
f23f6a3a 632 * Feel free to experiment with the code and report bugs and enhancements
633 * to marc@its-projects.nl
a6172cd5 634 **/
f23f6a3a 635
636$advanced_tree = false; /* set this to true if you want to see a nicer mailboxtree */
38068e69 637$oldway = false; /* default SM behaviour */
f23f6a3a 638
639if ($advanced_tree) {
640$xtra .= <<<ECHO
599038d5 641<script language="Javascript" TYPE="text/javascript">
f23f6a3a 642
599038d5 643<!--
f23f6a3a 644
51ea258b 645 function preload() {
646 if (document.images) {
647 var treeImages = new Array;
648 var arguments = preload.arguments;
649 for (var i = 0; i<arguments.length; i++) {
650 treeImages[i] = new Image();
651 treeImages[i].src = arguments[i];
652 }
653 }
654 }
655
99034855 656var vTreeImg;
657var vTreeDiv;
658var vTreeSrc;
659
660 function fTreeTimeout() {
661 if (vTreeDiv.readyState == "complete")
662 vTreeImg.src = vTreeSrc;
663 else
664 setTimeout("fTreeTimeout()", 100);
665 }
666
667 function hidechilds(img) {
668 id = img.id + ".0000";
669 form_id = "mbx[" + img.id +"F]";
c72be5a6 670 if (document.all) { //IE, Opera7
99034855 671 div = document.all[id];
672 if (div) {
673 if (div.style.display == "none") {
674 vTreeSrc = "../images/minus.png";
675 style = "block";
676 value = 0;
677 }
678 else {
679 vTreeSrc = "../images/plus.png";
680 style = "none";
681 value = 1;
a6172cd5 682 }
99034855 683 vTreeImg = img;
684 vTreeDiv = div;
c72be5a6 685 if (typeof vTreeDiv.readyState != "undefined") //IE
686 setTimeout("fTreeTimeout()",100);
687 else //Non IE
688 vTreeImg.src = vTreeSrc;
99034855 689 div.style.display = style;
690 document.all[form_id].value = value;
a6172cd5 691 }
99034855 692 }
c72be5a6 693 else if (document.getElementById) { //Gecko
99034855 694 div = document.getElementById(id);
695 if (div) {
696 if (div.style.display == "none") {
697 src = "../images/minus.png";
698 style = "block";
699 value = 0;
700 }
701 else {
702 src = "../images/plus.png";
703 style = "none";
704 value = 1;
a6172cd5 705 }
99034855 706 div.style.display = style;
707 img.src = src;
708 document.getElementById(form_id).value = value;
a6172cd5 709 }
51ea258b 710 }
a6172cd5 711 }
a6172cd5 712
f23f6a3a 713 function buttonover(el,on) {
714 if (!on) {
c72be5a6 715// el.style.borderColor="$color[9]";}
716 el.style.background="$color[0]";}
f23f6a3a 717 else {
c72be5a6 718 el.style.background="$color[9]";}
f23f6a3a 719 }
720
721 function buttonclick(el,on) {
a6172cd5 722 if (!on) {
c72be5a6 723 el.style.border="groove";}
f23f6a3a 724 else {
725 el.style.border="ridge";}
726 }
599038d5 727
728 function hideframe(hide) {
a6172cd5 729
599038d5 730ECHO;
731$xtra .= " left_size = \"$left_size\";\n";
732$xtra .= <<<ECHO
733 if (document.all) {
a6172cd5 734 masterf = window.parent.document.all["fs1"];
735 leftf = window.parent.document.all["left"];
736 leftcontent = document.all["leftframe"];
737 leftbutton = document.all["showf"];
599038d5 738 } else if (document.getElementById) {
a6172cd5 739 masterf = window.parent.document.getElementById("fs1");
740 leftf = window.parent.document.getElementById("left");
741 leftcontent = document.getElementById("leftframe");
742 leftbutton = document.getElementById("showf");
599038d5 743 } else {
744 return false;
a6172cd5 745 }
599038d5 746 if(hide) {
747 new_col = calc_col("20");
748 masterf.cols = new_col;
a6172cd5 749 document.body.scrollLeft=0;
750 document.body.style.overflow='hidden';
751 leftcontent.style.display = 'none';
752 leftbutton.style.display='block';
599038d5 753 } else {
754 masterf.cols = calc_col(left_size);
a6172cd5 755 document.body.style.overflow='';
756 leftbutton.style.display='none';
757 leftcontent.style.display='block';
758
599038d5 759 }
760 }
a6172cd5 761
599038d5 762 function calc_col(c_w) {
763
764ECHO;
765 if ($location_of_bar == 'right') {
766 $xtra .= ' right=true;';
a6172cd5 767 } else {
599038d5 768 $xtra .= ' right=false;';
769 }
770 $xtra .= "\n";
771$xtra .= <<<ECHO
772 if (right) {
773 new_col = '*,'+c_w;
774 } else {
775 new_col = c_w+',*';
776 }
777 return new_col;
a6172cd5 778 }
779
599038d5 780 function resizeframe(direction) {
781 if (document.all) {
a6172cd5 782 masterf = window.parent.document.all["fs1"];
599038d5 783 } else if (document.getElementById) {
a6172cd5 784 window.parent.document.getElementById("fs1");
599038d5 785 } else {
786 return false;
787 }
a6172cd5 788
599038d5 789ECHO;
790 if ($location_of_bar == 'right') {
791 $xtra .= ' colPat=/^\*,(\d+)$/;';
a6172cd5 792 } else {
599038d5 793 $xtra .= ' colPat=/^(\d+),.*$/;';
794 }
795 $xtra .= "\n";
a6172cd5 796
599038d5 797$xtra .= <<<ECHO
798 old_col = masterf.cols;
799 colPat.exec(old_col);
a6172cd5 800
599038d5 801 if (direction) {
802 new_col_width = parseInt(RegExp.$1) + 25;
a6172cd5 803
599038d5 804 } else {
805 if (parseInt(RegExp.$1) > 35) {
806 new_col_width = parseInt(RegExp.$1) - 25;
807 }
808 }
a6172cd5 809 masterf.cols = calc_col(new_col_width);
599038d5 810 }
811
812//-->
a6172cd5 813
f23f6a3a 814</script>
815
816ECHO;
817
818/* style definitions */
386e556f 819
f23f6a3a 820$xtra .= <<<ECHO
821
d68323ff 822<style type="text/css">
f23f6a3a 823<!--
599038d5 824 body {
825 margin: 0px 0px 0px 0px;
826 padding: 5px 5px 5px 5px;
827 }
c8fa94cf 828
f23f6a3a 829 .button {
830 border:outset;
c72be5a6 831 border-color: $color[9];
832 background:$color[0];
833 color:$color[6];
f23f6a3a 834 width:99%;
835 heigth:99%;
836 }
837
838 .mbx_par {
d1dbd575 839 font-size:1.0em;
599038d5 840 margin-left:4px;
841 margin-right:0px;
c8fa94cf 842 }
599038d5 843
c8fa94cf 844 a.mbx_link {
845 text-decoration: none;
846 background-color: $color[0];
847 display: inline;
848 }
849
850 a:hover.mbx_link {
851 background-color: $color[9];
852 }
853
854 a.mbx_link img {
855 border-style: none;
f23f6a3a 856 }
857
858 .mbx_sub {
f23f6a3a 859 padding-left:5px;
599038d5 860 padding-right:0px;
f23f6a3a 861 margin-left:4px;
599038d5 862 margin-right:0px;
d1dbd575 863 font-size:0.9em;
f23f6a3a 864 }
865
866 .par_area {
599038d5 867 margin-top:0px;
868 margin-left:4px;
869 margin-right:0px;
f23f6a3a 870 padding-left:10px;
599038d5 871 padding-bottom:5px;
f23f6a3a 872 border-left: solid;
873 border-left-width:0.1em;
51ea258b 874 border-left-color:$color[9];
f23f6a3a 875 border-bottom: solid;
876 border-bottom-width:0.1em;
51ea258b 877 border-bottom-color:$color[9];
c8fa94cf 878 display: block;
f23f6a3a 879 }
880
881 .mailboxes {
f23f6a3a 882 padding-bottom:3px;
599038d5 883 margin-right:4px;
884 padding-right:4px;
885 margin-left:4px;
886 padding-left:4px;
f23f6a3a 887 border: groove;
888 border-width:0.1em;
c72be5a6 889 border-color:$color[9];
c8fa94cf 890 background: $color[0];
f23f6a3a 891 }
892
893-->
894
d68323ff 895</style>
f23f6a3a 896
897ECHO;
898
899}
900
901
902
903
95e93571 904displayHtmlHeader( 'SquirrelMail', $xtra );
905
906/* If requested and not yet complete, attempt to autocreate folders. */
907if ($auto_create_special && !isset($auto_create_done)) {
a3439b27 908 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
95e93571 909 foreach( $autocreate as $folder ) {
a3439b27 910 if (($folder != '') && ($folder != 'none')) {
95e93571 911 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
912 sqimap_mailbox_create($imapConnection, $folder, '');
a3439b27 913 } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
95e93571 914 sqimap_subscribe($imapConnection, $folder);
2d367c68 915 }
ebf18afa 916 }
2d367c68 917 }
a6d2e0de 918
95e93571 919 /* Let the world know that autocreation is complete! Hurrah! */
90de1755 920 $auto_create_done = TRUE;
a32985a5 921 sqsession_register($auto_create_done, 'auto_create_done');
95e93571 922}
a6d2e0de 923
51ea258b 924if ($advanced_tree)
925 echo "\n<body" .
926 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
927 " bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
928else
929 echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
a6d2e0de 930
95e93571 931do_hook('left_main_before');
1053f1e5 932if ($advanced_tree) {
a6172cd5 933 /* nice future feature, needs layout !! volunteers? */
599038d5 934 $right_pos = $left_size - 20;
b6d26135 935/* 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 936 echo '<div ID="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
937 echo '<div ID="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
938 echo '<div ID="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
b6d26135 939 echo '<div ID="leftframe"><br /><br />';*/
599038d5 940}
2d367c68 941
a6172cd5 942echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
943 html_tag( 'tr' ) .
944 html_tag( 'td', '', 'left' ) .
d68323ff 945 '<center><font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
a6d2e0de 946
95e93571 947if ($date_format != 6) {
948 /* First, display the clock. */
949 if ($hour_format == 1) {
950 $hr = 'G:i';
951 if ($date_format == 4) {
952 $hr .= ':s';
a6d2e0de 953 }
95e93571 954 } else {
955 if ($date_format == 4) {
956 $hr = 'g:i:s a';
957 } else {
958 $hr = 'g:i a';
2d367c68 959 }
960 }
961
95e93571 962 switch( $date_format ) {
963 case 1:
964 $clk = date('m/d/y '.$hr, time());
965 break;
966 case 2:
967 $clk = date('d/m/y '.$hr, time());
968 break;
969 case 4:
970 case 5:
971 $clk = date($hr, time());
972 break;
973 default:
fc6f062a 974 $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() );
2d367c68 975 }
95e93571 976 $clk = str_replace(' ','&nbsp;',$clk);
977
3fde693b 978 echo '<center><small>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
979 ": $clk</small></center>";
95e93571 980}
981
982/* Next, display the refresh button. */
3fde693b 983echo '<small>(<a href="../src/left_main.php" target="left">'.
d68323ff 984 _("refresh folder list") . '</a>)</small></center><br />';
95e93571 985
986/* Lastly, display the folder list. */
987if ( $collapse_folders ) {
988 /* If directed, collapse or uncollapse a folder. */
989 if (isset($fold)) {
990 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
991 } else if (isset($unfold)) {
992 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
993 }
994}
995
f23f6a3a 996if ($oldway) { /* normal behaviour SM */
a6172cd5 997
f23f6a3a 998$boxes = sqimap_mailbox_list($imapConnection);
95e93571 999/* Prepare do do out collapsedness and visibility computation. */
1000$curbox = 0;
1001$boxcount = count($boxes);
1002
1003/* Compute the collapsedness and visibility of each box. */
90de1755 1004
95e93571 1005while ($curbox < $boxcount) {
1006 $boxes[$curbox]['visible'] = TRUE;
1007 compute_folder_children($curbox, $boxcount);
1008}
1009
1c52ba77 1010for ($i = 0; $i < count($boxes); $i++) {
95e93571 1011 if ( $boxes[$i]['visible'] ) {
1012 $mailbox = $boxes[$i]['formatted'];
1013 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
1014
1015 /* Create the prefix for the folder name and link. */
1016 $prefix = str_repeat(' ',$mblevel);
1017 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
1018 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
1019 create_collapse_link($i) . '&nbsp;';
1020 } else {
1021 $prefix = str_replace(' ','&nbsp;',$prefix);
1022 }
d68323ff 1023 $line = "<nobr><tt>$prefix</tt>";
95e93571 1024
1025 /* Add the folder name and link. */
1c52ba77 1026 if (! isset($color[15])) {
05611cba 1027 $color[15] = $color[6];
1c52ba77 1028 }
90de1755 1029
95e93571 1030 if (in_array('noselect', $boxes[$i]['flags'])) {
1c52ba77 1031 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
d68323ff 1032 $line .= "<font color=\"$color[11]\">";
1c52ba77 1033 } else {
d68323ff 1034 $line .= "<font color=\"$color[15]\">";
1c52ba77 1035 }
95e93571 1036 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
1037 $mailbox = str_replace('&nbsp;','',$mailbox);
1038 $line .= str_replace(' ', '&nbsp;', $mailbox);
2d367c68 1039 }
d68323ff 1040 $line .= '</font>';
95e93571 1041 } else {
1042 $line .= formatMailboxName($imapConnection, $boxes[$i]);
1043 }
2d367c68 1044
95e93571 1045 /* Put the final touches on our folder line. */
d68323ff 1046 $line .= "</nobr><br>\n";
2d367c68 1047
95e93571 1048 /* Output the line for this folder. */
1049 echo $line;
2d367c68 1050 }
95e93571 1051}
a6172cd5 1052} else { /* expiremental code */
f23f6a3a 1053 $boxes = sqimap_mailbox_tree($imapConnection);
1054 if (isset($advanced_tree) && $advanced_tree) {
e4c5976a 1055 echo '<form name="collapse" action="left_main.php" method="post" ' .
1056 'enctype="multipart/form-data"'."\n";
b6d26135 1057 echo '<small>';
51ea258b 1058/* 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 1059 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
1060 if (!isset($mbx)) $mbx=NULL;
a6172cd5 1061 ListAdvancedBoxes($boxes, $mbx);
e4c5976a 1062 echo '</div></small>'."\n";
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?>