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