newthread.php 5.7 KB

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