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