reply.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * These files are a complete rework of the forum. The database structure is
  6. * based on phpBB but all the code is rewritten. A lot of new functionalities
  7. * are added:
  8. * - forum categories and forums can be sorted up or down, locked or made invisible
  9. * - consistent and integrated forum administration
  10. * - forum options: are students allowed to edit their post?
  11. * moderation of posts (approval)
  12. * reply only forums (students cannot create new threads)
  13. * multiple forums per group
  14. * - sticky messages
  15. * - new view option: nested view
  16. * - quoting a message
  17. *
  18. * @package chamilo.forum
  19. */
  20. $this_section = SECTION_COURSES;
  21. // Notification for unauthorized people.
  22. api_protect_course_script(true);
  23. $nameTools = get_lang('ForumCategories');
  24. $origin = '';
  25. if (isset($_GET['origin'])) {
  26. $origin = Security::remove_XSS($_GET['origin']);
  27. $origin_string = '&origin='.$origin;
  28. }
  29. /* Including necessary files */
  30. require_once 'forumconfig.inc.php';
  31. require_once 'forumfunction.inc.php';
  32. $forumId = isset($_GET['forum']) ? (int)$_GET['forum'] : 0;
  33. $threadId = isset($_GET['thread']) ? (int)$_GET['thread'] : 0;
  34. /* MAIN DISPLAY SECTION */
  35. /* Retrieving forum and forum categorie information */
  36. // We are getting all the information about the current forum and forum category.
  37. // Note pcool: I tried to use only one sql statement (and function) for this,
  38. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  39. $current_thread = get_thread_information($forumId, $threadId); // Note: This has to be validated that it is an existing thread.
  40. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
  41. $current_forum_category = get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
  42. /* Is the user allowed here? */
  43. // The user is not allowed here if
  44. // 1. the forumcategory, forum or thread is invisible (visibility==0
  45. // 2. the forumcategory, forum or thread is locked (locked <>0)
  46. // 3. if anonymous posts are not allowed
  47. // The only exception is the course manager
  48. // I have split this is several pieces for clarity.
  49. if (!api_is_allowed_to_edit(false, true) &&
  50. (($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
  51. ) {
  52. api_not_allowed(true);
  53. }
  54. if (!api_is_allowed_to_edit(false, true) &&
  55. (($current_forum_category && $current_forum_category['locked'] <> 0) || $current_forum['locked'] <> 0 || $current_thread['locked'] <> 0)
  56. ) {
  57. api_not_allowed(true);
  58. }
  59. if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
  60. api_not_allowed(true);
  61. }
  62. if ($current_forum['forum_of_group'] != 0) {
  63. $show_forum = GroupManager::user_has_access(
  64. api_get_user_id(),
  65. $current_forum['forum_of_group'],
  66. GroupManager::GROUP_TOOL_FORUM
  67. );
  68. if (!$show_forum) {
  69. api_not_allowed();
  70. }
  71. }
  72. /* Breadcrumbs */
  73. if (api_is_in_gradebook()) {
  74. $interbreadcrumb[]= array(
  75. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  76. 'name' => get_lang('ToolGradebook')
  77. );
  78. }
  79. $groupId = api_get_group_id();
  80. if (!empty($groupId)) {
  81. $group_properties = GroupManager :: get_group_properties($groupId);
  82. $interbreadcrumb[] = array(
  83. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  84. 'name' => get_lang('Groups'),
  85. );
  86. $interbreadcrumb[] = array(
  87. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  88. 'name' => get_lang('GroupSpace').' '.$group_properties['name'],
  89. );
  90. $interbreadcrumb[] = array(
  91. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
  92. 'name' => $current_forum['forum_title'],
  93. );
  94. $interbreadcrumb[] = array(
  95. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&'.api_get_cidreq(),
  96. 'name' => $current_thread['thread_title'],
  97. );
  98. $interbreadcrumb[] = array(
  99. 'url' => 'javascript: void(0);',
  100. 'name' => get_lang('Reply'),
  101. );
  102. } else {
  103. $interbreadcrumb[] = array(
  104. 'url' => 'index.php?'.api_get_cidreq(),
  105. 'name' => $nameTools,
  106. );
  107. $interbreadcrumb[] = array(
  108. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
  109. 'name' => $current_forum_category['cat_title'],
  110. );
  111. $interbreadcrumb[] = array(
  112. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
  113. 'name' => $current_forum['forum_title'],
  114. );
  115. $interbreadcrumb[] = array(
  116. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&'.api_get_cidreq(),
  117. 'name' => $current_thread['thread_title'],
  118. );
  119. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
  120. }
  121. /* Header */
  122. $htmlHeadXtra[] = <<<JS
  123. <script>
  124. $(document).on('ready', function() {
  125. $('#reply-add-attachment').on('click', function(e) {
  126. e.preventDefault();
  127. var newInputFile = $('<input>', {
  128. type: 'file',
  129. name: 'user_upload[]'
  130. });
  131. $('[name="user_upload[]"]').parent().append(newInputFile);
  132. });
  133. });
  134. </script>
  135. JS;
  136. /* End new display forum */
  137. // The form for the reply
  138. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  139. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  140. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  141. $form = show_add_post_form(
  142. $current_forum,
  143. $forum_setting,
  144. $my_action,
  145. $my_post,
  146. $my_elements
  147. );
  148. if ($origin == 'learnpath') {
  149. Display::display_reduced_header();
  150. } else {
  151. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
  152. Display::display_header();
  153. }
  154. /* Action links */
  155. if ($origin != 'learnpath') {
  156. echo '<div class="actions">';
  157. echo '<span style="float:right;">'.search_link().'</span>';
  158. echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&gradebook='.$gradebook.'&thread='.$threadId.'">'.
  159. Display::return_icon('back.png', get_lang('BackToThread'), '', ICON_SIZE_MEDIUM).'</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. $form->display();
  174. if ($origin == 'learnpath') {
  175. Display::display_reduced_footer();
  176. } else {
  177. Display::display_footer();
  178. }