viewthread.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
  5. * @package chamilo.forum
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $current_course_tool = TOOL_FORUM;
  9. $this_section = SECTION_COURSES;
  10. // Notification for unauthorized people.
  11. api_protect_course_script(true);
  12. require_once 'forumconfig.inc.php';
  13. require_once 'forumfunction.inc.php';
  14. $nameTools = get_lang('Forum');
  15. $forumUrl = api_get_path(WEB_CODE_PATH).'forum/';
  16. // Are we in a lp ?
  17. $origin = api_get_origin();
  18. $my_search = null;
  19. /* MAIN DISPLAY SECTION */
  20. /* Retrieving forum and forum category information */
  21. // We are getting all the information about the current forum and forum category.
  22. // Note pcool: I tried to use only one sql statement (and function) for this,
  23. // but the problem is that the visibility of the forum AND forum category are stored in the item_property table.
  24. // Note: This has to be validated that it is an existing thread
  25. $current_thread = get_thread_information($_GET['forum'], $_GET['thread']);
  26. // Note: This has to be validated that it is an existing forum.
  27. $current_forum = get_forum_information($current_thread['forum_id']);
  28. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  29. $whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
  30. if (api_is_in_gradebook()) {
  31. $interbreadcrumb[] = array(
  32. 'url' => Category::getUrl(),
  33. 'name' => get_lang('ToolGradebook')
  34. );
  35. }
  36. $groupId = api_get_group_id();
  37. $group_properties = GroupManager::get_group_properties($groupId);
  38. $sessionId = api_get_session_id();
  39. $ajaxURL = api_get_path(WEB_AJAX_PATH).'forum.ajax.php?'.api_get_cidreq().'&a=change_post_status';
  40. $htmlHeadXtra[] = '<script>
  41. $(function() {
  42. $("span").on("click", ".change_post_status", function() {
  43. var updateDiv = $(this).parent();
  44. var postId = updateDiv.attr("id");
  45. $.ajax({
  46. url: "'.$ajaxURL.'&post_id="+postId,
  47. type: "GET",
  48. success: function(data) {
  49. updateDiv.html(data);
  50. }
  51. });
  52. });
  53. });
  54. </script>';
  55. if (!empty($groupId)) {
  56. $interbreadcrumb[] = array(
  57. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  58. 'name' => get_lang('Groups')
  59. );
  60. $interbreadcrumb[] = array(
  61. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  62. 'name' => get_lang('GroupSpace').' '.$group_properties['name']
  63. );
  64. $interbreadcrumb[] = array(
  65. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq()."&search=".Security::remove_XSS(urlencode($my_search)),
  66. 'name' => Security::remove_XSS($current_forum['forum_title'])
  67. );
  68. $interbreadcrumb[] = array(
  69. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq().'&thread='.intval($_GET['thread']),
  70. 'name' => Security::remove_XSS($current_thread['thread_title'])
  71. );
  72. Display::display_header('');
  73. } else {
  74. $my_search = isset($_GET['search']) ? $_GET['search'] : '';
  75. if ($origin == 'learnpath') {
  76. Display::display_reduced_header();
  77. } else {
  78. $interbreadcrumb[] = array(
  79. 'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(urlencode($my_search)),
  80. 'name' => $nameTools
  81. );
  82. $interbreadcrumb[] = array(
  83. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id']."&search=".Security::remove_XSS(urlencode($my_search)),
  84. 'name' => Security::remove_XSS($current_forum_category['cat_title'])
  85. );
  86. $interbreadcrumb[] = array(
  87. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.intval($_GET['forum'])."&search=".Security::remove_XSS(urlencode($my_search)),
  88. 'name' => Security::remove_XSS($current_forum['forum_title'])
  89. );
  90. $interbreadcrumb[] = array(
  91. 'url' => '#', 'name' => Security::remove_XSS($current_thread['thread_title'])
  92. );
  93. $message = isset($message) ? $message : '';
  94. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  95. Display::display_header('');
  96. }
  97. }
  98. /* Is the user allowed here? */
  99. // If the user is not a course administrator and the forum is hidden
  100. // then the user is not allowed here.
  101. if (!api_is_allowed_to_edit(false, true) &&
  102. ($current_forum['visibility'] == 0 || $current_thread['visibility'] == 0)
  103. ) {
  104. api_not_allowed(false);
  105. }
  106. /* Actions */
  107. $my_action = isset($_GET['action']) ? $_GET['action'] : '';
  108. if ($my_action == 'delete' &&
  109. isset($_GET['content']) &&
  110. isset($_GET['id']) &&
  111. (api_is_allowed_to_edit(false, true) ||
  112. (isset($group_properties['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties)))
  113. ) {
  114. $message = delete_post($_GET['id']);
  115. }
  116. if (($my_action == 'invisible' || $my_action == 'visible') &&
  117. isset($_GET['id']) &&
  118. (api_is_allowed_to_edit(false, true) ||
  119. (isset($group_properties['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties)))
  120. ) {
  121. $message = approve_post($_GET['id'], $_GET['action']);
  122. }
  123. if ($my_action == 'move' && isset($_GET['post'])) {
  124. $message = move_post_form();
  125. }
  126. /* Display the action messages */
  127. $my_message = isset($message) ? $message : '';
  128. if ($my_message) {
  129. echo Display::return_message(get_lang($my_message), 'confirm');
  130. }
  131. if ($my_message != 'PostDeletedSpecial') {
  132. // in this case the first and only post of the thread is removed
  133. // this increases the number of times the thread has been viewed
  134. increase_thread_view($_GET['thread']);
  135. /* Action Links */
  136. if ($origin == 'learnpath') {
  137. echo '<div style="height:15px">&nbsp;</div>';
  138. }
  139. echo '<div class="actions">';
  140. echo '<span style="float:right;">'.search_link().'</span>';
  141. if ($origin != 'learnpath') {
  142. echo '<a href="'.$forumUrl.'viewforum.php?forum='
  143. . intval($_GET['forum']).'&'.api_get_cidreq().'">'
  144. . Display::return_icon('back.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
  145. }
  146. // The reply to thread link should only appear when the forum_category is
  147. // not locked AND the forum is not locked AND the thread is not locked.
  148. // If one of the three levels is locked then the link should not be displayed.
  149. if (($current_forum_category &&
  150. $current_forum_category['locked'] == 0) &&
  151. $current_forum['locked'] == 0 &&
  152. $current_thread['locked'] == 0 ||
  153. api_is_allowed_to_edit(false, true)
  154. ) {
  155. // The link should only appear when the user is logged in or when anonymous posts are allowed.
  156. if ($_user['user_id'] || ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) {
  157. // reply link
  158. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
  159. echo '<a href="'.$forumUrl.'reply.php?'.api_get_cidreq().'&forum='
  160. . intval($_GET['forum']).'&thread='
  161. . intval($_GET['thread']).'&action=replythread">'
  162. . Display::return_icon('reply_thread.png', get_lang('ReplyToThread'), '', ICON_SIZE_MEDIUM)
  163. . '</a>';
  164. }
  165. // new thread link
  166. if ((
  167. api_is_allowed_to_edit(false, true) &&
  168. !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
  169. ) ||
  170. ($current_forum['allow_new_threads'] == 1 && isset($_user['user_id'])) ||
  171. ($current_forum['allow_new_threads'] == 1 && !isset($_user['user_id']) && $current_forum['allow_anonymous'] == 1)
  172. ) {
  173. if ($current_forum['locked'] <> 1 && $current_forum['locked'] <> 1) {
  174. echo '&nbsp;&nbsp;';
  175. } else {
  176. echo get_lang('ForumLocked');
  177. }
  178. }
  179. }
  180. }
  181. // The different views of the thread.
  182. if ($origin != 'learnpath') {
  183. $my_url = '<a href="'.$forumUrl.'viewthread.php?'.api_get_cidreq().'&'.api_get_cidreq()
  184. . '&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread'])
  185. . '&search='.Security::remove_XSS(urlencode($my_search));
  186. echo $my_url.'&view=flat">'
  187. . Display::return_icon('forum_listview.png', get_lang('FlatView'), null, ICON_SIZE_MEDIUM)
  188. . '</a>';
  189. echo $my_url.'&view=nested">'
  190. . Display::return_icon('forum_nestedview.png', get_lang('NestedView'), null, ICON_SIZE_MEDIUM)
  191. . '</a>';
  192. }
  193. $my_url = null;
  194. echo '</div>&nbsp;';
  195. /* Display Forum Category and the Forum information */
  196. if (!isset($_SESSION['view'])) {
  197. $viewMode = $current_forum['default_view'];
  198. } else {
  199. $viewMode = $_SESSION['view'];
  200. }
  201. $whiteList = array('flat', 'threaded', 'nested');
  202. if (isset($_GET['view']) && in_array($_GET['view'], $whiteList)) {
  203. $viewMode = $_GET['view'];
  204. $_SESSION['view'] = $viewMode;
  205. }
  206. if (empty($viewMode)) {
  207. $viewMode = 'flat';
  208. }
  209. if ($current_thread['thread_peer_qualify'] == 1) {
  210. echo Display::return_message(get_lang('ForumThreadPeerScoringStudentComment'), 'info');
  211. }
  212. switch ($viewMode) {
  213. case 'threaded':
  214. //no break;
  215. case 'nested':
  216. include_once 'viewthread_nested.inc.php';
  217. break;
  218. case 'flat':
  219. //no break
  220. default:
  221. include_once 'viewthread_flat.inc.php';
  222. break;
  223. }
  224. }
  225. if ($origin != 'learnpath') {
  226. Display::display_footer();
  227. }