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