[ Index ] |
PHP Cross Reference of phpBB 3.0 Beta 3 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @package mcp 5 * @version $Id: mcp_main.php,v 1.44 2006/10/11 20:37:53 grahamje Exp $ 6 * @copyright (c) 2005 phpBB Group 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 8 * 9 */ 10 11 /** 12 * mcp_main 13 * Handling mcp actions 14 * @package mcp 15 */ 16 class mcp_main 17 { 18 var $p_master; 19 var $u_action; 20 21 function mcp_main(&$p_master) 22 { 23 $this->p_master = &$p_master; 24 } 25 26 function main($id, $mode) 27 { 28 global $auth, $db, $user, $template, $action; 29 global $config, $phpbb_root_path, $phpEx; 30 31 $quickmod = ($mode == 'quickmod') ? true : false; 32 33 switch ($action) 34 { 35 case 'lock': 36 case 'unlock': 37 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); 38 39 if (!sizeof($topic_ids)) 40 { 41 trigger_error('NO_TOPIC_SELECTED'); 42 } 43 44 lock_unlock($action, $topic_ids); 45 break; 46 47 case 'lock_post': 48 case 'unlock_post': 49 50 $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0)); 51 52 if (!sizeof($post_ids)) 53 { 54 trigger_error('NO_POST_SELECTED'); 55 } 56 57 lock_unlock($action, $post_ids); 58 break; 59 60 case 'make_announce': 61 case 'make_sticky': 62 case 'make_global': 63 case 'make_normal': 64 65 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); 66 67 if (!sizeof($topic_ids)) 68 { 69 trigger_error('NO_TOPIC_SELECTED'); 70 } 71 72 change_topic_type($action, $topic_ids); 73 break; 74 75 case 'move': 76 $user->add_lang('viewtopic'); 77 78 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); 79 80 if (!sizeof($topic_ids)) 81 { 82 trigger_error('NO_TOPIC_SELECTED'); 83 } 84 85 mcp_move_topic($topic_ids); 86 break; 87 88 case 'fork': 89 $user->add_lang('viewtopic'); 90 91 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); 92 93 if (!sizeof($topic_ids)) 94 { 95 trigger_error('NO_TOPIC_SELECTED'); 96 } 97 98 mcp_fork_topic($topic_ids); 99 break; 100 101 case 'delete_topic': 102 $user->add_lang('viewtopic'); 103 104 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); 105 106 if (!sizeof($topic_ids)) 107 { 108 trigger_error('NO_TOPIC_SELECTED'); 109 } 110 111 mcp_delete_topic($topic_ids); 112 break; 113 114 case 'delete_post': 115 $user->add_lang('posting'); 116 117 $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0)); 118 119 if (!sizeof($post_ids)) 120 { 121 trigger_error('NO_POST_SELECTED'); 122 } 123 124 mcp_delete_post($post_ids); 125 break; 126 } 127 128 switch ($mode) 129 { 130 case 'front': 131 include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx); 132 133 $user->add_lang('acp/common'); 134 135 mcp_front_view($id, $mode, $action); 136 137 $this->tpl_name = 'mcp_front'; 138 $this->page_title = 'MCP_MAIN'; 139 break; 140 141 case 'forum_view': 142 include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx); 143 144 $user->add_lang('viewforum'); 145 146 $forum_id = request_var('f', 0); 147 148 $forum_info = get_forum_data($forum_id, 'm_'); 149 150 if (!sizeof($forum_info)) 151 { 152 $this->main('main', 'front'); 153 return; 154 } 155 156 $forum_info = $forum_info[$forum_id]; 157 158 mcp_forum_view($id, $mode, $action, $forum_info); 159 160 $this->tpl_name = 'mcp_forum'; 161 $this->page_title = 'MCP_MAIN_FORUM_VIEW'; 162 break; 163 164 case 'topic_view': 165 include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx); 166 167 mcp_topic_view($id, $mode, $action); 168 169 $this->tpl_name = 'mcp_topic'; 170 $this->page_title = 'MCP_MAIN_TOPIC_VIEW'; 171 break; 172 173 case 'post_details': 174 include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx); 175 176 mcp_post_details($id, $mode, $action); 177 178 $this->tpl_name = ($action == 'whois') ? 'mcp_whois' : 'mcp_post'; 179 $this->page_title = 'MCP_MAIN_POST_DETAILS'; 180 break; 181 182 default: 183 trigger_error("Unknown mode: $mode", E_USER_ERROR); 184 } 185 } 186 } 187 188 /** 189 * Lock/Unlock Topic/Post 190 */ 191 function lock_unlock($action, $ids) 192 { 193 global $auth, $user, $db, $phpEx, $phpbb_root_path; 194 195 if ($action == 'lock' || $action == 'unlock') 196 { 197 $table = TOPICS_TABLE; 198 $sql_id = 'topic_id'; 199 $set_id = 'topic_status'; 200 $l_prefix = 'TOPIC'; 201 } 202 else 203 { 204 $table = POSTS_TABLE; 205 $sql_id = 'post_id'; 206 $set_id = 'post_edit_locked'; 207 $l_prefix = 'POST'; 208 } 209 210 if (!($forum_id = check_ids($ids, $table, $sql_id, array('m_lock')))) 211 { 212 // Make sure that for f_user_lock only the lock action is triggered. 213 if ($action != 'lock') 214 { 215 return; 216 } 217 218 if (!($forum_id = check_ids($ids, $table, $sql_id, array('f_user_lock')))) 219 { 220 return; 221 } 222 } 223 224 $redirect = request_var('redirect', $user->data['session_page']); 225 226 $s_hidden_fields = build_hidden_fields(array( 227 $sql_id . '_list' => $ids, 228 'action' => $action, 229 'redirect' => $redirect) 230 ); 231 $success_msg = ''; 232 233 if (confirm_box(true)) 234 { 235 $sql = "UPDATE $table 236 SET $set_id = " . (($action == 'lock' || $action == 'lock_post') ? ITEM_LOCKED : ITEM_UNLOCKED) . ' 237 WHERE ' . $db->sql_in_set($sql_id, $ids); 238 $db->sql_query($sql); 239 240 $data = ($action == 'lock' || $action == 'unlock') ? get_topic_data($ids) : get_post_data($ids); 241 242 foreach ($data as $id => $row) 243 { 244 add_log('mod', $forum_id, $row['topic_id'], 'LOG_' . strtoupper($action), $row['topic_title']); 245 } 246 247 $success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS'; 248 } 249 else 250 { 251 confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields); 252 } 253 254 $redirect = request_var('redirect', "index.$phpEx"); 255 $redirect = reapply_sid($redirect); 256 257 if (!$success_msg) 258 { 259 redirect($redirect); 260 } 261 else 262 { 263 meta_refresh(2, $redirect); 264 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>')); 265 } 266 } 267 268 /** 269 * Change Topic Type 270 */ 271 function change_topic_type($action, $topic_ids) 272 { 273 global $auth, $user, $db, $phpEx, $phpbb_root_path; 274 275 if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('f_announce', 'f_sticky', 'm_')))) 276 { 277 return; 278 } 279 280 switch ($action) 281 { 282 case 'make_announce': 283 $new_topic_type = POST_ANNOUNCE; 284 $check_acl = 'f_announce'; 285 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS'; 286 break; 287 288 case 'make_global': 289 $new_topic_type = POST_GLOBAL; 290 $check_acl = 'f_announce'; 291 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS'; 292 break; 293 294 case 'make_sticky': 295 $new_topic_type = POST_STICKY; 296 $check_acl = 'f_sticky'; 297 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES'; 298 break; 299 300 default: 301 $new_topic_type = POST_NORMAL; 302 $check_acl = ''; 303 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS'; 304 break; 305 } 306 307 $redirect = request_var('redirect', $user->data['session_page']); 308 309 $s_hidden_fields = build_hidden_fields(array( 310 'topic_id_list' => $topic_ids, 311 'f' => $forum_id, 312 'action' => $action, 313 'redirect' => $redirect) 314 ); 315 $success_msg = ''; 316 317 if (confirm_box(true)) 318 { 319 if ($new_topic_type != POST_GLOBAL) 320 { 321 $sql = 'UPDATE ' . TOPICS_TABLE . " 322 SET topic_type = $new_topic_type 323 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . ' 324 AND forum_id <> 0'; 325 $db->sql_query($sql); 326 327 // Reset forum id if a global topic is within the array 328 if ($forum_id) 329 { 330 $sql = 'UPDATE ' . TOPICS_TABLE . " 331 SET topic_type = $new_topic_type, forum_id = $forum_id 332 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . ' 333 AND forum_id = 0'; 334 $db->sql_query($sql); 335 336 // Update forum_ids for all posts 337 $sql = 'UPDATE ' . POSTS_TABLE . " 338 SET forum_id = $forum_id 339 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . ' 340 AND forum_id = 0'; 341 $db->sql_query($sql); 342 343 sync('forum', 'forum_id', $forum_id); 344 } 345 } 346 else 347 { 348 // Get away with those topics already being a global announcement by re-calculating $topic_ids 349 $sql = 'SELECT topic_id 350 FROM ' . TOPICS_TABLE . ' 351 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . ' 352 AND forum_id <> 0'; 353 $result = $db->sql_query($sql); 354 355 $topic_ids = array(); 356 while ($row = $db->sql_fetchrow($result)) 357 { 358 $topic_ids[] = $row['topic_id']; 359 } 360 $db->sql_freeresult($result); 361 362 if (sizeof($topic_ids)) 363 { 364 // Delete topic shadows for global announcements 365 $sql = 'DELETE FROM ' . TOPICS_TABLE . ' 366 WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids); 367 $db->sql_query($sql); 368 369 $sql = 'UPDATE ' . TOPICS_TABLE . " 370 SET topic_type = $new_topic_type, forum_id = 0 371 WHERE " . $db->sql_in_set('topic_id', $topic_ids); 372 $db->sql_query($sql); 373 374 // Update forum_ids for all posts 375 $sql = 'UPDATE ' . POSTS_TABLE . ' 376 SET forum_id = 0 377 WHERE ' . $db->sql_in_set('topic_id', $topic_ids); 378 $db->sql_query($sql); 379 380 sync('forum', 'forum_id', $forum_id); 381 } 382 } 383 384 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED'; 385 386 if (sizeof($topic_ids)) 387 { 388 $data = get_topic_data($topic_ids); 389 390 foreach ($data as $topic_id => $row) 391 { 392 add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']); 393 } 394 } 395 } 396 else 397 { 398 confirm_box(false, $l_new_type, $s_hidden_fields); 399 } 400 401 $redirect = request_var('redirect', "index.$phpEx"); 402 $redirect = reapply_sid($redirect); 403 404 if (!$success_msg) 405 { 406 redirect($redirect); 407 } 408 else 409 { 410 meta_refresh(2, $redirect); 411 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>')); 412 } 413 } 414 415 /** 416 * Move Topic 417 */ 418 function mcp_move_topic($topic_ids) 419 { 420 global $auth, $user, $db, $template; 421 global $phpEx, $phpbb_root_path; 422 423 if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_move'))) 424 { 425 return; 426 } 427 428 $to_forum_id = request_var('to_forum_id', 0); 429 $redirect = request_var('redirect', $user->data['session_page']); 430 $additional_msg = $success_msg = ''; 431 432 $s_hidden_fields = build_hidden_fields(array( 433 'topic_id_list' => $topic_ids, 434 'f' => $forum_id, 435 'action' => 'move', 436 'redirect' => $redirect) 437 ); 438 439 if ($to_forum_id) 440 { 441 $forum_data = get_forum_data($to_forum_id); 442 443 if (!sizeof($forum_data)) 444 { 445 $additional_msg = $user->lang['FORUM_NOT_EXIST']; 446 } 447 else 448 { 449 $forum_data = $forum_data[$to_forum_id]; 450 451 if ($forum_data['forum_type'] != FORUM_POST) 452 { 453 $additional_msg = $user->lang['FORUM_NOT_POSTABLE']; 454 } 455 else if (!$auth->acl_get('f_post', $to_forum_id)) 456 { 457 $additional_msg = $user->lang['USER_CANNOT_POST']; 458 } 459 else if ($forum_id == $to_forum_id) 460 { 461 $additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM']; 462 } 463 } 464 } 465 466 if (!$to_forum_id || $additional_msg) 467 { 468 unset($_POST['confirm']); 469 } 470 471 if (confirm_box(true)) 472 { 473 $topic_data = get_topic_data($topic_ids); 474 $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false; 475 476 // Move topics, but do not resync yet 477 move_topics($topic_ids, $to_forum_id, false); 478 479 $forum_ids = array($to_forum_id); 480 foreach ($topic_data as $topic_id => $row) 481 { 482 // Get the list of forums to resync, add a log entry 483 $forum_ids[] = $row['forum_id']; 484 add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name']); 485 486 // If we have moved a global announcement, we need to correct the topic type 487 if ($row['topic_type'] == POST_GLOBAL) 488 { 489 $sql = 'UPDATE ' . TOPICS_TABLE . ' 490 SET topic_type = ' . POST_ANNOUNCE . ' 491 WHERE topic_id = ' . (int) $row['topic_id']; 492 $db->sql_query($sql); 493 } 494 495 // Leave a redirection if required and only if the topic is visible to users 496 if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL) 497 { 498 $shadow = array( 499 'forum_id' => (int) $row['forum_id'], 500 'icon_id' => (int) $row['icon_id'], 501 'topic_attachment' => (int) $row['topic_attachment'], 502 'topic_approved' => 1, 503 'topic_reported' => (int) $row['topic_reported'], 504 'topic_title' => (string) $row['topic_title'], 505 'topic_poster' => (int) $row['topic_poster'], 506 'topic_time' => (int) $row['topic_time'], 507 'topic_time_limit' => (int) $row['topic_time_limit'], 508 'topic_views' => (int) $row['topic_views'], 509 'topic_replies' => (int) $row['topic_replies'], 510 'topic_replies_real' => (int) $row['topic_replies_real'], 511 'topic_status' => ITEM_MOVED, 512 'topic_type' => (int) $row['topic_type'], 513 'topic_first_post_id' => (int) $row['topic_first_post_id'], 514 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'], 515 'topic_last_post_id' => (int) $row['topic_last_post_id'], 516 'topic_last_poster_id' => (int) $row['topic_last_poster_id'], 517 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'], 518 'topic_last_post_time' => (int) $row['topic_last_post_time'], 519 'topic_last_view_time' => (int) $row['topic_last_view_time'], 520 'topic_moved_id' => (int) $row['topic_id'], 521 'topic_bumped' => (int) $row['topic_bumped'], 522 'topic_bumper' => (int) $row['topic_bumper'], 523 'poll_title' => (string) $row['poll_title'], 524 'poll_start' => (int) $row['poll_start'], 525 'poll_length' => (int) $row['poll_length'], 526 'poll_max_options' => (int) $row['poll_max_options'], 527 'poll_last_vote' => (int) $row['poll_last_vote'] 528 ); 529 530 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow)); 531 } 532 } 533 unset($topic_data); 534 535 // Now sync forums 536 sync('forum', 'forum_id', $forum_ids); 537 538 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS'; 539 } 540 else 541 { 542 $template->assign_vars(array( 543 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true), 544 'S_CAN_LEAVE_SHADOW' => true, 545 'ADDITIONAL_MSG' => $additional_msg) 546 ); 547 548 confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); 549 } 550 551 $redirect = request_var('redirect', "index.$phpEx"); 552 $redirect = reapply_sid($redirect); 553 554 if (!$success_msg) 555 { 556 redirect($redirect); 557 } 558 else 559 { 560 meta_refresh(3, $redirect); 561 562 $message = $user->lang[$success_msg]; 563 $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'); 564 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>'); 565 $message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>'); 566 567 trigger_error($message); 568 } 569 } 570 571 /** 572 * Delete Topics 573 */ 574 function mcp_delete_topic($topic_ids) 575 { 576 global $auth, $user, $db, $phpEx, $phpbb_root_path; 577 578 if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_delete'))) 579 { 580 return; 581 } 582 583 $redirect = request_var('redirect', $user->data['session_page']); 584 585 $s_hidden_fields = build_hidden_fields(array( 586 'topic_id_list' => $topic_ids, 587 'f' => $forum_id, 588 'action' => 'delete_topic', 589 'redirect' => $redirect) 590 ); 591 $success_msg = ''; 592 593 if (confirm_box(true)) 594 { 595 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS'; 596 597 $data = get_topic_data($topic_ids); 598 599 foreach ($data as $topic_id => $row) 600 { 601 add_log('mod', $forum_id, 0, 'LOG_TOPIC_DELETED', $row['topic_title']); 602 } 603 604 $return = delete_topics('topic_id', $topic_ids); 605 } 606 else 607 { 608 confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields); 609 } 610 611 $redirect = request_var('redirect', "index.$phpEx"); 612 $redirect = reapply_sid($redirect); 613 614 if (!$success_msg) 615 { 616 redirect($redirect); 617 } 618 else 619 { 620 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); 621 meta_refresh(3, $redirect_url); 622 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>')); 623 } 624 } 625 626 /** 627 * Delete Posts 628 */ 629 function mcp_delete_post($post_ids) 630 { 631 global $auth, $user, $db, $phpEx, $phpbb_root_path; 632 633 if (!($forum_id = check_ids($post_ids, POSTS_TABLE, 'post_id', 'm_delete'))) 634 { 635 return; 636 } 637 638 $redirect = request_var('redirect', $user->data['session_page']); 639 640 $s_hidden_fields = build_hidden_fields(array( 641 'post_id_list' => $post_ids, 642 'f' => $forum_id, 643 'action' => 'delete_post', 644 'redirect' => $redirect) 645 ); 646 $success_msg = ''; 647 648 if (confirm_box(true)) 649 { 650 if (!function_exists('delete_posts')) 651 { 652 include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx); 653 } 654 655 // Count the number of topics that are affected 656 // I did not use COUNT(DISTINCT ...) because I remember having problems 657 // with it on older versions of MySQL -- Ashe 658 659 $sql = 'SELECT DISTINCT topic_id 660 FROM ' . POSTS_TABLE . ' 661 WHERE ' . $db->sql_in_set('post_id', $post_ids); 662 $result = $db->sql_query($sql); 663 664 $topic_id_list = array(); 665 while ($row = $db->sql_fetchrow($result)) 666 { 667 $topic_id_list[] = $row['topic_id']; 668 } 669 $affected_topics = sizeof($topic_id_list); 670 $db->sql_freeresult($result); 671 672 $post_data = get_post_data($post_ids); 673 674 foreach ($post_data as $id => $row) 675 { 676 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject']); 677 } 678 679 // Now delete the posts, topics and forums are automatically resync'ed 680 delete_posts('post_id', $post_ids); 681 682 $sql = 'SELECT COUNT(topic_id) AS topics_left 683 FROM ' . TOPICS_TABLE . ' 684 WHERE ' . $db->sql_in_set('topic_id', $topic_id_list); 685 $result = $db->sql_query_limit($sql, 1); 686 687 $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics; 688 $db->sql_freeresult($result); 689 690 $topic_id = request_var('t', 0); 691 692 // Return links 693 $return_link = array(); 694 if ($affected_topics == 1 && !$deleted_topics && $topic_id) 695 { 696 $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") . '">', '</a>'); 697 } 698 $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>'); 699 700 if (sizeof($post_ids) == 1) 701 { 702 if ($deleted_topics) 703 { 704 // We deleted the only post of a topic, which in turn has 705 // been removed from the database 706 $success_msg = $user->lang['TOPIC_DELETED_SUCCESS']; 707 } 708 else 709 { 710 $success_msg = $user->lang['POST_DELETED_SUCCESS']; 711 } 712 } 713 else 714 { 715 if ($deleted_topics) 716 { 717 // Some of topics disappeared 718 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING']; 719 } 720 else 721 { 722 $success_msg = $user->lang['POSTS_DELETED_SUCCESS']; 723 } 724 } 725 } 726 else 727 { 728 confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields); 729 } 730 731 $redirect = request_var('redirect', "index.$phpEx"); 732 $redirect = reapply_sid($redirect); 733 734 if (!$success_msg) 735 { 736 redirect($redirect); 737 } 738 else 739 { 740 meta_refresh(3, $redirect); 741 trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link)); 742 } 743 } 744 745 /** 746 * Fork Topic 747 */ 748 function mcp_fork_topic($topic_ids) 749 { 750 global $auth, $user, $db, $template, $config; 751 global $phpEx, $phpbb_root_path; 752 753 if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_'))) 754 { 755 return; 756 } 757 758 $to_forum_id = request_var('to_forum_id', 0); 759 $redirect = request_var('redirect', $user->data['session_page']); 760 $additional_msg = $success_msg = ''; 761 762 $s_hidden_fields = build_hidden_fields(array( 763 'topic_id_list' => $topic_ids, 764 'f' => $forum_id, 765 'action' => 'fork', 766 'redirect' => $redirect) 767 ); 768 769 if ($to_forum_id) 770 { 771 $forum_data = get_forum_data($to_forum_id); 772 773 if (!sizeof($topic_ids)) 774 { 775 $additional_msg = $user->lang['NO_TOPICS_SELECTED']; 776 } 777 else if (!sizeof($forum_data)) 778 { 779 $additional_msg = $user->lang['FORUM_NOT_EXIST']; 780 } 781 else 782 { 783 $forum_data = $forum_data[$to_forum_id]; 784 785 if ($forum_data['forum_type'] != FORUM_POST) 786 { 787 $additional_msg = $user->lang['FORUM_NOT_POSTABLE']; 788 } 789 else if (!$auth->acl_get('f_post', $to_forum_id)) 790 { 791 $additional_msg = $user->lang['USER_CANNOT_POST']; 792 } 793 } 794 } 795 796 if (!$to_forum_id || $additional_msg) 797 { 798 unset($_POST['confirm']); 799 } 800 801 if (confirm_box(true)) 802 { 803 $topic_data = get_topic_data($topic_ids); 804 805 $total_posts = 0; 806 $new_topic_id_list = array(); 807 foreach ($topic_data as $topic_id => $topic_row) 808 { 809 $sql_ary = array( 810 'forum_id' => (int) $to_forum_id, 811 'icon_id' => (int) $topic_row['icon_id'], 812 'topic_attachment' => (int) $topic_row['topic_attachment'], 813 'topic_approved' => 1, 814 'topic_reported' => 0, 815 'topic_title' => (string) $topic_row['topic_title'], 816 'topic_poster' => (int) $topic_row['topic_poster'], 817 'topic_time' => (int) $topic_row['topic_time'], 818 'topic_replies' => (int) $topic_row['topic_replies_real'], 819 'topic_replies_real' => (int) $topic_row['topic_replies_real'], 820 'topic_status' => (int) $topic_row['topic_status'], 821 'topic_type' => (int) $topic_row['topic_type'], 822 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], 823 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'], 824 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'], 825 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'], 826 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'], 827 'topic_bumped' => (int) $topic_row['topic_bumped'], 828 'topic_bumper' => (int) $topic_row['topic_bumper'], 829 'poll_title' => (string) $topic_row['poll_title'], 830 'poll_start' => (int) $topic_row['poll_start'], 831 'poll_length' => (int) $topic_row['poll_length'] 832 ); 833 834 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); 835 $new_topic_id = $db->sql_nextid(); 836 $new_topic_id_list[$topic_id] = $new_topic_id; 837 838 /** 839 * @todo enable? (is this still needed?) 840 * markread('topic', $to_forum_id, $new_topic_id); 841 */ 842 843 if ($topic_row['poll_start']) 844 { 845 $poll_rows = array(); 846 847 $sql = 'SELECT * 848 FROM ' . POLL_OPTIONS_TABLE . " 849 WHERE topic_id = $topic_id"; 850 $result = $db->sql_query($sql); 851 852 while ($row = $db->sql_fetchrow($result)) 853 { 854 $sql_ary = array( 855 'poll_option_id' => (int) $row['poll_option_id'], 856 'topic_id' => (int) $new_topic_id, 857 'poll_option_text' => (string) $row['poll_option_text'], 858 'poll_option_total' => 0 859 ); 860 861 $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); 862 } 863 } 864 865 $sql = 'SELECT * 866 FROM ' . POSTS_TABLE . " 867 WHERE topic_id = $topic_id 868 ORDER BY post_time ASC"; 869 $result = $db->sql_query($sql); 870 871 $post_rows = array(); 872 while ($row = $db->sql_fetchrow($result)) 873 { 874 $post_rows[] = $row; 875 } 876 $db->sql_freeresult($result); 877 878 if (!sizeof($post_rows)) 879 { 880 continue; 881 } 882 883 $total_posts += sizeof($post_rows); 884 foreach ($post_rows as $row) 885 { 886 $sql_ary = array( 887 'topic_id' => (int) $new_topic_id, 888 'forum_id' => (int) $to_forum_id, 889 'poster_id' => (int) $row['poster_id'], 890 'icon_id' => (int) $row['icon_id'], 891 'poster_ip' => (string) $row['poster_ip'], 892 'post_time' => (int) $row['post_time'], 893 'post_approved' => 1, 894 'post_reported' => 0, 895 'enable_bbcode' => (int) $row['enable_bbcode'], 896 'enable_smilies' => (int) $row['enable_smilies'], 897 'enable_magic_url' => (int) $row['enable_magic_url'], 898 'enable_sig' => (int) $row['enable_sig'], 899 'post_username' => (string) $row['post_username'], 900 'post_subject' => (string) $row['post_subject'], 901 'post_text' => (string) $row['post_text'], 902 'post_edit_reason' => (string) $row['post_edit_reason'], 903 'post_edit_user' => (int) $row['post_edit_user'], 904 'post_checksum' => (string) $row['post_checksum'], 905 'post_attachment' => (int) $row['post_attachment'], 906 'bbcode_bitfield' => $row['bbcode_bitfield'], 907 'bbcode_uid' => (string) $row['bbcode_uid'], 908 'post_edit_time' => (int) $row['post_edit_time'], 909 'post_edit_count' => (int) $row['post_edit_count'], 910 'post_edit_locked' => (int) $row['post_edit_locked'] 911 ); 912 913 $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); 914 $new_post_id = $db->sql_nextid(); 915 916 // Copy whether the topic is dotted 917 markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']); 918 919 // Copy Attachments 920 if ($row['post_attachment']) 921 { 922 $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . " 923 WHERE post_msg_id = {$row['post_id']} 924 AND topic_id = $topic_id 925 AND in_message = 0"; 926 $result = $db->sql_query($sql); 927 928 while ($attach_row = $db->sql_fetchrow($result)) 929 { 930 $sql_ary = array( 931 'post_msg_id' => (int) $new_post_id, 932 'topic_id' => (int) $new_topic_id, 933 'in_message' => 0, 934 'poster_id' => (int) $attach_row['poster_id'], 935 'physical_filename' => (string) basename($attach_row['physical_filename']), 936 'real_filename' => (string) basename($attach_row['real_filename']), 937 'download_count' => (int) $attach_row['download_count'], 938 'attach_comment' => (string) $attach_row['attach_comment'], 939 'extension' => (string) $attach_row['extension'], 940 'mimetype' => (string) $attach_row['mimetype'], 941 'filesize' => (int) $attach_row['filesize'], 942 'filetime' => (int) $attach_row['filetime'], 943 'thumbnail' => (int) $attach_row['thumbnail'] 944 ); 945 946 $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); 947 } 948 $db->sql_freeresult($result); 949 } 950 } 951 } 952 953 // Sync new topics, parent forums and board stats 954 sync('topic', 'topic_id', $new_topic_id_list, true); 955 sync('forum', 'forum_id', $to_forum_id, true); 956 set_config('num_topics', $config['num_topics'] + sizeof($new_topic_id_list), true); 957 set_config('num_posts', $config['num_posts'] + $total_posts, true); 958 959 foreach ($new_topic_id_list as $topic_id => $new_topic_id) 960 { 961 add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']); 962 } 963 964 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS'; 965 } 966 else 967 { 968 $template->assign_vars(array( 969 'S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true), 970 'S_CAN_LEAVE_SHADOW' => false, 971 'ADDITIONAL_MSG' => $additional_msg) 972 ); 973 974 confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); 975 } 976 977 $redirect = request_var('redirect', "index.$phpEx"); 978 $redirect = reapply_sid($redirect); 979 980 if (!$success_msg) 981 { 982 redirect($redirect); 983 } 984 else 985 { 986 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); 987 meta_refresh(3, $redirect_url); 988 $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'); 989 990 if ($forum_id != $to_forum_id) 991 { 992 $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $to_forum_id) . '">', '</a>'); 993 } 994 995 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link); 996 } 997 } 998 999 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 22 00:35:05 2006 | Cross-referenced by PHPXref 0.6 |