newthread.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 chamilo.forum
  22. */
  23. // Language file that need to be included.
  24. $language_file = array('forum', 'document');
  25. // Including the global initialization 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. // Notification 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. /* Including necessary files */
  37. require_once 'forumconfig.inc.php';
  38. require_once 'forumfunction.inc.php';
  39. // Are we in a lp ?
  40. $origin = '';
  41. if (isset($_GET['origin'])) {
  42. $origin = Security::remove_XSS($_GET['origin']);
  43. }
  44. // javascript
  45. $htmlHeadXtra[] = '<script>
  46. function advanced_parameters() {
  47. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  48. document.getElementById(\'id_qualify\').style.display = \'block\';
  49. 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').'\';
  50. } else {
  51. document.getElementById(\'id_qualify\').style.display = \'none\';
  52. 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').'\';
  53. }
  54. }
  55. </script>';
  56. /* MAIN DISPLAY SECTION */
  57. /* Retrieving forum and forum category information */
  58. $current_forum = get_forum_information($_GET['forum']); // Note: This has to be validated that it is an existing forum.
  59. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  60. /* Breadcrumbs */
  61. if (isset($_SESSION['gradebook'])){
  62. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  63. }
  64. if (!empty($gradebook) && $gradebook == 'view') {
  65. $interbreadcrumb[] = array (
  66. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  67. 'name' => get_lang('ToolGradebook')
  68. );
  69. }
  70. if (!empty($_GET['gidReq'])) {
  71. $toolgroup = intval($_GET['gidReq']);
  72. api_session_register('toolgroup');
  73. }
  74. $session_toolgroup = 0;
  75. if ($origin == 'group') {
  76. $session_toolgroup = intval($_SESSION['toolgroup']);
  77. $group_properties = GroupManager :: get_group_properties($session_toolgroup);
  78. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  79. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$session_toolgroup, 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  80. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;gidReq='.$session_toolgroup.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  81. $interbreadcrumb[] = array('url' => 'newthread.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']),'name' => get_lang('NewTopic'));
  82. } else {
  83. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook, 'name' => $nameTools);
  84. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => $current_forum_category['cat_title']);
  85. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  86. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewTopic'));
  87. }
  88. /* Resource Linker */
  89. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  90. $_SESSION['formelements'] = $_POST;
  91. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  92. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  93. header('Location: ../resourcelinker/resourcelinker.php');
  94. }
  95. /* Header */
  96. if ($origin == 'learnpath') {
  97. require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
  98. } else {
  99. Display :: display_header(null);
  100. //api_display_tool_title($nameTools);
  101. }
  102. /* Is the user allowed here? */
  103. // The user is not allowed here if:
  104. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  105. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  106. // 3. new threads are not allowed and the user is not a course manager
  107. // 4. anonymous posts are not allowed and the user is not logged in
  108. // I have split this is several pieces for clarity.
  109. if (!api_is_allowed_to_edit(false, true) && (($current_forum_category['visibility'] == 0 || $current_forum['visibility'] == 0))) {
  110. $forum_allow = forum_not_allowed_here();
  111. if ($forum_allow === false) {
  112. exit;
  113. }
  114. }
  115. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  116. if (!api_is_allowed_to_edit(false, true) AND ($current_forum_category['locked'] <> 0 OR $current_forum['locked'] <> 0)) {
  117. $forum_allow = forum_not_allowed_here();
  118. if ($forum_allow === false) {
  119. exit;
  120. }
  121. }
  122. // 3. new threads are not allowed and the user is not a course manager
  123. if (!api_is_allowed_to_edit(false, true) AND $current_forum['allow_new_threads'] <> 1) {
  124. $forum_allow = forum_not_allowed_here();
  125. if ($forum_allow === false) {
  126. exit;
  127. }
  128. }
  129. // 4. anonymous posts are not allowed and the user is not logged in
  130. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] <> 1) {
  131. $forum_allow = forum_not_allowed_here();
  132. if ($forum_allow === false) {
  133. exit;
  134. }
  135. }
  136. /* Display forms / Feedback Messages */
  137. handle_forum_and_forumcategories();
  138. // Action links
  139. echo '<div class="actions">';
  140. echo '<span style="float:right;">'.search_link().'</span>';
  141. /*
  142. if ($origin == 'group') {
  143. echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
  144. } else {
  145. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';
  146. }*/
  147. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'">'.Display::return_icon('back.png',get_lang('BackToForum'),'','32').'</a>';
  148. echo '</div>';
  149. /* Display Forum Category and the Forum information */
  150. /*
  151. echo "<table class=\"data_table\" width=\"100%\">\n";
  152. if ($origin != 'learnpath') {
  153. echo "<tr>\n<th align=\"left\" colspan=\"2\">";
  154. echo '<span class="forum_title">'.prepare4display($current_forum['forum_title']).'</span>';
  155. if (!empty($current_forum['forum_comment'])) {
  156. echo '<br><span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
  157. }
  158. if (!empty($current_forum_category['cat_title'])) {
  159. echo '<br /><span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])."</span><br />";
  160. }
  161. echo "</th>\n";
  162. echo "</tr>\n";
  163. }
  164. echo '</table>';
  165. */
  166. $values = show_add_post_form('newthread', '', isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null);
  167. if (!empty($values) && isset($values['SubmitPost'])) {
  168. // Add new thread in table forum_thread.
  169. store_thread($values);
  170. }
  171. /* FOOTER */
  172. if ($origin != 'learnpath') {
  173. Display :: display_footer();
  174. }