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