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