Fixed login crash
[squirrelmail.git] / src / folders.php
1 <?php
2
3 /**
4 ** folders.php
5 **
6 ** Copyright (c) 1999-2001 The SquirrelMail development team
7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 **
9 ** Handles all interaction between the user and the other folder
10 ** scripts which do most of the work. Also handles the Special
11 ** Folders.
12 **
13 ** $Id$
14 **/
15
16 require_once('../src/validate.php');
17 require_once('../functions/imap.php');
18 require_once('../functions/array.php');
19 require_once('../functions/plugin.php');
20
21 displayPageHeader($color, 'None');
22
23 ?>
24
25 <br>
26 <table bgcolor="<?php echo $color[0] ?>" width="95%" align="center" cellpadding="2" cellspacing="0" border="0">
27 <tr><td align="center">
28
29 <b><?php echo _("Folders"); ?></b>
30
31 <table width="100%" border="0" cellpadding="5" cellspacing="0">
32 <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
33
34 <?php
35
36 if ((isset($success) && $success) ||
37 (isset($sent_create) && $sent_create == "true") ||
38 (isset($trash_create) && $trash_create == "true")) {
39 echo "<table width=100% align=center cellpadding=2 cellspacing=0 border=0>\n";
40 echo " <tr><td align=center>\n";
41 if ($success == "subscribe") {
42 echo "<b>" . _("Subscribed successfully!") . "</b><br>";
43 } else if ($success == "unsubscribe") {
44 echo "<b>" . _("Unsubscribed successfully!") . "</b><br>";
45 } else if ($success == "delete") {
46 echo "<b>" . _("Deleted folder successfully!") . "</b><br>";
47 } else if ($success == "create") {
48 echo "<b>" . _("Created folder successfully!") . "</b><br>";
49 } else if ($success == "rename") {
50 echo "<b>" . _("Renamed successfully!") . "</b><br>";
51 }
52
53 echo " <a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>";
54 echo " </td></tr>\n";
55 echo "</table><br>\n";
56 }
57 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
58 $boxes = sqimap_mailbox_list($imapConnection);
59
60 /** DELETING FOLDERS **/
61 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
62 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
63 echo _("Delete Folder");
64 echo "</B></TD></TR>";
65 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
66
67 $count_special_folders = 0;
68 $num_max = 1;
69 if (strtolower($imap_server_type) == "courier" || $move_to_trash)
70 $num_max++;
71 if ($move_to_sent)
72 $num_max++;
73
74 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
75 if (strtolower($boxes[$p]["unformatted"]) == "inbox")
76 $count_special_folders++;
77 else if (strtolower($imap_server_type) == "courier" &&
78 strtolower($boxes[$p]["unformatted"]) == "inbox.trash")
79 $count_special_folders++;
80 else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder)
81 $count_special_folders++;
82 else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder)
83 $count_special_folders++;
84 }
85
86 if ($count_special_folders < count($boxes)) {
87 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
88 echo "<TT><SELECT NAME=mailbox>\n";
89 for ($i = 0; $i < count($boxes); $i++) {
90 $use_folder = true;
91 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
92 ($boxes[$i]["unformatted"] != $trash_folder) &&
93 ($boxes[$i]["unformatted"] != $sent_folder) &&
94 (strtolower($imap_server_type) != "courier" ||
95 strtolower($boxes[$i]["unformatted"]) != "inbox.trash"))
96 {
97 $box = $boxes[$i]["unformatted-dm"];
98 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
99 echo " <OPTION VALUE=\"$box\">$box2\n";
100 }
101 }
102 echo "</SELECT></TT>\n";
103 echo "<INPUT TYPE=SUBMIT VALUE=\"";
104 echo _("Delete");
105 echo "\">\n";
106 echo "</FORM></TD></TR>\n";
107 } else {
108 echo _("No folders found") . "<br><br></td><tr>";
109 }
110
111 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
112
113 /** CREATING FOLDERS **/
114 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
115 echo _("Create Folder");
116 echo "</B></TD></TR>";
117 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
118 echo "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
119 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
120 echo _("as a subfolder of");
121 echo "<BR>";
122 echo "<TT><SELECT NAME=subfolder>\n";
123 if (strtolower($imap_server_type) != "courier"){
124 if ($default_sub_of_inbox == false)
125 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
126 else
127 echo '<OPTION VALUE="">[ '._("None")." ]\n";
128 }
129
130 for ($i = 0; $i < count($boxes); $i++) {
131 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
132 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
133 $box = $boxes[$i]["unformatted"];
134 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
135 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
136 } else {
137 $box = $boxes[$i]["unformatted"];
138 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
139 if (strtolower($imap_server_type) != "courier" ||
140 strtolower($box) != "inbox.trash")
141 echo "<OPTION VALUE=\"$box\">$box2\n";
142 }
143 }
144 }
145 echo "</SELECT></TT>\n";
146 if ($show_contain_subfolders_option) {
147 echo "<br><INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
148 echo _("Let this folder contain subfolders");
149 echo "<BR>";
150 }
151 echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n";
152 echo "</FORM></TD></TR>\n";
153
154 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
155
156 /** RENAMING FOLDERS **/
157 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
158 echo _("Rename a Folder");
159 echo "</B></TD></TR>";
160 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
161 if ($count_special_folders < count($boxes)) {
162 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
163 echo "<TT><SELECT NAME=old>\n";
164 for ($i = 0; $i < count($boxes); $i++) {
165 $use_folder = true;
166
167 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
168 ($boxes[$i]["unformatted"] != $trash_folder) &&
169 ($boxes[$i]["unformatted"] != $sent_folder))
170 {
171 $box = $boxes[$i]["unformatted-dm"];
172 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
173 if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash")
174 echo "<OPTION VALUE=\"$box\">$box2\n";
175 }
176 }
177 echo "</SELECT></TT>\n";
178 echo "<INPUT TYPE=SUBMIT VALUE=\"";
179 echo _("Rename");
180 echo "\">\n";
181 echo "</FORM></TD></TR>\n";
182 } else {
183 echo _("No folders found") . "<br><br></td></tr>";
184 }
185 $boxes_sub = $boxes;
186
187 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr></table>\n";
188
189 /** UNSUBSCRIBE FOLDERS **/
190 echo "<TABLE WIDTH=70% COLS=2 ALIGN=CENTER cellpadding=2 cellspacing=1 border=0>\n";
191 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=2><B>";
192 echo _("Unsubscribe") . "/" . _("Subscribe");
193 echo "</B></TD></TR>\n";
194 echo "<TR><TD BGCOLOR=\"$color[0]\" width=50% ALIGN=CENTER>\n";
195 if ($count_special_folders < count($boxes)) {
196 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
197 echo "<TT><SELECT NAME=mailbox[] multiple size=8>\n";
198 for ($i = 0; $i < count($boxes); $i++) {
199 $use_folder = true;
200 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
201 ($boxes[$i]["unformatted"] != $trash_folder) &&
202 ($boxes[$i]["unformatted"] != $sent_folder))
203 {
204 $box = $boxes[$i]["unformatted-dm"];
205 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
206 echo " <OPTION VALUE=\"$box\">$box2\n";
207 }
208 }
209 echo "</SELECT></TT><br>\n";
210 echo "<INPUT TYPE=SUBMIT VALUE=\"";
211 echo _("Unsubscribe");
212 echo "\">\n";
213 echo "</FORM></TD>\n";
214 } else {
215 echo _("No folders were found to unsubscribe from!") . "</td>";
216 }
217 $boxes_sub = $boxes;
218
219 /** SUBSCRIBE TO FOLDERS **/
220 echo "<TD BGCOLOR=\"$color[0]\" width=50% ALIGN=CENTER>";
221 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
222 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
223
224 $box = "";
225 $box2 = "";
226 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
227 $use_folder = true;
228 for ($p = 0; $p < count ($boxes); $p++) {
229 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
230 $use_folder = false;
231 continue;
232 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
233 $use_folder = false;
234 }
235 }
236 if ($use_folder == true) {
237 $box[$q] = $boxes_all[$i]["unformatted-dm"];
238 $box2[$q] = $boxes_all[$i]["unformatted-disp"];
239 $q++;
240 }
241 }
242 sqimap_logout($imap_stream);
243
244 if ($box && $box2) {
245 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
246 echo "<tt><select name=mailbox[] multiple size=8>";
247
248 for ($q = 0; $q < count($box); $q++) {
249 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
250 }
251 echo "</select></tt><br>";
252 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
253 echo "</FORM></TD></TR></TABLE><BR>\n";
254 } else {
255 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
256 }
257 ?>
258
259
260 <?php do_hook("folders_bottom"); ?>
261
262
263 </td></tr>
264 </table>
265
266 </td></tr>
267 </table>
268
269 <?php
270 sqimap_logout($imapConnection);
271 ?>
272
273 </body></html>