viewthread.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. // Are we in a lp ?
  20. $origin = '';
  21. if (isset($_GET['origin'])) {
  22. $origin = Security::remove_XSS($_GET['origin']);
  23. }
  24. /* MAIN DISPLAY SECTION */
  25. /* Retrieving forum and forum categorie information */
  26. // We are getting all the information about the current forum and forum category.
  27. // Note pcool: I tried to use only one sql statement (and function) for this,
  28. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  29. $current_thread = get_thread_information($_GET['thread']); // Nnote: This has to be validated that it is an existing thread
  30. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
  31. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  32. $whatsnew_post_info = $_SESSION['whatsnew_post_info']; // This variable should be deprecated?
  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. if ($origin == 'group') {
  45. $session_toolgroup = intval($_SESSION['toolgroup']);
  46. $group_properties = GroupManager :: get_group_properties($session_toolgroup);
  47. $interbreadcrumb[] = array('url'=>'../group/group.php', 'name' => get_lang('Groups'));
  48. $interbreadcrumb[] = array('url'=>'../group/group_space.php?gidReq='.$session_toolgroup, 'name'=> get_lang('GroupSpace').' '.$group_properties['name']);
  49. $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']));
  50. $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']));
  51. Display :: display_header('');
  52. //api_display_tool_title($nameTools);
  53. } else {
  54. $my_search = isset($_GET['search']) ? $_GET['search'] : '';
  55. if ($origin == 'learnpath') {
  56. Display::display_reduced_header();
  57. } else {
  58. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook.'&amp;search='.Security::remove_XSS(urlencode($my_search)), 'name' => $nameTools);
  59. $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']));
  60. $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']));
  61. $interbreadcrumb[] = array('url' => '#', 'name' => Security::remove_XSS($current_thread['thread_title']));
  62. $message = isset($message) ? $message : '';
  63. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  64. Display :: display_header('');
  65. //api_display_tool_title($nameTools);
  66. }
  67. }
  68. /* Is the user allowed here? */
  69. // If the user is not a course administrator and the forum is hidden
  70. // then the user is not allowed here.
  71. if (!api_is_allowed_to_edit(false, true) AND ($current_forum['visibility'] == 0 OR $current_thread['visibility'] == 0)) {
  72. $forum_allow = forum_not_allowed_here();
  73. if ($forum_allow === false) {
  74. exit;
  75. }
  76. }
  77. /* Actions */
  78. $group_id = api_get_group_id();
  79. $my_action = isset($_GET['action']) ? $_GET['action'] : '';
  80. 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))) {
  81. $message = delete_post($_GET['id']); // Note: This has to be cleaned first.
  82. }
  83. 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))) {
  84. $message = approve_post($_GET['id'], $_GET['action']); // Note: This has to be cleaned first.
  85. }
  86. if ($my_action == 'move' AND isset($_GET['post'])) {
  87. $message = move_post_form();
  88. }
  89. /* Display the action messages */
  90. $my_message = isset($message) ? $message : '';
  91. if ($my_message) {
  92. Display :: display_confirmation_message(get_lang($my_message));
  93. }
  94. if ($my_message != 'PostDeletedSpecial') {
  95. // in this case the first and only post of the thread is removed
  96. // this increases the number of times the thread has been viewed
  97. increase_thread_view($_GET['thread']);
  98. /* Action Links */
  99. if ($origin == 'learnpath') {
  100. echo '<div style="height:15px">&nbsp;</div>';
  101. }
  102. echo '<div class="actions">';
  103. echo '<span style="float:right;">'.search_link().'</span>';
  104. if ($origin != 'learnpath') {
  105. /*if ($origin == 'group') {
  106. echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('Groups'), '', ICON_SIZE_MEDIUM).'</a>';
  107. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'&amp;origin='.$origin.'">'.Display::return_icon('forum.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
  108. } else {
  109. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  110. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'">'.Display::return_icon('forum.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
  111. }*/
  112. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'&amp;origin='.$origin.'">'.Display::return_icon('back.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
  113. }
  114. // 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.
  115. // If one of the three levels is locked then the link should not be displayed.
  116. 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)) {
  117. // The link should only appear when the user is logged in or when anonymous posts are allowed.
  118. if ($_user['user_id'] OR ($current_forum['allow_anonymous'] == 1 AND !$_user['user_id'])) {
  119. // reply link
  120. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
  121. echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&amp;origin='.$origin.'">'.Display::return_icon('reply_thread.png', get_lang('ReplyToThread'), '', ICON_SIZE_MEDIUM).'</a>';
  122. }
  123. // new thread link
  124. 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)) {
  125. if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
  126. echo '&nbsp;&nbsp;';
  127. /* if ( isset($_GET['gradebook']) && $_GET['gradebook'] != '') {
  128. $info_thread = get_thread_information($_GET['thread']);
  129. echo '<a href="newthread.php?'.api_get_cidreq().'&amp;forum='.$info_thread['forum_id'].'&amp;origin='.$origin.'&amp;gradebook='.Security::remove_XSS($_GET['gradebook']).'">'.Display::return_icon('new_thread.png', get_lang('NewTopic'), '', ICON_SIZE_MEDIUM).'</a>';
  130. } else {
  131. echo '<a href="newthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;origin='.$origin.'">'.Display::return_icon('new_thread.png', get_lang('NewTopic'), '', ICON_SIZE_MEDIUM).'</a>';
  132. } */
  133. } else {
  134. echo get_lang('ForumLocked');
  135. }
  136. }
  137. }
  138. }
  139. // The different views of the thread.
  140. if ($origin != 'learnpath') {
  141. $my_url = '<a href="viewthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;search='.Security::remove_XSS(urlencode($my_search));
  142. echo $my_url.'&amp;view=flat&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_listview.gif', get_lang('FlatView')).get_lang('FlatView').'</a>';
  143. echo $my_url.'&amp;view=threaded&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_threadedview.gif', get_lang('ThreadedView')).get_lang('ThreadedView').'</a>';
  144. echo $my_url.'&amp;view=nested&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_nestedview.gif', get_lang('NestedView')).get_lang('NestedView').'</a>';
  145. }
  146. $my_url = null;
  147. echo '</div>&nbsp;';
  148. /* Display Forum Category and the Forum information */
  149. if (!isset($_SESSION['view'])) {
  150. $viewmode = $current_forum['default_view'];
  151. } else {
  152. $viewmode = $_SESSION['view'];
  153. }
  154. $viewmode_whitelist = array('flat', 'threaded', 'nested');
  155. if (isset($_GET['view']) && in_array($_GET['view'], $viewmode_whitelist)) {
  156. $viewmode = $_GET['view'];
  157. $_SESSION['view'] = $viewmode;
  158. }
  159. if (empty($viewmode)) {
  160. $viewmode = 'flat';
  161. }
  162. /* Display Forum Category and the Forum information */
  163. // We are getting all the information about the current forum and forum category.
  164. // Note pcool: I tried to use only one sql statement (and function) for this,
  165. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  166. /*echo '<table class="forum_table_title" width="100%">';
  167. // The thread
  168. echo '<tr><th style="padding:5px;" align="left" colspan="6">';
  169. echo '<div class="forum_title">';
  170. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'&amp;origin='.$origin.'">'.$current_forum['forum_title'].'</a><br />';
  171. echo '<span class="forum_description">';
  172. echo $current_forum['forum_comment'];
  173. echo '</span>';
  174. echo '</div>';
  175. echo '</th></tr>';
  176. echo '</table>';*/
  177. if (isset($_GET['msg']) && isset($_GET['type'])) {
  178. switch($_GET['type']) {
  179. case 'error':
  180. Display::display_error_message($_GET['msg']);
  181. break;
  182. case 'confirmation':
  183. Display::display_confirmation_message($_GET['msg']);
  184. break;
  185. }
  186. }
  187. switch ($viewmode) {
  188. case 'flat':
  189. include_once('viewthread_flat.inc.php');
  190. break;
  191. case 'threaded':
  192. include_once('viewthread_threaded.inc.php');
  193. break;
  194. case 'nested':
  195. include_once('viewthread_nested.inc.php');
  196. break;
  197. default:
  198. include_once('viewthread_flat.inc.php');
  199. break;
  200. }
  201. } // if ($message != 'PostDeletedSpecial') // in this case the first and only post of the thread is removed.
  202. /* FOOTER */
  203. if ($origin != 'learnpath') {
  204. Display :: display_footer();
  205. }