466e6ef7c4bd80433302122e2d0d00af7fd53bb2
[squirrelmail.git] / src / folders.php
1 <?php
2
3 /**
4 * folders.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project 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 /* Path for SquirrelMail required files. */
17 define('SM_PATH','../');
18
19 /* SquirrelMail required files. */
20 require_once(SM_PATH . 'include/validate.php');
21 require_once(SM_PATH . 'functions/imap.php');
22 require_once(SM_PATH . 'functions/plugin.php');
23 require_once(SM_PATH . 'functions/html.php');
24
25 displayPageHeader($color, 'None');
26
27 /* get globals we may need */
28
29 $username = $_SESSION['username'];
30 $key = $_COOKIE['key'];
31 $delimiter = $_SESSION['delimiter'];
32 $onetimepad = $_SESSION['onetimepad'];
33 if (isset($_GET['success'])) {
34 $success = $_GET['success'];
35 }
36
37 /* end of get globals */
38
39 echo '<br>' .
40 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
41 html_tag( 'tr' ) .
42 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
43 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
44 html_tag( 'tr' ) .
45 html_tag( 'td', '', 'center', $color[4] );
46
47 if ( isset($success) && $success ) {
48
49 $td_str = '<b>';
50
51 switch ($success)
52 {
53 case 'subscribe':
54 $td_str .= _("Subscribed successfully!");
55 break;
56 case 'unsubscribe':
57 $td_str .= _("Unsubscribed successfully!");
58 break;
59 case 'delete':
60 $td_str .= _("Deleted folder successfully!");
61 break;
62 case 'create':
63 $td_str .= _("Created folder successfully!");
64 break;
65 case 'rename':
66 $td_str .= _("Renamed successfully!");
67 break;
68 case 'subscribe-doesnotexist':
69 $td_str .= _("Subscription Unsuccessful - Folder does not exist.");
70 break;
71 }
72
73 $td_str .= '</b><br>';
74
75
76 echo html_tag( 'table',
77 html_tag( 'tr',
78 html_tag( 'td', $td_str .
79 '<a href="../src/left_main.php" target=left>' .
80 _("refresh folder list") . '</a>' ,
81 'center' )
82 ) ,
83 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
84 }
85
86 echo "\n<br>";
87
88 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
89 $boxes = sqimap_mailbox_list($imapConnection);
90
91 /** CREATING FOLDERS **/
92 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
93 html_tag( 'tr',
94 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
95 ) .
96 html_tag( 'tr' ) .
97 html_tag( 'td', '', 'center', $color[0] ) .
98
99 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
100 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
101 _("as a subfolder of").
102 '<BR>'.
103 "<TT><SELECT NAME=subfolder>\n";
104
105 $show_selected=0;
106 $skip_folders=0;
107 $server_type = strtolower($imap_server_type);
108 if ( $server_type == 'courier' ) {
109 $show_selected = array('inbox');
110 $skip_folders = array('inbox.trash');
111 if ( $default_folder_prefix == 'INBOX.' ) {
112 array_push($skip_folders, 'inbox');
113 }
114 }
115
116 if ( $default_sub_of_inbox == false ) {
117 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
118 } else {
119 echo '<OPTION VALUE="">[ '._("None")." ]\n";
120 $show_selected = array('inbox');
121 }
122
123 echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors');
124
125 echo "</SELECT></TT>\n";
126 if ($show_contain_subfolders_option) {
127 echo '<br><input type=CHECKBOX NAME="contain_subs"> &nbsp;'
128 . _("Let this folder contain subfolders")
129 . '<BR>';
130 }
131 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
132 echo "</FORM></td></tr>\n";
133
134 echo html_tag( 'tr',
135 html_tag( 'td', '&nbsp;', 'left', $color[4] )
136 ) ."\n";
137
138 /** count special folders **/
139 $count_special_folders = 0;
140 $num_max = 1;
141 if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
142 $num_max++;
143 }
144 if ($move_to_sent) {
145 $num_max++;
146 }
147 if ($save_as_draft) {
148 $num_max++;
149 }
150 for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
151 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
152 $count_special_folders++;
153 else if (strtolower($imap_server_type) == 'courier' &&
154 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
155 $count_special_folders++;
156 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
157 $count_special_folders++;
158 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
159 $count_special_folders++;
160 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
161 $count_special_folders++;
162 }
163
164
165 /** RENAMING FOLDERS **/
166 echo html_tag( 'tr',
167 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
168 ) .
169 html_tag( 'tr' ) .
170 html_tag( 'td', '', 'center', $color[0] );
171
172 if ($count_special_folders < count($boxes)) {
173 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
174 . "<TT><SELECT NAME=old>\n"
175 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
176
177 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
178
179 echo "</SELECT></TT>\n".
180 "<input type=SUBMIT VALUE=\"".
181 _("Rename").
182 "\">\n".
183 "</FORM></td></tr>\n";
184 } else {
185 echo _("No folders found") . '<br><br></td></tr>';
186 }
187 $boxes_sub = $boxes;
188
189 echo html_tag( 'tr',
190 html_tag( 'td', '&nbsp;', 'left', $color[4] )
191 ) ."\n";
192
193 /** DELETING FOLDERS **/
194 echo html_tag( 'tr',
195 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
196 ) .
197 html_tag( 'tr' ) .
198 html_tag( 'td', '', 'center', $color[0] );
199
200 if ($count_special_folders < count($boxes)) {
201 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
202 . "<TT><SELECT NAME=mailbox>\n"
203 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
204
205 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
206
207 echo "</SELECT></TT>\n"
208 . '<input type=SUBMIT VALUE="'
209 . _("Delete")
210 . "\">\n"
211 . "</form></td></tr>\n";
212 } else {
213 echo _("No folders found") . "<br><br></td></tr>";
214 }
215
216 echo html_tag( 'tr',
217 html_tag( 'td', '&nbsp;', 'left', $color[4] )
218 ) ."</table>\n";
219
220
221 /** UNSUBSCRIBE FOLDERS **/
222 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
223 html_tag( 'tr',
224 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
225 ) .
226 html_tag( 'tr' ) .
227 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
228
229 if ($count_special_folders < count($boxes)) {
230 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
231 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
232 for ($i = 0; $i < count($boxes); $i++) {
233 $use_folder = true;
234 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
235 ($boxes[$i]["unformatted"] != $trash_folder) &&
236 ($boxes[$i]["unformatted"] != $sent_folder) &&
237 ($boxes[$i]["unformatted"] != $draft_folder)) {
238 $box = $boxes[$i]["unformatted-dm"];
239 $box2 = str_replace(' ', '&nbsp;',
240 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
241 echo " <OPTION VALUE=\"$box\">$box2\n";
242 }
243 }
244 echo "</SELECT></TT><br><br>\n"
245 . '<input type=SUBMIT VALUE="'
246 . _("Unsubscribe")
247 . "\">\n"
248 . "</FORM></td>\n";
249 } else {
250 echo _("No folders were found to unsubscribe from!") . '</td>';
251 }
252 $boxes_sub = $boxes;
253
254 /** SUBSCRIBE TO FOLDERS **/
255 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
256 if(!$no_list_for_subscribe) {
257 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
258
259 $box = '';
260 $box2 = '';
261 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
262 $use_folder = true;
263 for ($p = 0; $p < count ($boxes); $p++) {
264 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
265 $use_folder = false;
266 continue;
267 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
268 $use_folder = false;
269 }
270 }
271 if ($use_folder == true) {
272 $box[$q] = $boxes_all[$i]['unformatted-dm'];
273 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']);
274 $q++;
275 }
276 }
277 if ($box && $box2) {
278 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
279 . '<tt><select name="mailbox[]" multiple size=8>';
280
281 for ($q = 0; $q < count($box); $q++) {
282 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
283 }
284 echo '</select></tt><br><br>'
285 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
286 . "</FORM></td></tr></table><BR>\n";
287 } else {
288 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
289 }
290 } else {
291 /* don't perform the list action -- this is much faster */
292 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
293 . _("Subscribe to:") . '<br>'
294 . '<tt><input type="text" name="mailbox[]" size=35>'
295 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
296 . "</FORM></TD></TR></TABLE><BR>\n";
297 }
298
299 do_hook('folders_bottom');
300 ?>
301
302 </td></tr>
303 </table>
304
305 </td></tr>
306 </table>
307
308 <?php
309 sqimap_logout($imapConnection);
310 ?>
311
312 </body></html>