added explicit include of global.php
[squirrelmail.git] / src / folders_delete.php
1 <?php
2
3 /**
4 * folders_delete.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 * Deletes folders from the IMAP server.
10 * Called from the folders.php
11 *
12 * $Id$
13 */
14
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/global.php');
21 require_once(SM_PATH . 'functions/imap.php');
22 require_once(SM_PATH . 'functions/tree.php');
23 require_once(SM_PATH . 'functions/display_messages.php');
24 require_once(SM_PATH . 'functions/html.php');
25
26 /*
27 * Incoming values:
28 * $mailbox - selected mailbox from the form
29 */
30
31 /* globals */
32 sqgetGlobalVar('key', $key, SQ_COOKIE);
33 sqgetGlobalVar('username', $username, SQ_SESSION);
34 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
35 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
36 sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
37 /* end globals */
38
39 if ($mailbox == '') {
40 displayPageHeader($color, 'None');
41
42 plain_error_message(_("You have not selected a folder to delete. Please do so.").
43 '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color);
44 exit;
45 }
46
47 if ( sqgetGlobalVar('backingout', $tmp, SQ_POST) ) {
48 $location = get_location();
49 header ("Location: $location/folders.php");
50 exit;
51 }
52
53 if( !sqgetGlobalVar('confirmed', $tmp, SQ_POST) ) {
54 displayPageHeader($color, 'None');
55
56 echo '<br>' .
57 html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
58 html_tag( 'tr',
59 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
60 ) .
61 html_tag( 'tr' ) .
62 html_tag( 'td', '', 'center', $color[4] ) .
63 sprintf(_("Are you sure you want to delete %s?"), imap_utf7_decode_local($mailbox)).
64 '<FORM ACTION="folders_delete.php" METHOD="POST"><p>'.
65
66 '<INPUT TYPE=HIDDEN NAME="mailbox" VALUE="'.$mailbox."\">\n" .
67 '<INPUT TYPE=SUBMIT NAME="confirmed" VALUE="'._("Yes")."\">\n".
68 '<INPUT TYPE=SUBMIT NAME="backingout" VALUE="'._("No")."\">\n".
69 '</p></FORM><BR></td></tr></table>';
70
71 exit;
72 }
73
74 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
75
76 $boxes = sqimap_mailbox_list ($imap_stream);
77 $numboxes = count($boxes);
78
79 global $delete_folder;
80
81 if (substr($mailbox, -1) == $delimiter)
82 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
83 else
84 $mailbox_no_dm = $mailbox;
85
86 /** lets see if we CAN move folders to the trash.. otherwise,
87 ** just delete them **/
88
89 /* Courier IMAP doesn't like subfolders of Trash
90 * If global options say we can't move it into Trash
91 * If it's already a subfolder of trash, we'll have to delete it */
92 if (strtolower($imap_server_type) == 'courier' ||
93 (isset($delete_folder) && $delete_folder) ||
94 eregi('^'.$trash_folder.'.+', $mailbox) )
95 {
96 $can_move_to_trash = FALSE;
97 }
98
99 /* Otherwise, check if trash folder exits and support sub-folders */
100 else {
101 for ($i = 0; $i < $numboxes; $i++) {
102 if ($boxes[$i]['unformatted'] == $trash_folder) {
103 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
104 }
105 }
106 }
107
108 /** First create the top node in the tree **/
109 for ($i = 0; $i < $numboxes; $i++) {
110 if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen($boxes[$i]['unformatted-dm']) == strlen($mailbox))) {
111 $foldersTree[0]['value'] = $mailbox;
112 $foldersTree[0]['doIHaveChildren'] = false;
113 continue;
114 }
115 }
116
117 /* Now create the nodes for subfolders of the parent folder
118 You can tell that it is a subfolder by tacking the mailbox delimiter
119 on the end of the $mailbox string, and compare to that. */
120 for ($i = 0; $i < $numboxes; $i++) {
121 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
122 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree);
123 }
124 }
125
126 /** Lets start removing the folders and messages **/
127 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
128 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
129 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
130 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
131 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
132 }
133
134 /** Log out this session **/
135 sqimap_logout($imap_stream);
136
137 $location = get_location();
138 header ("Location: $location/folders.php?success=delete");
139
140 ?>