viewthread.php 10 KB

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