diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index e29cc5448..d44948d35 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -32,7 +32,7 @@ class e107forum $this->setDefaults(); } // var_dump($this->prefs); - + /* $this->fieldTypes['forum_post']['post_user'] = 'int'; $this->fieldTypes['forum_post']['post_forum'] = 'int'; @@ -74,7 +74,7 @@ class e107forum } unset($tmp); } - + private function setDefaults() { $this->prefs->set('show_topics', '1'); @@ -93,7 +93,7 @@ class e107forum function getForumPermList() { $e107 = e107::getInstance(); - + $this->permList = array(); $qryList = array(); @@ -273,6 +273,44 @@ class e107forum return false; } + function threadMove($threadId, $newForumId, $threadTitle= '', $titleType=0) + { + $sql = e107::getDb(); + $threadInfo = $this->threadGet($threadId); + $oldForumId = $threadInfo['thread_forum_id']; + + //Move thread to new forum, changing thread title if needed + if($threadTitle) + { + + if($titleType == 0) + { + //prepend to existing title + $threadTitle = ", thread_name = CONCAT('{$threadTitle} ', thread_name)"; + } + else + { + //Replace title + $threadTitle = ", thread_name = '{$threadTitle}'"; + } + } + $sql->db_Update('forum_thread', "thread_forum_id={$newForumId} {$threadTitle} WHERE thread_id={$threadId}"); + + //Move all posts to new forum + $posts = $sql->db_Update('forum_post', "post_forum={$newForumId} WHERE post_thread={$threadId}"); + $replies = $posts-1; + if($replies < 0) { $replies = 0; } + + //change thread counts accordingly + $sql->db_Update('forum', "forum_threads=forum_threads-1, forum_replies=forum_replies-$replies WHERE forum_id={$oldForumId}"); + $sql->db_Update('forum', "forum_threads=forum_threads+1, forum_replies=forum_replies+$replies WHERE forum_id={$newForumId}"); + + // update lastpost information for old and new forums + $this->forumUpdateLastpost('forum', $oldForumId, false); + $this->forumUpdateLastpost('forum', $newForumId, false); + + } + function threadUpdate($threadId, $threadInfo) { $e107 = e107::getInstance(); @@ -654,7 +692,7 @@ class e107forum } return $this->modArray; } - + function isModerator($uid) { return ($uid && in_array($uid, array_keys($this->modArray))); diff --git a/e107_plugins/forum/forum_conf.php b/e107_plugins/forum/forum_conf.php index 847232b14..0d3d31343 100644 --- a/e107_plugins/forum/forum_conf.php +++ b/e107_plugins/forum/forum_conf.php @@ -68,46 +68,25 @@ if (isset($_POST['move'])) require_once(e_PLUGIN.'forum/forum_class.php'); $forum = new e107forum; - $postInfo = $forum->postGet($id, 0, 1); - $threadId = (int)$postInfo[0]['post_thread']; - $threadInfo = $forum->threadGet($threadId); - -// print_a($postInfo); -// print_a($threadInfo); -// exit; - - $oldForumId = (int)$threadInfo['thread_forum_id']; - $newForumId = (int)$_POST['forum_move']; - $newThreadName = $threadInfo['thread_name']; - $replyCount = $threadInfo['thread_total_replies']; - + $newThreadTitle = ''; if($_POST['rename_thread'] == 'add') { - $newThreadName = '['.FORCONF_27.'] '.$newThreadName; + $newThreadTitle = '['.FORCONF_27.']'; + $newThreadTitleType = 0; } elseif($_POST['rename_thread'] == 'rename' && trim($_POST['newtitle']) != '') { - $newThreadName = $e107->tp->toDB($_POST['newtitle']); + $newThreadTitle = $e107->tp->toDB($_POST['newtitle']); + $newThreadTitleType = 1; } - //Move thread to new forum, changing thread title if needed - $sql->db_Update('forum_thread', "thread_forum_id={$newForumId}, thread_name='{$newThreadName}' WHERE thread_id={$threadId}", true); + $threadId = $_GET['id']; + $toForum = $_POST['forum_move']; - //Move all posts to new forum - $sql->db_Update('forum_post', "post_forum={$newForumId} WHERE post_thread={$threadId}", true); - - //set the thread counts correctly - $sql->db_Update('forum', "forum_threads=forum_threads-1, forum_replies=forum_replies-$replyCount WHERE forum_id={$oldForumId}", true); - $sql->db_Update('forum', "forum_threads=forum_threads+1, forum_replies=forum_replies+$replyCount WHERE forum_id={$newForumId}", true); - - // update lastpost information for old and new forums - $forum->forumUpdateLastpost('forum', $oldForumId, false); - $forum->forumUpdateLastpost('forum', $newForumId, false); + $forum->threadMove($threadId, $toForum, $newThreadTitle, $newThreadTitleType); $message = FORCONF_9; -// $url = e_PLUGIN."forum/forum_viewforum.php?".$new_forum; - $url = $e107->url->getUrl('forum', 'thread', 'func=view&id='.$id); - + $url = $e107->url->getUrl('forum', 'thread', 'func=view&id='.$threadId); } if (isset($_POST['movecancel']))