reply.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. if (api_is_in_gradebook()) {
  69. $interbreadcrumb[] = array(
  70. 'url' => Category::getUrl(),
  71. 'name' => get_lang('ToolGradebook')
  72. );
  73. }
  74. $groupId = api_get_group_id();
  75. if (!empty($groupId)) {
  76. $group_properties = GroupManager::get_group_properties($groupId);
  77. $interbreadcrumb[] = array(
  78. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  79. 'name' => get_lang('Groups'),
  80. );
  81. $interbreadcrumb[] = array(
  82. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  83. 'name' => get_lang('GroupSpace').' '.$group_properties['name']
  84. );
  85. $interbreadcrumb[] = array(
  86. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
  87. 'name' => $current_forum['forum_title']
  88. );
  89. $interbreadcrumb[] = array(
  90. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
  91. 'name' => $current_thread['thread_title']
  92. );
  93. $interbreadcrumb[] = array(
  94. 'url' => 'javascript: void(0);',
  95. 'name' => get_lang('Reply'),
  96. );
  97. } else {
  98. $interbreadcrumb[] = array(
  99. 'url' => 'index.php?'.api_get_cidreq(),
  100. 'name' => $nameTools
  101. );
  102. $interbreadcrumb[] = array(
  103. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
  104. 'name' => $current_forum_category['cat_title']
  105. );
  106. $interbreadcrumb[] = array(
  107. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
  108. 'name' => $current_forum['forum_title']
  109. );
  110. $interbreadcrumb[] = array(
  111. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
  112. 'name' => $current_thread['thread_title']
  113. );
  114. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
  115. }
  116. /* Header */
  117. $htmlHeadXtra[] = <<<JS
  118. <script>
  119. $(document).on('ready', function() {
  120. $('#reply-add-attachment').on('click', function(e) {
  121. e.preventDefault();
  122. var newInputFile = $('<input>', {
  123. type: 'file',
  124. name: 'user_upload[]'
  125. });
  126. $('[name="user_upload[]"]').parent().append(newInputFile);
  127. });
  128. });
  129. </script>
  130. JS;
  131. /* End new display forum */
  132. // The form for the reply
  133. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  134. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  135. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  136. $form = show_add_post_form(
  137. $current_forum,
  138. $forum_setting,
  139. $my_action,
  140. $my_post,
  141. $my_elements
  142. );
  143. if ($origin == 'learnpath') {
  144. Display::display_reduced_header();
  145. } else {
  146. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
  147. Display::display_header();
  148. }
  149. /* Action links */
  150. if ($origin != 'learnpath') {
  151. echo '<div class="actions">';
  152. echo '<span style="float:right;">'.search_link().'</span>';
  153. echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId.'">';
  154. echo Display::return_icon(
  155. 'back.png',
  156. get_lang('BackToThread'),
  157. '',
  158. ICON_SIZE_MEDIUM
  159. ).'</a>';
  160. echo '</div>';
  161. }
  162. /*New display forum div*/
  163. echo '<div class="forum_title">';
  164. echo '<h1>';
  165. echo Display::url(
  166. prepare4display($current_forum['forum_title']),
  167. 'viewforum.php?'.api_get_cidreq().'&'.http_build_query(['forum' => $current_forum['forum_id']]),
  168. ['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
  169. );
  170. echo '</h1>';
  171. echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
  172. echo '</div>';
  173. if ($form) {
  174. $form->display();
  175. }
  176. if ($origin == 'learnpath') {
  177. Display::display_reduced_footer();
  178. } else {
  179. Display::display_footer();
  180. }