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