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