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