reply.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. // The section (tabs).
  21. $this_section = SECTION_COURSES;
  22. // Notification for unauthorized people.
  23. api_protect_course_script(true);
  24. $nameTools = get_lang('ForumCategories');
  25. $origin = '';
  26. if (isset($_GET['origin'])) {
  27. $origin = Security::remove_XSS($_GET['origin']);
  28. $origin_string = '&origin='.$origin;
  29. }
  30. /* Including necessary files */
  31. require_once 'forumconfig.inc.php';
  32. require_once 'forumfunction.inc.php';
  33. /* MAIN DISPLAY SECTION */
  34. /* Retrieving forum and forum categorie information */
  35. // We are getting all the information about the current forum and forum category.
  36. // Note pcool: I tried to use only one sql statement (and function) for this,
  37. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  38. $current_thread = get_thread_information($_GET['thread']); // Note: This has to be validated that it is an existing thread.
  39. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
  40. $current_forum_category = get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
  41. /* Is the user allowed here? */
  42. // The user is not allowed here if
  43. // 1. the forumcategory, forum or thread is invisible (visibility==0
  44. // 2. the forumcategory, forum or thread is locked (locked <>0)
  45. // 3. if anonymous posts are not allowed
  46. // The only exception is the course manager
  47. // I have split this is several pieces for clarity.
  48. //if (!api_is_allowed_to_edit() AND (($current_forum_category['visibility'] == 0 OR $current_forum['visibility'] == 0) OR ($current_forum_category['locked'] <> 0 OR $current_forum['locked'] <> 0 OR $current_thread['locked'] <> 0))) {
  49. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category && $current_forum_category['visibility'] == 0) OR $current_forum['visibility'] == 0)) {
  50. api_not_allowed();
  51. }
  52. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category && $current_forum_category['locked'] <> 0) OR $current_forum['locked'] <> 0 OR $current_thread['locked'] <> 0)) {
  53. api_not_allowed();
  54. }
  55. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] == 0) {
  56. api_not_allowed();
  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. if ($origin == 'group') {
  80. $_clean['toolgroup'] = api_get_group_id();
  81. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  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?gradebook='.$gradebook,
  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. /* Resource Linker */
  122. if (isset($_POST['add_resources']) && $_POST['add_resources'] == get_lang('Resources')) {
  123. $_SESSION['formelements'] = $_POST;
  124. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  125. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  126. header('Location: ../resourcelinker/resourcelinker.php');
  127. exit;
  128. }
  129. /* Header */
  130. $htmlHeadXtra[] = <<<JS
  131. <script>
  132. $(document).on('ready', function() {
  133. $('#reply-add-attachment').on('click', function(e) {
  134. e.preventDefault();
  135. var newInputFile = $('<input>', {
  136. type: 'file',
  137. name: 'user_upload[]'
  138. });
  139. $('[name="user_upload[]"]').parent().append(newInputFile);
  140. });
  141. });
  142. </script>
  143. JS;
  144. if ($origin == 'learnpath') {
  145. Display::display_reduced_header();
  146. } else {
  147. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
  148. Display::display_header();
  149. }
  150. /* Action links */
  151. if ($origin != 'learnpath') {
  152. echo '<div class="actions">';
  153. echo '<span style="float:right;">'.search_link().'</span>';
  154. echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&gradebook='.$gradebook.'&thread='.Security::remove_XSS($_GET['thread']).'&origin='.$origin.'">'.
  155. Display::return_icon('back.png', get_lang('BackToThread'), '', ICON_SIZE_MEDIUM).'</a>';
  156. echo '</div>';
  157. }
  158. /*New display forum div*/
  159. echo '<div class="forum_title">';
  160. echo '<h1><a href="viewforum.php?&origin='.$origin.'&forum='.$current_forum['forum_id'].'" '.
  161. class_visible_invisible($current_forum['visibility']).'>'.
  162. prepare4display($current_forum['forum_title']).'</a></h1>';
  163. echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
  164. echo '</div>';
  165. /* End new display forum */
  166. // The form for the reply
  167. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  168. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  169. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  170. $values = show_add_post_form(
  171. $current_forum,
  172. $forum_setting,
  173. $my_action,
  174. $my_post,
  175. $my_elements
  176. );
  177. if (!empty($values) && isset($_POST['SubmitPost'])) {
  178. $result = store_reply($current_forum, $values);
  179. //@todo split the show_add_post_form function
  180. $origin = isset($_GET['origin']) && $_GET['origin'] === 'learnpath' ? 'learnpath' : null;
  181. $url = 'viewthread.php?' . http_build_query([
  182. 'forum' => $current_thread['forum_id'],
  183. 'gradebook' => $gradebook,
  184. 'thread' => intval($_GET['thread']),
  185. 'gidReq' => api_get_group_id(),
  186. 'origin' => $origin,
  187. 'msg' => $result['msg'],
  188. 'type' => $result['type']
  189. ]);
  190. echo '
  191. <script>
  192. window.location = "'.$url.'";
  193. </script>';
  194. }
  195. if ($origin == 'learnpath') {
  196. Display::display_reduced_footer();
  197. } else {
  198. Display::display_footer();
  199. }