reply.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. // Including the global initialization file.
  20. require_once '../inc/global.inc.php';
  21. // The section (tabs).
  22. $this_section = SECTION_COURSES;
  23. // Notification for unauthorized people.
  24. api_protect_course_script(true);
  25. $nameTools = get_lang('ForumCategories');
  26. $origin = '';
  27. if (isset($_GET['origin'])) {
  28. $origin = Security::remove_XSS($_GET['origin']);
  29. $origin_string = '&origin='.$origin;
  30. }
  31. /* Including necessary files */
  32. require_once 'forumconfig.inc.php';
  33. require_once 'forumfunction.inc.php';
  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($_GET['thread']); // 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() 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))) {
  50. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category && $current_forum_category['visibility'] == 0) OR $current_forum['visibility'] == 0)) {
  51. api_not_allowed();
  52. }
  53. 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)) {
  54. api_not_allowed();
  55. }
  56. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] == 0) {
  57. api_not_allowed();
  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. /* Breadcrumbs */
  70. $gradebook = null;
  71. if (isset($_SESSION['gradebook'])){
  72. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  73. }
  74. if (!empty($gradebook) && $gradebook == 'view') {
  75. $interbreadcrumb[] = array (
  76. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  77. 'name' => get_lang('ToolGradebook')
  78. );
  79. }
  80. if ($origin == 'group') {
  81. $_clean['toolgroup'] = (int)$_SESSION['toolgroup'];
  82. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  83. $interbreadcrumb[] = array(
  84. 'url' => '../group/group.php?'.api_get_cidreq(),
  85. 'name' => get_lang('Groups'),
  86. );
  87. $interbreadcrumb[] = array(
  88. 'url' => '../group/group_space.php?'.api_get_cidreq(),
  89. 'name' => get_lang('GroupSpace').' '.$group_properties['name'],
  90. );
  91. $interbreadcrumb[] = array(
  92. 'url' => 'viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
  93. 'name' => $current_forum['forum_title'],
  94. );
  95. $interbreadcrumb[] = array(
  96. 'url' => 'viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&'.api_get_cidreq(),
  97. 'name' => $current_thread['thread_title'],
  98. );
  99. $interbreadcrumb[] = array(
  100. 'url' => 'javascript: void(0);',
  101. 'name' => get_lang('Reply'),
  102. );
  103. } else {
  104. $interbreadcrumb[] = array(
  105. 'url' => 'index.php?gradebook='.$gradebook,
  106. 'name' => $nameTools,
  107. );
  108. $interbreadcrumb[] = array(
  109. 'url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
  110. 'name' => $current_forum_category['cat_title'],
  111. );
  112. $interbreadcrumb[] = array(
  113. 'url' => 'viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
  114. 'name' => $current_forum['forum_title'],
  115. );
  116. $interbreadcrumb[] = array(
  117. 'url' => 'viewthread.php?origin='.$origin.'&gradebook='.$gradebook.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']).'&'.api_get_cidreq(),
  118. 'name' => $current_thread['thread_title'],
  119. );
  120. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
  121. }
  122. /* Resource Linker */
  123. if (isset($_POST['add_resources']) && $_POST['add_resources'] == get_lang('Resources')) {
  124. $_SESSION['formelements'] = $_POST;
  125. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  126. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  127. header('Location: ../resourcelinker/resourcelinker.php');
  128. exit;
  129. }
  130. /* Header */
  131. $htmlHeadXtra[] = <<<JS
  132. <script>
  133. $(document).on('ready', function() {
  134. $('#reply-add-attachment').on('click', function(e) {
  135. e.preventDefault();
  136. var newInputFile = $('<input>', {
  137. type: 'file',
  138. name: 'user_upload[]'
  139. });
  140. $('[name="user_upload[]"]').parent().append(newInputFile);
  141. });
  142. });
  143. </script>
  144. JS;
  145. if ($origin == 'learnpath') {
  146. Display :: display_reduced_header('');
  147. } else {
  148. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
  149. Display :: display_header('');
  150. }
  151. /* Action links */
  152. if ($origin != 'learnpath') {
  153. echo '<div class="actions">';
  154. echo '<span style="float:right;">'.search_link().'</span>';
  155. echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&gradebook='.$gradebook.'&thread='.Security::remove_XSS($_GET['thread']).'&origin='.$origin.'">'.
  156. Display::return_icon('back.png', get_lang('BackToThread'), '', ICON_SIZE_MEDIUM).'</a>';
  157. echo '</div>';
  158. } else {
  159. echo '<div style="height:15px">&nbsp;</div>';
  160. }
  161. /*New display forum div*/
  162. echo '<div class="forum_title">';
  163. echo '<h1><a href="viewforum.php?&origin='.$origin.'&forum='.$current_forum['forum_id'].'" '.
  164. class_visible_invisible($current_forum['visibility']).'>'.
  165. prepare4display($current_forum['forum_title']).'</a></h1>';
  166. echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
  167. echo '</div>';
  168. /* End new display forum */
  169. // The form for the reply
  170. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  171. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  172. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  173. $values = show_add_post_form(
  174. $current_forum,
  175. $forum_setting,
  176. $my_action,
  177. $my_post,
  178. $my_elements
  179. );
  180. if (!empty($values) AND isset($_POST['SubmitPost'])) {
  181. $result = store_reply($current_forum, $values);
  182. //@todo split the show_add_post_form function
  183. $url = 'viewthread.php?forum='.$current_thread['forum_id'].'&gradebook='.$gradebook.'&thread='.intval($_GET['thread']).'&gidReq='.api_get_group_id().'&origin='.$origin.'&msg='.$result['msg'].'&type='.$result['type'];
  184. echo '
  185. <script>
  186. window.location = "'.$url.'";
  187. </script>';
  188. }
  189. if (isset($origin) && $origin != 'learnpath') {
  190. Display :: display_footer();
  191. }