r2l by Yoav
[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
91e5e252 29/* fixes the sort_array for the prev_del/next_del links when
30 * using server side sorting or thread sorting
31 */
32
33function 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 54function 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
66function 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
76function 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
104function 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
119function 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
128function 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
138function 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/\">" . */
7af2f95f 161 echo html_tag( 'table', '', '', '', 'cellspacing="0" width="100%" border="0" cellpadding="2"' ) .
162 html_tag( 'tr' ) .
163 html_tag( 'td', '', 'center', $color[9], 'width="100%"' ) .
164 '<small>';
7a46945e 165
166 if ($prev > 0) {
b9fb0634 167 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";
7a46945e 168 } else {
169 echo _("Previous") . "&nbsp;|&nbsp;";
170 }
171 if ($next > 0) {
b9fb0634 172 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";
7a46945e 173 } else {
174 echo _("Next") . "&nbsp;|&nbsp;";
175 }
176 if ($prev > 0){
b9fb0634 177 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";
7a46945e 178 }
179 else {
180 echo _("Delete & Prev") . "&nbsp;|&nbsp;";
181 }
182 if ($next > 0){
b9fb0634 183 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";
7a46945e 184 } else {
185 echo _("Delete & Next");
186 }
187 echo '</small></td></tr>';
188
189 if ($next_if_del < 0) {
190 $next_if_del = $prev_if_del;
191 }
192 if (($delete_move_next_formATtop == 'on') && ($currloc == 'top')){
193 if ($next_if_del > 0) {
194 delete_move_next_moveNextForm($next_if_del);
195 } else {
196 delete_move_next_moveRightMainForm();
197 }
198 }
199 if (($delete_move_next_formATbottom != 'off') && ($currloc == 'bottom')){
200 if ($next_if_del > 0) {
201 delete_move_next_moveNextForm($next_if_del);
202 } else {
203 delete_move_next_moveRightMainForm();
204 }
205 }
206 echo '</table>';
207 }
208}
209
210function get_move_target_list() {
211 global $imapConnection;
212
213 $boxes = sqimap_mailbox_list($imapConnection);
214 for ($i = 0; $i < count($boxes); $i++) {
215 if (!in_array('noselect', $boxes[$i]['flags'])) {
216 $box = $boxes[$i]['unformatted'];
217 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
4366bea4 218 if ( $box2 == 'INBOX' ) {
219 $box2 = _("INBOX");
220 }
221 echo "<option value=\"$box\">$box2</option>\n";
7a46945e 222 }
223 }
224}
225
226function delete_move_next_moveNextForm($next) {
227
228 global $color, $where, $what, $currentArrayIndex, $passed_id,
229 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
230 $imapConnection;
231
7af2f95f 232 echo html_tag( 'tr' ) .
233 html_tag( 'td', '', 'center', $color[9], 'width="100%"' ) .
b9fb0634 234 '<form action="read_body.php" method="post"><small>'.
4366bea4 235 "<input type=\"hidden\" name=\"passed_id\" value=\"$next\">".
4ec98852 236 "<input type=\"hidden\" name=\"mailbox\" value=\"".urldecode($urlMailbox)."\">".
4366bea4 237 "<input type=\"hidden\" name=\"sort\" value=\"$sort\">".
238 "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">".
239 "<input type=\"hidden\" name=\"show_more\" value=\"0\">".
240 "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">".
241 _("Move to:") .
242 ' <select name="targetMailbox">';
243 get_move_target_list();
244 echo '</select> '.
245 '<input type="submit" value="' . _("Move") . '">'.
246 '</small>'.
b9fb0634 247 '</form>'.
4366bea4 248 '</td>'.
b9fb0634 249 '</tr>';
7a46945e 250
251}
7a46945e 252function delete_move_next_moveRightMainForm() {
253
254 global $color, $where, $what, $currentArrayIndex, $passed_id,
255 $urlMailbox, $sort, $startMessage, $delete_id, $move_id,
256 $imapConnection;
257
7af2f95f 258 echo html_tag( 'tr' ) .
259 html_tag( 'td', '', 'center', $color[9], 'width="100%"' ) .
b9fb0634 260 '<form action="right_main.php" method="post"><small>' .
4ec98852 261 "<input type=\"hidden\" name=\"mailbox\" value=\"".urldecode($urlMailbox)."\">".
4366bea4 262 "<input type=\"hidden\" name=\"sort\" value=\"$sort\">".
263 "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">".
264 "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">".
265 _("Move to:") .
266 ' <select name="targetMailbox">';
267 get_move_target_list();
268 echo ' </select>' .
269 '<input type=submit value="' . _("Move") . '">'.
270 '</small>'.
b9fb0634 271 '</form>' .
4366bea4 272 '</td>'.
b9fb0634 273 '</tr>';
7a46945e 274
275}
276
277
278function delete_move_next_delete() {
279 global $imapConnection, $delete_id, $mailbox, $auto_expunge;
280
281 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
282 if ($auto_expunge){
283 delete_move_expunge_from_all($delete_id);
284 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
285 }
286}
287
288function delete_move_next_move() {
289 global $imapConnection, $move_id, $targetMailbox, $auto_expunge, $mailbox;
290
291 // Move message
292 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
293 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted');
294 if ($auto_expunge) {
295 delete_move_expunge_from_all($move_id);
296 // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
297 }
298}
299
300function delete_move_next_display_inside() {
301 global $username,$data_dir,
302 $delete_move_next_t, $delete_move_next_formATtop,
303 $delete_move_next_b, $delete_move_next_formATbottom;
304
7af2f95f 305 echo html_tag( 'tr' ) .
306 html_tag( 'td', _("Delete/Move/Next Buttons:"), 'right', '', 'valign="top"' ) . "\n" .
307 html_tag( 'td', '', 'left' ) .
308 '<input type=checkbox name=delete_move_next_ti';
7a46945e 309
310 if ($delete_move_next_t == 'on') {
311 echo " checked";
312 }
59b578d1 313 echo '> ' . _("Display at top").
7a46945e 314 " <input type=checkbox name=delete_move_next_formATtopi";
315
316 if ($delete_move_next_formATtop == 'on') {
317 echo ' checked';
318 }
59b578d1 319 echo '> ' . _("with move option") . '<br>';
7a46945e 320
321 echo '<input type=checkbox name=delete_move_next_bi';
322 if($delete_move_next_b != 'off') {
323 echo ' checked';
324 }
59b578d1 325 echo '> ' . _("Display at bottom") .
7a46945e 326 '<input type=checkbox name=delete_move_next_formATbottomi';
327
328 if ($delete_move_next_formATbottom != 'off') {
329 echo ' checked';
330 }
59b578d1 331 echo '> ' . _("with move option") . '<br>'.
7a46945e 332 "</td></tr>\n";
333}
334
335function delete_move_next_display_save() {
336
337 global $username,$data_dir,
338 $delete_move_next_ti, $delete_move_next_formATtopi,
339 $delete_move_next_bi, $delete_move_next_formATbottomi;
340
341 if (isset($delete_move_next_ti)) {
342 setPref($data_dir, $username, 'delete_move_next_t', 'on');
343 } else {
344 setPref($data_dir, $username, 'delete_move_next_t', "off");
345 }
346
347 if (isset($delete_move_next_formATtopi)) {
348 setPref($data_dir, $username, 'delete_move_next_formATtop', 'on');
349 } else {
350 setPref($data_dir, $username, 'delete_move_next_formATtop', "off");
351 }
352
353
354 if (isset($delete_move_next_bi)) {
355 setPref($data_dir, $username, 'delete_move_next_b', 'on');
356 } else {
357 setPref($data_dir, $username, 'delete_move_next_b', "off");
358 }
359
360 if (isset($delete_move_next_formATbottomi)) {
361 setPref($data_dir, $username, 'delete_move_next_formATbottom', 'on');
362 } else {
363 setPref($data_dir, $username, 'delete_move_next_formATbottom', "off");
364 }
365
366}
367
368
369function delete_move_next_loading_prefs() {
370 global $username,$data_dir,
371 $delete_move_next_t, $delete_move_next_formATtop,
372 $delete_move_next_b, $delete_move_next_formATbottom;
373
374 $delete_move_next_t = getPref($data_dir, $username, 'delete_move_next_t');
375 $delete_move_next_b = getPref($data_dir, $username, 'delete_move_next_b');
376 $delete_move_next_formATtop = getPref($data_dir, $username, 'delete_move_next_formATtop');
377 $delete_move_next_formATbottom = getPref($data_dir, $username, 'delete_move_next_formATbottom');
378
379}
380
b9fb0634 381?>