viewthread.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  5. * @Copyright Ghent University
  6. * @Copyright Patrick Cool
  7. *
  8. * @package dokeos.forum
  9. */
  10. // name of the language file that needs to be included
  11. $language_file = array ('forum','group');
  12. // including the global dokeos file
  13. require_once '../inc/global.inc.php';
  14. // the section (tabs)
  15. $this_section=SECTION_COURSES;
  16. // notice for unauthorized people.
  17. api_protect_course_script(true);
  18. // including additional library scripts
  19. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  20. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  21. require_once 'forumconfig.inc.php';
  22. require_once 'forumfunction.inc.php';
  23. $nameTools=get_lang('ToolForum');
  24. //are we in a lp ?
  25. $origin = '';
  26. if (isset($_GET['origin'])) {
  27. $origin = Security::remove_XSS($_GET['origin']);
  28. }
  29. /*
  30. ==============================================================================
  31. MAIN DISPLAY SECTION
  32. ==============================================================================
  33. */
  34. /*
  35. -----------------------------------------------------------
  36. Retrieving forum and forum categorie information
  37. -----------------------------------------------------------
  38. */
  39. // we are getting all the information about the current forum and forum category.
  40. // note pcool: I tried to use only one sql statement (and function) for this
  41. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  42. $current_thread = get_thread_information($_GET['thread']); // note: this has to be validated that it is an existing thread
  43. $current_forum = get_forum_information($current_thread['forum_id']); // note: this has to be validated that it is an existing forum.
  44. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  45. $whatsnew_post_info = $_SESSION['whatsnew_post_info']; //this variable should be deprecated?
  46. /*
  47. -----------------------------------------------------------
  48. Header and Breadcrumbs
  49. -----------------------------------------------------------
  50. */
  51. if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
  52. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  53. $gradebook= $_SESSION['gradebook'];
  54. }
  55. if (!empty($gradebook) && $gradebook=='view') {
  56. $interbreadcrumb[] = array (
  57. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  58. 'name' => get_lang('ToolGradebook')
  59. );
  60. }
  61. if (!empty($_SESSION['toolgroup'])) {
  62. $session_toolgroup = intval($_SESSION['toolgroup']);
  63. $group_properties = GroupManager :: get_group_properties($session_toolgroup);
  64. $interbreadcrumb[] = array("url"=>"../group/group.php", "name" => get_lang('Groups'));
  65. $interbreadcrumb[] = array("url"=>"../group/group_space.php?gidReq=".$session_toolgroup, "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  66. $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" => prepare4display($current_forum['forum_title']));
  67. $interbreadcrumb[] = array("url"=>"viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
  68. Display :: display_header('');
  69. api_display_tool_title($nameTools);
  70. } else {
  71. $my_search=isset($_GET['search']) ? $_GET['search'] : '';
  72. if ($origin=='learnpath') {
  73. require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
  74. } else {
  75. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS(urlencode($my_search)),"name" => $nameTools);
  76. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => prepare4display($current_forum_category['cat_title']));
  77. $interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => prepare4display($current_forum['forum_title']));
  78. $message = isset($message) ? $message : '';
  79. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  80. Display :: display_header('');
  81. api_display_tool_title($nameTools);
  82. }
  83. }
  84. /*
  85. -----------------------------------------------------------
  86. Is the user allowed here?
  87. -----------------------------------------------------------
  88. */
  89. // if the user is not a course administrator and the forum is hidden
  90. // then the user is not allowed here.
  91. if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
  92. $forum_allow = forum_not_allowed_here();
  93. if ($forum_allow === false) {
  94. exit;
  95. }
  96. }
  97. /*
  98. -----------------------------------------------------------
  99. Actions
  100. -----------------------------------------------------------
  101. */
  102. $my_action = isset($_GET['action']) ? $_GET['action'] : '';
  103. if ($my_action=='delete' AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit(false,true)) {
  104. $message=delete_post($_GET['id']); // note: this has to be cleaned first
  105. }
  106. if (($my_action=='invisible' OR $my_action=='visible') AND isset($_GET['id']) AND api_is_allowed_to_edit(false,true)) {
  107. $message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
  108. }
  109. if ($my_action=='move' AND isset($_GET['post'])) {
  110. $message=move_post_form();
  111. }
  112. /*
  113. -----------------------------------------------------------
  114. Display the action messages
  115. -----------------------------------------------------------
  116. */
  117. $my_message = isset($message) ? $message : '';
  118. if ($my_message) {
  119. Display :: display_confirmation_message(get_lang($my_message));
  120. }
  121. if ($my_message<>'PostDeletedSpecial') {
  122. // in this case the first and only post of the thread is removed
  123. // this increases the number of times the thread has been viewed
  124. increase_thread_view($_GET['thread']);
  125. /*
  126. -----------------------------------------------------------
  127. Action Links
  128. -----------------------------------------------------------
  129. */
  130. if ($origin=='learnpath') {
  131. echo '<div style="height:15px">&nbsp;</div>';
  132. }
  133. echo '<div class="actions">';
  134. echo '<span style="float:right;">'.search_link().'</span>';
  135. if ($origin != 'learnpath') {
  136. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview')).' '.get_lang('BackToForumOverview').'</a>';
  137. echo '<a href="viewforum.php?&forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'">'.Display::return_icon('forum.gif',get_lang('BackToForum')).' '.get_lang('BackToForum').'</a>';
  138. }
  139. // 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.
  140. // if one of the three levels is locked then the link should not be displayed
  141. if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
  142. // The link should only appear when the user is logged in or when anonymous posts are allowed.
  143. if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
  144. //reply link
  145. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
  146. 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.'">'.Display::return_icon('forumthread_new.gif',get_lang('ReplyToThread')).get_lang('ReplyToThread').'</a>';
  147. }
  148. //new thread link
  149. 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)) {
  150. if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
  151. echo '&nbsp;&nbsp;';
  152. /* if ( isset($_GET['gradebook']) && $_GET['gradebook']!=""){
  153. $info_thread=get_thread_information($_GET['thread']);
  154. echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.$info_thread['forum_id'].'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'">'.Display::return_icon('forumthread_new.gif', get_lang('NewTopic')).' '.get_lang('NewTopic').'</a>';
  155. } else {
  156. echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'">'.Display::return_icon('forumthread_new.gif', get_lang('NewTopic')).' '.get_lang('NewTopic').'</a>';
  157. } */
  158. } else {
  159. echo get_lang('ForumLocked');
  160. }
  161. }
  162. }
  163. }
  164. // the different views of the thread
  165. if ($origin != 'learnpath') {
  166. $my_url = '<a href="viewthread.php?'.api_get_cidreq().'&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));
  167. echo $my_url.'&amp;view=flat&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_listview.gif',get_lang('FlatView')).get_lang('FlatView').'</a>';
  168. echo $my_url.'&amp;view=threaded&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_threadedview.gif',get_lang('ThreadedView')).get_lang('ThreadedView').'</a>';
  169. echo $my_url.'&amp;view=nested&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_nestedview.gif',get_lang('NestedView')).get_lang('NestedView').'</a>';
  170. }
  171. $my_url = null;
  172. echo '</div>&nbsp;';
  173. /*
  174. -----------------------------------------------------------
  175. Display Forum Category and the Forum information
  176. -----------------------------------------------------------
  177. */
  178. if (!isset($_SESSION['view'])) {
  179. $viewmode=$current_forum['default_view'];
  180. } else {
  181. $viewmode=$_SESSION['view'];
  182. }
  183. $viewmode_whitelist=array('flat', 'threaded', 'nested');
  184. if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
  185. $viewmode=$_GET['view'];
  186. $_SESSION['view']=$viewmode;
  187. }
  188. if(empty($viewmode)) {
  189. $viewmode = 'flat';
  190. }
  191. /*
  192. -----------------------------------------------------------
  193. Display Forum Category and the Forum information
  194. -----------------------------------------------------------
  195. */
  196. // we are getting all the information about the current forum and forum category.
  197. // note pcool: I tried to use only one sql statement (and function) for this
  198. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  199. echo "<table class=\"data_table\" width='100%'>\n";
  200. // the thread
  201. echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
  202. echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
  203. if ($origin!='learnpath') {
  204. echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
  205. }
  206. echo prepare4display($current_forum['forum_title']).'<br />';
  207. echo "</th>\n";
  208. echo "\t</tr>\n";
  209. echo '<span>'.prepare4display(isset($current_thread['thread_comment'])?$current_thread['thread_comment']:'').'</span>';
  210. echo "</table>";
  211. switch ($viewmode) {
  212. case 'flat':
  213. include_once('viewthread_flat.inc.php');
  214. break;
  215. case 'threaded':
  216. include_once('viewthread_threaded.inc.php');
  217. break;
  218. case 'nested':
  219. include_once('viewthread_nested.inc.php');
  220. break;
  221. default:
  222. include_once('viewthread_flat.inc.php');
  223. break;
  224. }
  225. } // if ($message<>'PostDeletedSpecial') // in this case the first and only post of the thread is removed
  226. /*
  227. ==============================================================================
  228. FOOTER
  229. ==============================================================================
  230. */
  231. if ($origin!='learnpath') {
  232. Display :: display_footer();
  233. }