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