newthread.php 6.2 KB

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