diff --git a/main/forum/download.php b/main/forum/download.php index bd7263cbf9..59da5bd80c 100755 --- a/main/forum/download.php +++ b/main/forum/download.php @@ -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(); diff --git a/main/forum/editpost.php b/main/forum/editpost.php index c376d47bbd..921db8ecac 100755 --- a/main/forum/editpost.php +++ b/main/forum/editpost.php @@ -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, diff --git a/main/forum/editthread.php b/main/forum/editthread.php index b7dd040207..db9b8f537f 100644 --- a/main/forum/editthread.php +++ b/main/forum/editthread.php @@ -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', ''); } -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')); } diff --git a/main/forum/forumconfig.inc.php b/main/forum/forumconfig.inc.php deleted file mode 100755 index 4778449a9f..0000000000 --- a/main/forum/forumconfig.inc.php +++ /dev/null @@ -1,50 +0,0 @@ -, 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; diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index 07c9200cbf..1d735c4f3d 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -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[] = ''; - -// 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 '
'; - $my_url = ''.get_lang('FlatView').' | '; - echo $my_url.'&view=threaded">'.get_lang('ThreadedView').' | '; - echo $my_url.'&view=nested">'.get_lang('NestedView').''; - $my_url = null; - echo '
'; - // 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 ''.get_lang('ReplyToThread').''; - - // 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 '  '; - /*echo ''.Display::return_icon('new_thread.png','','',ICON_SIZE_MEDIUM).'';*/ - } 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 ' '; - /* 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 "\n"; - - // The thread - echo "\t\n\t\t\n"; - echo "\t\n"; - echo ''.prepare4display($current_thread['thread_comment']).''; - echo "
"; - echo ''.prepare4display($current_thread['thread_title']).'
'; - - if ($origin != 'learnpath') { - echo ''.prepare4display($current_forum_category['cat_title']).' - '; - } - - echo prepare4display($current_forum['forum_title']).'
'; - echo "
"; - - include_once 'viewpost.inc.php'; -} - -if ($origin != 'learnpath') { - Display :: display_footer(); -} diff --git a/main/forum/viewthread.php b/main/forum/viewthread.php index bf8853cf84..54ccd7459b 100755 --- a/main/forum/viewthread.php +++ b/main/forum/viewthread.php @@ -1,6 +1,8 @@ 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() { '; +/* 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 '
 
'; - } - echo '
'; - echo ''.search_link().''; +$actions = ''.search_link().''; if ($origin != 'learnpath') { - echo '' + $actions .= '' .Display::return_icon('back.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).''; } + // 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 '' + $actions .= '' .Display::return_icon('reply_thread.png', get_lang('ReplyToThread'), '', ICON_SIZE_MEDIUM) .''; } @@ -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 '  '; + $actions .= '  '; } 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 = '' .Display::return_icon('forum_listview.png', get_lang('FlatView'), null, ICON_SIZE_MEDIUM) .''; + /* echo $my_url.'&view=nested">' .Display::return_icon('forum_nestedview.png', get_lang('NestedView'), null, ICON_SIZE_MEDIUM) - .''; + .'';*/ } - $my_url = null; - echo '
 '; +$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'] = '
'. + display_user_image($posterId, $name, $origin).'
'; +} + + $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 = ''; + } else { + $iconStatus = ''; + } + } else { + if ($_user['status'] == 1) { + if ($isAdmin) { + $iconStatus = ''; + } else { + $iconStatus = ''; + } + } + } + + $post['user_data'] .= '
'.$iconStatus.'
'; + } else { + if ($allowUserImageForum) { + $post['user_data'] .= '
'. + display_user_image($posterId, $name, $origin).'
'; + } + + $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 .= "" + .Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL) + .""; + + $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 .= "".Display::return_icon('move.png', get_lang('MovePost'), [], ICON_SIZE_SMALL).""; + } + } + + $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 = ' '; + $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 = ' '; + $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 .= "".Display::return_icon('quiz.png', get_lang('Qualify')).""; + } + } + } + + $reportButton = ''; + if ($allowReport) { + $reportButton = getReportButton($post['post_id'], $current_thread); + } + + $statusIcon = getPostStatus($current_forum, $post); + if (!empty($iconEdit)) { + $post['user_data'] .= "
$iconEdit $statusIcon
"; + } else { + if (!empty(strip_tags($statusIcon))) { + $post['user_data'] .= "
$statusIcon
"; + } + } + + $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', + ' '.get_lang('ForumcategoryLocked'), + ['class' => 'alert alert-warning post-closed'] + ); + } + if ($current_forum['locked'] == 1) { + $closedPost = Display::tag( + 'div', + ' '.get_lang('ForumLocked'), + ['class' => 'alert alert-warning post-closed'] + ); + } + if ($current_thread['locked'] == 1) { + $closedPost = Display::tag( + 'div', + ' '.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'] = ''; + $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'] .= ' '.$user_filename.' '; + $post['post_attachments'] .= ''.$attachment['comment'].''; + 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'] .= '  ' + .Display::return_icon('delete.png', get_lang('Delete')).'
'; + } + } + } + + $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); diff --git a/main/forum/viewthread_flat.inc.php b/main/forum/viewthread_flat.inc.php deleted file mode 100755 index 3527291a66..0000000000 --- a/main/forum/viewthread_flat.inc.php +++ /dev/null @@ -1,364 +0,0 @@ - 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', - ' '.get_lang('ForumcategoryLocked'), - ['class' => 'alert alert-warning post-closed'] - ); - } - if ($current_forum['locked'] == 1) { - $closedPost = Display::tag( - 'div', - ' '.get_lang('ForumLocked'), - ['class' => 'alert alert-warning post-closed'] - ); - } - if ($current_thread['locked'] == 1) { - $closedPost = Display::tag( - 'div', - ' '.get_lang('ThreadLocked'), - ['class' => 'alert alert-warning post-closed'] - ); - } - } - - $html = ''; - $html .= '
'; - $html .= '
'; - $html .= '
'; - $html .= '
'; - - if ($origin != 'learnpath') { - if (api_get_course_setting('allow_user_image_forum')) { - $html .= '
'.display_user_image($posterId, $name, $origin).'
'; - } - $html .= Display::tag( - 'h4', - display_user_link($posterId, $name), - ['class' => 'title-username'] - ); - } else { - if (api_get_course_setting('allow_user_image_forum')) { - $html .= '
'.display_user_image($posterId, $name, $origin).'
'; - } - $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 .= "" - .Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).""; - } - } - } - - 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 .= "" - .Display::return_icon('move.png', get_lang('MovePost'), [], ICON_SIZE_SMALL) - .""; - } - } - } - - $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 .= "" - .Display::return_icon('quiz.png', get_lang('Qualify')) - ." "; - } - } - - if (!empty($iconEdit)) { - $html .= '
'.$iconEdit.' '.$statusIcon.'
'; - } else { - if (!empty(strip_tags($statusIcon))) { - $html .= '
'.$statusIcon.'
'; - } - } - $html .= $closedPost; - $html .= '
'; - $html .= '
'; - - $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 .= '
'; - $html .= '
'; - - $html .= '
'; - $html .= '
'; - - // 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 .= ' '.$user_filename.' '; - - 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 .= '  ' - .Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL) - .'
'; - } - $html .= ''.$attachment['comment'].''; - } - } - - $html .= '
'; - $html .= '
'; - $html .= $buttonReply.' '.$buttonQuote; - $html .= '
'; - $html .= '
'; - - // 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 .= '
'; - $html .= '
'; - echo $html; - } - } -} diff --git a/main/forum/viewthread_nested.inc.php b/main/forum/viewthread_nested.inc.php deleted file mode 100755 index 932410039f..0000000000 --- a/main/forum/viewthread_nested.inc.php +++ /dev/null @@ -1,366 +0,0 @@ -, Ghent University - * @author Julio Montoya 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 .= '
'; - $html .= '
'; - $html .= '
'; - $html .= '
'; - $html .= '
'; - $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 .= '
'.display_user_image($posterId, $name, $origin).'
'; - } - - $html .= Display::tag( - 'h4', - display_user_link($posterId, $name, $origin, $username), - ['class' => 'title-username'] - ); - } else { - if ($allowUserImageForum) { - $html .= '
'.display_user_image($posterId, $name, $origin).'
'; - } - - $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 .= "" - .Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL) - .""; - - $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 .= "".Display::return_icon('move.png', get_lang('MovePost'), [], ICON_SIZE_SMALL).""; - } - } - - $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 .= "".Display::return_icon('quiz.png', get_lang('Qualify')).""; - } - } - } - - $statusIcon = getPostStatus($current_forum, $post); - if (!empty($iconEdit)) { - $html .= '
'.$iconEdit.' '.$statusIcon.'
'; - } else { - if (!empty(strip_tags($statusIcon))) { - $html .= '
'.$statusIcon.'
'; - } - } - - $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', - ' '.get_lang('ForumcategoryLocked'), - ['class' => 'alert alert-warning post-closed'] - ); - } - if ($current_forum['locked'] == 1) { - $closedPost = Display::tag( - 'div', - ' '.get_lang('ForumLocked'), - ['class' => 'alert alert-warning post-closed'] - ); - } - if ($current_thread['locked'] == 1) { - $closedPost = Display::tag( - 'div', - ' '.get_lang('ThreadLocked'), - ['class' => 'alert alert-warning post-closed'] - ); - } - - $html .= $closedPost; - } - $html .= '
'; - - // 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 .= '
'; - // 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 .= '
'; - $html .= '
'; - - $html .= '
'; - $html .= '
'; - // 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 .= ' '.$user_filename.' '; - $html .= ''.$attachment['comment'].''; - 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 .= '  ' - .Display::return_icon('delete.gif', get_lang('Delete')).'
'; - } - } - } - - $html .= '
'; - $html .= '
'; - $html .= "$editButton $buttonReply $buttonQuote $waitingValidation"; - $html .= '
'; - $html .= '
'; - - // 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 .= '
'; - $html .= '
'; - $html .= '
'; - - echo $html; - $count++; -} diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index b9ab875568..9b7adbebe0 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -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( diff --git a/main/inc/lib/certificate.lib.php b/main/inc/lib/certificate.lib.php index 6e97b89c69..20a92fd98e 100755 --- a/main/inc/lib/certificate.lib.php +++ b/main/inc/lib/certificate.lib.php @@ -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'); + } } diff --git a/main/template/default/forum/list.html.twig b/main/template/default/forum/list.html.twig index 045bc619b5..ffcd5681a1 100644 --- a/main/template/default/forum/list.html.twig +++ b/main/template/default/forum/list.html.twig @@ -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 %} + + {% 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 %} -
- {{ item.description }} + {% if fold_forum_categories %} + {% set panel_icon %} + + {{ 'forum_blue.png'|img(32) }} + + {% endset %} + + {% set panel_title %} + {{ item.title }}{{ item.icon_session }} + {% endset %} + {% else %} + {% set panel_title %} + + {{ 'forum_blue.png'|img(32) }} + {{ item.title }}{{ item.icon_session }} + +
+ {{ item.tools }}
- {% for subitem in item.forums %} - {% set content %} -
-
-
- -
-
-
-

- {{ subitem.title }} - {% if subitem.forum_of_group != 0 %} - - {{ "forum.png"|img(22) }} {{ "GoTo"|get_lang }} {{ subitem.forum_group_title }} + {% endset %} + {% endif %} + + {% set panel_content %} +
+ {{ item.description }} +
+ {% for subitem in item.forums %} +

-
{% endif %} - +
+ {{ subitem.description }} +
+ + {{ subitem.last_post_text }} + + {{ subitem.alert }} + {% if subitem.moderation is not empty %} + + {{ "PostsPendingModeration"|get_lang }}: {{ subitem.moderation }} + + {% endif %} +
-
- {{ subitem.description }} -
- {{ subitem.alert }} - - {% if subitem.moderation is not empty %} - - {{ "PostsPendingModeration"|get_lang }}: {{ subitem.moderation }} - - {% endif %} - {% endset %} - {% set forum_id = 'forum-'~ subitem.id %} -
- {{ macro.panel_box(forum_id,'', content ) }}
- {% endfor %} - + + {% endfor %} + {% endset %} + +
+ {% 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 %}
- - {% endfor %} + {% endfor %} {% else %}
{{ 'NoForumInThisCategory'|get_lang }}
{% endif %} - {% endautoescape %} {% endblock %} diff --git a/main/template/default/forum/posts.html.twig b/main/template/default/forum/posts.html.twig new file mode 100644 index 0000000000..ce975d567f --- /dev/null +++ b/main/template/default/forum/posts.html.twig @@ -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' %} +
 
+ {% endif %} + + {% if forum_actions %} +
+ {{ forum_actions }} +
+ {% endif %} + + {% for post in posts %} + {% set post_data %} +
+
+ {{ post.user_data }} +
+ {% 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 %} + +
+ {{ post.post_title }} + + {% if post.is_a_revision %} + {{ 'ProposedRevision' | get_lang }} {{ post.flag_revision }} + {% endif %} + +
+ {{ post.post_data }} +
+ + {{ post.post_attachments }} +
+
+
+
+
+ {{ post.post_buttons }} +
+
+ {% endset %} + +
+ {{ display.panel('', post_data ) }} +
+ {% endfor %} + {% endautoescape %} +{% endblock %} diff --git a/src/ThemeBundle/Resources/views/Macros/box.html.twig b/src/ThemeBundle/Resources/views/Macros/box.html.twig index 2527f32348..4e2fb688fe 100644 --- a/src/ThemeBundle/Resources/views/Macros/box.html.twig +++ b/src/ThemeBundle/Resources/views/Macros/box.html.twig @@ -54,16 +54,27 @@ {% 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 %}