viewthread.php 9.8 KB

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