Update from 1.11.x #2833

pull/3016/head
Julio Montoya 6 years ago
parent 5b6eb88465
commit 1cb62cca5d
  1. 48
      main/forum/download.php
  2. 3
      main/forum/editpost.php
  3. 8
      main/forum/editthread.php
  4. 50
      main/forum/forumconfig.inc.php
  5. 537
      main/forum/forumfunction.inc.php
  6. 3
      main/forum/forumqualify.php
  7. 1
      main/forum/forumsearch.php
  8. 5
      main/forum/iframe_thread.php
  9. 115
      main/forum/index.php
  10. 4
      main/forum/newthread.php
  11. 4
      main/forum/reply.php
  12. 54
      main/forum/viewforum.php
  13. 14
      main/forum/viewforumcategory.php
  14. 187
      main/forum/viewpost.php
  15. 594
      main/forum/viewthread.php
  16. 364
      main/forum/viewthread_flat.inc.php
  17. 366
      main/forum/viewthread_nested.inc.php
  18. 6
      main/inc/lib/api.lib.php
  19. 20
      main/inc/lib/certificate.lib.php
  20. 189
      main/template/default/forum/list.html.twig
  21. 59
      main/template/default/forum/posts.html.twig
  22. 13
      src/ThemeBundle/Resources/views/Macros/box.html.twig

@ -12,18 +12,16 @@
session_cache_limiter('public');
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
require_once 'forumconfig.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');
//protection
api_protect_course_script(true);
$doc_url = $_GET['file'];
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
$doc_url = str_replace('///', '&', $doc_url);
@ -31,35 +29,12 @@ $doc_url = str_replace('///', '&', $doc_url);
$doc_url = str_replace(' ', '+', $doc_url);
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
if (!isset($_course)) {
api_not_allowed(true);
}
$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/'.$doc_url;
//if the rewrite rule asks for a directory, we redirect to the document explorer
if (is_dir($full_file_name)) {
//remove last slash if present
//mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
while ($doc_url[$dul = strlen($doc_url) - 1] == '/') {
$doc_url = substr($doc_url, 0, $dul);
}
//create the path
$document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path();
//redirect
header('Location: '.$document_explorer);
exit;
}
$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);
// launch event
Event::event_download($doc_url);
$sql = 'SELECT thread_id, forum_id,filename
FROM '.$tbl_forum_post.' f
INNER JOIN '.$tbl_forum_attachment.' a
@ -72,6 +47,10 @@ $sql = 'SELECT thread_id, forum_id,filename
$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,
@ -86,15 +65,24 @@ $forum_forum_visibility = api_get_item_visibility(
);
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/'
)) {
DocumentManager::file_send_for_download(
// 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);
}
}
exit;
}
api_not_allowed();

@ -34,8 +34,6 @@ $nameTools = get_lang('ToolForum');
// Unset the formElements in session before the includes function works
unset($_SESSION['formelements']);
/* Including necessary files */
require_once 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
// Are we in a lp ?
@ -234,7 +232,6 @@ getAttachedFiles(
);
show_edit_post_form(
$forum_setting,
$current_post,
$current_thread,
$current_forum,

@ -18,9 +18,6 @@ api_protect_course_script(true);
$cidreq = api_get_cidreq();
$nameTools = get_lang('ToolForum');
/* Including necessary files */
require_once 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
// Are we in a lp ?
@ -31,9 +28,6 @@ $forumId = (int) $_GET['forum'];
$currentForum = get_forum_information($forumId);
$currentForumCategory = get_forumcategory_information($currentForum['forum_category']);
// the variable $forum_settings is declared in forumconfig.inc.php
$forumSettings = $forum_setting;
if (api_is_in_gradebook()) {
$interbreadcrumb[] = [
'url' => Category::getUrl(),
@ -214,7 +208,7 @@ if ((api_is_course_admin() || api_is_session_general_coach() || api_is_course_tu
$form->addElement('html', '</div>');
}
if ($forumSettings['allow_sticky'] && api_is_allowed_to_edit(null, true)) {
if (api_is_allowed_to_edit(null, true)) {
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
}

@ -1,50 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @todo move the tool constants to the appropriate place
* @todo make config settings out of $forum_setting
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version february 2006, dokeos 1.8
*/
/*
Database Variables
*/
$table_categories = Database::get_course_table(TABLE_FORUM_CATEGORY);
$table_forums = Database::get_course_table(TABLE_FORUM);
$table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database::get_course_table(TABLE_FORUM_POST);
$table_mailcue = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE);
$table_threads_qualify = Database::get_course_table(
TABLE_FORUM_THREAD_QUALIFY
);
$table_threads_qualify_historical = Database::get_course_table(
TABLE_FORUM_THREAD_QUALIFY_LOG
);
$forum_table_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$table_users = Database::get_main_table(TABLE_MAIN_USER);
/*
Some configuration settings
(these can go to the dokeos config settings afterwards)
*/
// if this setting is true then an I-frame will be displayed when replying
$forum_setting['show_thread_iframe_on_reply'] = true;
// if this setting is true then students and teachers can check a checkbox so
// that they receive a mail when somebody replies to the thread
$forum_setting['allow_post_notification'] = true;
// when this setting is true then the course admin can post threads that
// are important. These posts remain on top all the time (until made unsticky)
// these special posts are indicated with a special icon also
$forum_setting['allow_sticky'] = true;
// when this setting is true there will be a column that displays the
// latest post (date and poster) of the given forum.
// This requires quite some sql statements that might slow down the page with the fora.
// note: I'm currently investigating how it would be possible to increase
// the performance of this part.
$forum_setting['show_last_post'] = false;

@ -26,7 +26,7 @@ use Doctrine\Common\Collections\Criteria;
* @todo convert into a class
*/
define('FORUM_NEW_POST', 0);
get_notifications_of_user();
getNotificationsPerUser();
$htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
$htmlHeadXtra[] = '<script>
@ -211,6 +211,19 @@ function show_add_forumcategory_form($inputvalues = [], $lp_id)
null,
['ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200']
);
$extraField = new ExtraField('forum_category');
$returnParams = $extraField->addElements(
$form,
null,
[], //exclude
false, // filter
false, // tag as select
[], //show only fields
[], // order fields
[] // extra data
);
$form->addButtonCreate(get_lang('CreateCategory'), 'SubmitForumCategory');
// Setting the rules.
@ -531,6 +544,18 @@ function show_edit_forumcategory_form($inputvalues = [])
['ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200']
);
$extraField = new ExtraField('forum_category');
$returnParams = $extraField->addElements(
$form,
$categoryId,
[], //exclude
false, // filter
false, // tag as select
[], //show only fields
[], // order fields
[] // extra data
);
$form->addButtonUpdate(get_lang('ModifyCategory'), 'SubmitEditForumCategory');
// Setting the default values.
@ -624,6 +649,8 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true)
'info' => $clean_cat_title,
];
Event::registerLog($logInfo);
$values['item_id'] = $values['forum_category_id'];
} else {
$params = [
'c_id' => $course_id,
@ -665,8 +692,13 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true)
'info' => $clean_cat_title,
];
Event::registerLog($logInfo);
$values['item_id'] = $last_id;
}
$extraFieldValue = new ExtraFieldValue('forum_category');
$extraFieldValue->saveFieldValues($values);
if ($showMessage) {
Display::addFlash(Display::return_message($return_message, 'confirmation'));
}
@ -1575,7 +1607,10 @@ function get_forum_categories($id = '', $courseId = 0, $sessionId = 0)
$result = Database::query($sql);
$forum_categories_list = [];
$extraFieldValue = new ExtraFieldValue('forum_category');
while ($row = Database::fetch_assoc($result)) {
$row['extra_fields'] = $extraFieldValue->getAllValuesByItem($row['cat_id']);
if (empty($id)) {
$forum_categories_list[$row['cat_id']] = $row;
} else {
@ -1823,6 +1858,8 @@ function get_forums(
$forum_list[$key]['last_poster_name'] = $last_post_info_of_forum['last_poster_name'];
$forum_list[$key]['last_poster_lastname'] = $last_post_info_of_forum['last_poster_lastname'];
$forum_list[$key]['last_poster_firstname'] = $last_post_info_of_forum['last_poster_firstname'];
$forum_list[$key]['last_post_title'] = $last_post_info_of_forum['last_post_title'];
$forum_list[$key]['last_post_text'] = $last_post_info_of_forum['last_post_text'];
}
}
} else {
@ -1841,6 +1878,8 @@ function get_forums(
$forum_list['last_poster_name'] = $last_post_info_of_forum['last_poster_name'];
$forum_list['last_poster_lastname'] = $last_post_info_of_forum['last_poster_lastname'];
$forum_list['last_poster_firstname'] = $last_post_info_of_forum['last_poster_firstname'];
$forum_list['last_post_title'] = $last_post_info_of_forum['last_post_title'];
$forum_list['last_post_text'] = $last_post_info_of_forum['last_post_text'];
}
}
@ -1945,7 +1984,9 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_
users.firstname,
post.visible,
thread_properties.visibility AS thread_visibility,
forum_properties.visibility AS forum_visibility
forum_properties.visibility AS forum_visibility,
post.post_title,
post.post_text
FROM
$table_posts post,
$table_users users,
@ -1973,6 +2014,8 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_
$return_array['last_poster_name'] = $row['poster_name'];
$return_array['last_poster_lastname'] = $row['lastname'];
$return_array['last_poster_firstname'] = $row['firstname'];
$return_array['last_post_title'] = $row['post_title'];
$return_array['last_post_text'] = $row['post_text'];
return $return_array;
} else {
@ -1986,6 +2029,8 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_
$return_array['last_poster_name'] = $row['poster_name'];
$return_array['last_poster_lastname'] = $row['lastname'];
$return_array['last_poster_firstname'] = $row['firstname'];
$return_array['last_post_title'] = $row['post_title'];
$return_array['last_post_text'] = $row['post_text'];
return $return_array;
}
@ -2275,12 +2320,17 @@ function get_post_information($post_id)
$table_posts = Database::get_course_table(TABLE_FORUM_POST);
$table_users = Database::get_main_table(TABLE_MAIN_USER);
$course_id = api_get_course_int_id();
$post_id = (int) $post_id;
if (empty($post_id)) {
return [];
}
$sql = "SELECT posts.*, email FROM ".$table_posts." posts, ".$table_users." users
WHERE
c_id = $course_id AND
posts.poster_id=users.user_id AND
posts.post_id = ".intval($post_id);
posts.post_id = ".$post_id;
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
@ -2758,7 +2808,7 @@ function updateThread($values)
* @param int $userId Optional. The user ID
* @param int $sessionId
*
* @return int
* @return CForumThread
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
@ -2805,11 +2855,9 @@ function store_thread(
}
$post_date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
$visible = 1;
if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) {
$visible = 0; // The post has not been approved yet.
} else {
$visible = 1;
}
$clean_post_title = $values['post_title'];
@ -2947,12 +2995,16 @@ function store_thread(
$lastPostId = $lastPost->getIid();
$lastThread->setThreadLastPost($lastPostId);
$em->merge($lastThread);
$em->flush();
$logInfo = [
'tool' => TOOL_FORUM,
'tool_id' => $values['forum_id'],
'tool_id_detail' => $lastThread->getIid(),
'action' => 'new-post',
'action_details' => '',
'info' => $clean_post_title,
];
Event::registerLog($logInfo);
@ -3056,14 +3108,13 @@ function store_thread(
Display::addFlash(Display::return_message($message, 'success', false));
}
return $lastThread->getIid();
return $lastThread;
}
/**
* This function displays the form that is used to add a post. This can be a new thread or a reply.
*
* @param array $current_forum
* @param array $forum_setting
* @param string $action is the parameter that determines if we are
* 1. newthread: adding a new thread (both empty) => No I-frame
* 2. replythread: Replying to a thread ($action = replythread) => I-frame with the complete thread (if enabled)
@ -3078,20 +3129,23 @@ function store_thread(
*
* @version february 2006, dokeos 1.8
*/
function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $form_values = '')
function show_add_post_form($current_forum, $action, $id = '', $form_values = '')
{
$_user = api_get_user_info();
$action = isset($action) ? Security::remove_XSS($action) : '';
$myThread = isset($_GET['thread']) ? (int) $_GET['thread'] : '';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : '';
$my_post = isset($_GET['post']) ? (int) $_GET['post'] : '';
$giveRevision = (isset($_GET['give_revision']) && $_GET['give_revision'] == 1);
$url = api_get_self().'?'.http_build_query([
'action' => $action,
'forum' => $forumId,
'thread' => $myThread,
'post' => $my_post,
]).'&'.api_get_cidreq();
$url = api_get_self().'?'.http_build_query(
[
'action' => $action,
'forum' => $forumId,
'thread' => $myThread,
'post' => $my_post,
]
).'&'.api_get_cidreq();
$form = new FormValidator(
'thread',
@ -3129,12 +3183,26 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
'UserStatus' => 'student',
]
);
$form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
if (in_array($action, ['newthread', 'replythread', 'replymessage', 'quote'])) {
$extraFields = new ExtraField('forum_post');
$extraFields->addElements(
$form,
null,
[], //exclude
false, // filter
false, // tag as select
['ask_for_revision'], //show only fields
[], // order fields
[] // extra data);
);
}
$iframe = null;
$myThread = Security::remove_XSS($myThread);
if ($forum_setting['show_thread_iframe_on_reply'] && $action != 'newthread' && !empty($myThread)) {
$iframe = "<iframe style=\"border: 1px solid black\" src=\"iframe_thread.php?".api_get_cidreq()."&forum=".intval($forumId)."&thread=".$myThread."#".Security::remove_XSS($my_post)."\" width=\"100%\"></iframe>";
if ($action != 'newthread' && !empty($myThread)) {
$iframe = "<iframe style=\"border: 1px solid black\" src=\"iframe_thread.php?".api_get_cidreq()."&forum=".$forumId."&thread=".$myThread."#".$my_post."\" width=\"100%\"></iframe>";
}
if (!empty($iframe)) {
$form->addElement('label', get_lang('Thread'), $iframe);
@ -3194,7 +3262,7 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
Skill::addSkillsToForm($form, ITEM_TYPE_FORUM_THREAD, 0);
}
if ($forum_setting['allow_sticky'] && api_is_allowed_to_edit(null, true) && $action == 'newthread') {
if (api_is_allowed_to_edit(null, true) && $action == 'newthread') {
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
}
@ -3213,6 +3281,21 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
$form->addFile('user_upload', get_lang('Attachment'));
}
if ($giveRevision) {
$form->addHidden('give_revision', 1);
$extraField = new ExtraField('forum_post');
$returnParams = $extraField->addElements(
$form,
null,
[], //exclude
false, // filter
false, // tag as select
['revision_language'], //show only fields
[], // order fields
[] // extra data
);
}
// Setting the class and text of the form title and submit button.
if ($action == 'quote') {
$form->addButtonCreate(get_lang('QuoteMessage'), 'SubmitPost');
@ -3224,22 +3307,21 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
$form->addButtonCreate(get_lang('CreateThread'), 'SubmitPost');
}
$defaults['thread_peer_qualify'] = 0;
if (!empty($form_values)) {
$defaults['post_title'] = prepare4display($form_values['post_title']);
$defaults['post_text'] = prepare4display($form_values['post_text']);
$defaults['post_notification'] = (int) $form_values['post_notification'];
$defaults['thread_sticky'] = (int) $form_values['thread_sticky'];
$defaults['thread_peer_qualify'] = (int) $form_values['thread_peer_qualify'];
} else {
$defaults['thread_peer_qualify'] = 0;
}
// If we are quoting a message we have to retrieve the information of the post we are quoting so that
// we can add this as default to the textarea.
if (($action == 'quote' || $action == 'replymessage') && isset($my_post)) {
// We also need to put the parent_id of the post in a hidden form when
// We also need to put the parent_id of the post in a hidden form when
if (($action == 'quote' || $action == 'replymessage' || $giveRevision) && !empty($my_post)) {
// we are quoting or replying to a message (<> reply to a thread !!!)
$form->addHidden('post_parent_id', intval($my_post));
$form->addHidden('post_parent_id', $my_post);
// If we are replying or are quoting then we display a default title.
$values = get_post_information($my_post);
@ -3264,6 +3346,9 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
<div>&nbsp;</div>
';
}
if ($giveRevision) {
$defaults['post_text'] = prepare4display($values['post_text']);
}
}
$form->setDefaults(isset($defaults) ? $defaults : []);
@ -3282,7 +3367,7 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$values = $form->getSubmitValues();
if (isset($values['thread_qualify_gradebook']) &&
$values['thread_qualify_gradebook'] == '1' &&
empty($values['weight_calification'])
@ -3298,23 +3383,59 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
return false;
}
$postId = 0;
$threadId = 0;
switch ($action) {
case 'newthread':
$myThread = store_thread($current_forum, $values);
Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $myThread);
if ($myThread) {
$threadId = $myThread->getIid();
Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $threadId);
$postId = $myThread->getThreadLastPost();
}
break;
case 'quote':
case 'replythread':
case 'replymessage':
store_reply($current_forum, $values);
$postId = store_reply($current_forum, $values);
break;
}
if ($postId) {
if (isset($values['give_revision']) && $values['give_revision'] == 1) {
$extraFieldValues = new ExtraFieldValue('forum_post');
$params = [
'item_id' => $postId,
'extra_revision_language' => $values['extra_revision_language'],
];
$extraFieldValues->saveFieldValues(
$params,
false,
false,
['revision_language']
);
}
if (in_array($action, ['newthread', 'replythread', 'replymessage', 'quote'])) {
$extraFieldValues = new ExtraFieldValue('forum_post');
$params = [
'item_id' => $postId,
'extra_ask_for_revision' => isset($values['extra_ask_for_revision']) ? $values['extra_ask_for_revision'] : '',
];
$extraFieldValues->saveFieldValues(
$params,
false,
false,
['ask_for_revision']
);
}
}
$url = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&'.http_build_query(
[
'forum' => $forumId,
'thread' => $myThread,
'thread' => $threadId,
]
);
@ -3457,8 +3578,8 @@ function showQualify($option, $user_id, $thread_id)
$table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
$course_id = api_get_course_int_id();
$user_id = intval($user_id);
$thread_id = intval($thread_id);
$user_id = (int) $user_id;
$thread_id = (int) $thread_id;
if (empty($user_id) || empty($thread_id)) {
return false;
@ -3505,6 +3626,9 @@ function showQualify($option, $user_id, $thread_id)
*/
function getThreadScoreHistory($user_id, $thread_id, $opt)
{
$user_id = (int) $user_id;
$thread_id = (int) $thread_id;
$table_threads_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
$course_id = api_get_course_int_id();
@ -3512,15 +3636,15 @@ function getThreadScoreHistory($user_id, $thread_id, $opt)
$sql = "SELECT * FROM $table_threads_qualify_log
WHERE
c_id = $course_id AND
thread_id='".Database::escape_string($thread_id)."' AND
user_id='".Database::escape_string($user_id)."'
thread_id='".$thread_id."' AND
user_id='".$user_id."'
ORDER BY qualify_time";
} else {
$sql = "SELECT * FROM $table_threads_qualify_log
WHERE
c_id = $course_id AND
thread_id='".Database::escape_string($thread_id)."' AND
user_id='".Database::escape_string($user_id)."'
thread_id='".$thread_id."' AND
user_id='".$user_id."'
ORDER BY qualify_time DESC";
}
$rs = Database::query($sql);
@ -3636,7 +3760,7 @@ function current_qualify_of_thread($threadId, $sessionId, $userId)
* @param int $courseId Optional
* @param int $userId Optional
*
* @return array
* @return int post id
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
@ -3660,16 +3784,15 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0)
return false;
}
$visible = 1;
if ($current_forum['approval_direct_post'] == '1' &&
!api_is_allowed_to_edit(null, true)
) {
$visible = 0;
} else {
$visible = 1;
}
$upload_ok = 1;
$return = [];
$new_post_id = 0;
if ($upload_ok) {
// We first store an entry in the forum_post table.
@ -3782,7 +3905,7 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0)
);
}
return $return;
return $new_post_id;
}
/**
@ -3798,7 +3921,6 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0)
* @version february 2006, dokeos 1.8
*/
function show_edit_post_form(
$forum_setting,
$current_post,
$current_thread,
$current_forum,
@ -3841,6 +3963,9 @@ function show_edit_post_form(
);
$form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
$extraFields = new ExtraField('forum_post');
$extraFields->addElements($form, $current_post['post_id']);
$form->addButtonAdvancedSettings('advanced_params');
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
@ -3871,18 +3996,14 @@ function show_edit_post_form(
}
$defaults['status']['status'] = isset($current_post['status']) && !empty($current_post['status']) ? $current_post['status'] : 2;
$form->addElement(
'checkbox',
'post_notification',
'',
get_lang('NotifyByEmail').' ('.$current_post['email'].')'
);
if ($forum_setting['allow_post_notification']) {
$form->addElement(
'checkbox',
'post_notification',
'',
get_lang('NotifyByEmail').' ('.$current_post['email'].')'
);
}
if ($forum_setting['allow_sticky'] &&
api_is_allowed_to_edit(null, true) &&
if (api_is_allowed_to_edit(null, true) &&
empty($current_post['post_parent_id'])
) {
// The sticky checkbox only appears when it is the first post of a thread.
@ -3929,6 +4050,11 @@ function show_edit_post_form(
// Validation or display
if ($form->validate()) {
$values = $form->exportValues();
$values['item_id'] = $current_post['post_id'];
$extraFieldValues = new ExtraFieldValue('forum_post');
$extraFieldValues->saveFieldValues($values);
store_edit_post($current_forum, $values);
} else {
// Delete from $_SESSION forum attachment from other posts
@ -4392,7 +4518,7 @@ function handle_mail_cue($content, $id)
posts.thread_id = $id AND
posts.post_notification = '1' AND
mailcue.thread_id = $id AND
users.user_id = posts.poster_id
users.user_id = posts.poster_id AND
users.active = 1
GROUP BY users.email";
$result = Database::query($sql);
@ -5010,16 +5136,16 @@ function add_forum_attachment_file($file_comment, $last_id)
$_course = api_get_course_info();
$agenda_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
if (!isset($_FILES['user_upload'])) {
if (empty($_FILES['user_upload'])) {
return false;
}
$fileCount = count($_FILES['user_upload']['name']);
$filesData = [];
if (!is_array($_FILES['user_upload']['name'])) {
$filesData[] = $_FILES['user_upload'];
} else {
$fileCount = count($_FILES['user_upload']['name']);
$fileKeys = array_keys($_FILES['user_upload']);
for ($i = 0; $i < $fileCount; $i++) {
foreach ($fileKeys as $key) {
@ -5109,12 +5235,12 @@ function edit_forum_attachment_file($file_comment, $post_id, $id_attach)
$table_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
$course_id = api_get_course_int_id();
$fileCount = count($_FILES['user_upload']['name']);
$filesData = [];
if (!is_array($_FILES['user_upload']['name'])) {
$filesData[] = $_FILES['user_upload'];
} else {
$fileCount = count($_FILES['user_upload']['name']);
$fileKeys = array_keys($_FILES['user_upload']);
for ($i = 0; $i < $fileCount; $i++) {
@ -5253,7 +5379,6 @@ function getAllAttachment($postId)
*
* @param int $post_id
* @param int $id_attach
* @param bool $display to show or not result message
*
* @return int
*
@ -5261,7 +5386,7 @@ function getAllAttachment($postId)
*
* @version october 2014, chamilo 1.9.8
*/
function delete_attachment($post_id, $id_attach = 0, $display = true)
function delete_attachment($post_id, $id_attach = 0)
{
$_course = api_get_course_info();
@ -5301,9 +5426,8 @@ function delete_attachment($post_id, $id_attach = 0, $display = true)
api_get_user_id()
);
if (!empty($result) && !empty($id_attach) && $display) {
$message = get_lang('AttachmentFileDeleteSuccess');
echo Display::return_message($message, 'confirmation');
if (!empty($result) && !empty($id_attach)) {
Display::addFlash(Display::return_message(get_lang('AttachmentFileDeleteSuccess'), 'confirmation'));
}
return $affectedRows;
@ -5495,7 +5619,7 @@ function set_notification($content, $id, $add_only = false)
VALUES (".$course_id.", '".Database::escape_string($id)."','".intval($_user['user_id'])."')";
Database::query($sql);
Session::erase('forum_notification');
get_notifications_of_user(0, true);
getNotificationsPerUser(0, true);
return get_lang('YouWillBeNotifiedOfNewPosts');
} else {
@ -5507,7 +5631,7 @@ function set_notification($content, $id, $add_only = false)
user_id = '".intval($_user['user_id'])."'";
Database::query($sql);
Session::erase('forum_notification');
get_notifications_of_user(0, true);
getNotificationsPerUser(0, true);
return get_lang('YouWillNoLongerBeNotifiedOfNewPosts');
}
@ -5579,6 +5703,14 @@ function get_notifications($content, $id)
function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
{
$_course = api_get_course_info();
$forumCourseId = api_get_configuration_value('global_forums_course_id');
if (!empty($forumCourseId)) {
if ($_course['real_id'] == $forumCourseId) {
return false;
}
}
$forum_id = (int) $forum_id;
// The content of the mail
@ -5639,11 +5771,11 @@ function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
*
* @since May 2008, dokeos 1.8.5
*/
function get_notifications_of_user($user_id = 0, $force = false)
function getNotificationsPerUser($user_id = 0, $force = false, $course_id = 0)
{
// Database table definition
$table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
$course_id = api_get_course_int_id();
$course_id = empty($course_id) ? api_get_course_int_id() : (int) $course_id;
if (empty($course_id) || $course_id == -1) {
return null;
}
@ -5659,6 +5791,7 @@ function get_notifications_of_user($user_id = 0, $force = false)
$sql = "SELECT * FROM $table_notification
WHERE c_id = $course_id AND user_id='".intval($user_id)."'";
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
if (!is_null($row['forum_id'])) {
@ -6289,7 +6422,7 @@ function clearAttachedFiles($postId = null, $courseId = null)
$array[] = $attachId;
if ($postId !== 0) {
// Post 0 is temporal, delete them from file system and DB
delete_attachment(0, $attachId, false);
delete_attachment(0, $attachId);
}
// Delete attachment data from $_SESSION
unset($_SESSION['forum']['upload_file'][$courseId][$attachId]);
@ -6515,3 +6648,271 @@ function postIsEditableByStudent($forum, $post)
return true;
}
}
/**
* @param int $postId
*
* @return bool
*/
function savePostRevision($postId)
{
$postData = get_post_information($postId);
if (empty($postData)) {
return false;
}
$userId = api_get_user_id();
if ($postData['poster_id'] != $userId) {
return false;
}
$status = (int) !postNeedsRevision($postId);
$extraFieldValue = new ExtraFieldValue('forum_post');
$params = [
'item_id' => $postId,
'extra_ask_for_revision' => ['extra_ask_for_revision' => $status],
];
if (empty($status)) {
unset($params['extra_ask_for_revision']);
}
$extraFieldValue->saveFieldValues(
$params,
true,
false,
['ask_for_revision']
);
}
/**
* @param int $postId
*
* @return string
*/
function getPostRevision($postId)
{
$extraFieldValue = new ExtraFieldValue('forum_post');
$value = $extraFieldValue->get_values_by_handler_and_field_variable(
$postId,
'revision_language'
);
$revision = '';
if ($value && isset($value['value'])) {
$revision = $value['value'];
}
return $revision;
}
/**
* @param int $postId
*
* @return bool
*/
function postNeedsRevision($postId)
{
$extraFieldValue = new ExtraFieldValue('forum_post');
$value = $extraFieldValue->get_values_by_handler_and_field_variable(
$postId,
'ask_for_revision'
);
$hasRevision = false;
if ($value && isset($value['value'])) {
return $value['value'] == 1;
}
return $hasRevision;
}
/**
* @param int $postId
* @param array $threadInfo
*
* @return string
*/
function getAskRevisionButton($postId, $threadInfo)
{
if (api_get_configuration_value('allow_forum_post_revisions') === false) {
return '';
}
$postId = (int) $postId;
$status = 'btn-default';
if (postNeedsRevision($postId)) {
$status = 'btn-success';
}
return Display::url(
get_lang('AskRevision'),
api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.
api_get_cidreq().'&action=ask_revision&post_id='.$postId.'&forum='.$threadInfo['forum_id'].'&thread='.$threadInfo['thread_id'],
['class' => "btn $status", 'title' => get_lang('AskRevision')]
);
}
/**
* @param int $postId
* @param array $threadInfo
*
* @return string
*/
function giveRevisionButton($postId, $threadInfo)
{
$postId = (int) $postId;
return Display::toolbarButton(
get_lang('GiveRevision'),
api_get_path(WEB_CODE_PATH).'forum/reply.php?'.api_get_cidreq().'&'.http_build_query(
[
'forum' => $threadInfo['forum_id'],
'thread' => $threadInfo['thread_id'],
'post' => $postId = (int) $postId,
'action' => 'replymessage',
'give_revision' => 1,
]
),
'reply',
'primary',
['id' => "reply-to-post-{$postId}"]
);
}
/**
* @param int $postId
* @param array $threadInfo
*
* @return string
*/
function getReportButton($postId, $threadInfo)
{
$postId = (int) $postId;
return Display::url(
Display::returnFontAwesomeIcon('flag'),
api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.
api_get_cidreq().'&action=report&post_id='.$postId.'&forum='.$threadInfo['forum_id'].'&thread='.$threadInfo['thread_id'],
['class' => 'btn btn-danger', 'title' => get_lang('Report')]
);
}
/**
* @return bool
*/
function reportAvailable()
{
$extraFieldValue = new ExtraFieldValue('course');
$value = $extraFieldValue->get_values_by_handler_and_field_variable(
api_get_course_int_id(),
'allow_forum_report_button'
);
$allowReport = false;
if ($value && isset($value['value']) && $value['value'] == 1) {
$allowReport = true;
}
return $allowReport;
}
/**
* @return array
*/
function getReportRecipients()
{
$extraFieldValue = new ExtraFieldValue('course');
$value = $extraFieldValue->get_values_by_handler_and_field_variable(
api_get_course_int_id(),
'forum_report_recipients'
);
$users = [];
if ($value && isset($value['value'])) {
$usersType = explode(';', $value['value']);
foreach ($usersType as $type) {
switch ($type) {
case 'teachers':
$teachers = CourseManager::get_teacher_list_from_course_code(api_get_course_id());
if (!empty($teachers)) {
$users = array_merge($users, array_column($teachers, 'user_id'));
}
break;
case 'admins':
$admins = UserManager::get_all_administrators();
if (!empty($admins)) {
$users = array_merge($users, array_column($admins, 'user_id'));
}
break;
case 'community_managers':
$managers = api_get_configuration_value('community_managers_user_list');
if (!empty($managers) && isset($managers['users'])) {
$users = array_merge($users, $managers['users']);
}
break;
}
}
$users = array_unique(array_filter($users));
}
return $users;
}
/**
* @param int $postId
* @param array $forumInfo
* @param array $threadInfo
*
* @return bool
*/
function reportPost($postId, $forumInfo, $threadInfo)
{
if (!reportAvailable()) {
return false;
}
if (empty($forumInfo) || empty($threadInfo)) {
return false;
}
$postId = (int) $postId;
$postData = get_post_information($postId);
$currentUser = api_get_user_info();
if (!empty($postData)) {
$users = getReportRecipients();
if (!empty($users)) {
$url = api_get_path(WEB_CODE_PATH).
'forum/viewthread.php?forum='.$threadInfo['forum_id'].'&thread='.$threadInfo['thread_id'].'&'.api_get_cidreq().'&post_id='.$postId.'#post_id_'.$postId;
$postLink = Display::url(
$postData['post_title'],
$url
);
$subject = get_lang('ForumPostReported');
$content = sprintf(
get_lang('UserXReportedPostXInForumX'),
$currentUser['complete_name'],
$postLink,
$forumInfo['forum_title']
);
foreach ($users as $userId) {
MessageManager::send_message_simple($userId, $subject, $content);
}
}
}
}
/**
* @return array
*/
function getLanguageListForFlag()
{
$languages = api_get_languages();
$languages = array_column($languages, 'english_name', 'isocode');
unset($languages['en']);
$languages['gb'] = 'english';
$languages = array_flip($languages);
return $languages;
}

@ -7,9 +7,10 @@
* @todo fix all this qualify files avoid including files, use classes POO jmontoya
*/
require_once __DIR__.'/../inc/global.inc.php';
require_once 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
api_protect_course_script(true);
$nameTools = get_lang('ToolForum');
$this_section = SECTION_COURSES;
$message = '';

@ -30,7 +30,6 @@ api_protect_course_script(true);
// Including additional library scripts.
include 'forumfunction.inc.php';
include 'forumconfig.inc.php';
// Are we in a lp ?
$origin = api_get_origin();

@ -24,9 +24,9 @@ require_once __DIR__.'/../inc/global.inc.php';
// A notice for unauthorized people.
api_protect_course_script(true);
$nameTools = get_lang('ToolForum');
require 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
/* Retrieving forum and forum categorie information */
@ -56,6 +56,9 @@ if (!api_is_allowed_to_edit(false, true) &&
$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.

@ -25,6 +25,9 @@ use ChamiloSession as Session;
* @package chamilo.forum
*/
require_once __DIR__.'/../inc/global.inc.php';
api_protect_course_script(true);
$current_course_tool = TOOL_FORUM;
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
@ -39,16 +42,14 @@ function hidecontent(content){
// The section (tabs).
$this_section = SECTION_COURSES;
// Notification for unauthorized people.
api_protect_course_script(true);
$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');
$hideNotifications = $hideNotifications == 1;
// Including necessary files.
require_once 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
if (api_is_in_gradebook()) {
@ -210,6 +211,49 @@ if (!empty($allCourseForums)) {
$actions = Display::toolbarAction('toolbar-forum', [$actionLeft]);
$languages = getLanguageListForFlag();
$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('translate_html');
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)) {
@ -238,6 +282,7 @@ if (is_array($forumCategories)) {
} else {
$forumCategoryInfo['title'] = $forumCategory['cat_title'];
}
$forumCategoryInfo['extra_fields'] = $forumCategory['extra_fields'];
$forumCategoryInfo['icon_session'] = api_get_session_image($forumCategory['session_id'], $_user['status']);
// Validation when belongs to a session
@ -307,7 +352,6 @@ if (is_array($forumCategories)) {
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.
@ -417,24 +461,27 @@ if (is_array($forumCategories)) {
$toolActions = null;
$forumInfo['alert'] = null;
// 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
);
if ($hideNotifications == false) {
// 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;
@ -461,9 +508,8 @@ if (is_array($forumCategories)) {
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['avatar'] = UserManager::getUserPicture($poster_id);
} else {
$forumInfo['avatar'] = UserManager::getUserPicture($forum['insert_user_id']);
$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)
@ -512,7 +558,7 @@ if (is_array($forumCategories)) {
}
}
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true) && $hideNotifications == false) {
$toolActions .= '<a href="'.api_get_self().'?'.api_get_cidreq()
.'&action=notify&content=forum&id='.$forum['forum_id'].'">'
.Display::return_icon($iconnotify, get_lang('NotifyMe'), null, ICON_SIZE_SMALL)
@ -535,13 +581,20 @@ if (is_array($forumCategories)) {
$listForumCategory[] = $forumCategoryInfo;
}
}
$tpl = new Template($nameTools);
if (api_get_configuration_value('forum_fold_categories') == true) {
$tpl->assign('forum_fold_categories', true);
}
$tpl->assign('introduction', $introduction);
$tpl->assign('actions', $actions);
$tpl->assign('data', $listForumCategory);
$tpl->assign('form_content', $formContent);
$layout = $tpl->get_template('forum/list.html.twig');
$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']) && $value['value'] == 1) {
$layout = $tpl->get_template('forum/global_list.tpl');
} else {
$layout = $tpl->get_template('forum/list.tpl');
}
$tpl->display($layout);

@ -34,9 +34,6 @@ $_user = api_get_user_info();
$nameTools = get_lang('ToolForum');
/* Including necessary files */
require_once 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
// Are we in a lp ?
@ -157,7 +154,6 @@ $htmlHeadXtra[] = "
$form = show_add_post_form(
$current_forum,
$forum_setting,
'newthread',
'',
isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null

@ -21,15 +21,12 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
// Notification for unauthorized people.
api_protect_course_script(true);
$nameTools = get_lang('ForumCategories');
$origin = api_get_origin();
$_user = api_get_user_info();
/* Including necessary files */
require_once 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
@ -167,7 +164,6 @@ Event::registerLog($logInfo);
$form = show_add_post_form(
$current_forum,
$forum_setting,
$my_action,
$my_post,
$my_elements

@ -38,8 +38,6 @@ $nameTools = get_lang('ToolForum');
// Are we in a lp ?
$origin = api_get_origin();
/* Including necessary files */
require 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
$userId = api_get_user_id();
@ -433,10 +431,9 @@ if (is_array($threads)) {
$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);
} else {
$newPost = '';
}
$name = api_get_person_name($row['firstname'], $row['lastname']);
@ -478,6 +475,43 @@ if (is_array($threads)) {
);
}
$_user = api_get_user_info($row['user_id']);
$urlImg = api_get_path(WEB_IMG_PATH);
$iconStatus = null;
$isAdmin = UserManager::is_admin($row['user_id']);
$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']
);
}
if ($_user['status'] == 5) {
if ($_user['has_certificates']) {
$iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_graduated.svg" width="22px" height="22px">';
} else {
$iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_student.svg" width="22px" height="22px">';
}
} elseif ($_user['status'] == 1) {
if ($isAdmin) {
$iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_admin.svg" width="22px" height="22px">';
} else {
$iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_teacher.svg" width="22px" height="22px">';
}
}
$html .= '<div class="thumbnail">'.display_user_image($row['user_id'], $name, $origin).'</div>';
$html .= '</div>';
$html .= '<div class="col-md-10">';
@ -488,8 +522,13 @@ if (is_array($threads)) {
'class' => 'title',
]
);
$html .= '<p>'.get_lang('By').' '.$authorName.'</p>';
$html .= '<p>'.api_convert_and_format_date($row['insert_date']).'</p>';
$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(
@ -509,6 +548,7 @@ if (is_array($threads)) {
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="col-md-6">';
$html .= '<div class="row">';
$html .= '<div class="col-md-4">'
@ -532,7 +572,7 @@ if (is_array($threads)) {
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']);
$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'],

@ -28,6 +28,9 @@ require_once __DIR__.'/../inc/global.inc.php';
Session::erase('_gid');
// Notification for unauthorized people.
api_protect_course_script(true);
$htmlHeadXtra[] = '<script>
$(document).ready(function(){
$(\'.hide-me\').slideUp()
@ -42,18 +45,15 @@ function hidecontent(content){
$this_section = SECTION_COURSES;
// Notification for unauthorized people.
api_protect_course_script(true);
// 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;
// Including necessary files
require 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
// Are we in a lp ?
@ -436,7 +436,7 @@ if ($action != 'add') {
$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 .= api_convert_and_format_date($forum['last_post_date'])
$html .= Display::dateToStringAgoAndLongDate($forum['last_post_date'])
.' '.get_lang('By').' '
.display_user_link($poster_id, $name);
}
@ -483,7 +483,7 @@ if ($action != 'add') {
}
}
if (!api_is_anonymous()) {
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, get_lang('NotifyMe')).
'</a>';

@ -1,187 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @deprecated?
*
* @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');
// Including necessary files.
require 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
$htmlHeadXtra[] = '<script language="javascript">
$(document).ready(function(){ $(\'.hide-me\').slideUp() });
function hidecontent(content){
$(content).slideToggle(\'normal\');
}
</script>';
// Are we in a lp ?
$origin = api_get_origin();
/* 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.
$current_thread = get_thread_information($_GET['forum'], $_GET['thread']);
$current_forum = get_forum_information($current_thread['forum_id']);
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
$whatsnew_post_info = $_SESSION['whatsnew_post_info'];
if (api_is_in_gradebook()) {
$interbreadcrumb[] = [
'url' => Category::getUrl(),
'name' => get_lang('ToolGradebook'),
];
}
if ($origin == 'learnpath') {
Display::display_reduced_header();
} else {
$interbreadcrumb[] = [
'url' => 'index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(urlencode($_GET['search'])),
'name' => $nameTools,
];
$interbreadcrumb[] = [
'url' => 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$current_forum_category['cat_id'].'&search='.Security::remove_XSS(urlencode($_GET['search'])),
'name' => prepare4display($current_forum_category['cat_title']),
];
$interbreadcrumb[] = [
'url' => 'viewforum.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&search='.Security::remove_XSS(urlencode($_GET['search'])),
'name' => prepare4display($current_forum['forum_title']),
];
// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
Display :: display_header('');
api_display_tool_title($nameTools);
}
/* 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);
}
/* Actions */
if ($_GET['action'] == 'delete' &&
isset($_GET['content']) &&
isset($_GET['id']) && api_is_allowed_to_edit(false, true)
) {
$message = delete_post($_GET['id']);
}
if (($_GET['action'] == 'invisible' || $_GET['action'] == 'visible') &&
isset($_GET['id']) && api_is_allowed_to_edit(false, true)
) {
$message = approve_post($_GET['id'], $_GET['action']);
}
if ($_GET['action'] == 'move' && isset($_GET['post'])) {
$message = move_post_form();
}
/* Display the action messages */
if (!empty($message)) {
echo Display::return_message(get_lang($message), 'confirm');
}
// In this case the first and only post of the thread is removed.
if ($message != 'PostDeletedSpecial') {
// This increases the number of times the thread has been viewed.
increase_thread_view($_GET['thread']);
/* Action Links */
echo '<div style="float:right;">';
$my_url = '<a href="viewthread.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&search='.Security::remove_XSS(urlencode($_GET['search']));
echo $my_url.'&view=flat">'.get_lang('FlatView').'</a> | ';
echo $my_url.'&view=threaded">'.get_lang('ThreadedView').'</a> | ';
echo $my_url.'&view=nested">'.get_lang('NestedView').'</a>';
$my_url = null;
echo '</div>';
// 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
echo '<a href="reply.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&action=replythread">'.get_lang('ReplyToThread').'</a>';
// new thread link
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) {
echo '&nbsp;&nbsp;';
/*echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).$origin_string.'">'.Display::return_icon('new_thread.png','','',ICON_SIZE_MEDIUM).'</a>';*/
} else {
echo get_lang('ForumLocked');
}
}
}
}
// Note: This is to prevent that some browsers display the links over the table (FF does it but Opera doesn't).
echo '&nbsp;';
/* Display Forum Category and the Forum information */
if (!$_SESSION['view']) {
$viewmode = $current_forum['default_view'];
} else {
$viewmode = $_SESSION['view'];
}
$viewmode_whitelist = ['flat', 'threaded', 'nested'];
if (isset($_GET['view']) && in_array($_GET['view'], $viewmode_whitelist)) {
$viewmode = Database::escape_string($_GET['view']);
$_SESSION['view'] = $viewmode;
}
if (empty($viewmode)) {
$viewmode = 'flat';
}
/* 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
echo "<table class=\"data_table\" width=\"100%\">\n";
// The thread
echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
if ($origin != 'learnpath') {
echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
}
echo prepare4display($current_forum['forum_title']).'<br />';
echo "</th>\n";
echo "\t</tr>\n";
echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
echo "</table>";
include_once 'viewpost.inc.php';
}
if ($origin != 'learnpath') {
Display :: display_footer();
}

@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CForumPost;
/**
* @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
*
@ -14,7 +16,6 @@ $this_section = SECTION_COURSES;
// Notification for unauthorized people.
api_protect_course_script(true);
require_once 'forumconfig.inc.php';
require_once 'forumfunction.inc.php';
$nameTools = get_lang('Forum');
@ -25,6 +26,8 @@ $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;
/* MAIN DISPLAY SECTION */
/* Retrieving forum and forum category information */
@ -32,7 +35,7 @@ $my_search = null;
// 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($_GET['forum'], $_GET['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']);
@ -68,6 +71,73 @@ $(function() {
</script>';
/* Actions */
$my_action = isset($_GET['action']) ? $_GET['action'] : '';
$logInfo = [
'tool' => TOOL_FORUM,
'tool_id' => $forumId,
'tool_id_detail' => $threadId,
'action' => !empty($my_action) ? $my_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='.intval($threadId);
switch ($my_action) {
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'], $_GET['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)));
}
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(),
@ -78,44 +148,41 @@ if (!empty($groupId)) {
'name' => get_lang('GroupSpace').' '.$group_properties['name'],
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq()."&search=".Security::remove_XSS(urlencode($my_search)),
'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='.intval($_GET['forum']).'&'.api_get_cidreq().'&thread='.intval($_GET['thread']),
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&'.api_get_cidreq().'&thread='.intval($threadId),
'name' => Security::remove_XSS($current_thread['thread_title']),
];
Display::display_header('');
} else {
$my_search = isset($_GET['search']) ? $_GET['search'] : '';
if ($origin == 'learnpath') {
Display::display_reduced_header();
} else {
if ($origin != 'learnpath') {
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(urlencode($my_search)),
'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(
urlencode($my_search)
),
'name' => $nameTools,
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id']."&search=".Security::remove_XSS(urlencode($my_search)),
'url' => api_get_path(
WEB_CODE_PATH
).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id']."&search=".Security::remove_XSS(
urlencode($my_search)
),
'name' => Security::remove_XSS($current_forum_category['cat_title']),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.intval($_GET['forum'])."&search=".Security::remove_XSS(urlencode($my_search)),
'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']),
'name' => Security::remove_XSS($current_thread['thread_title']),
];
$message = isset($message) ? $message : '';
// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
Display::display_header('');
}
}
/* 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) &&
@ -124,61 +191,20 @@ if (!api_is_allowed_to_edit(false, true) &&
api_not_allowed(false);
}
increase_thread_view($threadId);
/* Actions */
$my_action = isset($_GET['action']) ? $_GET['action'] : '';
$logInfo = [
'tool' => TOOL_FORUM,
'tool_id' => $_GET['forum'],
'tool_id_detail' => $_GET['thread'],
'action' => !empty($my_action) ? $my_action : 'view-thread',
'action_details' => isset($_GET['content']) ? $_GET['content'] : '',
];
Event::registerLog($logInfo);
if ($my_action == 'delete' &&
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']);
}
if (($my_action == 'invisible' || $my_action == 'visible') &&
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'], $_GET['action']);
}
if ($my_action == 'move' && isset($_GET['post'])) {
$message = move_post_form();
}
/* Display the action messages */
$my_message = isset($message) ? $message : '';
if ($my_message) {
echo Display::return_message(get_lang($my_message), 'confirm');
if ($origin == 'learnpath') {
$template = new Template('', false, false, true, true, false);
} else {
$template = new Template();
}
if ($my_message != 'PostDeletedSpecial') {
// in this case the first and only post of the thread is removed
// this increases the number of times the thread has been viewed
increase_thread_view($_GET['thread']);
/* Action Links */
if ($origin == 'learnpath') {
echo '<div style="height:15px">&nbsp;</div>';
}
echo '<div class="actions">';
echo '<span style="float:right;">'.search_link().'</span>';
$actions = '<span style="float:right;">'.search_link().'</span>';
if ($origin != 'learnpath') {
echo '<a href="'.$forumUrl.'viewforum.php?forum='
.intval($_GET['forum']).'&'.api_get_cidreq().'">'
$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.
@ -192,9 +218,8 @@ if ($my_message != 'PostDeletedSpecial') {
if ($_user['user_id'] || ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) {
// reply link
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
echo '<a href="'.$forumUrl.'reply.php?'.api_get_cidreq().'&forum='
.intval($_GET['forum']).'&thread='
.intval($_GET['thread']).'&action=replythread">'
$actions .= '<a href="'.$forumUrl.'reply.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='
.intval($threadId).'&action=replythread">'
.Display::return_icon('reply_thread.png', get_lang('ReplyToThread'), '', ICON_SIZE_MEDIUM)
.'</a>';
}
@ -207,9 +232,9 @@ if ($my_message != 'PostDeletedSpecial') {
($current_forum['allow_new_threads'] == 1 && !isset($_user['user_id']) && $current_forum['allow_anonymous'] == 1)
) {
if ($current_forum['locked'] != 1 && $current_forum['locked'] != 1) {
echo '&nbsp;&nbsp;';
$actions .= '&nbsp;&nbsp;';
} else {
echo get_lang('ForumLocked');
$actions .= get_lang('ForumLocked');
}
}
}
@ -217,19 +242,20 @@ if ($my_message != 'PostDeletedSpecial') {
// The different views of the thread.
if ($origin != 'learnpath') {
$my_url = '<a href="'.$forumUrl.'viewthread.php?'.api_get_cidreq().'&'.api_get_cidreq()
.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread'])
/*$actions .= '<a href="'.$forumUrl.'viewthread.php?'.api_get_cidreq().'&'.api_get_cidreq()
.'&forum='.intval($forumId).'&thread='.intval($threadId)
.'&search='.Security::remove_XSS(urlencode($my_search));
echo $my_url.'&view=flat">'
.Display::return_icon('forum_listview.png', get_lang('FlatView'), null, ICON_SIZE_MEDIUM)
.'</a>';
/*
echo $my_url.'&view=nested">'
.Display::return_icon('forum_nestedview.png', get_lang('NestedView'), null, ICON_SIZE_MEDIUM)
.'</a>';
.'</a>';*/
}
$my_url = null;
echo '</div>&nbsp;';
$template->assign('forum_actions', $actions);
$template->assign('origin', api_get_origin());
/* Display Forum Category and the Forum information */
if (!isset($_SESSION['view'])) {
@ -243,26 +269,418 @@ if ($my_message != 'PostDeletedSpecial') {
$viewMode = $_GET['view'];
$_SESSION['view'] = $viewMode;
}
if (empty($viewMode)) {
$viewMode = 'flat';
}
if ($current_thread['thread_peer_qualify'] == 1) {
echo Display::return_message(get_lang('ForumThreadPeerScoringStudentComment'), 'info');
Display::addFlash(Display::return_message(get_lang('ForumThreadPeerScoringStudentComment'), 'info'));
}
switch ($viewMode) {
case 'threaded':
case 'nested':
include_once 'viewthread_nested.inc.php';
break;
case 'flat':
default:
include_once 'viewthread_flat.inc.php';
break;
$allowReport = reportAvailable();
// Are we in a lp ?
$origin = api_get_origin();
//delete attachment file
if (isset($_GET['action']) &&
$_GET['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') {
Display::display_footer();
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);
$urlImg = api_get_path(WEB_IMG_PATH);
$iconStatus = null;
$isAdmin = UserManager::is_admin($posterId);
if ($_user['status'] == 5) {
if ($_user['has_certificates']) {
$iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_graduated.svg" width="22px" height="22px">';
} else {
$iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_student.svg" width="22px" height="22px">';
}
} else {
if ($_user['status'] == 1) {
if ($isAdmin) {
$iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_admin.svg" width="22px" height="22px">';
} else {
$iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_teacher.svg" width="22px" height="22px">';
}
}
}
$post['user_data'] .= '<div class="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 {
$languageId = api_get_language_id(strtolower($revision));
$languageInfo = api_get_language_info($languageId);
if ($languageInfo) {
$languages = getLanguageListForFlag();
$flagRevision = '<span class="flag-icon flag-icon-'.$languages[$languageInfo['english_name']].'"></span> ';
$postIsARevision = true;
}
}
} else {
if (postNeedsRevision($post['post_id'])) {
$askForRevision = giveRevisionButton($post['post_id'], $current_thread);
} else {
$revision = getPostRevision($post['post_id']);
if (!empty($revision)) {
$languageId = api_get_language_id(strtolower($revision));
$languageInfo = api_get_language_info($languageId);
if ($languageInfo) {
$languages = getLanguageListForFlag();
$flagRevision = '<span class="flag-icon flag-icon-'.$languages[$languageInfo['english_name']].'"></span> ';
$postIsARevision = true;
}
}
}
}
$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;
}
// 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_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'] .= '&nbsp;&nbsp;<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);
$layout = $template->get_template('forum/posts.tpl');
$template->display($layout);

@ -1,364 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script manages the display of forum threads in flat view.
*
* @copyright Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
*
* @package chamilo.forum
*/
// Delete attachment file
if ((isset($_GET['action']) &&
$_GET['action'] == 'delete_attach') &&
isset($_GET['id_attach'])
) {
delete_attachment(0, $_GET['id_attach']);
}
// Are we in a lp ?
$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');
if (isset($current_thread['thread_id'])) {
$rows = getPosts($current_forum, $current_thread['thread_id'], $sortDirection);
$increment = 0;
$clean_forum_id = intval($_GET['forum']);
$clean_thread_id = intval($_GET['thread']);
$locked = api_resource_is_locked_by_gradebook(
$clean_thread_id,
LINK_FORUM_THREAD
);
$buttonReply = '';
$buttonQuote = '';
$closedPost = '';
if (!empty($rows)) {
$postCount = count($rows);
foreach ($rows as $row) {
$posterId = isset($row['user_id']) ? $row['user_id'] : 0;
$name = '';
if (empty($posterId)) {
$name = prepare4display($row['poster_name']);
} else {
if (isset($row['complete_name'])) {
$name = $row['complete_name'];
}
}
$username = '';
if (isset($row['username'])) {
$username = sprintf(get_lang('LoginX'), $row['username']);
}
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() && $current_forum['allow_anonymous'] == 1) ||
(!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' => $clean_forum_id,
'thread' => $clean_thread_id,
'post' => $row['post_id'],
'action' => 'replymessage',
]),
'reply',
'primary',
['id' => "reply-to-post-{$row['post_id']}"]
);
$buttonQuote = Display::toolbarButton(
get_lang('QuoteMessage'),
'reply.php?'.api_get_cidreq().'&'.http_build_query([
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'post' => $row['post_id'],
'action' => 'quote',
]),
'quote-left',
'success',
['id' => "quote-post-{$row['post_id']}"]
);
}
}
} else {
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']
);
}
}
$html = '';
$html .= '<div class="panel panel-default forum-post">';
$html .= '<div class="panel-body">';
$html .= '<div class="row">';
$html .= '<div class="col-md-2">';
if ($origin != 'learnpath') {
if (api_get_course_setting('allow_user_image_forum')) {
$html .= '<div class="thumbnail">'.display_user_image($posterId, $name, $origin).'</div>';
}
$html .= Display::tag(
'h4',
display_user_link($posterId, $name),
['class' => 'title-username']
);
} else {
if (api_get_course_setting('allow_user_image_forum')) {
$html .= '<div class="thumbnail">'.display_user_image($posterId, $name, $origin).'</div>';
}
$name = Display::tag('strong', "#".$postCount--, ['class' => 'text-info'])." | $name";
$html .= Display::tag(
'p',
$name,
[
'title' => api_htmlentities($username, ENT_QUOTES),
'class' => 'lead',
]
);
}
if ($origin != 'learnpath') {
$html .= Display::tag(
'p',
Display::dateToStringAgoAndLongDate($row['post_date']),
['class' => 'post-date']
);
} else {
$html .= Display::tag(
'p',
Display::dateToStringAgoAndLongDate($row['post_date']),
['class' => 'text-muted']
);
}
// get attach id
$attachment_list = get_attachment($row['post_id']);
$id_attach = !empty($attachment_list) ? $attachment_list['iid'] : '';
$iconEdit = '';
$statusIcon = '';
// 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
$groupInfo = GroupManager::get_group_properties($groupId);
if ((isset($groupInfo['iid']) && GroupManager::is_tutor_of_group($userId, $groupInfo)) ||
($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 (api_is_allowed_to_session_edit(false, true)) {
if ($locked == false && postIsEditableByStudent($current_forum, $row)) {
$iconEdit .= "<a href=\"editpost.php?".api_get_cidreq()."&forum=".$clean_forum_id
."&thread=".$clean_thread_id."&post=".$row['post_id']
."&edit=edition&id_attach=".$id_attach."\">"
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL)."</a>";
}
}
}
if ($origin != 'learnpath') {
if (GroupManager::is_tutor_of_group($userId, $groupInfo) ||
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' => $clean_forum_id,
'thread' => $clean_thread_id,
'action' => 'delete',
'content' => 'post',
'id' => $row['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-{$row['post_id']}",
]
);
}
}
$statusIcon = getPostStatus($current_forum, $row);
if (GroupManager::is_tutor_of_group($userId, $groupInfo) ||
(
api_is_allowed_to_edit(false, true) &&
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
)
) {
$iconEdit .= return_visible_invisible_icon(
'post',
$row['post_id'],
$row['visible'],
[
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'origin' => $origin,
]
);
if ($increment > 0) {
$iconEdit .= "<a href=\"viewthread.php?".api_get_cidreq()."&forum=".$clean_forum_id
."&thread=".$clean_thread_id."&action=move&post=".$row['post_id']."\">"
.Display::return_icon('move.png', get_lang('MovePost'), [], ICON_SIZE_SMALL)
."</a>";
}
}
}
$user_status = api_get_status_of_user_in_course($posterId, api_get_course_int_id());
$current_qualify_thread = showQualify('1', $row['poster_id'], $_GET['thread']);
if (($current_thread['thread_peer_qualify'] == 1 || api_is_allowed_to_edit(null, true)) &&
$current_thread['thread_qualify_max'] > 0 && $origin != 'learnpath'
) {
$my_forum_id = $clean_forum_id;
$info_thread = get_thread_information($clean_forum_id, $clean_thread_id);
$my_forum_id = $info_thread['forum_id'];
$userCanEdit = $current_thread['thread_peer_qualify'] == 1 && $row['poster_id'] != $userId;
/*if ($row['poster_id'] != $userId && $current_forum['moderated'] == 1 && $row['status']) {
}*/
if (api_is_allowed_to_edit(null, true)) {
$userCanEdit = true;
}
if ($increment > 0 && $locked == false && $userCanEdit) {
$iconEdit .= "<a href=\"forumqualify.php?".api_get_cidreq()."&forum=".$my_forum_id
."&thread=".$clean_thread_id."&action=list&post=".$row['post_id']
."&user=".$row['poster_id']."&user_id=".$row['poster_id']
."&idtextqualify=".$current_qualify_thread."\" >"
.Display::return_icon('quiz.png', get_lang('Qualify'))
."</a> ";
}
}
if (!empty($iconEdit)) {
$html .= '<div class="tools-icons">'.$iconEdit.' '.$statusIcon.'</div>';
} else {
if (!empty(strip_tags($statusIcon))) {
$html .= '<div class="tools-icons">'.$statusIcon.'</div>';
}
}
$html .= $closedPost;
$html .= '</div>';
$html .= '<div class="col-md-10">';
$titlePost = Display::tag(
'h3',
$row['post_title'],
['class' => 'forum_post_title']
);
$html .= Display::tag(
'div',
$titlePost,
['class' => 'post-header']
);
// see comments inside forumfunction.inc.php to lower filtering and allow more visual changes
$html .= Display::tag(
'div',
$row['post_text'],
['class' => 'post-body']
);
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="row">';
$html .= '<div class="col-md-7">';
// prepare the notification icon
if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]) &&
!empty(
$whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]
) &&
!empty($whatsnew_post_info[$_GET['forum']][$row['thread_id']])
) {
$post_image = Display::return_icon('forumpostnew.gif');
} else {
$post_image = Display::return_icon('forumpost.gif');
}
if ($row['post_notification'] == '1' && $row['poster_id'] == $userId) {
$post_image .= Display::return_icon('forumnotification.gif', get_lang('YouWillBeNotified'));
}
// The post title
// The check if there is an attachment
$attachment_list = getAllAttachment($row['post_id']);
if (!empty($attachment_list) && is_array($attachment_list)) {
foreach ($attachment_list as $attachment) {
$realname = $attachment['path'];
$user_filename = $attachment['filename'];
$html .= Display::return_icon('attachment.gif', get_lang('Attachment'));
$html .= '<a href="download.php?file='.$realname.'"> '.$user_filename.' </a>';
if (($current_forum['allow_edit'] == 1 && $posterId == $userId) ||
(api_is_allowed_to_edit(false, true) &&
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
) {
$html .= '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete_attach&id_attach='
.$attachment['iid'].'&forum='.$clean_forum_id.'&thread='.$clean_thread_id
.'" onclick="javascript:if(!confirm(\''
.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))
.'\')) return false;">'
.Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL)
.'</a><br />';
}
$html .= '<span class="forum_attach_comment" >'.$attachment['comment'].'</span>';
}
}
$html .= '</div>';
$html .= '<div class="col-md-5 text-right">';
$html .= $buttonReply.' '.$buttonQuote;
$html .= '</div>';
$html .= '</div>';
// 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']][$row['post_id']]);
unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']]);
unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']]);
$increment++;
$html .= '</div>';
$html .= '</div>';
echo $html;
}
}
}

@ -1,366 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CForumPost;
/**
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
* @copyright Ghent University
*
* @package chamilo.forum
*/
// Are we in a lp ?
$origin = api_get_origin();
//delete attachment file
if (isset($_GET['action']) &&
$_GET['action'] == 'delete_attach' &&
isset($_GET['id_attach'])
) {
delete_attachment(0, $_GET['id_attach']);
}
// 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, $_GET['thread'], $sortDirection, true);
$count = 0;
$clean_forum_id = intval($_GET['forum']);
$clean_thread_id = intval($_GET['thread']);
$group_id = api_get_group_id();
$locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREAD);
$sessionId = api_get_session_id();
$currentThread = get_thread_information($clean_forum_id, $_GET['thread']);
$userId = api_get_user_id();
$groupInfo = GroupManager::get_group_properties($group_id);
$postCount = 1;
$allowUserImageForum = api_get_course_setting('allow_user_image_forum');
foreach ($posts as $post) {
$posterId = isset($post['user_id']) ? $post['user_id'] : 0;
// The style depends on the status of the message: approved or not.
if ($post['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';
}
$indent = $post['indent_cnt'];
$html = '';
$html .= '<div class="col-md-offset-'.$indent.'" >';
$html .= '<div class="panel panel-default forum-post">';
$html .= '<div class="panel-body">';
$html .= '<div class="row">';
$html .= '<div class="col-md-2">';
$username = '';
if (isset($post['username'])) {
$username = sprintf(get_lang('LoginX'), $post['username']);
}
if (empty($posterId)) {
$name = $post['poster_name'];
} else {
$name = $post['complete_name'];
}
if ($origin != 'learnpath') {
if ($allowUserImageForum) {
$html .= '<div class="thumbnail">'.display_user_image($posterId, $name, $origin).'</div>';
}
$html .= Display::tag(
'h4',
display_user_link($posterId, $name, $origin, $username),
['class' => 'title-username']
);
} else {
if ($allowUserImageForum) {
$html .= '<div class="thumbnail">'.display_user_image($posterId, $name, $origin).'</div>';
}
$html .= Display::tag(
'p',
$name,
[
'title' => api_htmlentities($username, ENT_QUOTES),
'class' => 'lead',
]
);
}
if ($origin != 'learnpath') {
$html .= Display::tag(
'p',
Display::dateToStringAgoAndLongDate($post['post_date']),
['class' => 'post-date']
);
} else {
$html .= 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 = '';
// 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);
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=$clean_forum_id&thread=$clean_thread_id&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' => $clean_forum_id,
'thread' => $clean_thread_id,
'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' => $clean_forum_id,
'thread' => $clean_thread_id,
]
);
if ($count > 0) {
$iconEdit .= "<a href=\"viewthread.php?".api_get_cidreq()
."&forum=$clean_forum_id&thread=$clean_thread_id&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;
}
if (empty($currentThread['thread_qualify_max'])) {
$userCanQualify = false;
}
if ($userCanQualify) {
if ($count > 0) {
$current_qualify_thread = showQualify(
'1',
$posterId,
$_GET['thread']
);
if ($locked == false) {
$iconEdit .= "<a href=\"forumqualify.php?".api_get_cidreq()
."&forum=$clean_forum_id&thread=$clean_thread_id&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>";
}
}
}
$statusIcon = getPostStatus($current_forum, $post);
if (!empty($iconEdit)) {
$html .= '<div class="tools-icons">'.$iconEdit.' '.$statusIcon.'</div>';
} else {
if (!empty(strip_tags($statusIcon))) {
$html .= '<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' => $clean_forum_id,
'thread' => $clean_thread_id,
'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' => $clean_forum_id,
'thread' => $clean_thread_id,
'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']
);
}
$html .= $closedPost;
}
$html .= '</div>';
// 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[$_GET['forum']][$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')
);
}
$html .= '<div class="col-md-10">';
// The post title
$titlePost = Display::tag('h3', $post['post_title'], ['class' => 'forum_post_title']);
$html .= Display::tag('div', $titlePost, ['class' => 'post-header']);
// the post body
$html .= Display::tag('div', $post['post_text'], ['class' => 'post-body']);
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="row">';
$html .= '<div class="col-md-6">';
// The check if there is an attachment
$attachment_list = getAllAttachment($post['post_id']);
if (!empty($attachment_list) && is_array($attachment_list)) {
foreach ($attachment_list as $attachment) {
$user_filename = $attachment['filename'];
$html .= Display::return_icon('attachment.gif', get_lang('Attachment'));
$html .= '<a href="download.php?file=';
$html .= $attachment['path'];
$html .= ' "> '.$user_filename.' </a>';
$html .= '<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))
) {
$html .= '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete_attach&id_attach='
.$attachment['iid'].'&forum='.$clean_forum_id.'&thread='.$clean_thread_id
.'" onclick="javascript:if(!confirm(\''
.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;">'
.Display::return_icon('delete.gif', get_lang('Delete')).'</a><br />';
}
}
}
$html .= '</div>';
$html .= '<div class="col-md-6 text-right">';
$html .= "$editButton $buttonReply $buttonQuote $waitingValidation";
$html .= '</div>';
$html .= '</div>';
// 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']]);
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
echo $html;
$count++;
}

@ -1588,6 +1588,12 @@ function _api_format_user($user, $add_password = false, $loadAvatars = true)
$result['profile_url'] = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_id;
$hasCertificates = Certificate::getCertificateByUser($user_id);
$result['has_certificates'] = 0;
if (!empty($hasCertificates)) {
$result['has_certificates'] = 1;
}
// Send message link
$sendMessage = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&user_id='.$user_id;
$result['complete_name_with_message_link'] = Display::url(

@ -842,4 +842,24 @@ class Certificate extends Model
false
);
}
/**
* @param int $userId
*
* @return array
*/
public static function getCertificateByUser($userId)
{
$userId = (int) $userId;
if (empty($userId)) {
return [];
}
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql = "SELECT * FROM $table
WHERE user_id= $userId";
$rs = Database::query($sql);
return Database::store_result($rs, 'ASSOC');
}
}

@ -1,90 +1,157 @@
{% extends "@ChamiloTheme/Layout/layout_one_col.html.twig" %}
{% import '@ChamiloTheme/Macros/box.html.twig' as macro %}
{% import '@ChamiloTheme/Macros/box.html.twig' as display %}
{% block content %}
{% autoescape false %}
{% if 'translate_html'|api_get_configuration_value %}
<script>
$(function () {
// default
$('.category-forum ').hide();
{{ form_content }}
<div class="accordion forum" id="accordion-forum">
{% if data is not empty %}
{% for item in data %}
<div class="card">
<h5 class="card-header" id="heading-{{ item.id }}">
<div class="float-actions">
{{ item.tools }}
</div>
<a href="#" data-toggle="collapse" class="btn btn-link" data-target="#collapse-{{ item.id }}" aria-expanded="true" aria-controls="collapse-{{ item.id }}">
{{ 'forum_blue.png'|img(32) }}
</a>
<a href="{{ item.url }}" title="{{ item.title }}">{{ item.title }}{{ item.icon_session }}</a>
</h5>
<div id="collapse-{{ item.id }}" class="collapse show" aria-labelledby="heading-{{ item.id }}" data-parent="#accordion-forum">
<div class="card-body">
{% if default_user_language %}
$('.{{ default_user_language }}').show();
{% endif %}
$('#extra_language').attr('data-width', '200px');
$('#extra_language option[value=""]').text('{{ 'Any' | get_lang | escape('js') }}');
$('#extra_language').on('change', function() {
var selectedLanguageArray = $(this).val();
$('.category-forum ').hide();
$.each(selectedLanguageArray, function(index, selectedLanguage) {
if (selectedLanguage == '') {
$('.category-forum ').show();
} else {
$('.'+ selectedLanguage).show();
}
});
});
});
</script>
{% endif %}
{{ form_content }}
{{ search_filter }}
{% set fold_forum_categories = 'forum_fold_categories'|api_get_configuration_value %}
{% if data is not empty %}
{% for item in data %}
{% set category_language_array = [] %}
{% set category_language = '' %}
{% for extra_field in item.extra_fields %}
{% if extra_field.variable == 'language' %}
{% set category_language_array = extra_field.value | split(';') %}
{% set category_language = extra_field.value | replace({';': ' ' }) %}
{% endif %}
{% endfor %}
<div class="forum-description">
{{ item.description }}
{% if fold_forum_categories %}
{% set panel_icon %}
<a href="{{ item.url }}" title="{{ item.title }}">
<span class="open">{{ 'forum_blue.png'|img(32) }}</span>
</a>
{% endset %}
{% set panel_title %}
{{ item.title }}{{ item.icon_session }}
{% endset %}
{% else %}
{% set panel_title %}
<a href="{{ item.url }}" title="{{ item.title }}">
<span class="open">{{ 'forum_blue.png'|img(32) }}</span>
{{ item.title }}{{ item.icon_session }}
</a>
<div class="pull-right">
{{ item.tools }}
</div>
{% for subitem in item.forums %}
{% set content %}
<div class="d-flex flex-row bd-highlight mb-3">
<div class="p-2 bd-highlight">
<div class="avatar">
<img src="{{ subitem.avatar }}" width="32px" class="rounded-circle">
</div>
</div>
<div class="p-2 bd-highlight">
<h4 class="title">
<a href="{{ subitem.url }}" title="{{ subitem.title }}" class="{{ subitem.visibility != '1' ? 'text-muted': '' }}">{{ subitem.title }}</a>
{% if subitem.forum_of_group != 0 %}
<a class="forum-goto" href="../group/group_space.php?{{ _p.web_cid_query }}&gidReq={{ subitem.forum_of_group }}">
{{ "forum.png"|img(22) }} {{ "GoTo"|get_lang }} {{ subitem.forum_group_title }}
{% endset %}
{% endif %}
{% set panel_content %}
<div class="forum-description">
{{ item.description }}
</div>
{% for subitem in item.forums %}
<div class="forum_display">
<div class="panel panel-default forum">
<div class="panel-body">
<div class="row">
<div class="col-xs-4 col-md-3">
<div class="number-post">
<a href="{{ forum.url }}" title="{{forum.title}}">
{% if subitem.forum_image is not empty %}
<img src="{{ subitem.forum_image }}" width="48px">
{% else %}
{% if subitem.forum_of_group == 0 %}
{{ 'forum_group.png'|img(48) }}
{% else %}
{{ 'forum.png'|img(48) }}
{% endif %}
{% endif %}
</a>
{% endif %}
{{ subitem.icon_session }}
<div class="float-right">
<p>{{ 'ForumThreads'| get_lang }}: {{ subitem.number_threads }} </p>
</div>
</div>
<div class="col-xs-8 col-md-9">
<div class="pull-right">
<div class="toolbar">
{{ subitem.tools }}
</div>
</div>
</h4>
<ul class="forum-threads">
<li class="threads">{{ 'ForumThreads'| get_lang }}: {{ subitem.number_threads }} </li>
<h3 class="title">
{{ 'forum_yellow.png'|img(32) }}
<a href="{{ subitem.url }}" title="{{ subitem.title }}" class="{{ subitem.visibility != '1' ? 'text-muted': '' }}">{{ subitem.title }}</a>
{% if subitem.forum_of_group != 0 %}
<a class="forum-goto" href="../group/group_space.php?{{ _p.web_cid_query }}&gidReq={{ subitem.forum_of_group }}">
{{ "forum.png"|img(22) }} {{ "GoTo"|get_lang }} {{ subitem.forum_group_title }}
</a>
{% endif %}
{{ subitem.icon_session }}
</h3>
{% if subitem.last_poster_id is not empty %}
<li class="date">
<div class="forum-date">
<i class="fa fa-comments" aria-hidden="true"></i>
{{ subitem.last_poster_date }}
« {{ subitem.last_post_title }} »
{{ "By"|get_lang }}
{{ subitem.last_poster_user }}
</li>
</div>
{% endif %}
</ul>
<div class="description">
{{ subitem.description }}
</div>
{{ subitem.last_post_text }}
{{ subitem.alert }}
{% if subitem.moderation is not empty %}
<span class="label label-warning">
{{ "PostsPendingModeration"|get_lang }}: {{ subitem.moderation }}
</span>
{% endif %}
</div>
</div>
</div>
<div class="description">
{{ subitem.description }}
</div>
{{ subitem.alert }}
{% if subitem.moderation is not empty %}
<span class="label label-warning">
{{ "PostsPendingModeration"|get_lang }}: {{ subitem.moderation }}
</span>
{% endif %}
{% endset %}
{% set forum_id = 'forum-'~ subitem.id %}
<div class="list-forum">
{{ macro.panel_box(forum_id,'', content ) }}
</div>
{% endfor %}
</div>
</div>
{% endfor %}
{% endset %}
<div class="category-forum {{ category_language }}" id="category_{{ item.id }}">
{% if fold_forum_categories %}
{{ display.collapse('category_' ~ item.id, panel_title, panel_content, false, fold_forum_categories, item.tools, panel_icon ) }}
{% else %}
{{ display.panel(panel_title, panel_content) }}
{% endif %}
</div>
</div>
{% endfor %}
{% endfor %}
{% else %}
<div class="alert alert-warning">
{{ 'NoForumInThisCategory'|get_lang }}
</div>
{% endif %}
</div>
{% endautoescape %}
{% endblock %}

@ -0,0 +1,59 @@
{% extends "@ChamiloTheme/Layout/layout_one_col.html.twig" %}
{% import '@ChamiloTheme/Macros/box.html.twig' as display %}
{% block content %}
{% autoescape false %}
{% if origin == 'learnpath' %}
<div style="height:15px">&nbsp;</div>
{% endif %}
{% if forum_actions %}
<div class="actions">
{{ forum_actions }}
</div>
{% endif %}
{% for post in posts %}
{% set post_data %}
<div class="row">
<div class="col-md-2">
{{ post.user_data }}
</div>
{% set highlight = '' %}
{% if post.current %}
{% set highlight = 'alert alert-danger' %}
{% endif %}
{% set highlight_revision = '' %}
{% if post.is_a_revision %}
{% set highlight_revision = 'forum_revision' %}
{% endif %}
<div class="col-md-10 {{ highlight }} ">
{{ post.post_title }}
{% if post.is_a_revision %}
{{ 'ProposedRevision' | get_lang }} {{ post.flag_revision }}
{% endif %}
<div class="{{ highlight_revision }} ">
{{ post.post_data }}
</div>
{{ post.post_attachments }}
</div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-8 text-right">
{{ post.post_buttons }}
</div>
</div>
{% endset %}
<div class="col-md-offset-{{ post.indent_cnt }} forum-post">
{{ display.panel('', post_data ) }}
</div>
{% endfor %}
{% endautoescape %}
{% endblock %}

@ -54,16 +54,27 @@
</li>
{% endmacro %}
{% macro collapse(name, title, content, list = false, expanded = 'true') %}
{% macro collapse(name, title, content, list = false, expanded = 'true', title_right = '', title_icons = '') %}
{% autoescape false %}
<div class="panel-group" id="{{ name }}" role="tablist" aria-multiselectable="true">
<div class="panel panel-default" id="{{ name }}_block">
<div class="panel-heading" role="tab">
{% if title_icons %}
{{ title_icons }}
{% endif %}
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#{{ name }}" href="#{{ name }}Collapse" aria-expanded="{{ expanded }}" aria-controls="{{ name }}Collapse">
{{ title }}
</a>
</h4>
{% if title_right %}
<div class="pull-right">
{{ title_right }}
</div>
{% endif %}
</div>
<div style="" aria-expanded="{{ expanded }}" id="{{ name }}Collapse" class="panel-collapse collapse {{ expanded == 'true' ? 'in' : '' }}" role="tabpanel">
<div class="panel-body">

Loading…
Cancel
Save