some color updates
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
3302d0d4 1<?
7c1b84d9 2
3302d0d4 3 /**
a09387f4 4 ** mailbox_display.php
3302d0d4 5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 **/
10
05207a68 11 function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox) {
3302d0d4 12 $senderName = getSenderName($from);
05207a68 13 $urlMailbox = urlencode($mailbox);
926da13e 14 echo "<TR>\n";
15 if ($seen == false) {
4c2d69ac 16 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><B><input type=checkbox name=\"msg[$t]\" value=$i></B></nobr></FONT></TD>\n";
926da13e 17 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
18 echo " <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
05207a68 19 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i\">$subject</A></B></FONT></TD>\n";
926da13e 20 } else {
4c2d69ac 21 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><input type=checkbox name=\"msg[$t]\" value=$i></nobr></FONT></TD>\n";
926da13e 22 echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
23 echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
05207a68 24 echo " <TD><FONT FACE=\"Arial,Helvetica\"><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i\">$subject</A></FONT></TD>\n";
926da13e 25 }
26 echo "</TR>\n";
27 }
28
29 /**
30 ** This function loops through a group of messages in the mailbox and shows them
31 **/
32 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort) {
61a4ac35 33 include("../config/config.php");
34
3e054c43 35 if (1 <= $numMessages) {
36 getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date);
37 }
38
39 $j = 0;
40 while ($j < $numMessages) {
0e919368 41 $date[$j] = ereg_replace(" ", " ", $date[$j]);
42 $tmpdate = explode(" ", trim($date[$j]));
43
44 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
45 $messages[$j]["DATE_STRING"] = getDateString($tmpdate);
3e054c43 46 $messages[$j]["ID"] = $j+1;
0e919368 47 $messages[$j]["FROM"] = getSenderName($from[$j]);
3e054c43 48 $messages[$j]["SUBJECT"] = $subject[$j];
5b10f02a 49 $messages[$j]["FLAG_DELETED"] = false;
50 $messages[$j]["FLAG_ANSWERED"] = false;
51 $messages[$j]["FLAG_SEEN"] = false;
926da13e 52
3e054c43 53 $num = 0;
54 getMessageFlags($imapConnection, $j+1, $flags);
55 while ($num < count($flags)) {
56 if ($flags[$num] == "Deleted") {
5b10f02a 57 $messages[$j]["FLAG_DELETED"] = true;
58 }
3e054c43 59 else if ($flags[$num] == "Answered") {
5b10f02a 60 $messages[$j]["FLAG_ANSWERED"] = true;
61 }
3e054c43 62 else if ($flags[$num] == "Seen") {
5b10f02a 63 $messages[$j]["FLAG_SEEN"] = true;
64 }
3e054c43 65 $num++;
3302d0d4 66 }
5b10f02a 67 $j++;
68 }
69
70 /** Find and remove the ones that are deleted */
3e054c43 71 $i = 0;
72 $j = 0;
73 while ($j < $numMessages) {
5b10f02a 74 if ($messages[$j]["FLAG_DELETED"] == true) {
75 $j++;
76 continue;
77 }
78 $msgs[$i]["TIME_STAMP"] = $messages[$j]["TIME_STAMP"];
79 $msgs[$i]["DATE_STRING"] = $messages[$j]["DATE_STRING"];
80 $msgs[$i]["ID"] = $messages[$j]["ID"];
81 $msgs[$i]["FROM"] = $messages[$j]["FROM"];
82 $msgs[$i]["SUBJECT"] = $messages[$j]["SUBJECT"];
83 $msgs[$i]["FLAG_DELETED"] = $messages[$j]["FLAG_DELETED"];
84 $msgs[$i]["FLAG_ANSWERED"] = $messages[$j]["FLAG_ANSWERED"];
85 $msgs[$i]["FLAG_SEEN"] = $messages[$j]["FLAG_SEEN"];
86 $i++;
3302d0d4 87 $j++;
88 }
89
3e054c43 90 $numMessages = $i;
926da13e 91
4c2d69ac 92 // There's gotta be messages in the array for it to sort them.
93 if ($numMessages > 0) {
0e919368 94 /** 0 = Date (up) 4 = Subject (up)
95 ** 1 = Date (dn) 5 = Subject (dn)
96 ** 2 = Name (up)
97 ** 3 = Name (dn)
98 **/
4c2d69ac 99 if ($sort == 0)
100 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
0e919368 101 else if ($sort == 1)
4c2d69ac 102 $msgs = ary_sort($msgs, "TIME_STAMP", 1);
0e919368 103 else {
104 $original = $msgs;
105 $i = 0;
106 while ($i < count($msgs)) {
107 $msgs[$i]["FROM"] = strtolower($msgs[$i]["FROM"]);
108 $msgs[$i]["SUBJECT"] = strtolower($msgs[$i]["SUBJECT"]);
109 $i++;
110 }
111
112 if ($sort == 2)
113 $msgs = ary_sort($msgs, "FROM", -1);
114 else if ($sort == 3)
115 $msgs = ary_sort($msgs, "FROM", 1);
116 else if ($sort == 4)
117 $msgs = ary_sort($msgs, "SUBJECT", -1);
118 else if ($sort == 5)
119 $msgs = ary_sort($msgs, "SUBJECT", 1);
120 else
121 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
122
123 $i = 0;
124 while ($i < count($msgs)) {
125 $j = 0;
126 while ($j < count($original)) {
127 if ($msgs[$i]["ID"] == $original[$j]["ID"]) {
128 $msgs[$i]["FROM"] = $original[$j]["FROM"];
129 $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"];
130 }
131 $j++;
132 }
133 $i++;
134 }
135 }
4c2d69ac 136 }
926da13e 137
138 if ($startMessage + 24 < $numMessages) {
926da13e 139 $endMessage = $startMessage + 24;
140 } else {
926da13e 141 $endMessage = $numMessages;
142 }
143
5b10f02a 144 $nextGroup = $startMessage + 25;
926da13e 145 $prevGroup = $startMessage - 25;
20db5033 146 $urlMailbox = urlencode($mailbox);
926da13e 147
20db5033 148 /** This is the beginning of the message list table. It wraps around all messages */
149 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
926da13e 150
0d1b4832 151 if ($startMessage < $endMessage) {
152 echo "<TR BGCOLOR=FFFFFF><TD>";
153 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">Viewing messages <B>$startMessage</B> to <B>$endMessage</B> ($numMessages total)</FONT></CENTER>\n";
154 echo "</TD></TR>\n";
155 } else if ($startMessage == $endMessage) {
156 echo "<TR BGCOLOR=FFFFFF><TD>";
157 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">Viewing message <B>$startMessage</B> ($numMessages total)</FONT></CENTER>\n";
158 echo "</TD></TR>\n";
159 }
26b6c99c 160
20db5033 161 echo "<TR BGCOLOR=FFFFFF><TD>";
5b10f02a 162 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
a09387f4 163 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
164 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
926da13e 165 }
5b10f02a 166 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
a09387f4 167 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
aa4c3749 168 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Next</FONT>\n";
3302d0d4 169 }
5b10f02a 170 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
aa4c3749 171 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Previous</FONT>\n";
a09387f4 172 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
926da13e 173 }
20db5033 174 echo "</TD></TR>\n";
926da13e 175
68347a84 176 /** The delete and move options */
faf8f4a2 177 echo "<TR><TD BGCOLOR=$color_lgray>";
05207a68 178 echo "<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
68347a84 179 echo "<SELECT NAME=move_or_delete><OPTION>Delete selected messages<OPTION>Move selected messages</SELECT>";
180 echo "<NOBR><INPUT TYPE=SUBMIT VALUE=\"Go\">";
61a4ac35 181 if (($move_to_trash == true) && ($mailbox == $trash_folder))
182 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF=\"empty_trash.php?numMessages=$numMessages&mailbox=$urlMailbox\">Empty Trash</A></NOBR>";
aa4c3749 183 echo "</TD></TR>";
184
faf8f4a2 185 echo "<TR><TD BGCOLOR=$color_lgray>";
926da13e 186 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=FFFFFF>";
187 echo "<TR BGCOLOR=FFFFCC ALIGN=\"center\">";
188 echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>Num</B></FONT></TD>";
0e919368 189 /** FROM HEADER **/
190 echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT>";
191 if ($sort == 2)
192 echo " <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
193 else if ($sort == 3)
194 echo " <A HREF=\"right_main.php?sort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
195 else
196 echo " <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
197 /** DATE HEADER **/
926da13e 198 echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>Date</B></FONT>";
199 if ($sort == 0)
a09387f4 200 echo " <A HREF=\"right_main.php?sort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
0e919368 201 else if ($sort == 1)
a09387f4 202 echo " <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
0e919368 203 else
204 echo " <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
205 /** SUBJECT HEADER **/
206 echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT>\n";
207 if ($sort == 4)
208 echo " <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
209 else if ($sort == 5)
210 echo " <A HREF=\"right_main.php?sort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
211 else
212 echo " <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
926da13e 213 echo "</TR>";
214
215 // loop through and display the info for each message.
aa4c3749 216 $t = 0; // $t is used for the checkbox number
4c2d69ac 217 if ($numMessages == 0) { // if there's no messages in this folder
218 echo "<TR><TD BGCOLOR=FFFFFF COLSPAN=4><CENTER><BR><B>THIS FOLDER IS EMPTY</B><BR>&nbsp</CENTER></TD></TR>";
219 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
3e054c43 220 $i = $startMessage - 1;
05207a68 221 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox);
4c2d69ac 222 } else {
223 for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
05207a68 224 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox);
4c2d69ac 225 $t++;
226 }
926da13e 227 }
68347a84 228 echo "</FORM></TABLE>";
aa4c3749 229
68347a84 230 echo "</TABLE>\n";
4c2d69ac 231 echo "</TD></TR>\n";
232
20db5033 233 echo "<TR BGCOLOR=FFFFFF><TD>";
234 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
a09387f4 235 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
236 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
20db5033 237 }
238 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
a09387f4 239 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
aa4c3749 240 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Next</FONT>\n";
20db5033 241 }
242 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
aa4c3749 243 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Previous</FONT>\n";
a09387f4 244 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
20db5033 245 }
926da13e 246 echo "</TD></TR></TABLE>"; /** End of message-list table */
3302d0d4 247 }
26b6c99c 248?>