newthread.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  35. $nameTools = get_lang('ToolForum');
  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 = Security::remove_XSS($_SESSION['gradebook']);
  79. }
  80. if (!empty($gradebook) && $gradebook=='view') {
  81. $interbreadcrumb[]= array (
  82. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  83. 'name' => get_lang('ToolGradebook')
  84. );
  85. }
  86. if (!empty($_GET['gidReq'])) {
  87. $toolgroup = intval($_GET['gidReq']);
  88. api_session_register('toolgroup');
  89. }
  90. $session_toolgroup = 0;
  91. if (!empty($_SESSION['toolgroup'])) {
  92. $session_toolgroup = intval($_SESSION['toolgroup']);
  93. $group_properties = GroupManager :: get_group_properties($session_toolgroup);
  94. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  95. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$session_toolgroup, "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  96. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$session_toolgroup."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  97. $interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
  98. } else {
  99. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
  100. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
  101. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  102. $interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
  103. }
  104. /*
  105. -----------------------------------------------------------
  106. Resource Linker
  107. -----------------------------------------------------------
  108. */
  109. if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
  110. $_SESSION['formelements'] = $_POST;
  111. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  112. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  113. header("Location: ../resourcelinker/resourcelinker.php");
  114. }
  115. /*
  116. -----------------------------------------------------------
  117. Header
  118. -----------------------------------------------------------
  119. */
  120. if($origin=='learnpath') {
  121. require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
  122. } else {
  123. Display :: display_header(null);
  124. //api_display_tool_title($nameTools);
  125. }
  126. /*
  127. -----------------------------------------------------------
  128. Is the user allowed here?
  129. -----------------------------------------------------------
  130. */
  131. // the user is not allowed here if:
  132. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  133. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  134. // 3. new threads are not allowed and the user is not a course manager
  135. // 4. anonymous posts are not allowed and the user is not logged in
  136. // I have split this is several pieces for clarity.
  137. if (!api_is_allowed_to_edit(false,true) && (($current_forum_category['visibility']==0 || $current_forum['visibility']==0))) {
  138. $forum_allow = forum_not_allowed_here();
  139. if ($forum_allow === false) {
  140. exit;
  141. }
  142. }
  143. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  144. if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0)) {
  145. $forum_allow = forum_not_allowed_here();
  146. if ($forum_allow === false) {
  147. exit;
  148. }
  149. }
  150. // 3. new threads are not allowed and the user is not a course manager
  151. if (!api_is_allowed_to_edit(false,true) AND $current_forum['allow_new_threads']<>1) {
  152. $forum_allow = forum_not_allowed_here();
  153. if ($forum_allow === false) {
  154. exit;
  155. }
  156. }
  157. // 4. anonymous posts are not allowed and the user is not logged in
  158. if (!$_user['user_id'] AND $current_forum['allow_anonymous']<>1) {
  159. $forum_allow = forum_not_allowed_here();
  160. if ($forum_allow === false) {
  161. exit;
  162. }
  163. }
  164. /*
  165. -----------------------------------------------------------
  166. Display forms / Feedback Messages
  167. -----------------------------------------------------------
  168. */
  169. handle_forum_and_forumcategories();
  170. // action links
  171. echo '<div class="actions">';
  172. echo '<span style="float:right;">'.search_link().'</span>';
  173. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview')).' '.get_lang('BackToForumOverview').'</a>';
  174. 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>';
  175. echo '</div>';
  176. /*
  177. -----------------------------------------------------------
  178. Display Forum Category and the Forum information
  179. -----------------------------------------------------------
  180. */
  181. echo "<table class=\"data_table\" width='100%'>\n";
  182. if ($origin != 'learnpath') {
  183. echo "\t<tr>\n\t\t<th align=\"left\" colspan=\"2\">";
  184. echo '<span class="forum_title">'.prepare4display(Security::remove_XSS($current_forum['forum_title'])).'</span>';
  185. if (!empty ($current_forum['forum_comment'])) {
  186. echo '<br><span class="forum_description">'.prepare4display(Security::remove_XSS($current_forum['forum_comment'],STUDENT)).'</span>';
  187. }
  188. if (!empty ($current_forum_category['cat_title'])) {
  189. echo '<br /><span class="forum_low_description">'.prepare4display(Security::remove_XSS($current_forum_category['cat_title']))."</span><br />";
  190. }
  191. echo "</th>\n";
  192. echo "\t</tr>\n";
  193. }
  194. echo '</table>';
  195. $values=show_add_post_form('newthread','', isset($_SESSION['formelements'])?$_SESSION['formelements']:null);
  196. if (!empty($values) and isset($values['SubmitPost'])) {
  197. //add new thread in table forum_thread
  198. store_thread($values);
  199. }
  200. /*
  201. ==============================================================================
  202. FOOTER
  203. ==============================================================================
  204. */
  205. if ($origin!='learnpath') {
  206. Display :: display_footer();
  207. }