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