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