Masato's Fix
[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_menu_bottom']['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 /* 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 $thread_sort_messages,
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);
40 break;
41 case ($allow_server_sort):
42 $server_sort_array = sqimap_get_sort_order($imapConnection, $sort, $mbx_response);
43 break;
44 case ($uid_support):
45 $server_sort_array = sqimap_get_php_sort_order($imapConnecion, $mbx_response);
46 break;
47 default:
48 break;
49 }
50 }
51
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 */
60
61 function delete_move_del_arr_elem($arr, $index) {
62 $tmp = array();
63 $j = 0;
64 foreach ($arr as $v) {
65 if ($j != $index) {
66 $tmp[] = $v;
67 }
68 $j++;
69 }
70 return $tmp;
71 }
72
73 function delete_move_show_msg_array() {
74 global $msort, $msgs;
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
82 function delete_move_expunge_from_all($id) {
83 global $msgs, $msort, $sort, $imapConnection, $mailbox, $uid_support;
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) {
89 if (!$uid_support) {
90 $msgs[$i]['ID']--;
91 }
92 }
93 }
94
95 $msgs = delete_move_del_arr_elem($msgs, $delAt);
96 $msort = delete_move_del_arr_elem($msort, $delAt);
97 if ($sort < 6) {
98 if ($sort % 2) {
99 asort($msort);
100 } else {
101 arsort($msort);
102 }
103 }
104 session_register('msgs');
105 session_register('msort');
106
107 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
108 }
109
110 function delete_move_next_action() {
111
112 global $PHP_SELF,
113 $delete_id, $move_id;
114
115 if ($delete_id) {
116 delete_move_next_delete();
117 fix_sort_array();
118 } elseif ($move_id) {
119 delete_move_next_move();
120 fix_sort_array();
121 }
122
123 }
124
125 function 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
134 function 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
144 function delete_move_next_read($currloc) {
145 global $delete_move_next_formATtop, $delete_move_next_formATbottom,
146 $color, $where, $what, $currentArrayIndex, $passed_id,
147 $mailbox, $sort, $startMessage, $delete_id, $move_id,
148 $imapConnection, $auto_expunge, $move_to_trash, $mbx_response,
149 $uid_support;
150
151 $urlMailbox = urlencode($mailbox);
152
153 if (!(($where && $what) || ($currentArrayIndex == -1))) {
154 $next = findNextMessage($passed_id);
155 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
156 $prev_if_del = $prev;
157 $next_if_del = $next;
158 if (!$uid_support && ($auto_expunge || $move_to_trash)) {
159 if ($prev_if_del > $passed_id) {
160 $prev_if_del--;
161 }
162 if ($next_if_del > $passed_id) {
163 $next_if_del--;
164 }
165 }
166
167 /* Base is illegal within documents
168 * $location = get_location();
169 * echo "<base href=\"$location/\">" . */
170 echo '<table cellspacing=0 width="100%" border=0 cellpadding=2>'.
171 '<tr>'.
172 "<td bgcolor=\"$color[9]\" width=\"100%\" align=center><small>";
173
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 // }
184 if ($prev > 0){
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";
186 }
187 else {
188 echo _("Delete & Prev") . "&nbsp;|&nbsp;";
189 }
190 if ($next > 0){
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";
192 } else {
193 echo _("Delete & Next");
194 }
195 echo '</small></td></tr>';
196
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
218 function get_move_target_list() {
219 global $imapConnection;
220
221 $boxes = sqimap_mailbox_list($imapConnection);
222 for ($i = 0; $i < count($boxes); $i++) {
223 if (!in_array('noselect', $boxes[$i]['flags'])) {
224 $box = $boxes[$i]['unformatted'];
225 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
226 if ( $box2 == 'INBOX' ) {
227 $box2 = _("INBOX");
228 }
229 echo "<option value=\"$box\">$box2</option>\n";
230 }
231 }
232 }
233
234 function delete_move_next_moveNextForm($next) {
235
236 global $color, $where, $what, $currentArrayIndex, $passed_id,
237 $mailbox, $sort, $startMessage, $delete_id, $move_id,
238 $imapConnection;
239
240 echo '<tr>'.
241 "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
242 '<form action="read_body.php" method="post"><small>'.
243 "<input type=\"hidden\" name=\"passed_id\" value=\"$next\">".
244 "<input type=\"hidden\" name=\"mailbox\" value=\"".$mailbox."\">".
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>'.
255 '</form>'.
256 '</td>'.
257 '</tr>';
258
259 }
260 function delete_move_next_moveRightMainForm() {
261
262 global $color, $where, $what, $currentArrayIndex, $passed_id,
263 $mailbox, $sort, $startMessage, $delete_id, $move_id,
264 $imapConnection;
265
266 echo '<tr>' .
267 "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
268 '<form action="right_main.php" method="post"><small>' .
269 "<input type=\"hidden\" name=\"mailbox\" value=\"".$mailbox."\">".
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>'.
279 '</form>' .
280 '</td>'.
281 '</tr>';
282
283 }
284
285
286 function delete_move_next_delete() {
287 global $imapConnection, $delete_id, $mailbox, $auto_expunge;
288
289 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
290 if ($auto_expunge) {
291 delete_move_expunge_from_all($delete_id);
292 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
293 }
294 }
295
296 function delete_move_next_move() {
297 global $imapConnection, $move_id, $targetMailbox, $auto_expunge, $mailbox;
298
299 // Move message
300 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
301 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true);
302 if ($auto_expunge) {
303 delete_move_expunge_from_all($move_id);
304 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
305 }
306 }
307
308 function 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;
312
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";
316
317 if ($delete_move_next_t == 'on') {
318 echo " checked";
319 }
320 echo '> ' . _("Display at top").
321 " <input type=checkbox name=delete_move_next_formATtopi";
322
323 if ($delete_move_next_formATtop == 'on') {
324 echo ' checked';
325 }
326 echo '> ' . _("with move option") . '<br>';
327
328 echo '<input type=checkbox name=delete_move_next_bi';
329 if($delete_move_next_b != 'off') {
330 echo ' checked';
331 }
332 echo '> ' . _("Display at bottom") .
333 '<input type=checkbox name=delete_move_next_formATbottomi';
334
335 if ($delete_move_next_formATbottom != 'off') {
336 echo ' checked';
337 }
338 echo '> ' . _("with move option") . '<br>'.
339 "</td></tr>\n";
340 }
341
342 function 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;
347
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 }
353
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 }
359
360
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 }
366
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
376 function 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;
380
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
388 ?>