Fix thread edition/creation

pull/2487/head
jmontoyaa 9 years ago
parent a924065f8d
commit 986562e1d4
  1. 129
      main/forum/forumfunction.inc.php
  2. 2
      main/forum/index.php
  3. 21
      main/forum/newthread.php
  4. 65
      main/forum/reply.php

@ -2386,14 +2386,14 @@ function updateThread($values)
* @param array $values
* @param array $courseInfo
* @param bool $showMessage
* @return void HTML
* @return int
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function store_thread($current_forum, $values, $courseInfo = array(), $showMessage = true)
{
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo ;
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
$_user = api_get_user_info();
$course_id = $courseInfo['real_id'];
$courseCode = $courseInfo['code'];
@ -2411,7 +2411,6 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
}
if ($upload_ok) {
$post_date = api_get_utc_datetime();
if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) {
@ -2547,7 +2546,7 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
editAttachedFile(
array(
'comment' => $_POST['file_comments'][$key],
'post_id' => $last_post_id,
'post_id' => $last_post_id
),
$id
);
@ -2592,10 +2591,13 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
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().'&forum='.$values['forum_id'].'">'.get_lang('Forum').'</a><br />';
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'">'.
get_lang('Forum').'</a><br />';
} else {
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'">'.get_lang('Forum').'</a><br />';
$message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'&gradebook='.$gradebook.'&thread='.$last_thread_id.'">'.get_lang('Message').'</a>';
$message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'">'.
get_lang('Forum').'</a><br />';
$message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'&gradebook='.$gradebook.'&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;
@ -2611,13 +2613,12 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
Session::erase('breadcrumbs');
Session::erase('addedresource');
Session::erase('addedresourceid');
if ($showMessage) {
Display:: display_confirmation_message($message, false);
}
Display::addFlash(Display::return_message($message, 'success', false));
return $last_thread_id;
} else {
if ($showMessage) {
Display::display_error_message(get_lang('UplNoFileUploaded'));
}
Display::addFlash(Display::return_message(get_lang('UplNoFileUploaded'), 'error', false));
}
}
@ -2632,8 +2633,6 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
*/
function showUpdateThreadForm($currentForum, $forumSetting, $formValues = '')
{
$userInfo = api_get_user_info();
$myThread = isset($_GET['thread']) ? intval($_GET['thread']) : '';
$myForum = isset($_GET['forum']) ? intval($_GET['forum']) : '';
$myGradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : '';
@ -2763,35 +2762,40 @@ function showUpdateThreadForm($currentForum, $forumSetting, $formValues = '')
* 2. replythread: Replying to a thread ($action = replythread) => I-frame with the complete thread (if enabled)
* 3. replymessage: Replying to a message ($action =replymessage) => I-frame with the complete thread (if enabled) (I first thought to put and I-frame with the message only)
* 4. quote: Quoting a message ($action= quotemessage) => I-frame with the complete thread (if enabled). The message will be in the reply. (I first thought not to put an I-frame here)
* @return void HMTL
* @return FormValidator
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function show_add_post_form($current_forum, $forum_setting, $action = '', $id = '', $form_values = '')
function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $form_values = '')
{
$_user = api_get_user_info();
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
$myThread = isset($_GET['thread']) ? $_GET['thread'] : '';
$my_forum = isset($_GET['forum']) ? $_GET['forum'] : '';
$my_post = isset($_GET['post']) ? $_GET['post'] : '';
$action = isset($action) ? Security::remove_XSS($action) : '';
$myThread = isset($_GET['thread']) ? (int) $_GET['thread'] : '';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : '';
$my_post = isset($_GET['post']) ? (int) $_GET['post'] : '';
$my_gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : '';
$url = api_get_self() . '?' . http_build_query([
'action' => $action,
'forum' => $forumId,
'gradebook' => $my_gradebook,
'thread' => $myThread,
'post' => $my_post
]) . '&' . api_get_cidreq();
$form = new FormValidator(
'thread',
'post',
api_get_self() . '?' . http_build_query([
'forum' => intval($my_forum),
'gradebook' => $my_gradebook,
'thread' => intval($myThread),
'post' => intval($my_post),
'action' => $action,
]) . '&' . api_get_cidreq()
$url
);
$form->setConstants(array('forum' => '5'));
// Setting the form elements.
$form->addElement('hidden', 'forum_id', intval($my_forum));
$form->addElement('hidden', 'thread_id', intval($myThread));
$form->addElement('hidden', 'forum_id', $forumId);
$form->addElement('hidden', 'thread_id', $myThread);
$form->addElement('hidden', 'gradebook', $my_gradebook);
$form->addElement('hidden', 'action', $action);
// If anonymous posts are allowed we also display a form to allow the user to put his name or username in.
if ($current_forum['allow_anonymous'] == 1 && !isset($_user['user_id'])) {
@ -2813,7 +2817,7 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
'ToolbarSet' => 'ForumStudent',
'Width' => '100%',
'Height' => '300',
'UserStatus' => 'student',
'UserStatus' => 'student'
)
);
@ -2821,7 +2825,7 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
$iframe = null;
$myThread = Security::remove_XSS($myThread);
if ($forum_setting['show_thread_iframe_on_reply'] && $action != 'newthread' && !empty($myThread)) {
$iframe = "<iframe style=\"border: 1px solid black\" src=\"iframe_thread.php?".api_get_cidreq()."&forum=".Security::remove_XSS($my_forum)."&thread=".$myThread."#".Security::remove_XSS($my_post)."\" width=\"100%\"></iframe>";
$iframe = "<iframe style=\"border: 1px solid black\" src=\"iframe_thread.php?".api_get_cidreq()."&forum=".Security::remove_XSS($forumId)."&thread=".$myThread."#".Security::remove_XSS($my_post)."\" width=\"100%\"></iframe>";
}
if (!empty($iframe)) {
$form->addElement('label', get_lang('Thread'), $iframe);
@ -2882,10 +2886,6 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
}
if ($current_forum['allow_attachments'] == '1' || api_is_allowed_to_edit(null, true)) {
$values = $form->exportValues();
}
$form->addElement('html', '</div>');
if (in_array($action, ['quote', 'replymessage'])) {
@ -2926,23 +2926,37 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
// If we are quoting a message we have to retrieve the information of the post we are quoting so that
// we can add this as default to the textarea.
if (($action == 'quote' || $action == 'replymessage') && isset($my_post)) {
// We also need to put the parent_id of the post in a hidden form when
// we are quoting or replying to a message (<> reply to a thread !!!)
$form->addElement('hidden', 'post_parent_id', intval($my_post));
$form->addHidden('post_parent_id', intval($my_post));
// If we are replying or are quoting then we display a default title.
$values = get_post_information($my_post);
$posterInfo = api_get_user_info($values['poster_id']);
$posterName = '';
if ($posterInfo) {
$posterName = $posterInfo['complete_name'];
}
$defaults['post_title'] = get_lang('ReplyShort').api_html_entity_decode($values['post_title'], ENT_QUOTES);
// When we are quoting a message then we have to put that message into the wysiwyg editor.
// Note: The style has to be hardcoded here because using class="quote" didn't work.
if ($action == 'quote') {
$defaults['post_text'] = '<div>&nbsp;</div><div style="margin: 5px;"><div style="font-size: 90%; font-style: italic;">'.get_lang('Quoting').' '.api_get_person_name($values['firstname'], $values['lastname']).':</div><div style="color: #006600; font-size: 90%; font-style: italic; background-color: #FAFAFA; border: #D1D7DC 1px solid; padding: 3px;">'.prepare4display($values['post_text']).'</div></div><div>&nbsp;</div><div>&nbsp;</div>';
$defaults['post_text'] = '<div>&nbsp;</div>
<div style="margin: 5px;">
<div style="font-size: 90%; font-style: italic;">'.
get_lang('Quoting').' '.$posterName.':</div>
<div style="color: #006600; font-size: 90%; font-style: italic; background-color: #FAFAFA; border: #D1D7DC 1px solid; padding: 3px;">'.
prepare4display($values['post_text']).'
</div>
</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
';
}
}
$form->setDefaults(isset($defaults) ? $defaults : null);
$form->setDefaults(isset($defaults) ? $defaults : []);
// The course admin can make a thread sticky (=appears with special icon and always on top).
$form->addRule('post_title', get_lang('ThisFieldIsRequired'), 'required');
@ -2969,9 +2983,29 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
return false;
}
Security::clear_token();
return $values;
switch ($action) {
case 'newthread':
$myThread = store_thread($current_forum, $values);
break;
case 'quote':
case 'replythread':
case 'replymessage':
store_reply($current_forum, $values);
break;
}
$url = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&'.http_build_query(
[
'forum' => $forumId,
'thread' => $myThread
]
);
Security::clear_token();
header('Location: '.$url);
exit;
}
} else {
$token = Security::get_token();
@ -2986,7 +3020,7 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
$ajaxHtml = $attachmentAjaxTable;
$form->addElement('html', $ajaxHtml);
$form->display();
return $form;
}
}
@ -5125,9 +5159,8 @@ function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
if (is_array($users_to_be_notified)) {
foreach ($users_to_be_notified as $value) {
$user_info = api_get_user_info($value['user_id']);
$email_body = get_lang('Dear').' '.api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS).", <br />\n\r";
$email_body = get_lang('Dear').' '.$user_info['complete_name'].", <br />\n\r";
$email_body .= get_lang('NewForumPost').": ".$current_forum['forum_title'].' - '.$current_thread['thread_title']." <br />\n";
$email_body .= get_lang('Course').': '.$_course['name'].' - ['.$_course['official_code']."] <br />\n";
$email_body .= get_lang('YouWantedToStayInformed')."<br />\n";
@ -5588,7 +5621,7 @@ function editAttachedFile($array, $id, $courseId = null) {
*
* @return string The Forum Attachments Ajax Table
*/
function getAttachmentsAjaxTable($postId = null)
function getAttachmentsAjaxTable($postId = 0)
{
// Init variables
$postId = intval($postId);
@ -5607,7 +5640,7 @@ function getAttachmentsAjaxTable($postId = null)
}
}
}
// Get data to fill into attachment files table
if (!empty($_SESSION['forum']['upload_file'][$courseId]) &&
is_array($_SESSION['forum']['upload_file'][$courseId])
@ -5662,7 +5695,7 @@ function getAttachmentsAjaxTable($postId = null)
*
* @return array
*/
function getAttachedFiles($forumId, $threadId, $postId = null, $attachId = null, $courseId = null)
function getAttachedFiles($forumId, $threadId, $postId = 0, $attachId = 0, $courseId = 0)
{
$forumId = intval($forumId);
$courseId = intval($courseId);

@ -469,7 +469,7 @@ if (is_array($forumCategories)) {
}
$forum['forum_of_group'] == 0 ? $groupid = '' : $groupid = $forum['forum_of_group'];
$number_threads = isset($forum['number_of_threads']) ? $forum['number_of_threads'] : 0;
$number_threads = isset($forum['number_of_threads']) ? (int) $forum['number_of_threads'] : 0;
$number_posts = isset($forum['number_of_posts']) ? $forum['number_of_posts'] : 0;
$html .= '<div class="row">';

@ -151,6 +151,14 @@ $htmlHeadXtra[] = <<<JS
</script>
JS;
$form = show_add_post_form(
$current_forum,
$forum_setting,
'newthread',
'',
isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null
);
if ($origin == 'learnpath') {
Display::display_reduced_header();
} else {
@ -168,18 +176,9 @@ echo '</div>';
// Set forum attachment data into $_SESSION
getAttachedFiles($current_forum['forum_id'], 0, 0);
$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($current_forum, $values);
}
$form->display();
if (isset($origin) && $origin == 'learnpath') {
Display::display_reduced_footer();

@ -20,7 +20,6 @@
require_once '../inc/global.inc.php';
// The section (tabs).
$this_section = SECTION_COURSES;
// Notification for unauthorized people.
@ -38,13 +37,16 @@ if (isset($_GET['origin'])) {
require_once 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
$forumId = isset($_GET['forum']) ? (int)$_GET['forum'] : 0;
$threadId = isset($_GET['thread']) ? (int)$_GET['thread'] : 0;
/* 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_thread = get_thread_information($threadId); // Note: This has to be validated that it is an existing thread.
$current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
$current_forum_category = get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
@ -55,19 +57,18 @@ $current_forum_category = get_forumcategory_information(Security::remove_XSS($cu
// 3. if anonymous posts are not allowed
// The only exception is the course manager
// I have split this is several pieces for clarity.
//if (!api_is_allowed_to_edit() AND (($current_forum_category['visibility'] == 0 OR $current_forum['visibility'] == 0) OR ($current_forum_category['locked'] <> 0 OR $current_forum['locked'] <> 0 OR $current_thread['locked'] <> 0))) {
if (!api_is_allowed_to_edit(false, true) &&
(($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
) {
api_not_allowed();
api_not_allowed(true);
}
if (!api_is_allowed_to_edit(false, true) &&
(($current_forum_category && $current_forum_category['locked'] <> 0) || $current_forum['locked'] <> 0 || $current_thread['locked'] <> 0)
) {
api_not_allowed();
api_not_allowed(true);
}
if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
api_not_allowed();
api_not_allowed(true);
}
if ($current_forum['forum_of_group'] != 0) {
@ -97,7 +98,7 @@ if (!empty($gradebook) && $gradebook == 'view') {
if ($origin == 'group') {
$_clean['toolgroup'] = api_get_group_id();
$group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
$group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
@ -105,16 +106,16 @@ if ($origin == 'group') {
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
'name' => get_lang('GroupSpace').' '.$group_properties['name'],
'name' => get_lang('GroupSpace').' '.$group_properties['name']
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
'name' => $current_forum['forum_title'],
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.$forumId.'&'.api_get_cidreq(),
'name' => $current_forum['forum_title']
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&'.api_get_cidreq(),
'name' => $current_thread['thread_title'],
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
'name' => $current_thread['thread_title']
);
$interbreadcrumb[] = array(
@ -124,19 +125,19 @@ if ($origin == 'group') {
} else {
$interbreadcrumb[] = array(
'url' => 'index.php?gradebook='.$gradebook,
'name' => $nameTools,
'name' => $nameTools
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
'name' => $current_forum_category['cat_title'],
'name' => $current_forum_category['cat_title']
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
'name' => $current_forum['forum_title'],
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.$forumId.'&'.api_get_cidreq(),
'name' => $current_forum['forum_title']
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&'.api_get_cidreq(),
'name' => $current_thread['thread_title'],
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
'name' => $current_thread['thread_title']
);
$interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
}
@ -174,35 +175,13 @@ $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(
$form = show_add_post_form(
$current_forum,
$forum_setting,
$my_action,
$my_post,
$my_elements
);
$form = '';
if (is_object($values)) {
$form = $values->returnForm();
} else {
if (!empty($values) && isset($_POST['SubmitPost'])) {
store_reply($current_forum, $values);
//@todo split the show_add_post_form function
$origin = isset($_GET['origin']) && $_GET['origin'] === 'learnpath' ? 'learnpath' : null;
$url = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query(
[
'forum' => $current_thread['forum_id'],
'gradebook' => $gradebook,
'thread' => intval($_GET['thread']),
'gidReq' => api_get_group_id(),
'origin' => $origin
]
);
header('Location: '.$url);
exit;
}
}
if ($origin == 'learnpath') {
Display::display_reduced_header();
@ -215,7 +194,7 @@ if ($origin == 'learnpath') {
if ($origin != 'learnpath') {
echo '<div class="actions">';
echo '<span style="float:right;">'.search_link().'</span>';
echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&gradebook='.$gradebook.'&thread='.Security::remove_XSS($_GET['thread']).'&origin='.$origin.'">'.
echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&gradebook='.$gradebook.'&thread='.$threadId.'&origin='.$origin.'">'.
Display::return_icon('back.png', get_lang('BackToThread'), '', ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
}
@ -227,7 +206,7 @@ echo '<h1><a href="viewforum.php?&origin='.$origin.'&forum='.$current_forum['for
echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
echo '</div>';
echo $form;
$form->display();
if ($origin == 'learnpath') {
Display::display_reduced_footer();

Loading…
Cancel
Save