newthread.php 8.8 KB

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