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