upgrade
This commit is contained in:
88
main/forum/download.php
Normal file
88
main/forum/download.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This file is responsible for passing requested documents to the browser.
|
||||
* Html files are parsed to fix a few problems with URLs,
|
||||
* but this code will hopefully be replaced soon by an Apache URL
|
||||
* rewrite mechanism.
|
||||
*
|
||||
* @package chamilo.document
|
||||
*/
|
||||
session_cache_limiter('public');
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_course_script(true);
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
// IMPORTANT to avoid caching of documents
|
||||
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
|
||||
header('Cache-Control: public');
|
||||
header('Pragma: no-cache');
|
||||
|
||||
$doc_url = $_GET['file'];
|
||||
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
|
||||
$doc_url = str_replace('///', '&', $doc_url);
|
||||
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
|
||||
$doc_url = str_replace(' ', '+', $doc_url);
|
||||
$doc_url = str_replace('/..', '', $doc_url);
|
||||
|
||||
$tbl_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
|
||||
$tbl_forum_post = Database::get_course_table(TABLE_FORUM_POST);
|
||||
|
||||
$course_id = api_get_course_int_id();
|
||||
$courseInfo = api_get_course_info_by_id($course_id);
|
||||
|
||||
$sql = 'SELECT thread_id, forum_id,filename
|
||||
FROM '.$tbl_forum_post.' f
|
||||
INNER JOIN '.$tbl_forum_attachment.' a
|
||||
ON a.post_id=f.post_id
|
||||
WHERE
|
||||
f.c_id = '.$course_id.' AND
|
||||
a.c_id = '.$course_id.' AND
|
||||
path LIKE BINARY "'.Database::escape_string($doc_url).'"';
|
||||
|
||||
$result = Database::query($sql);
|
||||
$row = Database::fetch_array($result);
|
||||
|
||||
if (empty($row)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$forum_thread_visibility = api_get_item_visibility(
|
||||
$courseInfo,
|
||||
TOOL_FORUM_THREAD,
|
||||
$row['thread_id'],
|
||||
api_get_session_id()
|
||||
);
|
||||
$forum_forum_visibility = api_get_item_visibility(
|
||||
$courseInfo,
|
||||
TOOL_FORUM,
|
||||
$row['forum_id'],
|
||||
api_get_session_id()
|
||||
);
|
||||
|
||||
if ($forum_thread_visibility == 1 && $forum_forum_visibility == 1) {
|
||||
$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/'.$doc_url;
|
||||
if (Security::check_abs_path(
|
||||
$full_file_name,
|
||||
api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/upload/forum/'
|
||||
)) {
|
||||
// launch event
|
||||
Event::event_download($doc_url);
|
||||
|
||||
$result = DocumentManager::file_send_for_download(
|
||||
$full_file_name,
|
||||
true,
|
||||
$row['filename']
|
||||
);
|
||||
|
||||
if ($result === false) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
api_not_allowed();
|
||||
246
main/forum/editpost.php
Normal file
246
main/forum/editpost.php
Normal file
@@ -0,0 +1,246 @@
|
||||
<?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
|
||||
* are added:
|
||||
* - forum categories and forums can be sorted up or down, locked or made invisible
|
||||
* - consistent and integrated forum administration
|
||||
* - forum options: are students allowed to edit their post?
|
||||
* moderation of posts (approval)
|
||||
* reply only forums (students cannot create new threads)
|
||||
* multiple forums per group
|
||||
* - sticky messages
|
||||
* - new view option: nested view
|
||||
* - quoting a message.
|
||||
*
|
||||
* @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
* @Copyright Ghent University
|
||||
* @Copyright Patrick Cool
|
||||
*
|
||||
* @package chamilo.forum
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// The section (tabs).
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
// Notification for unauthorized people.
|
||||
api_protect_course_script(true);
|
||||
|
||||
$nameTools = get_lang('ToolForum');
|
||||
|
||||
// Unset the formElements in session before the includes function works
|
||||
unset($_SESSION['formelements']);
|
||||
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
// Are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
|
||||
/* MAIN DISPLAY SECTION */
|
||||
|
||||
/* Retrieving forum and forum category 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 category are stored in the item_property table.
|
||||
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
|
||||
$current_thread = get_thread_information($forumId, $_GET['thread']);
|
||||
$current_forum = get_forum_information($forumId);
|
||||
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
|
||||
$current_post = get_post_information($_GET['post']);
|
||||
if (empty($current_post)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
|
||||
|
||||
$isEditable = postIsEditableByStudent($current_forum, $current_post);
|
||||
if (!$isEditable) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
$group_properties = GroupManager::get_group_properties(api_get_group_id());
|
||||
if ($origin == 'group') {
|
||||
$_clean['toolgroup'] = api_get_group_id();
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('Groups'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('GroupSpace').' '.$group_properties['name'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId,
|
||||
'name' => prepare4display($current_forum['forum_title']),
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => 'javascript: void (0);', 'name' => get_lang('EditPost')];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(),
|
||||
'name' => $nameTools,
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'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[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
|
||||
'name' => prepare4display($current_forum['forum_title']),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.intval($_GET['thread']),
|
||||
'name' => prepare4display($current_thread['thread_title']),
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => 'javascript: void (0);', 'name' => get_lang('EditPost')];
|
||||
}
|
||||
|
||||
$table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
|
||||
|
||||
/* Header */
|
||||
$htmlHeadXtra[] = <<<JS
|
||||
<script>
|
||||
$(function() {
|
||||
$('#reply-add-attachment').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var newInputFile = $('<input>', {
|
||||
type: 'file',
|
||||
name: 'user_upload[]'
|
||||
});
|
||||
|
||||
$('[name="user_upload[]"]').parent().append(newInputFile);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
JS;
|
||||
|
||||
/* Is the user allowed here? */
|
||||
|
||||
// The user is not allowed here if
|
||||
// 1. the forum category, forum or thread is invisible (visibility==0)
|
||||
// 2. the forum category, forum or thread is locked (locked <>0)
|
||||
// 3. if anonymous posts are not allowed
|
||||
// 4. if editing of replies is not allowed
|
||||
// The only exception is the course manager
|
||||
// I have split this is several pieces for clarity.
|
||||
if (!api_is_allowed_to_edit(null, true) &&
|
||||
(
|
||||
($current_forum_category && $current_forum_category['visibility'] == 0) ||
|
||||
$current_forum['visibility'] == 0
|
||||
)
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (!api_is_allowed_to_edit(null, true) &&
|
||||
(
|
||||
($current_forum_category && $current_forum_category['locked'] != 0) ||
|
||||
$current_forum['locked'] != 0 ||
|
||||
$current_thread['locked'] != 0
|
||||
)
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$group_id = api_get_group_id();
|
||||
|
||||
if (!api_is_allowed_to_edit(null, true) &&
|
||||
$current_forum['allow_edit'] == 0 &&
|
||||
!GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties)
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
Display::display_reduced_header();
|
||||
} else {
|
||||
Display::display_header();
|
||||
}
|
||||
|
||||
// Action links
|
||||
if ($origin != 'learnpath') {
|
||||
echo '<div class="actions">';
|
||||
echo '<span style="float:right;">'.search_link().'</span>';
|
||||
if ($origin == 'group') {
|
||||
echo '<a href="../group/group_space.php?'.api_get_cidreq().'">'.
|
||||
Display::return_icon(
|
||||
'back.png',
|
||||
get_lang('BackTo').' '.get_lang('Groups'),
|
||||
'',
|
||||
ICON_SIZE_MEDIUM
|
||||
).
|
||||
'</a>';
|
||||
} else {
|
||||
echo '<a href="index.php?'.api_get_cidreq().'">'.
|
||||
Display::return_icon(
|
||||
'back.png',
|
||||
get_lang('BackToForumOverview'),
|
||||
'',
|
||||
ICON_SIZE_MEDIUM
|
||||
).
|
||||
'</a>';
|
||||
}
|
||||
echo '<a href="viewforum.php?forum='.$forumId.'&'.api_get_cidreq().'">'.
|
||||
Display::return_icon(
|
||||
'forum.png',
|
||||
get_lang('BackToForum'),
|
||||
'',
|
||||
ICON_SIZE_MEDIUM
|
||||
).
|
||||
'</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/* Display Forum Category and the Forum information */
|
||||
|
||||
/*New display forum div*/
|
||||
echo '<div class="forum_title">';
|
||||
echo '<h1>';
|
||||
echo Display::url(
|
||||
prepare4display($current_forum['forum_title']),
|
||||
'viewforum.php?'.api_get_cidreq().'&'.http_build_query([
|
||||
'origin' => $origin,
|
||||
'forum' => $current_forum['forum_id'],
|
||||
]),
|
||||
['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
|
||||
);
|
||||
echo '</h1>';
|
||||
echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
|
||||
echo '</div>';
|
||||
/* End new display forum */
|
||||
|
||||
// Set forum attachment data into $_SESSION
|
||||
getAttachedFiles(
|
||||
$current_forum['forum_id'],
|
||||
$current_thread['thread_id'],
|
||||
$current_post['post_id']
|
||||
);
|
||||
|
||||
show_edit_post_form(
|
||||
$current_post,
|
||||
$current_thread,
|
||||
$current_forum,
|
||||
isset($_SESSION['formelements']) ? $_SESSION['formelements'] : ''
|
||||
);
|
||||
|
||||
// Footer
|
||||
if (isset($origin) && $origin == 'learnpath') {
|
||||
Display::display_reduced_footer();
|
||||
} else {
|
||||
Display::display_footer();
|
||||
}
|
||||
269
main/forum/editthread.php
Normal file
269
main/forum/editthread.php
Normal file
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Edit a Forum Thread.
|
||||
*
|
||||
* @Author José Loguercio <jose.loguercio@beeznest.com>
|
||||
*
|
||||
* @package chamilo.forum
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// The section (tabs).
|
||||
$this_section = SECTION_COURSES;
|
||||
// Notification for unauthorized people.
|
||||
api_protect_course_script(true);
|
||||
|
||||
$cidreq = api_get_cidreq();
|
||||
$nameTools = get_lang('ToolForum');
|
||||
$_user = api_get_user_info();
|
||||
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
// Are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
|
||||
/* MAIN DISPLAY SECTION */
|
||||
$forumId = (int) $_GET['forum'];
|
||||
$currentForum = get_forum_information($forumId);
|
||||
$currentForumCategory = get_forumcategory_information($currentForum['forum_category']);
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
$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? */
|
||||
|
||||
// The user is not allowed here if:
|
||||
|
||||
// 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
(($currentForumCategory['visibility'] && $currentForumCategory['visibility'] == 0) || $currentForum['visibility'] == 0)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
// 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
(($currentForumCategory['visibility'] && $currentForumCategory['locked'] != 0) || $currentForum['locked'] != 0)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
// 3. new threads are not allowed and the user is not a course manager
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
$currentForum['allow_new_threads'] != 1
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
// 4. anonymous posts are not allowed and the user is not logged in
|
||||
if (!$_user['user_id'] && $currentForum['allow_anonymous'] != 1) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
// 5. Check user access
|
||||
if ($currentForum['forum_of_group'] != 0) {
|
||||
$show_forum = GroupManager::user_has_access(
|
||||
api_get_user_id(),
|
||||
$currentForum['forum_of_group'],
|
||||
GroupManager::GROUP_TOOL_FORUM
|
||||
);
|
||||
if (!$show_forum) {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Invited users can't create new threads
|
||||
if (api_is_invitee()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$groupId = api_get_group_id();
|
||||
if (!empty($groupId)) {
|
||||
$groupProperties = GroupManager::get_group_properties($groupId);
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.$cidreq,
|
||||
'name' => get_lang('Groups'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.$cidreq,
|
||||
'name' => get_lang('GroupSpace').' '.$groupProperties['name'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.$forumId,
|
||||
'name' => $currentForum['forum_title'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/newthread.php?'.$cidreq.'&forum='.$forumId,
|
||||
'name' => get_lang('EditThread'),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.$cidreq, 'name' => $nameTools];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.$cidreq.'&forumcategory='.$currentForumCategory['cat_id'],
|
||||
'name' => $currentForumCategory['cat_title'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.$forumId,
|
||||
'name' => $currentForum['forum_title'],
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('EditThread')];
|
||||
}
|
||||
|
||||
$tableLink = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
|
||||
|
||||
/* Header */
|
||||
$htmlHeadXtra[] = <<<JS
|
||||
<script>
|
||||
$(function() {
|
||||
$('[name="thread_qualify_gradebook"]:checkbox').change(function () {
|
||||
if (this.checked) {
|
||||
$('#options_field').show();
|
||||
} else {
|
||||
$('#options_field').hide();
|
||||
$("[name='numeric_calification']").val(0);
|
||||
$("[name='calification_notebook_title']").val('');
|
||||
$("[name='weight_calification']").val(0);
|
||||
$("[name='thread_peer_qualify'][value='0']").prop('checked', true);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
JS;
|
||||
|
||||
// Action links
|
||||
$actions = [
|
||||
Display::url(
|
||||
Display::return_icon('back.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM),
|
||||
'viewforum.php?forum='.$forumId.'&'.$cidreq
|
||||
),
|
||||
search_link(),
|
||||
];
|
||||
|
||||
$threadData = getThreadInfo($threadId, $cId);
|
||||
|
||||
$gradeThisThread = empty($_POST) && ($threadData['threadQualifyMax'] > 0 || $threadData['threadWeight'] > 0);
|
||||
|
||||
$form = new FormValidator(
|
||||
'thread',
|
||||
'post',
|
||||
api_get_self().'?'.http_build_query([
|
||||
'forum' => $forumId,
|
||||
'thread' => $threadId,
|
||||
]).'&'.api_get_cidreq()
|
||||
);
|
||||
|
||||
$form->addElement('header', get_lang('EditThread'));
|
||||
$form->setConstants(['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_session_general_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')
|
||||
);
|
||||
} else {
|
||||
$form->addElement('hidden', 'thread_qualify_gradebook', false);
|
||||
}
|
||||
|
||||
$form->addElement('html', '<div id="options_field" style="'.($gradeThisThread ? '' : '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 = [];
|
||||
$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 (api_is_allowed_to_edit(null, true)) {
|
||||
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
|
||||
}
|
||||
|
||||
$form->addElement('html', '</div>');
|
||||
|
||||
Skill::addSkillsToForm($form, api_get_course_int_id(), api_get_session_id(), ITEM_TYPE_FORUM_THREAD, $threadId);
|
||||
|
||||
if (!empty($threadData)) {
|
||||
$defaults['thread_qualify_gradebook'] = $gradeThisThread;
|
||||
$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->addButtonUpdate(get_lang('ModifyThread'), 'SubmitPost');
|
||||
|
||||
if ($form->validate()) {
|
||||
$redirectUrl = api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq();
|
||||
$check = Security::check_token('post');
|
||||
if ($check) {
|
||||
$values = $form->exportValues();
|
||||
Security::clear_token();
|
||||
updateThread($values);
|
||||
Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $threadId);
|
||||
header('Location: '.$redirectUrl);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$form->setDefaults(isset($defaults) ? $defaults : null);
|
||||
$token = Security::get_token();
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$originIsLearnPath = $origin == 'learnpath';
|
||||
|
||||
$view = new Template(
|
||||
'',
|
||||
!$originIsLearnPath,
|
||||
!$originIsLearnPath,
|
||||
$originIsLearnPath,
|
||||
$originIsLearnPath
|
||||
);
|
||||
$view->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', $actions)
|
||||
);
|
||||
$view->assign('content', $form->returnForm());
|
||||
$view->display_one_col_template();
|
||||
7068
main/forum/forumfunction.inc.php
Normal file
7068
main/forum/forumfunction.inc.php
Normal file
File diff suppressed because it is too large
Load Diff
342
main/forum/forumqualify.php
Normal file
342
main/forum/forumqualify.php
Normal file
@@ -0,0 +1,342 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @todo fix all this qualify files avoid including files, use classes POO jmontoya
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
api_protect_course_script(true);
|
||||
|
||||
$nameTools = get_lang('ToolForum');
|
||||
$this_section = SECTION_COURSES;
|
||||
$message = '';
|
||||
//are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
|
||||
$currentUserId = api_get_user_id();
|
||||
$userIdToQualify = isset($_GET['user_id']) ? intval($_GET['user_id']) : null;
|
||||
$forumId = isset($_GET['forum']) ? intval($_GET['forum']) : 0;
|
||||
api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
|
||||
$nameTools = get_lang('ToolForum');
|
||||
|
||||
$allowed_to_edit = api_is_allowed_to_edit(null, true);
|
||||
$currentThread = get_thread_information($forumId, $_GET['thread']);
|
||||
$forumId = $currentThread['forum_id'];
|
||||
$currentForum = get_forums($currentThread['forum_id']);
|
||||
$threadId = $currentThread['thread_id'];
|
||||
|
||||
$allowToQualify = false;
|
||||
if ($allowed_to_edit) {
|
||||
$allowToQualify = true;
|
||||
} else {
|
||||
$allowToQualify = $currentThread['thread_peer_qualify'] == 1 && $currentForum['visibility'] == 1 && $userIdToQualify != $currentUserId;
|
||||
}
|
||||
|
||||
if (!$allowToQualify) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Show max qualify in my form
|
||||
$maxQualify = showQualify('2', $userIdToQualify, $threadId);
|
||||
$score = 0;
|
||||
|
||||
if (isset($_POST['idtextqualify'])) {
|
||||
$score = floatval($_POST['idtextqualify']);
|
||||
|
||||
if ($score <= $maxQualify) {
|
||||
saveThreadScore(
|
||||
$currentThread,
|
||||
$userIdToQualify,
|
||||
$threadId,
|
||||
$score,
|
||||
api_get_utc_datetime(),
|
||||
api_get_session_id()
|
||||
);
|
||||
|
||||
header(
|
||||
'Location: '.api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&'
|
||||
.http_build_query([
|
||||
'forum' => $forumId,
|
||||
'action' => 'liststd',
|
||||
'content' => 'thread',
|
||||
'id' => $threadId,
|
||||
'list' => 'qualify',
|
||||
])
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('QualificationCanNotBeGreaterThanMaxScore'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
/* Including necessary files */
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
$(\'.hide-me\').slideUp()
|
||||
});
|
||||
|
||||
function hidecontent(content){
|
||||
$(content).slideToggle(\'normal\');
|
||||
}
|
||||
</script>';
|
||||
|
||||
$currentForumCategory = get_forumcategory_information(
|
||||
$currentForum['forum_category']
|
||||
);
|
||||
$groupId = api_get_group_id();
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
$search = isset($_GET['search']) ? Security::remove_XSS(urlencode($_GET['search'])) : '';
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
Display::display_reduced_header();
|
||||
} else {
|
||||
if (!empty($groupId)) {
|
||||
$group_properties = GroupManager::get_group_properties($groupId);
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "../group/group.php?".api_get_cidreq(),
|
||||
"name" => get_lang('Groups'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "../group/group_space.php?".api_get_cidreq(),
|
||||
"name" => get_lang('GroupSpace').' ('.$group_properties['name'].')',
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "viewforum.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&search=".$search,
|
||||
"name" => prepare4display($currentForum['forum_title']),
|
||||
];
|
||||
if ($message != 'PostDeletedSpecial') {
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "viewthread.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&thread=".intval($_GET['thread']),
|
||||
"name" => prepare4display($currentThread['thread_title']),
|
||||
];
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "#",
|
||||
"name" => get_lang('QualifyThread'),
|
||||
];
|
||||
|
||||
// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
|
||||
Display::display_header('');
|
||||
api_display_tool_title($nameTools);
|
||||
} else {
|
||||
$info_thread = get_thread_information($currentForum['forum_id'], $_GET['thread']);
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "index.php?".api_get_cidreq()."&search=".$search,
|
||||
"name" => $nameTools,
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "viewforumcategory.php?".api_get_cidreq()."&forumcategory=".$currentForumCategory['cat_id']."&search=".$search,
|
||||
"name" => prepare4display($currentForumCategory['cat_title']),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "viewforum.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&search=".$search,
|
||||
"name" => prepare4display($currentForum['forum_title']),
|
||||
];
|
||||
|
||||
if ($message != 'PostDeletedSpecial') {
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "viewthread.php?".api_get_cidreq()."&forum=".$info_thread['forum_id']."&thread=".intval($_GET['thread']),
|
||||
"name" => prepare4display($currentThread['thread_title']),
|
||||
];
|
||||
}
|
||||
// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "#",
|
||||
"name" => get_lang('QualifyThread'),
|
||||
];
|
||||
Display::display_header('');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Actions
|
||||
*/
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : '';
|
||||
|
||||
if ($action == 'delete' &&
|
||||
isset($_GET['content']) &&
|
||||
isset($_GET['id']) && api_is_allowed_to_edit(false, true)
|
||||
) {
|
||||
$message = delete_post($_GET['id']);
|
||||
}
|
||||
if (($action == 'invisible' || $action == 'visible') &&
|
||||
isset($_GET['id']) && api_is_allowed_to_edit(false, true)
|
||||
) {
|
||||
$message = approve_post($_GET['id'], $action);
|
||||
}
|
||||
if ($action == 'move' && isset($_GET['post'])) {
|
||||
$message = move_post_form();
|
||||
}
|
||||
|
||||
/*
|
||||
Display the action messages
|
||||
*/
|
||||
if (!empty($message)) {
|
||||
echo Display::return_message(get_lang($message), 'confirm');
|
||||
}
|
||||
|
||||
// show qualifications history
|
||||
$type = isset($_GET['type']) ? $_GET['type'] : '';
|
||||
$historyList = getThreadScoreHistory(
|
||||
$userIdToQualify,
|
||||
$threadId,
|
||||
$type
|
||||
);
|
||||
|
||||
$counter = count($historyList);
|
||||
|
||||
// Show current qualify in my form
|
||||
$qualify = current_qualify_of_thread(
|
||||
$threadId,
|
||||
api_get_session_id(),
|
||||
$_GET['user']
|
||||
);
|
||||
|
||||
$result = get_statistical_information(
|
||||
$threadId,
|
||||
$_GET['user_id'],
|
||||
api_get_course_int_id()
|
||||
);
|
||||
|
||||
$url = api_get_path(WEB_CODE_PATH).'forum/forumqualify.php?'.
|
||||
api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.$threadId.'&user='.intval($_GET['user']).'&user_id='.intval($_GET['user']);
|
||||
|
||||
$userToQualifyInfo = api_get_user_info($userIdToQualify);
|
||||
$form = new FormValidator('forum-thread-qualify', 'post', $url);
|
||||
$form->addHeader($userToQualifyInfo['complete_name']);
|
||||
$form->addLabel(get_lang('Thread'), $currentThread['thread_title']);
|
||||
$form->addLabel(get_lang('CourseUsers'), $result['user_course']);
|
||||
$form->addLabel(get_lang('PostsNumber'), $result['post']);
|
||||
$form->addLabel(get_lang('NumberOfPostsForThisUser'), $result['user_post']);
|
||||
$form->addLabel(
|
||||
get_lang('AveragePostPerUser'),
|
||||
round($result['user_post'] / $result['post'], 2)
|
||||
);
|
||||
$form->addText(
|
||||
'idtextqualify',
|
||||
[get_lang('Qualification'), get_lang('MaxScore').' '.$maxQualify],
|
||||
$qualify
|
||||
);
|
||||
|
||||
$course = api_get_course_info();
|
||||
|
||||
$rows = get_thread_user_post($course['code'], $currentThread['thread_id'], $_GET['user']);
|
||||
if (isset($rows)) {
|
||||
$counter = 1;
|
||||
foreach ($rows as $row) {
|
||||
if ($row['status'] == '0') {
|
||||
$style = " id = 'post".$post_en."' class=\"hide-me\" style=\"border:1px solid red; display:none; background-color:#F7F7F7; width:95%; margin: 0px 0px 4px 40px; \" ";
|
||||
} else {
|
||||
$style = '';
|
||||
$post_en = $row['post_parent_id'];
|
||||
}
|
||||
|
||||
if ($row['user_id'] == '0') {
|
||||
$name = prepare4display($row['poster_name']);
|
||||
} else {
|
||||
$name = api_get_person_name($row['firstname'], $row['lastname']);
|
||||
}
|
||||
if ($counter == 1) {
|
||||
echo Display::page_subheader($name);
|
||||
}
|
||||
|
||||
echo "<div ".$style."><table class=\"table table-hover table-striped data_table\">";
|
||||
|
||||
if ($row['visible'] == '0') {
|
||||
$titleclass = 'forum_message_post_title_2_be_approved';
|
||||
$messageclass = 'forum_message_post_text_2_be_approved';
|
||||
$leftclass = 'forum_message_left_2_be_approved';
|
||||
} else {
|
||||
$titleclass = 'forum_message_post_title';
|
||||
$messageclass = 'forum_message_post_text';
|
||||
$leftclass = 'forum_message_left';
|
||||
}
|
||||
|
||||
echo "<tr>";
|
||||
echo "<td rowspan=\"3\" class=\"$leftclass\">";
|
||||
echo '<br /><b>'.api_convert_and_format_date($row['post_date'], DATE_TIME_FORMAT_LONG).'</b><br />';
|
||||
echo "</td>";
|
||||
|
||||
// The post title
|
||||
echo "<td class=\"$titleclass\">".prepare4display($row['post_title'])."</td>";
|
||||
echo "</tr>";
|
||||
|
||||
// The post message
|
||||
echo "<tr >";
|
||||
echo "<td class=\"$messageclass\">".prepare4display($row['post_text'])."</td>";
|
||||
echo "</tr>";
|
||||
|
||||
// The check if there is an attachment
|
||||
$attachment_list = get_attachment($row['post_id']);
|
||||
if (!empty($attachment_list)) {
|
||||
echo '<tr ><td height="50%">';
|
||||
$realname = $attachment_list['path'];
|
||||
$user_filename = $attachment_list['filename'];
|
||||
echo Display::return_icon('attachment.gif', get_lang('Attachment'));
|
||||
echo '<a href="download.php?file=';
|
||||
echo $realname;
|
||||
echo ' "> '.$user_filename.' </a>';
|
||||
echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span><br />';
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
echo "</table></div>";
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
$form->addButtonSave(get_lang('QualifyThisThread'));
|
||||
$form->setDefaults(['idtextqualify' => $qualify]);
|
||||
$form->display();
|
||||
|
||||
// Show past data
|
||||
if (api_is_allowed_to_edit() && $counter > 0) {
|
||||
echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
|
||||
if (isset($_GET['type']) && $_GET['type'] === 'false') {
|
||||
$buttons = '<a class="btn btn-default" href="forumqualify.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&origin='.$origin.'&thread='.$threadId.'&user='.intval($_GET['user']).'&user_id='.intval($_GET['user_id']).'&type=true&idtextqualify='.$score.'#history">'.
|
||||
get_lang('MoreRecent').'</a> <a class="btn btn-default disabled" >'.get_lang('Older').'</a>';
|
||||
} else {
|
||||
$buttons = '<a class="btn btn-default">'.get_lang('MoreRecent').'</a>
|
||||
<a class="btn btn-default" href="forumqualify.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&origin='.$origin.'&thread='.$threadId.'&user='.intval($_GET['user']).'&user_id='.intval($_GET['user_id']).'&type=false&idtextqualify='.$score.'#history">'.
|
||||
get_lang('Older').'</a>';
|
||||
}
|
||||
|
||||
$table_list = '<br /><div class="btn-group">'.$buttons.'</div>';
|
||||
$table_list .= '<br /><table class="table">';
|
||||
$table_list .= '<tr>';
|
||||
$table_list .= '<th width="50%">'.get_lang('WhoChanged').'</th>';
|
||||
$table_list .= '<th width="10%">'.get_lang('NoteChanged').'</th>';
|
||||
$table_list .= '<th width="40%">'.get_lang('DateChanged').'</th>';
|
||||
$table_list .= '</tr>';
|
||||
|
||||
for ($i = 0; $i < count($historyList); $i++) {
|
||||
$userInfo = api_get_user_info($historyList[$i]['qualify_user_id']);
|
||||
$table_list .= '<tr><td>'.$userInfo['complete_name'].'</td>';
|
||||
$table_list .= '<td>'.$historyList[$i]['qualify'].'</td>';
|
||||
$table_list .= '<td>'.api_convert_and_format_date(
|
||||
$historyList[$i]['qualify_time'],
|
||||
DATE_TIME_FORMAT_LONG
|
||||
);
|
||||
$table_list .= '</td></tr>';
|
||||
}
|
||||
$table_list .= '</table>';
|
||||
|
||||
echo $table_list;
|
||||
}
|
||||
|
||||
if ($origin != 'learnpath') {
|
||||
Display::display_footer();
|
||||
}
|
||||
93
main/forum/forumsearch.php
Normal file
93
main/forum/forumsearch.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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
|
||||
* are added:
|
||||
* - forum categories and forums can be sorted up or down, locked or made invisible
|
||||
* - consistent and integrated forum administration
|
||||
* - forum options: are students allowed to edit their post?
|
||||
* moderation of posts (approval)
|
||||
* reply only forums (students cannot create new threads)
|
||||
* multiple forums per group
|
||||
* - sticky messages
|
||||
* - new view option: nested view
|
||||
* - quoting a message.
|
||||
*
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
* @copyright Ghent University
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// The section (tabs).
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
// Notification for unauthorized people.
|
||||
api_protect_course_script(true);
|
||||
|
||||
// Including additional library scripts.
|
||||
include 'forumfunction.inc.php';
|
||||
|
||||
// Are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
|
||||
// Name of the tool
|
||||
$nameTools = get_lang('ToolForum');
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
$groupId = api_get_group_id();
|
||||
|
||||
if ($origin == 'group') {
|
||||
$group_properties = GroupManager::get_group_properties($groupId);
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('Groups'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('GroupSpace').' ('.$group_properties['name'].')',
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'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[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/forumsearch.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('ForumSearch'),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(),
|
||||
'name' => $nameTools,
|
||||
];
|
||||
$nameTools = get_lang('ForumSearch');
|
||||
}
|
||||
|
||||
// Display the header.
|
||||
if ('learnpath' == $origin) {
|
||||
Display::display_reduced_header();
|
||||
} else {
|
||||
Display::display_header($nameTools);
|
||||
}
|
||||
|
||||
// Tool introduction
|
||||
Display::display_introduction_section(TOOL_FORUM);
|
||||
|
||||
// Tracking
|
||||
Event::event_access_tool(TOOL_FORUM);
|
||||
|
||||
// Forum search
|
||||
forum_search();
|
||||
|
||||
// Footer
|
||||
if ('learnpath' != $origin) {
|
||||
Display::display_footer();
|
||||
}
|
||||
100
main/forum/iframe_thread.php
Normal file
100
main/forum/iframe_thread.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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
|
||||
* are added:
|
||||
* - forum categories and forums can be sorted up or down, locked or made invisible
|
||||
* - consistent and integrated forum administration
|
||||
* - forum options: are students allowed to edit their post?
|
||||
* moderation of posts (approval)
|
||||
* reply only forums (students cannot create new threads)
|
||||
* multiple forums per group
|
||||
* - sticky messages
|
||||
* - new view option: nested view
|
||||
* - quoting a message.
|
||||
*
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
* @copyright Ghent University
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// A notice for unauthorized people.
|
||||
api_protect_course_script(true);
|
||||
|
||||
$nameTools = get_lang('ToolForum');
|
||||
Display::display_reduced_header();
|
||||
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
/* 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['forum'],
|
||||
$_GET['thread']
|
||||
); // 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(
|
||||
$current_forum['forum_category']
|
||||
);
|
||||
|
||||
/* Is the user allowed here? */
|
||||
|
||||
// if the user is not a course administrator and the forum is hidden
|
||||
// then the user is not allowed here.
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
($current_forum['visibility'] == 0 || $current_thread['visibility'] == 0)
|
||||
) {
|
||||
api_not_allowed(false);
|
||||
}
|
||||
|
||||
$course_id = api_get_course_int_id();
|
||||
|
||||
$table_posts = Database::get_course_table(TABLE_FORUM_POST);
|
||||
$table_users = Database::get_main_table(TABLE_MAIN_USER);
|
||||
|
||||
/* Display Forum Category and the Forum 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.
|
||||
$sql = "SELECT * FROM $table_posts posts
|
||||
INNER JOIN $table_users users
|
||||
ON (posts.poster_id = users.user_id)
|
||||
WHERE
|
||||
posts.c_id = $course_id AND
|
||||
posts.thread_id='".$current_thread['thread_id']."'
|
||||
ORDER BY posts.post_id ASC";
|
||||
$result = Database::query($sql);
|
||||
|
||||
echo "<table width=\"100%\" height=\"100%\" cellspacing=\"5\" border=\"0\">";
|
||||
while ($row = Database::fetch_array($result)) {
|
||||
echo "<tr>";
|
||||
echo "<td rowspan=\"2\" class=\"forum_message_left\">";
|
||||
$username = api_htmlentities(sprintf(get_lang('LoginX'), $row['username']), ENT_QUOTES);
|
||||
if ($row['user_id'] == '0') {
|
||||
$name = $row['poster_name'];
|
||||
} else {
|
||||
$name = api_get_person_name($row['firstname'], $row['lastname']);
|
||||
}
|
||||
echo Display::tag('span', $name, ['title' => $username]).'<br />';
|
||||
echo api_convert_and_format_date($row['post_date']).'<br /><br />';
|
||||
|
||||
echo "</td>";
|
||||
echo "<td class=\"forum_message_post_title\">".Security::remove_XSS($row['post_title'])."</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr>";
|
||||
echo "<td class=\"forum_message_post_text\">".Security::remove_XSS($row['post_text'], STUDENT)."</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
592
main/forum/index.php
Normal file
592
main/forum/index.php
Normal file
@@ -0,0 +1,592 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CourseBundle\Entity\CForumPost;
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* are added:
|
||||
* - forum categories and forums can be sorted up or down, locked or made invisible
|
||||
* - consistent and integrated forum administration
|
||||
* - forum options: are students allowed to edit their post?
|
||||
* moderation of posts (approval)
|
||||
* reply only forums (students cannot create new threads)
|
||||
* multiple forums per group
|
||||
* - sticky messages
|
||||
* - new view option: nested view
|
||||
* - quoting a message.
|
||||
*
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
* @copyright Ghent University
|
||||
* @copyright Patrick Cool
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$current_course_tool = TOOL_FORUM;
|
||||
api_protect_course_script(true);
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
$(\'.hide-me\').slideUp();
|
||||
});
|
||||
|
||||
function hidecontent(content){
|
||||
$(content).slideToggle(\'normal\');
|
||||
}
|
||||
</script>';
|
||||
|
||||
// The section (tabs).
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
$nameTools = get_lang('Forums');
|
||||
$_course = api_get_course_info();
|
||||
$sessionId = api_get_session_id();
|
||||
$_user = api_get_user_info();
|
||||
|
||||
$hideNotifications = api_get_course_setting('hide_forum_notifications') == 1;
|
||||
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
$search_forum = isset($_GET['search']) ? Security::remove_XSS($_GET['search']) : '';
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : '';
|
||||
|
||||
if ('add' === $action) {
|
||||
switch ($_GET['content']) {
|
||||
case 'forum':
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php?search='.$search_forum.'&'.api_get_cidreq(),
|
||||
'name' => get_lang('Forum'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => get_lang('AddForum'),
|
||||
];
|
||||
break;
|
||||
case 'forumcategory':
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php?search='.$search_forum.'&'.api_get_cidreq(),
|
||||
'name' => get_lang('Forum'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => get_lang('AddForumCategory'),
|
||||
];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => get_lang('ForumCategories'),
|
||||
];
|
||||
}
|
||||
|
||||
// Tool introduction
|
||||
$introduction = Display::return_introduction_section(TOOL_FORUM);
|
||||
$form_count = 0;
|
||||
$formContent = '';
|
||||
if (api_is_allowed_to_edit(false, true)) {
|
||||
//if is called from a learning path lp_id
|
||||
$lp_id = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : null;
|
||||
$formContent = handle_forum_and_forumcategories($lp_id);
|
||||
}
|
||||
|
||||
// Notification
|
||||
if ($action == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
|
||||
if (api_get_session_id() != 0 &&
|
||||
api_is_allowed_to_session_edit(false, true) == false
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$return_message = set_notification($_GET['content'], $_GET['id']);
|
||||
Display::addFlash(Display::return_message($return_message, 'confirm', false));
|
||||
}
|
||||
|
||||
get_whats_new();
|
||||
$whatsnew_post_info = Session::read('whatsnew_post_info');
|
||||
|
||||
Event::event_access_tool(TOOL_FORUM);
|
||||
|
||||
$logInfo = [
|
||||
'tool' => TOOL_FORUM,
|
||||
'action' => !empty($action) ? $action : 'list-category',
|
||||
'action_details' => isset($_GET['content']) ? $_GET['content'] : '',
|
||||
];
|
||||
Event::registerLog($logInfo);
|
||||
|
||||
/*
|
||||
RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
|
||||
note: we do this here just after het handling of the actions to be
|
||||
sure that we already incorporate the latest changes
|
||||
*/
|
||||
|
||||
// Step 1: We store all the forum categories in an array $forum_categories.
|
||||
$forumCategories = get_forum_categories();
|
||||
|
||||
// Step 2: We find all the forums (only the visible ones if it is a student).
|
||||
// display group forum in general forum tool depending to configuration option
|
||||
$setting = api_get_setting('display_groups_forum_in_general_tool');
|
||||
|
||||
$allCourseForums = get_forums('', '', $setting === 'true');
|
||||
$user_id = api_get_user_id();
|
||||
|
||||
/* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
|
||||
|
||||
// The groups of the user.
|
||||
$groups_of_user = GroupManager::get_group_ids($_course['real_id'], $user_id);
|
||||
|
||||
// All groups in the course (and sorting them as the
|
||||
// id of the group = the key of the array).
|
||||
if (!api_is_anonymous()) {
|
||||
$all_groups = GroupManager::get_group_list();
|
||||
if (is_array($all_groups)) {
|
||||
foreach ($all_groups as $group) {
|
||||
$all_groups[$group['id']] = $group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ACTION LINKS */
|
||||
$actionLeft = null;
|
||||
//if is called from learning path
|
||||
if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])) {
|
||||
$url = '../lp/lp_controller.php?'.api_get_cidreq()
|
||||
."&gradebook=&action=add_item&type=step&lp_id='.$lp_id.'#resource_tab-5";
|
||||
$actionLeft .= Display::url(
|
||||
Display::return_icon(
|
||||
'back.png',
|
||||
get_lang("BackTo").' '.get_lang("LearningPaths"),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
if (api_is_allowed_to_edit(false, true)) {
|
||||
if (is_array($forumCategories) && !empty($forumCategories)) {
|
||||
$actionLeft .= Display::url(
|
||||
Display::return_icon(
|
||||
'new_forum.png',
|
||||
get_lang('AddForum'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_self().'?'.api_get_cidreq().'&action=add&content=forum&lp_id='.$lp_id
|
||||
);
|
||||
}
|
||||
|
||||
$actionLeft .= Display::url(
|
||||
Display::return_icon(
|
||||
'new_folder.png',
|
||||
get_lang('AddForumCategory'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_self().'?'.api_get_cidreq().'&action=add&content=forumcategory&lp_id='.$lp_id
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($allCourseForums)) {
|
||||
$actionLeft .= search_link();
|
||||
}
|
||||
|
||||
$actions = Display::toolbarAction('toolbar-forum', [$actionLeft]);
|
||||
|
||||
$languages = api_get_language_list_for_flag();
|
||||
$defaultUserLanguage = ucfirst(api_get_interface_language());
|
||||
if (isset($_user['language']) && !empty($_user['language'])) {
|
||||
$defaultUserLanguage = ucfirst($_user['language']);
|
||||
}
|
||||
$extraFieldValues = new ExtraFieldValue('user');
|
||||
$value = $extraFieldValues->get_values_by_handler_and_field_variable(api_get_user_id(), 'langue_cible');
|
||||
|
||||
if ($value && isset($value['value']) && !empty($value['value'])) {
|
||||
$defaultUserLanguage = ucfirst($value['value']);
|
||||
}
|
||||
|
||||
// Create a search-box
|
||||
$searchFilter = '';
|
||||
$translate = api_get_configuration_value('allow_forum_category_language_filter');
|
||||
if ($translate) {
|
||||
$form = new FormValidator('search_simple', 'get', api_get_self().'?'.api_get_cidreq(), null, null, 'inline');
|
||||
$form->addHidden('cidReq', api_get_course_id());
|
||||
$form->addHidden('id_session', api_get_session_id());
|
||||
|
||||
$extraField = new ExtraField('forum_category');
|
||||
$returnParams = $extraField->addElements(
|
||||
$form,
|
||||
null,
|
||||
[], //exclude
|
||||
false, // filter
|
||||
false, // tag as select
|
||||
['language'], //show only fields
|
||||
[], // order fields
|
||||
[], // extra data
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
[],
|
||||
true //$addEmptyOptionSelects = false,
|
||||
);
|
||||
$form->setDefaults(['extra_language' => $defaultUserLanguage]);
|
||||
|
||||
$searchFilter = $form->returnForm();
|
||||
}
|
||||
|
||||
// Fixes error if there forums with no category.
|
||||
$forumsInNoCategory = get_forums_in_category(0);
|
||||
if (!empty($forumsInNoCategory)) {
|
||||
$forumCategories = array_merge(
|
||||
$forumCategories,
|
||||
[
|
||||
[
|
||||
'cat_id' => 0,
|
||||
'session_id' => 0,
|
||||
'visibility' => 1,
|
||||
'cat_comment' => null,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/* Display Forum Categories and the Forums in it */
|
||||
// Step 3: We display the forum_categories first.
|
||||
$listForumCategory = [];
|
||||
$forumCategoryInfo = [];
|
||||
if (is_array($forumCategories)) {
|
||||
foreach ($forumCategories as $forumCategory) {
|
||||
$forumCategoryInfo['id'] = $forumCategory['cat_id'];
|
||||
if (empty($forumCategory['cat_title'])) {
|
||||
$forumCategoryInfo['title'] = get_lang('WithoutCategory');
|
||||
} else {
|
||||
$forumCategoryInfo['title'] = Security::remove_XSS($forumCategory['cat_title']);
|
||||
}
|
||||
$forumCategoryInfo['extra_fields'] = isset($forumCategory['extra_fields']) ? $forumCategory['extra_fields'] : [];
|
||||
$forumCategoryInfo['icon_session'] = api_get_session_image($forumCategory['session_id'], $_user['status']);
|
||||
|
||||
// Validation when belongs to a session
|
||||
$forumCategoryInfo['description'] = Security::remove_XSS($forumCategory['cat_comment']);
|
||||
$forumCategory['session_display'] = null;
|
||||
if (empty($sessionId) && !empty($forumCategory['session_name'])) {
|
||||
$forumCategory['session_display'] = ' ('.Security::remove_XSS($forumCategory['session_name']).')';
|
||||
}
|
||||
|
||||
$tools = null;
|
||||
$idCategory = (int) $forumCategory['cat_id'];
|
||||
$forumCategoryInfo['url'] = 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$idCategory;
|
||||
|
||||
if (!empty($idCategory)) {
|
||||
if (api_is_allowed_to_edit(false, true) &&
|
||||
!($forumCategory['session_id'] == 0 && $sessionId != 0)
|
||||
) {
|
||||
$tools .= '<a href="'.api_get_self().'?'.api_get_cidreq()
|
||||
.'&action=edit&content=forumcategory&id='.$idCategory
|
||||
.'">'.Display::return_icon(
|
||||
'edit.png',
|
||||
get_lang('Edit'),
|
||||
[],
|
||||
ICON_SIZE_SMALL
|
||||
)
|
||||
.'</a>';
|
||||
|
||||
$tools .= '<a href="'.api_get_self().'?'.api_get_cidreq()
|
||||
.'&action=delete&content=forumcategory&id='.$idCategory
|
||||
."\" onclick=\"javascript:if(!confirm('"
|
||||
.addslashes(api_htmlentities(
|
||||
get_lang('DeleteForumCategory'),
|
||||
ENT_QUOTES
|
||||
))
|
||||
."')) return false;\">"
|
||||
.Display::return_icon(
|
||||
'delete.png',
|
||||
get_lang('Delete'),
|
||||
[],
|
||||
ICON_SIZE_SMALL
|
||||
)
|
||||
.'</a>';
|
||||
$tools .= return_visible_invisible_icon(
|
||||
'forumcategory',
|
||||
$idCategory,
|
||||
$forumCategory['visibility']
|
||||
);
|
||||
$tools .= return_lock_unlock_icon(
|
||||
'forumcategory',
|
||||
$idCategory,
|
||||
$forumCategory['locked']
|
||||
);
|
||||
$tools .= return_up_down_icon(
|
||||
'forumcategory',
|
||||
$idCategory,
|
||||
$forumCategories
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$forumCategoryInfo['tools'] = $tools;
|
||||
$forumCategoryInfo['forums'] = [];
|
||||
// The forums in this category.
|
||||
$forumsInCategory = get_forums_in_category($forumCategory['cat_id']);
|
||||
|
||||
if (!empty($forumsInCategory)) {
|
||||
$forumsDetailsList = [];
|
||||
// We display all the forums in this category.
|
||||
foreach ($allCourseForums as $forum) {
|
||||
// Here we clean the whatnew_post_info array a little bit because to display the icon we
|
||||
// test if $whatsnew_post_info[$forum['forum_id']] is empty or not.
|
||||
if (isset($forum['forum_id'])) {
|
||||
if (!empty($whatsnew_post_info)) {
|
||||
if (isset($whatsnew_post_info[$forum['forum_id']]) &&
|
||||
is_array($whatsnew_post_info[$forum['forum_id']])
|
||||
) {
|
||||
foreach ($whatsnew_post_info[$forum['forum_id']] as $key_thread_id => $new_post_array) {
|
||||
if (empty($whatsnew_post_info[$forum['forum_id']][$key_thread_id])) {
|
||||
unset($whatsnew_post_info[$forum['forum_id']][$key_thread_id]);
|
||||
unset($_SESSION['whatsnew_post_info'][$forum['forum_id']][$key_thread_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note: This can be speed up if we transform the $allCourseForums
|
||||
// to an array that uses the forum_category as the key.
|
||||
if (isset($forum['forum_category']) && $forum['forum_category'] == $forumCategory['cat_id']) {
|
||||
$show_forum = false;
|
||||
// SHOULD WE SHOW THIS PARTICULAR FORUM
|
||||
// you are teacher => show forum
|
||||
if (api_is_allowed_to_edit(false, true)) {
|
||||
$show_forum = true;
|
||||
} else {
|
||||
// you are not a teacher
|
||||
// it is not a group forum => show forum
|
||||
// (invisible forums are already left out see get_forums function)
|
||||
if ($forum['forum_of_group'] == '0') {
|
||||
$show_forum = true;
|
||||
} else {
|
||||
$show_forum = GroupManager::user_has_access(
|
||||
$user_id,
|
||||
$forum['forum_of_group'],
|
||||
GroupManager::GROUP_TOOL_FORUM
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($show_forum) {
|
||||
$forumInfo = [];
|
||||
$form_count++;
|
||||
$mywhatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']])
|
||||
? $whatsnew_post_info[$forum['forum_id']]
|
||||
: null;
|
||||
$forumInfo['id'] = $forum['forum_id'];
|
||||
$forumInfo['forum_of_group'] = $forum['forum_of_group'];
|
||||
$forumInfo['title'] = $forum['forum_title'];
|
||||
$forumInfo['forum_image'] = null;
|
||||
// Showing the image
|
||||
if (!empty($forum['forum_image'])) {
|
||||
$image_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'
|
||||
.$forum['forum_image'];
|
||||
$image_size = api_getimagesize($image_path);
|
||||
$img_attributes = '';
|
||||
if (!empty($image_size)) {
|
||||
$forumInfo['forum_image'] = $image_path;
|
||||
}
|
||||
}
|
||||
// Validation when belongs to a session
|
||||
$forumInfo['icon_session'] = api_get_session_image(
|
||||
$forum['session_id'],
|
||||
$_user['status']
|
||||
);
|
||||
if ($forum['forum_of_group'] != '0') {
|
||||
$my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name'])
|
||||
? $all_groups[$forum['forum_of_group']]['name']
|
||||
: null;
|
||||
$my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id'])
|
||||
? $all_groups[$forum['forum_of_group']]['id']
|
||||
: null;
|
||||
$group_title = api_substr($my_all_groups_forum_name, 0, 30);
|
||||
$forumInfo['forum_group_title'] = $group_title;
|
||||
}
|
||||
|
||||
$forum['forum_of_group'] == 0 ? $groupid = '' : $groupid = $forum['forum_of_group'];
|
||||
$forumInfo['visibility'] = $forum['visibility'];
|
||||
$forumInfo['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;
|
||||
|
||||
$linkForum = api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq()
|
||||
.'&gidReq='.$groupid.'&forum='.$forum['forum_id'];
|
||||
$forumInfo['url'] = $linkForum;
|
||||
|
||||
if (!empty($forum['start_time']) && !empty($forum['end_time'])) {
|
||||
$res = api_is_date_in_date_range($forum['start_time'], $forum['end_time']);
|
||||
if (!$res) {
|
||||
$linkForum = $forum['forum_title'];
|
||||
}
|
||||
}
|
||||
|
||||
$forumInfo['description'] = Security::remove_XSS($forum['forum_comment']);
|
||||
|
||||
if ($forum['moderated'] == 1 && api_is_allowed_to_edit(false, true)) {
|
||||
$waitingCount = getCountPostsWithStatus(
|
||||
CForumPost::STATUS_WAITING_MODERATION,
|
||||
$forum
|
||||
);
|
||||
if (!empty($waitingCount)) {
|
||||
$forumInfo['moderation'] = $waitingCount;
|
||||
}
|
||||
}
|
||||
|
||||
$toolActions = null;
|
||||
$forumInfo['alert'] = null;
|
||||
// The number of topics and posts.
|
||||
if (false == $hideNotifications) {
|
||||
// The number of topics and posts.
|
||||
if ($forum['forum_of_group'] !== '0') {
|
||||
if (is_array($mywhatsnew_post_info) && !empty($mywhatsnew_post_info)) {
|
||||
$forumInfo['alert'] = ' '.
|
||||
Display::return_icon(
|
||||
'alert.png',
|
||||
get_lang('Forum'),
|
||||
null,
|
||||
ICON_SIZE_SMALL
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (is_array($mywhatsnew_post_info) && !empty($mywhatsnew_post_info)) {
|
||||
$forumInfo['alert'] = ' '.Display::return_icon(
|
||||
'alert.png',
|
||||
get_lang('Forum'),
|
||||
null,
|
||||
ICON_SIZE_SMALL
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$poster_id = null;
|
||||
// The last post in the forum.
|
||||
if (isset($forum['last_poster_name']) && $forum['last_poster_name'] != '') {
|
||||
$name = $forum['last_poster_name'];
|
||||
$poster_id = 0;
|
||||
$username = "";
|
||||
} else {
|
||||
if (isset($forum['last_poster_firstname'])) {
|
||||
$name = api_get_person_name(
|
||||
$forum['last_poster_firstname'],
|
||||
$forum['last_poster_lastname']
|
||||
);
|
||||
$poster_id = $forum['last_poster_id'];
|
||||
$userinfo = api_get_user_info($poster_id);
|
||||
$username = sprintf(
|
||||
get_lang('LoginX'),
|
||||
$userinfo['username']
|
||||
);
|
||||
}
|
||||
}
|
||||
$forumInfo['last_poster_id'] = $poster_id;
|
||||
if (!empty($forum['last_poster_id'])) {
|
||||
$forumInfo['last_poster_date'] = api_convert_and_format_date($forum['last_post_date']);
|
||||
$forumInfo['last_poster_user'] = display_user_link($poster_id, $name, null, $username);
|
||||
$forumInfo['last_post_title'] = Security::remove_XSS(cut($forum['last_post_title'], 140));
|
||||
$forumInfo['last_post_text'] = Security::remove_XSS(cut($forum['last_post_text'], 140));
|
||||
}
|
||||
|
||||
if (api_is_allowed_to_edit(false, true)
|
||||
&& !($forum['session_id'] == 0 && $sessionId != 0)
|
||||
) {
|
||||
$toolActions .= '<a href="'.api_get_self().'?'.api_get_cidreq()
|
||||
.'&action=edit&content=forum&id='.$forum['forum_id'].'">'
|
||||
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL)
|
||||
.'</a>';
|
||||
$toolActions .= '<a href="'.api_get_self().'?'.api_get_cidreq()
|
||||
.'&action=delete&content=forum&id='.$forum['forum_id']
|
||||
."\" onclick=\"javascript:if(!confirm('".addslashes(
|
||||
api_htmlentities(get_lang('DeleteForum'), ENT_QUOTES)
|
||||
)
|
||||
."')) return false;\">"
|
||||
.Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL)
|
||||
.'</a>';
|
||||
|
||||
$toolActions .= return_visible_invisible_icon(
|
||||
'forum',
|
||||
$forum['forum_id'],
|
||||
$forum['visibility']
|
||||
);
|
||||
|
||||
$toolActions .= return_lock_unlock_icon(
|
||||
'forum',
|
||||
$forum['forum_id'],
|
||||
$forum['locked']
|
||||
);
|
||||
|
||||
$toolActions .= return_up_down_icon(
|
||||
'forum',
|
||||
$forum['forum_id'],
|
||||
$forumsInCategory
|
||||
);
|
||||
}
|
||||
|
||||
$iconnotify = 'notification_mail_na.png';
|
||||
$notifyAltText = get_lang('NotifyMe');
|
||||
$session_forum_notification = isset($_SESSION['forum_notification']['forum'])
|
||||
? $_SESSION['forum_notification']['forum']
|
||||
: false;
|
||||
|
||||
if (is_array($session_forum_notification)) {
|
||||
if (in_array($forum['forum_id'], $session_forum_notification)) {
|
||||
$iconnotify = 'notification_mail.png';
|
||||
$notifyAltText = get_lang('CancelNotifyMe');
|
||||
}
|
||||
}
|
||||
|
||||
if ($hideNotifications == false && !api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
|
||||
$toolActions .= '<a href="'.api_get_self().'?'.api_get_cidreq()
|
||||
.'&action=notify&content=forum&id='.$forum['forum_id'].'">'
|
||||
.Display::return_icon($iconnotify, $notifyAltText, null, ICON_SIZE_SMALL)
|
||||
.'</a>';
|
||||
}
|
||||
$forumInfo['tools'] = $toolActions;
|
||||
$forumsDetailsList[] = $forumInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
$forumCategoryInfo['forums'] = $forumsDetailsList;
|
||||
}
|
||||
|
||||
// Don't show empty categories (for students)
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
if (empty($forumCategoryInfo['forums'])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$listForumCategory[] = $forumCategoryInfo;
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = new Template($nameTools);
|
||||
$tpl->assign('introduction', $introduction);
|
||||
$tpl->assign('actions', $actions);
|
||||
$tpl->assign('data', $listForumCategory);
|
||||
$tpl->assign('form_content', $formContent);
|
||||
$tpl->assign('search_filter', $searchFilter);
|
||||
$tpl->assign('default_user_language', $defaultUserLanguage);
|
||||
$tpl->assign('languages', $languages);
|
||||
$extraFieldValue = new ExtraFieldValue('course');
|
||||
$value = $extraFieldValue->get_values_by_handler_and_field_variable(api_get_course_int_id(), 'global_forum');
|
||||
if ($value && isset($value['value']) && 1 == $value['value']) {
|
||||
$layout = $tpl->get_template('forum/global_list.tpl');
|
||||
} else {
|
||||
$layout = $tpl->get_template('forum/list.tpl');
|
||||
}
|
||||
$tpl->display($layout);
|
||||
186
main/forum/newthread.php
Normal file
186
main/forum/newthread.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?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
|
||||
* are added:
|
||||
* - forum categories and forums can be sorted up or down, locked or made invisible
|
||||
* - consistent and integrated forum administration
|
||||
* - forum options: are students allowed to edit their post?
|
||||
* moderation of posts (approval)
|
||||
* reply only forums (students cannot create new threads)
|
||||
* multiple forums per group
|
||||
* - sticky messages
|
||||
* - new view option: nested view
|
||||
* - quoting a message.
|
||||
*
|
||||
* @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
* @Copyright Ghent University
|
||||
* @Copyright Patrick Cool
|
||||
*
|
||||
* @package chamilo.forum
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// The section (tabs).
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
// Notification for unauthorized people.
|
||||
api_protect_course_script(true);
|
||||
|
||||
$cidreq = api_get_cidreq();
|
||||
$_user = api_get_user_info();
|
||||
|
||||
$nameTools = get_lang('ToolForum');
|
||||
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
// Are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
/* MAIN DISPLAY SECTION */
|
||||
$current_forum = get_forum_information($_GET['forum']);
|
||||
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
|
||||
|
||||
$logInfo = [
|
||||
'tool' => TOOL_FORUM,
|
||||
'tool_id' => (int) $_GET['forum'],
|
||||
'tool_id_detail' => 0,
|
||||
'action' => 'add-thread',
|
||||
'action_details' => '',
|
||||
];
|
||||
Event::registerLog($logInfo);
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
/* Is the user allowed here? */
|
||||
|
||||
// The user is not allowed here if:
|
||||
|
||||
// 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
(($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
// 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
(($current_forum_category['visibility'] && $current_forum_category['locked'] != 0) || $current_forum['locked'] != 0)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
// 3. new threads are not allowed and the user is not a course manager
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
$current_forum['allow_new_threads'] != 1
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
// 4. anonymous posts are not allowed and the user is not logged in
|
||||
if (!$_user['user_id'] && $current_forum['allow_anonymous'] != 1) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
// 5. Check user access
|
||||
if ($current_forum['forum_of_group'] != 0) {
|
||||
$show_forum = GroupManager::user_has_access(
|
||||
api_get_user_id(),
|
||||
$current_forum['forum_of_group'],
|
||||
GroupManager::GROUP_TOOL_FORUM
|
||||
);
|
||||
if (!$show_forum) {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Invited users can't create new threads
|
||||
if (api_is_invitee()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$groupId = api_get_group_id();
|
||||
if (!empty($groupId)) {
|
||||
$groupProperties = GroupManager::get_group_properties($groupId);
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.$cidreq,
|
||||
'name' => get_lang('Groups'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.$cidreq,
|
||||
'name' => get_lang('GroupSpace').' '.$groupProperties['name'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']),
|
||||
'name' => $current_forum['forum_title'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/newthread.php?'.$cidreq.'&forum='.intval($_GET['forum']),
|
||||
'name' => get_lang('NewTopic'),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.$cidreq, 'name' => $nameTools];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.$cidreq.'&forumcategory='.$current_forum_category['cat_id'],
|
||||
'name' => $current_forum_category['cat_title'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']),
|
||||
'name' => $current_forum['forum_title'],
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewTopic')];
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = "
|
||||
<script>
|
||||
$(function() {
|
||||
$('#reply-add-attachment').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var newInputFile = $('<input>', {
|
||||
type: 'file',
|
||||
name: 'user_upload[]'
|
||||
});
|
||||
$('[name=\"user_upload[]\"]').parent().append(newInputFile);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
";
|
||||
|
||||
$form = show_add_post_form(
|
||||
$current_forum,
|
||||
'newthread',
|
||||
isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null
|
||||
);
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
Display::display_reduced_header();
|
||||
} else {
|
||||
Display::display_header();
|
||||
}
|
||||
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>';
|
||||
|
||||
// Set forum attachment data into $_SESSION
|
||||
getAttachedFiles($current_forum['forum_id'], 0, 0);
|
||||
|
||||
if ($form) {
|
||||
$form->display();
|
||||
}
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
Display::display_reduced_footer();
|
||||
} else {
|
||||
Display::display_footer();
|
||||
}
|
||||
209
main/forum/reply.php
Normal file
209
main/forum/reply.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?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
|
||||
* are added:
|
||||
* - forum categories and forums can be sorted up or down, locked or made invisible
|
||||
* - consistent and integrated forum administration
|
||||
* - forum options: are students allowed to edit their post?
|
||||
* moderation of posts (approval)
|
||||
* reply only forums (students cannot create new threads)
|
||||
* multiple forums per group
|
||||
* - sticky messages
|
||||
* - new view option: nested view
|
||||
* - quoting a message.
|
||||
*
|
||||
* @package chamilo.forum
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
api_protect_course_script(true);
|
||||
|
||||
$nameTools = get_lang('ForumCategories');
|
||||
$origin = api_get_origin();
|
||||
$_user = api_get_user_info();
|
||||
|
||||
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 category are stored in the item_property table.
|
||||
// Note: This has to be validated that it is an existing thread.
|
||||
$current_thread = get_thread_information($forumId, $threadId);
|
||||
// Note: This has to be validated that it is an existing forum.
|
||||
$current_forum = get_forum_information($current_thread['forum_id']);
|
||||
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
|
||||
|
||||
/* Is the user allowed here? */
|
||||
// The user is not allowed here if
|
||||
// 1. the forumcategory, forum or thread is invisible (visibility==0
|
||||
// 2. the forumcategory, forum or thread is locked (locked <>0)
|
||||
// 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(false, true) &&
|
||||
(($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
|
||||
) {
|
||||
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(true);
|
||||
}
|
||||
if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if ($current_forum['forum_of_group'] != 0) {
|
||||
$show_forum = GroupManager::user_has_access(
|
||||
api_get_user_id(),
|
||||
$current_forum['forum_of_group'],
|
||||
GroupManager::GROUP_TOOL_FORUM
|
||||
);
|
||||
if (!$show_forum) {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
$groupId = api_get_group_id();
|
||||
if (!empty($groupId)) {
|
||||
$group_properties = GroupManager::get_group_properties($groupId);
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('Groups'),
|
||||
];
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('GroupSpace').' '.$group_properties['name'],
|
||||
];
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
|
||||
'name' => $current_forum['forum_title'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
|
||||
'name' => $current_thread['thread_title'],
|
||||
];
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'javascript: void(0);',
|
||||
'name' => get_lang('Reply'),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php?'.api_get_cidreq(),
|
||||
'name' => $nameTools,
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'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[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
|
||||
'name' => $current_forum['forum_title'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
|
||||
'name' => $current_thread['thread_title'],
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Reply')];
|
||||
}
|
||||
|
||||
/* Header */
|
||||
$htmlHeadXtra[] = <<<JS
|
||||
<script>
|
||||
$(function() {
|
||||
$('#reply-add-attachment').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var newInputFile = $('<input>', {
|
||||
type: 'file',
|
||||
name: 'user_upload[]'
|
||||
});
|
||||
|
||||
$('[name="user_upload[]"]').parent().append(newInputFile);
|
||||
});
|
||||
});
|
||||
</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'] : '';
|
||||
|
||||
$logInfo = [
|
||||
'tool' => TOOL_FORUM,
|
||||
'tool_id' => $forumId,
|
||||
'tool_id_detail' => $threadId,
|
||||
'action' => !empty($my_action) ? $my_action : 'reply',
|
||||
];
|
||||
Event::registerLog($logInfo);
|
||||
|
||||
$form = show_add_post_form(
|
||||
$current_forum,
|
||||
$my_action,
|
||||
$my_elements
|
||||
);
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
Display::display_reduced_header();
|
||||
} else {
|
||||
// The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
|
||||
Display::display_header();
|
||||
}
|
||||
/* Action links */
|
||||
|
||||
if ($origin != 'learnpath') {
|
||||
echo '<div class="actions">';
|
||||
echo '<span style="float:right;">'.search_link().'</span>';
|
||||
echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId.'">';
|
||||
echo Display::return_icon(
|
||||
'back.png',
|
||||
get_lang('BackToThread'),
|
||||
'',
|
||||
ICON_SIZE_MEDIUM
|
||||
).'</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
/*New display forum div*/
|
||||
echo '<div class="forum_title">';
|
||||
echo '<h1>';
|
||||
echo Display::url(
|
||||
prepare4display($current_forum['forum_title']),
|
||||
'viewforum.php?'.api_get_cidreq().'&'.http_build_query(['forum' => $current_forum['forum_id']]),
|
||||
['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
|
||||
);
|
||||
echo '</h1>';
|
||||
echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
|
||||
echo '</div>';
|
||||
if ($form) {
|
||||
$form->display();
|
||||
}
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
Display::display_reduced_footer();
|
||||
} else {
|
||||
Display::display_footer();
|
||||
}
|
||||
678
main/forum/viewforum.php
Normal file
678
main/forum/viewforum.php
Normal file
@@ -0,0 +1,678 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CourseBundle\Entity\CForumPost;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* are added:
|
||||
* - forum categories and forums can be sorted up or down, locked or made invisible
|
||||
* - consistent and integrated forum administration
|
||||
* - forum options: are students allowed to edit their post?
|
||||
* moderation of posts (approval)
|
||||
* reply only forums (students cannot create new threads)
|
||||
* multiple forums per group
|
||||
* - sticky messages
|
||||
* - new view option: nested view
|
||||
* - quoting a message.
|
||||
*
|
||||
* @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
* @Copyright Ghent University
|
||||
* @Copyright Patrick Cool
|
||||
*
|
||||
* @package chamilo.forum
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$current_course_tool = TOOL_FORUM;
|
||||
|
||||
// Notification for unauthorized people.
|
||||
api_protect_course_script(true);
|
||||
api_protect_course_group(GroupManager::GROUP_TOOL_FORUM);
|
||||
|
||||
// The section (tabs).
|
||||
$this_section = SECTION_COURSES;
|
||||
$nameTools = get_lang('ToolForum');
|
||||
|
||||
// Are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
$userId = api_get_user_id();
|
||||
$sessionId = api_get_session_id();
|
||||
$groupId = api_get_group_id();
|
||||
$courseId = api_get_course_int_id();
|
||||
$groupInfo = GroupManager::get_group_properties($groupId);
|
||||
$isTutor = GroupManager::is_tutor_of_group($userId, $groupInfo, $courseId);
|
||||
$isAllowedToEdit = api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true);
|
||||
|
||||
/* MAIN DISPLAY SECTION */
|
||||
|
||||
$my_forum = isset($_GET['forum']) ? (int) $_GET['forum'] : '';
|
||||
// Note: This has to be validated that it is an existing forum.
|
||||
$current_forum = get_forum_information($my_forum);
|
||||
$isForumOpenByDateAccess = api_is_date_in_date_range($current_forum['start_time'], $current_forum['end_time']);
|
||||
|
||||
if (!$isForumOpenByDateAccess && !$isAllowedToEdit) {
|
||||
if ($origin) {
|
||||
api_not_allowed(true);
|
||||
} else {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($current_forum)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
|
||||
$is_group_tutor = false;
|
||||
|
||||
if (!empty($groupId)) {
|
||||
//Group info & group category info
|
||||
$group_properties = GroupManager::get_group_properties($groupId);
|
||||
$is_group_tutor = GroupManager::is_tutor_of_group(
|
||||
api_get_user_id(),
|
||||
$group_properties
|
||||
);
|
||||
|
||||
// Course
|
||||
if (!api_is_allowed_to_edit(false, true) && //is a student
|
||||
(
|
||||
($current_forum_category && $current_forum_category['visibility'] == 0) ||
|
||||
$current_forum['visibility'] == 0
|
||||
)
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
} else {
|
||||
// Course
|
||||
if (!api_is_allowed_to_edit(false, true) && (
|
||||
($current_forum_category && $current_forum_category['visibility'] == 0) ||
|
||||
$current_forum['visibility'] == 0
|
||||
) //forum category or forum visibility is false
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
|
||||
/* Header and Breadcrumbs */
|
||||
$my_search = isset($_GET['search']) ? $_GET['search'] : '';
|
||||
$my_action = isset($_GET['action']) ? $_GET['action'] : '';
|
||||
|
||||
$logInfo = [
|
||||
'tool' => TOOL_FORUM,
|
||||
'tool_id' => $my_forum,
|
||||
'tool_id_detail' => 0,
|
||||
'action' => !empty($my_action) ? $my_action : 'list-threads',
|
||||
'action_details' => isset($_GET['content']) ? $_GET['content'] : '',
|
||||
];
|
||||
Event::registerLog($logInfo);
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
$forumUrl = api_get_path(WEB_CODE_PATH).'forum/';
|
||||
|
||||
if (!empty($groupId)) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('Groups'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('GroupSpace').' '.$group_properties['name'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => get_lang('Forum').' '.Security::remove_XSS($current_forum['forum_title']),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => $forumUrl.'index.php?search='.Security::remove_XSS($my_search),
|
||||
'name' => get_lang('ForumCategories'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => $forumUrl.'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id']
|
||||
.'&search='.Security::remove_XSS(urlencode($my_search)),
|
||||
'name' => Security::remove_XSS(prepare4display($current_forum_category['cat_title'])),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => Security::remove_XSS($current_forum['forum_title']),
|
||||
];
|
||||
}
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
Display::display_reduced_header();
|
||||
} else {
|
||||
// The last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string.
|
||||
Display::display_header();
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
// Change visibility of a forum or a forum category.
|
||||
if (($my_action == 'invisible' || $my_action == 'visible') &&
|
||||
isset($_GET['content']) &&
|
||||
isset($_GET['id']) &&
|
||||
$isAllowedToEdit
|
||||
) {
|
||||
$message = change_visibility($_GET['content'], $_GET['id'], $_GET['action']);
|
||||
}
|
||||
// Locking and unlocking.
|
||||
if (($my_action == 'lock' || $my_action == 'unlock') &&
|
||||
isset($_GET['content']) && isset($_GET['id']) &&
|
||||
$isAllowedToEdit
|
||||
) {
|
||||
$message = change_lock_status($_GET['content'], $_GET['id'], $my_action);
|
||||
}
|
||||
// Deleting.
|
||||
if ($my_action == 'delete' &&
|
||||
isset($_GET['content']) &&
|
||||
isset($_GET['id']) &&
|
||||
$isAllowedToEdit
|
||||
) {
|
||||
$locked = api_resource_is_locked_by_gradebook($_GET['id'], LINK_FORUM_THREAD);
|
||||
if ($locked == false) {
|
||||
$message = deleteForumCategoryThread($_GET['content'], $_GET['id']);
|
||||
|
||||
// Delete link
|
||||
$link_info = GradebookUtils::isResourceInCourseGradebook(
|
||||
api_get_course_id(),
|
||||
5,
|
||||
$_GET['id'],
|
||||
api_get_session_id()
|
||||
);
|
||||
$link_id = $link_info['id'];
|
||||
if ($link_info !== false) {
|
||||
GradebookUtils::remove_resource_from_course_gradebook($link_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Moving.
|
||||
if ($my_action == 'move' && isset($_GET['thread']) &&
|
||||
$isAllowedToEdit
|
||||
) {
|
||||
$message = move_thread_form();
|
||||
}
|
||||
// Notification.
|
||||
if ($my_action == 'notify' &&
|
||||
isset($_GET['content']) &&
|
||||
isset($_GET['id']) &&
|
||||
api_is_allowed_to_session_edit(false, true)
|
||||
) {
|
||||
$return_message = set_notification($_GET['content'], $_GET['id']);
|
||||
echo Display::return_message($return_message, 'confirm', false);
|
||||
}
|
||||
|
||||
// Student list
|
||||
if ($my_action == 'liststd' &&
|
||||
isset($_GET['content']) &&
|
||||
isset($_GET['id']) &&
|
||||
(api_is_allowed_to_edit(null, true) || $is_group_tutor)
|
||||
) {
|
||||
$active = null;
|
||||
$listType = isset($_GET['list']) ? $_GET['list'] : null;
|
||||
|
||||
switch ($listType) {
|
||||
case 'qualify':
|
||||
$student_list = get_thread_users_qualify($_GET['id']);
|
||||
$nrorow3 = -2;
|
||||
$active = 2;
|
||||
break;
|
||||
case 'notqualify':
|
||||
$student_list = get_thread_users_not_qualify($_GET['id']);
|
||||
$nrorow3 = -2;
|
||||
$active = 3;
|
||||
break;
|
||||
default:
|
||||
$student_list = get_thread_users_details($_GET['id']);
|
||||
$nrorow3 = Database::num_rows($student_list);
|
||||
$active = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
$table_list = Display::page_subheader(get_lang('ThreadUsersList').': '.get_name_thread_by_id($_GET['id']));
|
||||
|
||||
if ($nrorow3 > 0 || $nrorow3 == -2) {
|
||||
$url = api_get_cidreq().'&forum='.$my_forum.'&action='
|
||||
.Security::remove_XSS($_GET['action']).'&content='
|
||||
.Security::remove_XSS($_GET['content'], STUDENT).'&id='.intval($_GET['id']);
|
||||
$tabs = [
|
||||
[
|
||||
'content' => get_lang('AllStudents'),
|
||||
'url' => $forumUrl.'viewforum.php?'.$url.'&list=all',
|
||||
],
|
||||
[
|
||||
'content' => get_lang('StudentsQualified'),
|
||||
'url' => $forumUrl.'viewforum.php?'.$url.'&list=qualify',
|
||||
],
|
||||
[
|
||||
'content' => get_lang('StudentsNotQualified'),
|
||||
'url' => $forumUrl.'viewforum.php?'.$url.'&list=notqualify',
|
||||
],
|
||||
];
|
||||
$table_list .= Display::tabsOnlyLink($tabs, $active);
|
||||
|
||||
$icon_qualify = 'quiz.png';
|
||||
$table_list .= '<center><br /><table class="table table-hover table-striped data_table" style="width:50%">';
|
||||
// The column headers (TODO: Make this sortable).
|
||||
$table_list .= '<tr >';
|
||||
$table_list .= '<th height="24">'.get_lang('NamesAndLastNames').'</th>';
|
||||
|
||||
if ($listType == 'qualify') {
|
||||
$table_list .= '<th>'.get_lang('Qualification').'</th>';
|
||||
}
|
||||
if (api_is_allowed_to_edit(null, true)) {
|
||||
$table_list .= '<th>'.get_lang('Qualify').'</th>';
|
||||
}
|
||||
$table_list .= '</tr>';
|
||||
$max_qualify = showQualify('2', $userId, $_GET['id']);
|
||||
$counter_stdlist = 0;
|
||||
|
||||
if (Database::num_rows($student_list) > 0) {
|
||||
while ($row_student_list = Database::fetch_array($student_list)) {
|
||||
$userInfo = api_get_user_info($row_student_list['id']);
|
||||
if ($counter_stdlist % 2 == 0) {
|
||||
$class_stdlist = 'row_odd';
|
||||
} else {
|
||||
$class_stdlist = 'row_even';
|
||||
}
|
||||
$table_list .= '<tr class="'.$class_stdlist.'"><td>';
|
||||
$table_list .= UserManager::getUserProfileLink($userInfo);
|
||||
|
||||
$table_list .= '</td>';
|
||||
if ($listType == 'qualify') {
|
||||
$table_list .= '<td>'.$row_student_list['qualify'].'/'.$max_qualify.'</td>';
|
||||
}
|
||||
if (api_is_allowed_to_edit(null, true)) {
|
||||
$current_qualify_thread = showQualify(
|
||||
'1',
|
||||
$row_student_list['id'],
|
||||
$_GET['id']
|
||||
);
|
||||
$table_list .= '<td>
|
||||
<a href="'.$forumUrl.'forumqualify.php?'.api_get_cidreq()
|
||||
.'&forum='.intval($my_forum).'&thread='
|
||||
.intval($_GET['id']).'&user='.$row_student_list['id']
|
||||
.'&user_id='.$row_student_list['id'].'&idtextqualify='
|
||||
.$current_qualify_thread.'">'
|
||||
.Display::return_icon($icon_qualify, get_lang('Qualify')).'</a></td></tr>';
|
||||
}
|
||||
$counter_stdlist++;
|
||||
}
|
||||
} else {
|
||||
if ($listType === 'qualify') {
|
||||
$table_list .= '<tr><td colspan="2">'.get_lang('ThereIsNotQualifiedLearners').'</td></tr>';
|
||||
} else {
|
||||
$table_list .= '<tr><td colspan="2">'.get_lang('ThereIsNotUnqualifiedLearners').'</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
$table_list .= '</table></center>';
|
||||
$table_list .= '<br />';
|
||||
} else {
|
||||
$table_list .= Display::return_message(get_lang('NoParticipation'), 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
echo '<div style="height:15px"> </div>';
|
||||
}
|
||||
|
||||
/* Display the action messages */
|
||||
if (!empty($message)) {
|
||||
echo Display::return_message($message, 'confirm');
|
||||
}
|
||||
|
||||
/* Action links */
|
||||
echo '<div class="actions">';
|
||||
if ($origin != 'learnpath') {
|
||||
if (!empty($groupId)) {
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq().'">'
|
||||
.Display::return_icon('back.png', get_lang('BackTo')
|
||||
.' '.get_lang('Groups'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
} else {
|
||||
echo '<span style="float:right;">'.search_link().'</span>';
|
||||
echo '<a href="'.$forumUrl.'index.php?'.api_get_cidreq().'">'
|
||||
.Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM)
|
||||
.'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
// The link should appear when
|
||||
// 1. the course admin is here
|
||||
// 2. the course member is here and new threads are allowed
|
||||
// 3. a visitor is here and new threads AND allowed AND anonymous posts are allowed
|
||||
if (api_is_allowed_to_edit(false, true) ||
|
||||
($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 && $current_forum['locked'] != 1) {
|
||||
if (!api_is_anonymous() && !api_is_invitee()) {
|
||||
if ($my_forum == strval(intval($my_forum))) {
|
||||
echo '<a href="'.$forumUrl.'newthread.php?'.api_get_cidreq().'&forum='
|
||||
.Security::remove_XSS($my_forum).'">'
|
||||
.Display::return_icon('new_thread.png', get_lang('NewTopic'), '', ICON_SIZE_MEDIUM)
|
||||
.'</a>';
|
||||
} else {
|
||||
$my_forum = strval(intval($my_forum));
|
||||
echo '<a href="'.$forumUrl.'newthread.php?'.api_get_cidreq()
|
||||
.'&forum='.$my_forum.'">'
|
||||
.Display::return_icon('new_thread.png', get_lang('NewTopic'), '', ICON_SIZE_MEDIUM)
|
||||
.'</a>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo get_lang('ForumLocked');
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
/* Display */
|
||||
$titleForum = Security::remove_XSS($current_forum['forum_title']);
|
||||
$descriptionForum = $current_forum['forum_comment'];
|
||||
$iconForum = Display::return_icon(
|
||||
'forum_yellow.png',
|
||||
get_lang('Forum'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
);
|
||||
$html = '';
|
||||
$html .= '<div class="topic-forum">';
|
||||
// The current forum
|
||||
if ($origin != 'learnpath') {
|
||||
$html .= Display::tag(
|
||||
'h3',
|
||||
$iconForum.' '.$titleForum,
|
||||
[
|
||||
'class' => 'title-forum', ]
|
||||
);
|
||||
|
||||
if (!empty($descriptionForum)) {
|
||||
$html .= Display::tag(
|
||||
'p',
|
||||
Security::remove_XSS($descriptionForum),
|
||||
[
|
||||
'class' => 'description',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
echo $html;
|
||||
|
||||
// Getting al the threads
|
||||
$threads = get_threads($my_forum);
|
||||
$whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
|
||||
$course_id = api_get_course_int_id();
|
||||
|
||||
$hideNotifications = api_get_course_setting('hide_forum_notifications') == 1;
|
||||
|
||||
echo '<div class="forum_display">';
|
||||
if (is_array($threads)) {
|
||||
$html = '';
|
||||
$count = 1;
|
||||
foreach ($threads as $row) {
|
||||
// Thread who have no replies yet and the only post is invisible should not be displayed to students.
|
||||
if (api_is_allowed_to_edit(false, true) ||
|
||||
!($row['thread_replies'] == '0' && $row['visibility'] == '0')
|
||||
) {
|
||||
$my_whatsnew_post_info = null;
|
||||
|
||||
if (isset($whatsnew_post_info[$my_forum][$row['thread_id']])) {
|
||||
$my_whatsnew_post_info = $whatsnew_post_info[$my_forum][$row['thread_id']];
|
||||
}
|
||||
|
||||
$newPost = '';
|
||||
if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
|
||||
$newPost = ' '.Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
|
||||
}
|
||||
|
||||
$name = api_get_person_name($row['firstname'], $row['lastname']);
|
||||
|
||||
$linkPostForum = '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$my_forum
|
||||
."&thread={$row['thread_id']}&search="
|
||||
.Security::remove_XSS(urlencode($my_search)).'">'
|
||||
.Security::remove_XSS($row['thread_title']).'</a>';
|
||||
$html = '';
|
||||
$html .= '<div class="panel panel-default forum '.($row['thread_sticky'] ? 'sticky' : '').'">';
|
||||
$html .= '<div class="panel-body">';
|
||||
$html .= '<div class="row">';
|
||||
$html .= '<div class="col-md-6">';
|
||||
$html .= '<div class="row">';
|
||||
$html .= '<div class="col-md-2">';
|
||||
|
||||
// display the author name
|
||||
$tab_poster_info = api_get_user_info($row['user_id']);
|
||||
$poster_username = sprintf(get_lang('LoginX'), $tab_poster_info['username']);
|
||||
$authorName = '';
|
||||
|
||||
if ($origin != 'learnpath') {
|
||||
$authorName = display_user_link(
|
||||
$row['user_id'],
|
||||
api_get_person_name($row['firstname'], $row['lastname']),
|
||||
'',
|
||||
$poster_username
|
||||
);
|
||||
} else {
|
||||
$authorName = Display::tag(
|
||||
'span',
|
||||
api_get_person_name(
|
||||
$row['firstname'],
|
||||
$row['lastname']
|
||||
),
|
||||
[
|
||||
'title' => api_htmlentities($poster_username, ENT_QUOTES),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$_user = api_get_user_info($row['user_id']);
|
||||
$iconStatus = $_user['icon_status'];
|
||||
$last_post_info = get_last_post_by_thread(
|
||||
$row['c_id'],
|
||||
$row['thread_id'],
|
||||
$row['forum_id'],
|
||||
api_is_allowed_to_edit()
|
||||
);
|
||||
$last_post = null;
|
||||
if ($last_post_info) {
|
||||
$poster_info = api_get_user_info($last_post_info['poster_id']);
|
||||
$post_date = api_convert_and_format_date($last_post_info['post_date']);
|
||||
$last_post = $post_date.'<br>'.get_lang('By').' '.display_user_link(
|
||||
$last_post_info['poster_id'],
|
||||
$poster_info['complete_name'],
|
||||
'',
|
||||
$poster_info['username']
|
||||
);
|
||||
}
|
||||
|
||||
$html .= '<div class="thumbnail">'.display_user_image($row['user_id'], $name, $origin).'</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="col-md-10">';
|
||||
$html .= Display::tag(
|
||||
'h3',
|
||||
$linkPostForum,
|
||||
[
|
||||
'class' => 'title',
|
||||
]
|
||||
);
|
||||
$html .= '<p>'.get_lang('By').' '.$iconStatus.' '.$authorName.'</p>';
|
||||
|
||||
if ($last_post_info) {
|
||||
$html .= '<p>'.Security::remove_XSS(cut($last_post_info['post_text'], 140)).'</p>';
|
||||
}
|
||||
|
||||
$html .= '<p>'.Display::dateToStringAgoAndLongDate($row['insert_date']).'</p>';
|
||||
|
||||
if ($current_forum['moderated'] == 1 && api_is_allowed_to_edit(false, true)) {
|
||||
$waitingCount = getCountPostsWithStatus(
|
||||
CForumPost::STATUS_WAITING_MODERATION,
|
||||
$current_forum,
|
||||
$row['thread_id']
|
||||
);
|
||||
if (!empty($waitingCount)) {
|
||||
$html .= Display::label(
|
||||
get_lang('PostsPendingModeration').': '.$waitingCount,
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div class="col-md-6">';
|
||||
$html .= '<div class="row">';
|
||||
$html .= '<div class="col-md-4">'
|
||||
.Display::return_icon('post-forum.png', null, null, ICON_SIZE_SMALL)
|
||||
." {$row['thread_replies']} ".get_lang('Replies').'<br>';
|
||||
$html .= Display::return_icon(
|
||||
'post-forum.png',
|
||||
null,
|
||||
null,
|
||||
ICON_SIZE_SMALL
|
||||
).' '.$row['thread_views'].' '.get_lang('Views').'<br>'.$newPost;
|
||||
$html .= '</div>';
|
||||
|
||||
$last_post_info = get_last_post_by_thread(
|
||||
$row['c_id'],
|
||||
$row['thread_id'],
|
||||
$row['forum_id'],
|
||||
api_is_allowed_to_edit()
|
||||
);
|
||||
$last_post = null;
|
||||
|
||||
if ($last_post_info) {
|
||||
$poster_info = api_get_user_info($last_post_info['poster_id']);
|
||||
$post_date = Display::dateToStringAgoAndLongDate($last_post_info['post_date']);
|
||||
$last_post = $post_date.'<br>'.get_lang('By').' '.display_user_link(
|
||||
$last_post_info['poster_id'],
|
||||
$poster_info['complete_name'],
|
||||
'',
|
||||
$poster_info['username']
|
||||
);
|
||||
}
|
||||
|
||||
$html .= '<div class="col-md-5">'
|
||||
.Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY)
|
||||
.' '.$last_post;
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="col-md-3">';
|
||||
$cidreq = api_get_cidreq();
|
||||
|
||||
// Get attachment id.
|
||||
if (isset($row['post_id'])) {
|
||||
$attachment_list = get_attachment($row['post_id']);
|
||||
}
|
||||
$id_attach = !empty($attachment_list) ? $attachment_list['id'] : '';
|
||||
$iconsEdit = '';
|
||||
if ($origin != 'learnpath') {
|
||||
if (api_is_allowed_to_edit(false, true) &&
|
||||
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
|
||||
) {
|
||||
$iconsEdit .= '<a href="'.$forumUrl.'editthread.php?'.$cidreq
|
||||
.'&forum='.$my_forum.'&thread='
|
||||
.intval($row['thread_id'])
|
||||
.'&id_attach='.$id_attach.'">'
|
||||
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
|
||||
if (api_resource_is_locked_by_gradebook($row['thread_id'], LINK_FORUM_THREAD)) {
|
||||
$iconsEdit .= Display::return_icon(
|
||||
'delete_na.png',
|
||||
get_lang('ResourceLockedByGradebook'),
|
||||
[],
|
||||
ICON_SIZE_SMALL
|
||||
);
|
||||
} else {
|
||||
$iconsEdit .= '<a href="'.api_get_self().'?'.$cidreq.'&forum='
|
||||
.$my_forum.'&action=delete&content=thread&id='
|
||||
.$row['thread_id']."\" onclick=\"javascript:if(!confirm('"
|
||||
.addslashes(api_htmlentities(get_lang('DeleteCompleteThread'), ENT_QUOTES))
|
||||
."')) return false;\">"
|
||||
.Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL).'</a>';
|
||||
}
|
||||
|
||||
$iconsEdit .= return_visible_invisible_icon(
|
||||
'thread',
|
||||
$row['thread_id'],
|
||||
$row['visibility'],
|
||||
[
|
||||
'forum' => $my_forum,
|
||||
'gidReq' => $groupId,
|
||||
]
|
||||
);
|
||||
$iconsEdit .= return_lock_unlock_icon(
|
||||
'thread',
|
||||
$row['thread_id'],
|
||||
$row['locked'],
|
||||
[
|
||||
'forum' => $my_forum,
|
||||
'gidReq' => api_get_group_id(),
|
||||
]
|
||||
);
|
||||
$iconsEdit .= '<a href="viewforum.php?'.$cidreq.'&forum='
|
||||
.$my_forum
|
||||
.'&action=move&thread='.$row['thread_id'].'">'
|
||||
.Display::return_icon('move.png', get_lang('MoveThread'), [], ICON_SIZE_SMALL)
|
||||
.'</a>';
|
||||
}
|
||||
}
|
||||
$iconnotify = 'notification_mail_na.png';
|
||||
$notifyAltText = get_lang('NotifyMe');
|
||||
if (is_array(
|
||||
isset($_SESSION['forum_notification']['thread']) ? $_SESSION['forum_notification']['thread'] : null
|
||||
)
|
||||
) {
|
||||
if (in_array($row['thread_id'], $_SESSION['forum_notification']['thread'])) {
|
||||
$iconnotify = 'notification_mail.png';
|
||||
$notifyAltText = get_lang('CancelNotifyMe');
|
||||
}
|
||||
}
|
||||
$icon_liststd = 'user.png';
|
||||
if (!api_is_anonymous() &&
|
||||
api_is_allowed_to_session_edit(false, true) &&
|
||||
!$hideNotifications
|
||||
) {
|
||||
$iconsEdit .= '<a href="'.api_get_self().'?'.$cidreq.'&forum='
|
||||
.$my_forum
|
||||
."&action=notify&content=thread&id={$row['thread_id']}"
|
||||
.'">'.Display::return_icon($iconnotify, $notifyAltText).'</a>';
|
||||
}
|
||||
|
||||
if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath') {
|
||||
$iconsEdit .= '<a href="'.api_get_self().'?'.$cidreq.'&forum='
|
||||
.$my_forum
|
||||
."&action=liststd&content=thread&id={$row['thread_id']}"
|
||||
.'">'.Display::return_icon($icon_liststd, get_lang('StudentList'), [], ICON_SIZE_SMALL)
|
||||
.'</a>';
|
||||
}
|
||||
$html .= $iconsEdit;
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
echo $html;
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
echo isset($table_list) ? $table_list : '';
|
||||
|
||||
if ($origin != 'learnpath') {
|
||||
Display::display_footer();
|
||||
}
|
||||
504
main/forum/viewforumcategory.php
Normal file
504
main/forum/viewforumcategory.php
Normal file
@@ -0,0 +1,504 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CourseBundle\Entity\CForumPost;
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* are added:
|
||||
* - forum categories and forums can be sorted up or down, locked or made invisible
|
||||
* - consistent and integrated forum administration
|
||||
* - forum options: are students allowed to edit their post?
|
||||
* moderation of posts (approval)
|
||||
* reply only forums (students cannot create new threads)
|
||||
* multiple forums per group
|
||||
* - sticky messages
|
||||
* - new view option: nested view
|
||||
* - quoting a message.
|
||||
*
|
||||
* @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
* @Copyright Ghent University
|
||||
* @Copyright Patrick Cool
|
||||
*
|
||||
* @package chamilo.forum
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
Session::erase('_gid');
|
||||
|
||||
// Notification for unauthorized people.
|
||||
api_protect_course_script(true);
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
$(\'.hide-me\').slideUp()
|
||||
});
|
||||
|
||||
function hidecontent(content){
|
||||
$(content).slideToggle(\'normal\');
|
||||
}
|
||||
</script>';
|
||||
|
||||
// The section (tabs)
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
// Including additional library scripts.
|
||||
$nameTools = get_lang('ToolForum');
|
||||
|
||||
$_user = api_get_user_info();
|
||||
$_course = api_get_course_info();
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : '';
|
||||
$hideNotifications = api_get_course_setting('hide_forum_notifications');
|
||||
$hideNotifications = $hideNotifications == 1;
|
||||
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
// Are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
$sessionId = api_get_session_id();
|
||||
$current_forum_category = get_forum_categories($_GET['forumcategory']);
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(urlencode(isset($_GET['search']) ? $_GET['search'] : '')),
|
||||
'name' => get_lang('Forum'),
|
||||
];
|
||||
|
||||
if (!empty($action) && !empty($_GET['content'])) {
|
||||
if ($action == 'add' && $_GET['content'] == 'forum') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$current_forum_category['cat_id'],
|
||||
'name' => $current_forum_category['cat_title'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => get_lang('AddForum'),
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => $current_forum_category['cat_title'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($origin == 'learnpath') {
|
||||
Display::display_reduced_header();
|
||||
} else {
|
||||
Display::display_header(null);
|
||||
}
|
||||
|
||||
/* ACTIONS */
|
||||
$whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
|
||||
|
||||
/* Is the user allowed here? */
|
||||
|
||||
// if the user is not a course administrator and the forum is hidden
|
||||
// then the user is not allowed here.
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
($current_forum_category && $current_forum_category['visibility'] == 0)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
/* Action Links */
|
||||
$html = '<div class="actions">';
|
||||
$html .= '<a href="index.php?'.api_get_cidreq().'">'.
|
||||
Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
if (api_is_allowed_to_edit(false, true)) {
|
||||
$html .= '<a href="'.api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&forumcategory='
|
||||
.$current_forum_category['cat_id'].'&action=add&content=forum"> '
|
||||
.Display::return_icon('new_forum.png', get_lang('AddForum'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
}
|
||||
$html .= search_link();
|
||||
$html .= '</div>';
|
||||
|
||||
echo $html;
|
||||
|
||||
$logInfo = [
|
||||
'tool' => TOOL_FORUM,
|
||||
'action' => $action,
|
||||
'info' => isset($_GET['content']) ? $_GET['content'] : '',
|
||||
];
|
||||
Event::registerLog($logInfo);
|
||||
|
||||
if (api_is_allowed_to_edit(false, true)) {
|
||||
handle_forum_and_forumcategories();
|
||||
}
|
||||
|
||||
// Notification
|
||||
if ($action == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
|
||||
$return_message = set_notification($_GET['content'], $_GET['id']);
|
||||
echo Display::return_message($return_message, 'confirm', false);
|
||||
}
|
||||
|
||||
if ($action != 'add') {
|
||||
/*
|
||||
RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
|
||||
Note: We do this here just after het handling of the actions to be sure that we already incorporate the
|
||||
latest changes.
|
||||
*/
|
||||
// Step 1: We store all the forum categories in an array $forum_categories.
|
||||
$forum_categories = [];
|
||||
$forum_category = get_forum_categories($_GET['forumcategory']);
|
||||
|
||||
// Step 2: We find all the forums.
|
||||
$forum_list = get_forums();
|
||||
|
||||
/* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
|
||||
|
||||
// The groups of the user.
|
||||
$groups_of_user = GroupManager::get_group_ids($_course['real_id'], $_user['user_id']);
|
||||
// All groups in the course (and sorting them as the id of the group = the key of the array.
|
||||
$all_groups = GroupManager::get_group_list();
|
||||
if (is_array($all_groups)) {
|
||||
foreach ($all_groups as $group) {
|
||||
$all_groups[$group['id']] = $group;
|
||||
}
|
||||
}
|
||||
|
||||
/* Display Forum Categories and the Forums in it */
|
||||
$html = '';
|
||||
$html .= '<div class="category-forum">';
|
||||
|
||||
$session_displayed = '';
|
||||
if ((!isset($sessionId) || $sessionId == 0) &&
|
||||
!empty($forum_category['session_name'])
|
||||
) {
|
||||
$session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
|
||||
}
|
||||
|
||||
$forum_categories_list = [];
|
||||
$forumId = $forum_category['cat_id'];
|
||||
$forumTitle = Security::remove_XSS($forum_category['cat_title']);
|
||||
$linkForumCategory = 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.strval(intval($forumId));
|
||||
$descriptionCategory = $forum_category['cat_comment'];
|
||||
$icoCategory = Display::return_icon(
|
||||
'forum_blue.png',
|
||||
get_lang($forum_category['cat_title']),
|
||||
['class' => ''],
|
||||
ICON_SIZE_MEDIUM
|
||||
);
|
||||
|
||||
if (api_is_allowed_to_edit(false, true) &&
|
||||
!($forum_category['session_id'] == 0 && $sessionId != 0)
|
||||
) {
|
||||
$iconsEdit = '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='
|
||||
.Security::remove_XSS($_GET['forumcategory']).'&action=edit&content=forumcategory&id='
|
||||
.''.$forumId.'">'
|
||||
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
|
||||
$iconsEdit .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='
|
||||
.Security::remove_XSS($_GET['forumcategory'])
|
||||
.'&action=delete&content=forumcategory&id='.$forumId
|
||||
."\" onclick=\"javascript:if(!confirm('"
|
||||
.addslashes(api_htmlentities(get_lang('DeleteForumCategory'), ENT_QUOTES))
|
||||
."')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL)
|
||||
.'</a>';
|
||||
$iconsEdit .= return_visible_invisible_icon(
|
||||
'forumcategory',
|
||||
$forum_category['cat_id'],
|
||||
$forum_category['visibility'],
|
||||
['forumcategory' => $_GET['forumcategory']]
|
||||
);
|
||||
$iconsEdit .= return_lock_unlock_icon(
|
||||
'forumcategory',
|
||||
$forum_category['cat_id'],
|
||||
$forum_category['locked'],
|
||||
['forumcategory' => $_GET['forumcategory']]
|
||||
);
|
||||
$iconsEdit .= return_up_down_icon(
|
||||
'forumcategory',
|
||||
$forum_category['cat_id'],
|
||||
$forum_categories_list
|
||||
);
|
||||
$html .= Display::tag(
|
||||
'div',
|
||||
$iconsEdit,
|
||||
['class' => 'pull-right']
|
||||
);
|
||||
}
|
||||
|
||||
$session_img = api_get_session_image($forum_category['session_id'], $_user['status']);
|
||||
|
||||
$html .= Display::tag(
|
||||
'h3',
|
||||
$icoCategory.
|
||||
Display::tag(
|
||||
'a',
|
||||
$forumTitle,
|
||||
[
|
||||
'href' => $linkForumCategory,
|
||||
'class' => empty($forum_category['visibility']) ? 'text-muted' : null,
|
||||
]
|
||||
).$session_displayed.$session_img,
|
||||
null
|
||||
);
|
||||
|
||||
if ($descriptionCategory != '' && trim($descriptionCategory) != ' ') {
|
||||
$html .= '<div class="forum-description">'.$descriptionCategory.'</div>';
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
echo $html;
|
||||
echo '<div class="forum_display">';
|
||||
// The forums in this category.
|
||||
$forums_in_category = get_forums_in_category($forum_category['cat_id']);
|
||||
|
||||
// Step 4: We display all the forums in this category.
|
||||
$forum_count = 0;
|
||||
foreach ($forum_list as $forum) {
|
||||
if (!empty($forum['forum_category'])) {
|
||||
if ($forum['forum_category'] == $forum_category['cat_id']) {
|
||||
// The forum has to be showed if
|
||||
// 1.v it is a not a group forum (teacher and student)
|
||||
// 2.v it is a group forum and it is public (teacher and student)
|
||||
// 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
|
||||
// if the forum is private and it is a group forum and the user
|
||||
// is not a member of the group forum then it cannot be displayed
|
||||
$show_forum = false;
|
||||
// SHOULD WE SHOW THIS PARTICULAR FORUM
|
||||
// you are teacher => show forum
|
||||
|
||||
if (api_is_allowed_to_edit(false, true)) {
|
||||
$show_forum = true;
|
||||
} else {
|
||||
// you are not a teacher
|
||||
// it is not a group forum => show forum
|
||||
// (invisible forums are already left out see get_forums function)
|
||||
if ($forum['forum_of_group'] == '0') {
|
||||
$show_forum = true;
|
||||
} else {
|
||||
// it is a group forum
|
||||
//echo '-groepsforum';
|
||||
// it is a group forum but it is public => show
|
||||
if ($forum['forum_group_public_private'] == 'public') {
|
||||
$show_forum = true;
|
||||
} else {
|
||||
// it is a group forum and it is private
|
||||
//echo '-prive';
|
||||
// it is a group forum and it is private but the user is member of the group
|
||||
if (in_array($forum['forum_of_group'], $groups_of_user)) {
|
||||
$show_forum = true;
|
||||
} else {
|
||||
$show_forum = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$form_count = isset($form_count) ? $form_count : 0;
|
||||
if ($show_forum === true) {
|
||||
$form_count++;
|
||||
$html = '<div class="panel panel-default forum">';
|
||||
$html .= '<div class="panel-body">';
|
||||
$my_whatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null;
|
||||
|
||||
if ($forum['forum_of_group'] == '0') {
|
||||
$forum_image = Display::return_icon(
|
||||
'forum_group.png',
|
||||
get_lang('GroupForum'),
|
||||
null,
|
||||
ICON_SIZE_LARGE
|
||||
);
|
||||
} else {
|
||||
$forum_image = Display::return_icon(
|
||||
'forum.png',
|
||||
get_lang('Forum'),
|
||||
null,
|
||||
ICON_SIZE_LARGE
|
||||
);
|
||||
}
|
||||
|
||||
if ($forum['forum_of_group'] != '0') {
|
||||
$my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name'])
|
||||
? $all_groups[$forum['forum_of_group']]['name']
|
||||
: null;
|
||||
$my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id'])
|
||||
? $all_groups[$forum['forum_of_group']]['id']
|
||||
: null;
|
||||
$group_title = api_substr($my_all_groups_forum_name, 0, 30);
|
||||
$forum_title_group_addition = ' (<a href="../group/group_space.php?'.api_get_cidreq()
|
||||
.'&gidReq='.$my_all_groups_forum_id.'" class="forum_group_link">'
|
||||
.get_lang('GoTo').' '.$group_title.'</a>)';
|
||||
} else {
|
||||
$forum_title_group_addition = '';
|
||||
}
|
||||
|
||||
if (!empty($sessionId) && !empty($forum['session_name'])) {
|
||||
$session_displayed = ' ('.$forum['session_name'].')';
|
||||
} else {
|
||||
$session_displayed = '';
|
||||
}
|
||||
|
||||
// the number of topics and posts
|
||||
$my_number_threads = isset($forum['forum_threads']) ? $forum['forum_threads'] : 0;
|
||||
$my_number_posts = isset($forum['forum_posts']) ? $forum['forum_posts'] : 0;
|
||||
|
||||
$html .= '<div class="row">';
|
||||
$html .= '<div class="col-md-6">';
|
||||
$html .= '<div class="col-md-3">';
|
||||
$html .= '<div class="number-post">'.$forum_image.
|
||||
'<p>'.$my_number_threads.' '.get_lang('ForumThreads').'</p></div>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div class="col-md-9">';
|
||||
$iconForum = Display::return_icon(
|
||||
'forum_yellow.png',
|
||||
Security::remove_XSS(get_lang($forum_category['cat_title'])),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
);
|
||||
|
||||
$linkForum = Display::tag(
|
||||
'a',
|
||||
Security::remove_XSS($forum['forum_title']).$session_displayed,
|
||||
[
|
||||
'href' => 'viewforum.php?'.api_get_cidreq(true, false)."&gidReq={$forum['forum_of_group']}&forum={$forum['forum_id']}&search=".Security::remove_XSS(urlencode(isset($_GET['search']) ? $_GET['search'] : '')),
|
||||
'class' => empty($forum['visibility']) ? 'text-muted' : null,
|
||||
]
|
||||
);
|
||||
$html .= Display::tag(
|
||||
'h3',
|
||||
$linkForum.' '.$forum_title_group_addition,
|
||||
[
|
||||
'class' => 'title',
|
||||
]
|
||||
);
|
||||
$html .= Display::tag(
|
||||
'p',
|
||||
Security::remove_XSS(strip_tags($forum['forum_comment'])),
|
||||
[
|
||||
'class' => 'description',
|
||||
]
|
||||
);
|
||||
|
||||
if ($forum['moderated'] == 1 && api_is_allowed_to_edit(false, true)) {
|
||||
$waitingCount = getCountPostsWithStatus(
|
||||
CForumPost::STATUS_WAITING_MODERATION,
|
||||
$forum
|
||||
);
|
||||
if (!empty($waitingCount)) {
|
||||
$html .= Display::label(
|
||||
get_lang('PostsPendingModeration').': '.$waitingCount,
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="col-md-6">';
|
||||
$iconEmpty = '';
|
||||
// The number of topics and posts.
|
||||
if ($forum['forum_of_group'] !== '0') {
|
||||
$newPost = $iconEmpty;
|
||||
if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
|
||||
$newPost = ' '.Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
|
||||
}
|
||||
} else {
|
||||
$newPost = $iconEmpty;
|
||||
if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
|
||||
$newPost = ' '.Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '<div class="row">';
|
||||
$html .= '<div class="col-md-2">';
|
||||
$html .= $newPost.'</div>';
|
||||
|
||||
$poster_id = 0;
|
||||
$name = '';
|
||||
// the last post in the forum
|
||||
if (isset($forum['last_poster_name']) && $forum['last_poster_name'] != '') {
|
||||
$name = $forum['last_poster_name'];
|
||||
} else {
|
||||
if (isset($forum['last_poster_lastname'])) {
|
||||
$name = api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
|
||||
$poster_id = $forum['last_poster_id'];
|
||||
}
|
||||
}
|
||||
$html .= '<div class="col-md-6">';
|
||||
if (!empty($forum['last_post_id'])) {
|
||||
$html .= Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY).' ';
|
||||
$html .= Display::dateToStringAgoAndLongDate($forum['last_post_date'])
|
||||
.' '.get_lang('By').' '
|
||||
.display_user_link($poster_id, $name);
|
||||
}
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="col-md-4">';
|
||||
|
||||
$url = api_get_path(WEB_CODE_PATH).'forum/index.php';
|
||||
$forumCategoryId = (int) $_GET['forumcategory'];
|
||||
|
||||
if (api_is_allowed_to_edit(false, true) &&
|
||||
!($forum['session_id'] == 0 && $sessionId != 0)
|
||||
) {
|
||||
$html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$forumCategoryId.'&action=edit&content=forum&id='.$forum['forum_id'].'">'
|
||||
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
|
||||
$html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$forumCategoryId.'&action=delete&content=forum&id='.$forum['forum_id']
|
||||
."\" onclick=\"javascript:if(!confirm('"
|
||||
.addslashes(api_htmlentities(get_lang('DeleteForum'), ENT_QUOTES))
|
||||
."')) return false;\">"
|
||||
.Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL)
|
||||
.'</a>';
|
||||
$html .= return_visible_invisible_icon(
|
||||
'forum',
|
||||
$forum['forum_id'],
|
||||
$forum['visibility'],
|
||||
['forumcategory' => $_GET['forumcategory']]
|
||||
);
|
||||
$html .= return_lock_unlock_icon(
|
||||
'forum',
|
||||
$forum['forum_id'],
|
||||
$forum['locked'],
|
||||
['forumcategory' => $_GET['forumcategory']]
|
||||
);
|
||||
$html .= return_up_down_icon(
|
||||
'forum',
|
||||
$forum['forum_id'],
|
||||
$forums_in_category
|
||||
);
|
||||
}
|
||||
|
||||
$iconnotify = 'notification_mail_na.png';
|
||||
$notifyAltText = get_lang('NotifyMe');
|
||||
if (is_array(isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : null)) {
|
||||
if (in_array($forum['forum_id'], $_SESSION['forum_notification']['forum'])) {
|
||||
$iconnotify = 'notification_mail.png';
|
||||
$notifyAltText = get_lang('CancelNotifyMe');
|
||||
}
|
||||
}
|
||||
|
||||
if (!api_is_anonymous() && $hideNotifications == false) {
|
||||
$html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$forumCategoryId.'&action=notify&content=forum&id='.$forum['forum_id'].'">'.
|
||||
Display::return_icon($iconnotify, $notifyAltText).
|
||||
'</a>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div></div>';
|
||||
}
|
||||
echo $html;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($forum_list) == 0) {
|
||||
echo '<div class="alert alert-warning">'.get_lang('NoForumInThisCategory').'</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/* FOOTER */
|
||||
if ($origin != 'learnpath') {
|
||||
Display::display_footer();
|
||||
}
|
||||
715
main/forum/viewthread.php
Normal file
715
main/forum/viewthread.php
Normal file
@@ -0,0 +1,715 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CourseBundle\Entity\CForumPost;
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$current_course_tool = TOOL_FORUM;
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
// Notification for unauthorized people.
|
||||
api_protect_course_script(true);
|
||||
|
||||
require_once 'forumfunction.inc.php';
|
||||
|
||||
$nameTools = get_lang('Forum');
|
||||
$forumUrl = api_get_path(WEB_CODE_PATH).'forum/';
|
||||
|
||||
// Are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
$_user = api_get_user_info();
|
||||
$my_search = null;
|
||||
|
||||
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
|
||||
$threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
|
||||
|
||||
$current_thread = get_thread_information($forumId, $threadId);
|
||||
$current_forum = get_forum_information($current_thread['forum_id']);
|
||||
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
|
||||
$whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
|
||||
|
||||
if (api_is_in_gradebook()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => Category::getUrl(),
|
||||
'name' => get_lang('ToolGradebook'),
|
||||
];
|
||||
}
|
||||
|
||||
$groupId = api_get_group_id();
|
||||
$group_properties = GroupManager::get_group_properties($groupId);
|
||||
$sessionId = api_get_session_id();
|
||||
|
||||
$ajaxURL = api_get_path(WEB_AJAX_PATH).'forum.ajax.php?'.api_get_cidreq().'&a=change_post_status';
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
$("span").on("click", ".change_post_status", function() {
|
||||
var updateDiv = $(this).parent();
|
||||
var postId = updateDiv.attr("id");
|
||||
|
||||
$.ajax({
|
||||
url: "'.$ajaxURL.'&post_id="+postId,
|
||||
type: "GET",
|
||||
success: function(data) {
|
||||
updateDiv.html(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>';
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : '';
|
||||
$logInfo = [
|
||||
'tool' => TOOL_FORUM,
|
||||
'tool_id' => $forumId,
|
||||
'tool_id_detail' => $threadId,
|
||||
'action' => !empty($action) ? $action : 'view-thread',
|
||||
'action_details' => isset($_GET['content']) ? $_GET['content'] : '',
|
||||
];
|
||||
Event::registerLog($logInfo);
|
||||
|
||||
$currentUrl = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&'.api_get_cidreq().'&thread='.$threadId;
|
||||
|
||||
switch ($action) {
|
||||
case 'change_view':
|
||||
$view = isset($_REQUEST['view']) && in_array($_REQUEST['view'], ['nested', 'flat']) ? $_REQUEST['view'] : '';
|
||||
if (!empty($view)) {
|
||||
Session::write('thread_view', $view);
|
||||
}
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'delete':
|
||||
if (
|
||||
isset($_GET['content']) &&
|
||||
isset($_GET['id']) &&
|
||||
(api_is_allowed_to_edit(false, true) ||
|
||||
(isset($group_properties['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties)))
|
||||
) {
|
||||
$message = delete_post($_GET['id']);
|
||||
Display::addFlash(Display::return_message(get_lang($message)));
|
||||
}
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'invisible':
|
||||
case 'visible':
|
||||
if (isset($_GET['id']) &&
|
||||
(api_is_allowed_to_edit(false, true) ||
|
||||
(isset($group_properties['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties)))
|
||||
) {
|
||||
$message = approve_post($_GET['id'], $action);
|
||||
Display::addFlash(Display::return_message(get_lang($message)));
|
||||
}
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'move':
|
||||
if (isset($_GET['post'])) {
|
||||
$message = move_post_form();
|
||||
Display::addFlash(Display::return_message(get_lang($message), 'normal', false));
|
||||
}
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'report':
|
||||
$postId = isset($_GET['post_id']) ? $_GET['post_id'] : 0;
|
||||
|
||||
$result = reportPost($postId, $current_forum, $current_thread);
|
||||
Display::addFlash(Display::return_message(get_lang('Reported')));
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'ask_revision':
|
||||
if (api_get_configuration_value('allow_forum_post_revisions')) {
|
||||
$postId = isset($_GET['post_id']) ? $_GET['post_id'] : 0;
|
||||
$result = savePostRevision($postId);
|
||||
Display::addFlash(Display::return_message(get_lang('Saved')));
|
||||
}
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($groupId)) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('Groups'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('GroupSpace').' '.$group_properties['name'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq()."&search=".Security::remove_XSS(urlencode($my_search)),
|
||||
'name' => Security::remove_XSS($current_forum['forum_title']),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&'.api_get_cidreq().'&thread='.$threadId,
|
||||
'name' => Security::remove_XSS($current_thread['thread_title']),
|
||||
];
|
||||
} else {
|
||||
$my_search = isset($_GET['search']) ? $_GET['search'] : '';
|
||||
if ($origin !== 'learnpath') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(
|
||||
urlencode($my_search)
|
||||
),
|
||||
'name' => $nameTools,
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'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[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId."&search=".Security::remove_XSS(urlencode($my_search)),
|
||||
'name' => Security::remove_XSS($current_forum['forum_title']),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => Security::remove_XSS($current_thread['thread_title']),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// If the user is not a course administrator and the forum is hidden
|
||||
// then the user is not allowed here.
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
($current_forum['visibility'] == 0 || $current_thread['visibility'] == 0)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
// this increases the number of times the thread has been viewed
|
||||
increase_thread_view($threadId);
|
||||
|
||||
if ($origin === 'learnpath') {
|
||||
$template = new Template('', false, false, true, true, false);
|
||||
} else {
|
||||
$template = new Template();
|
||||
}
|
||||
|
||||
$actions = '<span style="float:right;">'.search_link().'</span>';
|
||||
if ($origin !== 'learnpath') {
|
||||
$actions .= '<a href="'.$forumUrl.'viewforum.php?forum='.$forumId.'&'.api_get_cidreq().'">'
|
||||
.Display::return_icon('back.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
}
|
||||
|
||||
// The reply to thread link should only appear when the forum_category is
|
||||
// not locked AND the forum is not locked AND the thread is not locked.
|
||||
// If one of the three levels is locked then the link should not be displayed.
|
||||
if (($current_forum_category &&
|
||||
$current_forum_category['locked'] == 0) &&
|
||||
$current_forum['locked'] == 0 &&
|
||||
$current_thread['locked'] == 0 ||
|
||||
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'] || ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) {
|
||||
// reply link
|
||||
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
|
||||
$actions .= '<a href="'.$forumUrl.'reply.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='
|
||||
.$threadId.'&action=replythread">'
|
||||
.Display::return_icon('reply_thread.png', get_lang('ReplyToThread'), '', ICON_SIZE_MEDIUM)
|
||||
.'</a>';
|
||||
}
|
||||
// new thread link
|
||||
if ((
|
||||
api_is_allowed_to_edit(false, true) &&
|
||||
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)) ||
|
||||
($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 && $current_forum['locked'] != 1) {
|
||||
$actions .= ' ';
|
||||
} else {
|
||||
$actions .= get_lang('ForumLocked');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$actions .= Display::url(
|
||||
Display::return_icon('forum_nestedview.png', get_lang('NestedView'), [], ICON_SIZE_MEDIUM),
|
||||
$currentUrl.'&action=change_view&view=nested'
|
||||
);
|
||||
|
||||
$actions .= Display::url(
|
||||
Display::return_icon('forum_listview.png', get_lang('FlatView'), [], ICON_SIZE_MEDIUM),
|
||||
$currentUrl.'&action=change_view&view=flat'
|
||||
);
|
||||
|
||||
$template->assign('forum_actions', $actions);
|
||||
$template->assign('origin', api_get_origin());
|
||||
|
||||
$viewMode = $current_forum['default_view'];
|
||||
|
||||
//$whiteList = ['flat', 'threaded', 'nested'];
|
||||
if ($viewMode !== 'flat') {
|
||||
$viewMode = 'nested';
|
||||
}
|
||||
|
||||
$userView = Session::read('thread_view');
|
||||
if (!empty($userView)) {
|
||||
$viewMode = $userView;
|
||||
}
|
||||
|
||||
if ($current_thread['thread_peer_qualify'] == 1) {
|
||||
Display::addFlash(Display::return_message(get_lang('ForumThreadPeerScoringStudentComment'), 'info'));
|
||||
}
|
||||
|
||||
$allowReport = reportAvailable();
|
||||
|
||||
// Are we in a lp ?
|
||||
$origin = api_get_origin();
|
||||
//delete attachment file
|
||||
if ($action === 'delete_attach' && isset($_GET['id_attach'])
|
||||
) {
|
||||
delete_attachment(0, $_GET['id_attach']);
|
||||
}
|
||||
|
||||
$origin = api_get_origin();
|
||||
$sessionId = api_get_session_id();
|
||||
$_user = api_get_user_info();
|
||||
$userId = api_get_user_id();
|
||||
$groupId = api_get_group_id();
|
||||
|
||||
// Decide whether we show the latest post first
|
||||
$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : ($origin !== 'learnpath' ? 'ASC' : 'DESC');
|
||||
$posts = getPosts($current_forum, $threadId, $sortDirection, true);
|
||||
$count = 0;
|
||||
$group_id = api_get_group_id();
|
||||
$locked = api_resource_is_locked_by_gradebook($threadId, LINK_FORUM_THREAD);
|
||||
$sessionId = api_get_session_id();
|
||||
$currentThread = get_thread_information($forumId, $threadId);
|
||||
$userId = api_get_user_id();
|
||||
$groupInfo = GroupManager::get_group_properties($group_id);
|
||||
$postCount = 1;
|
||||
$allowUserImageForum = api_get_course_setting('allow_user_image_forum');
|
||||
|
||||
// The user who posted it can edit his thread only if the course admin allowed this in the properties
|
||||
// of the forum
|
||||
// The course admin him/herself can do this off course always
|
||||
$tutorGroup = GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo);
|
||||
|
||||
$postList = [];
|
||||
foreach ($posts as $post) {
|
||||
$posterId = isset($post['user_id']) ? $post['user_id'] : 0;
|
||||
$username = '';
|
||||
if (isset($post['username'])) {
|
||||
$username = sprintf(get_lang('LoginX'), $post['username']);
|
||||
}
|
||||
|
||||
$name = $post['complete_name'];
|
||||
if (empty($posterId)) {
|
||||
$name = $post['poster_name'];
|
||||
}
|
||||
|
||||
$post['user_data'] = '';
|
||||
if ($origin !== 'learnpath') {
|
||||
if ($allowUserImageForum) {
|
||||
$post['user_data'] = '<div class="thumbnail">'.
|
||||
display_user_image($posterId, $name, $origin).'</div>';
|
||||
}
|
||||
|
||||
$post['user_data'] .= Display::tag(
|
||||
'h4',
|
||||
display_user_link($posterId, $name, $origin, $username),
|
||||
['class' => 'title-username']
|
||||
);
|
||||
|
||||
$_user = api_get_user_info($posterId);
|
||||
$iconStatus = $_user['icon_status'];
|
||||
$post['user_data'] .= '<div class="user-type text-center">'.$iconStatus.'</div>';
|
||||
} else {
|
||||
if ($allowUserImageForum) {
|
||||
$post['user_data'] .= '<div class="thumbnail">'.
|
||||
display_user_image($posterId, $name, $origin).'</div>';
|
||||
}
|
||||
|
||||
$post['user_data'] .= Display::tag(
|
||||
'p',
|
||||
$name,
|
||||
[
|
||||
'title' => api_htmlentities($username, ENT_QUOTES),
|
||||
'class' => 'lead',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ($origin !== 'learnpath') {
|
||||
$post['user_data'] .= Display::tag(
|
||||
'p',
|
||||
Display::dateToStringAgoAndLongDate($post['post_date']),
|
||||
['class' => 'post-date']
|
||||
);
|
||||
} else {
|
||||
$post['user_data'] .= Display::tag(
|
||||
'p',
|
||||
Display::dateToStringAgoAndLongDate($post['post_date']),
|
||||
['class' => 'text-muted']
|
||||
);
|
||||
}
|
||||
|
||||
// get attach id
|
||||
$attachment_list = get_attachment($post['post_id']);
|
||||
$id_attach = !empty($attachment_list) ? $attachment_list['iid'] : '';
|
||||
|
||||
$iconEdit = '';
|
||||
$editButton = '';
|
||||
$askForRevision = '';
|
||||
if ((isset($groupInfo['iid']) && $tutorGroup) ||
|
||||
($current_forum['allow_edit'] == 1 && $posterId == $userId) ||
|
||||
(api_is_allowed_to_edit(false, true) &&
|
||||
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
|
||||
) {
|
||||
if ($locked == false && postIsEditableByStudent($current_forum, $post)) {
|
||||
$editUrl = api_get_path(WEB_CODE_PATH).'forum/editpost.php?'.api_get_cidreq();
|
||||
$editUrl .= "&forum=$forumId&thread=$threadId&post={$post['post_id']}&id_attach=$id_attach";
|
||||
$iconEdit .= "<a href='".$editUrl."'>"
|
||||
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL)
|
||||
."</a>";
|
||||
|
||||
$editButton = Display::toolbarButton(
|
||||
get_lang('Edit'),
|
||||
$editUrl,
|
||||
'pencil',
|
||||
'default'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ((isset($groupInfo['iid']) && $tutorGroup) ||
|
||||
api_is_allowed_to_edit(false, true) &&
|
||||
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
|
||||
) {
|
||||
if ($locked == false) {
|
||||
$deleteUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query(
|
||||
[
|
||||
'forum' => $forumId,
|
||||
'thread' => $threadId,
|
||||
'action' => 'delete',
|
||||
'content' => 'post',
|
||||
'id' => $post['post_id'],
|
||||
]
|
||||
);
|
||||
$iconEdit .= Display::url(
|
||||
Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL),
|
||||
$deleteUrl,
|
||||
[
|
||||
'onclick' => "javascript:if(!confirm('"
|
||||
.addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES))
|
||||
."')) return false;",
|
||||
'id' => "delete-post-{$post['post_id']}",
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (api_is_allowed_to_edit(false, true) &&
|
||||
!(
|
||||
api_is_session_general_coach() &&
|
||||
$current_forum['session_id'] != $sessionId
|
||||
)
|
||||
) {
|
||||
$iconEdit .= return_visible_invisible_icon(
|
||||
'post',
|
||||
$post['post_id'],
|
||||
$post['visible'],
|
||||
[
|
||||
'forum' => $forumId,
|
||||
'thread' => $threadId,
|
||||
]
|
||||
);
|
||||
|
||||
if ($count > 0) {
|
||||
$iconEdit .= "<a href=\"viewthread.php?".api_get_cidreq()
|
||||
."&forum=$forumId&thread=$threadId&action=move&post={$post['post_id']}"
|
||||
."\">".Display::return_icon('move.png', get_lang('MovePost'), [], ICON_SIZE_SMALL)."</a>";
|
||||
}
|
||||
}
|
||||
|
||||
$userCanQualify = $currentThread['thread_peer_qualify'] == 1 && $post['poster_id'] != $userId;
|
||||
if (api_is_allowed_to_edit(null, true)) {
|
||||
$userCanQualify = true;
|
||||
}
|
||||
|
||||
$postIsARevision = false;
|
||||
$flagRevision = '';
|
||||
|
||||
if ($post['poster_id'] == $userId) {
|
||||
$revision = getPostRevision($post['post_id']);
|
||||
if (empty($revision)) {
|
||||
$askForRevision = getAskRevisionButton($post['post_id'], $current_thread);
|
||||
} else {
|
||||
$postIsARevision = true;
|
||||
$languageId = api_get_language_id(strtolower($revision));
|
||||
$languageInfo = api_get_language_info($languageId);
|
||||
if ($languageInfo) {
|
||||
$languages = api_get_language_list_for_flag();
|
||||
$flagRevision = '<span class="flag-icon flag-icon-'.$languages[$languageInfo['english_name']].'"></span> ';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (postNeedsRevision($post['post_id'])) {
|
||||
$askForRevision = giveRevisionButton($post['post_id'], $current_thread);
|
||||
} else {
|
||||
$revision = getPostRevision($post['post_id']);
|
||||
if (!empty($revision)) {
|
||||
$postIsARevision = true;
|
||||
$languageId = api_get_language_id(strtolower($revision));
|
||||
$languageInfo = api_get_language_info($languageId);
|
||||
if ($languageInfo) {
|
||||
$languages = api_get_language_list_for_flag();
|
||||
$flagRevision = '<span
|
||||
class="flag-icon flag-icon-'.$languages[$languageInfo['english_name']].'"></span> ';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$post['is_a_revision'] = $postIsARevision;
|
||||
$post['flag_revision'] = $flagRevision;
|
||||
|
||||
if (empty($currentThread['thread_qualify_max'])) {
|
||||
$userCanQualify = false;
|
||||
}
|
||||
|
||||
if ($userCanQualify) {
|
||||
if ($count > 0) {
|
||||
$current_qualify_thread = showQualify(
|
||||
'1',
|
||||
$posterId,
|
||||
$threadId
|
||||
);
|
||||
if ($locked == false) {
|
||||
$iconEdit .= "<a href=\"forumqualify.php?".api_get_cidreq()
|
||||
."&forum=$forumId&thread=$threadId&action=list&post={$post['post_id']}"
|
||||
."&user={$post['user_id']}&user_id={$post['user_id']}"
|
||||
."&idtextqualify=$current_qualify_thread"
|
||||
."\" >".Display::return_icon('quiz.png', get_lang('Qualify'))."</a>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$reportButton = '';
|
||||
if ($allowReport) {
|
||||
$reportButton = getReportButton($post['post_id'], $current_thread);
|
||||
}
|
||||
|
||||
$statusIcon = getPostStatus($current_forum, $post);
|
||||
if (!empty($iconEdit)) {
|
||||
$post['user_data'] .= "<div class='tools-icons'> $iconEdit $statusIcon </div>";
|
||||
} else {
|
||||
if (!empty(strip_tags($statusIcon))) {
|
||||
$post['user_data'] .= "<div class='tools-icons'> $statusIcon </div>";
|
||||
}
|
||||
}
|
||||
|
||||
$buttonReply = '';
|
||||
$buttonQuote = '';
|
||||
$waitingValidation = '';
|
||||
|
||||
if (($current_forum_category && $current_forum_category['locked'] == 0) &&
|
||||
$current_forum['locked'] == 0 && $current_thread['locked'] == 0 || api_is_allowed_to_edit(false, true)
|
||||
) {
|
||||
if ($userId || ($current_forum['allow_anonymous'] == 1 && !$userId)) {
|
||||
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
|
||||
$buttonReply = Display::toolbarButton(
|
||||
get_lang('ReplyToMessage'),
|
||||
'reply.php?'.api_get_cidreq().'&'.http_build_query([
|
||||
'forum' => $forumId,
|
||||
'thread' => $threadId,
|
||||
'post' => $post['post_id'],
|
||||
'action' => 'replymessage',
|
||||
]),
|
||||
'reply',
|
||||
'primary',
|
||||
['id' => "reply-to-post-{$post['post_id']}"]
|
||||
);
|
||||
|
||||
$buttonQuote = Display::toolbarButton(
|
||||
get_lang('QuoteMessage'),
|
||||
'reply.php?'.api_get_cidreq().'&'.http_build_query([
|
||||
'forum' => $forumId,
|
||||
'thread' => $threadId,
|
||||
'post' => $post['post_id'],
|
||||
'action' => 'quote',
|
||||
]),
|
||||
'quote-left',
|
||||
'success',
|
||||
['id' => "quote-post-{$post['post_id']}"]
|
||||
);
|
||||
|
||||
if ($current_forum['moderated'] && !api_is_allowed_to_edit(false, true)) {
|
||||
if (empty($post['status']) || $post['status'] == CForumPost::STATUS_WAITING_MODERATION) {
|
||||
$buttonReply = '';
|
||||
$buttonQuote = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$closedPost = '';
|
||||
if ($current_forum_category && $current_forum_category['locked'] == 1) {
|
||||
$closedPost = Display::tag(
|
||||
'div',
|
||||
'<em class="fa fa-exclamation-triangle"></em> '.get_lang('ForumcategoryLocked'),
|
||||
['class' => 'alert alert-warning post-closed']
|
||||
);
|
||||
}
|
||||
if ($current_forum['locked'] == 1) {
|
||||
$closedPost = Display::tag(
|
||||
'div',
|
||||
'<em class="fa fa-exclamation-triangle"></em> '.get_lang('ForumLocked'),
|
||||
['class' => 'alert alert-warning post-closed']
|
||||
);
|
||||
}
|
||||
if ($current_thread['locked'] == 1) {
|
||||
$closedPost = Display::tag(
|
||||
'div',
|
||||
'<em class="fa fa-exclamation-triangle"></em> '.get_lang('ThreadLocked'),
|
||||
['class' => 'alert alert-warning post-closed']
|
||||
);
|
||||
}
|
||||
|
||||
$post['user_data'] .= $closedPost;
|
||||
}
|
||||
|
||||
// note: this can be removed here because it will be displayed in the tree
|
||||
if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
|
||||
!empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
|
||||
!empty($whatsnew_post_info[$forumId][$post['thread_id']])
|
||||
) {
|
||||
$post_image = Display::return_icon('forumpostnew.gif');
|
||||
} else {
|
||||
$post_image = Display::return_icon('forumpost.gif');
|
||||
}
|
||||
|
||||
if ($post['post_notification'] == '1' && $post['poster_id'] == $userId) {
|
||||
$post_image .= Display::return_icon(
|
||||
'forumnotification.gif',
|
||||
get_lang('YouWillBeNotified')
|
||||
);
|
||||
}
|
||||
|
||||
$post['current'] = false;
|
||||
if (isset($_GET['post_id']) && $_GET['post_id'] == $post['post_id']) {
|
||||
$post['current'] = true;
|
||||
}
|
||||
|
||||
// Replace Re: with an icon
|
||||
$search = [
|
||||
get_lang('ReplyShort'),
|
||||
'Re:',
|
||||
'RE:',
|
||||
'AW:',
|
||||
'Aw:',
|
||||
];
|
||||
$replace = '<span>'.Display::returnFontAwesomeIcon('mail-reply').'</span>';
|
||||
$post['post_title'] = str_replace($search, $replace, Security::remove_XSS($post['post_title']));
|
||||
|
||||
// The post title
|
||||
$titlePost = Display::tag('h3', $post['post_title'], ['class' => 'forum_post_title']);
|
||||
$post['post_title'] = '<a name="post_id_'.$post['post_id'].'"></a>';
|
||||
$post['post_title'] .= Display::tag('div', $titlePost, ['class' => 'post-header']);
|
||||
|
||||
// the post body
|
||||
$post['post_text'] = Security::remove_XSS($post['post_text']);
|
||||
$post['post_data'] = Display::tag('div', $post['post_text'], ['class' => 'post-body']);
|
||||
|
||||
// The check if there is an attachment
|
||||
$post['post_attachments'] = '';
|
||||
$attachment_list = getAllAttachment($post['post_id']);
|
||||
if (!empty($attachment_list) && is_array($attachment_list)) {
|
||||
foreach ($attachment_list as $attachment) {
|
||||
$user_filename = $attachment['filename'];
|
||||
$post['post_attachments'] .= Display::return_icon('attachment.gif', get_lang('Attachment'));
|
||||
$post['post_attachments'] .= '<a href="download.php?file=';
|
||||
$post['post_attachments'] .= $attachment['path'];
|
||||
$post['post_attachments'] .= ' "> '.$user_filename.' </a>';
|
||||
$post['post_attachments'] .= '<span class="forum_attach_comment" >'.$attachment['comment'].'</span>';
|
||||
if (($current_forum['allow_edit'] == 1 && $post['user_id'] == $userId) ||
|
||||
(api_is_allowed_to_edit(false, true) && !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
|
||||
) {
|
||||
$post['post_attachments'] .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete_attach&id_attach='
|
||||
.$attachment['iid'].'&forum='.$forumId.'&thread='.$threadId
|
||||
.'" onclick="javascript:if(!confirm(\''
|
||||
.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;">'
|
||||
.Display::return_icon('delete.png', get_lang('Delete')).'</a><br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$post['post_buttons'] = "$askForRevision $editButton $reportButton $buttonReply $buttonQuote $waitingValidation";
|
||||
$postList[] = $post;
|
||||
|
||||
// The post has been displayed => it can be removed from the what's new array
|
||||
unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
|
||||
unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
|
||||
$count++;
|
||||
}
|
||||
|
||||
$template->assign('posts', $postList);
|
||||
|
||||
$formToString = '';
|
||||
$showForm = true;
|
||||
if (!api_is_allowed_to_edit(false, true) &&
|
||||
(($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
|
||||
) {
|
||||
$showForm = false;
|
||||
}
|
||||
|
||||
if (!api_is_allowed_to_session_edit(false, true) ||
|
||||
(
|
||||
($current_forum_category && $current_forum_category['locked'] != 0) ||
|
||||
$current_forum['locked'] != 0 || $current_thread['locked'] != 0
|
||||
)
|
||||
) {
|
||||
$showForm = false;
|
||||
}
|
||||
|
||||
if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
|
||||
$showForm = false;
|
||||
}
|
||||
|
||||
if ($current_forum['forum_of_group'] != 0) {
|
||||
$show_forum = GroupManager::user_has_access(
|
||||
api_get_user_id(),
|
||||
$current_forum['forum_of_group'],
|
||||
GroupManager::GROUP_TOOL_FORUM
|
||||
);
|
||||
if (!$show_forum) {
|
||||
$showForm = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($showForm) {
|
||||
$values = [
|
||||
'post_title' => Security::remove_XSS($current_thread['thread_title']),
|
||||
'post_text' => '',
|
||||
'post_notification' => '',
|
||||
'thread_sticky' => '',
|
||||
'thread_peer_qualify' => '',
|
||||
];
|
||||
$form = show_add_post_form(
|
||||
$current_forum,
|
||||
'replythread',
|
||||
$values,
|
||||
false
|
||||
);
|
||||
$formToString = $form->returnForm();
|
||||
}
|
||||
|
||||
$template->assign('form', $formToString);
|
||||
$template->assign('view_mode', $viewMode);
|
||||
$template->display($template->get_template('forum/posts.tpl'));
|
||||
Reference in New Issue
Block a user