viewthread.php 10 KB

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