Show flash messages when update forum thread - refs BT#12514

pull/2487/head
Angel Fernando Quiroz Campos 8 years ago
parent 929f4ea576
commit 426b157946
  1. 151
      main/forum/editthread.php
  2. 129
      main/forum/forumfunction.inc.php

@ -27,7 +27,8 @@ require_once 'forumfunction.inc.php';
$origin = api_get_origin();
/* MAIN DISPLAY SECTION */
$currentForum = get_forum_information($_GET['forum']);
$forumId = (int) $_GET['forum'];
$currentForum = get_forum_information($forumId);
$currentForumCategory = get_forumcategory_information($currentForum['forum_category']);
// the variable $forum_settings is declared in forumconfig.inc.php
@ -49,6 +50,7 @@ if (!empty($gradebook) && $gradebook == 'view') {
$threadId = isset($_GET['thread']) ? intval($_GET['thread']) : 0;
$courseInfo = isset($_GET['cidReq']) ? api_get_course_info($_GET['cidReq']) : 0;
$cId = isset($courseInfo['real_id']) ? intval($courseInfo['real_id']) : 0;
$gradebookId = intval(api_is_in_gradebook());
/* Is the user allowed here? */
@ -101,12 +103,12 @@ if (!empty($groupId)) {
$groupProperties = GroupManager :: get_group_properties($groupId);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.$cidreq, 'name' => get_lang('Groups'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.$cidreq, 'name' => get_lang('GroupSpace').' '.$groupProperties['name']);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']), 'name' => $currentForum['forum_title']);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/newthread.php?'.$cidreq.'&forum='.intval($_GET['forum']),'name' => get_lang('EditThread'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.$forumId, 'name' => $currentForum['forum_title']);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/newthread.php?'.$cidreq.'&forum='.$forumId,'name' => get_lang('EditThread'));
} else {
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.$cidreq, 'name' => $nameTools);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.$cidreq.'&forumcategory='.$currentForumCategory['cat_id'], 'name' => $currentForumCategory['cat_title']);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']), 'name' => $currentForum['forum_title']);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.$forumId, 'name' => $currentForum['forum_title']);
$interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditThread'));
}
@ -139,35 +141,132 @@ $htmlHeadXtra[] = <<<JS
</script>
JS;
if ($origin == 'learnpath') {
Display::display_reduced_header();
} else {
Display :: display_header(null);
}
handle_forum_and_forumcategories();
// Action links
echo '<div class="actions">';
echo '<span style="float:right;">'.search_link().'</span>';
echo '<a href="viewforum.php?forum='.intval($_GET['forum']).'&'.$cidreq.'">'.
Display::return_icon('back.png',get_lang('BackToForum'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
$actions = '
<div class="actions">
<span class="pull-right">'.search_link().'</span>
<a href="viewforum.php?forum='.$forumId.'&'.$cidreq.'">'
.Display::return_icon('back.png',get_lang('BackToForum'),'',ICON_SIZE_MEDIUM)
.'</a>
</div>
';
$threadData = getThreadInfo($threadId, $cId);
$values = showUpdateThreadForm(
$currentForum,
$forumSettings,
$threadData
$form = new FormValidator(
'thread',
'post',
api_get_self() . '?' . http_build_query([
'forum' => $forumId,
'thread' => $threadId,
]) . '&' . api_get_cidreq()
);
if (!empty($values) && isset($values['SubmitPost'])) {
$form->addElement('header', get_lang('EditThread'));
$form->setConstants(array('forum' => '5'));
$form->addElement('hidden', 'forum_id', $forumId);
$form->addElement('hidden', 'thread_id', $threadId);
$form->addElement('hidden', 'gradebook', $gradebookId);
$form->addElement('text', 'thread_title', get_lang('Title'));
$form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
if ((api_is_course_admin() || api_is_course_coach() || api_is_course_tutor()) && ($threadId)) {
// Thread qualify
if (Gradebook::is_active()) {
//Loading gradebook select
GradebookUtils::load_gradebook_select_in_tool($form);
$form->addElement(
'checkbox',
'thread_qualify_gradebook',
'',
get_lang('QualifyThreadGradebook'),
['id' => 'thread_qualify_gradebook']
);
} else {
$form->addElement('hidden', 'thread_qualify_gradebook', false);
}
$form->addElement('html', '<div id="options_field" style="display:none">');
$form->addElement('text', 'numeric_calification', get_lang('QualificationNumeric'));
$form->applyFilter('numeric_calification', 'html_filter');
$form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'));
$form->applyFilter('calification_notebook_title', 'html_filter');
$form->addElement(
'number',
'weight_calification',
get_lang('QualifyWeight'),
['value' => '0.00', 'step' => '0.01']
);
$form->applyFilter('weight_calification', 'html_filter');
$group = array();
$group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('No'), 0);
$form->addGroup(
$group,
'',
[get_lang('ForumThreadPeerScoring'), get_lang('ForumThreadPeerScoringComment'),]
);
$form->addElement('html', '</div>');
}
if ($forumSettings['allow_sticky'] && api_is_allowed_to_edit(null, true)) {
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
}
$form->addElement('html', '</div>');
// update thread in table forum_thread.
updateThread($values);
if (!empty($threadData)) {
$defaults['thread_qualify_gradebook'] = ($threadData['threadQualifyMax'] > 0 && empty($_POST)) ? 1 : 0 ;
$defaults['thread_title'] = prepare4display($threadData['threadTitle']);
$defaults['thread_sticky'] = strval(intval($threadData['threadSticky']));
$defaults['thread_peer_qualify'] = intval($threadData['threadPeerQualify']);
$defaults['numeric_calification'] = $threadData['threadQualifyMax'];
$defaults['calification_notebook_title'] = $threadData['threadTitleQualify'];
$defaults['weight_calification'] = $threadData['threadWeight'];
} else {
$defaults['thread_qualify_gradebook'] = 0;
$defaults['numeric_calification'] = 0;
$defaults['calification_notebook_title'] = '';
$defaults['weight_calification'] = 0;
$defaults['thread_peer_qualify'] = 0;
}
$form->setDefaults(isset($defaults) ? $defaults : null);
$form->addButtonUpdate(get_lang('ModifyThread'), 'SubmitPost');
if ($form->validate()) {
$redirectUrl = api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId;
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
error_log(print_r($values, true));
if (isset($values['thread_qualify_gradebook']) &&
$values['thread_qualify_gradebook'] == '1' &&
empty($values['weight_calification'])
) {
Display::addFlash(
Display::return_message(get_lang('YouMustAssignWeightOfQualification'), 'error', false)
);
header('Location: '.$redirectUrl);
exit;
}
if (isset($origin) && $origin != 'learnpath') {
Display :: display_footer();
Security::clear_token();
updateThread($values);
header('Location: '.$redirectUrl);
exit;
}
} else {
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
}
$orginIsLearpath = $origin == 'learnpath';
$view = new Template('', !$orginIsLearpath, !$orginIsLearpath, $orginIsLearpath, $orginIsLearpath);
$view->assign('actions', $actions);
$view->assign('content', $form->returnForm());
$view->display_one_col_template();

@ -2747,135 +2747,6 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
return $lastThread->getIid();
}
/**
* This function displays the form that is used to UPDATE a Thread.
* @param array $currentForum
* @param array $forumSetting
* @param array $formValues
* @return void HMTL
* @author José Loguercio <jose.loguercio@beeznest.com>
* @version february 2016, chamilo 1.10.4
*/
function showUpdateThreadForm($currentForum, $forumSetting, $formValues = '')
{
$myThread = isset($_GET['thread']) ? intval($_GET['thread']) : '';
$myForum = isset($_GET['forum']) ? intval($_GET['forum']) : '';
$myGradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : '';
$form = new FormValidator(
'thread',
'post',
api_get_self() . '?' . http_build_query([
'forum' => $myForum,
'gradebook' => $myGradebook,
'thread' => $myThread,
]) . '&' . api_get_cidreq()
);
$form->addElement('header', get_lang('EditThread'));
$form->setConstants(array('forum' => '5'));
$form->addElement('hidden', 'forum_id', $myForum);
$form->addElement('hidden', 'thread_id', $myThread);
$form->addElement('hidden', 'gradebook', $myGradebook);
$form->addElement('text', 'thread_title', get_lang('Title'));
$form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
if ((api_is_course_admin() || api_is_course_coach() || api_is_course_tutor()) && ($myThread)) {
// Thread qualify
if (Gradebook::is_active()) {
//Loading gradebook select
GradebookUtils::load_gradebook_select_in_tool($form);
$form->addElement(
'checkbox',
'thread_qualify_gradebook',
'',
get_lang('QualifyThreadGradebook'),
[
'id' => 'thread_qualify_gradebook'
]
);
} else {
$form->addElement('hidden', 'thread_qualify_gradebook', false);
}
$form->addElement('html', '<div id="options_field" style="display:none">');
$form->addElement('text', 'numeric_calification', get_lang('QualificationNumeric'));
$form->applyFilter('numeric_calification', 'html_filter');
$form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'));
$form->applyFilter('calification_notebook_title', 'html_filter');
$form->addElement(
'text',
'weight_calification',
get_lang('QualifyWeight'),
array('value' => '0.00', 'onfocus' => "javascript: this.select();")
);
$form->applyFilter('weight_calification', 'html_filter');
$group = array();
$group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('No'), 0);
$form->addGroup(
$group,
'',
[
get_lang('ForumThreadPeerScoring'),
get_lang('ForumThreadPeerScoringComment'),
]
);
$form->addElement('html', '</div>');
}
if ($forumSetting['allow_sticky'] && api_is_allowed_to_edit(null, true)) {
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
}
$form->addElement('html', '</div>');
if (!empty($formValues)) {
$defaults['thread_qualify_gradebook'] = ($formValues['threadQualifyMax'] > 0 && empty($_POST)) ? 1 : 0 ;
$defaults['thread_title'] = prepare4display($formValues['threadTitle']);
$defaults['thread_sticky'] = strval(intval($formValues['threadSticky']));
$defaults['thread_peer_qualify'] = intval($formValues['threadPeerQualify']);
$defaults['numeric_calification'] = $formValues['threadQualifyMax'];
$defaults['calification_notebook_title'] = $formValues['threadTitleQualify'];
$defaults['weight_calification'] = $formValues['threadWeight'];
} else {
$defaults['thread_qualify_gradebook'] = 0;
$defaults['numeric_calification'] = 0;
$defaults['calification_notebook_title'] = '';
$defaults['weight_calification'] = 0;
$defaults['thread_peer_qualify'] = 0;
}
$form->setDefaults(isset($defaults) ? $defaults : null);
$form->addButtonUpdate(get_lang('ModifyThread'), 'SubmitPost');
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
if (isset($values['thread_qualify_gradebook']) &&
$values['thread_qualify_gradebook'] == '1' &&
empty($values['weight_calification'])
) {
Display::addFlash(Display::return_message(
get_lang('YouMustAssignWeightOfQualification').'&nbsp;<a href="javascript:window.history.go(-1);">'.
get_lang('Back').'</a>',
'error',
false
));
return false;
}
Security::clear_token();
return $values;
}
} else {
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$form->display();
}
}
/**
* This function displays the form that is used to add a post. This can be a new thread or a reply.
* @param array $current_forum

Loading…
Cancel
Save