viewthread.php 9.7 KB

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