corrected error which caused no data
[squirrelmail.git] / src / left_main.php
1 <?php
2 /**
3 ** left_main.php
4 **
5 ** This is the code for the left bar. The left bar shows the folders
6 ** available, and has cookie information.
7 **
8 **/
9
10 session_start();
11
12 if(!isset($username)) {
13 echo "You need a valid user and password to access this page!";
14 exit;
15 }
16
17 // Configure the left frame for the help menu
18 // Maybe this should be a function but since I haven't done one it isn't
19
20 $ishelp = substr(getenv(REQUEST_URI),-8); // take the right 8 characters from the requested URL
21 if ($ishelp == "help.php") {
22 if (!isset($config_php))
23 include("../config/config.php");
24 if (!isset($i18n_php))
25 include("../functions/i18n.php");
26 include("../src/load_prefs.php");
27 echo "<HTML BGCOLOR=\"$color[3]\">";
28 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" BGCOLOR=\"$color[3]\" LINK=\"$color[11]\" VLINK=\"$color[6]\" ALINK=\"$color[11]\">\n";
29 $left_size = 250; //doesn't seem to work
30 /**
31 ** Array used to list the include .hlp files, we could use a dir function
32 ** to step through the directory and list its contents but it doesn't order those.
33 ** This should probably go in config.php but it might mess up conf.pl
34 **/
35 $helpdir[0] = "basic.hlp";
36 $helpdir[1] = "main_folder.hlp";
37 $helpdir[2] = "read_mail.hlp";
38 $helpdir[3] = "addresses.hlp";
39 $helpdir[4] = "compose.hlp";
40 $helpdir[5] = "folders.hlp";
41 $helpdir[6] = "options.hlp";
42 $helpdir[7] = "FAQ.hlp";
43
44 /**
45 ** Build a menu dynamically for the left frame from the HTML tagged right frame include (.hlp) files listed in the $helpdir var.
46 ** This is done by first listing all the .hlp files in the $helpdir array.
47 ** Next, we loop through the array, for every value of $helpdir we loop through the file and look for anchor tags (<A NAME=) and
48 ** header tags (<H1> or <H3>).
49 **/
50
51 if (!file_exists("../help/$user_language")) // If the selected language doesn't exist, use english
52 $user_language = "en";
53
54
55 while ( list( $key, $val ) = each( $helpdir ) ) { // loop through the array of files
56 $fcontents = file("../help/$user_language/$val"); // assign each line of the above file to another array
57 while ( list( $line_num, $line ) = each( $fcontents ) ) { // loop through the second array
58 $temphed="";
59 $tempanc="";
60 if ( eregi("<A NAME=", $line, $tempanc)) { // if a name anchor is found, make a link
61 $tempanc = $line;
62 $tempanc = ereg_replace("<A NAME=", "", $tempanc);
63 $tempanc = ereg_replace("></A>", "", $tempanc);
64 echo "<A HREF=\"help.php#$tempanc\" target=\"right\">";
65 }
66 if ( eregi("<H1>", $line, $temphed)) { // grab a description for the link made above
67 $temphed = $line;
68 $temphed = ereg_replace("<H1>", "", $temphed);
69 $temphed = ereg_replace("</H1>", "", $temphed);
70 echo "<BR>";
71 echo "<FONT SIZE=+1>" . _("$temphed") . "</FONT></A><BR>\n"; // make it bigger since it is a heading type 1
72 }
73 if ( eregi("<H3>", $line, $temphed)) { // grab a description for the link made above
74 $temphed = $line;
75 $temphed = ereg_replace("<H3>", "", $temphed);
76 $temphed = ereg_replace("</H3>", "", $temphed);
77 echo "" . _("$temphed") . "</A><BR>\n"; // keep same size since it is a normal entry
78 }
79 }
80 }
81 } else {
82 if (!isset($config_php))
83 include("../config/config.php");
84 if (!isset($array_php))
85 include("../functions/array.php");
86 if (!isset($strings_php))
87 include("../functions/strings.php");
88 if (!isset($imap_php))
89 include("../functions/imap.php");
90 if (!isset($page_header_php))
91 include("../functions/page_header.php");
92 if (!isset($i18n_php))
93 include("../functions/i18n.php");
94
95
96 displayHtmlHeader();
97
98 function formatMailboxName($imapConnection, $mailbox, $real_box, $delimeter, $unseen) {
99 global $folder_prefix, $trash_folder, $sent_folder;
100 global $color, $move_to_sent, $move_to_trash;
101
102 $mailboxURL = urlencode($real_box);
103 if($real_box=="INBOX") {
104 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box);
105 }
106
107 $line .= "<NOBR>";
108 if ($unseen > 0)
109 $line .= "<B>";
110
111 $special_color = false;
112 if ((strtolower($real_box) == "inbox") ||
113 (($real_box == $trash_folder) && ($move_to_trash)) ||
114 (($real_box == $sent_folder) && ($move_to_sent)))
115 $special_color = true;
116
117 if ($special_color == true) {
118 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT COLOR=\"$color[11]\">";
119 $line .= replace_spaces($mailbox);
120 $line .= "</font></a>";
121 } else {
122 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
123 $line .= replace_spaces($mailbox);
124 $line .= "</a>";
125 }
126
127 if ($unseen > 0)
128 $line .= "</B>";
129
130 if ($unseen > 0) {
131 $line .= "&nbsp;<small>($unseen)</small>";
132 }
133
134 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
135 $urlMailbox = urlencode($real_box);
136 $line .= "\n<small>\n";
137 $line .= " &nbsp;&nbsp;&nbsp;&nbsp;(<B><A HREF=\"empty_trash.php?numMessages=$numMessages&mailbox=$urlMailbox\" TARGET=right style=\"text-decoration:none\">"._("purge")."</A></B>)";
138 $line .= "\n</small>\n";
139 }
140 $line .= "</NOBR>";
141 return $line;
142 }
143
144 // open a connection on the imap port (143)
145 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
146
147 /** If it was a successful login, lets load their preferences **/
148 include("../src/load_prefs.php");
149
150 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
151 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
152 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
153 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
154 }
155
156 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n\n";
157
158 $boxes = sqimap_mailbox_list($imapConnection);
159
160 echo "<CENTER><FONT SIZE=4><B>";
161 echo _("Folders") . "</B><BR></FONT>\n\n";
162
163 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
164 echo _("refresh folder list");
165 echo "</A>)</small></CENTER><BR>";
166 $delimeter = sqimap_get_delimiter($imapConnection);
167
168 for ($i = 0;$i < count($boxes); $i++) {
169 $line = "";
170 $mailbox = $boxes[$i]["formatted"];
171
172 if ($boxes[$i]["flags"]) {
173 $noselect = false;
174 for ($h = 0; $h < count($boxes[$i]["flags"]); $h++) {
175 if (strtolower($boxes[$i]["flags"][$h]) == "noselect")
176 $noselect = true;
177 }
178 if ($noselect == true) {
179 $line .= "<FONT COLOR=\"$color[10]\">";
180 $line .= replace_spaces(readShortMailboxName($mailbox, $delimeter));
181 $line .= "</FONT>";
182 } else {
183 $line .= formatMailboxName($imapConnection, $mailbox, $boxes[$i]["unformatted"], $delimeter, $boxes[$i]["unseen"]);
184 }
185 } else {
186 $line .= formatMailboxName($imapConnection, $mailbox, $boxes[$i]["unformatted"], $delimeter, $boxes[$i]["unseen"]);
187 }
188 echo "\n$line<BR>\n";
189 }
190
191
192 fclose($imapConnection);
193
194 }
195 ?>
196 </BODY></HTML>