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