reply.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. api_protect_course_script(true);
  22. $nameTools = get_lang('ForumCategories');
  23. $origin = api_get_origin();
  24. $_user = api_get_user_info();
  25. require_once 'forumfunction.inc.php';
  26. $forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
  27. $threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
  28. /* MAIN DISPLAY SECTION */
  29. /* Retrieving forum and forum categorie information */
  30. // We are getting all the information about the current forum and forum category.
  31. // Note pcool: I tried to use only one sql statement (and function) for this,
  32. // but the problem is that the visibility of the forum AND forum category are stored in the item_property table.
  33. // Note: This has to be validated that it is an existing thread.
  34. $current_thread = get_thread_information($forumId, $threadId);
  35. // Note: This has to be validated that it is an existing forum.
  36. $current_forum = get_forum_information($current_thread['forum_id']);
  37. $current_forum_category = get_forumcategory_information($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) ||
  52. $current_forum['locked'] != 0 || $current_thread['locked'] != 0)
  53. ) {
  54. api_not_allowed(true);
  55. }
  56. if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
  57. api_not_allowed(true);
  58. }
  59. if ($current_forum['forum_of_group'] != 0) {
  60. $show_forum = GroupManager::user_has_access(
  61. api_get_user_id(),
  62. $current_forum['forum_of_group'],
  63. GroupManager::GROUP_TOOL_FORUM
  64. );
  65. if (!$show_forum) {
  66. api_not_allowed();
  67. }
  68. }
  69. if (api_is_in_gradebook()) {
  70. $interbreadcrumb[] = [
  71. 'url' => Category::getUrl(),
  72. 'name' => get_lang('ToolGradebook'),
  73. ];
  74. }
  75. $groupId = api_get_group_id();
  76. if (!empty($groupId)) {
  77. $group_properties = GroupManager::get_group_properties($groupId);
  78. $interbreadcrumb[] = [
  79. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  80. 'name' => get_lang('Groups'),
  81. ];
  82. $interbreadcrumb[] = [
  83. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  84. 'name' => get_lang('GroupSpace').' '.$group_properties['name'],
  85. ];
  86. $interbreadcrumb[] = [
  87. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
  88. 'name' => $current_forum['forum_title'],
  89. ];
  90. $interbreadcrumb[] = [
  91. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
  92. 'name' => $current_thread['thread_title'],
  93. ];
  94. $interbreadcrumb[] = [
  95. 'url' => 'javascript: void(0);',
  96. 'name' => get_lang('Reply'),
  97. ];
  98. } else {
  99. $interbreadcrumb[] = [
  100. 'url' => 'index.php?'.api_get_cidreq(),
  101. 'name' => $nameTools,
  102. ];
  103. $interbreadcrumb[] = [
  104. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
  105. 'name' => $current_forum_category['cat_title'],
  106. ];
  107. $interbreadcrumb[] = [
  108. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
  109. 'name' => $current_forum['forum_title'],
  110. ];
  111. $interbreadcrumb[] = [
  112. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
  113. 'name' => $current_thread['thread_title'],
  114. ];
  115. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Reply')];
  116. }
  117. /* Header */
  118. $htmlHeadXtra[] = <<<JS
  119. <script>
  120. $(function() {
  121. $('#reply-add-attachment').on('click', function(e) {
  122. e.preventDefault();
  123. var newInputFile = $('<input>', {
  124. type: 'file',
  125. name: 'user_upload[]'
  126. });
  127. $('[name="user_upload[]"]').parent().append(newInputFile);
  128. });
  129. });
  130. </script>
  131. JS;
  132. /* End new display forum */
  133. // The form for the reply
  134. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  135. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  136. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  137. $logInfo = [
  138. 'tool' => TOOL_FORUM,
  139. 'tool_id' => $forumId,
  140. 'tool_id_detail' => $threadId,
  141. 'action' => !empty($my_action) ? $my_action : 'reply',
  142. ];
  143. Event::registerLog($logInfo);
  144. $form = show_add_post_form(
  145. $current_forum,
  146. $my_action,
  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.'&thread='.$threadId.'">';
  160. echo Display::return_icon(
  161. 'back.png',
  162. get_lang('BackToThread'),
  163. '',
  164. ICON_SIZE_MEDIUM
  165. ).'</a>';
  166. echo '</div>';
  167. }
  168. /*New display forum div*/
  169. echo '<div class="forum_title">';
  170. echo '<h1>';
  171. echo Display::url(
  172. prepare4display($current_forum['forum_title']),
  173. 'viewforum.php?'.api_get_cidreq().'&'.http_build_query(['forum' => $current_forum['forum_id']]),
  174. ['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
  175. );
  176. echo '</h1>';
  177. echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
  178. echo '</div>';
  179. if ($form) {
  180. $form->display();
  181. }
  182. if ($origin == 'learnpath') {
  183. Display::display_reduced_footer();
  184. } else {
  185. Display::display_footer();
  186. }