c8470e4143758d1719732651f7ef645c39884348
[squirrelmail.git] / plugins / delete_move_next / setup.php
1 <?php
2
3 /**
4 * setup.php
5 *
6 * delete_move_next
7 * deletes or moves currently displayed message and displays
8 * next or previous message.
9 *
10 * Copyright (c) 1999-2002 The SquirrelMail Project Team
11 * Licensed under the GNU GPL. For full terms see the file COPYING.
12 *
13 * $Id$
14 */
15
16 function squirrelmail_plugin_init_delete_move_next() {
17 global $squirrelmail_plugin_hooks;
18
19 $squirrelmail_plugin_hooks['html_top']['delete_move_next'] = 'delete_move_next_action';
20 $squirrelmail_plugin_hooks['right_main_after_header']['delete_move_next'] = 'delete_move_next_action';
21 $squirrelmail_plugin_hooks['read_body_bottom']['delete_move_next'] = 'delete_move_next_read_b';
22 $squirrelmail_plugin_hooks['read_body_top']['delete_move_next'] = 'delete_move_next_read_t';
23 $squirrelmail_plugin_hooks['options_display_inside']['delete_move_next'] = 'delete_move_next_display_inside';
24 $squirrelmail_plugin_hooks['options_display_save']['delete_move_next'] = 'delete_move_next_display_save';
25 $squirrelmail_plugin_hooks['loading_prefs']['delete_move_next'] = 'delete_move_next_loading_prefs';
26 }
27
28
29 /*
30 * Warning: this function relies on the internal representation of
31 * of the message cache for the current mailbox. As such, it is fragile
32 * because the underlying implementation can change. I will present it
33 * to the squirrelmail maintainers as a proposed addition to the API,
34 * perhaps even as inline code to sqimap_mailbox_expunge(). In the
35 * meantime, you have been warned. [alane@geeksrus.net 2001/05/06]
36 */
37 function delete_move_del_arr_elem($arr, $index) {
38 $tmp = array();
39 $lim = count($arr);
40 $j = 0;
41 for ($i = 0; $i < $lim; $i++) {
42 if ($i != $index) {
43 $tmp[$j++] = $arr[$i];
44 }
45 }
46 return $tmp;
47 }
48
49 function delete_move_show_msg_array() {
50 global $msort, $msgs;
51
52 $keys = array_keys($msort);
53 for ($i = 0; $i < count($keys); $i++) {
54 echo '<p>key ' . $keys[$i] . ' msgid ' . $msgs[$keys[$i]]['ID'] . '</p>';
55 }
56 }
57
58
59 function delete_move_expunge_from_all($id) {
60 global $msgs, $msort, $sort, $imapConnection, $mailbox;
61
62 // delete_move_show_msg_array();
63
64 $delAt = -1;
65 for ($i = 0; $i < count($msort); $i++) {
66 if ($msgs[$i]['ID'] == $id) {
67 $delAt = $i;
68 } elseif ($msgs[$i]['ID'] > $id) {
69 $msgs[$i]['ID']--;
70 }
71 }
72
73 $msgs = delete_move_del_arr_elem($msgs, $delAt);
74 $msort = delete_move_del_arr_elem($msort, $delAt);
75
76 if ($sort < 6) {
77 if ($sort % 2) {
78 asort($msort);
79 } else {
80 arsort($msort);
81 }
82 }
83
84 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
85 }
86
87 function delete_move_next_action() {
88
89 global $PHP_SELF,
90 $delete_id, $move_id;
91
92 if ($delete_id) {
93 delete_move_next_delete();
94 } elseif ($move_id) {
95 delete_move_next_move();
96 }
97
98 }
99
100 function delete_move_next_read_t() {
101
102 global $delete_move_next_t;
103
104 if($delete_move_next_t == 'on') {
105 delete_move_next_read('top');
106 }
107 }
108
109 function delete_move_next_read_b() {
110
111 global $delete_move_next_b;
112
113 if ($delete_move_next_b != 'off') {
114 delete_move_next_read('bottom');
115 }
116 }
117
118
119 function delete_move_next_read($currloc) {
120 global $delete_move_next_formATtop, $delete_move_next_formATbottom,
121 $color, $where, $what, $currentArrayIndex, $passed_id,
122 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
123 $imapConnection, $auto_expunge, $move_to_trash;
124
125 if (!(($where && $what) || ($currentArrayIndex == -1))) {
126
127 $next = findNextMessage();
128 $prev = findPreviousMessage();
129 $prev_if_del = $prev;
130 $next_if_del = $next;
131 if ($auto_expunge || $move_to_trash) {
132 if ($prev_if_del > $passed_id) {
133 $prev_if_del--;
134 }
135 if ($next_if_del > $passed_id) {
136 $next_if_del--;
137 }
138 }
139
140 /* Base is illegal within documents
141 * $location = get_location();
142 * echo "<base href=\"$location/\">" . */
143 echo '<table cellspacing=0 width="100%" border=0 cellpadding=2>'.
144 '<tr>'.
145 "<td bgcolor=\"$color[9]\" width=\"100%\" align=center><small>";
146
147 if ($prev > 0) {
148 echo "<a href=\"read_body.php?passed_id=$prev&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;\n";
149 } else {
150 echo _("Previous") . "&nbsp;|&nbsp;";
151 }
152 if ($next > 0) {
153 echo "<a href=\"read_body.php?passed_id=$next&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0\">" . _("Next") . "</A>&nbsp;|&nbsp;\n";
154 } else {
155 echo _("Next") . "&nbsp;|&nbsp;";
156 }
157 if ($prev > 0){
158 echo "<a href=\"read_body.php?passed_id=$prev_if_del&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0&amp;delete_id=$passed_id\">" . _("Delete & Prev") . "</a>" . "&nbsp;|&nbsp;\n";
159 }
160 else {
161 echo _("Delete & Prev") . "&nbsp;|&nbsp;";
162 }
163 if ($next > 0){
164 echo "<a href=\"read_body.php?passed_id=$next_if_del&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0&amp;delete_id=$passed_id\">" . _("Delete & Next") . "</a>\n";
165 } else {
166 echo _("Delete & Next");
167 }
168 echo '</small></td></tr>';
169
170 if ($next_if_del < 0) {
171 $next_if_del = $prev_if_del;
172 }
173 if (($delete_move_next_formATtop == 'on') && ($currloc == 'top')){
174 if ($next_if_del > 0) {
175 delete_move_next_moveNextForm($next_if_del);
176 } else {
177 delete_move_next_moveRightMainForm();
178 }
179 }
180 if (($delete_move_next_formATbottom != 'off') && ($currloc == 'bottom')){
181 if ($next_if_del > 0) {
182 delete_move_next_moveNextForm($next_if_del);
183 } else {
184 delete_move_next_moveRightMainForm();
185 }
186 }
187 echo '</table>';
188 }
189 }
190
191 function get_move_target_list() {
192 global $imapConnection;
193
194 $boxes = sqimap_mailbox_list($imapConnection);
195 for ($i = 0; $i < count($boxes); $i++) {
196 if (!in_array('noselect', $boxes[$i]['flags'])) {
197 $box = $boxes[$i]['unformatted'];
198 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
199 if ( $box2 == 'INBOX' ) {
200 $box2 = _("INBOX");
201 }
202 echo "<option value=\"$box\">$box2</option>\n";
203 }
204 }
205 }
206
207 function delete_move_next_moveNextForm($next) {
208
209 global $color, $where, $what, $currentArrayIndex, $passed_id,
210 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
211 $imapConnection;
212
213 echo '<tr>'.
214 "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
215 '<form action="read_body.php" method="post"><small>'.
216 "<input type=\"hidden\" name=\"passed_id\" value=\"$next\">".
217 "<input type=\"hidden\" name=\"mailbox\" value=\"$urlMailbox\">".
218 "<input type=\"hidden\" name=\"sort\" value=\"$sort\">".
219 "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">".
220 "<input type=\"hidden\" name=\"show_more\" value=\"0\">".
221 "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">".
222 _("Move to:") .
223 ' <select name="targetMailbox">';
224 get_move_target_list();
225 echo '</select> '.
226 '<input type="submit" value="' . _("Move") . '">'.
227 '</small>'.
228 '</form>'.
229 '</td>'.
230 '</tr>';
231
232 }
233 function delete_move_next_moveRightMainForm() {
234
235 global $color, $where, $what, $currentArrayIndex, $passed_id,
236 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
237 $imapConnection;
238
239 echo '<tr>' .
240 "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
241 '<form action="right_main.php" method="post"><small>' .
242 "<input type=\"hidden\" name=\"mailbox\" value=\"$urlMailbox\">".
243 "<input type=\"hidden\" name=\"sort\" value=\"$sort\">".
244 "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">".
245 "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">".
246 _("Move to:") .
247 ' <select name="targetMailbox">';
248 get_move_target_list();
249 echo ' </select>' .
250 '<input type=submit value="' . _("Move") . '">'.
251 '</small>'.
252 '</form>' .
253 '</td>'.
254 '</tr>';
255
256 }
257
258
259 function delete_move_next_delete() {
260 global $imapConnection, $delete_id, $mailbox, $auto_expunge;
261
262 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
263 if ($auto_expunge){
264 delete_move_expunge_from_all($delete_id);
265 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
266 }
267 }
268
269 function delete_move_next_move() {
270 global $imapConnection, $move_id, $targetMailbox, $auto_expunge, $mailbox;
271
272 // Move message
273 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
274 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted');
275 if ($auto_expunge) {
276 delete_move_expunge_from_all($move_id);
277 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
278 }
279 }
280
281 function delete_move_next_display_inside() {
282 global $username,$data_dir,
283 $delete_move_next_t, $delete_move_next_formATtop,
284 $delete_move_next_b, $delete_move_next_formATbottom;
285
286 echo "<tr><td align=right valign=top>\n".
287 _("delete_move_next:") . "</td>\n".
288 "<td><input type=checkbox name=delete_move_next_ti";
289
290 if ($delete_move_next_t == 'on') {
291 echo " checked";
292 }
293 echo '> <- ' . _("display at top").
294 " <input type=checkbox name=delete_move_next_formATtopi";
295
296 if ($delete_move_next_formATtop == 'on') {
297 echo ' checked';
298 }
299 echo '> <- ' . _("with move option") . '<br>';
300
301 echo '<input type=checkbox name=delete_move_next_bi';
302 if($delete_move_next_b != 'off') {
303 echo ' checked';
304 }
305 echo '> <- ' . _("display at bottom") .
306 '<input type=checkbox name=delete_move_next_formATbottomi';
307
308 if ($delete_move_next_formATbottom != 'off') {
309 echo ' checked';
310 }
311 echo '> <- ' . _("with move option") . '<br>'.
312 "</td></tr>\n";
313 }
314
315 function delete_move_next_display_save() {
316
317 global $username,$data_dir,
318 $delete_move_next_ti, $delete_move_next_formATtopi,
319 $delete_move_next_bi, $delete_move_next_formATbottomi;
320
321 if (isset($delete_move_next_ti)) {
322 setPref($data_dir, $username, 'delete_move_next_t', 'on');
323 } else {
324 setPref($data_dir, $username, 'delete_move_next_t', "off");
325 }
326
327 if (isset($delete_move_next_formATtopi)) {
328 setPref($data_dir, $username, 'delete_move_next_formATtop', 'on');
329 } else {
330 setPref($data_dir, $username, 'delete_move_next_formATtop', "off");
331 }
332
333
334 if (isset($delete_move_next_bi)) {
335 setPref($data_dir, $username, 'delete_move_next_b', 'on');
336 } else {
337 setPref($data_dir, $username, 'delete_move_next_b', "off");
338 }
339
340 if (isset($delete_move_next_formATbottomi)) {
341 setPref($data_dir, $username, 'delete_move_next_formATbottom', 'on');
342 } else {
343 setPref($data_dir, $username, 'delete_move_next_formATbottom', "off");
344 }
345
346 }
347
348
349 function delete_move_next_loading_prefs() {
350 global $username,$data_dir,
351 $delete_move_next_t, $delete_move_next_formATtop,
352 $delete_move_next_b, $delete_move_next_formATbottom;
353
354 $delete_move_next_t = getPref($data_dir, $username, 'delete_move_next_t');
355 $delete_move_next_b = getPref($data_dir, $username, 'delete_move_next_b');
356 $delete_move_next_formATtop = getPref($data_dir, $username, 'delete_move_next_formATtop');
357 $delete_move_next_formATbottom = getPref($data_dir, $username, 'delete_move_next_formATbottom');
358
359 }
360
361 ?>