/** * Do the actual split of a selection of topics. * is accessed with ?action=splittopics;sa=splitSelection. * uses the main SplitTopics template. * uses splitTopic function to do the actual splitting. */ public function action_splitSelection() { global $txt, $topic, $context; // Make sure the session id was passed with post. checkSession(); require_once SUBSDIR . '/Topic.subs.php'; // You must've selected some messages! Can't split out none! if (empty($_SESSION['split_selection'][$topic])) { $this->_unset_session_values(); fatal_lang_error('no_posts_selected', false); } // This is here because there are two fatal_lang_errors in there $boards = splitDestinationBoard($_SESSION['move_to_board']); $context['old_topic'] = $topic; $context['new_topic'] = splitTopic($topic, $_SESSION['split_selection'][$topic], $_SESSION['new_topic_subject']); $context['page_title'] = $txt['split_topic']; $context['sub_template'] = 'split_successful'; splitAttemptMove($boards, $context['new_topic']); // Create a link to this in the old topic. // @todo Does this make sense if the topic was unapproved before? We are not yet sure if the resulting topic is unapproved. if ($_SESSION['messageRedirect']) { postSplitRedirect($_SESSION['reason'], $_SESSION['new_topic_subject'], $boards['destination'], $context['new_topic']); } $this->_unset_session_values(); }
/** * If we are also moving the topic somewhere else, let's try do to it * Includes checks for permissions move_own/any, etc. * * @param mixed[] $boards an array containing basic info of the origin and destination boards (from splitDestinationBoard) * @param int $totopic id of the destination topic */ function splitAttemptMove($boards, $totopic) { global $board, $user_info, $context; $db = database(); // If the starting and final boards are different we have to check some permissions and stuff if ($boards['destination']['id'] != $board) { $doMove = false; if (allowedTo('move_any')) { $doMove = true; } else { $new_topic = getTopicInfo($totopic); if ($new_topic['id_member_started'] == $user_info['id'] && allowedTo('move_own')) { $doMove = true; } } if ($doMove) { // Update member statistics if needed // @todo this should probably go into a function... if ($boards['destination']['count_posts'] != $boards['current']['count_posts']) { $request = $db->query('', ' SELECT id_member FROM {db_prefix}messages WHERE id_topic = {int:current_topic} AND approved = {int:is_approved}', array('current_topic' => $totopic, 'is_approved' => 1)); $posters = array(); while ($row = $db->fetch_assoc($request)) { if (!isset($posters[$row['id_member']])) { $posters[$row['id_member']] = 0; } $posters[$row['id_member']]++; } $db->free_result($request); foreach ($posters as $id_member => $posts) { // The board we're moving from counted posts, but not to. if (empty($boards['current']['count_posts'])) { updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); } else { updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); } } } // And finally move it! moveTopics($totopic, $boards['destination']['id']); } else { $boards['destination'] = $boards['current']; } } // Create a link to this in the old topic. // @todo Does this make sense if the topic was unapproved before? We are not yet sure if the resulting topic is unapproved. if (!empty($_POST['messageRedirect'])) { postSplitRedirect($context['reason'], $_POST['subname'], $boards['destination'], $context['new_topic']); } }