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