newthread.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. /*
  54. -----------------------------------------------------------
  55. Including necessary files
  56. -----------------------------------------------------------
  57. */
  58. include('forumconfig.inc.php');
  59. include('forumfunction.inc.php');
  60. //are we in a lp ?
  61. $origin = '';
  62. if(isset($_GET['origin'])) {
  63. $origin = Security::remove_XSS($_GET['origin']);
  64. }
  65. // javascript
  66. $htmlHeadXtra[] = '<script>
  67. function advanced_parameters() {
  68. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  69. document.getElementById(\'id_qualify\').style.display = \'block\';
  70. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  71. } else {
  72. document.getElementById(\'id_qualify\').style.display = \'none\';
  73. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  74. }
  75. }
  76. </script>';
  77. /*
  78. ==============================================================================
  79. MAIN DISPLAY SECTION
  80. ==============================================================================
  81. */
  82. /*
  83. -----------------------------------------------------------
  84. Retrieving forum and forum categorie information
  85. -----------------------------------------------------------
  86. */
  87. $current_forum=get_forum_information($_GET['forum']); // note: this has to be validated that it is an existing forum.
  88. $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
  89. /*
  90. -----------------------------------------------------------
  91. Breadcrumbs
  92. -----------------------------------------------------------
  93. */
  94. if (isset($_SESSION['gradebook'])){
  95. $gradebook= $_SESSION['gradebook'];
  96. }
  97. if (!empty($gradebook) && $gradebook=='view') {
  98. $interbreadcrumb[]= array (
  99. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  100. 'name' => get_lang('Gradebook')
  101. );
  102. }
  103. if (!empty($_GET['gidReq'])) {
  104. $toolgroup = Database::escape_string($_GET['gidReq']);
  105. api_session_register('toolgroup');
  106. }
  107. if (!empty($_SESSION['toolgroup'])) {
  108. $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
  109. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  110. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  111. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  112. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  113. $interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
  114. } else {
  115. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
  116. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
  117. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  118. $interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
  119. }
  120. /*
  121. -----------------------------------------------------------
  122. Resource Linker
  123. -----------------------------------------------------------
  124. */
  125. if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
  126. $_SESSION['formelements']=$_POST;
  127. $_SESSION['origin']=$_SERVER['REQUEST_URI'];
  128. $_SESSION['breadcrumbs']=$interbreadcrumb;
  129. header("Location: ../resourcelinker/resourcelinker.php");
  130. }
  131. /*
  132. -----------------------------------------------------------
  133. Header
  134. -----------------------------------------------------------
  135. */
  136. if($origin=='learnpath') {
  137. include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
  138. } else {
  139. Display :: display_header(null);
  140. //api_display_tool_title($nameTools);
  141. }
  142. /*
  143. -----------------------------------------------------------
  144. Is the user allowed here?
  145. -----------------------------------------------------------
  146. */
  147. // the user is not allowed here if:
  148. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  149. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  150. // 3. new threads are not allowed and the user is not a course manager
  151. // 4. anonymous posts are not allowed and the user is not logged in
  152. // I have split this is several pieces for clarity.
  153. if (!api_is_allowed_to_edit(false,true) && (($current_forum_category['visibility']==0 || $current_forum['visibility']==0))) {
  154. forum_not_allowed_here();
  155. }
  156. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  157. if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0)) {
  158. forum_not_allowed_here();
  159. }
  160. // 3. new threads are not allowed and the user is not a course manager
  161. if (!api_is_allowed_to_edit(false,true) AND $current_forum['allow_new_threads']<>1) {
  162. forum_not_allowed_here();
  163. }
  164. // 4. anonymous posts are not allowed and the user is not logged in
  165. if (!$_user['user_id'] AND $current_forum['allow_anonymous']<>1) {
  166. forum_not_allowed_here();
  167. }
  168. /*
  169. -----------------------------------------------------------
  170. Display forms / Feedback Messages
  171. -----------------------------------------------------------
  172. */
  173. handle_forum_and_forumcategories();
  174. // action links
  175. echo '<div class="actions">';
  176. echo '<span style="float:right;">'.search_link().'</span>';
  177. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview')).' '.get_lang('BackToForumOverview').'</a>';
  178. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'">'.Display::return_icon('forum.gif',get_lang('BackToForum')).' '.get_lang('BackToForum').'</a>';
  179. echo '</div>';
  180. /*
  181. -----------------------------------------------------------
  182. Display Forum Category and the Forum information
  183. -----------------------------------------------------------
  184. */
  185. echo "<table class=\"data_table\" width='100%'>\n";
  186. if ($origin != 'learnpath') {
  187. echo "\t<tr>\n\t\t<th align=\"left\" colspan=\"2\">";
  188. echo '<span class="forum_title">'.prepare4display($current_forum['forum_title']).'</span>';
  189. if (!empty ($current_forum['forum_comment'])) {
  190. echo '<br><span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
  191. }
  192. if (!empty ($current_forum_category['cat_title'])) {
  193. echo '<br /><span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])."</span><br />";
  194. }
  195. echo "</th>\n";
  196. echo "\t</tr>\n";
  197. }
  198. echo '</table>';
  199. $values=show_add_post_form('newthread','', isset($_SESSION['formelements'])?$_SESSION['formelements']:null);
  200. if (!empty($values) and isset($values['SubmitPost'])) {
  201. //add new thread in table forum_thread
  202. store_thread($values);
  203. }
  204. /*
  205. ==============================================================================
  206. FOOTER
  207. ==============================================================================
  208. */
  209. if ($origin!='learnpath') {
  210. Display :: display_footer();
  211. }