7 * deletes or moves currently displayed message and displays
8 * next or previous message.
10 * Copyright (c) 1999-2002 The SquirrelMail Project Team
11 * Licensed under the GNU GPL. For full terms see the file COPYING.
16 function squirrelmail_plugin_init_delete_move_next() {
17 global $squirrelmail_plugin_hooks;
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';
29 /* fixes the sort_array for the prev_del/next_del links when
30 * using server side sorting or thread sorting
33 function fix_sort_array () {
34 global $username, $data_dir, $allow_server_sort, $allow_thread_sort,
35 $mailbox, $imapConnection, $sort, $uid_support, $mbx_response;
37 case ($allow_thread_sort && $thread_sort_messages):
38 $server_sort_array = get_thread_sort($imapConnection);
40 case ($allow_server_sort):
41 $server_sort_array = sqimap_get_sort_order($imapConnection, $sort, $mbx_response);
44 $server_sort_array = sqimap_get_php_sort_order($imapConnecion, $mbx_response);
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]
60 function delete_move_del_arr_elem($arr, $index) {
64 for ($i = 0; $i < $lim; $i++
) {
66 $tmp[$j++
] = $arr[$i];
72 function delete_move_show_msg_array() {
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>';
82 function delete_move_expunge_from_all($id) {
83 global $msgs, $msort, $sort, $imapConnection, $mailbox;
85 // delete_move_show_msg_array();
87 for ($i = 0; $i < count($msort); $i++
) {
88 if ($msgs[$i]['ID'] == $id) {
90 } elseif ($msgs[$i]['ID'] > $id) {
97 $msgs = delete_move_del_arr_elem($msgs, $delAt);
98 $msort = delete_move_del_arr_elem($msort, $delAt);
108 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
111 function delete_move_next_action() {
114 $delete_id, $move_id;
117 delete_move_next_delete();
119 } elseif ($move_id) {
120 delete_move_next_move();
126 function delete_move_next_read_t() {
128 global $delete_move_next_t;
130 if($delete_move_next_t == 'on') {
131 delete_move_next_read('top');
135 function delete_move_next_read_b() {
137 global $delete_move_next_b;
139 if ($delete_move_next_b != 'off') {
140 delete_move_next_read('bottom');
145 function 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,
149 $imapConnection, $auto_expunge, $move_to_trash, $mbx_response,
152 if (!(($where && $what) ||
($currentArrayIndex == -1))) {
153 $next = findNextMessage();
154 $prev = findPreviousMessage($mbx_response['EXISTS']);
155 $prev_if_del = $prev;
156 $next_if_del = $next;
157 if (!$uid_support && ($auto_expunge ||
$move_to_trash)) {
158 if ($prev_if_del > $passed_id) {
161 if ($next_if_del > $passed_id) {
166 /* Base is illegal within documents
167 * $location = get_location();
168 * echo "<base href=\"$location/\">" . */
169 echo '<table cellspacing=0 width="100%" border=0 cellpadding=2>'.
171 "<td bgcolor=\"$color[9]\" width=\"100%\" align=center><small>";
174 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | \n";
176 echo _("Previous") . " | ";
179 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A> | \n";
181 echo _("Next") . " | ";
184 echo "<a href=\"read_body.php?passed_id=$prev_if_del&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0&delete_id=$passed_id\">" . _("Delete & Prev") . "</a>" . " | \n";
187 echo _("Delete & Prev") . " | ";
190 echo "<a href=\"read_body.php?passed_id=$next_if_del&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0&delete_id=$passed_id\">" . _("Delete & Next") . "</a>\n";
192 echo _("Delete & Next");
194 echo '</small></td></tr>';
196 if ($next_if_del < 0) {
197 $next_if_del = $prev_if_del;
199 if (($delete_move_next_formATtop == 'on') && ($currloc == 'top')){
200 if ($next_if_del > 0) {
201 delete_move_next_moveNextForm($next_if_del);
203 delete_move_next_moveRightMainForm();
206 if (($delete_move_next_formATbottom != 'off') && ($currloc == 'bottom')){
207 if ($next_if_del > 0) {
208 delete_move_next_moveNextForm($next_if_del);
210 delete_move_next_moveRightMainForm();
217 function get_move_target_list() {
218 global $imapConnection;
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(' ', ' ', $boxes[$i]['unformatted-disp']);
225 if ( $box2 == 'INBOX' ) {
228 echo "<option value=\"$box\">$box2</option>\n";
233 function delete_move_next_moveNextForm($next) {
235 global $color, $where, $what, $currentArrayIndex, $passed_id,
236 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
240 "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
241 '<form action="read_body.php" method="post"><small>'.
242 "<input type=\"hidden\" name=\"passed_id\" value=\"$next\">".
243 "<input type=\"hidden\" name=\"mailbox\" value=\"".urldecode($urlMailbox)."\">".
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\">".
249 ' <select name="targetMailbox">';
250 get_move_target_list();
252 '<input type="submit" value="' . _("Move") . '">'.
259 function delete_move_next_moveRightMainForm() {
261 global $color, $where, $what, $currentArrayIndex, $passed_id,
262 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
266 "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
267 '<form action="right_main.php" method="post"><small>' .
268 "<input type=\"hidden\" name=\"mailbox\" value=\"".urldecode($urlMailbox)."\">".
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\">".
273 ' <select name="targetMailbox">';
274 get_move_target_list();
276 '<input type=submit value="' . _("Move") . '">'.
285 function delete_move_next_delete() {
286 global $imapConnection, $delete_id, $mailbox, $auto_expunge;
288 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
290 delete_move_expunge_from_all($delete_id);
291 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
295 function delete_move_next_move() {
296 global $imapConnection, $move_id, $targetMailbox, $auto_expunge, $mailbox;
299 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
300 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted');
302 delete_move_expunge_from_all($move_id);
303 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
307 function 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;
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";
316 if ($delete_move_next_t == 'on') {
319 echo '> ' . _("Display at top").
320 " <input type=checkbox name=delete_move_next_formATtopi";
322 if ($delete_move_next_formATtop == 'on') {
325 echo '> ' . _("with move option") . '<br>';
327 echo '<input type=checkbox name=delete_move_next_bi';
328 if($delete_move_next_b != 'off') {
331 echo '> ' . _("Display at bottom") .
332 '<input type=checkbox name=delete_move_next_formATbottomi';
334 if ($delete_move_next_formATbottom != 'off') {
337 echo '> ' . _("with move option") . '<br>'.
341 function delete_move_next_display_save() {
343 global $username,$data_dir,
344 $delete_move_next_ti, $delete_move_next_formATtopi,
345 $delete_move_next_bi, $delete_move_next_formATbottomi;
347 if (isset($delete_move_next_ti)) {
348 setPref($data_dir, $username, 'delete_move_next_t', 'on');
350 setPref($data_dir, $username, 'delete_move_next_t', "off");
353 if (isset($delete_move_next_formATtopi)) {
354 setPref($data_dir, $username, 'delete_move_next_formATtop', 'on');
356 setPref($data_dir, $username, 'delete_move_next_formATtop', "off");
360 if (isset($delete_move_next_bi)) {
361 setPref($data_dir, $username, 'delete_move_next_b', 'on');
363 setPref($data_dir, $username, 'delete_move_next_b', "off");
366 if (isset($delete_move_next_formATbottomi)) {
367 setPref($data_dir, $username, 'delete_move_next_formATbottom', 'on');
369 setPref($data_dir, $username, 'delete_move_next_formATbottom', "off");
375 function 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;
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');