viewpost.php 9.3 KB

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