viewthread.php 13 KB

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