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