bugfixes
[squirrelmail.git] / src / folders.php
1 <?php
2 session_start();
3
4 if (!isset($config_php))
5 include("../config/config.php");
6 if (!isset($strings_php))
7 include("../functions/strings.php");
8 if (!isset($page_header_php))
9 include("../functions/page_header.php");
10 if (!isset($imap_php))
11 include("../functions/imap.php");
12 if (!isset($array_php))
13 include("../functions/array.php");
14
15 include("../src/load_prefs.php");
16
17 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
18
19 displayPageHeader($color, "None");
20
21 echo "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
22 echo " <TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n";
23 echo _("Folders");
24 echo " </TD></TR>\n";
25 echo "</TABLE>\n";
26
27 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
28 $boxes = sqimap_mailbox_list($imapConnection);
29
30 /** Cyrus Folder Options**/
31 //Creates the Sent and Trash folder
32 if (($sent_create == "true") || ($trash_create == "true")) {
33 if ($sent_create == "true") {
34 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
35 }
36 if ($trash_create == "true") {
37 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
38 }
39 echo "<BR><BR><CENTER><b>";
40 echo _("Mailboxes Created Successfully!");
41 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
42 echo _("Click here");
43 echo "</A> ";
44 echo _("to continue.");
45 echo "</CENTER>";
46 echo "</BODY></HTML>";
47
48 exit;
49 }
50
51 //display form option for creating Sent and Trash folder
52 if ($imap_server_type == "cyrus") {
53 if ((!sqimap_mailbox_exists ($imapConnection, $sent_folder)) || (!sqimap_mailbox_exists ($imapConnection, $trash_folder))) {
54 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>\n";
55 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
56 echo _("Special Folder Options");
57 echo "</B></TD></TR>";
58 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
59 echo _("In order for SquirrelMail to provide the full set of options you need to create the special folders listed below. Just click the check box and hit the create button.");
60 echo "<FORM ACTION=\"folders.php\" METHOD=\"POST\">\n";
61 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
62 echo _("Create Sent") . "<INPUT TYPE=checkbox NAME=sent_create value=true><br>\n";
63 }
64 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)){
65 echo _("Create Trash") . "<INPUT TYPE=checkbox NAME=trash_create value=true><br>\n";
66 echo "<INPUT TYPE=submit VALUE=Create>";
67 echo "</FORM></TD></TR>\n";
68 }
69 }
70 }
71
72 /** DELETING FOLDERS **/
73 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>\n";
74 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
75 echo _("Delete Folder");
76 echo "</B></TD></TR>";
77 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
78
79 $count_special_folders = 0;
80 $num_max = 1;
81 if ($move_to_trash)
82 $num_max++;
83 if ($move_to_sent)
84 $num_max++;
85
86 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
87 echo "$count_special_folders - $p<br>";
88 if (strtolower($boxes[$i]["unformatted"]) == "inbox")
89 $count_special_folders++;
90 else if ($boxes[$i]["unformatted"] == $trash_folder)
91 $count_special_folders++;
92 else if ($boxes[$i]["unformatted"] == $sent_folder)
93 $count_special_folders++;
94 }
95
96 if ($count_special_folders < count($boxes)) {
97 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
98 echo "<TT><SELECT NAME=mailbox>\n";
99 for ($i = 0; $i < count($boxes); $i++) {
100 $use_folder = true;
101 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
102 ($boxes[$i]["unformatted"] != $trash_folder) &&
103 ($boxes[$i]["unformatted"] != $sent_folder))
104 {
105 $box = $boxes[$i]["unformatted-dm"];
106 $box2 = replace_spaces($boxes[$i]["formatted"]);
107 echo " <OPTION VALUE=\"$box\">$box2\n";
108 }
109 }
110 echo "</SELECT></TT>\n";
111 echo "<INPUT TYPE=SUBMIT VALUE=\"";
112 echo _("Delete");
113 echo "\">\n";
114 echo "</FORM><BR></TD></TR>\n";
115 } else {
116 echo _("No mailboxes found") . "<br><br></td><tr>";
117 }
118
119
120 /** CREATING FOLDERS **/
121 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
122 echo _("Create Folder");
123 echo "</B></TD></TR>";
124 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
125 echo "<FORM ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
126 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
127 echo _("as a subfolder of");
128 echo "<BR>";
129 echo "<TT><SELECT NAME=subfolder>\n";
130 if ($default_sub_of_inbox == false)
131 echo "<OPTION SELECTED>[ None ]\n";
132 else
133 echo "<OPTION>[ None ]\n";
134
135 for ($i = 0; $i < count($boxes); $i++) {
136 if (count($boxes[$i]["flags"]) > 0) {
137 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
138 if ($boxes[$i]["flags"][$j] != "noinferiors") {
139 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
140 $box = $boxes[$i]["unformatted"];
141 $box2 = replace_spaces($boxes[$i]["formatted"]);
142 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
143 } else {
144 $box = $boxes[$i]["unformatted"];
145 $box2 = replace_spaces($boxes[$i]["formatted"]);
146 echo "<OPTION VALUE=\"$box\">$box2\n";
147 }
148 }
149 }
150 } else {
151 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
152 $box = $boxes[$i]["unformatted"];
153 $box2 = replace_spaces($boxes[$i]["formatted"]);
154 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
155 } else {
156 $box = $boxes[$i]["unformatted"];
157 $box2 = replace_spaces($boxes[$i]["formatted"]);
158 echo "<OPTION VALUE=\"$box\">$box2\n";
159 }
160 }
161 }
162 echo "</SELECT></TT><BR>\n";
163 if ($show_contain_subfolders_option) {
164 echo "<INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
165 echo _("Let this folder contain subfolders");
166 echo "<BR>";
167 }
168 echo "<INPUT TYPE=SUBMIT VALUE=Create>\n";
169 echo "</FORM><BR></TD></TR><BR>\n";
170
171 /** RENAMING FOLDERS **/
172 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
173 echo _("Rename a Folder");
174 echo "</B></TD></TR>";
175 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
176 if ($count_special_folders < count($boxes)) {
177 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
178 echo "<TT><SELECT NAME=old>\n";
179 for ($i = 0; $i < count($boxes); $i++) {
180 $use_folder = true;
181
182 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
183 ($boxes[$i]["unformatted"] != $trash_folder) &&
184 ($boxes[$i]["unformatted"] != $sent_folder))
185 {
186 $box = $boxes[$i]["unformatted-dm"];
187 $box2 = replace_spaces($boxes[$i]["formatted"]);
188 echo " <OPTION VALUE=\"$box\">$box2\n";
189 }
190 }
191 echo "</SELECT></TT>\n";
192 echo "<INPUT TYPE=SUBMIT VALUE=\"";
193 echo _("Rename");
194 echo "\">\n";
195 echo "</FORM></TD></TR>\n";
196 } else {
197 echo _("No mailboxes found") . "<br><br></td></tr>";
198 }
199 $boxes_sub = $boxes;
200
201 /** UNSUBSCRIBE FOLDERS **/
202 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
203 echo _("Unsubscribe/Subscribe");
204 echo "</B></TD></TR>";
205 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
206 if ($count_special_folders < count($boxes)) {
207 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
208 echo "<TT><SELECT NAME=mailbox>\n";
209 for ($i = 0; $i < count($boxes); $i++) {
210 $use_folder = true;
211 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
212 ($boxes[$i]["unformatted"] != $trash_folder) &&
213 ($boxes[$i]["unformatted"] != $sent_folder))
214 {
215 $box = $boxes[$i]["unformatted-dm"];
216 $box2 = replace_spaces($boxes[$i]["formatted"]);
217 echo " <OPTION VALUE=\"$box\">$box2\n";
218 }
219 }
220 echo "</SELECT></TT>\n";
221 echo "<INPUT TYPE=SUBMIT VALUE=\"";
222 echo _("Unsubscribe");
223 echo "\">\n";
224 echo "</FORM></TD></TR>\n";
225 } else {
226 echo _("No mailboxes found") . "<br><br></td></tr>";
227 }
228 $boxes_sub = $boxes;
229
230 /** SUBSCRIBE TO FOLDERS **/
231
232 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
233 if ($count_special_folders <= count($boxes)) {
234 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
235 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
236
237 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
238 echo "<tt><select name=mailbox>";
239 for ($i = 0; $i < count($boxes_all); $i++) {
240 $use_folder = true;
241 for ($p = 0; $p < count ($boxes); $p++) {
242 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
243 $use_folder = false;
244 continue;
245 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
246 $use_folder = false;
247 }
248 }
249 if ($use_folder == true) {
250 $box = $boxes_all[$i]["unformatted-dm"];
251 $box2 = replace_spaces($boxes_all[$i]["formatted"]);
252 echo " <OPTION VALUE=\"$box\">$box2\n";
253 }
254 }
255 echo "</select></tt>";
256 echo "<INPUT TYPE=SUBMIT VALUE=\"";
257 echo _("Subscribe");
258 echo "\">\n";
259 echo "</FORM></TD></TR></TABLE><BR>\n";
260 } else {
261 echo _("No mailboxes found") . "<br><br></td></tr></table>";
262 }
263
264 ?>
265 </BODY></HTML>