/** * * @param array * @return string HTML language variable * * @author Patrick Cool <*****@*****.**>, Ghent University * @version february 2006, dokeos 1.8 */ function store_move_post($values) { $_course = api_get_course_info(); $course_id = api_get_course_int_id(); $table_forums = Database::get_course_table(TABLE_FORUM); $table_threads = Database::get_course_table(TABLE_FORUM_THREAD); $table_posts = Database::get_course_table(TABLE_FORUM_POST); if ($values['thread'] == '0') { $current_post = get_post_information($values['post_id']); // Storing a new thread. $params = ['c_id' => $course_id, 'thread_title' => $current_post['post_title'], 'forum_id' => $current_post['forum_id'], 'thread_poster_id' => $current_post['poster_id'], 'thread_poster_name' => $current_post['poster_name'], 'thread_last_post' => $values['post_id'], 'thread_date' => $current_post['post_date']]; $new_thread_id = Database::insert($table_threads, $params); api_item_property_update($_course, TOOL_FORUM_THREAD, $new_thread_id, 'visible', $current_post['poster_id']); // Moving the post to the newly created thread. $sql = "UPDATE {$table_posts} SET thread_id='" . intval($new_thread_id) . "', post_parent_id='0'\n 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'\n 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\n 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}\n WHERE c_id = {$course_id} AND thread_id='" . intval($current_post['thread_id']) . "'\n ORDER BY post_id DESC"; $result = Database::query($sql); $row = Database::fetch_array($result); $sql = "UPDATE {$table_threads} SET\n thread_last_post='" . $row['post_id'] . "',\n thread_replies=thread_replies-1\n WHERE\n c_id = {$course_id} AND\n thread_id='" . intval($current_post['thread_id']) . "'"; Database::query($sql); } else { // Moving to the chosen thread. $sql = "SELECT thread_id FROM " . $table_posts . "\n 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 . "\n WHERE c_id = {$course_id} AND thread_id = '" . $original_thread_id . "' "; $result = Database::query($sql); $row = Database::fetch_array($result); $thread_is_last_post = $row['thread_last_post']; // 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 . "\n WHERE c_id = {$course_id} AND thread_id = '" . $original_thread_id . "' AND post_id <> '" . $values['post_id'] . "'\n 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 . "'\n WHERE c_id = {$course_id} AND thread_id = '" . $original_thread_id . "' "; Database::query($sql); } $sql = "UPDATE {$table_threads} SET thread_replies=thread_replies-1\n 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'\n 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'\n 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\n WHERE c_id = {$course_id} AND thread_id='" . intval($_POST['thread']) . "'"; Database::query($sql); } return get_lang('ThreadMoved'); }
document.getElementById(\'id_qualify\').style.display = \'none\'; document.getElementById(\'img_plus_and_minus\').innerHTML=\' ' . Display::return_icon('div_show.gif', get_lang('Show'), array('style' => 'vertical-align:middle')) . ' ' . get_lang('AdvancedParameters') . '\'; } } </script>'; /* MAIN DISPLAY SECTION */ /* Retrieving forum and forum categorie information */ // We are getting all the information about the current forum and forum category. // Note pcool: I tried to use only one sql statement (and function) for this, // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table. $current_thread = get_thread_information($_GET['thread']); // Note: This has to be validated that it is an existing thread. $current_forum = get_forum_information($_GET['forum']); // Note: This has to be validated that it is an existing forum. $current_forum_category = get_forumcategory_information($current_forum['forum_category']); $current_post = get_post_information($_GET['post']); api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD); /* Header and Breadcrumbs */ if (isset($_SESSION['gradebook'])) { $gradebook = $_SESSION['gradebook']; } if (!empty($gradebook) && $gradebook == 'view') { $interbreadcrumb[] = array('url' => '../gradebook/' . $_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook')); } if ($origin == 'group') { $_clean['toolgroup'] = (int) $_SESSION['toolgroup']; $group_properties = GroupManager::get_group_properties($_clean['toolgroup']); $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups')); $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq=' . $_SESSION['toolgroup'], 'name' => get_lang('GroupSpace') . ' ' . $group_properties['name']); $interbreadcrumb[] = array('url' => 'viewforum.php?origin=' . $origin . '&gidReq=' . $_SESSION['toolgroup'] . '&forum=' . Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title'])); $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
/** * * @param array * @return string HTML language variable * * @author Patrick Cool <*****@*****.**>, Ghent University * @version february 2006, dokeos 1.8 */ function store_move_post($values) { $_course = api_get_course_info(); $course_id = api_get_course_int_id(); $table_forums = Database::get_course_table(TABLE_FORUM); $table_threads = Database::get_course_table(TABLE_FORUM_THREAD); $table_posts = Database::get_course_table(TABLE_FORUM_POST); if ($values['thread'] == '0') { $current_post = get_post_information($values['post_id']); // Storing a new thread. $sql = "INSERT INTO {$table_threads} (c_id, thread_title, forum_id, thread_poster_id, thread_poster_name, thread_last_post, thread_date)\n VALUES (\n " . $course_id . ",\n '" . Database::escape_string($current_post['post_title']) . "',\n '" . Database::escape_string($current_post['forum_id']) . "',\n '" . Database::escape_string($current_post['poster_id']) . "',\n '" . Database::escape_string($current_post['poster_name']) . "',\n '" . Database::escape_string($values['post_id']) . "',\n '" . Database::escape_string($current_post['post_date']) . "'\n )"; Database::query($sql); $new_thread_id = Database::insert_id(); api_item_property_update($_course, TOOL_FORUM_THREAD, $new_thread_id, 'visible', $current_post['poster_id']); // Moving the post to the newly created thread. $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']) . "'"; 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']) . "'"; 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']) . "'"; 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"; $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']) . "'"; Database::query($sql); } else { // Moving to the chosen thread. //Old code //$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'] . "' "; $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 . "' "; $result = Database::query($sql); $row = Database::fetch_array($result); $thread_is_last_post = $row['thread_last_post']; // 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"; $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 . "' "; Database::query($sql); } $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']) . "'"; 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']) . "'"; Database::query($sql); $sql = "UPDATE {$table_threads} SET thread_replies=thread_replies+1 WHERE c_id = {$course_id} AND thread_id='" . intval($_POST['thread']) . "'"; Database::query($sql); } return get_lang('ThreadMoved'); }