reply.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * @package chamilo.forum
  18. */
  19. require_once __DIR__.'/../inc/global.inc.php';
  20. $this_section = SECTION_COURSES;
  21. // Notification for unauthorized people.
  22. api_protect_course_script(true);
  23. $nameTools = get_lang('ForumCategories');
  24. $origin = api_get_origin();
  25. /* Including necessary files */
  26. require_once 'forumconfig.inc.php';
  27. require_once 'forumfunction.inc.php';
  28. $forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
  29. $threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
  30. /* MAIN DISPLAY SECTION */
  31. /* Retrieving forum and forum categorie information */
  32. // We are getting all the information about the current forum and forum category.
  33. // Note pcool: I tried to use only one sql statement (and function) for this,
  34. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  35. $current_thread = get_thread_information($forumId, $threadId); // Note: This has to be validated that it is an existing thread.
  36. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
  37. $current_forum_category = get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
  38. /* Is the user allowed here? */
  39. // The user is not allowed here if
  40. // 1. the forumcategory, forum or thread is invisible (visibility==0
  41. // 2. the forumcategory, forum or thread is locked (locked <>0)
  42. // 3. if anonymous posts are not allowed
  43. // The only exception is the course manager
  44. // I have split this is several pieces for clarity.
  45. if (!api_is_allowed_to_edit(false, true) &&
  46. (($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
  47. ) {
  48. api_not_allowed(true);
  49. }
  50. if (!api_is_allowed_to_edit(false, true) &&
  51. (($current_forum_category && $current_forum_category['locked'] <> 0) || $current_forum['locked'] <> 0 || $current_thread['locked'] <> 0)
  52. ) {
  53. api_not_allowed(true);
  54. }
  55. if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
  56. api_not_allowed(true);
  57. }
  58. if ($current_forum['forum_of_group'] != 0) {
  59. $show_forum = GroupManager::user_has_access(
  60. api_get_user_id(),
  61. $current_forum['forum_of_group'],
  62. GroupManager::GROUP_TOOL_FORUM
  63. );
  64. if (!$show_forum) {
  65. api_not_allowed();
  66. }
  67. }
  68. /* Breadcrumbs */
  69. $gradebook = null;
  70. if (isset($_SESSION['gradebook'])) {
  71. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  72. }
  73. if (!empty($gradebook) && $gradebook == 'view') {
  74. $interbreadcrumb[] = array(
  75. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  76. 'name' => get_lang('ToolGradebook')
  77. );
  78. }
  79. $groupId = api_get_group_id();
  80. if (!empty($groupId)) {
  81. $_clean['toolgroup'] = $groupId;
  82. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  83. $interbreadcrumb[] = array(
  84. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  85. 'name' => get_lang('Groups'),
  86. );
  87. $interbreadcrumb[] = array(
  88. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  89. 'name' => get_lang('GroupSpace').' '.$group_properties['name']
  90. );
  91. $interbreadcrumb[] = array(
  92. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
  93. 'name' => $current_forum['forum_title']
  94. );
  95. $interbreadcrumb[] = array(
  96. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?gradebook='.$gradebook.'&forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
  97. 'name' => $current_thread['thread_title']
  98. );
  99. $interbreadcrumb[] = array(
  100. 'url' => 'javascript: void(0);',
  101. 'name' => get_lang('Reply'),
  102. );
  103. } else {
  104. $interbreadcrumb[] = array(
  105. 'url' => 'index.php?gradebook='.$gradebook,
  106. 'name' => $nameTools
  107. );
  108. $interbreadcrumb[] = array(
  109. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
  110. 'name' => $current_forum_category['cat_title']
  111. );
  112. $interbreadcrumb[] = array(
  113. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
  114. 'name' => $current_forum['forum_title']
  115. );
  116. $interbreadcrumb[] = array(
  117. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?gradebook='.$gradebook.'&forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
  118. 'name' => $current_thread['thread_title']
  119. );
  120. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
  121. }
  122. /* Header */
  123. $htmlHeadXtra[] = <<<JS
  124. <script>
  125. $(document).on('ready', function() {
  126. $('#reply-add-attachment').on('click', function(e) {
  127. e.preventDefault();
  128. var newInputFile = $('<input>', {
  129. type: 'file',
  130. name: 'user_upload[]'
  131. });
  132. $('[name="user_upload[]"]').parent().append(newInputFile);
  133. });
  134. });
  135. </script>
  136. JS;
  137. /* End new display forum */
  138. // The form for the reply
  139. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  140. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  141. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  142. $form = show_add_post_form(
  143. $current_forum,
  144. $forum_setting,
  145. $my_action,
  146. $my_post,
  147. $my_elements
  148. );
  149. if ($origin == 'learnpath') {
  150. Display::display_reduced_header();
  151. } else {
  152. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
  153. Display::display_header();
  154. }
  155. /* Action links */
  156. if ($origin != 'learnpath') {
  157. echo '<div class="actions">';
  158. echo '<span style="float:right;">'.search_link().'</span>';
  159. echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&gradebook='.$gradebook.'&thread='.$threadId.'">'.
  160. Display::return_icon('back.png', get_lang('BackToThread'), '', ICON_SIZE_MEDIUM).'</a>';
  161. echo '</div>';
  162. }
  163. /*New display forum div*/
  164. echo '<div class="forum_title">';
  165. echo '<h1>';
  166. echo Display::url(
  167. prepare4display($current_forum['forum_title']),
  168. 'viewforum.php?'.api_get_cidreq().'&'.http_build_query(['forum' => $current_forum['forum_id']]),
  169. ['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
  170. );
  171. echo '</h1>';
  172. echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
  173. echo '</div>';
  174. if ($form) {
  175. $form->display();
  176. }
  177. if ($origin == 'learnpath') {
  178. Display::display_reduced_footer();
  179. } else {
  180. Display::display_footer();
  181. }