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