$link = "{$_CONF['site_url']}/forum/viewtopic.php?showtopic={$moveid}"; forum_statusMessage(sprintf($LANG_GF02['msg183'], $movetoforum), $link, $LANG_GF02['msg183']); } else { // Move complete topic $moveResult = DB_query("Select id from {$_TABLES['gf_topic']} WHERE pid={$moveid}"); $postCount = DB_numRows($moveResult) + 1; // Need to account for the parent post while ($movetopic = DB_fetchArray($moveResult)) { DB_query("UPDATE {$_TABLES['gf_topic']} SET forum='{$newforumid}' WHERE id='{$movetopic['id']}'"); } // Update any topic subscription records - need to change the forum ID record DB_query("UPDATE {$_TABLES['gf_watch']} SET forum_id = '{$newforumid}' WHERE topic_id='{$moveid}'"); DB_query("UPDATE {$_TABLES['gf_topic']} SET forum = '{$newforumid}', moved = '1' WHERE id={$moveid}"); // Update the Last Post Information gf_updateLastPost($newforumid, $moveid); gf_updateLastPost($forum); // Update Topic and Post Count for the effected forums DB_query("UPDATE {$_TABLES['gf_forums']} SET topic_count=topic_count+1, post_count=post_count+{$postCount} WHERE forum_id={$newforumid}"); DB_query("UPDATE {$_TABLES['gf_forums']} SET topic_count=topic_count-1, post_count=post_count-{$postCount} WHERE forum_id={$forum}"); // Remove any lastviewed records in the log so that the new updated topic indicator will appear DB_query("DELETE FROM {$_TABLES['gf_log']} WHERE topic='{$moveid}'"); $link = "{$_CONF['site_url']}/forum/viewtopic.php?showtopic={$moveid}"; forum_statusMessage($LANG_GF02['msg163'], $link, $LANG_GF02['msg163']); } gf_siteFooter(); exit; } } if ($modfunction == 'deletepost' and forum_modPermission($forum, $_USER['uid'], 'mod_delete') and $fortopicid != 0) { if ($top == 'yes') { $alertmessage = $LANG_GF02['msg65'] . "<p>";
function moderator_mergePost($topic_id, $topic_parent_id, $forum_id, $move_to_forum, $move_to_topic, $splittype) { global $_CONF, $_USER, $_TABLES, $_FF_CONF, $LANG_GF02; $retval = ''; // right now we are only implementing moving a single post. if ($move_to_topic == 0) { echo COM_refresh($_CONF['site_url'] . "/forum/viewtopic.php?showtopic={$topic_id}"); exit; } $curpostpid = DB_getItem($_TABLES['ff_topic'], "pid", "id=" . (int) $topic_id); if ($curpostpid == '') { echo COM_refresh($_CONF['site_url'] . "/forum/viewtopic.php?showtopic={$topic_id}"); exit; } $move_to_forum = DB_getItem($_TABLES['ff_topic'], "forum", "id=" . (int) $move_to_topic); if ($move_to_forum == 0 || $move_to_forum == '') { echo COM_refresh($_CONF['site_url'] . "/forum/viewtopic.php?showtopic={$topic_id}"); exit; } // ensure move_to_topic is a parent id $move_to_topic_pid = DB_getItem($_TABLES['ff_topic'], 'pid', 'id=' . (int) $move_to_topic); if ($move_to_topic_pid != 0 && $move_to_topic_pid != '') { $move_to_topic = $move_to_topic_pid; } if ($curpostpid == 0) { $subject = DB_escapeString(DB_getItem($_TABLES['ff_topic'], 'subject', 'id=' . (int) $move_to_topic)); $pidDate = DB_getItem($_TABLES['ff_topic'], 'date', 'id=' . (int) $move_to_topic); $moveResult = DB_query("SELECT id,date FROM {$_TABLES['ff_topic']} WHERE pid=" . (int) $topic_id); $postCount = DB_numRows($moveResult) + 1; // Need to account for the parent post while ($movetopic = DB_fetchArray($moveResult)) { DB_query("UPDATE {$_TABLES['ff_topic']} SET forum=" . (int) $move_to_forum . ",pid=" . (int) $move_to_topic . ",subject='" . $subject . "' WHERE id=" . (int) $movetopic['id']); // check to see if we need to swap pids if ($movetopic['date'] < $pidDate) { DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=" . (int) $movetopic['id'] . " WHERE id=" . (int) $move_to_topic); DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=0 WHERE id=" . (int) $movetopic['id']); DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=" . (int) $movetopic['id'] . " WHERE pid=" . (int) $move_to_topic); $move_to_topic = $movetopic['id']; $pidDate = $movetopic['date']; } } // Update any topic subscription records - need to change the forum ID record //check if the whole forum is already subscribed to? if (DB_count($_TABLES['subscriptions'], array('type,category,id'), array('forum', (int) $move_to_forum, 0)) == 0) { DB_query("UPDATE {$_TABLES['subscriptions']} SET category=" . (int) $move_to_forum . " WHERE type='forum' AND id=" . (int) $topic_id); } else { DB_query("DELETE FROM {$_TABLES['subscriptions']} WHERE type='forum' AND id=" . (int) $topic_id); } // this moves the parent record. DB_query("UPDATE {$_TABLES['ff_topic']} SET forum=" . (int) $move_to_forum . ",pid=" . (int) $move_to_topic . ",subject='" . $subject . "' WHERE id=" . (int) $topic_id); $topicDate = DB_getItem($_TABLES['ff_topic'], 'date', 'id=' . (int) $topic_id); if ($topicDate < $pidDate) { DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=" . (int) $topic_id . " WHERE id=" . (int) $move_to_topic); DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=0 WHERE id=" . (int) $topic_id); DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=" . (int) $topic_id . " WHERE pid=" . (int) $move_to_topic); $move_to_topic = $topic_id; $pidDate = $topicDate; } // new forum $postCount = DB_Count($_TABLES['ff_topic'], 'forum', (int) $move_to_forum); $topicsQuery = DB_query("SELECT id FROM {$_TABLES['ff_topic']} WHERE forum=" . (int) $move_to_forum . " AND pid=0"); $topicCount = DB_numRows($topicsQuery); DB_query("UPDATE {$_TABLES['ff_forums']} SET topic_count=" . (int) $topicCount . ", post_count=" . (int) $postCount . " WHERE forum_id=" . (int) $move_to_forum); $sql = "SELECT count(*) AS count FROM {$_TABLES['ff_topic']} topic LEFT JOIN {$_TABLES['ff_attachments']} att ON topic.id=att.topic_id WHERE (topic.id=" . (int) $move_to_topic . " OR topic.pid=" . (int) $move_to_topic . ") and att.filename <> ''"; $result = DB_query($sql); if (DB_numRows($result) > 0) { list($attCount) = DB_fetchArray($result); DB_query("UPDATE {$_TABLES['ff_topic']} SET attachments=" . $attCount . " WHERE id=" . (int) $move_to_topic); } //oldforum $postCount = DB_Count($_TABLES['ff_topic'], 'forum', (int) $forum_id); $topicsQuery = DB_query("SELECT id FROM {$_TABLES['ff_topic']} WHERE forum=" . (int) $forum_id . " AND pid=0"); $topic_count = DB_numRows($topicsQuery); DB_query("UPDATE {$_TABLES['ff_forums']} SET topic_count=" . (int) $topic_count . ", post_count=" . (int) $postCount . " WHERE forum_id=" . (int) $forum_id); $sql = "SELECT count(*) AS count FROM {$_TABLES['ff_topic']} topic LEFT JOIN {$_TABLES['ff_attachments']} att ON topic.id=att.topic_id WHERE (topic.id=" . (int) $topic_id . " OR topic.pid=" . (int) $topic_id . ") and att.filename <> ''"; $result = DB_query($sql); if (DB_numRows($result) > 0) { list($attCount) = DB_fetchArray($result); DB_query("UPDATE {$_TABLES['ff_topic']} SET attachments=" . (int) $attCount . " WHERE id=" . (int) $topic_id); } // Update the Last Post Information gf_updateLastPost($move_to_forum, $topic_id); gf_updateLastPost($forum_id); // Remove any lastviewed records in the log so that the new updated topic indicator will appear DB_query("DELETE FROM {$_TABLES['ff_log']} WHERE topic=" . (int) $topic_id); $link = $_CONF['site_url'] . '/forum/viewtopic.php?showtopic=' . $topic_id; $retval .= FF_statusMessage($LANG_GF02['msg163'], $link, $LANG_GF02['msg163'], false, '', true); } else { $subject = DB_escapeString(DB_getItem($_TABLES['ff_topic'], 'subject', 'id=' . (int) $move_to_topic)); $sql = "UPDATE {$_TABLES['ff_topic']} SET forum=" . (int) $move_to_forum . ", pid=" . (int) $move_to_topic . ", subject='" . $subject . "' WHERE id=" . (int) $topic_id; DB_query($sql); DB_query("UPDATE {$_TABLES['ff_topic']} SET replies=replies-1 WHERE id=" . (int) $curpostpid); $movedDate = DB_getItem($_TABLES['ff_topic'], 'date', 'id=' . (int) $topic_id); $targetDate = DB_getItem($_TABLES['ff_topic'], 'date', 'id=' . (int) $move_to_topic); if ($movedDate < $targetDate) { DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=" . (int) $topic_id . " WHERE id=" . (int) $move_to_topic); DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=0 WHERE id=" . (int) $topic_id); DB_query("UPDATE {$_TABLES['ff_topic']} SET pid=" . (int) $topic_id . " WHERE pid=" . (int) $move_to_topic); $move_to_topic = $topic_id; $pidDate = $movedDate; } // Update Topic and Post Count for the effected forums // new forum $postCount = DB_Count($_TABLES['ff_topic'], 'forum', (int) $move_to_forum); $topicsQuery = DB_query("SELECT id FROM {$_TABLES['ff_topic']} WHERE forum=" . (int) $move_to_forum . " AND pid=0"); $topicCount = DB_numRows($topicsQuery); DB_query("UPDATE {$_TABLES['ff_forums']} SET topic_count=" . (int) $topicCount . ", post_count=" . (int) $postCount . " WHERE forum_id=" . (int) $move_to_forum); $sql = "SELECT count(*) AS count FROM {$_TABLES['ff_topic']} topic left join {$_TABLES['ff_attachments']} att ON topic.id=att.topic_id WHERE (topic.id=" . (int) $move_to_topic . " OR topic.pid=" . (int) $move_to_topic . ") and att.filename <> ''"; $result = DB_query($sql); if (DB_numRows($result) > 0) { list($attCount) = DB_fetchArray($result); DB_query("UPDATE {$_TABLES['ff_topic']} SET attachments=" . $attCount . " WHERE id=" . (int) $move_to_topic); } //oldforum $postCount = DB_Count($_TABLES['ff_topic'], 'forum', (int) $forum_id); $topicsQuery = DB_query("SELECT id FROM {$_TABLES['ff_topic']} WHERE forum=" . (int) $forum_id . " AND pid=0"); $topic_count = DB_numRows($topicsQuery); DB_query("UPDATE {$_TABLES['ff_forums']} SET topic_count=" . (int) $topic_count . ", post_count=" . (int) $postCount . " WHERE forum_id=" . (int) $forum_id); $sql = "SELECT count(*) AS count FROM {$_TABLES['ff_topic']} topic left join {$_TABLES['ff_attachments']} att ON topic.id=att.topic_id WHERE (topic.id=" . (int) $curpostpid . " OR topic.pid=" . (int) $curpostpid . ") and att.filename <> ''"; $result = DB_query($sql); if (DB_numRows($result) > 0) { list($attCount) = DB_fetchArray($result); DB_query("UPDATE {$_TABLES['ff_topic']} SET attachments=" . $attCount . " WHERE id=" . (int) $curpostpid); } // Update the Forum and topic indexes gf_updateLastPost($forum_id, $curpostpid); gf_updateLastPost($move_to_forum, $move_to_topic); $link = $_CONF['site_url'] . "/forum/viewtopic.php?showtopic={$topic_id}"; $retval .= FF_statusMessage($LANG_GF02['msg163'], $link, $LANG_GF02['msg163'], false, '', true); } CACHE_remove_instance('forumcb'); return $retval; }