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, $unseen_cum;
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 /* handle Cumulative Unread Message Notification */
66 if ($collapse && $unseen_cum) {
67 foreach ($boxes->mbxs
as $cumn_box) {
68 if (!empty($cumn_box->unseen
)) $boxes->unseen +
= $cumn_box->unseen
;
69 if (!empty($cumn_box->total
)) $boxes->total +
= $cumn_box->total
;
72 if (($boxes->unseen
!== false) ||
($boxes->total
!== false)) {
73 if ($boxes->unseen
!== false) {
74 $unseen = $boxes->unseen
;
77 * Should only display unseen info if the folder is inbox
78 * or you set the option for all folders
80 if ((strtolower($mailbox) == 'inbox') ||
($unseen_notify == 3)) {
81 $unseen_string = $unseen;
82 /* If users requests, display message count too */
83 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total
!== false)) {
84 $unseen_string .= '/' . $boxes->total
;
86 $unseen_string = "<span class=\"leftunseen\">($unseen_string)</span>";
89 * Finally allow the script to display the values by setting a boolean.
90 * This can only occur if the unseen count is great than 0 (if you have
91 * unseen count only), or you have the message count too.
93 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
100 if (isset($boxes->mbxs
[0]) && $collapse_folders) {
101 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
102 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
103 $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
105 if ($use_icons && $icon_theme != 'none') {
106 $link .= "unfold=$mailboxURL\">$leader<img src=\"" . SM_PATH
. 'images/plus.png" border="0" height="7" width="7" /> ';
108 $link .= "unfold=$mailboxURL\">$leader+ ";
111 if ($use_icons && $icon_theme != 'none') {
112 $link .= "fold=$mailboxURL\">$leader<img src=\"" . SM_PATH
. 'images/minus.png" border="0" height="7" width="7" /> ';
114 $link .= "fold=$mailboxURL\">$leader- ";
120 $pre.= $leader . ' ';
123 /* If there are unseen message, bold the line. */
124 if (($move_to_trash) && ($mailbox == $trash_folder)) {
126 if ( !is_numeric($boxes->total
) ) {
127 $result = sqimap_status_messages($imapConnection, $mailbox);
128 $boxes->total
= $result['MESSAGES'];
129 $boxes->unseen
= $result['UNSEEN'];
132 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
138 if ($boxes->total
> 0) {
139 /* Print unseen information. */
141 $end .= " <small>$unseen_string</small>";
143 $end .= "\n<small>" .
144 ' [<a href="empty_trash.php">'._("Purge").'</a>]'.
148 if (!$boxes->is_noselect
) {
149 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
156 /* Print unseen information. */
158 $end .= " <small>$unseen_string</small>";
165 if ($use_special_folder_color && $boxes->is_special
) {
166 $span = "<span class=\"leftspecial\">";
167 $spanend = "</span>";
168 } elseif ( $boxes->is_noselect
) {
169 $span = "<span class=\"leftnoselect\">";
170 $spanend = '</span>';
174 // let plugins fiddle with end of line
175 $end .= concat_hook_function('left_main_after_each_folder',
176 array(isset($numMessages) ?
$numMessages : '',
177 $boxes->mailboxname_full
, $imapConnection));
181 if (!$boxes->is_root
) {
182 echo "" . $span . $pre .
185 array(' ','<','>'),
186 $boxes->mailboxname_sub
) .
187 $end. $spanend .'<br />' . "\n";
191 if (!$collapse ||
$boxes->is_root
) {
192 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
193 ListBoxes($boxes->mbxs
[$i],$j);
198 function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
199 global $data_dir, $username, $color, $unseen_notify, $unseen_type, $unseen_cum,
200 $move_to_trash, $trash_folder, $collapse_folders, $use_special_folder_color;
206 /* use_folder_images only works if the images exist in ../images */
207 $use_folder_images = true;
212 $unseen_found = false;
215 $mailbox = $boxes->mailboxname_full
;
216 $mailboxURL = urlencode($mailbox);
218 /* get collapse information */
219 if ($collapse_folders) {
220 $form_entry = $j.'F';
221 if (isset($mbx) && isset($mbx[$form_entry])) {
222 $collapse = $mbx[$form_entry];
223 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full
,
224 $collapse ? SM_BOX_COLLAPSED
: SM_BOX_UNCOLLAPSED
);
226 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
227 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
229 $img_src = ($collapse ?
'../images/plus.png' : '../images/minus.png');
230 $collapse_link = '<a href="javascript:void(0)">' .
231 " <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
236 /* get unseen/total messages information */
237 /* Only need to display info when option is set */
238 if (isset($unseen_notify) && ($unseen_notify > 1)) {
239 /* handle Cumulative Unread Message Notification */
240 if ($collapse && $unseen_cum) {
241 foreach ($boxes->mbxs
as $cumn_box) {
242 if (!empty($cumn_box->unseen
)) $boxes->unseen +
= $cumn_box->unseen
;
243 if (!empty($cumn_box->total
)) $boxes->total +
= $cumn_box->total
;
246 if (($boxes->unseen
!== false) ||
($boxes->total
!== false)) {
247 if ($boxes->unseen
!== false) $unseen = $boxes->unseen
;
249 * Should only display unseen info if the folder is inbox
250 * or you set the option for all folders
252 if ((strtolower($mailbox) == 'inbox') ||
($unseen_notify == 3)) {
253 $unseen_string = $unseen;
255 /* If users requests, display message count too */
256 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total
!== false)) {
257 $unseen_string .= '/' . $boxes->total
;
260 $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
263 * Finally allow the script to display the values by setting a boolean.
264 * This can only occur if the unseen count is great than 0 (if you have
265 * unseen count only), or you have the message count too.
267 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
268 $unseen_found = true;
274 /* If there are unseen message, bold the line. */
275 if ($unseen > 0) { $pre .= '<b>'; }
277 /* color special boxes */
278 if ($use_special_folder_color && $boxes->is_special
) {
279 $pre .= "<span class=\"leftspecial\">";
283 /* If there are unseen message, close bolding. */
284 if ($unseen > 0) { $end .= '</b>'; }
286 /* Print unseen information. */
288 $end .= " $unseen_string";
291 if (($move_to_trash) && ($mailbox == $trash_folder)) {
292 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
294 $end .= "\n<small>\n" .
295 ' [<a class="mbx_link" href="empty_trash.php">'._("Purge").'</a>]'.
298 if (!$boxes->is_noselect
) { /* \Noselect boxes can't be selected */
299 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
304 // let plugins fiddle with end of line
305 global $imapConnection;
306 $end .= concat_hook_function('left_main_after_each_folder',
307 array(isset($numMessages) ?
$numMessages : '',
308 $boxes->mailboxname_full
, $imapConnection));
310 if (!$boxes->is_root
) {
311 if ($use_folder_images) {
312 if ($boxes->is_inbox
) {
313 $folder_img = '../images/inbox.png';
314 } else if ($boxes->is_sent
) {
315 $folder_img = '../images/senti.png';
316 } else if ($boxes->is_trash
) {
317 $folder_img = '../images/delitem.png';
318 } else if ($boxes->is_draft
) {
319 $folder_img = '../images/draft.png';
320 } else if ($boxes->is_noinferiors
) {
321 $folder_img = '../images/folder_noinf.png';
323 $folder_img = '../images/folder.png';
325 $folder_img = ' <img src="'.$folder_img.'" height="15" /> ';
329 if (!isset($boxes->mbxs
[0])) {
330 echo ' ' . html_tag( 'div',
332 str_replace( array(' ','<','>'),
333 array(' ','<','>'),
334 $boxes->mailboxname_sub
) .
336 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
339 echo ' ' . html_tag( 'div',
340 $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub
. $end ,
341 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
342 echo ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
346 $visible = ($collapse ?
' style="display:none"' : ' style="display:block"');
347 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) /* mailbox contains childs */
348 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
350 if ($j !='ID.0000') {
353 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
355 ListAdvancedBoxes($boxes->mbxs
[$i],$mbx,$j);
357 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) {
358 echo '</div>'."\n\n";
365 /* -------------------- MAIN ------------------------ */
368 sqgetGlobalVar('username', $username, SQ_SESSION
);
369 sqgetGlobalVar('key', $key, SQ_COOKIE
);
370 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
371 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
373 sqgetGlobalVar('fold', $fold, SQ_GET
);
374 sqgetGlobalVar('unfold', $unfold, SQ_GET
);
378 // open a connection on the imap port (143)
379 // why hide the output?
380 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true);
383 * Using stristr since very old preferences may contain "None" and "none".
385 if (!empty($left_refresh) &&
386 !stristr($left_refresh, 'none')){
387 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
388 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
389 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
395 * $advanced_tree and is a boolean var which is default set to default
397 * Setting $advanced tree to true causes SM to display a experimental
398 * mailbox-tree with dhtml behaviour.
399 * It only works on browsers which supports css and javascript. The used
400 * javascript is experimental and doesn't support all browsers.
401 * It has been tested on IE6 an Konquerer 3.0.0-2.
402 * It is now tested and working on: (please test and update this list)
403 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
406 * In the function ListAdvancedBoxes there is another var $use_folder_images.
407 * setting this to true is only usefull if the images exists in ../images.
409 * Feel free to experiment with the code and report bugs and enhancements
412 /* set this to true if you want to see a nicer mailboxtree */
413 if (empty($advanced_tree)) {
414 $advanced_tree=false;
417 if ($advanced_tree) {
419 <script type="text/javascript">
422 if (document.images) {
423 var treeImages = new Array;
424 var arguments = preload.arguments;
425 for (var i = 0; i<arguments.length; i++) {
426 treeImages[i] = new Image();
427 treeImages[i].src = arguments[i];
434 function fTreeTimeout() {
435 if (vTreeDiv.readyState == "complete")
436 vTreeImg.src = vTreeSrc;
438 setTimeout("fTreeTimeout()", 100);
440 function hidechilds(img) {
441 id = img.id + ".0000";
442 form_id = "mbx[" + img.id +"F]";
443 if (document.all) { //IE, Opera7
444 div = document.all[id];
446 if (div.style.display == "none") {
447 vTreeSrc = "../images/minus.png";
452 vTreeSrc = "../images/plus.png";
458 if (typeof vTreeDiv.readyState != "undefined") //IE
459 setTimeout("fTreeTimeout()",100);
461 vTreeImg.src = vTreeSrc;
462 div.style.display = style;
463 document.all[form_id].value = value;
466 else if (document.getElementById) { //Gecko
467 div = document.getElementById(id);
469 if (div.style.display == "none") {
470 src = "../images/minus.png";
475 src = "../images/plus.png";
479 div.style.display = style;
481 document.getElementById(form_id).value = value;
485 function buttonover(el,on) {
487 el.style.background="$color[0]";}
489 el.style.background="$color[9]";}
491 function buttonclick(el,on) {
493 el.style.border="groove";}
495 el.style.border="ridge";}
497 function hideframe(hide) {
498 left_size = "$left_size";
500 masterf = window.parent.document.all["fs1"];
501 leftf = window.parent.document.all["left"];
502 leftcontent = document.all["leftframe"];
503 leftbutton = document.all["showf"];
504 } else if (document.getElementById) {
505 masterf = window.parent.document.getElementById("fs1");
506 leftf = window.parent.document.getElementById("left");
507 leftcontent = document.getElementById("leftframe");
508 leftbutton = document.getElementById("showf");
513 new_col = calc_col("20");
514 masterf.cols = new_col;
515 document.body.scrollLeft=0;
516 document.body.style.overflow="hidden";
517 leftcontent.style.display = "none";
518 leftbutton.style.display="block";
520 masterf.cols = calc_col(left_size);
521 document.body.style.overflow="";
522 leftbutton.style.display="none";
523 leftcontent.style.display="block";
526 function calc_col(c_w) {
528 if ($location_of_bar == 'right') {
529 $xtra .= ' right=true;';
531 $xtra .= ' right=false;';
541 function resizeframe(direction) {
543 masterf = window.parent.document.all["fs1"];
544 } else if (document.getElementById) {
545 window.parent.document.getElementById("fs1");
550 if ($location_of_bar == 'right') {
551 $xtra .= ' colPat=/^\*,(\d+)$/;';
553 $xtra .= ' colPat=/^(\d+),.*$/;';
556 old_col = masterf.cols;
557 colPat.exec(old_col);
559 new_col_width = parseInt(RegExp.$1) + 25;
561 if (parseInt(RegExp.$1) > 35) {
562 new_col_width = parseInt(RegExp.$1) - 25;
565 masterf.cols = calc_col(new_col_width);
572 /* style definitions */
575 <style type="text/css">
578 margin: 0px 0px 0px 0px;
579 padding: 5px 5px 5px 5px;
582 vertical-align: middle;
586 border-color: $color[9];
587 background:$color[0];
599 text-decoration: none;
600 background-color: $color[0];
604 background-color: $color[9];
624 border-left-width:0.1em;
625 border-left-color:$color[9];
626 border-bottom: solid;
627 border-bottom-width:0.1em;
628 border-bottom-color:$color[9];
639 border-color:$color[9];
640 background: $color[0];
649 // get mailbox list and cache it
650 $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
652 displayHtmlHeader( 'SquirrelMail', $xtra );
654 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION
);
655 /* If requested and not yet complete, attempt to autocreate folders. */
656 if ($auto_create_special && !isset($auto_create_done)) {
657 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
658 $folders_created = false;
659 foreach( $autocreate as $folder ) {
660 if (($folder != '') && ($folder != 'none')) {
661 // use $mailboxes array for checking if mailbox exists
662 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailboxes)) {
663 sqimap_mailbox_create($imapConnection, $folder, '');
664 $folders_created = true;
666 // check for subscription is useless and expensive, just
667 // surpress the NO response. Unless we're on Mecury, which
668 // will just subscribe a folder again if it's already
670 if ( strtolower($imap_server_type) != 'mercury32' ||
671 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
672 sqimap_subscribe($imapConnection, $folder, false);
673 $folders_created = true;
679 /* Let the world know that autocreation is complete! Hurrah! */
680 $auto_create_done = TRUE;
681 sqsession_register($auto_create_done, 'auto_create_done');
682 // reload mailbox list
683 if ($folders_created)
684 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
687 if ($advanced_tree) {
689 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
690 " class=\"leftmain\">\n<div class=\"leftmain\">\n";
692 echo "\n<body class=\"leftmain\">\n<div class=\"leftmain\">\n";
695 do_hook('left_main_before');
696 if ($advanced_tree) {
697 /* nice future feature, needs layout !! volunteers? */
698 $right_pos = $left_size - 20;
699 /* 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>';
700 echo '<div id="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
701 echo '<div id="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
702 echo '<div id="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
703 echo '<div id="leftframe"><br /><br />';*/
706 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
708 html_tag( 'td', '', 'left' ) .
709 html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0"' ) .
711 html_tag( 'td', '', 'center' ) .
712 '<font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
714 if ($date_format != 6) {
715 /* First, display the clock. */
716 if ($hour_format == 1) {
718 if ($date_format == 4) {
722 if ($date_format == 4) {
729 switch( $date_format ) {
731 $clk = date('Y-m-d '.$hr. ' T', time());
734 $clk = date('m/d/y '.$hr, time());
737 $clk = date('d/m/y '.$hr, time());
741 $clk = date($hr, time());
744 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
746 $clk = str_replace(' ',' ',$clk);
748 echo '<small><span style="white-space: nowrap;">'
749 . str_replace(' ', ' ', _("Last Refresh"))
750 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
753 /* Next, display the refresh button. */
754 echo '<div style="white-space: nowrap;"><small>[<a href="../src/left_main.php" target="left">'.
755 _("Check mail") . "</a>]</small></div></td></tr></table><br />\n\n";
757 /* Lastly, display the folder list. */
759 if ( $collapse_folders ) {
760 /* If directed, collapse or uncollapse a folder. */
762 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED
);
763 } else if (isset($unfold)) {
764 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED
);
768 /* Get unseen/total display prefs */
769 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
770 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
772 if (empty($unseen_type)) {
773 if (!empty($default_unseen_type)) {
774 $unseen_type = $default_unseen_type;
780 if (empty($unseen_notify)) {
781 if (!empty($default_unseen_notify)) {
782 $unseen_notify = $default_unseen_notify;
788 * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
789 * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
791 $boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
793 if (isset($advanced_tree) && $advanced_tree) {
794 echo '<form name="collapse" action="left_main.php" method="post" ' .
795 'enctype="multipart/form-data">'."\n";
796 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 />';
797 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
798 sqgetGlobalVar('mbx', $mbx, SQ_POST
);
799 if (!isset($mbx)) $mbx=NULL;
800 ListAdvancedBoxes($boxes, $mbx);
807 do_hook('left_main_after');
808 sqimap_logout($imapConnection);
814 $oTemplate->display('footer.tpl');