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