@ -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 > < / 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 > < / div > < div > < / div > ';
$defaults['post_text'] = '< div > < / 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 > < / div >
< div > < / 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);