6 * This is the code for the left bar. The left bar shows the folders
7 * available, and has cookie information.
9 * @copyright © 1999-2005 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 require_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 = "<font color=\"$color[11]\">($unseen_string)</font>";
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 $font = "<font color=\"$color[11]\">";
164 $fontend = "</font>";
165 } elseif ( $boxes->is_noselect
) {
166 $font = "<font color=\"$color[15]\">";
167 $fontend = '</font>';
170 // let plugins fiddle with end of line
171 $end .= concat_hook_function('left_main_after_each_folder',
172 array(isset($numMessages) ?
$numMessages : '',
173 $boxes->mailboxname_full
, $imapConnection));
177 if (!$boxes->is_root
) {
178 echo "" . $pre .$font.
181 array(' ','<','>'),
182 $boxes->mailboxname_sub
) .
183 $fontend . $end. '<br />' . "\n";
187 if (!$collapse ||
$boxes->is_root
) {
188 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
189 ListBoxes($boxes->mbxs
[$i],$j);
194 function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
195 global $data_dir, $username, $color, $unseen_notify, $unseen_type,
196 $move_to_trash, $trash_folder, $collapse_folders, $use_special_folder_color;
202 /* use_folder_images only works if the images exist in ../images */
203 $use_folder_images = true;
208 $unseen_found = false;
211 $mailbox = $boxes->mailboxname_full
;
212 $mailboxURL = urlencode($mailbox);
214 /* get unseen/total messages information */
215 /* Only need to display info when option is set */
216 if (isset($unseen_notify) && ($unseen_notify > 1) &&
217 (($boxes->unseen
!== false) ||
($boxes->total
!== false))) {
219 if ($boxes->unseen
!== false)
220 $unseen = $boxes->unseen
;
223 Should only display unseen info if the folder is inbox
224 or you set the option for all folders
227 if ((strtolower($mailbox) == 'inbox') ||
($unseen_notify == 3)) {
228 $unseen_string = $unseen;
230 /* If users requests, display message count too */
231 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total
!== false)) {
232 $unseen_string .= '/' . $boxes->total
;
235 $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
238 Finally allow the script to display the values by setting a boolean.
239 This can only occur if the unseen count is great than 0 (if you have
240 unseen count only), or you have the message count too.
242 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
243 $unseen_found = true;
248 /* If there are unseen message, bold the line. */
249 if ($unseen > 0) { $pre .= '<b>'; }
251 /* color special boxes */
252 if ($use_special_folder_color && $boxes->is_special
) {
253 $pre .= "<font color=\"$color[11]\">";
257 /* If there are unseen message, close bolding. */
258 if ($unseen > 0) { $end .= '</b>'; }
260 /* Print unseen information. */
262 $end .= " $unseen_string";
265 if (($move_to_trash) && ($mailbox == $trash_folder)) {
266 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
268 $end .= "\n<small>\n" .
269 ' [<a class="mbx_link" href="empty_trash.php">'._("Purge").'</a>]'.
272 if (!$boxes->is_noselect
) { /* \Noselect boxes can't be selected */
273 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
278 // let plugins fiddle with end of line
279 global $imapConnection;
280 $end .= concat_hook_function('left_main_after_each_folder',
281 array(isset($numMessages) ?
$numMessages : '',
282 $boxes->mailboxname_full
, $imapConnection));
284 if (!$boxes->is_root
) {
285 if ($use_folder_images) {
286 if ($boxes->is_inbox
) {
287 $folder_img = '../images/inbox.png';
288 } else if ($boxes->is_sent
) {
289 $folder_img = '../images/senti.png';
290 } else if ($boxes->is_trash
) {
291 $folder_img = '../images/delitem.png';
292 } else if ($boxes->is_draft
) {
293 $folder_img = '../images/draft.png';
294 } else if ($boxes->is_noinferiors
) {
295 $folder_img = '../images/folder_noinf.png';
297 $folder_img = '../images/folder.png';
299 $folder_img = ' <img src="'.$folder_img.'" height="15" /> ';
303 if (!isset($boxes->mbxs
[0])) {
304 echo ' ' . html_tag( 'div',
306 str_replace( array(' ','<','>'),
307 array(' ','<','>'),
308 $boxes->mailboxname_sub
) .
310 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
312 /* get collapse information */
313 if ($collapse_folders) {
314 $form_entry = $j.'F';
315 if (isset($mbx) && isset($mbx[$form_entry])) {
316 $collapse = $mbx[$form_entry];
317 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full
,
318 $collapse ? SM_BOX_COLLAPSED
: SM_BOX_UNCOLLAPSED
);
320 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
321 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
323 $img_src = ($collapse ?
'../images/plus.png' : '../images/minus.png');
324 $collapse_link = '<a href="javascript:void(0)">' .
325 " <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
329 echo ' ' . html_tag( 'div',
330 $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub
. $end ,
331 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
332 echo ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
336 $visible = ($collapse ?
' style="display:none"' : ' style="display:block"');
337 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) /* mailbox contains childs */
338 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
340 if ($j !='ID.0000') {
343 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
345 ListAdvancedBoxes($boxes->mbxs
[$i],$mbx,$j);
347 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) {
348 echo '</div>'."\n\n";
355 /* -------------------- MAIN ------------------------ */
358 sqgetGlobalVar('username', $username, SQ_SESSION
);
359 sqgetGlobalVar('key', $key, SQ_COOKIE
);
360 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
361 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
363 sqgetGlobalVar('fold', $fold, SQ_GET
);
364 sqgetGlobalVar('unfold', $unfold, SQ_GET
);
368 // open a connection on the imap port (143)
369 // why hide the output?
370 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true);
373 * Using stristr since very old preferences may contain "None" and "none".
375 if (!empty($left_refresh) &&
376 !stristr($left_refresh, 'none')){
377 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
378 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
379 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
385 * $advanced_tree and is a boolean var which is default set to default
387 * Setting $advanced tree to true causes SM to display a experimental
388 * mailbox-tree with dhtml behaviour.
389 * It only works on browsers which supports css and javascript. The used
390 * javascript is experimental and doesn't support all browsers.
391 * It has been tested on IE6 an Konquerer 3.0.0-2.
392 * It is now tested and working on: (please test and update this list)
393 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
396 * In the function ListAdvancedBoxes there is another var $use_folder_images.
397 * setting this to true is only usefull if the images exists in ../images.
399 * Feel free to experiment with the code and report bugs and enhancements
402 /* set this to true if you want to see a nicer mailboxtree */
403 if (empty($advanced_tree)) {
404 $advanced_tree=false;
407 if ($advanced_tree) {
409 <script language="Javascript" type="text/javascript">
412 if (document.images) {
413 var treeImages = new Array;
414 var arguments = preload.arguments;
415 for (var i = 0; i<arguments.length; i++) {
416 treeImages[i] = new Image();
417 treeImages[i].src = arguments[i];
424 function fTreeTimeout() {
425 if (vTreeDiv.readyState == "complete")
426 vTreeImg.src = vTreeSrc;
428 setTimeout("fTreeTimeout()", 100);
430 function hidechilds(img) {
431 id = img.id + ".0000";
432 form_id = "mbx[" + img.id +"F]";
433 if (document.all) { //IE, Opera7
434 div = document.all[id];
436 if (div.style.display == "none") {
437 vTreeSrc = "../images/minus.png";
442 vTreeSrc = "../images/plus.png";
448 if (typeof vTreeDiv.readyState != "undefined") //IE
449 setTimeout("fTreeTimeout()",100);
451 vTreeImg.src = vTreeSrc;
452 div.style.display = style;
453 document.all[form_id].value = value;
456 else if (document.getElementById) { //Gecko
457 div = document.getElementById(id);
459 if (div.style.display == "none") {
460 src = "../images/minus.png";
465 src = "../images/plus.png";
469 div.style.display = style;
471 document.getElementById(form_id).value = value;
475 function buttonover(el,on) {
477 el.style.background="$color[0]";}
479 el.style.background="$color[9]";}
481 function buttonclick(el,on) {
483 el.style.border="groove";}
485 el.style.border="ridge";}
487 function hideframe(hide) {
488 left_size = "$left_size";
490 masterf = window.parent.document.all["fs1"];
491 leftf = window.parent.document.all["left"];
492 leftcontent = document.all["leftframe"];
493 leftbutton = document.all["showf"];
494 } else if (document.getElementById) {
495 masterf = window.parent.document.getElementById("fs1");
496 leftf = window.parent.document.getElementById("left");
497 leftcontent = document.getElementById("leftframe");
498 leftbutton = document.getElementById("showf");
503 new_col = calc_col("20");
504 masterf.cols = new_col;
505 document.body.scrollLeft=0;
506 document.body.style.overflow="hidden";
507 leftcontent.style.display = "none";
508 leftbutton.style.display="block";
510 masterf.cols = calc_col(left_size);
511 document.body.style.overflow="";
512 leftbutton.style.display="none";
513 leftcontent.style.display="block";
516 function calc_col(c_w) {
518 if ($location_of_bar == 'right') {
519 $xtra .= ' right=true;';
521 $xtra .= ' right=false;';
531 function resizeframe(direction) {
533 masterf = window.parent.document.all["fs1"];
534 } else if (document.getElementById) {
535 window.parent.document.getElementById("fs1");
540 if ($location_of_bar == 'right') {
541 $xtra .= ' colPat=/^\*,(\d+)$/;';
543 $xtra .= ' colPat=/^(\d+),.*$/;';
546 old_col = masterf.cols;
547 colPat.exec(old_col);
549 new_col_width = parseInt(RegExp.$1) + 25;
551 if (parseInt(RegExp.$1) > 35) {
552 new_col_width = parseInt(RegExp.$1) - 25;
555 masterf.cols = calc_col(new_col_width);
562 /* style definitions */
565 <style type="text/css">
568 margin: 0px 0px 0px 0px;
569 padding: 5px 5px 5px 5px;
572 vertical-align: middle;
576 border-color: $color[9];
577 background:$color[0];
589 text-decoration: none;
590 background-color: $color[0];
594 background-color: $color[9];
614 border-left-width:0.1em;
615 border-left-color:$color[9];
616 border-bottom: solid;
617 border-bottom-width:0.1em;
618 border-bottom-color:$color[9];
629 border-color:$color[9];
630 background: $color[0];
639 displayHtmlHeader( 'SquirrelMail', $xtra );
640 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION
);
641 /* If requested and not yet complete, attempt to autocreate folders. */
642 if ($auto_create_special && !isset($auto_create_done)) {
643 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
644 foreach( $autocreate as $folder ) {
645 if (($folder != '') && ($folder != 'none')) {
646 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
647 sqimap_mailbox_create($imapConnection, $folder, '');
649 // check for subscription is useless and expensive, just
650 // surpress the NO response. Unless we're on Mecury, which
651 // will just subscribe a folder again if it's already
653 if ( strtolower($imap_server_type) != 'mercury32' ||
654 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
655 sqimap_subscribe($imapConnection, $folder, false);
661 /* Let the world know that autocreation is complete! Hurrah! */
662 $auto_create_done = TRUE;
663 sqsession_register($auto_create_done, 'auto_create_done');
666 if ($advanced_tree) {
668 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
669 " bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
671 echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
674 do_hook('left_main_before');
675 if ($advanced_tree) {
676 /* nice future feature, needs layout !! volunteers? */
677 $right_pos = $left_size - 20;
678 /* 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>';
679 echo '<div id="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
680 echo '<div id="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
681 echo '<div id="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
682 echo '<div id="leftframe"><br /><br />';*/
685 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
687 html_tag( 'td', '', 'left' ) .
688 html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0"' ) .
690 html_tag( 'td', '', 'center' ) .
691 '<font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
693 if ($date_format != 6) {
694 /* First, display the clock. */
695 if ($hour_format == 1) {
697 if ($date_format == 4) {
701 if ($date_format == 4) {
708 switch( $date_format ) {
710 $clk = date('Y-m-d '.$hr. ' T', time());
713 $clk = date('m/d/y '.$hr, time());
716 $clk = date('d/m/y '.$hr, time());
720 $clk = date($hr, time());
723 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
725 $clk = str_replace(' ',' ',$clk);
727 echo '<small><span style="white-space: nowrap;">'
728 . str_replace(' ', ' ', _("Last Refresh"))
729 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
732 /* Next, display the refresh button. */
733 echo '<div style="white-space: nowrap;"><small>[<a href="../src/left_main.php" target="left">'.
734 _("Check mail") . "</a>]</small></div></td></tr></table><br />\n\n";
736 /* Lastly, display the folder list. */
738 if ( $collapse_folders ) {
739 /* If directed, collapse or uncollapse a folder. */
741 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED
);
742 } else if (isset($unfold)) {
743 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED
);
747 /* Get unseen/total display prefs */
748 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
749 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
751 if (empty($unseen_type)) {
752 if (!empty($default_unseen_type)) {
753 $unseen_type = $default_unseen_type;
759 if (empty($unseen_notify)) {
760 if (!empty($default_unseen_notify)) {
761 $unseen_notify = $default_unseen_notify;
767 $boxes = sqimap_mailbox_tree($imapConnection);
768 if (isset($advanced_tree) && $advanced_tree) {
769 echo '<form name="collapse" action="left_main.php" method="post" ' .
770 'enctype="multipart/form-data">'."\n";
771 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 />';
772 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
773 sqgetGlobalVar('mbx', $mbx, SQ_POST
);
774 if (!isset($mbx)) $mbx=NULL;
775 ListAdvancedBoxes($boxes, $mbx);
782 do_hook('left_main_after');
783 sqimap_logout($imapConnection);