viewpost.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.forum
  5. */
  6. // Language file that needs to be included.
  7. $language_file = 'forum';
  8. // Including the global initialization file.
  9. require_once '../inc/global.inc.php';
  10. // The section (tabs).
  11. $this_section = SECTION_COURSES;
  12. // Notification for unauthorized people.
  13. api_protect_course_script(true);
  14. $nameTools = get_lang('ToolForum');
  15. // Including necessary files.
  16. require 'forumconfig.inc.php';
  17. require_once 'forumfunction.inc.php';
  18. $htmlHeadXtra[] = '<script language="javascript">
  19. $(document).ready(function(){ $(\'.hide-me\').slideUp() });
  20. function hidecontent(content){ $(content).slideToggle(\'normal\'); }
  21. </script>';
  22. // Are we in a lp ?
  23. $origin = '';
  24. if (isset($_GET['origin'])) {
  25. $origin = Security::remove_XSS($_GET['origin']);
  26. }
  27. /* MAIN DISPLAY SECTION */
  28. /* Retrieving forum and forum categorie 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. $current_thread = get_thread_information($_GET['thread']); // Note: This has to be validated that it is an existing thread.
  33. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
  34. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  35. $whatsnew_post_info = $_SESSION['whatsnew_post_info'];
  36. /* Header and Breadcrumbs */
  37. if (isset($_SESSION['gradebook'])){
  38. $gradebook = $_SESSION['gradebook'];
  39. }
  40. if (!empty($gradebook) && $gradebook == 'view') {
  41. $interbreadcrumb[] = array (
  42. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  43. 'name' => get_lang('ToolGradebook')
  44. );
  45. }
  46. if ($origin == 'learnpath') {
  47. Display::display_reduced_header();
  48. } else {
  49. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook.'&amp;search='.Security::remove_XSS(urlencode($_GET['search'])), 'name' => $nameTools);
  50. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&amp;search='.Security::remove_XSS(urlencode($_GET['search'])), 'name' => prepare4display($current_forum_category['cat_title']));
  51. $interbreadcrumb[] = array('url' => 'viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;origin='.$origin.'&amp;search='.Security::remove_XSS(urlencode($_GET['search'])), 'name' => prepare4display($current_forum['forum_title']));
  52. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  53. Display :: display_header('');
  54. api_display_tool_title($nameTools);
  55. }
  56. /* Is the user allowed here? */
  57. // if the user is not a course administrator and the forum is hidden
  58. // then the user is not allowed here.
  59. if (!api_is_allowed_to_edit(false, true) AND ($current_forum['visibility'] == 0 OR $current_thread['visibility'] == 0)) {
  60. $forum_allow = forum_not_allowed_here();
  61. if ($forum_allow === false) {
  62. exit;
  63. }
  64. }
  65. /* Actions */
  66. if ($_GET['action'] == 'delete' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false, true)) {
  67. $message = delete_post($_GET['id']); // Note: This has to be cleaned first.
  68. }
  69. if (($_GET['action'] == 'invisible' || $_GET['action'] == 'visible') && isset($_GET['id']) && api_is_allowed_to_edit(false, true)) {
  70. $message = approve_post($_GET['id'], $_GET['action']); // Note: This has to be cleaned first.
  71. }
  72. if ($_GET['action'] == 'move' && isset($_GET['post'])) {
  73. $message = move_post_form();
  74. }
  75. /* Display the action messages */
  76. if (!empty($message)) {
  77. Display :: display_confirmation_message(get_lang($message));
  78. }
  79. if ($message != 'PostDeletedSpecial') { // In this case the first and only post of the thread is removed.
  80. // This increases the number of times the thread has been viewed.
  81. increase_thread_view($_GET['thread']);
  82. /* Action Links */
  83. echo '<div style="float:right;">';
  84. $my_url = '<a href="viewthread.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;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;search='.Security::remove_XSS(urlencode($_GET['search']));
  85. echo $my_url.'&amp;view=flat&amp;origin='.$origin.'">'.get_lang('FlatView').'</a> | ';
  86. echo $my_url.'&amp;view=threaded&amp;origin='.$origin.'">'.get_lang('ThreadedView').'</a> | ';
  87. echo $my_url.'&amp;view=nested&amp;origin='.$origin.'">'.get_lang('NestedView').'</a>';
  88. $my_url = null;
  89. echo '</div>';
  90. // 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.
  91. // If one of the three levels is locked then the link should not be displayed.
  92. 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)) {
  93. // The link should only appear when the user is logged in or when anonymous posts are allowed.
  94. if ($_user['user_id'] OR ($current_forum['allow_anonymous'] == 1 AND !$_user['user_id'])) {
  95. // reply link
  96. 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.'">'.get_lang('ReplyToThread').'</a>';
  97. // new thread link
  98. if (api_is_allowed_to_edit(false, true) 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)) {
  99. if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
  100. echo '&nbsp;&nbsp;';
  101. /*echo '<a href="newthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).$origin_string.'">'.Display::return_icon('new_thread.png','','',ICON_SIZE_MEDIUM).'</a>';*/
  102. } else {
  103. echo get_lang('ForumLocked');
  104. }
  105. }
  106. }
  107. }
  108. // Note: This is to prevent that some browsers display the links over the table (FF does it but Opera doesn't).
  109. echo '&nbsp;';
  110. /* Display Forum Category and the Forum information */
  111. if (!$_SESSION['view']) {
  112. $viewmode = $current_forum['default_view'];
  113. } else {
  114. $viewmode = $_SESSION['view'];
  115. }
  116. $viewmode_whitelist=array('flat', 'threaded', 'nested');
  117. if (isset($_GET['view']) && in_array($_GET['view'], $viewmode_whitelist)) {
  118. $viewmode = Database::escape_string($_GET['view']);
  119. $_SESSION['view'] = $viewmode;
  120. }
  121. if (empty($viewmode)) {
  122. $viewmode = 'flat';
  123. }
  124. /* Display Forum Category and the Forum information */
  125. // we are getting all the information about the current forum and forum category.
  126. // note pcool: I tried to use only one sql statement (and function) for this
  127. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  128. echo "<table class=\"data_table\" width=\"100%\">\n";
  129. // The thread
  130. echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
  131. echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
  132. if ($origin!='learnpath') {
  133. echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
  134. }
  135. echo prepare4display($current_forum['forum_title']).'<br />';
  136. echo "</th>\n";
  137. echo "\t</tr>\n";
  138. echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
  139. echo "</table>";
  140. include_once('viewpost.inc.php');
  141. } // if ($message != 'PostDeletedSpecial') // In this case the first and only post of the thread is removed.
  142. /* FOOTER */
  143. if ($origin != 'learnpath') {
  144. Display :: display_footer();
  145. }