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 if (isset($boxes->recent
) && $boxes->recent
) {
87 $unseen_string = "<span class=\"leftrecent\">($unseen_string)</span>";
89 $unseen_string = "<span class=\"leftunseen\">($unseen_string)</span>";
93 * Finally allow the script to display the values by setting a boolean.
94 * This can only occur if the unseen count is great than 0 (if you have
95 * unseen count only), or you have the message count too.
97 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
104 if (isset($boxes->mbxs
[0]) && $collapse_folders) {
105 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
106 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
107 $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
109 if ($use_icons && $icon_theme != 'none') {
110 $link .= "unfold=$mailboxURL\">$leader<img src=\"" . SM_PATH
. 'images/plus.png" border="0" height="7" width="7" /> ';
112 $link .= "unfold=$mailboxURL\">$leader+ ";
115 if ($use_icons && $icon_theme != 'none') {
116 $link .= "fold=$mailboxURL\">$leader<img src=\"" . SM_PATH
. 'images/minus.png" border="0" height="7" width="7" /> ';
118 $link .= "fold=$mailboxURL\">$leader- ";
124 $pre.= $leader . ' ';
127 /* If there are unseen message, bold the line. */
128 if (($move_to_trash) && ($mailbox == $trash_folder)) {
130 if ( !is_numeric($boxes->total
) ) {
131 $result = sqimap_status_messages($imapConnection, $mailbox);
132 $boxes->total
= $result['MESSAGES'];
133 $boxes->unseen
= $result['UNSEEN'];
136 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
142 if ($boxes->total
> 0) {
143 /* Print unseen information. */
145 $end .= " <small>$unseen_string</small>";
147 $end .= "\n<small>" .
148 ' [<a href="empty_trash.php">'._("Purge").'</a>]'.
152 if (!$boxes->is_noselect
) {
153 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
160 /* Print unseen information. */
162 $end .= " <small>$unseen_string</small>";
169 if ($use_special_folder_color && $boxes->is_special
) {
170 $span = "<span class=\"leftspecial\">";
171 $spanend = "</span>";
172 } elseif ( $boxes->is_noselect
) {
173 $span = "<span class=\"leftnoselect\">";
174 $spanend = '</span>';
178 // let plugins fiddle with end of line
179 $end .= concat_hook_function('left_main_after_each_folder',
180 array(isset($numMessages) ?
$numMessages : '',
181 $boxes->mailboxname_full
, $imapConnection));
185 if (!$boxes->is_root
) {
186 echo "" . $span . $pre .
189 array(' ','<','>'),
190 $boxes->mailboxname_sub
) .
191 $end. $spanend .'<br />' . "\n";
195 if (!$collapse ||
$boxes->is_root
) {
196 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
197 ListBoxes($boxes->mbxs
[$i],$j);
202 function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
203 global $data_dir, $username, $color, $unseen_notify, $unseen_type, $unseen_cum,
204 $move_to_trash, $trash_folder, $collapse_folders, $use_special_folder_color;
210 /* use_folder_images only works if the images exist in ../images */
211 $use_folder_images = true;
216 $unseen_found = false;
219 $mailbox = $boxes->mailboxname_full
;
220 $mailboxURL = urlencode($mailbox);
222 /* get collapse information */
223 if ($collapse_folders) {
224 $form_entry = $j.'F';
225 if (isset($mbx) && isset($mbx[$form_entry])) {
226 $collapse = $mbx[$form_entry];
227 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full
,
228 $collapse ? SM_BOX_COLLAPSED
: SM_BOX_UNCOLLAPSED
);
230 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
231 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
233 $img_src = ($collapse ?
'../images/plus.png' : '../images/minus.png');
234 $collapse_link = '<a href="javascript:void(0)">' .
235 " <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
240 /* get unseen/total messages information */
241 /* Only need to display info when option is set */
242 if (isset($unseen_notify) && ($unseen_notify > 1)) {
243 /* handle Cumulative Unread Message Notification */
244 if ($collapse && $unseen_cum) {
245 foreach ($boxes->mbxs
as $cumn_box) {
246 if (!empty($cumn_box->unseen
)) $boxes->unseen +
= $cumn_box->unseen
;
247 if (!empty($cumn_box->total
)) $boxes->total +
= $cumn_box->total
;
250 if (($boxes->unseen
!== false) ||
($boxes->total
!== false)) {
251 if ($boxes->unseen
!== false) $unseen = $boxes->unseen
;
253 * Should only display unseen info if the folder is inbox
254 * or you set the option for all folders
256 if ((strtolower($mailbox) == 'inbox') ||
($unseen_notify == 3)) {
257 $unseen_string = $unseen;
259 /* If users requests, display message count too */
260 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total
!== false)) {
261 $unseen_string .= '/' . $boxes->total
;
263 if (isset($boxes->recent
) && $boxes->recent
> 0) {
264 $unseen_string = "<span class=\"leftrecent\">($unseen_string)</span>";
266 $unseen_string = "<span class=\"leftunseen\">($unseen_string)</span>";
270 * Finally allow the script to display the values by setting a boolean.
271 * This can only occur if the unseen count is great than 0 (if you have
272 * unseen count only), or you have the message count too.
274 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
275 $unseen_found = true;
281 /* If there are unseen message, bold the line. */
282 if ($unseen > 0) { $pre .= '<b>'; }
284 /* color special boxes */
285 if ($use_special_folder_color && $boxes->is_special
) {
286 $pre .= "<span class=\"leftspecial\">";
290 /* If there are unseen message, close bolding. */
291 if ($unseen > 0) { $end .= '</b>'; }
293 /* Print unseen information. */
295 $end .= " $unseen_string";
298 if (($move_to_trash) && ($mailbox == $trash_folder)) {
299 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
301 $end .= "\n<small>\n" .
302 ' [<a class="mbx_link" href="empty_trash.php">'._("Purge").'</a>]'.
305 if (!$boxes->is_noselect
) { /* \Noselect boxes can't be selected */
306 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
311 // let plugins fiddle with end of line
312 global $imapConnection;
313 $end .= concat_hook_function('left_main_after_each_folder',
314 array(isset($numMessages) ?
$numMessages : '',
315 $boxes->mailboxname_full
, $imapConnection));
317 if (!$boxes->is_root
) {
318 if ($use_folder_images) {
319 if ($boxes->is_inbox
) {
320 $folder_img = '../images/inbox.png';
321 } else if ($boxes->is_sent
) {
322 $folder_img = '../images/senti.png';
323 } else if ($boxes->is_trash
) {
324 $folder_img = '../images/delitem.png';
325 } else if ($boxes->is_draft
) {
326 $folder_img = '../images/draft.png';
327 } else if ($boxes->is_noinferiors
) {
328 $folder_img = '../images/folder_noinf.png';
330 $folder_img = '../images/folder.png';
332 $folder_img = ' <img src="'.$folder_img.'" height="15" /> ';
336 if (!isset($boxes->mbxs
[0])) {
337 echo ' ' . html_tag( 'div',
339 str_replace( array(' ','<','>'),
340 array(' ','<','>'),
341 $boxes->mailboxname_sub
) .
343 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
346 echo ' ' . html_tag( 'div',
347 $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub
. $end ,
348 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
349 echo ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
353 $visible = ($collapse ?
' style="display:none"' : ' style="display:block"');
354 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) /* mailbox contains childs */
355 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
357 if ($j !='ID.0000') {
360 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
362 ListAdvancedBoxes($boxes->mbxs
[$i],$mbx,$j);
364 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) {
365 echo '</div>'."\n\n";
372 /* -------------------- MAIN ------------------------ */
375 sqgetGlobalVar('username', $username, SQ_SESSION
);
376 sqgetGlobalVar('key', $key, SQ_COOKIE
);
377 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
378 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
380 sqgetGlobalVar('fold', $fold, SQ_GET
);
381 sqgetGlobalVar('unfold', $unfold, SQ_GET
);
385 // open a connection on the imap port (143)
386 // why hide the output?
387 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true);
390 * Using stristr since very old preferences may contain "None" and "none".
392 if (!empty($left_refresh) &&
393 !stristr($left_refresh, 'none')){
394 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
395 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
396 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
402 * $advanced_tree and is a boolean var which is default set to default
404 * Setting $advanced tree to true causes SM to display a experimental
405 * mailbox-tree with dhtml behaviour.
406 * It only works on browsers which supports css and javascript. The used
407 * javascript is experimental and doesn't support all browsers.
408 * It has been tested on IE6 an Konquerer 3.0.0-2.
409 * It is now tested and working on: (please test and update this list)
410 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
413 * In the function ListAdvancedBoxes there is another var $use_folder_images.
414 * setting this to true is only usefull if the images exists in ../images.
416 * Feel free to experiment with the code and report bugs and enhancements
419 /* set this to true if you want to see a nicer mailboxtree */
420 if (empty($advanced_tree)) {
421 $advanced_tree=false;
424 if ($advanced_tree) {
426 <script type="text/javascript">
429 if (document.images) {
430 var treeImages = new Array;
431 var arguments = preload.arguments;
432 for (var i = 0; i<arguments.length; i++) {
433 treeImages[i] = new Image();
434 treeImages[i].src = arguments[i];
441 function fTreeTimeout() {
442 if (vTreeDiv.readyState == "complete")
443 vTreeImg.src = vTreeSrc;
445 setTimeout("fTreeTimeout()", 100);
447 function hidechilds(img) {
448 id = img.id + ".0000";
449 form_id = "mbx[" + img.id +"F]";
450 if (document.all) { //IE, Opera7
451 div = document.all[id];
453 if (div.style.display == "none") {
454 vTreeSrc = "../images/minus.png";
459 vTreeSrc = "../images/plus.png";
465 if (typeof vTreeDiv.readyState != "undefined") //IE
466 setTimeout("fTreeTimeout()",100);
468 vTreeImg.src = vTreeSrc;
469 div.style.display = style;
470 document.all[form_id].value = value;
473 else if (document.getElementById) { //Gecko
474 div = document.getElementById(id);
476 if (div.style.display == "none") {
477 src = "../images/minus.png";
482 src = "../images/plus.png";
486 div.style.display = style;
488 document.getElementById(form_id).value = value;
492 function buttonover(el,on) {
494 el.style.background="$color[0]";}
496 el.style.background="$color[9]";}
498 function buttonclick(el,on) {
500 el.style.border="groove";}
502 el.style.border="ridge";}
504 function hideframe(hide) {
505 left_size = "$left_size";
507 masterf = window.parent.document.all["fs1"];
508 leftf = window.parent.document.all["left"];
509 leftcontent = document.all["leftframe"];
510 leftbutton = document.all["showf"];
511 } else if (document.getElementById) {
512 masterf = window.parent.document.getElementById("fs1");
513 leftf = window.parent.document.getElementById("left");
514 leftcontent = document.getElementById("leftframe");
515 leftbutton = document.getElementById("showf");
520 new_col = calc_col("20");
521 masterf.cols = new_col;
522 document.body.scrollLeft=0;
523 document.body.style.overflow="hidden";
524 leftcontent.style.display = "none";
525 leftbutton.style.display="block";
527 masterf.cols = calc_col(left_size);
528 document.body.style.overflow="";
529 leftbutton.style.display="none";
530 leftcontent.style.display="block";
533 function calc_col(c_w) {
535 if ($location_of_bar == 'right') {
536 $xtra .= ' right=true;';
538 $xtra .= ' right=false;';
548 function resizeframe(direction) {
550 masterf = window.parent.document.all["fs1"];
551 } else if (document.getElementById) {
552 window.parent.document.getElementById("fs1");
557 if ($location_of_bar == 'right') {
558 $xtra .= ' colPat=/^\*,(\d+)$/;';
560 $xtra .= ' colPat=/^(\d+),.*$/;';
563 old_col = masterf.cols;
564 colPat.exec(old_col);
566 new_col_width = parseInt(RegExp.$1) + 25;
568 if (parseInt(RegExp.$1) > 35) {
569 new_col_width = parseInt(RegExp.$1) - 25;
572 masterf.cols = calc_col(new_col_width);
579 /* style definitions */
582 <style type="text/css">
585 margin: 0px 0px 0px 0px;
586 padding: 5px 5px 5px 5px;
589 vertical-align: middle;
593 border-color: $color[9];
594 background:$color[0];
606 text-decoration: none;
607 background-color: $color[0];
611 background-color: $color[9];
631 border-left-width:0.1em;
632 border-left-color:$color[9];
633 border-bottom: solid;
634 border-bottom-width:0.1em;
635 border-bottom-color:$color[9];
646 border-color:$color[9];
647 background: $color[0];
656 // get mailbox list and cache it
657 $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
659 displayHtmlHeader( 'SquirrelMail', $xtra );
661 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION
);
662 /* If requested and not yet complete, attempt to autocreate folders. */
663 if ($auto_create_special && !isset($auto_create_done)) {
664 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
665 $folders_created = false;
666 foreach( $autocreate as $folder ) {
667 if (($folder != '') && ($folder != 'none')) {
668 // use $mailboxes array for checking if mailbox exists
669 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailboxes)) {
670 sqimap_mailbox_create($imapConnection, $folder, '');
671 $folders_created = true;
673 // check for subscription is useless and expensive, just
674 // surpress the NO response. Unless we're on Mecury, which
675 // will just subscribe a folder again if it's already
677 if ( strtolower($imap_server_type) != 'mercury32' ||
678 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
679 sqimap_subscribe($imapConnection, $folder, false);
680 $folders_created = true;
686 /* Let the world know that autocreation is complete! Hurrah! */
687 $auto_create_done = TRUE;
688 sqsession_register($auto_create_done, 'auto_create_done');
689 // reload mailbox list
690 if ($folders_created)
691 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
694 if ($advanced_tree) {
696 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
697 " class=\"leftmain\">\n<div class=\"leftmain\">\n";
699 echo "\n<body class=\"leftmain\">\n<div class=\"leftmain\">\n";
702 do_hook('left_main_before');
703 if ($advanced_tree) {
704 /* nice future feature, needs layout !! volunteers? */
705 $right_pos = $left_size - 20;
706 /* 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>';
707 echo '<div id="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
708 echo '<div id="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
709 echo '<div id="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
710 echo '<div id="leftframe"><br /><br />';*/
713 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
715 html_tag( 'td', '', 'left' ) .
716 html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0"' ) .
718 html_tag( 'td', '', 'center' ) .
719 '<font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
721 if ($date_format != 6) {
722 /* First, display the clock. */
723 if ($hour_format == 1) {
725 if ($date_format == 4) {
729 if ($date_format == 4) {
736 switch( $date_format ) {
738 $clk = date('Y-m-d '.$hr. ' T', time());
741 $clk = date('m/d/y '.$hr, time());
744 $clk = date('d/m/y '.$hr, time());
748 $clk = date($hr, time());
751 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
753 $clk = str_replace(' ',' ',$clk);
755 echo '<small><span style="white-space: nowrap;">'
756 . str_replace(' ', ' ', _("Last Refresh"))
757 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
760 /* Next, display the refresh button. */
761 echo '<div style="white-space: nowrap;"><small>[<a href="../src/left_main.php" target="left">'.
762 _("Check mail") . "</a>]</small></div></td></tr></table><br />\n\n";
764 /* Lastly, display the folder list. */
766 if ( $collapse_folders ) {
767 /* If directed, collapse or uncollapse a folder. */
769 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED
);
770 } else if (isset($unfold)) {
771 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED
);
775 /* Get unseen/total display prefs */
776 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
777 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
779 if (empty($unseen_type)) {
780 if (!empty($default_unseen_type)) {
781 $unseen_type = $default_unseen_type;
787 if (empty($unseen_notify)) {
788 if (!empty($default_unseen_notify)) {
789 $unseen_notify = $default_unseen_notify;
795 * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
796 * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
798 $boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
800 if (isset($advanced_tree) && $advanced_tree) {
801 echo '<form name="collapse" action="left_main.php" method="post" ' .
802 'enctype="multipart/form-data">'."\n";
803 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 />';
804 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
805 sqgetGlobalVar('mbx', $mbx, SQ_POST
);
806 if (!isset($mbx)) $mbx=NULL;
807 ListAdvancedBoxes($boxes, $mbx);
814 do_hook('left_main_after');
815 sqimap_logout($imapConnection);
821 $oTemplate->display('footer.tpl');