newthread.php 5.5 KB

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