| 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 | sqsession_register($msgs, 'msgs'); |
| 105 | sqsession_register($msort, 'msort'); |
| 106 | |
| 107 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 108 | } |
| 109 | |
| 110 | function delete_move_next_action() { |
| 111 | |
| 112 | global $PHP_SELF; |
| 113 | |
| 114 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 115 | global $_GET, $_POST; |
| 116 | } |
| 117 | |
| 118 | if (isset($_GET['delete_id'])) { |
| 119 | $delete_id = $_GET['delete_id']; |
| 120 | } |
| 121 | if (isset($_POST['move_id'])) { |
| 122 | $move_id = $_POST['move_id']; |
| 123 | } |
| 124 | |
| 125 | if (isset($delete_id)) { |
| 126 | delete_move_next_delete(); |
| 127 | fix_sort_array(); |
| 128 | } elseif (isset($move_id)) { |
| 129 | delete_move_next_move(); |
| 130 | fix_sort_array(); |
| 131 | } |
| 132 | |
| 133 | } |
| 134 | |
| 135 | function delete_move_next_read_t() { |
| 136 | |
| 137 | global $delete_move_next_t; |
| 138 | |
| 139 | if($delete_move_next_t == 'on') { |
| 140 | delete_move_next_read('top'); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | function delete_move_next_read_b() { |
| 145 | |
| 146 | global $delete_move_next_b; |
| 147 | |
| 148 | if ($delete_move_next_b != 'off') { |
| 149 | delete_move_next_read('bottom'); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | |
| 154 | function delete_move_next_read($currloc) { |
| 155 | global $delete_move_next_formATtop, $delete_move_next_formATbottom, |
| 156 | $color, $where, $what, $currentArrayIndex, $passed_id, |
| 157 | $mailbox, $sort, $startMessage, $delete_id, $move_id, |
| 158 | $imapConnection, $auto_expunge, $move_to_trash, $mbx_response, |
| 159 | $uid_support; |
| 160 | |
| 161 | $urlMailbox = urlencode($mailbox); |
| 162 | |
| 163 | if (!(($where && $what) || ($currentArrayIndex == -1))) { |
| 164 | $next = findNextMessage($passed_id); |
| 165 | $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id); |
| 166 | $prev_if_del = $prev; |
| 167 | $next_if_del = $next; |
| 168 | if (!$uid_support && ($auto_expunge || $move_to_trash)) { |
| 169 | if ($prev_if_del > $passed_id) { |
| 170 | $prev_if_del--; |
| 171 | } |
| 172 | if ($next_if_del > $passed_id) { |
| 173 | $next_if_del--; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /* Base is illegal within documents |
| 178 | * $location = get_location(); |
| 179 | * echo "<base href=\"$location/\">" . */ |
| 180 | echo '<table cellspacing=0 width="100%" border=0 cellpadding=2>'. |
| 181 | '<tr>'. |
| 182 | "<td bgcolor=\"$color[9]\" width=\"100%\" align=center><small>"; |
| 183 | |
| 184 | // if ($prev > 0) { |
| 185 | // echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | \n"; |
| 186 | // } else { |
| 187 | // echo _("Previous") . " | "; |
| 188 | // } |
| 189 | // if ($next > 0) { |
| 190 | // echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A> | \n"; |
| 191 | // } else { |
| 192 | // echo _("Next") . " | "; |
| 193 | // } |
| 194 | if ($prev > 0){ |
| 195 | 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"; |
| 196 | } |
| 197 | else { |
| 198 | echo _("Delete & Prev") . " | "; |
| 199 | } |
| 200 | if ($next > 0){ |
| 201 | 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"; |
| 202 | } else { |
| 203 | echo _("Delete & Next"); |
| 204 | } |
| 205 | echo '</small></td></tr>'; |
| 206 | |
| 207 | if ($next_if_del < 0) { |
| 208 | $next_if_del = $prev_if_del; |
| 209 | } |
| 210 | if (($delete_move_next_formATtop == 'on') && ($currloc == 'top')){ |
| 211 | if ($next_if_del > 0) { |
| 212 | delete_move_next_moveNextForm($next_if_del); |
| 213 | } else { |
| 214 | delete_move_next_moveRightMainForm(); |
| 215 | } |
| 216 | } |
| 217 | if (($delete_move_next_formATbottom != 'off') && ($currloc == 'bottom')){ |
| 218 | if ($next_if_del > 0) { |
| 219 | delete_move_next_moveNextForm($next_if_del); |
| 220 | } else { |
| 221 | delete_move_next_moveRightMainForm(); |
| 222 | } |
| 223 | } |
| 224 | echo '</table>'; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | function get_move_target_list() { |
| 229 | global $imapConnection; |
| 230 | |
| 231 | $boxes = sqimap_mailbox_list($imapConnection); |
| 232 | for ($i = 0; $i < count($boxes); $i++) { |
| 233 | if (!in_array('noselect', $boxes[$i]['flags'])) { |
| 234 | $box = $boxes[$i]['unformatted']; |
| 235 | $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']); |
| 236 | if ( $box2 == 'INBOX' ) { |
| 237 | $box2 = _("INBOX"); |
| 238 | } |
| 239 | echo "<option value=\"$box\">$box2</option>\n"; |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | function delete_move_next_moveNextForm($next) { |
| 245 | |
| 246 | global $color, $where, $what, $currentArrayIndex, $passed_id, |
| 247 | $mailbox, $sort, $startMessage, $delete_id, $move_id, |
| 248 | $imapConnection; |
| 249 | |
| 250 | echo '<tr>'. |
| 251 | "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">". |
| 252 | '<form action="read_body.php" method="post"><small>'. |
| 253 | "<input type=\"hidden\" name=\"passed_id\" value=\"$next\">". |
| 254 | "<input type=\"hidden\" name=\"mailbox\" value=\"".$mailbox."\">". |
| 255 | "<input type=\"hidden\" name=\"sort\" value=\"$sort\">". |
| 256 | "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">". |
| 257 | "<input type=\"hidden\" name=\"show_more\" value=\"0\">". |
| 258 | "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">". |
| 259 | _("Move to:") . |
| 260 | ' <select name="targetMailbox">'; |
| 261 | get_move_target_list(); |
| 262 | echo '</select> '. |
| 263 | '<input type="submit" value="' . _("Move") . '">'. |
| 264 | '</small>'. |
| 265 | '</form>'. |
| 266 | '</td>'. |
| 267 | '</tr>'; |
| 268 | |
| 269 | } |
| 270 | function delete_move_next_moveRightMainForm() { |
| 271 | |
| 272 | global $color, $where, $what, $currentArrayIndex, $passed_id, |
| 273 | $mailbox, $sort, $startMessage, $delete_id, $move_id, |
| 274 | $imapConnection; |
| 275 | |
| 276 | echo '<tr>' . |
| 277 | "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">". |
| 278 | '<form action="right_main.php" method="post"><small>' . |
| 279 | "<input type=\"hidden\" name=\"mailbox\" value=\"".$mailbox."\">". |
| 280 | "<input type=\"hidden\" name=\"sort\" value=\"$sort\">". |
| 281 | "<input type=\"hidden\" name=\"startMessage\" value=\"$startMessage\">". |
| 282 | "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">". |
| 283 | _("Move to:") . |
| 284 | ' <select name="targetMailbox">'; |
| 285 | get_move_target_list(); |
| 286 | echo ' </select>' . |
| 287 | '<input type=submit value="' . _("Move") . '">'. |
| 288 | '</small>'. |
| 289 | '</form>' . |
| 290 | '</td>'. |
| 291 | '</tr>'; |
| 292 | |
| 293 | } |
| 294 | |
| 295 | |
| 296 | function delete_move_next_delete() { |
| 297 | global $imapConnection, $auto_expunge; |
| 298 | |
| 299 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 300 | global $_GET; |
| 301 | } |
| 302 | |
| 303 | $delete_id = $_GET['delete_id']; |
| 304 | $mailbox = $_GET['mailbox']; |
| 305 | |
| 306 | sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox); |
| 307 | if ($auto_expunge) { |
| 308 | delete_move_expunge_from_all($delete_id); |
| 309 | // sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | function delete_move_next_move() { |
| 314 | global $imapConnection, $mailbox; |
| 315 | |
| 316 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 317 | global $_POST; |
| 318 | } |
| 319 | |
| 320 | $move_id = $_POST['move_id']; |
| 321 | $mailbox = $_POST['mailbox']; |
| 322 | $targetMailbox = $_POST['targetMailbox']; |
| 323 | |
| 324 | // Move message |
| 325 | sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox); |
| 326 | sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true); |
| 327 | if ($auto_expunge) { |
| 328 | delete_move_expunge_from_all($move_id); |
| 329 | // sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | function delete_move_next_display_inside() { |
| 334 | global $username,$data_dir, |
| 335 | $delete_move_next_t, $delete_move_next_formATtop, |
| 336 | $delete_move_next_b, $delete_move_next_formATbottom; |
| 337 | |
| 338 | echo "<tr><td align=right valign=top>\n". |
| 339 | _("Delete/Move/Next Buttons:") . "</td>\n". |
| 340 | "<td><input type=checkbox name=delete_move_next_ti"; |
| 341 | |
| 342 | if ($delete_move_next_t == 'on') { |
| 343 | echo " checked"; |
| 344 | } |
| 345 | echo '> ' . _("Display at top"). |
| 346 | " <input type=checkbox name=delete_move_next_formATtopi"; |
| 347 | |
| 348 | if ($delete_move_next_formATtop == 'on') { |
| 349 | echo ' checked'; |
| 350 | } |
| 351 | echo '> ' . _("with move option") . '<br>'; |
| 352 | |
| 353 | echo '<input type=checkbox name=delete_move_next_bi'; |
| 354 | if($delete_move_next_b != 'off') { |
| 355 | echo ' checked'; |
| 356 | } |
| 357 | echo '> ' . _("Display at bottom") . |
| 358 | '<input type=checkbox name=delete_move_next_formATbottomi'; |
| 359 | |
| 360 | if ($delete_move_next_formATbottom != 'off') { |
| 361 | echo ' checked'; |
| 362 | } |
| 363 | echo '> ' . _("with move option") . '<br>'. |
| 364 | "</td></tr>\n"; |
| 365 | } |
| 366 | |
| 367 | function delete_move_next_display_save() { |
| 368 | |
| 369 | global $username,$data_dir; |
| 370 | |
| 371 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 372 | global $_POST; |
| 373 | } |
| 374 | |
| 375 | if (isset($_POST['delete_move_next_ti'])) { |
| 376 | $delete_move_next_ti = $_POST['delete_move_next_ti']; |
| 377 | } |
| 378 | if (isset($_POST['delete_move_next_bi'])) { |
| 379 | $delete_move_next_bi = $_POST['delete_move_next_bi']; |
| 380 | } |
| 381 | if (isset($_POST['delete_move_next_formATtopi'])) { |
| 382 | $delete_move_next_formATtopi = $_POST['delete_move_next_formATtopi']; |
| 383 | } |
| 384 | if (isset($_POST['delete_move_next_formATbottomi'])) { |
| 385 | $delete_move_next_formATbottomi = $_POST['delete_move_next_formATbottomi']; |
| 386 | } |
| 387 | |
| 388 | if (isset($delete_move_next_ti)) { |
| 389 | setPref($data_dir, $username, 'delete_move_next_t', 'on'); |
| 390 | } else { |
| 391 | setPref($data_dir, $username, 'delete_move_next_t', "off"); |
| 392 | } |
| 393 | |
| 394 | if (isset($delete_move_next_formATtopi)) { |
| 395 | setPref($data_dir, $username, 'delete_move_next_formATtop', 'on'); |
| 396 | } else { |
| 397 | setPref($data_dir, $username, 'delete_move_next_formATtop', "off"); |
| 398 | } |
| 399 | |
| 400 | |
| 401 | if (isset($delete_move_next_bi)) { |
| 402 | setPref($data_dir, $username, 'delete_move_next_b', 'on'); |
| 403 | } else { |
| 404 | setPref($data_dir, $username, 'delete_move_next_b', "off"); |
| 405 | } |
| 406 | |
| 407 | if (isset($delete_move_next_formATbottomi)) { |
| 408 | setPref($data_dir, $username, 'delete_move_next_formATbottom', 'on'); |
| 409 | } else { |
| 410 | setPref($data_dir, $username, 'delete_move_next_formATbottom', "off"); |
| 411 | } |
| 412 | |
| 413 | } |
| 414 | |
| 415 | |
| 416 | function delete_move_next_loading_prefs() { |
| 417 | global $username,$data_dir, |
| 418 | $delete_move_next_t, $delete_move_next_formATtop, |
| 419 | $delete_move_next_b, $delete_move_next_formATbottom; |
| 420 | |
| 421 | $delete_move_next_t = getPref($data_dir, $username, 'delete_move_next_t'); |
| 422 | $delete_move_next_b = getPref($data_dir, $username, 'delete_move_next_b'); |
| 423 | $delete_move_next_formATtop = getPref($data_dir, $username, 'delete_move_next_formATtop'); |
| 424 | $delete_move_next_formATbottom = getPref($data_dir, $username, 'delete_move_next_formATbottom'); |
| 425 | |
| 426 | } |
| 427 | |
| 428 | ?> |