* Another little bug I made when I was mucking with the code
[squirrelmail.git] / src / left_main.php
CommitLineData
59177427 1<?php
21c3249f 2 /**
a09387f4 3 ** left_main.php
ef870322 4 ** Copyright (c) 1999-2000 The SquirrelMail development team
5 ** Licensed under the GNU GPL. For full terms see the file COPYING.
21c3249f 6 **
7 ** This is the code for the left bar. The left bar shows the folders
8 ** available, and has cookie information.
9 **
245a6892 10 ** $Id$
21c3249f 11 **/
12
2a32fc83 13 session_start();
14
6d7061ac 15 if (!isset($i18n_php))
16 include ("../functions/i18n.php");
17
21c3249f 18 if(!isset($username)) {
441f2d33 19 set_up_language($squirrelmail_language, true);
10455998 20 include ("../themes/default_theme.php");
21 printf('<html><BODY TEXT="%s" BGCOLOR="%s" LINK="%s" VLINK="%s" ALINK="%s">',
22 $color[8], $color[4], $color[7], $color[7], $color[7]);
23 echo "</body></html>";
21c3249f 24 exit;
25 }
142499d4 26
207dff25 27
245a6892 28 if (!isset($strings_php))
29 include("../functions/strings.php");
d068c0ec 30 if (!isset($config_php))
31 include("../config/config.php");
32 if (!isset($array_php))
33 include("../functions/array.php");
d068c0ec 34 if (!isset($imap_php))
35 include("../functions/imap.php");
142499d4 36 if (!isset($page_header_php))
37 include("../functions/page_header.php");
9c1852ff 38 if (!isset($i18n_php))
39 include("../functions/i18n.php");
9d0c7bee 40 if (!isset($plugin_php))
41 include("../functions/plugin.php");
142499d4 42
99ab0367 43 // open a connection on the imap port (143)
44 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
45
46 /** If it was a successful login, lets load their preferences **/
47 include("../src/load_prefs.php");
48
2a833d72 49 displayHtmlHeader();
21c3249f 50
0cd84d75 51 function formatMailboxName($imapConnection, $box_array, $delimeter) {
5bdd7223 52 global $folder_prefix, $trash_folder, $sent_folder;
53 global $color, $move_to_sent, $move_to_trash;
0cd84d75 54 global $unseen_notify, $unseen_type, $collapse_folders;
55
56 $real_box = $box_array['unformatted'];
57 $mailbox = $box_array['formatted'];
4c34dac5 58 $mailboxURL = urlencode($real_box);
5bdd7223 59
0cd84d75 60 $unseen = 0;
61
62 if (($unseen_notify == 2 && $real_box == "INBOX") ||
63 $unseen_notify == 3) {
5bdd7223 64 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box);
24fc5dd2 65 if ($unseen_type == 1 && $unseen > 0) {
66 $unseen_string = "($unseen)";
67 $unseen_found = true;
68 } else if ($unseen_type == 2) {
69 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
70 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
71 $unseen_found = true;
72 }
73 }
5bdd7223 74
7ce342dc 75 $special_color = false;
508ca2d3 76 if ((strtolower($real_box) == "inbox") ||
5bdd7223 77 (($real_box == $trash_folder) && ($move_to_trash)) ||
78 (($real_box == $sent_folder) && ($move_to_sent)))
79 $special_color = true;
0cd84d75 80
81 $spaces = '';
82 $line = "<NOBR>";
83 if (ereg("^( *)([^ ]*)$", $mailbox, $regs))
84 {
85 $spaces = $regs[1];
86 $mailbox = $regs[2];
87 }
5bdd7223 88
0cd84d75 89 if ($unseen > 0)
90 $line .= "<B>";
91 $line .= str_replace(' ', '&nbsp;', $spaces);
92
93 if ($collapse_folders)
94 {
95 if (isset($box_array['parent']))
96 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
97 else
98 $line .= '&nbsp;&nbsp;';
d92b6f31 99 }
0cd84d75 100
101 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
102 if ($special_color == true)
103 $line .= "<FONT COLOR=\"$color[11]\">";
104 $line .= str_replace(' ', '&nbsp;', $mailbox);
105 if ($special_color == true)
106 $line .= "</font>";
107 $line .= "</a>";
7ce342dc 108
d1941f35 109 if ($unseen > 0)
7ce342dc 110 $line .= "</B>";
0cd84d75 111
245a6892 112 if (isset($unseen_found) && $unseen_found) {
24fc5dd2 113 $line .= "&nbsp;<small>$unseen_string</small>";
7ce342dc 114 }
115
1e0628fb 116 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
0ab89329 117 $urlMailbox = urlencode($real_box);
1d4fe45e 118 $line .= "\n<small>\n";
0cd84d75 119 $line .= " &nbsp; (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
1d4fe45e 120 $line .= "\n</small>\n";
d92b6f31 121 }
1d4fe45e 122 $line .= "</NOBR>";
d92b6f31 123 return $line;
124 }
125
4c34dac5 126 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
1d4fe45e 127 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
128 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
129 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
469eb37b 130 }
813eba2f 131
04632dbc 132 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
f3d17401 133
9d0c7bee 134 do_hook("left_main_before");
135
813eba2f 136 $boxes = sqimap_mailbox_list($imapConnection);
21c3249f 137
1d4fe45e 138 echo "<CENTER><FONT SIZE=4><B>";
139 echo _("Folders") . "</B><BR></FONT>\n\n";
97afcee9 140
9f2215a1 141 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
ad6f805c 142 echo _("refresh folder list");
aae41ae9 143 echo "</A>)</small></CENTER><BR>";
813eba2f 144 $delimeter = sqimap_get_delimiter($imapConnection);
4c34dac5 145
0cd84d75 146 if ($collapse_folders)
147 {
148 if (isset($fold))
149 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
150 if (isset($unfold))
151 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
152 $IAmAParent = array();
153 for ($i = 0; $i < count($boxes); $i ++)
154 {
155 $parts = explode($delimeter, $boxes[$i]['unformatted']);
156 $box_name = array_pop($parts);
157 $box_parent = implode($delimeter, $parts);
158 $hidden = 0;
159 if (isset($box_parent))
160 {
161 $hidden = getPref($data_dir, $username,
162 'collapse_folder_' . $box_parent);
163 $IAmAParent[$box_parent] = $hidden;
164 }
165 $boxes[$i]['folded'] = $hidden;
166 }
167 }
168
7ce342dc 169 for ($i = 0;$i < count($boxes); $i++) {
0cd84d75 170 if (! isset($boxes[$i]['folded']) || ! $boxes[$i]['folded'])
171 {
172 $line = "";
173 $mailbox = $boxes[$i]["formatted"];
174
175 if ($collapse_folders &&
176 isset($IAmAParent[$boxes[$i]['unformatted']]))
177 {
178 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
179 }
180
181 if (in_array('noselect', $boxes[$i]['flags'])) {
182 $line .= "<FONT COLOR=\"$color[10]\">";
183 if (ereg("^([\\s]*)([^\\s]*)$", $mailbox, $regs))
184 {
185 $line .= str_replace(' ', '&nbsp;', $regs[1]);
186 if ($boxes[$i]['parent'])
187 $line .= FoldLink($boxes[$i]['unformatted'],
188 $boxes[$i]['parent']);
189 $line .= str_replace(' ', '&nbsp;', $regs[2]);
190 }
191 $line .= '</FONT>';
192 } else {
193 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
194 }
195 echo "$line<BR>\n";
d92b6f31 196 }
d92b6f31 197 }
1195c340 198 sqimap_logout($imapConnection);
6b638171 199 do_hook("left_main_after");
0cd84d75 200
201
202
203 function FoldLink($mailbox, $folded)
204 {
205 $mailbox = urlencode($mailbox);
206 echo '<tt><a target="left" style="text-decoration:none" ';
207 echo 'href="left_main.php?';
208 if ($folded)
209 echo "unfold=$mailbox\">+";
210 else
211 echo "fold=$mailbox\">-";
212 echo '</a></tt>&nbsp;';
213 }
214
21c3249f 215?>
aae41ae9 216</BODY></HTML>