newthread.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. require_once __DIR__.'/../inc/global.inc.php';
  24. // The section (tabs).
  25. $this_section = SECTION_COURSES;
  26. // Notification for unauthorized people.
  27. api_protect_course_script(true);
  28. $cidreq = api_get_cidreq();
  29. $_user = api_get_user_info();
  30. $nameTools = get_lang('Forums');
  31. require_once 'forumfunction.inc.php';
  32. // Are we in a lp ?
  33. $origin = api_get_origin();
  34. /* MAIN DISPLAY SECTION */
  35. $current_forum = get_forum_information($_GET['forum']);
  36. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  37. $logInfo = [
  38. 'tool' => TOOL_FORUM,
  39. 'tool_id' => (int) $_GET['forum'],
  40. 'tool_id_detail' => 0,
  41. 'action' => 'add-thread',
  42. 'action_details' => '',
  43. ];
  44. Event::registerLog($logInfo);
  45. if (api_is_in_gradebook()) {
  46. $interbreadcrumb[] = [
  47. 'url' => Category::getUrl(),
  48. 'name' => get_lang('Assessments'),
  49. ];
  50. }
  51. /* Is the user allowed here? */
  52. // The user is not allowed here if:
  53. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  54. if (!api_is_allowed_to_edit(false, true) &&
  55. (($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
  56. ) {
  57. api_not_allowed();
  58. }
  59. // 2. the forumcategory or forum is locked (locked <>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['locked'] != 0) || $current_forum['locked'] != 0)
  62. ) {
  63. api_not_allowed();
  64. }
  65. // 3. new threads are not allowed and the user is not a course manager
  66. if (!api_is_allowed_to_edit(false, true) &&
  67. $current_forum['allow_new_threads'] != 1
  68. ) {
  69. api_not_allowed();
  70. }
  71. // 4. anonymous posts are not allowed and the user is not logged in
  72. if (!$_user['user_id'] && $current_forum['allow_anonymous'] != 1) {
  73. api_not_allowed();
  74. }
  75. // 5. Check user access
  76. if ($current_forum['forum_of_group'] != 0) {
  77. $show_forum = GroupManager::user_has_access(
  78. api_get_user_id(),
  79. $current_forum['forum_of_group'],
  80. GroupManager::GROUP_TOOL_FORUM
  81. );
  82. if (!$show_forum) {
  83. api_not_allowed();
  84. }
  85. }
  86. // 6. Invited users can't create new threads
  87. if (api_is_invitee()) {
  88. api_not_allowed(true);
  89. }
  90. $groupId = api_get_group_id();
  91. if (!empty($groupId)) {
  92. $groupProperties = GroupManager::get_group_properties($groupId);
  93. $interbreadcrumb[] = [
  94. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.$cidreq,
  95. 'name' => get_lang('Groups'),
  96. ];
  97. $interbreadcrumb[] = [
  98. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.$cidreq,
  99. 'name' => get_lang('Group area').' '.$groupProperties['name'],
  100. ];
  101. $interbreadcrumb[] = [
  102. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']),
  103. 'name' => $current_forum['forum_title'],
  104. ];
  105. $interbreadcrumb[] = [
  106. 'url' => api_get_path(WEB_CODE_PATH).'forum/newthread.php?'.$cidreq.'&forum='.intval($_GET['forum']),
  107. 'name' => get_lang('Create thread'),
  108. ];
  109. } else {
  110. $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.$cidreq, 'name' => $nameTools];
  111. $interbreadcrumb[] = [
  112. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.$cidreq.'&forumcategory='.$current_forum_category['cat_id'],
  113. 'name' => $current_forum_category['cat_title'],
  114. ];
  115. $interbreadcrumb[] = [
  116. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']),
  117. 'name' => $current_forum['forum_title'],
  118. ];
  119. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Create thread')];
  120. }
  121. $htmlHeadXtra[] = "
  122. <script>
  123. $(function() {
  124. $('#reply-add-attachment').on('click', function(e) {
  125. e.preventDefault();
  126. var newInputFile = $('<input>', {
  127. type: 'file',
  128. name: 'user_upload[]'
  129. });
  130. $('[name=\"user_upload[]\"]').parent().append(newInputFile);
  131. });
  132. });
  133. </script>
  134. ";
  135. $form = show_add_post_form(
  136. $current_forum,
  137. 'newthread',
  138. isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null
  139. );
  140. if ($origin == 'learnpath') {
  141. Display::display_reduced_header();
  142. } else {
  143. Display::display_header();
  144. }
  145. handle_forum_and_forumcategories();
  146. // Action links
  147. echo '<div class="actions">';
  148. echo '<span style="float:right;">'.search_link().'</span>';
  149. echo '<a href="viewforum.php?forum='.intval($_GET['forum']).'&'.$cidreq.'">'.
  150. Display::return_icon('back.png', get_lang('Back to forum'), '', ICON_SIZE_MEDIUM).'</a>';
  151. echo '</div>';
  152. // Set forum attachment data into $_SESSION
  153. getAttachedFiles($current_forum['forum_id'], 0, 0);
  154. if ($form) {
  155. $form->display();
  156. }
  157. if ($origin == 'learnpath') {
  158. Display::display_reduced_footer();
  159. } else {
  160. Display::display_footer();
  161. }