Format code, removing globals.

1.9.x
Julio Montoya 12 years ago
parent 5c44fa72ee
commit 363589e1ed
  1. 2
      main/forum/editpost.php
  2. 229
      main/forum/forumfunction.inc.php
  3. 4
      main/forum/newthread.php
  4. 4
      main/forum/reply.php

@ -195,7 +195,7 @@ echo "</tr>";
echo '</table>';
// The form for the reply
$values = show_edit_post_form($current_post, $current_thread, $current_forum, isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '');
$values = show_edit_post_form($forum_setting, $current_post, $current_thread, $current_forum, isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '');
if (!empty($values) and isset($_POST['SubmitPost'])) {
store_edit_post($values);

@ -1,6 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
* These files are a complete rework of the forum. The database structure is
* based on phpBB but all the code is rewritten. A lot of new functionalities
@ -32,8 +31,6 @@ require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.
get_notifications_of_user();
/* Javascript */
$htmlHeadXtra[] = '<script type="text/javascript">
function setFocus(){
$("#forum_title").focus();
@ -185,14 +182,13 @@ function show_add_forumcategory_form($inputvalues = array(), $lp_id)
* @return void HTML
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* Juan Carlos Raña Trabado (return to lp_id)
* @author Juan Carlos Raña Trabado (return to lp_id)
*
* @version may 2011, Chamilo 1.8.8
*/
function show_add_forum_form($inputvalues = array(), $lp_id)
{
global $_course;
$_course = api_get_course_info();
$gradebook = Security::remove_XSS($_GET['gradebook']);
// Initialize the object.
@ -451,11 +447,7 @@ function show_edit_forumcategory_form($inputvalues = array())
*/
function store_forumcategory($values)
{
global $_course;
global $_user;
$course_id = api_get_course_int_id();
$table_categories = Database::get_course_table(TABLE_FORUM_CATEGORY);
// Find the max cat_order. The new forum category is added at the end => max cat_order + &
@ -468,11 +460,19 @@ function store_forumcategory($values)
$clean_cat_title = Database::escape_string($values['forum_category_title']);
if (isset($values['forum_category_id'])) { // Storing after edition.
$sql = "UPDATE ".$table_categories." SET cat_title='".$clean_cat_title."', cat_comment='".Database::escape_string($values['forum_category_comment'])."'
$sql = "UPDATE ".$table_categories." SET
cat_title='".$clean_cat_title."',
cat_comment='".Database::escape_string($values['forum_category_comment'])."'
WHERE c_id = $course_id AND cat_id='".Database::escape_string($values['forum_category_id'])."'";
Database::query($sql);
$last_id = Database::insert_id();
api_item_property_update(api_get_course_info(), TOOL_FORUM_CATEGORY, $values['forum_category_id'], 'ForumCategoryUpdated', api_get_user_id());
Database::insert_id();
api_item_property_update(
api_get_course_info(),
TOOL_FORUM_CATEGORY,
$values['forum_category_id'],
'ForumCategoryUpdated',
api_get_user_id()
);
$return_message = get_lang('ForumCategoryEdited');
} else {
$sql = "INSERT INTO ".$table_categories." (c_id, cat_title, cat_comment, cat_order, session_id)
@ -499,8 +499,7 @@ function store_forumcategory($values)
*/
function store_forum($values)
{
global $_course;
$_course = api_get_course_info();
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();
@ -518,14 +517,14 @@ function store_forum($values)
} else {
$sql = "SELECT MAX(forum_order) as sort_max
FROM ".$table_forums."
WHERE c_id = $course_id AND
forum_category='".Database::escape_string($values['forum_category'])."'";
WHERE
c_id = $course_id AND
forum_category='".Database::escape_string($values['forum_category'])."'";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$new_max = $row['sort_max'] + 1;
}
$clean_title = Database::escape_string($values['forum_title']);
// Forum images
@ -549,9 +548,6 @@ function store_forum($values)
$updir = $sys_course_path.$course_dir;
// Try to add an extension to the file if it hasn't one.
$new_file_name = add_ext_on_mime(Database::escape_string($_FILES['picture']['name']), $_FILES['picture']['type']);
// User's file name
$file_name = $_FILES['picture']['name'];
if (!filter_extension($new_file_name)) {
//Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
$image_moved = false;
@ -598,7 +594,6 @@ function store_forum($values)
WHERE c_id = $course_id AND forum_id='".Database::escape_string($values['forum_id'])."'";
Database::query($sql);
api_item_property_update($_course, TOOL_FORUM, Database::escape_string($values['forum_id']), 'ForumUpdated', api_get_user_id(), $group_id);
$return_message = get_lang('ForumEdited');
@ -655,8 +650,7 @@ function store_forum($values)
*/
function delete_forum_forumcategory_thread($content, $id)
{
global $_course;
$_course = api_get_course_info();
$table_forums = Database::get_course_table(TABLE_FORUM);
$table_forums_post = Database::get_course_table(TABLE_FORUM_POST);
$table_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD);
@ -701,7 +695,15 @@ function delete_forum_forumcategory_thread($content, $id)
$tool_constant = TOOL_FORUM_THREAD;
$return_message = get_lang('ThreadDeleted');
}
api_item_property_update($_course, $tool_constant, $id, 'delete', api_get_user_id()); // Note: Check if this returns a true and if so => return $return_message, if not => return false;
api_item_property_update(
$_course,
$tool_constant,
$id,
'delete',
api_get_user_id()
);
// Check if this returns a true and if so => return $return_message, if not => return false;
return $return_message;
}
@ -744,7 +746,6 @@ function delete_post($post_id)
$last_post_of_thread = check_if_last_post_of_thread($_GET['thread']);
if (is_array($last_post_of_thread)) {
// Decreasing the number of replies for this thread and also changing the last post information.
$sql = "UPDATE $table_threads SET thread_replies=thread_replies-1,
@ -799,16 +800,15 @@ function check_if_last_post_of_thread($thread_id)
*/
function display_visible_invisible_icon($content, $id, $current_visibility_status, $additional_url_parameters = '')
{
global $origin;
$id = Security::remove_XSS($id);
if ($current_visibility_status == '1') {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gidReq='.api_get_group_id().'&amp;';
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&';
if (is_array($additional_url_parameters)) {
foreach ($additional_url_parameters as $key => $value) {
echo $key.'='.$value.'&amp;';
}
}
echo 'action=invisible&amp;content='.$content.'&amp;id='.$id.'&origin='.$origin.'">'.Display::return_icon('visible.png', get_lang('MakeInvisible'), array(), ICON_SIZE_SMALL).'</a>';
echo 'action=invisible&amp;content='.$content.'&amp;id='.$id.'">'.Display::return_icon('visible.png', get_lang('MakeInvisible'), array(), ICON_SIZE_SMALL).'</a>';
}
if ($current_visibility_status == '0') {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;';
@ -817,7 +817,7 @@ function display_visible_invisible_icon($content, $id, $current_visibility_statu
echo $key.'='.$value.'&amp;';
}
}
echo 'action=visible&amp;content='.$content.'&amp;id='.$id.'&origin='.$origin.'">'.Display::return_icon('invisible.png', get_lang('MakeVisible'), array(), ICON_SIZE_SMALL).'</a>';
echo 'action=visible&amp;content='.$content.'&amp;id='.$id.'">'.Display::return_icon('invisible.png', get_lang('MakeVisible'), array(), ICON_SIZE_SMALL).'</a>';
}
}
@ -881,7 +881,6 @@ function display_up_down_icon($content, $id, $list)
$total_items = count($list);
$position = 0;
$internal_counter = 0;
$forumCategory = isset($_GET['forumcategory']) ? Security::remove_XSS($_GET['forumcategory']) : null;
if (is_array($list)) {
@ -892,6 +891,7 @@ function display_up_down_icon($content, $id, $list)
}
}
}
if ($position > 1) {
$return_value = '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=move&amp;direction=up&amp;content='.$content.'&amp;forumcategory='.$forumCategory.'&amp;id='.$id.'" title="'.get_lang('MoveUp').'">'.
Display::return_icon('up.png', get_lang('MoveUp'), array(), ICON_SIZE_SMALL).'</a>';
@ -926,7 +926,7 @@ function display_up_down_icon($content, $id, $list)
*/
function change_visibility($content, $id, $target_visibility)
{
global $_course;
$_course = api_get_course_info();
$constants = array('forumcategory' => TOOL_FORUM_CATEGORY, 'forum' => TOOL_FORUM, 'thread' => TOOL_FORUM_THREAD);
api_item_property_update($_course, $constants[$content], $id, $target_visibility, api_get_user_id()); // Note: Check if this returns true or false => returnmessage depends on it.
if ($target_visibility == 'visible') {
@ -953,7 +953,6 @@ function change_lock_status($content, $id, $action)
$table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$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);
// Determine the relevant table.
if ($content == 'forumcategory') {
@ -983,7 +982,8 @@ function change_lock_status($content, $id, $action)
$course_id = api_get_course_int_id();
// Doing the change in the database
$sql = "UPDATE $table SET locked='".Database::escape_string($db_locked)."' WHERE c_id = $course_id AND $id_field='".Database::escape_string($id)."'";
$sql = "UPDATE $table SET locked='".Database::escape_string($db_locked)."'
WHERE c_id = $course_id AND $id_field='".Database::escape_string($id)."'";
if (Database::query($sql)) {
return $return_message;
} else {
@ -1042,16 +1042,21 @@ function move_up_down($content, $direction, $id)
// The SQL statement
if ($content == 'forumcategory') {
$sql = "SELECT * FROM".$table_categories." forum_categories, ".$table_item_property." item_properties
$sql = "SELECT *
FROM".$table_categories." forum_categories, ".$table_item_property." item_properties
WHERE
forum_categories.c_id = $course_id AND
item_properties.c_id = $course_id AND
forum_categories.cat_id=item_properties.ref
AND item_properties.tool='".TOOL_FORUM_CATEGORY."'
forum_categories.c_id = $course_id AND
item_properties.c_id = $course_id AND
forum_categories.cat_id=item_properties.ref AND
item_properties.tool='".TOOL_FORUM_CATEGORY."'
ORDER BY forum_categories.cat_order $sort_direction";
}
if ($content == 'forum') {
$sql = "SELECT * FROM".$table." WHERE c_id = $course_id AND forum_category='".Database::escape_string($forum_category)."' ORDER BY forum_order $sort_direction";
$sql = "SELECT * FROM".$table."
WHERE
c_id = $course_id AND
forum_category='".Database::escape_string($forum_category)."'
ORDER BY forum_order $sort_direction";
}
// echo $sql.'<br />';
// Finding the items that need to be switched.
@ -1075,8 +1080,10 @@ function move_up_down($content, $direction, $id)
// We do an extra check if we do not have illegal values. If your remove this if statment you will
// be able to mess with the sorting by refreshing the page over and over again.
if ($this_sort != '' && $next_sort != '' && $next_id != '' && $this_id != '') {
$sql_update1 = "UPDATE $table SET $sort_column='".Database::escape_string($this_sort)."' WHERE c_id = $course_id AND $id_column='".Database::escape_string($next_id)."'";
$sql_update2 = "UPDATE $table SET $sort_column='".Database::escape_string($next_sort)."' WHERE c_id = $course_id AND $id_column='".Database::escape_string($this_id)."'";
$sql_update1 = "UPDATE $table SET $sort_column='".Database::escape_string($this_sort)."'
WHERE c_id = $course_id AND $id_column='".Database::escape_string($next_id)."'";
$sql_update2 = "UPDATE $table SET $sort_column='".Database::escape_string($next_sort)."'
WHERE c_id = $course_id AND $id_column='".Database::escape_string($this_id)."'";
Database::query($sql_update1);
Database::query($sql_update2);
}
@ -1971,18 +1978,16 @@ function count_number_of_forums_in_category($cat_id)
* in the forum_post table because. The threads are also stored in the item_property table. (forum posts are not (yet))
*
* @param array
* @param array
* @return void HTML
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function store_thread($values)
function store_thread($current_forum, $values)
{
global $_user;
global $_course;
global $current_forum;
global $origin;
$_course = api_get_course_info();
$_user = api_get_user_info();
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
@ -2094,9 +2099,6 @@ function store_thread($values)
// Try to add an extension to the file if it hasn't one.
$new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
// User's file name
$file_name = $_FILES['user_upload']['name'];
if (!filter_extension($new_file_name)) {
Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
} else {
@ -2111,10 +2113,10 @@ function store_thread($values)
if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) {
$message .= get_lang('MessageHasToBeApproved').'<br />';
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&amp;forum='.$values['forum_id'].'&amp;gidReq='.$_SESSION['toolgroup'].'&amp;origin='.$origin.'">'.get_lang('Forum').'</a><br />';
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&amp;forum='.$values['forum_id'].'">'.get_lang('Forum').'</a><br />';
} else {
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&amp;forum='.$values['forum_id'].'&amp;gidReq='.$_SESSION['toolgroup'].'&amp;origin='.$origin.'">'.get_lang('Forum').'</a><br />';
$message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&amp;forum='.$values['forum_id'].'&amp;gidReq='.$_SESSION['toolgroup'].'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;thread='.$last_thread_id.'">'.get_lang('Message').'</a>';
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&amp;forum='.$values['forum_id'].'">'.get_lang('Forum').'</a><br />';
$message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&amp;forum='.$values['forum_id'].'&gradebook='.$gradebook.'&amp;thread='.$last_thread_id.'">'.get_lang('Message').'</a>';
}
$reply_info['new_post_id'] = $last_post_id;
$my_post_notification = isset($values['post_notification']) ? $values['post_notification'] : null;
@ -2148,13 +2150,9 @@ function store_thread($values)
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function show_add_post_form($action = '', $id = '', $form_values = '')
function show_add_post_form($current_forum, $forum_setting, $action = '', $id = '', $form_values = '')
{
global $forum_setting;
global $current_forum;
global $_user;
global $origin;
$_user = api_get_user_info();
$gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : null;
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
@ -2499,21 +2497,20 @@ function current_qualify_of_thread($thread_id, $session_id)
/**
* This function stores a reply in the forum_post table.
* It also updates the forum_threads table (thread_replies +1 , thread_last_post, thread_date)
*
* @param array
* @param array
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function store_reply($values)
function store_reply($current_forum, $values)
{
global $_course;
global $current_forum;
$_course = api_get_course_info();
$forum_table_attachment = Database :: get_course_table(TABLE_FORUM_ATTACHMENT);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$post_date = api_get_utc_datetime();
if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) {
$visible = 0; // The post has not been approved yet.
$visible = 0;
} else {
$visible = 1;
}
@ -2621,15 +2618,16 @@ function store_reply($values)
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function show_edit_post_form($current_post, $current_thread, $current_forum, $form_values = '', $id_attach = 0)
function show_edit_post_form($forum_setting, $current_post, $current_thread, $current_forum, $form_values = '', $id_attach = 0)
{
global $forum_setting;
global $origin;
$gradebook = Security::remove_XSS($_GET['gradebook']);
// Initialize the object.
$form = new FormValidator('edit_post', 'post', api_get_self().'?forum='.Security::remove_XSS($_GET['forum']).'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;post='.Security::remove_XSS($_GET['post']));
$form = new FormValidator(
'edit_post',
'post',
api_get_self().'?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&amp;gradebook='.$gradebook.'&thread='.Security::remove_XSS($_GET['thread']).'&amp;post='.Security::remove_XSS($_GET['post'])
);
$form->addElement('header', get_lang('EditPost'));
// Setting the form elements.
$form->addElement('hidden', 'post_id', $current_post['post_id']);
@ -2764,13 +2762,9 @@ function show_edit_post_form($current_post, $current_thread, $current_forum, $fo
*/
function store_edit_post($values)
{
global $origin;
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$gradebook = Security::remove_XSS($_GET['gradebook']);
$course_id = api_get_course_int_id();
//check if this post is the first of the thread
@ -2839,8 +2833,8 @@ function store_edit_post($values)
//update_added_resources('forum_post', $values['post_id']);
$message = get_lang('EditPostStored').'<br />';
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$_SESSION['toolgroup'].'&amp;origin='.$origin.'">'.get_lang('Forum').'</a><br />';
$message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$_SESSION['toolgroup'].'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;thread='.$values['thread_id'].'&amp;post='.Security::remove_XSS($_GET['post']).'">'.get_lang('Message').'</a>';
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&">'.get_lang('Forum').'</a><br />';
$message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&gradebook='.$gradebook.'&thread='.$values['thread_id'].'&post='.Security::remove_XSS($_GET['post']).'">'.get_lang('Message').'</a>';
Session::erase('formelements');
Session::erase('origin');
@ -2948,8 +2942,8 @@ function forum_not_allowed_here()
*/
function get_whats_new()
{
global $_user;
global $_course;
$_user = api_get_user_info();
$_course = api_get_course_info();
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$tracking_last_tool_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
@ -3277,7 +3271,7 @@ function handle_mail_cue($content, $id)
*/
function send_mail($user_info = array(), $thread_information = array())
{
global $_course;
$_course = api_get_course_info();
$user_id = api_get_user_id();
$subject = get_lang('NewForumPost').' - '.$_course['official_code'];
if (isset($thread_information) && is_array($thread_information)) {
@ -3304,10 +3298,9 @@ function send_mail($user_info = array(), $thread_information = array())
*/
function move_thread_form()
{
global $origin;
$gradebook = Security::remove_XSS($_GET['gradebook']);
// Initialize the object.
$form = new FormValidator('movepost', 'post', api_get_self().'?forum='.Security::remove_XSS($_GET['forum']).'&gradebook='.$gradebook.'&thread='.Security::remove_XSS($_GET['thread']).'&action='.Security::remove_XSS($_GET['action']).'&origin='.$origin);
$form = new FormValidator('movepost', 'post', api_get_self().'?forum='.Security::remove_XSS($_GET['forum']).'&gradebook='.$gradebook.'&thread='.Security::remove_XSS($_GET['thread']).'&action='.Security::remove_XSS($_GET['action']).'&'.api_get_cidreq());
// The header for the form
$form->addElement('header', '', get_lang('MoveThread'));
// Invisible form: the thread_id
@ -3360,10 +3353,9 @@ function move_thread_form()
*/
function move_post_form()
{
global $origin;
$gradebook = Security::remove_XSS($_GET['gradebook']);
// initiate the object
$form = new FormValidator('movepost', 'post', api_get_self().'?forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&origin='.$origin.'&gradebook='.$gradebook.'&post='.Security::remove_XSS($_GET['post']).'&action='.Security::remove_XSS($_GET['action']).'&post='.Security::remove_XSS($_GET['post']));
$form = new FormValidator('movepost', 'post', api_get_self().'?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&gradebook='.$gradebook.'&post='.Security::remove_XSS($_GET['post']).'&action='.Security::remove_XSS($_GET['action']).'&post='.Security::remove_XSS($_GET['post']));
// The header for the form
$form->addElement('header', '', get_lang('MovePost'));
@ -3404,14 +3396,13 @@ function move_post_form()
*/
function store_move_post($values)
{
global $_course;
$_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);
$course_id = api_get_course_int_id();
if ($values['thread'] == '0') {
$current_post = get_post_information($values['post_id']);
@ -3510,19 +3501,19 @@ function store_move_post($values)
*/
function store_move_thread($values)
{
global $_course;
$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);
$course_id = api_get_course_int_id();
// Change the thread table: Setting the forum_id to the new forum.
$sql = "UPDATE $table_threads SET forum_id='".Database::escape_string($_POST['forum'])."' WHERE c_id = $course_id AND thread_id='".Database::escape_string($_POST['thread_id'])."'";
$sql = "UPDATE $table_threads SET forum_id='".Database::escape_string($_POST['forum'])."'
WHERE c_id = $course_id AND thread_id='".Database::escape_string($_POST['thread_id'])."'";
Database::query($sql);
// Changing all the posts of the thread: setting the forum_id to the new forum.
$sql = "UPDATE $table_posts SET forum_id='".Database::escape_string($_POST['forum'])."' WHERE c_id = $course_id AND thread_id='".Database::escape_string($_POST['thread_id'])."'";
$sql = "UPDATE $table_posts SET forum_id='".Database::escape_string($_POST['forum'])."'
WHERE c_id = $course_id AND thread_id='".Database::escape_string($_POST['thread_id'])."'";
Database::query($sql);
return get_lang('ThreadMoved');
@ -3578,16 +3569,14 @@ function prepare4display($input)
*/
function forum_search()
{
global $origin;
// Initialize the object.
$form = new FormValidator('forumsearch', 'post', 'forumsearch.php?origin='.$origin.'');
$form = new FormValidator('forumsearch', 'post', 'forumsearch.php?'.api_get_cidreq());
// Setting the form elements.
$form->addElement('header', '', get_lang('ForumSearch'));
$form->addElement('text', 'search_term', get_lang('SearchTerm'), 'class="input_titles" id="search_title"');
$form->applyFilter('search_term', 'html_filter');
$form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation')/* , $dissertation[$_GET['opleidingsonderdeelcode']]['code'] */);
$form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation'));
$form->addElement('style_submit_button', null, get_lang('Search'), 'class="search"');
// Setting the rules.
@ -3615,16 +3604,12 @@ function forum_search()
*/
function display_forum_search_results($search_term)
{
global $origin;
$table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$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);
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$session_id = api_get_session_id();
$gradebook = Security::remove_XSS($_GET['gradebook']);
$course_id = api_get_course_int_id();
// Defining the search strings as an array.
@ -3635,13 +3620,16 @@ function display_forum_search_results($search_term)
}
// Search restriction.
foreach ($search_terms as $key => $value) {
$search_restriction[] = "(posts.post_title LIKE '%".Database::escape_string(trim($value))."%'
OR posts.post_text LIKE '%".Database::escape_string(trim($value))."%')";
foreach ($search_terms as $value) {
$search_restriction[] = "
(posts.post_title LIKE '%".Database::escape_string(trim($value))."%'
OR posts.post_text LIKE '%".Database::escape_string(trim($value))."%')";
}
$sql = "SELECT posts.* FROM $table_posts posts, $table_threads threads, $table_item_property item_property
WHERE posts.c_id = $course_id
$sql = "SELECT posts.*
FROM $table_posts posts, $table_threads threads, $table_item_property item_property
WHERE
posts.c_id = $course_id
AND item_property.c_id = $course_id
AND posts.thread_id = threads.thread_id
AND item_property.ref = threads.thread_id
@ -3663,13 +3651,15 @@ function display_forum_search_results($search_term)
$display_result = false;
/*
We only show it when
1. forum cateogory is visible
1. forum category is visible
2. forum is visible
3. thread is visible (to do)
4. post is visible
*/
if (!api_is_allowed_to_edit(null, true)) {
if ($forum_categories_list[$row['forum_id']['forum_category']]['visibility'] == '1' AND $forum_list[$row['forum_id']]['visibility'] == '1' AND $row['visible'] == '1') {
if ($forum_categories_list[$row['forum_id']['forum_category']]['visibility'] == '1' AND
$forum_list[$row['forum_id']]['visibility'] == '1' AND $row['visible'] == '1'
) {
$display_result = true;
}
} else {
@ -3677,10 +3667,13 @@ function display_forum_search_results($search_term)
}
if ($display_result) {
$search_results_item = '<li><a href="viewforumcategory.php?forumcategory='.$forum_list[$row['forum_id']]['forum_category'].'&amp;origin='.$origin.'&amp;search='.urlencode($search_term).'">'.prepare4display($forum_categories_list[$row['forum_id']['forum_category']]['cat_title']).'</a> &gt; ';
$search_results_item .= '<a href="viewforum.php?forum='.$row['forum_id'].'&amp;origin='.$origin.'&amp;search='.urlencode($search_term).'">'.prepare4display($forum_list[$row['forum_id']]['forum_title']).'</a> &gt; ';
$search_results_item = '<li><a href="viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$forum_list[$row['forum_id']]['forum_category'].'&search='.urlencode($search_term).'">'.
prepare4display($forum_categories_list[$row['forum_id']['forum_category']]['cat_title']).'</a> &gt; ';
$search_results_item .= '<a href="viewforum.php?'.api_get_cidreq().'&forum='.$row['forum_id'].'&search='.urlencode($search_term).'">'.
prepare4display($forum_list[$row['forum_id']]['forum_title']).'</a> &gt; ';
//$search_results_item .= '<a href="">THREAD</a> &gt; ';
$search_results_item .= '<a href="viewthread.php?forum='.$row['forum_id'].'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;thread='.$row['thread_id'].'&amp;search='.urlencode($search_term).'">'.prepare4display($row['post_title']).'</a>';
$search_results_item .= '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$row['forum_id'].'&gradebook='.$gradebook.'&thread='.$row['thread_id'].'&search='.urlencode($search_term).'">'.
prepare4display($row['post_title']).'</a>';
$search_results_item .= '<br />';
if (api_strlen($row['post_title']) > 200) {
$search_results_item .= prepare4display(api_substr(strip_tags($row['post_title']), 0, 200)).'...';
@ -3707,10 +3700,10 @@ function display_forum_search_results($search_term)
*/
function search_link()
{
global $origin;
$return = '';
$origin = api_get_origin();
if ($origin != 'learnpath') {
$return = '<a href="forumsearch.php?'.api_get_cidreq().'&amp;gidReq='.api_get_group_id().'&amp;action=search&amp;origin='.$origin.'"> ';
$return = '<a href="forumsearch.php?'.api_get_cidreq().'&action=search"> ';
$return .= Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM).'</a>';
if (!empty($_GET['search'])) {
@ -3737,8 +3730,7 @@ function search_link()
*/
function add_forum_attachment_file($file_comment, $last_id)
{
global $_course;
$_course = api_get_course_info();
$agenda_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
// Storing the attachments
@ -3789,8 +3781,7 @@ function add_forum_attachment_file($file_comment, $last_id)
*/
function edit_forum_attachment_file($file_comment, $post_id, $id_attach)
{
global $_course;
$_course = api_get_course_info();
$table_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
$course_id = api_get_course_int_id();
@ -3863,7 +3854,7 @@ function get_attachment($post_id)
*/
function delete_attachment($post_id, $id_attach = 0)
{
global $_course;
$_course = api_get_course_info();
$forum_table_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
$course_id = api_get_course_int_id();
@ -4035,7 +4026,7 @@ function get_forums_of_group($group_id)
*/
function set_notification($content, $id, $add_only = false)
{
global $_user;
$_user = api_get_user_info();
// Database table definition
$table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
@ -4129,7 +4120,8 @@ function get_notifications($content, $id)
*/
function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
{
global $_course, $_user;
$_user = api_get_user_info();
$_course = api_get_course_info();
// The content of the mail
$thread_link = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&amp;forum='.$forum_id.'&amp;thread='.$thread_id;
@ -4145,7 +4137,6 @@ function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
$current_forum = get_forum_information($current_thread['forum_id']);
$subject = get_lang('NewForumPost').' - '.$_course['official_code'].' - '.$current_forum['forum_title'].' - '.$current_thread['thread_title'];
// User who subscribed to the thread
if ($thread_id != 0) {
$users_to_be_notified_by_thread = get_notifications('thread', $thread_id);

@ -158,11 +158,11 @@ echo '<span style="float:right;">'.search_link().'</span>';
echo '<a href="viewforum.php?origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']).'&'.api_get_cidreq().'">'.Display::return_icon('back.png',get_lang('BackToForum'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
$values = show_add_post_form('newthread', '', isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null);
$values = show_add_post_form($current_forum, $forum_setting, 'newthread', '', isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null);
if (!empty($values) && isset($values['SubmitPost'])) {
// Add new thread in table forum_thread.
store_thread($values);
store_thread($current_forum, $values);
}
/* FOOTER */

@ -155,10 +155,10 @@ $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) :
$my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
$my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
$values = show_add_post_form($my_action, $my_post, $my_elements); // Note: This has to be cleaned first.
$values = show_add_post_form($current_forum, $forum_setting, $my_action, $my_post, $my_elements);
if (!empty($values) AND isset($_POST['SubmitPost'])) {
$result = store_reply($values);
$result = store_reply($current_forum, $values);
//@todo split the show_add_post_form function
$url = 'viewthread.php?forum='.$current_thread['forum_id'].'&gradebook='.$gradebook.'&thread='.intval($_GET['thread']).'&gidReq='.api_get_group_id().'&origin='.$origin.'&msg='.$result['msg'].'&type='.$result['type'];

Loading…
Cancel
Save