01cb56a2f9ac8225d9a78c0b66fba5bf7c92acb2
[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, $server_sort_array,
124 $allow_thread_sort, $allow_server_sort, $thread_sort_messages;
125
126 if (!(($where && $what) || ($currentArrayIndex == -1))) {
127 if ($allow_server_sort == true) {
128 $server_sort_array = sqimap_get_sort_order($imapConnection, $sort);
129 }
130 if ($allow_thread_sort == true && $thread_sort_messages == 1) {
131 $server_sort_array = get_thread_sort($imapConnection);
132 }
133 $next = findNextMessage();
134 $prev = findPreviousMessage();
135 $prev_if_del = $prev;
136 $next_if_del = $next;
137 if ($auto_expunge || $move_to_trash) {
138 if ($prev_if_del > $passed_id) {
139 $prev_if_del--;
140 }
141 if ($next_if_del > $passed_id) {
142 $next_if_del--;
143 }
144 }
145
146 /* Base is illegal within documents
147 * $location = get_location();
148 * echo "<base href=\"$location/\">" . */
149 echo '<table cellspacing=0 width="100%" border=0 cellpadding=2>'.
150 '<tr>'.
151 "<td bgcolor=\"$color[9]\" width=\"100%\" align=center><small>";
152
153 if ($prev > 0) {
154 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";
155 } else {
156 echo _("Previous") . "&nbsp;|&nbsp;";
157 }
158 if ($next > 0) {
159 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";
160 } else {
161 echo _("Next") . "&nbsp;|&nbsp;";
162 }
163 if ($prev > 0){
164 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";
165 }
166 else {
167 echo _("Delete & Prev") . "&nbsp;|&nbsp;";
168 }
169 if ($next > 0){
170 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";
171 } else {
172 echo _("Delete & Next");
173 }
174 echo '</small></td></tr>';
175
176 if ($next_if_del < 0) {
177 $next_if_del = $prev_if_del;
178 }
179 if (($delete_move_next_formATtop == 'on') && ($currloc == 'top')){
180 if ($next_if_del > 0) {
181 delete_move_next_moveNextForm($next_if_del);
182 } else {
183 delete_move_next_moveRightMainForm();
184 }
185 }
186 if (($delete_move_next_formATbottom != 'off') && ($currloc == 'bottom')){
187 if ($next_if_del > 0) {
188 delete_move_next_moveNextForm($next_if_del);
189 } else {
190 delete_move_next_moveRightMainForm();
191 }
192 }
193 echo '</table>';
194 }
195 }
196
197 function get_move_target_list() {
198 global $imapConnection;
199
200 $boxes = sqimap_mailbox_list($imapConnection);
201 for ($i = 0; $i < count($boxes); $i++) {
202 if (!in_array('noselect', $boxes[$i]['flags'])) {
203 $box = $boxes[$i]['unformatted'];
204 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
205 if ( $box2 == 'INBOX' ) {
206 $box2 = _("INBOX");
207 }
208 echo "<option value=\"$box\">$box2</option>\n";
209 }
210 }
211 }
212
213 function delete_move_next_moveNextForm($next) {
214
215 global $color, $where, $what, $currentArrayIndex, $passed_id,
216 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
217 $imapConnection;
218
219 echo '<tr>'.
220 "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
221 '<form action="read_body.php" method="post"><small>'.
222 "<input type=\"hidden\" name=\"passed_id\" value=\"$next\">".
223 "<input type=\"hidden\" name=\"mailbox\" value=\"$urlMailbox\">".
224 "<input type=\"hidden\" name=\"sort\" value=\"$sort\">".
225 "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">".
226 "<input type=\"hidden\" name=\"show_more\" value=\"0\">".
227 "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">".
228 _("Move to:") .
229 ' <select name="targetMailbox">';
230 get_move_target_list();
231 echo '</select> '.
232 '<input type="submit" value="' . _("Move") . '">'.
233 '</small>'.
234 '</form>'.
235 '</td>'.
236 '</tr>';
237
238 }
239 function delete_move_next_moveRightMainForm() {
240
241 global $color, $where, $what, $currentArrayIndex, $passed_id,
242 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
243 $imapConnection;
244
245 echo '<tr>' .
246 "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
247 '<form action="right_main.php" method="post"><small>' .
248 "<input type=\"hidden\" name=\"mailbox\" value=\"$urlMailbox\">".
249 "<input type=\"hidden\" name=\"sort\" value=\"$sort\">".
250 "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">".
251 "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">".
252 _("Move to:") .
253 ' <select name="targetMailbox">';
254 get_move_target_list();
255 echo ' </select>' .
256 '<input type=submit value="' . _("Move") . '">'.
257 '</small>'.
258 '</form>' .
259 '</td>'.
260 '</tr>';
261
262 }
263
264
265 function delete_move_next_delete() {
266 global $imapConnection, $delete_id, $mailbox, $auto_expunge;
267
268 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
269 if ($auto_expunge){
270 delete_move_expunge_from_all($delete_id);
271 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
272 }
273 }
274
275 function delete_move_next_move() {
276 global $imapConnection, $move_id, $targetMailbox, $auto_expunge, $mailbox;
277
278 // Move message
279 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
280 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted');
281 if ($auto_expunge) {
282 delete_move_expunge_from_all($move_id);
283 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
284 }
285 }
286
287 function delete_move_next_display_inside() {
288 global $username,$data_dir,
289 $delete_move_next_t, $delete_move_next_formATtop,
290 $delete_move_next_b, $delete_move_next_formATbottom;
291
292 echo "<tr><td align=right valign=top>\n".
293 _("Delete/Move/Next Buttons:") . "</td>\n".
294 "<td><input type=checkbox name=delete_move_next_ti";
295
296 if ($delete_move_next_t == 'on') {
297 echo " checked";
298 }
299 echo '> ' . _("Display at top").
300 " <input type=checkbox name=delete_move_next_formATtopi";
301
302 if ($delete_move_next_formATtop == 'on') {
303 echo ' checked';
304 }
305 echo '> ' . _("with move option") . '<br>';
306
307 echo '<input type=checkbox name=delete_move_next_bi';
308 if($delete_move_next_b != 'off') {
309 echo ' checked';
310 }
311 echo '> ' . _("Display at bottom") .
312 '<input type=checkbox name=delete_move_next_formATbottomi';
313
314 if ($delete_move_next_formATbottom != 'off') {
315 echo ' checked';
316 }
317 echo '> ' . _("with move option") . '<br>'.
318 "</td></tr>\n";
319 }
320
321 function delete_move_next_display_save() {
322
323 global $username,$data_dir,
324 $delete_move_next_ti, $delete_move_next_formATtopi,
325 $delete_move_next_bi, $delete_move_next_formATbottomi;
326
327 if (isset($delete_move_next_ti)) {
328 setPref($data_dir, $username, 'delete_move_next_t', 'on');
329 } else {
330 setPref($data_dir, $username, 'delete_move_next_t', "off");
331 }
332
333 if (isset($delete_move_next_formATtopi)) {
334 setPref($data_dir, $username, 'delete_move_next_formATtop', 'on');
335 } else {
336 setPref($data_dir, $username, 'delete_move_next_formATtop', "off");
337 }
338
339
340 if (isset($delete_move_next_bi)) {
341 setPref($data_dir, $username, 'delete_move_next_b', 'on');
342 } else {
343 setPref($data_dir, $username, 'delete_move_next_b', "off");
344 }
345
346 if (isset($delete_move_next_formATbottomi)) {
347 setPref($data_dir, $username, 'delete_move_next_formATbottom', 'on');
348 } else {
349 setPref($data_dir, $username, 'delete_move_next_formATbottom', "off");
350 }
351
352 }
353
354
355 function delete_move_next_loading_prefs() {
356 global $username,$data_dir,
357 $delete_move_next_t, $delete_move_next_formATtop,
358 $delete_move_next_b, $delete_move_next_formATbottom;
359
360 $delete_move_next_t = getPref($data_dir, $username, 'delete_move_next_t');
361 $delete_move_next_b = getPref($data_dir, $username, 'delete_move_next_b');
362 $delete_move_next_formATtop = getPref($data_dir, $username, 'delete_move_next_formATtop');
363 $delete_move_next_formATbottom = getPref($data_dir, $username, 'delete_move_next_formATbottom');
364
365 }
366
367 ?>