newthread.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. * These files are a complete rework of the forum. The database structure is
  22. * based on phpBB but all the code is rewritten. A lot of new functionalities
  23. * are added:
  24. * - forum categories and forums can be sorted up or down, locked or made invisible
  25. * - consistent and integrated forum administration
  26. * - forum options: are students allowed to edit their post?
  27. * moderation of posts (approval)
  28. * reply only forums (students cannot create new threads)
  29. * multiple forums per group
  30. * - sticky messages
  31. * - new view option: nested view
  32. * - quoting a message
  33. *
  34. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  35. * @Copyright Ghent University
  36. * @Copyright Patrick Cool
  37. *
  38. * @package dokeos.forum
  39. */
  40. // name of the language file that needs to be included
  41. $language_file = array('forum','document');
  42. // including the global dokeos file
  43. require_once '../inc/global.inc.php';
  44. require_once '../gradebook/lib/gradebook_functions.inc.php';
  45. // the section (tabs)
  46. $this_section=SECTION_COURSES;
  47. // notice for unauthorized people.
  48. api_protect_course_script(true);
  49. // including additional library scripts
  50. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  51. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  52. $nameTools=get_lang('Forum');
  53. // configuration for FCKeditor
  54. $fck_attribute['Width'] = '100%';
  55. $fck_attribute['Height'] = '300';
  56. $fck_attribute['ToolbarSet'] = 'Middle';
  57. $fck_attribute['Config']['IMUploadPath'] = 'upload/forum/';
  58. $fck_attribute['Config']['FlashUploadPath'] = 'upload/forum/';
  59. $fck_attribute['Config']['InDocument'] = false;
  60. $fck_attribute['Config']['CreateDocumentDir'] = '../../courses/'.api_get_course_path().'/document/';
  61. if(!api_is_allowed_to_edit(false,true)) {
  62. $fck_attribute['Config']['UserStatus'] = 'student';
  63. }
  64. /*
  65. -----------------------------------------------------------
  66. Including necessary files
  67. -----------------------------------------------------------
  68. */
  69. include('forumconfig.inc.php');
  70. include('forumfunction.inc.php');
  71. //are we in a lp ?
  72. $origin = '';
  73. if(isset($_GET['origin'])) {
  74. $origin = Security::remove_XSS($_GET['origin']);
  75. }
  76. /*
  77. ==============================================================================
  78. MAIN DISPLAY SECTION
  79. ==============================================================================
  80. */
  81. /*
  82. -----------------------------------------------------------
  83. Retrieving forum and forum categorie information
  84. -----------------------------------------------------------
  85. */
  86. $current_forum=get_forum_information($_GET['forum']); // note: this has to be validated that it is an existing forum.
  87. $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
  88. /*
  89. -----------------------------------------------------------
  90. Breadcrumbs
  91. -----------------------------------------------------------
  92. */
  93. if (!empty($_GET['gidReq'])) {
  94. $toolgroup = Database::escape_string($_GET['gidReq']);
  95. api_session_register('toolgroup');
  96. }
  97. if (!empty($_SESSION['toolgroup'])) {
  98. $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
  99. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  100. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  101. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  102. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  103. $interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
  104. } else {
  105. if( (isset($_GET['gradebook']) && $_GET['gradebook']=='view') || ( isset($_POST['gradebook']) && $_POST['gradebook']=='view')) {
  106. $interbreadcrumb[]= array (
  107. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  108. 'name' => get_lang('Gradebook')
  109. );
  110. }
  111. $interbreadcrumb[]=array("url" => "index.php","name" => $nameTools);
  112. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
  113. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  114. $interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
  115. }
  116. /*
  117. -----------------------------------------------------------
  118. Resource Linker
  119. -----------------------------------------------------------
  120. */
  121. if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
  122. $_SESSION['formelements']=$_POST;
  123. $_SESSION['origin']=$_SERVER['REQUEST_URI'];
  124. $_SESSION['breadcrumbs']=$interbreadcrumb;
  125. header("Location: ../resourcelinker/resourcelinker.php");
  126. }
  127. /*
  128. -----------------------------------------------------------
  129. Header
  130. -----------------------------------------------------------
  131. */
  132. if($origin=='learnpath') {
  133. include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
  134. } else {
  135. Display :: display_header(null);
  136. api_display_tool_title($nameTools);
  137. }
  138. /*
  139. -----------------------------------------------------------
  140. Is the user allowed here?
  141. -----------------------------------------------------------
  142. */
  143. // the user is not allowed here if:
  144. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  145. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  146. // 3. new threads are not allowed and the user is not a course manager
  147. // 4. anonymous posts are not allowed and the user is not logged in
  148. // I have split this is several pieces for clarity.
  149. if (!api_is_allowed_to_edit(false,true) && (($current_forum_category['visibility']==0 || $current_forum['visibility']==0))) {
  150. forum_not_allowed_here();
  151. }
  152. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  153. if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0)) {
  154. forum_not_allowed_here();
  155. }
  156. // 3. new threads are not allowed and the user is not a course manager
  157. if (!api_is_allowed_to_edit(false,true) AND $current_forum['allow_new_threads']<>1) {
  158. forum_not_allowed_here();
  159. }
  160. // 4. anonymous posts are not allowed and the user is not logged in
  161. if (!$_user['user_id'] AND $current_forum['allow_anonymous']<>1) {
  162. forum_not_allowed_here();
  163. }
  164. /*
  165. -----------------------------------------------------------
  166. Display forms / Feedback Messages
  167. -----------------------------------------------------------
  168. */
  169. handle_forum_and_forumcategories();
  170. /*
  171. -----------------------------------------------------------
  172. Display Forum Category and the Forum information
  173. -----------------------------------------------------------
  174. */
  175. echo "<table class=\"data_table\" width='100%'>\n";
  176. if ($origin != 'learnpath') {
  177. echo "\t<tr>\n\t\t<th align=\"left\" colspan=\"2\">";
  178. echo '<span class="forum_title">'.prepare4display($current_forum['forum_title']).'</span>';
  179. if (!empty ($current_forum['forum_comment'])) {
  180. echo '<br><span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
  181. }
  182. if (!empty ($current_forum_category['cat_title'])) {
  183. echo '<br /><span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])."</span><br />";
  184. }
  185. echo "</th>\n";
  186. echo "\t</tr>\n";
  187. }
  188. echo '</table>';
  189. $values=show_add_post_form('newthread','', isset($_SESSION['formelements'])?$_SESSION['formelements']:null);
  190. if (!empty($values) and isset($values['SubmitPost'])) {
  191. //add new thread in table forum_thread
  192. store_thread($values);
  193. }
  194. /*
  195. ==============================================================================
  196. FOOTER
  197. ==============================================================================
  198. */
  199. if ($origin!='learnpath') {
  200. Display :: display_footer();
  201. }