function check_unzip() { if (document.upload.unzip.checked){ document.upload.if_exists[0].disabled=true; document.upload.if_exists[1].checked=true; document.upload.if_exists[2].disabled=true; } else { document.upload.if_exists[0].checked=true; document.upload.if_exists[0].disabled=false; document.upload.if_exists[2].disabled=false; } } function setFocus() { $("#title_file").focus(); } '; // The next javascript script is to manage ajax upload file $htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']); // Recover Thread ID, will be used to generate delete attachment URL to do ajax $threadId = isset($_REQUEST['thread']) ? (int) ($_REQUEST['thread']) : 0; $forumId = isset($_REQUEST['forum']) ? (int) ($_REQUEST['forum']) : 0; $ajaxUrl = api_get_path(WEB_AJAX_PATH).'forum.ajax.php?'.api_get_cidreq(); // The next javascript script is to delete file by ajax $htmlHeadXtra[] = ''; $nameTools = get_lang('Forum'); $forumUrl = api_get_path(WEB_CODE_PATH).'forum/'; // Are we in a lp ? $origin = api_get_origin(); $_user = api_get_user_info(); $my_search = null; $moveForm = ''; $forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0; $postId = isset($_GET['post_id']) ? $_GET['post_id'] : 0; $threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0; $repo = Container::getForumRepository(); $forumEntity = null; if (!empty($forumId)) { /** @var CForum $forumEntity */ $forumEntity = $repo->find($forumId); } $repoThread = Container::getForumThreadRepository(); /** @var CForumThread $threadEntity */ $threadEntity = $repoThread->find($threadId); if (empty($threadEntity)) { $url = api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId; header('Location: '.$url); exit; } $repoPost = Container::getForumPostRepository(); $postEntity = null; if (!empty($postId)) { /** @var CForumPost $postEntity */ $postEntity = $repoPost->find($postId); } $courseEntity = api_get_course_entity(api_get_course_int_id()); $sessionEntity = api_get_session_entity(api_get_session_id()); $current_forum_category = $forumEntity->getForumCategory(); $whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null; if (api_is_in_gradebook()) { $interbreadcrumb[] = [ 'url' => Category::getUrl(), 'name' => get_lang('Assessments'), ]; } $groupId = api_get_group_id(); $groupEntity = null; if (!empty($groupId)) { $groupEntity = api_get_group_entity($groupId); } $sessionId = api_get_session_id(); $ajaxURL = api_get_path(WEB_AJAX_PATH).'forum.ajax.php?'.api_get_cidreq().'&a=change_post_status'; $htmlHeadXtra[] = ''; $my_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='.$threadId; switch ($my_action) { case 'delete_attach': delete_attachment($_GET['post'], $_GET['id_attach']); header('Location: '.$currentUrl); exit; break; case 'delete': if ( isset($_GET['content']) && isset($_GET['id']) && (api_is_allowed_to_edit(false, true) || ($groupEntity && GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity))) ) { /** @var CForumPost $postEntity */ $postEntity = $repoPost->find($_GET['id']); deletePost($postEntity); } header('Location: '.$currentUrl); exit; break; case 'invisible': case 'visible': if (isset($_GET['id']) && (api_is_allowed_to_edit(false, true) || ($groupEntity && GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity))) ) { /** @var CForumPost $postEntity */ $postEntity = $repoPost->find($_GET['id']); $message = approvePost($postEntity, $_GET['action']); Display::addFlash(Display::return_message(get_lang($message))); } header('Location: '.$currentUrl); exit; break; case 'move': if (isset($_GET['post'])) { $form = move_post_form(); // Validation or display if ($form->validate()) { $values = $form->exportValues(); store_move_post($values); $currentUrl = api_get_path(WEB_CODE_PATH). 'forum/viewthread.php?forum='.$forumId.'&'.api_get_cidreq().'&thread='.$threadId; header('Location: '.$currentUrl); exit; } else { $moveForm = $form->returnForm(); } } break; case 'report': $result = reportPost($postEntity, $forumEntity, $threadEntity); 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')) { $result = savePostRevision($postEntity); Display::addFlash(Display::return_message(get_lang('Saved.'))); } header('Location: '.$currentUrl); exit; break; } if (!empty($groupId)) { $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'name' => get_lang('Groups'), ]; $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), 'name' => get_lang('Group area').' '.$groupEntity->getName(), ]; $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq().'&search='.Security::remove_XSS(urlencode($my_search)), 'name' => Security::remove_XSS($forumEntity->getForumTitle()), ]; $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&'.api_get_cidreq().'&thread='.$threadId, 'name' => Security::remove_XSS($threadEntity->getThreadTitle()), ]; } else { $my_search = isset($_GET['search']) ? $_GET['search'] : ''; if ('learnpath' != $origin) { $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search='.Security::remove_XSS( urlencode($my_search) ), 'name' => $nameTools, ]; $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH). 'forum/index.php?forumcategory='.$current_forum_category->getIid().'&search='.Security::remove_XSS( urlencode($my_search) ), 'name' => Security::remove_XSS($current_forum_category->getCatTitle()), ]; $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId.'&search='.Security::remove_XSS(urlencode($my_search)), 'name' => Security::remove_XSS($forumEntity->getForumTitle()), ]; $interbreadcrumb[] = [ 'url' => '#', 'name' => Security::remove_XSS($threadEntity->getThreadTitle()), ]; } } // 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) && ( !$forumEntity->isVisible($courseEntity, $sessionEntity) || !$threadEntity->isVisible($courseEntity, $sessionEntity) ) ) { api_not_allowed(); } // this increases the number of times the thread has been viewed increase_thread_view($threadId); if ('learnpath' === $origin) { $template = new Template('', false, false, true, true, false); } else { $template = new Template(); } $actions = ''.search_link().''; if ('learnpath' != $origin) { $actions .= '' .Display::return_icon('back.png', get_lang('Back to forum'), '', 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. if (($current_forum_category && 0 == $current_forum_category->getLocked()) && 0 == $forumEntity->getLocked() && 0 == $threadEntity->getLocked() || 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'] || (1 == $forumEntity->getAllowAnonymous() && !$_user['user_id'])) { // reply link if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) { $actions .= '' .Display::return_icon('reply_thread.png', get_lang('Reply to this thread'), '', ICON_SIZE_MEDIUM) .''; } // new thread link if (( api_is_allowed_to_edit(false, true) && !(api_is_session_general_coach())) || //&& $forumEntity->getSessionId() != $sessionId (1 == $forumEntity->getAllowNewThreads() && isset($_user['user_id'])) || (1 == $forumEntity->getAllowNewThreads() && !isset($_user['user_id']) && 1 == $forumEntity->getAllowAnonymous()) ) { if (1 != $forumEntity->getLocked() && 1 != $forumEntity->getLocked()) { $actions .= ' '; } else { $actions .= get_lang('Forum blocked'); } } } } $actions = Display::toolbarAction('toolbar', [$actions]); $template->assign('forum_actions', $actions); $template->assign('origin', api_get_origin()); /* Display Forum Category and the Forum information */ if (!isset($_SESSION['view'])) { $viewMode = $forumEntity->getDefaultView(); } else { $viewMode = $_SESSION['view']; } $whiteList = ['flat', 'threaded', 'nested']; if (isset($_GET['view']) && in_array($_GET['view'], $whiteList)) { $viewMode = $_GET['view']; $_SESSION['view'] = $viewMode; } if (empty($viewMode)) { $viewMode = 'flat'; } if ($threadEntity->isThreadPeerQualify()) { Display::addFlash(Display::return_message(get_lang('To get the expected score in this forum, your contribution will have to be scored by another student, and you will have to score at least 2 other student\'s contributions. Until you reach this objective, even if scored, your contribution will show as a 0 score in the global grades for this course.'), 'info')); } $allowReport = reportAvailable(); $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']) && 'desc' === $_GET['posts_order'] ? 'DESC' : ('learnpath' != $origin ? 'ASC' : 'DESC'); $posts = getPosts($forumEntity, $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(); $userId = api_get_user_id(); $postCount = 1; $allowUserImageForum = api_get_course_setting('allow_user_image_forum'); $tutorGroup = false; $groupEntity = null; if (!empty($group_id)) { $groupEntity = api_get_group_entity($group_id); // 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::isTutorOfGroup(api_get_user_id(), $groupEntity); } $postList = []; foreach ($posts as $post) { /** @var CForumPost $postEntity */ $postEntity = $post['entity']; $posterId = isset($post['user_id']) ? $post['user_id'] : 0; $username = ''; if (isset($post['username'])) { $username = sprintf(get_lang('Login: %s'), $post['username']); } /*$name = $post['complete_name']; if (empty($posterId)) { $name = $post['poster_name']; }*/ $post['user_data'] = ''; $post['author'] = $postEntity->getUser(); $posterId = $postEntity->getUser()->getId(); /*if ('learnpath' !== $origin) { if ($allowUserImageForum) { $post['user_data'] = '