removed debugging info
[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 if (strtolower($boxes[$i]["unformatted"]) == "inbox")
88 $count_special_folders++;
89 else if ($boxes[$i]["unformatted"] == $trash_folder)
90 $count_special_folders++;
91 else if ($boxes[$i]["unformatted"] == $sent_folder)
92 $count_special_folders++;
93 }
94
95 if ($count_special_folders < count($boxes)) {
96 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
97 echo "<TT><SELECT NAME=mailbox>\n";
98 for ($i = 0; $i < count($boxes); $i++) {
99 $use_folder = true;
100 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
101 ($boxes[$i]["unformatted"] != $trash_folder) &&
102 ($boxes[$i]["unformatted"] != $sent_folder))
103 {
104 $box = $boxes[$i]["unformatted-dm"];
105 $box2 = replace_spaces($boxes[$i]["formatted"]);
106 echo " <OPTION VALUE=\"$box\">$box2\n";
107 }
108 }
109 echo "</SELECT></TT>\n";
110 echo "<INPUT TYPE=SUBMIT VALUE=\"";
111 echo _("Delete");
112 echo "\">\n";
113 echo "</FORM><BR></TD></TR>\n";
114 } else {
115 echo _("No mailboxes found") . "<br><br></td><tr>";
116 }
117
118
119 /** CREATING FOLDERS **/
120 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
121 echo _("Create Folder");
122 echo "</B></TD></TR>";
123 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
124 echo "<FORM ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
125 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
126 echo _("as a subfolder of");
127 echo "<BR>";
128 echo "<TT><SELECT NAME=subfolder>\n";
129 if ($default_sub_of_inbox == false)
130 echo "<OPTION SELECTED>[ None ]\n";
131 else
132 echo "<OPTION>[ None ]\n";
133
134 for ($i = 0; $i < count($boxes); $i++) {
135 if (count($boxes[$i]["flags"]) > 0) {
136 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
137 if ($boxes[$i]["flags"][$j] != "noinferiors") {
138 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
139 $box = $boxes[$i]["unformatted"];
140 $box2 = replace_spaces($boxes[$i]["formatted"]);
141 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
142 } else {
143 $box = $boxes[$i]["unformatted"];
144 $box2 = replace_spaces($boxes[$i]["formatted"]);
145 echo "<OPTION VALUE=\"$box\">$box2\n";
146 }
147 }
148 }
149 } else {
150 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
151 $box = $boxes[$i]["unformatted"];
152 $box2 = replace_spaces($boxes[$i]["formatted"]);
153 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
154 } else {
155 $box = $boxes[$i]["unformatted"];
156 $box2 = replace_spaces($boxes[$i]["formatted"]);
157 echo "<OPTION VALUE=\"$box\">$box2\n";
158 }
159 }
160 }
161 echo "</SELECT></TT><BR>\n";
162 if ($show_contain_subfolders_option) {
163 echo "<INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
164 echo _("Let this folder contain subfolders");
165 echo "<BR>";
166 }
167 echo "<INPUT TYPE=SUBMIT VALUE=Create>\n";
168 echo "</FORM><BR></TD></TR><BR>\n";
169
170 /** RENAMING FOLDERS **/
171 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
172 echo _("Rename a Folder");
173 echo "</B></TD></TR>";
174 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
175 if ($count_special_folders < count($boxes)) {
176 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
177 echo "<TT><SELECT NAME=old>\n";
178 for ($i = 0; $i < count($boxes); $i++) {
179 $use_folder = true;
180
181 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
182 ($boxes[$i]["unformatted"] != $trash_folder) &&
183 ($boxes[$i]["unformatted"] != $sent_folder))
184 {
185 $box = $boxes[$i]["unformatted-dm"];
186 $box2 = replace_spaces($boxes[$i]["formatted"]);
187 echo " <OPTION VALUE=\"$box\">$box2\n";
188 }
189 }
190 echo "</SELECT></TT>\n";
191 echo "<INPUT TYPE=SUBMIT VALUE=\"";
192 echo _("Rename");
193 echo "\">\n";
194 echo "</FORM></TD></TR>\n";
195 } else {
196 echo _("No mailboxes found") . "<br><br></td></tr>";
197 }
198 $boxes_sub = $boxes;
199
200 /** UNSUBSCRIBE FOLDERS **/
201 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
202 echo _("Unsubscribe/Subscribe");
203 echo "</B></TD></TR>";
204 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
205 if ($count_special_folders < count($boxes)) {
206 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
207 echo "<TT><SELECT NAME=mailbox>\n";
208 for ($i = 0; $i < count($boxes); $i++) {
209 $use_folder = true;
210 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
211 ($boxes[$i]["unformatted"] != $trash_folder) &&
212 ($boxes[$i]["unformatted"] != $sent_folder))
213 {
214 $box = $boxes[$i]["unformatted-dm"];
215 $box2 = replace_spaces($boxes[$i]["formatted"]);
216 echo " <OPTION VALUE=\"$box\">$box2\n";
217 }
218 }
219 echo "</SELECT></TT>\n";
220 echo "<INPUT TYPE=SUBMIT VALUE=\"";
221 echo _("Unsubscribe");
222 echo "\">\n";
223 echo "</FORM></TD></TR>\n";
224 } else {
225 echo _("No mailboxes found") . "<br><br></td></tr>";
226 }
227 $boxes_sub = $boxes;
228
229 /** SUBSCRIBE TO FOLDERS **/
230
231 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
232 if ($count_special_folders <= count($boxes)) {
233 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
234 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
235
236 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
237 echo "<tt><select name=mailbox>";
238 for ($i = 0; $i < count($boxes_all); $i++) {
239 $use_folder = true;
240 for ($p = 0; $p < count ($boxes); $p++) {
241 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
242 $use_folder = false;
243 continue;
244 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
245 $use_folder = false;
246 }
247 }
248 if ($use_folder == true) {
249 $box = $boxes_all[$i]["unformatted-dm"];
250 $box2 = replace_spaces($boxes_all[$i]["formatted"]);
251 echo " <OPTION VALUE=\"$box\">$box2\n";
252 }
253 }
254 echo "</select></tt>";
255 echo "<INPUT TYPE=SUBMIT VALUE=\"";
256 echo _("Subscribe");
257 echo "\">\n";
258 echo "</FORM></TD></TR></TABLE><BR>\n";
259 } else {
260 echo _("No mailboxes found") . "<br><br></td></tr></table>";
261 }
262
263 ?>
264 </BODY></HTML>