6 * This is the code for the left bar. The left bar shows the folders
7 * available, and has cookie information.
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
16 * Path for SquirrelMail required files.
19 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 include_once(SM_PATH
. 'include/validate.php');
23 require_once(SM_PATH
. 'functions/imap.php');
24 require_once(SM_PATH
. 'functions/plugin.php');
25 require_once(SM_PATH
. 'functions/page_header.php');
26 require_once(SM_PATH
. 'functions/html.php');
27 require_once(SM_PATH
. 'functions/date.php');
29 /* These constants are used for folder stuff. */
30 define('SM_BOX_UNCOLLAPSED', 0);
31 define('SM_BOX_COLLAPSED', 1);
33 /* --------------------- FUNCTIONS ------------------------- */
37 * Recursive function to output a tree of folders.
38 * It is called on a list of boxes and iterates over that tree.
42 function ListBoxes ($boxes, $j=0 ) {
43 global $data_dir, $username, $color, $unseen_notify, $unseen_type,
44 $move_to_trash, $trash_folder, $collapse_folders, $imapConnection,
45 $use_icons, $icon_theme, $use_special_folder_color;
52 $pre = '<span style="white-space: nowrap;">';
55 $unseen_found = false;
58 $mailbox = $boxes->mailboxname_full
;
59 $leader = str_repeat(' ',$j);
60 $mailboxURL = urlencode($mailbox);
62 /* get unseen/total messages information */
63 /* Only need to display info when option is set */
64 if (isset($unseen_notify) && ($unseen_notify > 1) &&
65 (($boxes->unseen
!== false) ||
($boxes->total
!== false))) {
67 if ($boxes->unseen
!== false)
68 $unseen = $boxes->unseen
;
71 Should only display unseen info if the folder is inbox
72 or you set the option for all folders
75 if ((strtolower($mailbox) == 'inbox') ||
($unseen_notify == 3)) {
76 $unseen_string = $unseen;
78 /* If users requests, display message count too */
79 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total
!== false)) {
80 $unseen_string .= '/' . $boxes->total
;
83 $unseen_string = "<span class=\"highlight\">($unseen_string)</span>";
86 Finally allow the script to display the values by setting a boolean.
87 This can only occur if the unseen count is great than 0 (if you have
88 unseen count only), or you have the message count too.
90 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
96 if (isset($boxes->mbxs
[0]) && $collapse_folders) {
97 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
98 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
100 $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
102 if ($use_icons && $icon_theme != 'none') {
103 $link .= "unfold=$mailboxURL\">$leader<img src=\"" . SM_PATH
. 'images/plus.png" border="0" height="7" width="7" /> ';
105 $link .= "unfold=$mailboxURL\">$leader+ ";
108 if ($use_icons && $icon_theme != 'none') {
109 $link .= "fold=$mailboxURL\">$leader<img src=\"" . SM_PATH
. 'images/minus.png" border="0" height="7" width="7" /> ';
111 $link .= "fold=$mailboxURL\">$leader- ";
117 $pre.= $leader . ' ';
120 /* If there are unseen message, bold the line. */
121 if (($move_to_trash) && ($mailbox == $trash_folder)) {
123 if ( !is_numeric($boxes->total
) ) {
124 $result = sqimap_status_messages($imapConnection, $mailbox);
125 $boxes->total
= $result['MESSAGES'];
126 $boxes->unseen
= $result['UNSEEN'];
129 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
135 if ($boxes->total
> 0) {
136 /* Print unseen information. */
138 $end .= " <small>$unseen_string</small>";
140 $end .= "\n<small>" .
141 ' [<a href="empty_trash.php">'._("Purge").'</a>]'.
145 if (!$boxes->is_noselect
) {
146 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
153 /* Print unseen information. */
155 $end .= " <small>$unseen_string</small>";
162 if ($use_special_folder_color && $boxes->is_special
) {
163 $span = "<span class=\"leftspecial\">";
164 $spanend = "</span>";
165 } elseif ( $boxes->is_noselect
) {
166 $span = "<span class=\"leftnoselect\">";
167 $spanend = '</span>';
171 // let plugins fiddle with end of line
172 $end .= concat_hook_function('left_main_after_each_folder',
173 array(isset($numMessages) ?
$numMessages : '',
174 $boxes->mailboxname_full
, $imapConnection));
178 if (!$boxes->is_root
) {
179 echo "" . $span . $pre .
182 array(' ','<','>'),
183 $boxes->mailboxname_sub
) .
184 $end. $spanend .'<br />' . "\n";
188 if (!$collapse ||
$boxes->is_root
) {
189 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
190 ListBoxes($boxes->mbxs
[$i],$j);
195 function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
196 global $data_dir, $username, $color, $unseen_notify, $unseen_type,
197 $move_to_trash, $trash_folder, $collapse_folders, $use_special_folder_color;
203 /* use_folder_images only works if the images exist in ../images */
204 $use_folder_images = true;
209 $unseen_found = false;
212 $mailbox = $boxes->mailboxname_full
;
213 $mailboxURL = urlencode($mailbox);
215 /* get unseen/total messages information */
216 /* Only need to display info when option is set */
217 if (isset($unseen_notify) && ($unseen_notify > 1) &&
218 (($boxes->unseen
!== false) ||
($boxes->total
!== false))) {
220 if ($boxes->unseen
!== false)
221 $unseen = $boxes->unseen
;
224 Should only display unseen info if the folder is inbox
225 or you set the option for all folders
228 if ((strtolower($mailbox) == 'inbox') ||
($unseen_notify == 3)) {
229 $unseen_string = $unseen;
231 /* If users requests, display message count too */
232 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total
!== false)) {
233 $unseen_string .= '/' . $boxes->total
;
236 $unseen_string = "<span class=\"highlight\">($unseen_string)</span>";
239 Finally allow the script to display the values by setting a boolean.
240 This can only occur if the unseen count is great than 0 (if you have
241 unseen count only), or you have the message count too.
243 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
244 $unseen_found = true;
249 /* If there are unseen message, bold the line. */
250 if ($unseen > 0) { $pre .= '<b>'; }
252 /* color special boxes */
253 if ($use_special_folder_color && $boxes->is_special
) {
254 $pre .= "<span class=\"leftspecial\">";
258 /* If there are unseen message, close bolding. */
259 if ($unseen > 0) { $end .= '</b>'; }
261 /* Print unseen information. */
263 $end .= " $unseen_string";
266 if (($move_to_trash) && ($mailbox == $trash_folder)) {
267 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
269 $end .= "\n<small>\n" .
270 ' [<a class="mbx_link" href="empty_trash.php">'._("Purge").'</a>]'.
273 if (!$boxes->is_noselect
) { /* \Noselect boxes can't be selected */
274 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
279 // let plugins fiddle with end of line
280 global $imapConnection;
281 $end .= concat_hook_function('left_main_after_each_folder',
282 array(isset($numMessages) ?
$numMessages : '',
283 $boxes->mailboxname_full
, $imapConnection));
285 if (!$boxes->is_root
) {
286 if ($use_folder_images) {
287 if ($boxes->is_inbox
) {
288 $folder_img = '../images/inbox.png';
289 } else if ($boxes->is_sent
) {
290 $folder_img = '../images/senti.png';
291 } else if ($boxes->is_trash
) {
292 $folder_img = '../images/delitem.png';
293 } else if ($boxes->is_draft
) {
294 $folder_img = '../images/draft.png';
295 } else if ($boxes->is_noinferiors
) {
296 $folder_img = '../images/folder_noinf.png';
298 $folder_img = '../images/folder.png';
300 $folder_img = ' <img src="'.$folder_img.'" height="15" /> ';
304 if (!isset($boxes->mbxs
[0])) {
305 echo ' ' . html_tag( 'div',
307 str_replace( array(' ','<','>'),
308 array(' ','<','>'),
309 $boxes->mailboxname_sub
) .
311 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
313 /* get collapse information */
314 if ($collapse_folders) {
315 $form_entry = $j.'F';
316 if (isset($mbx) && isset($mbx[$form_entry])) {
317 $collapse = $mbx[$form_entry];
318 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full
,
319 $collapse ? SM_BOX_COLLAPSED
: SM_BOX_UNCOLLAPSED
);
321 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
322 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
324 $img_src = ($collapse ?
'../images/plus.png' : '../images/minus.png');
325 $collapse_link = '<a href="javascript:void(0)">' .
326 " <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
330 echo ' ' . html_tag( 'div',
331 $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub
. $end ,
332 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
333 echo ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
337 $visible = ($collapse ?
' style="display:none"' : ' style="display:block"');
338 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) /* mailbox contains childs */
339 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
341 if ($j !='ID.0000') {
344 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
346 ListAdvancedBoxes($boxes->mbxs
[$i],$mbx,$j);
348 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) {
349 echo '</div>'."\n\n";
356 /* -------------------- MAIN ------------------------ */
359 sqgetGlobalVar('username', $username, SQ_SESSION
);
360 sqgetGlobalVar('key', $key, SQ_COOKIE
);
361 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
362 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
364 sqgetGlobalVar('fold', $fold, SQ_GET
);
365 sqgetGlobalVar('unfold', $unfold, SQ_GET
);
369 // open a connection on the imap port (143)
370 // why hide the output?
371 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true);
374 * Using stristr since very old preferences may contain "None" and "none".
376 if (!empty($left_refresh) &&
377 !stristr($left_refresh, 'none')){
378 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
379 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
380 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
386 * $advanced_tree and is a boolean var which is default set to default
388 * Setting $advanced tree to true causes SM to display a experimental
389 * mailbox-tree with dhtml behaviour.
390 * It only works on browsers which supports css and javascript. The used
391 * javascript is experimental and doesn't support all browsers.
392 * It has been tested on IE6 an Konquerer 3.0.0-2.
393 * It is now tested and working on: (please test and update this list)
394 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
397 * In the function ListAdvancedBoxes there is another var $use_folder_images.
398 * setting this to true is only usefull if the images exists in ../images.
400 * Feel free to experiment with the code and report bugs and enhancements
403 /* set this to true if you want to see a nicer mailboxtree */
404 if (empty($advanced_tree)) {
405 $advanced_tree=false;
408 if ($advanced_tree) {
410 <script type="text/javascript">
413 if (document.images) {
414 var treeImages = new Array;
415 var arguments = preload.arguments;
416 for (var i = 0; i<arguments.length; i++) {
417 treeImages[i] = new Image();
418 treeImages[i].src = arguments[i];
425 function fTreeTimeout() {
426 if (vTreeDiv.readyState == "complete")
427 vTreeImg.src = vTreeSrc;
429 setTimeout("fTreeTimeout()", 100);
431 function hidechilds(img) {
432 id = img.id + ".0000";
433 form_id = "mbx[" + img.id +"F]";
434 if (document.all) { //IE, Opera7
435 div = document.all[id];
437 if (div.style.display == "none") {
438 vTreeSrc = "../images/minus.png";
443 vTreeSrc = "../images/plus.png";
449 if (typeof vTreeDiv.readyState != "undefined") //IE
450 setTimeout("fTreeTimeout()",100);
452 vTreeImg.src = vTreeSrc;
453 div.style.display = style;
454 document.all[form_id].value = value;
457 else if (document.getElementById) { //Gecko
458 div = document.getElementById(id);
460 if (div.style.display == "none") {
461 src = "../images/minus.png";
466 src = "../images/plus.png";
470 div.style.display = style;
472 document.getElementById(form_id).value = value;
476 function buttonover(el,on) {
478 el.style.background="$color[0]";}
480 el.style.background="$color[9]";}
482 function buttonclick(el,on) {
484 el.style.border="groove";}
486 el.style.border="ridge";}
488 function hideframe(hide) {
489 left_size = "$left_size";
491 masterf = window.parent.document.all["fs1"];
492 leftf = window.parent.document.all["left"];
493 leftcontent = document.all["leftframe"];
494 leftbutton = document.all["showf"];
495 } else if (document.getElementById) {
496 masterf = window.parent.document.getElementById("fs1");
497 leftf = window.parent.document.getElementById("left");
498 leftcontent = document.getElementById("leftframe");
499 leftbutton = document.getElementById("showf");
504 new_col = calc_col("20");
505 masterf.cols = new_col;
506 document.body.scrollLeft=0;
507 document.body.style.overflow="hidden";
508 leftcontent.style.display = "none";
509 leftbutton.style.display="block";
511 masterf.cols = calc_col(left_size);
512 document.body.style.overflow="";
513 leftbutton.style.display="none";
514 leftcontent.style.display="block";
517 function calc_col(c_w) {
519 if ($location_of_bar == 'right') {
520 $xtra .= ' right=true;';
522 $xtra .= ' right=false;';
532 function resizeframe(direction) {
534 masterf = window.parent.document.all["fs1"];
535 } else if (document.getElementById) {
536 window.parent.document.getElementById("fs1");
541 if ($location_of_bar == 'right') {
542 $xtra .= ' colPat=/^\*,(\d+)$/;';
544 $xtra .= ' colPat=/^(\d+),.*$/;';
547 old_col = masterf.cols;
548 colPat.exec(old_col);
550 new_col_width = parseInt(RegExp.$1) + 25;
552 if (parseInt(RegExp.$1) > 35) {
553 new_col_width = parseInt(RegExp.$1) - 25;
556 masterf.cols = calc_col(new_col_width);
563 /* style definitions */
566 <style type="text/css">
569 margin: 0px 0px 0px 0px;
570 padding: 5px 5px 5px 5px;
573 vertical-align: middle;
577 border-color: $color[9];
578 background:$color[0];
590 text-decoration: none;
591 background-color: $color[0];
595 background-color: $color[9];
615 border-left-width:0.1em;
616 border-left-color:$color[9];
617 border-bottom: solid;
618 border-bottom-width:0.1em;
619 border-bottom-color:$color[9];
630 border-color:$color[9];
631 background: $color[0];
640 // get mailbox list and cache it
641 $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
643 displayHtmlHeader( 'SquirrelMail', $xtra );
645 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION
);
646 /* If requested and not yet complete, attempt to autocreate folders. */
647 if ($auto_create_special && !isset($auto_create_done)) {
648 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
649 $folders_created = false;
650 foreach( $autocreate as $folder ) {
651 if (($folder != '') && ($folder != 'none')) {
652 // use $mailboxes array for checking if mailbox exists
653 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailboxes)) {
654 sqimap_mailbox_create($imapConnection, $folder, '');
655 $folders_created = true;
657 // check for subscription is useless and expensive, just
658 // surpress the NO response. Unless we're on Mecury, which
659 // will just subscribe a folder again if it's already
661 if ( strtolower($imap_server_type) != 'mercury32' ||
662 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
663 sqimap_subscribe($imapConnection, $folder, false);
664 $folders_created = true;
670 /* Let the world know that autocreation is complete! Hurrah! */
671 $auto_create_done = TRUE;
672 sqsession_register($auto_create_done, 'auto_create_done');
673 // reload mailbox list
674 if ($folders_created)
675 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
678 if ($advanced_tree) {
680 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
681 " class=\"leftmain\">\n<div class=\"leftmain\">\n";
683 echo "\n<body class=\"leftmain\">\n<div class=\"leftmain\">\n";
686 do_hook('left_main_before');
687 if ($advanced_tree) {
688 /* nice future feature, needs layout !! volunteers? */
689 $right_pos = $left_size - 20;
690 /* 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>';
691 echo '<div id="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
692 echo '<div id="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
693 echo '<div id="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
694 echo '<div id="leftframe"><br /><br />';*/
697 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
699 html_tag( 'td', '', 'left' ) .
700 html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0"' ) .
702 html_tag( 'td', '', 'center' ) .
703 '<font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
705 if ($date_format != 6) {
706 /* First, display the clock. */
707 if ($hour_format == 1) {
709 if ($date_format == 4) {
713 if ($date_format == 4) {
720 switch( $date_format ) {
722 $clk = date('Y-m-d '.$hr. ' T', time());
725 $clk = date('m/d/y '.$hr, time());
728 $clk = date('d/m/y '.$hr, time());
732 $clk = date($hr, time());
735 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
737 $clk = str_replace(' ',' ',$clk);
739 echo '<small><span style="white-space: nowrap;">'
740 . str_replace(' ', ' ', _("Last Refresh"))
741 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
744 /* Next, display the refresh button. */
745 echo '<div style="white-space: nowrap;"><small>[<a href="../src/left_main.php" target="left">'.
746 _("Check mail") . "</a>]</small></div></td></tr></table><br />\n\n";
748 /* Lastly, display the folder list. */
750 if ( $collapse_folders ) {
751 /* If directed, collapse or uncollapse a folder. */
753 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED
);
754 } else if (isset($unfold)) {
755 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED
);
759 /* Get unseen/total display prefs */
760 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
761 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
763 if (empty($unseen_type)) {
764 if (!empty($default_unseen_type)) {
765 $unseen_type = $default_unseen_type;
771 if (empty($unseen_notify)) {
772 if (!empty($default_unseen_notify)) {
773 $unseen_notify = $default_unseen_notify;
779 * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
780 * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
782 $boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
784 if (isset($advanced_tree) && $advanced_tree) {
785 echo '<form name="collapse" action="left_main.php" method="post" ' .
786 'enctype="multipart/form-data">'."\n";
787 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 />';
788 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
789 sqgetGlobalVar('mbx', $mbx, SQ_POST
);
790 if (!isset($mbx)) $mbx=NULL;
791 ListAdvancedBoxes($boxes, $mbx);
798 do_hook('left_main_after');
799 sqimap_logout($imapConnection);
805 $oTemplate->display('footer.tpl');