newthread.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. use ChamiloSession as Session;
  24. // Including the global initialization file.
  25. require_once '../inc/global.inc.php';
  26. // The section (tabs).
  27. $this_section = SECTION_COURSES;
  28. // Notification for unauthorized people.
  29. api_protect_course_script(true);
  30. $nameTools = get_lang('ToolForum');
  31. /* Including necessary files */
  32. require_once 'forumconfig.inc.php';
  33. require_once 'forumfunction.inc.php';
  34. // Are we in a lp ?
  35. $origin = '';
  36. if (isset($_GET['origin'])) {
  37. $origin = Security::remove_XSS($_GET['origin']);
  38. }
  39. /* MAIN DISPLAY SECTION */
  40. /* Retrieving forum and forum category information */
  41. $current_forum = get_forum_information($_GET['forum']); // Note: This has to be validated that it is an existing forum.
  42. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  43. /* Breadcrumbs */
  44. if (isset($_SESSION['gradebook'])){
  45. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  46. }
  47. if (!empty($gradebook) && $gradebook == 'view') {
  48. $interbreadcrumb[] = array (
  49. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  50. 'name' => get_lang('ToolGradebook')
  51. );
  52. }
  53. if (!empty($_GET['gidReq'])) {
  54. $toolgroup = intval($_GET['gidReq']);
  55. Session::write('toolgroup',$toolgroup);
  56. }
  57. /* Is the user allowed here? */
  58. // The user is not allowed here if:
  59. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  60. if (!api_is_allowed_to_edit(false, true) &&
  61. (($current_forum_category['visibility'] && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
  62. ) {
  63. api_not_allowed();
  64. }
  65. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  66. if (!api_is_allowed_to_edit(false, true) &&
  67. (($current_forum_category['visibility'] && $current_forum_category['locked'] <> 0) OR $current_forum['locked'] <> 0)
  68. ) {
  69. api_not_allowed();
  70. }
  71. // 3. new threads are not allowed and the user is not a course manager
  72. if (!api_is_allowed_to_edit(false, true) &&
  73. $current_forum['allow_new_threads'] <> 1
  74. ) {
  75. api_not_allowed();
  76. }
  77. // 4. anonymous posts are not allowed and the user is not logged in
  78. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] <> 1) {
  79. api_not_allowed();
  80. }
  81. // 5. Check user access
  82. if ($current_forum['forum_of_group'] != 0) {
  83. $show_forum = GroupManager::user_has_access(
  84. api_get_user_id(),
  85. $current_forum['forum_of_group'],
  86. GroupManager::GROUP_TOOL_FORUM
  87. );
  88. if (!$show_forum) {
  89. api_not_allowed();
  90. }
  91. }
  92. // 6. Invited users can't create new threads
  93. if (api_is_invitee()) {
  94. api_not_allowed(true);
  95. }
  96. $groupId = api_get_group_id();
  97. if (!empty($groupId)) {
  98. $group_properties = GroupManager :: get_group_properties($groupId);
  99. $interbreadcrumb[] = array('url' => '../group/group.php?'.api_get_cidreq(), 'name' => get_lang('Groups'));
  100. $interbreadcrumb[] = array('url' => '../group/group_space.php?'.api_get_cidreq(), 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  101. $interbreadcrumb[] = array('url' => 'viewforum.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  102. $interbreadcrumb[] = array('url' => 'newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']),'name' => get_lang('NewTopic'));
  103. } else {
  104. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq(), 'name' => $nameTools);
  105. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$current_forum_category['cat_id'], 'name' => $current_forum_category['cat_title']);
  106. $interbreadcrumb[] = array('url' => 'viewforum.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  107. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewTopic'));
  108. }
  109. /* Resource Linker */
  110. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  111. $_SESSION['formelements'] = $_POST;
  112. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  113. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  114. header('Location: ../resourcelinker/resourcelinker.php');
  115. exit;
  116. }
  117. /* Header */
  118. $htmlHeadXtra[] = <<<JS
  119. <script>
  120. $(document).on('ready', function() {
  121. $('#reply-add-attachment').on('click', function(e) {
  122. e.preventDefault();
  123. var newInputFile = $('<input>', {
  124. type: 'file',
  125. name: 'user_upload[]'
  126. });
  127. $('[name="user_upload[]"]').parent().append(newInputFile);
  128. });
  129. });
  130. </script>
  131. JS;
  132. if ($origin == 'learnpath') {
  133. Display::display_reduced_header();
  134. } else {
  135. Display :: display_header(null);
  136. }
  137. handle_forum_and_forumcategories();
  138. // Action links
  139. echo '<div class="actions">';
  140. echo '<span style="float:right;">'.search_link().'</span>';
  141. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&'.api_get_cidreq().'">'.
  142. Display::return_icon('back.png',get_lang('BackToForum'),'',ICON_SIZE_MEDIUM).'</a>';
  143. echo '</div>';
  144. // Set forum attachment data into $_SESSION
  145. getAttachedFiles($current_forum['forum_id'], 0, 0);
  146. $values = show_add_post_form(
  147. $current_forum,
  148. $forum_setting,
  149. 'newthread',
  150. '',
  151. isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null
  152. );
  153. if (!empty($values) && isset($values['SubmitPost'])) {
  154. // Add new thread in table forum_thread.
  155. store_thread($current_forum, $values);
  156. }
  157. if (isset($origin) && $origin != 'learnpath') {
  158. Display :: display_footer();
  159. }