Chris@76: $topic, Chris@76: ) Chris@76: ); Chris@76: list ($id_member_started, $context['subject'], $context['is_approved']) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Can they see it - if not approved? Chris@76: if ($modSettings['postmod_active'] && !$context['is_approved']) Chris@76: isAllowedTo('approve_posts'); Chris@76: Chris@76: // Permission check! Chris@76: // !!! Chris@76: if (!allowedTo('move_any')) Chris@76: { Chris@76: if ($id_member_started == $user_info['id']) Chris@76: { Chris@76: isAllowedTo('move_own'); Chris@76: //$boards = array_merge(boardsAllowedTo('move_own'), boardsAllowedTo('move_any')); Chris@76: } Chris@76: else Chris@76: isAllowedTo('move_any'); Chris@76: } Chris@76: //else Chris@76: //$boards = boardsAllowedTo('move_any'); Chris@76: Chris@76: loadTemplate('MoveTopic'); Chris@76: Chris@76: // Get a list of boards this moderator can move to. Chris@76: $request = $smcFunc['db_query']('order_by_board_order', ' Chris@76: SELECT b.id_board, b.name, b.child_level, c.name AS cat_name, c.id_cat Chris@76: FROM {db_prefix}boards AS b Chris@76: LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) Chris@76: WHERE {query_see_board} Chris@76: AND b.redirect = {string:blank_redirect} Chris@76: AND b.id_board != {int:current_board}', Chris@76: array( Chris@76: 'blank_redirect' => '', Chris@76: 'current_board' => $board, Chris@76: ) Chris@76: ); Chris@76: $context['boards'] = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: if (!isset($context['categories'][$row['id_cat']])) Chris@76: $context['categories'][$row['id_cat']] = array ( Chris@76: 'name' => strip_tags($row['cat_name']), Chris@76: 'boards' => array(), Chris@76: ); Chris@76: Chris@76: $context['categories'][$row['id_cat']]['boards'][] = array( Chris@76: 'id' => $row['id_board'], Chris@76: 'name' => strip_tags($row['name']), Chris@76: 'category' => strip_tags($row['cat_name']), Chris@76: 'child_level' => $row['child_level'], Chris@76: 'selected' => !empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] == $row['id_board'] && $row['id_board'] != $board, Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if (empty($context['categories'])) Chris@76: fatal_lang_error('moveto_noboards', false); Chris@76: Chris@76: $context['page_title'] = $txt['move_topic']; Chris@76: Chris@76: $context['linktree'][] = array( Chris@76: 'url' => $scripturl . '?topic=' . $topic . '.0', Chris@76: 'name' => $context['subject'], Chris@76: 'extra_before' => $settings['linktree_inline'] ? $txt['topic'] . ': ' : '', Chris@76: ); Chris@76: Chris@76: $context['linktree'][] = array( Chris@76: 'name' => $txt['move_topic'], Chris@76: ); Chris@76: Chris@76: $context['back_to_topic'] = isset($_REQUEST['goback']); Chris@76: Chris@76: if ($user_info['language'] != $language) Chris@76: { Chris@76: loadLanguage('index', $language); Chris@76: $temp = $txt['movetopic_default']; Chris@76: loadLanguage('index'); Chris@76: Chris@76: $txt['movetopic_default'] = $temp; Chris@76: } Chris@76: Chris@76: // Register this form and get a sequence number in $context. Chris@76: checkSubmitOnce('register'); Chris@76: } Chris@76: Chris@76: // Execute the move. Chris@76: function MoveTopic2() Chris@76: { Chris@76: global $txt, $board, $topic, $scripturl, $sourcedir, $modSettings, $context; Chris@76: global $board, $language, $user_info, $smcFunc; Chris@76: Chris@76: if (empty($topic)) Chris@76: fatal_lang_error('no_access', false); Chris@76: Chris@76: // You can't choose to have a redirection topic and use an empty reason. Chris@76: if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) Chris@76: fatal_lang_error('movetopic_no_reason', false); Chris@76: Chris@76: // Make sure this form hasn't been submitted before. Chris@76: checkSubmitOnce('check'); Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_member_started, id_first_msg, approved Chris@76: FROM {db_prefix}topics Chris@76: WHERE id_topic = {int:current_topic} Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: ) Chris@76: ); Chris@76: list ($id_member_started, $id_first_msg, $context['is_approved']) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Can they see it? Chris@76: if (!$context['is_approved']) Chris@76: isAllowedTo('approve_posts'); Chris@76: Chris@76: // Can they move topics on this board? Chris@76: if (!allowedTo('move_any')) Chris@76: { Chris@76: if ($id_member_started == $user_info['id']) Chris@76: { Chris@76: isAllowedTo('move_own'); Chris@76: $boards = array_merge(boardsAllowedTo('move_own'), boardsAllowedTo('move_any')); Chris@76: } Chris@76: else Chris@76: isAllowedTo('move_any'); Chris@76: } Chris@76: else Chris@76: $boards = boardsAllowedTo('move_any'); Chris@76: Chris@76: // If this topic isn't approved don't let them move it if they can't approve it! Chris@76: if ($modSettings['postmod_active'] && !$context['is_approved'] && !allowedTo('approve_posts')) Chris@76: { Chris@76: // Only allow them to move it to other boards they can't approve it in. Chris@76: $can_approve = boardsAllowedTo('approve_posts'); Chris@76: $boards = array_intersect($boards, $can_approve); Chris@76: } Chris@76: Chris@76: checkSession(); Chris@76: require_once($sourcedir . '/Subs-Post.php'); Chris@76: Chris@76: // The destination board must be numeric. Chris@76: $_POST['toboard'] = (int) $_POST['toboard']; Chris@76: Chris@76: // Make sure they can see the board they are trying to move to (and get whether posts count in the target board). Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT b.count_posts, b.name, m.subject Chris@76: FROM {db_prefix}boards AS b Chris@76: INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) Chris@76: INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) Chris@76: WHERE {query_see_board} Chris@76: AND b.id_board = {int:to_board} Chris@76: AND b.redirect = {string:blank_redirect} Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'to_board' => $_POST['toboard'], Chris@76: 'blank_redirect' => '', Chris@76: ) Chris@76: ); Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: fatal_lang_error('no_board'); Chris@76: list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Remember this for later. Chris@76: $_SESSION['move_to_topic'] = $_POST['toboard']; Chris@76: Chris@76: // Rename the topic... Chris@76: if (isset($_POST['reset_subject'], $_POST['custom_subject']) && $_POST['custom_subject'] != '') Chris@76: { Chris@76: $_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); Chris@76: // Keep checking the length. Chris@76: if ($smcFunc['strlen']($_POST['custom_subject']) > 100) Chris@76: $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); Chris@76: Chris@76: // If it's still valid move onwards and upwards. Chris@76: if ($_POST['custom_subject'] != '') Chris@76: { Chris@76: if (isset($_POST['enforce_subject'])) Chris@76: { Chris@76: // Get a response prefix, but in the forum's default language. Chris@76: if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) Chris@76: { Chris@76: if ($language === $user_info['language']) Chris@76: $context['response_prefix'] = $txt['response_prefix']; Chris@76: else Chris@76: { Chris@76: loadLanguage('index', $language, false); Chris@76: $context['response_prefix'] = $txt['response_prefix']; Chris@76: loadLanguage('index'); Chris@76: } Chris@76: cache_put_data('response_prefix', $context['response_prefix'], 600); Chris@76: } Chris@76: Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}messages Chris@76: SET subject = {string:subject} Chris@76: WHERE id_topic = {int:current_topic}', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'subject' => $context['response_prefix'] . $_POST['custom_subject'], Chris@76: ) Chris@76: ); Chris@76: } Chris@76: Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}messages Chris@76: SET subject = {string:custom_subject} Chris@76: WHERE id_msg = {int:id_first_msg}', Chris@76: array( Chris@76: 'id_first_msg' => $id_first_msg, Chris@76: 'custom_subject' => $_POST['custom_subject'], Chris@76: ) Chris@76: ); Chris@76: Chris@76: // Fix the subject cache. Chris@76: updateStats('subject', $topic, $_POST['custom_subject']); Chris@76: } Chris@76: } Chris@76: Chris@76: // Create a link to this in the old board. Chris@76: //!!! Does this make sense if the topic was unapproved before? I'd just about say so. Chris@76: if (isset($_POST['postRedirect'])) Chris@76: { Chris@76: // Should be in the boardwide language. Chris@76: if ($user_info['language'] != $language) Chris@76: loadLanguage('index', $language); Chris@76: Chris@76: $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES); Chris@76: preparsecode($_POST['reason']); Chris@76: Chris@76: // Add a URL onto the message. Chris@76: $_POST['reason'] = strtr($_POST['reason'], array( Chris@76: $txt['movetopic_auto_board'] => '[url=' . $scripturl . '?board=' . $_POST['toboard'] . '.0]' . $board_name . '[/url]', Chris@76: $txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]' Chris@76: )); Chris@76: Chris@76: $msgOptions = array( Chris@76: 'subject' => $txt['moved'] . ': ' . $subject, Chris@76: 'body' => $_POST['reason'], Chris@76: 'icon' => 'moved', Chris@76: 'smileys_enabled' => 1, Chris@76: ); Chris@76: $topicOptions = array( Chris@76: 'board' => $board, Chris@76: 'lock_mode' => 1, Chris@76: 'mark_as_read' => true, Chris@76: ); Chris@76: $posterOptions = array( Chris@76: 'id' => $user_info['id'], Chris@76: 'update_post_count' => empty($pcounter), Chris@76: ); Chris@76: createPost($msgOptions, $topicOptions, $posterOptions); Chris@76: } Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT count_posts Chris@76: FROM {db_prefix}boards Chris@76: WHERE id_board = {int:current_board} Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'current_board' => $board, Chris@76: ) Chris@76: ); Chris@76: list ($pcounter_from) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if ($pcounter_from != $pcounter) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_member Chris@76: FROM {db_prefix}messages Chris@76: WHERE id_topic = {int:current_topic} Chris@76: AND approved = {int:is_approved}', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'is_approved' => 1, Chris@76: ) Chris@76: ); Chris@76: $posters = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: if (!isset($posters[$row['id_member']])) Chris@76: $posters[$row['id_member']] = 0; Chris@76: Chris@76: $posters[$row['id_member']]++; Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: foreach ($posters as $id_member => $posts) Chris@76: { Chris@76: // The board we're moving from counted posts, but not to. Chris@76: if (empty($pcounter_from)) Chris@76: updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); Chris@76: // The reverse: from didn't, to did. Chris@76: else Chris@76: updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); Chris@76: } Chris@76: } Chris@76: Chris@76: // Do the move (includes statistics update needed for the redirect topic). Chris@76: moveTopics($topic, $_POST['toboard']); Chris@76: Chris@76: // Log that they moved this topic. Chris@76: if (!allowedTo('move_own') || $id_member_started != $user_info['id']) Chris@76: logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); Chris@76: // Notify people that this topic has been moved? Chris@76: sendNotifications($topic, 'move'); Chris@76: Chris@76: // Why not go back to the original board in case they want to keep moving? Chris@76: if (!isset($_REQUEST['goback'])) Chris@76: redirectexit('board=' . $board . '.0'); Chris@76: else Chris@76: redirectexit('topic=' . $topic . '.0'); Chris@76: } Chris@76: Chris@76: // Moves one or more topics to a specific board. (doesn't check permissions.) Chris@76: function moveTopics($topics, $toBoard) Chris@76: { Chris@76: global $sourcedir, $user_info, $modSettings, $smcFunc; Chris@76: Chris@76: // Empty array? Chris@76: if (empty($topics)) Chris@76: return; Chris@76: // Only a single topic. Chris@76: elseif (is_numeric($topics)) Chris@76: $topics = array($topics); Chris@76: $num_topics = count($topics); Chris@76: $fromBoards = array(); Chris@76: Chris@76: // Destination board empty or equal to 0? Chris@76: if (empty($toBoard)) Chris@76: return; Chris@76: Chris@76: // Are we moving to the recycle board? Chris@76: $isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard; Chris@76: Chris@76: // Determine the source boards... Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_board, approved, COUNT(*) AS num_topics, SUM(unapproved_posts) AS unapproved_posts, Chris@76: SUM(num_replies) AS num_replies Chris@76: FROM {db_prefix}topics Chris@76: WHERE id_topic IN ({array_int:topics}) Chris@76: GROUP BY id_board, approved', Chris@76: array( Chris@76: 'topics' => $topics, Chris@76: ) Chris@76: ); Chris@76: // Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards. Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: return; Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: if (!isset($fromBoards[$row['id_board']]['num_posts'])) Chris@76: { Chris@76: $fromBoards[$row['id_board']] = array( Chris@76: 'num_posts' => 0, Chris@76: 'num_topics' => 0, Chris@76: 'unapproved_posts' => 0, Chris@76: 'unapproved_topics' => 0, Chris@76: 'id_board' => $row['id_board'] Chris@76: ); Chris@76: } Chris@76: // Posts = (num_replies + 1) for each approved topic. Chris@76: $fromBoards[$row['id_board']]['num_posts'] += $row['num_replies'] + ($row['approved'] ? $row['num_topics'] : 0); Chris@76: $fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; Chris@76: Chris@76: // Add the topics to the right type. Chris@76: if ($row['approved']) Chris@76: $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; Chris@76: else Chris@76: $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Move over the mark_read data. (because it may be read and now not by some!) Chris@76: $SaveAServer = max(0, $modSettings['maxMsgID'] - 50000); Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT lmr.id_member, lmr.id_msg, t.id_topic Chris@76: FROM {db_prefix}topics AS t Chris@76: INNER JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board Chris@76: AND lmr.id_msg > t.id_first_msg AND lmr.id_msg > {int:protect_lmr_msg}) Chris@76: LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = lmr.id_member) Chris@76: WHERE t.id_topic IN ({array_int:topics}) Chris@76: AND lmr.id_msg > IFNULL(lt.id_msg, 0)', Chris@76: array( Chris@76: 'protect_lmr_msg' => $SaveAServer, Chris@76: 'topics' => $topics, Chris@76: ) Chris@76: ); Chris@76: $log_topics = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: $log_topics[] = array($row['id_topic'], $row['id_member'], $row['id_msg']); Chris@76: Chris@76: // Prevent queries from getting too big. Taking some steam off. Chris@76: if (count($log_topics) > 500) Chris@76: { Chris@76: $smcFunc['db_insert']('replace', Chris@76: '{db_prefix}log_topics', Chris@76: array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), Chris@76: $log_topics, Chris@76: array('id_topic', 'id_member') Chris@76: ); Chris@76: Chris@76: $log_topics = array(); Chris@76: } Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Now that we have all the topics that *should* be marked read, and by which members... Chris@76: if (!empty($log_topics)) Chris@76: { Chris@76: // Insert that information into the database! Chris@76: $smcFunc['db_insert']('replace', Chris@76: '{db_prefix}log_topics', Chris@76: array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), Chris@76: $log_topics, Chris@76: array('id_topic', 'id_member') Chris@76: ); Chris@76: } Chris@76: Chris@76: // Update the number of posts on each board. Chris@76: $totalTopics = 0; Chris@76: $totalPosts = 0; Chris@76: $totalUnapprovedTopics = 0; Chris@76: $totalUnapprovedPosts = 0; Chris@76: foreach ($fromBoards as $stats) Chris@76: { Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}boards Chris@76: SET Chris@76: num_posts = CASE WHEN {int:num_posts} > num_posts THEN 0 ELSE num_posts - {int:num_posts} END, Chris@76: num_topics = CASE WHEN {int:num_topics} > num_topics THEN 0 ELSE num_topics - {int:num_topics} END, Chris@76: unapproved_posts = CASE WHEN {int:unapproved_posts} > unapproved_posts THEN 0 ELSE unapproved_posts - {int:unapproved_posts} END, Chris@76: unapproved_topics = CASE WHEN {int:unapproved_topics} > unapproved_topics THEN 0 ELSE unapproved_topics - {int:unapproved_topics} END Chris@76: WHERE id_board = {int:id_board}', Chris@76: array( Chris@76: 'id_board' => $stats['id_board'], Chris@76: 'num_posts' => $stats['num_posts'], Chris@76: 'num_topics' => $stats['num_topics'], Chris@76: 'unapproved_posts' => $stats['unapproved_posts'], Chris@76: 'unapproved_topics' => $stats['unapproved_topics'], Chris@76: ) Chris@76: ); Chris@76: $totalTopics += $stats['num_topics']; Chris@76: $totalPosts += $stats['num_posts']; Chris@76: $totalUnapprovedTopics += $stats['unapproved_topics']; Chris@76: $totalUnapprovedPosts += $stats['unapproved_posts']; Chris@76: } Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}boards Chris@76: SET Chris@76: num_topics = num_topics + {int:total_topics}, Chris@76: num_posts = num_posts + {int:total_posts},' . ($isRecycleDest ? ' Chris@76: unapproved_posts = {int:no_unapproved}, unapproved_topics = {int:no_unapproved}' : ' Chris@76: unapproved_posts = unapproved_posts + {int:total_unapproved_posts}, Chris@76: unapproved_topics = unapproved_topics + {int:total_unapproved_topics}') . ' Chris@76: WHERE id_board = {int:id_board}', Chris@76: array( Chris@76: 'id_board' => $toBoard, Chris@76: 'total_topics' => $totalTopics, Chris@76: 'total_posts' => $totalPosts, Chris@76: 'total_unapproved_topics' => $totalUnapprovedTopics, Chris@76: 'total_unapproved_posts' => $totalUnapprovedPosts, Chris@76: 'no_unapproved' => 0, Chris@76: ) Chris@76: ); Chris@76: Chris@76: // Move the topic. Done. :P Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}topics Chris@76: SET id_board = {int:id_board}' . ($isRecycleDest ? ', Chris@76: unapproved_posts = {int:no_unapproved}, approved = {int:is_approved}' : '') . ' Chris@76: WHERE id_topic IN ({array_int:topics})', Chris@76: array( Chris@76: 'id_board' => $toBoard, Chris@76: 'topics' => $topics, Chris@76: 'is_approved' => 1, Chris@76: 'no_unapproved' => 0, Chris@76: ) Chris@76: ); Chris@76: Chris@76: // If this was going to the recycle bin, check what messages are being recycled, and remove them from the queue. Chris@76: if ($isRecycleDest && ($totalUnapprovedTopics || $totalUnapprovedPosts)) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_msg Chris@76: FROM {db_prefix}messages Chris@76: WHERE id_topic IN ({array_int:topics}) Chris@76: and approved = {int:not_approved}', Chris@76: array( Chris@76: 'topics' => $topics, Chris@76: 'not_approved' => 0, Chris@76: ) Chris@76: ); Chris@76: $approval_msgs = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: $approval_msgs[] = $row['id_msg']; Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Empty the approval queue for these, as we're going to approve them next. Chris@76: if (!empty($approval_msgs)) Chris@76: $smcFunc['db_query']('', ' Chris@76: DELETE FROM {db_prefix}approval_queue Chris@76: WHERE id_msg IN ({array_int:message_list}) Chris@76: AND id_attach = {int:id_attach}', Chris@76: array( Chris@76: 'message_list' => $approval_msgs, Chris@76: 'id_attach' => 0, Chris@76: ) Chris@76: ); Chris@76: Chris@76: // Get all the current max and mins. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_topic, id_first_msg, id_last_msg Chris@76: FROM {db_prefix}topics Chris@76: WHERE id_topic IN ({array_int:topics})', Chris@76: array( Chris@76: 'topics' => $topics, Chris@76: ) Chris@76: ); Chris@76: $topicMaxMin = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: $topicMaxMin[$row['id_topic']] = array( Chris@76: 'min' => $row['id_first_msg'], Chris@76: 'max' => $row['id_last_msg'], Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Check the MAX and MIN are correct. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_topic, MIN(id_msg) AS first_msg, MAX(id_msg) AS last_msg Chris@76: FROM {db_prefix}messages Chris@76: WHERE id_topic IN ({array_int:topics}) Chris@76: GROUP BY id_topic', Chris@76: array( Chris@76: 'topics' => $topics, Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: // If not, update. Chris@76: if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}topics Chris@76: SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg} Chris@76: WHERE id_topic = {int:selected_topic}', Chris@76: array( Chris@76: 'first_msg' => $row['first_msg'], Chris@76: 'last_msg' => $row['last_msg'], Chris@76: 'selected_topic' => $row['id_topic'], Chris@76: ) Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}messages Chris@76: SET id_board = {int:id_board}' . ($isRecycleDest ? ',approved = {int:is_approved}' : '') . ' Chris@76: WHERE id_topic IN ({array_int:topics})', Chris@76: array( Chris@76: 'id_board' => $toBoard, Chris@76: 'topics' => $topics, Chris@76: 'is_approved' => 1, Chris@76: ) Chris@76: ); Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}log_reported Chris@76: SET id_board = {int:id_board} Chris@76: WHERE id_topic IN ({array_int:topics})', Chris@76: array( Chris@76: 'id_board' => $toBoard, Chris@76: 'topics' => $topics, Chris@76: ) Chris@76: ); Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}calendar Chris@76: SET id_board = {int:id_board} Chris@76: WHERE id_topic IN ({array_int:topics})', Chris@76: array( Chris@76: 'id_board' => $toBoard, Chris@76: 'topics' => $topics, Chris@76: ) Chris@76: ); Chris@76: Chris@76: // Mark target board as seen, if it was already marked as seen before. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT (IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS isSeen Chris@76: FROM {db_prefix}boards AS b Chris@76: LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) Chris@76: WHERE b.id_board = {int:id_board}', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'id_board' => $toBoard, Chris@76: ) Chris@76: ); Chris@76: list ($isSeen) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if (!empty($isSeen) && !$user_info['is_guest']) Chris@76: { Chris@76: $smcFunc['db_insert']('replace', Chris@76: '{db_prefix}log_boards', Chris@76: array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), Chris@76: array($toBoard, $user_info['id'], $modSettings['maxMsgID']), Chris@76: array('id_board', 'id_member') Chris@76: ); Chris@76: } Chris@76: Chris@76: // Update the cache? Chris@76: if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) Chris@76: foreach ($topics as $topic_id) Chris@76: cache_put_data('topic_board-' . $topic_id, null, 120); Chris@76: Chris@76: require_once($sourcedir . '/Subs-Post.php'); Chris@76: Chris@76: $updates = array_keys($fromBoards); Chris@76: $updates[] = $toBoard; Chris@76: Chris@76: updateLastMessages(array_unique($updates)); Chris@76: Chris@76: // Update 'em pesky stats. Chris@76: updateStats('topic'); Chris@76: updateStats('message'); Chris@76: updateSettings(array( Chris@76: 'calendar_updated' => time(), Chris@76: )); Chris@76: } Chris@76: Chris@76: ?>