Adding post moderation see BT#10894

ofaj
jmontoya 9 years ago
parent b5aa212def
commit 885bb43eab
  1. 4
      app/Migrations/Schema/V111/Version111.php
  2. 38
      main/forum/editpost.php
  3. 109
      main/forum/forumfunction.inc.php
  4. 98
      main/forum/reply.php
  5. 45
      main/forum/viewthread.php
  6. 42
      main/forum/viewthread_flat.inc.php
  7. 6
      main/forum/viewthread_nested.inc.php
  8. 7
      main/forum/viewthread_threaded.inc.php
  9. 3
      main/inc/lib/api.lib.php
  10. 27
      src/Chamilo/CourseBundle/Entity/CForumForum.php
  11. 27
      src/Chamilo/CourseBundle/Entity/CForumPost.php

@ -36,7 +36,6 @@ class Version111 extends AbstractMigrationChamilo
$this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_my_files','true','Yes') ");
$this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_my_files','false','No') ");
$this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_invisible_in_session',NULL,'radio','Session','false','ExerciseInvisibleInSessionTitle','ExerciseInvisibleInSessionComment','',NULL, 1)");
$this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('exercise_invisible_in_session','true','Yes') ");
$this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('exercise_invisible_in_session','false','No') ");
@ -44,7 +43,8 @@ class Version111 extends AbstractMigrationChamilo
$this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('configure_exercise_visibility_in_course',NULL,'radio','Session','false','ConfigureExerciseVisibilityInCourseTitle','ConfigureExerciseVisibilityInCourseComment','',NULL, 1)");
$this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('configure_exercise_visibility_in_course','true','Yes') ");
$this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('configure_exercise_visibility_in_course','false','No') ");
$this->addSql("ALTER TABLE c_forum_forum ADD moderated TINYINT(1) DEFAULT NULL");
$this->addSql("ALTER TABLE c_forum_post ADD status INT DEFAULT NULL");
}
/**

@ -73,23 +73,41 @@ if (!empty($gradebook) && $gradebook == 'view') {
}
if ($origin == 'group') {
$_clean['toolgroup'] = (int) $_SESSION['toolgroup'];
$_clean['toolgroup'] = api_get_group_id();
$group_properties = GroupManager::get_group_properties($_clean['toolgroup']);
$interbreadcrumb[] = array('url' => '../group/group.php?'.api_get_cidreq(), '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' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
'name' => get_lang('GroupSpace').' '.$group_properties['name'],
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']),
'name' => prepare4display($current_forum['forum_title']),
);
$interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
} else {
$interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq(), 'name' => $nameTools);
$interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => prepare4display($current_forum_category['cat_title']));
$interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title']));
$interbreadcrumb[] = array('url' => 'viewthread.php?'.api_get_cidreq().'&origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']), 'name' => prepare4display($current_thread['thread_title']));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(), 'name' => $nameTools);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
'name' => prepare4display($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' => prepare4display($current_forum['forum_title']),
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&origin='.$origin.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']),
'name' => prepare4display($current_thread['thread_title']),
);
$interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
}
/* Resource Linker */
if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
if (isset($_POST['add_resources']) && $_POST['add_resources'] == get_lang('Resources')) {
$_SESSION['formelements'] = $_POST;
$_SESSION['origin'] = $_SERVER['REQUEST_URI'];
$_SESSION['breadcrumbs'] = $interbreadcrumb;
@ -212,7 +230,7 @@ $values = show_edit_post_form(
);
if (!empty($values) and isset($_POST['SubmitPost'])) {
store_edit_post($values);
store_edit_post($current_forum, $values);
}
// Footer

@ -24,6 +24,7 @@
use ChamiloSession as Session;
use Doctrine\Common\Collections\Criteria;
use Chamilo\CourseBundle\Entity\CForumPost;
define('FORUM_NEW_POST', 0);
@ -231,10 +232,7 @@ function show_add_forumcategory_form($inputvalues = array(), $lp_id)
function show_add_forum_form($inputvalues = array(), $lp_id)
{
$_course = api_get_course_info();
$gradebook = Security::remove_XSS($_GET['gradebook']);
// Initialize the object.
$form = new FormValidator('forumcategory', 'post', 'index.php?gradebook='.$gradebook.'&'.api_get_cidreq());
$form = new FormValidator('forumcategory', 'post', 'index.php?'.api_get_cidreq());
// The header for the form
if (!empty($inputvalues)) {
@ -242,7 +240,7 @@ function show_add_forum_form($inputvalues = array(), $lp_id)
} else {
$form_title = get_lang('AddForum');
}
$session_header = isset($_SESSION['session_name']) ? ' ('.$_SESSION['session_name'].') ' : '';
$session_header = api_get_session_name();
$form->addElement('header', $form_title.$session_header);
// We have a hidden field if we are editing.
@ -251,6 +249,7 @@ function show_add_forum_form($inputvalues = array(), $lp_id)
$form->addElement('hidden', 'forum_id', $my_forum_id);
}
$lp_id = intval($lp_id);
// hidden field if from learning path
$form->addElement('hidden', 'lp_id', $lp_id);
@ -285,6 +284,11 @@ function show_add_forum_form($inputvalues = array(), $lp_id)
$form->addButtonAdvancedSettings('advanced_params');
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
$group = array();
$group[] = $form->createElement('radio', 'moderated', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'moderated', null, get_lang('No'), 0);
$form->addGroup($group, 'moderated', get_lang('ModeratedForum'), ' ');
$group = array();
$group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('No'), 0);
@ -361,6 +365,7 @@ function show_add_forum_form($inputvalues = array(), $lp_id)
// Settings the defaults
if (empty($inputvalues) || !is_array($inputvalues)) {
$defaults['moderated']['moderated'] = 0;
$defaults['allow_anonymous_group']['allow_anonymous'] = 0;
$defaults['students_can_edit_group']['students_can_edit'] = 0;
$defaults['approval_direct_group']['approval_direct'] = 0;
@ -375,6 +380,7 @@ function show_add_forum_form($inputvalues = array(), $lp_id)
$defaults['forum_id'] = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
$defaults['forum_title'] = prepare4display(isset($inputvalues['forum_title']) ? $inputvalues['forum_title'] : null);
$defaults['forum_comment'] = prepare4display(isset($inputvalues['forum_comment']) ? $inputvalues['forum_comment'] : null);
$defaults['moderated']['moderated'] = isset($inputvalues['moderated']) ? $inputvalues['moderated'] : 0;
$defaults['forum_category'] = isset($inputvalues['forum_category']) ? $inputvalues['forum_category'] : null;
$defaults['allow_anonymous_group']['allow_anonymous'] = isset($inputvalues['allow_anonymous']) ? $inputvalues['allow_anonymous'] : null;
$defaults['students_can_edit_group']['students_can_edit'] = isset($inputvalues['allow_edit']) ? $inputvalues['allow_edit'] : null;
@ -685,6 +691,7 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
'default_view'=> isset($values['default_view_type_group']['default_view_type']) ? $values['default_view_type_group']['default_view_type'] : null,
'forum_of_group'=> isset($values['group_forum']) ? $values['group_forum'] : null,
'forum_group_public_private'=> isset($values['public_private_group_forum_group']['public_private_group_forum']) ? $values['public_private_group_forum_group']['public_private_group_forum'] : null,
'moderated'=> isset($values['moderated']['moderated']) ? 1 : 0,
'forum_order'=> isset($new_max) ? $new_max : null,
'session_id'=> $session_id,
'lp_id' => isset($values['lp_id']) ? intval($values['lp_id']) : 0
@ -725,6 +732,7 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
'default_view'=> isset($values['default_view_type_group']['default_view_type']) ? $values['default_view_type_group']['default_view_type'] : null,
'forum_of_group'=> isset($values['group_forum']) ? $values['group_forum'] : null,
'forum_group_public_private'=> isset($values['public_private_group_forum_group']['public_private_group_forum']) ? $values['public_private_group_forum_group']['public_private_group_forum'] : null,
'moderated'=> isset($values['moderated']['moderated']) ? 1 : 0,
'forum_order'=> isset($new_max) ? $new_max : null,
'session_id'=> $session_id,
'lp_id' => isset($values['lp_id']) ? intval($values['lp_id']) : 0
@ -1838,6 +1846,7 @@ function getThreadInfo($threadId, $cId)
/**
* Retrieve all posts of a given thread
* @param array $forumInfo
* @param int $threadId The thread ID
* @param string $orderDirection Optional. The direction for sort the posts
* @param boolean $recursive Optional. If the list is recursive
@ -1847,7 +1856,7 @@ function getThreadInfo($threadId, $cId)
*
* @return array containing all the information about the posts of a given thread
*/
function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postId = 0, $depth = -1)
function getPosts($forumInfo, $threadId, $orderDirection = 'ASC', $recursive = false, $postId = 0, $depth = -1)
{
$list = [];
@ -1866,6 +1875,12 @@ function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postI
->andWhere($visibleCriteria)
;
if (!api_is_allowed_to_edit()) {
if ($forumInfo['moderated']) {
$criteria->where(Criteria::expr()->eq('status', 1));
}
}
if ($recursive) {
$criteria->andWhere(Criteria::expr()->eq('postParentId', $postId));
}
@ -1875,10 +1890,11 @@ function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postI
->addCriteria($criteria)
->addOrderBy('p.postId', $orderDirection);
$posts = $qb->getQuery()->getResult();
$depth++;
/** @var \Chamilo\CourseBundle\Entity\CForumPost $post */
/** @var CForumPost $post */
foreach ($posts as $post) {
$user = $em->find('ChamiloUserBundle:User', $post->getPosterId());
@ -1895,6 +1911,7 @@ function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postI
'post_notification' => $post->getPostNotification(),
'post_parent_id' => $post->getPostParentId(),
'visible' => $post->getVisible(),
'status' => $post->getStatus(),
'indent_cnt' => $depth,
'user_id' => $user->getUserId(),
'username' => $user->getUsername(),
@ -1910,6 +1927,7 @@ function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postI
$list = array_merge(
$list,
getPosts(
$forumInfo,
$threadId,
$orderDirection,
$recursive,
@ -1938,13 +1956,13 @@ function get_post_information($post_id)
$table_users = Database :: get_main_table(TABLE_MAIN_USER);
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM ".$table_posts." posts, ".$table_users." users
$sql = "SELECT posts.*, email FROM ".$table_posts." posts, ".$table_users." users
WHERE
c_id = $course_id AND
posts.poster_id=users.user_id AND
posts.post_id = ".intval($post_id)."";
posts.post_id = ".intval($post_id);
$result = Database::query($sql);
$row = Database::fetch_array($result);
$row = Database::fetch_array($result, 'ASSOC');
return $row;
}
@ -2603,6 +2621,7 @@ function showUpdateThreadForm($currentForum, $forumSetting, $formValues = '')
$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()) {
@ -2913,10 +2932,12 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
$values['thread_qualify_gradebook'] == '1' &&
empty($values['weight_calification'])
) {
Display::display_error_message(
get_lang('YouMustAssignWeightOfQualification').'&nbsp;<a href="javascript:window.history.go(-1);">'.
get_lang('Back').'</a>',
Display::addFlash(
Display::return_message(
get_lang('YouMustAssignWeightOfQualification').'&nbsp;<a href="javascript:window.history.go(-1);">'.get_lang('Back').'</a>',
'error',
false
)
);
return false;
@ -2937,7 +2958,8 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
$attachmentAjaxTable = getAttachmentsAjaxTable(0, $current_forum['forum_id']);
$ajaxHtml = $attachmentAjaxTable;
$form->addElement('html', $ajaxHtml);
$form->display();
return $form;
}
}
@ -3239,7 +3261,6 @@ function store_reply($current_forum, $values)
}
$upload_ok = 1;
$return = array();
if ($upload_ok) {
@ -3306,6 +3327,12 @@ function store_reply($current_forum, $values)
$message .= '<br />'.get_lang('MessageHasToBeApproved').'<br />';
}
if ($current_forum['moderated'] &&
!api_is_allowed_to_edit(null, true)
) {
$message .= '<br />'.get_lang('MessageHasToBeApproved').'<br />';
}
// Setting the notification correctly.
$my_post_notification = isset($values['post_notification']) ? $values['post_notification'] : null;
if ($my_post_notification == 1) {
@ -3321,12 +3348,12 @@ function store_reply($current_forum, $values)
Session::erase('breadcrumbs');
Session::erase('addedresource');
Session::erase('addedresourceid');
$return['msg'] = $message;
$return['type'] = 'confirmation';
Display::addFlash(Display::return_message($message, 'confirmation', false));
} else {
$return['msg'] = get_lang('UplNoFileUploaded').' '.get_lang('UplSelectFileFirst');
$return['type'] = 'error';
Display::addFlash(
Display::return_message(get_lang('UplNoFileUploaded').' '.get_lang('UplSelectFileFirst'), 'error')
);
}
return $return;
@ -3463,9 +3490,20 @@ function show_edit_post_form(
$form->addElement('html', '</div>');
}
if ($current_forum['moderated']) {
$group = array();
$group[] = $form->createElement('radio', 'status', null, get_lang('Validated'), 1);
$group[] = $form->createElement('radio', 'status', null, get_lang('WaitingModeration'), 2);
$group[] = $form->createElement('radio', 'status', null, get_lang('Rejected'), 3);
$form->addGroup($group, 'status', get_lang('Status'), ' ');
}
$defaults['status']['status'] = isset($current_post['status']) && !empty($current_post['status']) ? $current_post['status'] : 2;
if ($forum_setting['allow_post_notification']) {
$form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail').' ('.$current_post['email'].')');
}
if ($forum_setting['allow_sticky'] &&
api_is_allowed_to_edit(null, true) &&
$current_post['post_parent_id'] == 0
@ -3501,6 +3539,7 @@ function show_edit_post_form(
// Setting the default values for the form elements.
$defaults['post_title'] = $current_post['post_title'];
$defaults['post_text'] = $current_post['post_text'];
if ($current_post['post_notification'] == 1) {
$defaults['post_notification'] = true;
}
@ -3548,7 +3587,7 @@ function show_edit_post_form(
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function store_edit_post($values)
function store_edit_post($forumInfo, $values)
{
$threadTable = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
@ -3559,7 +3598,7 @@ function store_edit_post($values)
// First we check if the change affects the thread and if so we commit
// the changes (sticky and post_title=thread_title are relevant).
$posts = getPosts($values['thread_id']);
$posts = getPosts($forumInfo, $values['thread_id']);
$first_post = null;
if (!empty($posts) && count($posts) > 0 && isset($posts[0])) {
$first_post = $posts[0];
@ -3579,8 +3618,14 @@ function store_edit_post($values)
Database::update($threadTable, $params, $where);
}
$status = '';
if ($forumInfo['moderated']) {
$status = $values['status']['status'];
}
// Update the post_title and the post_text.
$params = [
'status' => $status,
'post_title' => $values['post_title'],
'post_text' => $values['post_text'],
'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : '',
@ -5857,3 +5902,25 @@ function getForumCategoryByTitle($title, $courseId, $sessionId = 0)
return $resultData;
}
function getPostStatus($current_forum, $row)
{
$statusIcon = '';
if ($current_forum['moderated']) {
$statusIcon = '<br /><br />';
$row['status'] = empty($row['status']) ? 2 : $row['status'];
switch ($row['status']) {
case 1:
$statusIcon .= Display::label(get_lang('Validated'), 'success');
break;
case 2:
$statusIcon .= Display::label(get_lang('WaitingModeration'), 'warning');
break;
case 3:
$statusIcon .= Display::label(get_lang('Rejected'), 'danger');
break;
}
}
return $statusIcon;
}

@ -56,13 +56,17 @@ $current_forum_category = get_forumcategory_information(Security::remove_XSS($cu
// 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) AND (($current_forum_category && $current_forum_category['visibility'] == 0) OR $current_forum['visibility'] == 0)) {
if (!api_is_allowed_to_edit(false, true) &&
(($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
) {
api_not_allowed();
}
if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category && $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['locked'] <> 0) || $current_forum['locked'] <> 0 || $current_thread['locked'] <> 0)
) {
api_not_allowed();
}
if (!$_user['user_id'] AND $current_forum['allow_anonymous'] == 0) {
if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
api_not_allowed();
}
@ -92,24 +96,27 @@ if (!empty($gradebook) && $gradebook == 'view') {
}
if ($origin == 'group') {
$_clean['toolgroup'] = (int)$_SESSION['toolgroup'];
$_clean['toolgroup'] = api_get_group_id();
$group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
$interbreadcrumb[] = array(
'url' => '../group/group.php?'.api_get_cidreq(),
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
);
$interbreadcrumb[] = array(
'url' => '../group/group_space.php?'.api_get_cidreq(),
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
'name' => get_lang('GroupSpace').' '.$group_properties['name'],
);
$interbreadcrumb[] = array(
'url' => 'viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
'name' => $current_forum['forum_title'],
);
$interbreadcrumb[] = array(
'url' => 'viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&'.api_get_cidreq(),
'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'],
);
$interbreadcrumb[] = array(
'url' => 'javascript: void(0);',
'name' => get_lang('Reply'),
@ -120,15 +127,15 @@ if ($origin == 'group') {
'name' => $nameTools,
);
$interbreadcrumb[] = array(
'url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
'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'],
);
$interbreadcrumb[] = array(
'url' => 'viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
'name' => $current_forum['forum_title'],
);
$interbreadcrumb[] = array(
'url' => 'viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&'.api_get_cidreq(),
'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'],
);
$interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
@ -163,6 +170,42 @@ $htmlHeadXtra[] = <<<JS
</script>
JS;
/* End new display forum */
// The form for the reply
$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(
$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();
} else {
@ -185,37 +228,8 @@ echo '<h1><a href="viewforum.php?&origin='.$origin.'&forum='.$current_forum['for
prepare4display($current_forum['forum_title']).'</a></h1>';
echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
echo '</div>';
/* End new display forum */
// The form for the reply
$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(
$current_forum,
$forum_setting,
$my_action,
$my_post,
$my_elements
);
if (!empty($values) && isset($_POST['SubmitPost'])) {
$result = store_reply($current_forum, $values);
//@todo split the show_add_post_form function
$origin = isset($_GET['origin']) && $_GET['origin'] === 'learnpath' ? 'learnpath' : null;
$url = 'viewthread.php?' . http_build_query([
'forum' => $current_thread['forum_id'],
'gradebook' => $gradebook,
'thread' => intval($_GET['thread']),
'gidReq' => api_get_group_id(),
'origin' => $origin,
'msg' => $result['msg'],
'type' => $result['type']
]);
echo '
<script>
window.location = "'.$url.'";
</script>';
}
echo $form;
if ($origin == 'learnpath') {
Display::display_reduced_footer();

@ -61,20 +61,19 @@ $sessionId = api_get_session_id();
if ($origin == 'group') {
$group_properties = GroupManager::get_group_properties($groupId);
$interbreadcrumb[] = array(
'url' => '../group/group.php',
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups')
);
$interbreadcrumb[] = array(
'url' => '../group/group_space.php?' . api_get_cidreq(),
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?' . api_get_cidreq(),
'name' => get_lang('GroupSpace') . ' ' . $group_properties['name']
);
$interbreadcrumb[] = array(
'url' => 'viewforum.php?forum=' . intval($_GET['forum']) . '&' . api_get_cidreq()
. "&origin=$origin&search=" . Security::remove_XSS(urlencode($my_search)),
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum=' . intval($_GET['forum']) . '&' . api_get_cidreq(). "&search=" . Security::remove_XSS(urlencode($my_search)),
'name' => Security::remove_XSS($current_forum['forum_title'])
);
$interbreadcrumb[] = array(
'url' => 'viewthread.php?forum=' . intval($_GET['forum']) . '&' . api_get_cidreq(). '&thread=' . intval($_GET['thread']),
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum=' . intval($_GET['forum']) . '&' . api_get_cidreq(). '&thread=' . intval($_GET['thread']),
'name' => Security::remove_XSS($current_thread['thread_title'])
);
@ -85,22 +84,15 @@ if ($origin == 'group') {
Display::display_reduced_header();
} else {
$interbreadcrumb[] = array(
'url' => 'index.php?'
. (isset($gradebook) ? "gradebook=$gradebook&" : '')
. 'search=' . Security::remove_XSS(urlencode($my_search)),
'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search=' . Security::remove_XSS(urlencode($my_search)),
'name' => $nameTools
);
$interbreadcrumb[] = array(
'url' => 'viewforumcategory.php?forumcategory='
. $current_forum_category['cat_id']
. "&origin=$origin&search="
. Security::remove_XSS(urlencode($my_search)),
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='. $current_forum_category['cat_id']. "&search=". Security::remove_XSS(urlencode($my_search)),
'name' => Security::remove_XSS($current_forum_category['cat_title'])
);
$interbreadcrumb[] = array(
'url' => 'viewforum.php?forum=' . intval($_GET['forum'])
. "&origin=$origin&search="
. Security::remove_XSS(urlencode($my_search)),
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum=' . intval($_GET['forum']). "&search=". Security::remove_XSS(urlencode($my_search)),
'name' => Security::remove_XSS($current_forum['forum_title'])
);
$interbreadcrumb[] = array(
@ -138,9 +130,7 @@ if (
) {
$message = delete_post($_GET['id']);
}
if (
($my_action == 'invisible' ||
$my_action == 'visible') &&
if (($my_action == 'invisible' || $my_action == 'visible') &&
isset($_GET['id']) &&
(api_is_allowed_to_edit(false, true) ||
GroupManager::is_tutor_of_group(api_get_user_id(), $groupId))
@ -186,7 +176,7 @@ if ($my_message != 'PostDeletedSpecial') {
api_is_allowed_to_edit(false, true)
) {
// The link should only appear when the user is logged in or when anonymous posts are allowed.
if ($_user['user_id'] OR ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) {
if ($_user['user_id'] || ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) {
// reply link
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
echo '<a href="' . $forumUrl . 'reply.php?' . api_get_cidreq() . '&forum='
@ -204,7 +194,7 @@ if ($my_message != 'PostDeletedSpecial') {
($current_forum['allow_new_threads'] == 1 && isset($_user['user_id'])) ||
($current_forum['allow_new_threads'] == 1 && !isset($_user['user_id']) && $current_forum['allow_anonymous'] == 1)
) {
if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
if ($current_forum['locked'] <> 1 && $current_forum['locked'] <> 1) {
echo '&nbsp;&nbsp;';
} else {
echo get_lang('ForumLocked');
@ -231,7 +221,7 @@ if ($my_message != 'PostDeletedSpecial') {
/* Display Forum Category and the Forum information */
if (!isset($_SESSION['view'])) {
if (!isset($_SESSION['view'])) {
$viewMode = $current_forum['default_view'];
} else {
$viewMode = $_SESSION['view'];
@ -246,18 +236,7 @@ if ($my_message != 'PostDeletedSpecial') {
$viewMode = 'flat';
}
if (isset($_GET['msg']) && isset($_GET['type'])) {
switch($_GET['type']) {
case 'error':
Display::display_error_message($_GET['msg']);
break;
case 'confirmation':
Display::display_confirmation_message($_GET['msg']);
break;
}
}
if ($current_thread['thread_peer_qualify'] == 1 ) {
if ($current_thread['thread_peer_qualify'] == 1) {
echo Display::return_message(get_lang('ForumThreadPeerScoringStudentComment'), 'info');
}

@ -15,7 +15,6 @@ if ((isset($_GET['action']) &&
delete_attachment(0, $_GET['id_attach']);
}
// Are we in a lp ?
$origin = '';
if (isset($_GET['origin'])) {
@ -31,7 +30,7 @@ $groupId = api_get_group_id();
$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : ($origin != 'learnpath' ? 'ASC' : 'DESC');
if (isset($current_thread['thread_id'])) {
$rows = getPosts($current_thread['thread_id'], $sortDirection);
$rows = getPosts($current_forum, $current_thread['thread_id'], $sortDirection);
$increment = 0;
$clean_forum_id = intval($_GET['forum']);
$clean_thread_id = intval($_GET['thread']);
@ -130,7 +129,6 @@ if (isset($current_thread['thread_id'])) {
);
} else {
$name = Display::tag('strong', "#" . $postCount--, ['class' => 'text-info']) . " | $name";
$html .= Display::tag(
'p',
$name,
@ -201,11 +199,15 @@ if (isset($current_thread['thread_id'])) {
api_is_allowed_to_edit(false, true) &&
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
) {
$statusIcon = getPostStatus($current_forum, $row);
$iconEdit .= return_visible_invisible_icon(
'post', $row['post_id'], $row['visible'], array(
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'origin' => $origin,
'post',
$row['post_id'],
$row['visible'],
array(
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'origin' => $origin,
)
);
$iconEdit .= "";
@ -219,14 +221,8 @@ if (isset($current_thread['thread_id'])) {
}
}
$user_status = api_get_status_of_user_in_course(
$row['user_id'], api_get_course_int_id()
);
$current_qualify_thread = showQualify(
'1', $row['poster_id'], $_GET['thread']
);
$user_status = api_get_status_of_user_in_course($row['user_id'], api_get_course_int_id());
$current_qualify_thread = showQualify('1', $row['poster_id'], $_GET['thread']);
if (
(
$current_thread['thread_peer_qualify'] == 1 ||
@ -254,27 +250,33 @@ if (isset($current_thread['thread_id'])) {
}
}
if ($iconEdit != '') {
$html .= '<div class="tools-icons">' . $iconEdit . '</div>';
$html .= '<div class="tools-icons">' . $iconEdit . $statusIcon.'</div>';
}
$html .= $closedPost;
$html .= '</div>';
$html .= '<div class="col-md-10">';
$titlePost = Display::tag(
'h3', $row['post_title'],
'h3',
$row['post_title'],
array('class' => 'forum_post_title')
);
$html .= Display::tag(
'div', $titlePost,
'div',
$titlePost,
array('class' => 'post-header')
);
// see comments inside forumfunction.inc.php to lower filtering and allow more visual changes
$html .= Display::tag(
'div', $row['post_text'],
'div',
$row['post_text'],
array('class' => 'post-body')
);
$html .= '</div>';
@ -307,10 +309,8 @@ if (isset($current_thread['thread_id'])) {
$attachment_list = getAllAttachment($row['post_id']);
if (!empty($attachment_list) && is_array($attachment_list)) {
foreach ($attachment_list as $attachment) {
$realname = $attachment['path'];
$user_filename = $attachment['filename'];
$html .= Display::return_icon('attachment.gif', get_lang('Attachment'));
$html .= '<a href="download.php?file=' . $realname . '"> ' . $user_filename . ' </a>';

@ -25,7 +25,7 @@ if (isset($_GET['action']) &&
// Decide whether we show the latest post first
$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : ($origin != 'learnpath' ? 'ASC' : 'DESC');
$rows = getPosts($_GET['thread'], $sortDirection, true);
$rows = getPosts($current_forum, $_GET['thread'], $sortDirection, true);
$count = 0;
$clean_forum_id = intval($_GET['forum']);
$clean_thread_id = intval($_GET['thread']);
@ -191,8 +191,10 @@ foreach ($rows as $post) {
}
}
$statusIcon = getPostStatus($current_forum, $post);
if ($iconEdit != '') {
$html .= '<div class="tools-icons">' . $iconEdit . '</div>';
$html .= '<div class="tools-icons">' . $iconEdit . ' '.$statusIcon.'</div>';
}
if (($current_forum_category && $current_forum_category['locked'] == 0) &&

@ -24,7 +24,7 @@
$forumUrl = api_get_path(WEB_CODE_PATH) . 'forum/';
$_user = api_get_user_info();
$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : 'ASC';
$rows = getPosts($_GET['thread'], $sortDirection, true);
$rows = getPosts($current_forum, $_GET['thread'], $sortDirection, true);
$sessionId = api_get_session_id();
$currentThread = get_thread_information($_GET['thread']);
$post_id = isset($_GET['post']) ? (int) $_GET['post'] : 0;
@ -263,7 +263,7 @@ if (
// Verified the post minor
$my_post = getPosts($_GET['thread']);
$my_post = getPosts($current_forum, $_GET['thread']);
$id_posts = array();
if (!empty($my_post) && is_array($my_post)) {
@ -279,7 +279,7 @@ if (!empty($my_post) && is_array($my_post)) {
if (
GroupManager::is_tutor_of_group(api_get_user_id(), $groupId) ||
api_is_allowed_to_edit(false, true) &&
!(api_is_course_coach() &&$current_forum['session_id'] != $sessionId)
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
) {
if ($locked == false) {
echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() .
@ -295,7 +295,6 @@ if (
ICON_SIZE_SMALL
)."</a>";
}
echo return_visible_invisible_icon(
'post',
$rows[$display_post_id]['post_id'],

@ -2175,13 +2175,12 @@ function api_get_group_id()
return Session::read('_gid', 0);
}
/**
* Gets the current or given session name
* @param int Session ID (optional)
* @return string The session name, or null if unfound
*/
function api_get_session_name($session_id) {
function api_get_session_name($session_id = 0) {
if (empty($session_id)) {
$session_id = api_get_session_id();
if (empty($session_id)) { return null; }

@ -183,11 +183,18 @@ class CForumForum
/**
* @var integer
*
*
* @ORM\Column(name="lp_id", type="integer", options={"unsigned":true})
*/
private $lpId;
/**
* @var boolean
*
* @ORM\Column(name="moderated", type="boolean", nullable=true)
*/
private $moderated;
/**
* Set forumTitle
*
@ -715,4 +722,22 @@ class CForumForum
return $this->lpId;
}
/**
* @return boolean
*/
public function isModerated()
{
return $this->moderated;
}
/**
* @param $moderated
* @return $this
*/
public function setModerated($moderated)
{
$this->moderated = $moderated;
return $this;
}
}

@ -115,6 +115,13 @@ class CForumPost
*/
private $visible;
/**
* @var integer
*
* @ORM\Column(name="status", type="integer", nullable=true)
*/
private $status;
/**
* Set postTitle
*
@ -390,4 +397,24 @@ class CForumPost
{
return $this->cId;
}
/**
* @return int
*/
public function getStatus()
{
return $this->status;
}
/**
* @param int $status
* @return CForumPost
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
}

Loading…
Cancel
Save