$sql = "UPDATE $table_posts SET thread_id='".Database::escape_string($new_thread_id)."', post_parent_id='0' WHERE c_id = $course_id AND post_id='".Database::escape_string($values['post_id'])."'";
$sql = "UPDATE $table_posts SET thread_id='".intval($new_thread_id)."', post_parent_id='0'
WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'";
Database::query($sql);
// Resetting the parent_id of the thread to 0 for all those who had this moved post as parent.
$sql = "UPDATE $table_posts SET post_parent_id='0' WHERE c_id = $course_id AND post_parent_id='".Database::escape_string($values['post_id'])."'";
$sql = "UPDATE $table_posts SET post_parent_id='0'
WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'";
Database::query($sql);
// Updating updating the number of threads in the forum.
$sql = "UPDATE $table_forums SET forum_threads=forum_threads+1 WHERE c_id = $course_id AND forum_id='".Database::escape_string($current_post['forum_id'])."'";
$sql = "UPDATE $table_forums SET forum_threads=forum_threads+1
WHERE c_id = $course_id AND forum_id='".intval($current_post['forum_id'])."'";
Database::query($sql);
// Resetting the last post of the old thread and decreasing the number of replies and the thread.
$sql = "SELECT * FROM $table_posts WHERE c_id = $course_id AND thread_id='".Database::escape_string($current_post['thread_id'])."' ORDER BY post_id DESC";
$sql = "SELECT * FROM $table_posts
WHERE c_id = $course_id AND thread_id='".intval($current_post['thread_id'])."'
ORDER BY post_id DESC";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$sql = "UPDATE $table_threads SET thread_last_post='".$row['post_id']."', thread_replies=thread_replies-1 WHERE c_id = $course_id AND thread_id='".Database::escape_string($current_post['thread_id'])."'";
//$sql = "UPDATE $table_posts SET thread_id='".Database::escape_string($_POST['thread'])."', post_parent_id='0' WHERE post_id='".Database::escape_string($values['post_id'])."'";
//$result = Database::query($sql);
// Resetting the parent_id of the thread to 0 for all those who had this moved post as parent.
//$sql = "UPDATE $table_posts SET post_parent_id='0' WHERE post_parent_id='".Database::escape_string($values['post_id'])."'";
//$result = Database::query($sql);
// If this post is the last post of the thread we must update the thread_last_post with a new post_id
// Search for the original thread_id
$sql = "SELECT thread_id FROM ".$table_posts." WHERE c_id = $course_id AND post_id = '".$values['post_id']."' ";
$sql = "SELECT thread_id FROM ".$table_posts."
WHERE c_id = $course_id AND post_id = '".$values['post_id']."' ";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$original_thread_id = $row['thread_id'];
$sql = "SELECT thread_last_post FROM ".$table_threads." WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' ";
$sql = "SELECT thread_last_post FROM ".$table_threads."
WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' ";
$result = Database::query($sql);
$row = Database::fetch_array($result);
@ -4103,28 +4122,35 @@ function store_move_post($values)
// If is this thread, update the thread_last_post with the last one.
if ($thread_is_last_post == $values['post_id']) {
$sql = "SELECT post_id FROM ".$table_posts." WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' AND post_id <> '".$values['post_id']."' ORDER BY post_date DESC LIMIT 1";
$sql = "SELECT post_id FROM ".$table_posts."
WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' AND post_id <> '".$values['post_id']."'
ORDER BY post_date DESC LIMIT 1";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$thread_new_last_post = $row['post_id'];
$sql = "UPDATE ".$table_threads." SET thread_last_post = '".$thread_new_last_post."' WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' ";
$sql = "UPDATE ".$table_threads." SET thread_last_post = '".$thread_new_last_post."'
WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' ";
Database::query($sql);
}
$sql = "UPDATE $table_threads SET thread_replies=thread_replies-1 WHERE c_id = $course_id AND thread_id='".$original_thread_id."'";
$sql = "UPDATE $table_threads SET thread_replies=thread_replies-1
WHERE c_id = $course_id AND thread_id='".$original_thread_id."'";
Database::query($sql);
// moving to the chosen thread
$sql = "UPDATE $table_posts SET thread_id='".intval($_POST['thread'])."', post_parent_id='0' WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'";
$sql = "UPDATE $table_posts SET thread_id='".intval($_POST['thread'])."', post_parent_id='0'
WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'";
Database::query($sql);
// resetting the parent_id of the thread to 0 for all those who had this moved post as parent
$sql = "UPDATE $table_posts SET post_parent_id='0' WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'";
$sql = "UPDATE $table_posts SET post_parent_id='0'
WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'";
Database::query($sql);
$sql = "UPDATE $table_threads SET thread_replies=thread_replies+1 WHERE c_id = $course_id AND thread_id='".intval($_POST['thread'])."'";
$sql = "UPDATE $table_threads SET thread_replies=thread_replies+1
WHERE c_id = $course_id AND thread_id='".intval($_POST['thread'])."'";