viewpost.php 7.8 KB

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