| 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 | /* 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, $uid_support, $mbx_response; |
| 36 | switch (true) { |
| 37 | case ($allow_thread_sort && $thread_sort_messages): |
| 38 | $server_sort_array = get_thread_sort($imapConnection); |
| 39 | break; |
| 40 | case ($allow_server_sort): |
| 41 | $server_sort_array = sqimap_get_sort_order($imapConnection, $sort, $mbx_response); |
| 42 | break; |
| 43 | case ($uid_support): |
| 44 | $server_sort_array = sqimap_get_php_sort_order($imapConnecion, $mbx_response); |
| 45 | break; |
| 46 | default: |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * Warning: this function relies on the internal representation of |
| 53 | * of the message cache for the current mailbox. As such, it is fragile |
| 54 | * because the underlying implementation can change. I will present it |
| 55 | * to the squirrelmail maintainers as a proposed addition to the API, |
| 56 | * perhaps even as inline code to sqimap_mailbox_expunge(). In the |
| 57 | * meantime, you have been warned. [alane@geeksrus.net 2001/05/06] |
| 58 | */ |
| 59 | |
| 60 | function delete_move_del_arr_elem($arr, $index) { |
| 61 | $tmp = array(); |
| 62 | $lim = count($arr); |
| 63 | $j = 0; |
| 64 | for ($i = 0; $i < $lim; $i++) { |
| 65 | if ($i != $index) { |
| 66 | $tmp[$j++] = $arr[$i]; |
| 67 | } |
| 68 | } |
| 69 | return $tmp; |
| 70 | } |
| 71 | |
| 72 | function delete_move_show_msg_array() { |
| 73 | global $msort, $msgs; |
| 74 | |
| 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; |
| 84 | |
| 85 | // delete_move_show_msg_array(); |
| 86 | $delAt = -1; |
| 87 | for ($i = 0; $i < count($msort); $i++) { |
| 88 | if ($msgs[$i]['ID'] == $id) { |
| 89 | $delAt = $i; |
| 90 | } elseif ($msgs[$i]['ID'] > $id) { |
| 91 | if (!$uid_support) { |
| 92 | $msgs[$i]['ID']--; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | $msgs = delete_move_del_arr_elem($msgs, $delAt); |
| 98 | $msort = delete_move_del_arr_elem($msort, $delAt); |
| 99 | |
| 100 | if ($sort < 6) { |
| 101 | if ($sort % 2) { |
| 102 | asort($msort); |
| 103 | } else { |
| 104 | arsort($msort); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 109 | } |
| 110 | |
| 111 | function delete_move_next_action() { |
| 112 | |
| 113 | global $PHP_SELF, |
| 114 | $delete_id, $move_id; |
| 115 | |
| 116 | if ($delete_id) { |
| 117 | delete_move_next_delete(); |
| 118 | fix_sort_array(); |
| 119 | } elseif ($move_id) { |
| 120 | delete_move_next_move(); |
| 121 | fix_sort_array(); |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | function delete_move_next_read_t() { |
| 127 | |
| 128 | global $delete_move_next_t; |
| 129 | |
| 130 | if($delete_move_next_t == 'on') { |
| 131 | delete_move_next_read('top'); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | function delete_move_next_read_b() { |
| 136 | |
| 137 | global $delete_move_next_b; |
| 138 | |
| 139 | if ($delete_move_next_b != 'off') { |
| 140 | delete_move_next_read('bottom'); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | |
| 145 | function delete_move_next_read($currloc) { |
| 146 | global $delete_move_next_formATtop, $delete_move_next_formATbottom, |
| 147 | $color, $where, $what, $currentArrayIndex, $passed_id, |
| 148 | $urlMailbox, $sort, $startMessage, $delete_id, $move_id, |
| 149 | $imapConnection, $auto_expunge, $move_to_trash, $mbx_response, |
| 150 | $uid_support; |
| 151 | |
| 152 | if (!(($where && $what) || ($currentArrayIndex == -1))) { |
| 153 | $next = findNextMessage(); |
| 154 | $prev = findPreviousMessage($mbx_response['EXISTS']); |
| 155 | $prev_if_del = $prev; |
| 156 | $next_if_del = $next; |
| 157 | if (!$uid_support && ($auto_expunge || $move_to_trash)) { |
| 158 | if ($prev_if_del > $passed_id) { |
| 159 | $prev_if_del--; |
| 160 | } |
| 161 | if ($next_if_del > $passed_id) { |
| 162 | $next_if_del--; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /* Base is illegal within documents |
| 167 | * $location = get_location(); |
| 168 | * echo "<base href=\"$location/\">" . */ |
| 169 | echo '<table cellspacing=0 width="100%" border=0 cellpadding=2>'. |
| 170 | '<tr>'. |
| 171 | "<td bgcolor=\"$color[9]\" width=\"100%\" align=center><small>"; |
| 172 | |
| 173 | if ($prev > 0) { |
| 174 | echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | \n"; |
| 175 | } else { |
| 176 | echo _("Previous") . " | "; |
| 177 | } |
| 178 | if ($next > 0) { |
| 179 | echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A> | \n"; |
| 180 | } else { |
| 181 | echo _("Next") . " | "; |
| 182 | } |
| 183 | if ($prev > 0){ |
| 184 | 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"; |
| 185 | } |
| 186 | else { |
| 187 | echo _("Delete & Prev") . " | "; |
| 188 | } |
| 189 | if ($next > 0){ |
| 190 | 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"; |
| 191 | } else { |
| 192 | echo _("Delete & Next"); |
| 193 | } |
| 194 | echo '</small></td></tr>'; |
| 195 | |
| 196 | if ($next_if_del < 0) { |
| 197 | $next_if_del = $prev_if_del; |
| 198 | } |
| 199 | if (($delete_move_next_formATtop == 'on') && ($currloc == 'top')){ |
| 200 | if ($next_if_del > 0) { |
| 201 | delete_move_next_moveNextForm($next_if_del); |
| 202 | } else { |
| 203 | delete_move_next_moveRightMainForm(); |
| 204 | } |
| 205 | } |
| 206 | if (($delete_move_next_formATbottom != 'off') && ($currloc == 'bottom')){ |
| 207 | if ($next_if_del > 0) { |
| 208 | delete_move_next_moveNextForm($next_if_del); |
| 209 | } else { |
| 210 | delete_move_next_moveRightMainForm(); |
| 211 | } |
| 212 | } |
| 213 | echo '</table>'; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | function get_move_target_list() { |
| 218 | global $imapConnection; |
| 219 | |
| 220 | $boxes = sqimap_mailbox_list($imapConnection); |
| 221 | for ($i = 0; $i < count($boxes); $i++) { |
| 222 | if (!in_array('noselect', $boxes[$i]['flags'])) { |
| 223 | $box = $boxes[$i]['unformatted']; |
| 224 | $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']); |
| 225 | if ( $box2 == 'INBOX' ) { |
| 226 | $box2 = _("INBOX"); |
| 227 | } |
| 228 | echo "<option value=\"$box\">$box2</option>\n"; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | function delete_move_next_moveNextForm($next) { |
| 234 | |
| 235 | global $color, $where, $what, $currentArrayIndex, $passed_id, |
| 236 | $urlMailbox, $sort, $startMessage, $delete_id, $move_id, |
| 237 | $imapConnection; |
| 238 | |
| 239 | echo '<tr>'. |
| 240 | "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">". |
| 241 | '<form action="read_body.php" method="post"><small>'. |
| 242 | "<input type=\"hidden\" name=\"passed_id\" value=\"$next\">". |
| 243 | "<input type=\"hidden\" name=\"mailbox\" value=\"".urldecode($urlMailbox)."\">". |
| 244 | "<input type=\"hidden\" name=\"sort\" value=\"$sort\">". |
| 245 | "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">". |
| 246 | "<input type=\"hidden\" name=\"show_more\" value=\"0\">". |
| 247 | "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">". |
| 248 | _("Move to:") . |
| 249 | ' <select name="targetMailbox">'; |
| 250 | get_move_target_list(); |
| 251 | echo '</select> '. |
| 252 | '<input type="submit" value="' . _("Move") . '">'. |
| 253 | '</small>'. |
| 254 | '</form>'. |
| 255 | '</td>'. |
| 256 | '</tr>'; |
| 257 | |
| 258 | } |
| 259 | function delete_move_next_moveRightMainForm() { |
| 260 | |
| 261 | global $color, $where, $what, $currentArrayIndex, $passed_id, |
| 262 | $urlMailbox, $sort, $startMessage, $delete_id, $move_id, |
| 263 | $imapConnection; |
| 264 | |
| 265 | echo '<tr>' . |
| 266 | "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">". |
| 267 | '<form action="right_main.php" method="post"><small>' . |
| 268 | "<input type=\"hidden\" name=\"mailbox\" value=\"".urldecode($urlMailbox)."\">". |
| 269 | "<input type=\"hidden\" name=\"sort\" value=\"$sort\">". |
| 270 | "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">". |
| 271 | "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">". |
| 272 | _("Move to:") . |
| 273 | ' <select name="targetMailbox">'; |
| 274 | get_move_target_list(); |
| 275 | echo ' </select>' . |
| 276 | '<input type=submit value="' . _("Move") . '">'. |
| 277 | '</small>'. |
| 278 | '</form>' . |
| 279 | '</td>'. |
| 280 | '</tr>'; |
| 281 | |
| 282 | } |
| 283 | |
| 284 | |
| 285 | function delete_move_next_delete() { |
| 286 | global $imapConnection, $delete_id, $mailbox, $auto_expunge; |
| 287 | |
| 288 | sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox); |
| 289 | if ($auto_expunge){ |
| 290 | delete_move_expunge_from_all($delete_id); |
| 291 | // sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | function delete_move_next_move() { |
| 296 | global $imapConnection, $move_id, $targetMailbox, $auto_expunge, $mailbox; |
| 297 | |
| 298 | // Move message |
| 299 | sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox); |
| 300 | sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted'); |
| 301 | if ($auto_expunge) { |
| 302 | delete_move_expunge_from_all($move_id); |
| 303 | // sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | function delete_move_next_display_inside() { |
| 308 | global $username,$data_dir, |
| 309 | $delete_move_next_t, $delete_move_next_formATtop, |
| 310 | $delete_move_next_b, $delete_move_next_formATbottom; |
| 311 | |
| 312 | echo "<tr><td align=right valign=top>\n". |
| 313 | _("Delete/Move/Next Buttons:") . "</td>\n". |
| 314 | "<td><input type=checkbox name=delete_move_next_ti"; |
| 315 | |
| 316 | if ($delete_move_next_t == 'on') { |
| 317 | echo " checked"; |
| 318 | } |
| 319 | echo '> ' . _("Display at top"). |
| 320 | " <input type=checkbox name=delete_move_next_formATtopi"; |
| 321 | |
| 322 | if ($delete_move_next_formATtop == 'on') { |
| 323 | echo ' checked'; |
| 324 | } |
| 325 | echo '> ' . _("with move option") . '<br>'; |
| 326 | |
| 327 | echo '<input type=checkbox name=delete_move_next_bi'; |
| 328 | if($delete_move_next_b != 'off') { |
| 329 | echo ' checked'; |
| 330 | } |
| 331 | echo '> ' . _("Display at bottom") . |
| 332 | '<input type=checkbox name=delete_move_next_formATbottomi'; |
| 333 | |
| 334 | if ($delete_move_next_formATbottom != 'off') { |
| 335 | echo ' checked'; |
| 336 | } |
| 337 | echo '> ' . _("with move option") . '<br>'. |
| 338 | "</td></tr>\n"; |
| 339 | } |
| 340 | |
| 341 | function delete_move_next_display_save() { |
| 342 | |
| 343 | global $username,$data_dir, |
| 344 | $delete_move_next_ti, $delete_move_next_formATtopi, |
| 345 | $delete_move_next_bi, $delete_move_next_formATbottomi; |
| 346 | |
| 347 | if (isset($delete_move_next_ti)) { |
| 348 | setPref($data_dir, $username, 'delete_move_next_t', 'on'); |
| 349 | } else { |
| 350 | setPref($data_dir, $username, 'delete_move_next_t', "off"); |
| 351 | } |
| 352 | |
| 353 | if (isset($delete_move_next_formATtopi)) { |
| 354 | setPref($data_dir, $username, 'delete_move_next_formATtop', 'on'); |
| 355 | } else { |
| 356 | setPref($data_dir, $username, 'delete_move_next_formATtop', "off"); |
| 357 | } |
| 358 | |
| 359 | |
| 360 | if (isset($delete_move_next_bi)) { |
| 361 | setPref($data_dir, $username, 'delete_move_next_b', 'on'); |
| 362 | } else { |
| 363 | setPref($data_dir, $username, 'delete_move_next_b', "off"); |
| 364 | } |
| 365 | |
| 366 | if (isset($delete_move_next_formATbottomi)) { |
| 367 | setPref($data_dir, $username, 'delete_move_next_formATbottom', 'on'); |
| 368 | } else { |
| 369 | setPref($data_dir, $username, 'delete_move_next_formATbottom', "off"); |
| 370 | } |
| 371 | |
| 372 | } |
| 373 | |
| 374 | |
| 375 | function delete_move_next_loading_prefs() { |
| 376 | global $username,$data_dir, |
| 377 | $delete_move_next_t, $delete_move_next_formATtop, |
| 378 | $delete_move_next_b, $delete_move_next_formATbottom; |
| 379 | |
| 380 | $delete_move_next_t = getPref($data_dir, $username, 'delete_move_next_t'); |
| 381 | $delete_move_next_b = getPref($data_dir, $username, 'delete_move_next_b'); |
| 382 | $delete_move_next_formATtop = getPref($data_dir, $username, 'delete_move_next_formATtop'); |
| 383 | $delete_move_next_formATbottom = getPref($data_dir, $username, 'delete_move_next_formATbottom'); |
| 384 | |
| 385 | } |
| 386 | |
| 387 | ?> |