".getgroupname($mod_group)."" : getgroupname($mod_group); } } } return (string)$moderators; } /** * Set a post id * * @param $value */ public function setPostId($value) { $this->post_id = $value; } /** * Set a thread id * * @param $value */ public function setThreadId($value) { $this->thread_id = $value; } /** * Set a forum id * * @param $value */ public function setForumID($value) { $this->forum_id = $value; } public function set_modActions() { $this->locale = fusion_get_locale('', FORUM_LOCALE); $this->form_action = FORUM.'viewthread.php?thread_id='.$this->thread_id.(isset($_GET['rowstart']) && isnum($_GET['rowstart']) ? "&rowstart=".$_GET['rowstart'] : ''); if (!isset($_GET['rowstart'])) { $_GET['rowstart'] = 0; } if (isset($_POST['step']) && $_POST['step'] != "") { $_GET['step'] = $_POST['step']; } $_GET['step'] = isset($_GET['step']) && in_array($_GET['step'], $this->allowed_actions) ? $_GET['step'] : ''; $_GET['error'] = isset($_GET['error']) ? $_GET['error'] : ''; if ($this->thread_id && !$this->forum_id) { $forum_id_data = dbarray(dbquery("SELECT forum_id FROM ".DB_FORUM_THREADS." WHERE thread_id='".$this->thread_id."'")); $this->forum_id = $forum_id_data['forum_id']; } // get forum parents $branch_data = dbarray(dbquery("SELECT forum_cat, forum_branch FROM ".DB_FORUMS." WHERE forum_id='".$this->forum_id."'")); $this->parent_id = $branch_data['forum_cat']; $this->branch_id = $branch_data['forum_branch']; // at any time when cancel is clicked, redirect to forum id. if (isset($_POST['cancelDelete'])) { redirect(FORUM."viewthread.php?thread_id=".intval($this->thread_id)); } /** * Thread actions */ switch ($_GET['step']) { case 'renew': self::mod_renew_thread(); break; case 'delete': self::mod_delete_thread(); break; case 'lock': self::mod_lock_thread(); break; case 'unlock': self::mod_unlock_thread(); break; case 'sticky': self::mod_sticky_thread(); break; case 'nonsticky': self::mod_nonsticky_thread(); break; case 'move': self::mod_move_thread(); break; } $message = ''; switch ($_GET['error']) { case '1': $message = $this->locale['error-MP001']; break; case '2': $message = $this->locale['error-MP002']; break; case '3': $message = $this->locale['forum_0307']; break; } if ($message != "") { opentable($this->locale['error-MP000']); echo "
".$message."

\n"; echo "".$this->locale['forum_0309']."
"; echo "
\n"; closetable(); } // Delete Posts self::mod_delete_posts(); // Move Posts self::mod_move_posts(); } /** * Moderator Action - Renew Thread Action * Modal pop up confirmation of thread being `renewed` */ private function mod_renew_thread() { if (iMOD) { $result = dbquery("SELECT p.post_id, p.post_author, p.post_datestamp, f.forum_id, f.forum_cat FROM ".DB_FORUM_POSTS." p INNER JOIN ".DB_FORUM_THREADS." t ON p.thread_id=t.thread_id INNER JOIN ".DB_FORUMS." f on f.forum_id = t.forum_id WHERE p.thread_id='".intval($this->thread_id)."' AND t.thread_hidden=0 AND p.post_hidden=0 ORDER BY p.post_id DESC LIMIT 1 "); if (dbrows($result)) { $data = dbarray($result); // update the last post timestamp dbquery("UPDATE ".DB_FORUM_POSTS." SET post_datestamp=:time WHERE post_id=:post_id", [':time' => TIME, ':post_id' => $data['post_id']]); // update the thread last post timestamp dbquery("UPDATE ".DB_FORUM_THREADS." SET thread_lastpost=:time, thread_lastpostid=:post_id, thread_lastuser=:post_author WHERE thread_id=:thread_id", [ ':time' => TIME, ':post_id' => $data['post_id'], ':post_author' => $data['post_author'], ':thread_id' => intval($this->thread_id) ]); // update forum lastpost timestamp dbquery("UPDATE ".DB_FORUMS." SET forum_lastpost=:time, forum_lastuser=:post_author WHERE forum_id=:forum_id", [ ':time' => TIME, ':post_author' => $data['post_author'], ':forum_id' => $data['forum_id'] ]); ob_start(); echo openmodal('renew', $this->locale['forum_0207'], ['class' => 'modal-center', 'static' => 1]); echo "

\n".$this->locale['forum_0759']."

\n"; echo "".$this->locale['forum_0549']."

\n"; echo "".$this->locale['forum_0550']."

\n"; echo closemodal(); add_to_footer(ob_get_clean()); } else { redirect(FORUM.'index.php'); } } } /** * Moderator Action - Delete Thread * Modal pop up confirmation of thread being `removed` */ private function mod_delete_thread() { if (iMOD) { ob_start(); echo openmodal('deletethread', $this->locale['forum_0201'], ['class' => 'modal-center']); echo "

\n"; if (!isset($_POST['deletethread'])) { echo openform('delform', 'post', $this->form_action."&step=delete"); echo $this->locale['forum_0704']."

\n"; echo form_button('deletethread', $this->locale['yes'], $this->locale['yes'], ['class' => 'm-r-10 btn-danger']); echo form_button('cancelDelete', $this->locale['no'], $this->locale['no'], ['class' => 'm-r-10 btn-default']); echo "\n"; echo closeform(); } else { // reset every user post count as if they never posted before self::unset_userpost(); // then we remove thread. outputs information what have been deleted $response = self::remove_thread(); // refresh forum information as if thread never existed self::refresh_forum(TRUE); if ($response == TRUE) { echo $this->locale['forum_0701']."

\n"; echo "".$this->locale['forum_0549']."

\n"; echo "".$this->locale['forum_0550']."

\n"; } else { echo $this->locale['forum_0705']; } } echo "
\n"; echo closemodal(); add_to_footer(ob_get_clean()); } } /** * Unset User Post based on Thread id * This function assumes as if user have never posted before * * @return int - number of posts that user have made in this thread */ private function unset_userpost() { $post_count = 0; if (self::verify_thread($this->thread_id)) { $result = dbquery("SELECT post_author, COUNT(post_id) as num_posts FROM ".DB_FORUM_POSTS." WHERE thread_id='".$this->thread_id."' GROUP BY post_author"); $rows = dbrows($result); if ($rows > 0) { while ($pdata = dbarray($result)) { dbquery("UPDATE ".DB_USERS." SET user_posts=user_posts-".$pdata['num_posts']." WHERE user_id='".$pdata['post_author']."'"); $post_count = $pdata['num_posts'] + $post_count; } } } return (int)$post_count; } /** * SQL action remove thread * - post deleted * - attachment deleted * - user thread tracking deleted. */ private function remove_thread() { $response = FALSE; if (self::verify_thread($this->thread_id) && self::verify_forum($this->forum_id)) { $param = [':thread_id' => intval($this->thread_id)]; // Delete all thread posts dbquery("DELETE FROM ".DB_FORUM_POSTS." WHERE thread_id=:thread_id", $param); // Delete all thread notifications dbquery("DELETE FROM ".DB_FORUM_THREAD_NOTIFY." WHERE thread_id=:thread_id", $param); // Delete all attachment files $result = dbquery("SELECT attach_name FROM ".DB_FORUM_ATTACHMENTS." WHERE thread_id=:thread_id", $param); if (dbrows($result)) { while ($attach = dbarray($result)) { if (file_exists(INFUSIONS."forum/attachments/".$attach['attach_name'])) { @unlink(INFUSIONS."forum/attachments/".$attach['attach_name']); } } } // Delete all attachments dbquery("DELETE FROM ".DB_FORUM_ATTACHMENTS." WHERE thread_id=:thread_id", $param); // Delete all poll voters dbquery("DELETE FROM ".DB_FORUM_POLL_VOTERS." WHERE thread_id=:thread_id", $param); // Delete all Poll Options dbquery("DELETE FROM ".DB_FORUM_POLL_OPTIONS." WHERE thread_id=:thread_id", $param); // Delete Thread Poll dbquery("DELETE FROM ".DB_FORUM_POLLS." WHERE thread_id=:thread_id", $param); // Delete The Thread dbquery("DELETE FROM ".DB_FORUM_THREADS." WHERE thread_id=:thread_id", $param); $response = TRUE; } return (boolean)$response; } /** * Refresh db_forum forum's stats * * @param bool $delete_thread true if thread deletion */ private function refresh_forum($delete_thread = FALSE) { if (self::verify_forum($this->forum_id)) { $remaining_threads_count = dbcount("(forum_id)", DB_FORUM_THREADS, "forum_id='$this->forum_id'"); // last post id from a given forum id. if ($remaining_threads_count) { $result = dbquery("SELECT p.forum_id, p.post_id, p.post_author, p.post_datestamp, COUNT(p.post_id) AS post_count FROM ".DB_FORUM_POSTS." p INNER JOIN ".DB_FORUMS." fo ON p.forum_id=fo.forum_id WHERE p.forum_id='".(int)$this->forum_id."' AND p.post_hidden='0' GROUP BY p.post_id ORDER BY p.post_datestamp DESC LIMIT 1"); if (dbrows($result) > 0) { $pdata = dbarray($result); // yielded LAST post dbquery("UPDATE ".DB_FORUMS." SET forum_lastpostid = '".$pdata['post_id']."', forum_lastpost = '".$pdata['post_datestamp']."', forum_postcount = '".$pdata['post_count']."', ".($delete_thread ? "forum_threadcount = '".(dbcount("(thread_id)", DB_FORUM_THREADS, "forum_id='".$this->forum_id."'"))."'," : '')." forum_lastuser = '".$pdata['post_author']."' WHERE forum_id = '".$this->forum_id."' "); } } else { dbquery("UPDATE ".DB_FORUMS." SET forum_lastpostid = '0', forum_lastpost='0', forum_postcount=0, forum_threadcount=0, forum_lastuser='0' WHERE forum_id='".intval($this->forum_id)."'"); } } } /** * Moderator Action - Lock Thread * Modal pop up confirmation of thread being `locked` */ private function mod_lock_thread() { if (iMOD) { dbquery("UPDATE ".DB_FORUM_THREADS." SET thread_locked='1' WHERE thread_id='".intval($this->thread_id)."' AND thread_hidden='0'"); ob_start(); echo openmodal('lockthread', $this->locale['forum_0202'], ['class' => 'modal-center']); echo "

\n"; echo "".$this->locale['forum_0711']."

\n"; echo "".$this->locale['forum_0549']."

\n"; echo "".$this->locale['forum_0550']."

\n
\n"; echo closemodal(); add_to_footer(ob_get_contents()); ob_end_clean(); } } /** * Moderator Action - Unlock Thread * Modal pop up confirmation of thread being `unlocked` */ protected function mod_unlock_thread() { if (iMOD) { dbquery("UPDATE ".DB_FORUM_THREADS." SET thread_locked='0' WHERE thread_id='".intval($this->thread_id)."' AND thread_hidden='0'"); ob_start(); echo openmodal('lockthread', $this->locale['forum_0720'], ['class' => 'modal-center']); echo "

\n"; echo "".$this->locale['forum_0721']."

\n"; echo "".$this->locale['forum_0549']."

\n"; echo "".$this->locale['forum_0550']."

\n
\n"; echo closemodal(); add_to_footer(ob_get_contents()); ob_end_clean(); } } /** * Moderator Action - Sticky Thread * Modal pop up confirmation of thread being `sticky` */ protected function mod_sticky_thread() { if (iMOD) { dbquery("UPDATE ".DB_FORUM_THREADS." SET thread_sticky='1' WHERE thread_id='".intval($this->thread_id)."' AND thread_hidden='0'"); ob_start(); echo openmodal('lockthread', $this->locale['forum_0204'], ['class' => 'modal-center']); echo "

\n"; echo "".$this->locale['forum_0731']."

\n"; echo "".$this->locale['forum_0549']."

\n"; echo "".$this->locale['forum_0550']."

\n
\n"; echo closemodal(); add_to_footer(ob_get_contents()); ob_end_clean(); } } /** * Moderator Action - Non Sticky Thread * Modal pop up confirmation of thread being `un-sticky` */ protected function mod_nonsticky_thread() { if (iMOD) { dbquery("UPDATE ".DB_FORUM_THREADS." SET thread_sticky='0' WHERE thread_id='".intval($this->thread_id)."' AND thread_hidden='0'"); ob_start(); echo openmodal('lockthread', $this->locale['forum_0205'], ['class' => 'modal-center']); echo "

\n"; echo "".$this->locale['forum_0741']."

\n"; echo "".$this->locale['forum_0549']."

\n"; echo "".$this->locale['forum_0550']."

\n"; echo closemodal(); add_to_footer(ob_get_contents()); ob_end_clean(); } } /** * Moderator Action - Move Thread */ private function mod_move_thread() { if (iMOD) { ob_start(); echo openmodal('movethread', $this->locale['forum_0206'], ['class' => 'modal-center']); if (isset($_POST['move_thread'])) { $new_forum_id = filter_input(INPUT_POST, 'new_forum_id', FILTER_VALIDATE_INT); $forum_id = intval($this->forum_id); $thread_id = intval($this->thread_id); // new forum does not exist. if (!$new_forum_id || !self::verify_forum($new_forum_id)) { redirect(INFUSIONS."forum/index.php"); } // thread id is hidden, and thread does not exist. if (!dbcount("(thread_id)", DB_FORUM_THREADS, "thread_id=".$thread_id." AND thread_hidden='0'")) { redirect(INFUSIONS."forum/index.php"); } $currentThreadPostCount = dbcount("(post_id)", DB_FORUM_POSTS, "thread_id=".$thread_id); // total post in current thread $currentThreadArray = dbarray( dbquery("SELECT thread_lastpost, thread_lastpostid, thread_lastuser FROM ".DB_FORUM_THREADS." WHERE thread_id=".$thread_id." AND thread_hidden='0'") ); if ($currentThreadPostCount == 0 || empty($currentThreadArray)) { redirect(INFUSIONS."forum/index.php"); } $newForumSql = "SELECT forum_lastpostid, forum_lastpost, forum_lastuser FROM ".DB_FORUMS." WHERE forum_id = '".$new_forum_id."' AND forum_type !='1'"; $newForumResult = dbquery($newForumSql); if (dbrows($newForumResult) > 0) { $newForumArray = dbarray($newForumResult); if ($currentThreadArray['thread_lastpost'] > $newForumArray['forum_lastpost']) { // As the current thread has a later datestamp than the target forum, copy current thread stats to the target forum. dbquery("UPDATE ".DB_FORUMS." SET forum_lastpost='".$currentThreadArray['thread_lastpost']."', forum_lastpostid = '".$currentThreadArray['thread_lastpostid']."', forum_postcount=forum_postcount+".$currentThreadPostCount.", forum_threadcount=forum_threadcount+1, forum_lastuser='".$currentThreadArray['thread_lastuser']."' WHERE forum_id=".$new_forum_id ); } else { // update add the postcount with the total postcount of current thread, and up +1 threadcount on the target forum dbquery("UPDATE ".DB_FORUMS." SET forum_postcount=forum_postcount+".$currentThreadPostCount.", forum_threadcount=forum_threadcount+1 WHERE forum_id=".$new_forum_id ); } dbquery("UPDATE ".DB_FORUM_THREADS." SET forum_id=".$new_forum_id." WHERE thread_id=".$thread_id); dbquery("UPDATE ".DB_FORUM_POSTS." SET forum_id=".$new_forum_id." WHERE thread_id=".$thread_id); $bestForumLastThread = dbarray(dbquery("select * from ".DB_FORUM_THREADS." where forum_id='".$forum_id."' order by thread_lastpost desc limit 1")); dbquery("UPDATE ".DB_FORUMS." SET forum_postcount=forum_postcount-".$currentThreadPostCount.", forum_threadcount=forum_threadcount-1, forum_lastpost='".$bestForumLastThread['thread_lastpost']."', forum_lastpostid = '".$bestForumLastThread['thread_lastpostid']."', forum_lastuser='".$bestForumLastThread['thread_lastuser']."' WHERE forum_id=".$forum_id ); addNotice('success', $this->locale['forum_0752']); } redirect(INFUSIONS."forum/viewthread.php?thread_id=".$this->thread_id); } else { echo openform('moveform', 'post', INFUSIONS."forum/viewthread.php?forum_id=".$this->forum_id."&thread_id=".$this->thread_id."&step=move"); // disable all forum that is type 1. $disabled_opts[] = $this->forum_id; $disabled_sql = "SELECT forum_id FROM ".DB_FORUMS." WHERE forum_type='1'"; $forum_search = dbquery($disabled_sql); if (dbrows($forum_search) > 0) { while ($disabled_data = dbarray($forum_search)) { $disabled_opts[] = $disabled_data['forum_id']; } } echo form_select_tree('new_forum_id', $this->locale['forum_0751'], '', [ 'input_id' => "new_forum_id", 'no_root' => TRUE, 'inline' => TRUE, 'disable_opts' => $disabled_opts ], DB_FORUMS, 'forum_name', 'forum_id', 'forum_cat'). form_button('move_thread', $this->locale['forum_0206'], $this->locale['forum_0206'], ['class' => 'btn-primary']). closeform(); } echo closemodal(); add_to_footer(ob_get_contents()); ob_end_clean(); } } /** * Moderator Action - Remove only selected post in a thread * Requires $_POST['delete_posts'] * refer to - viewthread_options.php */ private function mod_delete_posts() { $del_posts = ''; if (isset($_POST['delete_posts']) && iMOD) { $post_items = form_sanitizer($_POST['delete_item_post'], '', 'delete_item_post'); $post_items = explode(',', $post_items); $post_items = array_filter($post_items); if (!empty($post_items)) { // the checkboxes $thread_count = FALSE; $i = 0; foreach ($post_items as $del_post_id) { if (isnum($del_post_id)) { $del_posts .= ($del_posts ? "," : "").$del_post_id; $i++; } } if (!empty($del_posts)) { // Update User Posts $calculate_post = "SELECT post_author, COUNT(post_id) as num_posts FROM ".DB_FORUM_POSTS." WHERE post_id IN (".$del_posts.") GROUP BY post_author"; $find_attachments = "SELECT attach_name FROM ".DB_FORUM_ATTACHMENTS." WHERE post_id IN (".$del_posts.")"; $delete_attachments = "DELETE FROM ".DB_FORUM_ATTACHMENTS." WHERE thread_id='".intval($this->thread_id)."' AND post_id IN(".$del_posts.")"; $delete_forum_posts = "DELETE FROM ".DB_FORUM_POSTS." WHERE thread_id='".intval($this->thread_id)."' AND post_id IN(".$del_posts.")"; $find_lastpost = "SELECT post_datestamp, post_author, post_id FROM ".DB_FORUM_POSTS." WHERE thread_id='".intval($this->thread_id)."' ORDER BY post_datestamp DESC LIMIT 1"; // also need to delete post_mood $result = dbquery($calculate_post); if (dbrows($result) > 0) { while ($pdata = dbarray($result)) { dbquery("UPDATE ".DB_USERS." SET user_posts=user_posts-".intval($pdata['num_posts'])." WHERE user_id='".intval($pdata['post_author'])."'"); } } // Delete attachments $result = dbquery($find_attachments); if (dbrows($result)) { while ($adata = dbarray($result)) { $file_path = INFUSIONS."forum/attachments/".$adata['attach_name']; if (file_exists($file_path) && !is_dir($file_path)) { @unlink($file_path); } } } dbquery($delete_attachments); dbquery($delete_forum_posts); if (!dbcount("(post_id)", DB_FORUM_POSTS, "thread_id='".intval($this->thread_id)."'")) { dbquery("DELETE FROM ".DB_FORUM_THREADS." WHERE thread_id='".intval($this->thread_id)."'"); } else { // Find last post $pdata = dbarray(dbquery($find_lastpost)); dbquery(" UPDATE ".DB_FORUM_THREADS." SET thread_lastpost='".$pdata['post_datestamp']."', thread_lastpostid='".$pdata['post_id']."', thread_postcount = '".dbcount("(post_id)", DB_FORUM_POSTS, "thread_id='".$this->thread_id."'")."', thread_lastuser='".$pdata['post_author']."' WHERE thread_id='".intval($this->thread_id)."' "); $thread_count = TRUE; } $delete_thread = $thread_count ? FALSE : TRUE; self::refresh_forum($delete_thread); addNotice('success', $this->locale['success-DP001']); if ($thread_count === FALSE) { // no remaining thread addNotice('success', $this->locale['success-DP002']); redirect(INFUSIONS."forum/index.php?viewforum&forum_id=".$this->forum_id."&parent_id=".$this->parent_id); } } else { addNotice('danger', $this->locale['error-DP001']); redirect($this->form_action); } } else { addNotice('danger', $this->locale['error-DP001']); redirect($this->form_action); } } } /** * Moving Posts */ private function mod_move_posts() { if (isset($_POST['move_posts']) && iMOD) { $remove_first_post = FALSE; $f_post_blo = FALSE; $post_items = form_sanitizer($_POST['delete_item_post'], '', 'delete_item_post'); // The selected checkbox of post to move. $post_items = explode(',', $post_items); $post_items = array_filter($post_items); if (!empty($post_items)) { //define('STOP_REDIRECT', true); $first_post = dbarray(dbquery("SELECT post_id FROM ".DB_FORUM_POSTS." WHERE thread_id='".intval($this->thread_id)."' ORDER BY post_datestamp ASC LIMIT 1")); /** * Scan for Posts */ $move_posts = ""; $array_post = []; $first_post_found = FALSE; foreach ($post_items as $move_post_id) { if (isnum($move_post_id)) { $move_posts .= ($move_posts ? "," : "").$move_post_id; $array_post[] = $move_post_id; if ($move_post_id == $first_post['post_id']) { $first_post_found = TRUE; } } } // found post items. if (!empty($move_posts)) { // Current Status Before Move. $move_result = dbquery("SELECT forum_id, thread_id, COUNT(post_id) 'num_posts' FROM ".DB_FORUM_POSTS." WHERE post_id IN (".$move_posts.") AND thread_id='".intval($this->thread_id)."' GROUP BY thread_id"); if (dbrows($move_result)) { $pdata = dbarray($move_result); $post_count = dbcount("(post_id)", DB_FORUM_POSTS, "thread_id='".intval($pdata['thread_id'])."'"); ob_start(); echo openmodal('forum0300', $this->locale['forum_0176'], ['class' => 'modal-center']); if ($first_post_found) { // there is a first post. echo "
"; if ($pdata['num_posts'] != $post_count) { $remove_first_post = TRUE; echo str_replace(['[STRONG]', '[/STRONG]'], ['', ''], $this->locale['forum_0305'])."
\n"; // trying to remove first post with other post in the thread } else { echo str_replace(['[STRONG]', '[/STRONG]'], ['', ''], $this->locale['forum_0306'])."
\n"; // confirm ok to remove first post. } if ($remove_first_post && count($array_post) == 1) { echo "
".$this->locale['forum_0307']."

\n"; // no post to move. echo "".$this->locale['forum_0309'].""; $f_post_blo = TRUE; } echo "
\n"; } if (!isset($_POST['new_forum_id']) && !$f_post_blo) { $fl_result = dbquery(" SELECT f.forum_id, f.forum_name, f.forum_type, f2.forum_name 'forum_cat_name', ( SELECT COUNT(thread_id) FROM ".DB_FORUM_THREADS." th WHERE f.forum_id=th.forum_id AND th.thread_id !='".intval($this->thread_id)."' GROUP BY th.forum_id ) AS threadcount FROM ".DB_FORUMS." f LEFT JOIN ".DB_FORUMS." f2 ON f.forum_cat=f2.forum_id WHERE ".groupaccess('f.forum_access')." ORDER BY f2.forum_order ASC, f.forum_order ASC "); if (dbrows($fl_result)) { $exclude_opts = []; while ($data = dbarray($fl_result)) { if (empty($data['threadcount']) || $data['forum_type'] == '1') { $exclude_opts[] = $data['forum_id']; } } echo openform('modopts', 'post', $this->form_action); echo form_select_tree('new_forum_id', $this->locale['forum_0301'], '', [ 'disable_opts' => $exclude_opts, 'no_root' => 1, 'inline' => FALSE, 'inner_width' => '100%' ], DB_FORUMS, 'forum_name', 'forum_id', 'forum_cat'); foreach ($array_post as $value) { echo form_hidden("delete_item_post[]", "", $value, ["input_id" => "delete_post[$value]"]); } echo form_hidden('move_posts', '', 1); echo modalfooter( form_button($this->locale['forum_0302'], $this->locale['forum_0208'], $this->locale['forum_0208'], ['class' => 'btn-primary']) ); echo closeform(); } else { echo "".$this->locale['forum_0310']."

\n"; echo "".$this->locale['forum_0309']."

\n"; } } else if (isset($_POST['new_forum_id']) && isnum($_POST['new_forum_id']) && !isset($_POST['new_thread_id']) && !isset($_POST['new_thread_subject']) && !$f_post_blo) { // Select Threads in Selected Forum. // build the list. $tl_result = dbquery(" SELECT thread_id, thread_subject FROM ".DB_FORUM_THREADS." WHERE forum_id='".intval($_POST['new_forum_id'])."' AND thread_id !='".intval($pdata['thread_id'])."' AND thread_hidden='0' ORDER BY thread_subject ASC "); if (dbrows($tl_result)) { $thread_list = []; while ($tl_data = dbarray($tl_result)) { $thread_list[$tl_data['thread_id']] = $tl_data['thread_subject']; } echo openform('modopts', 'post', $this->form_action."&sv"); echo form_hidden('new_forum_id', '', $_POST['new_forum_id']); // has val if (!isset($_POST['new_thread_select'])) { echo form_checkbox('new_thread_select', '', '', [ 'type' => 'radio', 'options' => [ 0 => $this->locale['forum_0300'], 1 => $this->locale['forum_0303'], ], 'inline' => TRUE, 'required' => TRUE, ]); } else { $thread_type = stripinput($_POST['new_thread_select']); if (!empty($thread_type)) { echo form_select('new_thread_id', $this->locale['forum_0303'], '', [ 'options' => $thread_list, 'inline' => FALSE, 'inner_width' => '100%', ]); echo form_hidden('new_thread_select', '', 0); } else { echo form_text('new_thread_subject', $this->locale['forum_2000'], '', ['required' => TRUE, 'max_length' => 250, 'inline' => FALSE]); echo form_hidden('new_thread_select', '', 1); } } foreach ($array_post as $value) { echo form_hidden("delete_item_post[]", "", $value, ["input_id" => "delete_post[$value]"]); } echo form_hidden('move_posts', '', 1); echo modalfooter( form_button($this->locale['forum_0176'], $this->locale['forum_0208'], $this->locale['forum_0208'], ['class' => 'btn-primary']) ); } else { echo $this->locale['forum_0308']."

\n"; echo "".$this->locale['forum_0309']."\n"; } } else if (isset($_GET['sv']) && isset($_POST['new_forum_id']) && isnum($_POST['new_forum_id']) && isset($_POST['new_thread_id']) && isnum($_POST['new_thread_id']) || isset($_POST['new_thread_subject'])) { $_POST['new_thread_id'] = isset($_POST['new_thread_id']) ? $_POST['new_thread_id'] : 0; /** * Execute move posts */ $move_posts_add = ''; $param = [ ':new_thread_id' => intval($_POST['new_thread_id']), ':new_forum_id' => intval($_POST['new_forum_id']) ]; // Redirect if there is no thread count if (!dbcount("(thread_id)", DB_FORUM_THREADS, "thread_id=:new_thread_id AND forum_id=:new_forum_id", $param)) { if (!empty($_POST['new_thread_id'])) { addNotice('danger', $this->locale['error-MP001']); redirect($this->form_action); } } // Selects all current selected posts foreach ($array_post as $move_post_id) { if (isnum($move_post_id)) { if ($first_post_found && $remove_first_post) { if ($move_post_id != $first_post['post_id']) { $move_posts_add .= ($move_posts_add ? "," : "").$move_post_id; } $pdata['num_posts'] = $pdata['num_posts'] - 1; } else { $move_posts_add = $move_post_id.($move_posts_add ? "," : "").$move_posts_add; } } } if (!empty($move_posts_add)) { // Validate if all the post belongs to the thread? if ($pdata['num_posts'] == count($array_post)) { // Create a new thread if (!empty($_POST['new_thread_subject'])) { $thread_subject = form_sanitizer($_POST['new_thread_subject']); $author_result = dbarray(dbquery("SELECT post_author FROM ".DB_FORUM_POSTS." WHERE post_id IN ($move_posts_add) ORDER BY post_datestamp ASC LIMIT 1")); // Create a Thread $new_thread_data = [ 'thread_id' => 0, 'forum_id' => intval($_POST['new_forum_id']), 'thread_subject' => $thread_subject, 'thread_author' => $author_result['post_author'], ]; $param[':new_thread_id'] = dbquery_insert(DB_FORUM_THREADS, $new_thread_data, 'save', ['keep_session' => TRUE]); } // Update all selected posts with new thread and forum ID dbquery("UPDATE ".DB_FORUM_POSTS." SET forum_id=:new_forum_id, thread_id=:new_thread_id, post_datestamp='".TIME."' WHERE post_id IN (".$move_posts_add.")", $param); // Update all thread attachments with new thread ID dbquery("UPDATE ".DB_FORUM_ATTACHMENTS." SET thread_id=:new_thread_id WHERE post_id IN(".$move_posts_add.")", [':new_thread_id' => $param[':new_thread_id']]); // Get the latest post $new_thread = dbarray(dbquery(" SELECT post_id, post_author, post_datestamp FROM ".DB_FORUM_POSTS." WHERE thread_id=:new_thread_id ORDER BY post_datestamp DESC LIMIT 1 ", [':new_thread_id' => $param[':new_thread_id']] )); $param[':thread_lastpost'] = $new_thread['post_datestamp']; $param[':thread_lastpostid'] = $new_thread['post_id']; $param[':thread_lastuser'] = $new_thread['post_author']; // ReUpdate the target thread dbquery(" UPDATE ".DB_FORUM_THREADS." SET thread_lastpost=:thread_lastpost, thread_lastpostid=:thread_lastpostid, thread_postcount=thread_postcount+".intval($pdata['num_posts']).", thread_lastuser=:thread_lastuser WHERE thread_id=:new_thread_id", [ ':thread_lastpost' => $param[':thread_lastpost'], ':thread_lastpostid' => $param[':thread_lastpostid'], ':thread_lastuser' => $param[':thread_lastuser'], ':new_thread_id' => $param[':new_thread_id'] ] ); // Re update the target forum dbquery("UPDATE ".DB_FORUMS." SET forum_lastpost=:thread_lastpost, forum_postcount=forum_postcount+".intval($pdata['num_posts']).", forum_lastuser=:thread_lastuser WHERE forum_id=:new_forum_id", [ ':thread_lastpost' => $param[':thread_lastpost'], ':thread_lastuser' => $param[':thread_lastuser'], ':new_forum_id' => $param[':new_forum_id'] ]); // If Current Thread has no more post if (!dbcount("(post_id)", DB_FORUM_POSTS, "thread_id='".intval($pdata['thread_id'])."'")) { // Select $forum_lastpost_res = dbarray(dbquery(" SELECT post_author, post_datestamp FROM ".DB_FORUM_POSTS." WHERE forum_id='".intval($pdata['forum_id'])."' ORDER BY post_datestamp DESC LIMIT 1 ")); dbquery("UPDATE ".DB_FORUMS." SET forum_lastpost='".intval($forum_lastpost_res['post_datestamp'])."', forum_postcount=forum_postcount-".intval($pdata['num_posts']).", forum_threadcount='".(dbcount("(thread_id)", DB_FORUM_THREADS, "forum_id='".intval($pdata['forum_id'])."'") - 1)."', forum_lastuser='".intval($forum_lastpost_res['post_author'])."' WHERE forum_id='".intval($pdata['forum_id'])."'"); dbquery("DELETE FROM ".DB_FORUM_THREADS." WHERE thread_id='".intval($pdata['thread_id'])."'"); dbquery("DELETE FROM ".DB_FORUM_THREAD_NOTIFY." WHERE thread_id='".intval($pdata['thread_id'])."'"); dbquery("DELETE FROM ".DB_FORUM_POLL_VOTERS." WHERE thread_id='".intval($pdata['thread_id'])."'"); dbquery("DELETE FROM ".DB_FORUM_POLL_OPTIONS." WHERE thread_id='".intval($pdata['thread_id'])."'"); dbquery("DELETE FROM ".DB_FORUM_POLLS." WHERE thread_id='".intval($pdata['thread_id'])."'"); } else { $thread_lastpost_res = dbarray(dbquery(" SELECT forum_id, thread_id, post_id, post_author, post_datestamp FROM ".DB_FORUM_POSTS." WHERE thread_id='".intval($pdata['thread_id'])."' ORDER BY post_datestamp DESC LIMIT 1 ")); dbquery("UPDATE ".DB_FORUM_THREADS." SET thread_lastpost='".intval($thread_lastpost_res['post_datestamp'])."', thread_lastpostid='".intval($thread_lastpost_res['post_id'])."', thread_postcount=thread_postcount-".intval($pdata['num_posts']).", thread_lastuser='".intval($thread_lastpost_res['post_author'])."' WHERE thread_id='".intval($pdata['thread_id'])."'"); dbquery("UPDATE ".DB_FORUMS." SET forum_lastpost='".intval($thread_lastpost_res['post_datestamp'])."', forum_postcount=forum_postcount-".intval($pdata['num_posts']).", forum_lastuser='".intval($thread_lastpost_res['post_author'])."' WHERE forum_id='".intval($pdata['forum_id'])."'"); } $pid = count($array_post) - 1; addNotice('success', 'Posts have been moved'); redirect(FORUM."viewthread.php?thread_id=".$param[':new_thread_id']."&pid=".$array_post[$pid]."#post_".$array_post[$pid]); } else { addNotice('danger', $this->locale['error-MP002']); redirect($this->form_action); } } else { addNotice('danger', $this->locale['forum_0307']); redirect($this->form_action); } } echo closemodal(); add_to_footer(ob_get_contents()); ob_end_clean(); } else { addNotice('danger', $this->locale['error-MP002']); redirect($this->form_action); } } else { addNotice('danger', $this->locale['forum_0307']); // No post to move //redirect($this->form_action); } } else { addNotice('danger', $this->locale['forum_0307']); // No post to move //redirect($this->form_action); } } } }