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