Fixed a glich that caused the 'Viewing message' line to show a strange colour when...
[squirrelmail.git] / functions / mailbox_display.php
1 <?php
2
3 /**
4 ** mailbox_display.php
5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 **/
10
11 $mailbox_info = true;
12
13 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage) {
14 global $color, $msgs, $msort;
15 global $sent_folder;
16
17 $msg = $msgs[$key];
18
19 $senderName = $msg["FROM"];
20 $urlMailbox = urlencode($mailbox);
21 $subject = trim(stripslashes($msg["SUBJECT"]));
22 echo "<TR>\n";
23
24 if ($msg["FLAG_FLAGGED"] == true) { $flag = "<font color=$color[2]>"; $flag_end = "</font>"; }
25 if ($msg["FLAG_SEEN"] == false) { $bold = "<b>"; $bold_end = "</b>"; }
26 if ($msg["FLAG_ANSWERED"] == true) { $ans = "&nbsp;[A]"; }
27 if ($mailbox == $sent_folder) { $italic = "<i>"; $italic_end = "</i>"; }
28
29 echo " <td width=1% align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."></TD>\n";
30 echo " <td width=30%>$italic$bold$flag$senderName$flag_end$bold_end$italic_end</td>\n";
31 echo " <td nowrap width=1%><center>$bold$flag".$msg["DATE_STRING"]."$flag_end$bold_end</center></td>\n";
32 echo " <td width=%>$bold<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0\">$flag$subject$flag_end</a>$ans$bold_end</td>\n";
33
34 echo "</tr>\n";
35 }
36
37 /**
38 ** This function loops through a group of messages in the mailbox and shows them
39 **/
40 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
41 global $msgs, $msort;
42 global $sent_folder;
43
44 if (!$use_cache) {
45 if ($numMessages >= 1) {
46 for ($q = 0; $q < $numMessages; $q++) {
47 if ($mailbox == $sent_folder)
48 sqimap_get_small_header ($imapConnection, $q+1, $f, $s, $d, true);
49 else
50 sqimap_get_small_header ($imapConnection, $q+1, $f, $s, $d, false);
51
52 $from[$q] = $f;
53 $date[$q] = $d;
54 $subject[$q] = $s;
55 $flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
56 }
57 }
58
59 $j = 0;
60 while ($j < $numMessages) {
61 $date[$j] = ereg_replace(" ", " ", $date[$j]);
62 $tmpdate = explode(" ", trim($date[$j]));
63
64 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
65 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
66 $messages[$j]["ID"] = $j+1;
67 $messages[$j]["FROM"] = decodeHeader($from[$j]);
68 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
69
70 $num = 0;
71 while ($num < count($flags[$j])) {
72 if ($flags[$j][$num] == "Deleted") {
73 $messages[$j]["FLAG_DELETED"] = true;
74 }
75 else if ($flags[$j][$num] == "Answered") {
76 $messages[$j]["FLAG_ANSWERED"] = true;
77 }
78 else if ($flags[$j][$num] == "Seen") {
79 $messages[$j]["FLAG_SEEN"] = true;
80 }
81 else if ($flags[$j][$num] == "Flagged") {
82 $messages[$j]["FLAG_FLAGGED"] = true;
83 }
84 $num++;
85 }
86 $j++;
87 }
88
89 /** Find and remove the ones that are deleted */
90 $i = 0;
91 $j = 0;
92 while ($j < $numMessages) {
93 if ($messages[$j]["FLAG_DELETED"] == true) {
94 $j++;
95 continue;
96 }
97 $msgs[$i] = $messages[$j];
98
99 $i++;
100 $j++;
101 }
102 $numMessages = $i;
103 }
104
105 // There's gotta be messages in the array for it to sort them.
106 if (($numMessages > 0) && (!$use_cache)) {
107 /** 0 = Date (up) 4 = Subject (up)
108 ** 1 = Date (dn) 5 = Subject (dn)
109 ** 2 = Name (up)
110 ** 3 = Name (dn)
111 **/
112
113 if (($sort == 0) || ($sort == 1))
114 $msort = array_cleave ($msgs, "TIME_STAMP");
115 if (($sort == 2) || ($sort == 3))
116 $msort = array_cleave ($msgs, "FROM");
117 if (($sort == 4) || ($sort == 5))
118 $msort = array_cleave ($msgs, "SUBJECT");
119
120 if(($sort % 2) == 1) {
121 asort($msort);
122 } else {
123 arsort($msort);
124 }
125 session_register("msort");
126 }
127 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
128 }
129
130 // generic function to convert the msgs array into an HTML table
131 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
132 global $folder_prefix, $sent_folder;
133 global $imapServerAddress;
134
135 // do a check to see if the config stuff has already been included or not
136 // if (!isset($imapServerAddress))
137 // include("../config/config.php");
138
139 // if cache isn't already set, do it now
140 if (!session_is_registered("msgs"))
141 session_register("msgs");
142 if (!session_is_registered("msort"))
143 session_register("msort");
144
145 if ($startMessage + ($show_num - 1) < $numMessages) {
146 $endMessage = $startMessage + ($show_num-1);
147 } else {
148 $endMessage = $numMessages;
149 }
150
151 $nextGroup = $startMessage + $show_num;
152 $prevGroup = $startMessage - $show_num;
153 $urlMailbox = urlencode($mailbox);
154
155 /** This is the beginning of the message list table. It wraps around all messages */
156 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
157
158 if ($startMessage < $endMessage) {
159 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
160 echo "<CENTER>". _("Viewing messages ") ."<B>$startMessage</B>". _(" to ") ."<B>$endMessage</B> ($numMessages total)</CENTER>\n";
161 echo "</TD></TR>\n";
162 } else if ($startMessage == $endMessage) {
163 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
164 echo "<CENTER>". _("Viewing message ") ."<B>$startMessage</B> ($numMessages ". _("total") .")</CENTER>\n";
165 echo "</TD></TR>\n";
166 }
167
168 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
169 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
170 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A>\n";
171 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
172 }
173 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
174 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A>\n";
175 echo "<FONT COLOR=\"$color[9]\">Next</FONT>\n";
176 }
177 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
178 echo "<FONT COLOR=\"$color[9]\">Previous</FONT>\n";
179 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
180 }
181 echo "</TD></TR>\n";
182
183 /** The delete and move options */
184 echo "<TR><TD BGCOLOR=\"$color[0]\">";
185
186 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage\">";
187 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0>\n";
188 echo " <TR>\n";
189 echo " <TD WIDTH=60% ALIGN=LEFT>\n";
190 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
191 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
192
193 $boxes = sqimap_mailbox_list($imapConnection);
194 for ($i = 0; $i < count($boxes); $i++) {
195 $box = $boxes[$i]["unformatted"];
196 $box2 = replace_spaces($boxes[$i]["formatted"]);
197 echo " <OPTION VALUE=\"$box\">$box2\n";
198 }
199 echo " </SELECT></SMALL></TT>";
200 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
201
202 echo " </TD>\n";
203 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
204 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
205 echo " </TD>";
206 echo " </TR>\n";
207
208 echo "</TABLE>\n\n\n";
209 echo "</TD></TR>";
210
211 echo "<TR><TD BGCOLOR=\"$color[0]\">";
212 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[4]\">";
213 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
214 echo " <TD WIDTH=1%><B>&nbsp;</B></TD>";
215 /** FROM HEADER **/
216 if ($mailbox == $sent_folder)
217 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
218 else
219 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
220
221 if ($sort == 2)
222 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
223 else if ($sort == 3)
224 echo " <A HREF=\"right_main.php?newsort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
225 else
226 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
227 /** DATE HEADER **/
228 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
229 if ($sort == 0)
230 echo " <A HREF=\"right_main.php?newsort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
231 else if ($sort == 1)
232 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
233 else
234 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
235 /** SUBJECT HEADER **/
236 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
237 if ($sort == 4)
238 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
239 else if ($sort == 5)
240 echo " <A HREF=\"right_main.php?newsort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
241 else
242 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
243 echo "</TR>";
244
245
246 // loop through and display the info for each message.
247 $t = 0; // $t is used for the checkbox number
248 if ($numMessages == 0) { // if there's no messages in this folder
249 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=4><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp</CENTER></TD></TR>";
250 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
251 $i = $startMessage - 1;
252 reset($msort);
253 do {
254 $key = key($msort);
255 next($msort);
256 $k++;
257 } while (isset ($key) && ($k < $i));
258 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage);
259 } else {
260 $i = $startMessage;
261 reset($msort);
262 do {
263 $key = key($msort);
264 next($msort);
265 $k++;
266 } while (isset ($key) && ($k < $i));
267
268 do {
269 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage);
270 $key = key($msort);
271 $t++;
272 $i++;
273 next($msort);
274 } while ($i < ($endMessage+1));
275 }
276 echo "</FORM></TABLE>";
277
278 echo "</TABLE>\n";
279 echo "</TD></TR>\n";
280
281 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
282 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
283 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A>\n";
284 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
285 }
286 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
287 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A>\n";
288 echo "<FONT COLOR=\"$color[9]\">" . _("Next") . "</FONT>\n";
289 }
290 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
291 echo "<FONT COLOR=\"$color[9]\">Previous</FONT>\n";
292 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
293 }
294 echo "</TD></TR></TABLE>"; /** End of message-list table */
295 }
296 ?>