editpost.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  18. * @Copyright Ghent University
  19. * @Copyright Patrick Cool
  20. *
  21. * @package chamilo.forum
  22. */
  23. require_once __DIR__.'/../inc/global.inc.php';
  24. // The section (tabs).
  25. $this_section = SECTION_COURSES;
  26. // Notification for unauthorized people.
  27. api_protect_course_script(true);
  28. $nameTools = get_lang('ToolForum');
  29. // Unset the formElements in session before the includes function works
  30. unset($_SESSION['formelements']);
  31. /* Including necessary files */
  32. require_once 'forumconfig.inc.php';
  33. require_once 'forumfunction.inc.php';
  34. // Are we in a lp ?
  35. $origin = api_get_origin();
  36. /* MAIN DISPLAY SECTION */
  37. /* Retrieving forum and forum category information */
  38. // We are getting all the information about the current forum and forum category.
  39. // Note pcool: I tried to use only one sql statement (and function) for this,
  40. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  41. $current_thread = get_thread_information($_GET['forum'], $_GET['thread']);
  42. $current_forum = get_forum_information($_GET['forum']);
  43. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  44. $current_post = get_post_information($_GET['post']);
  45. if (empty($current_post)) {
  46. api_not_allowed(true);
  47. }
  48. api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
  49. $isEditable = postIsEditableByStudent($current_forum, $current_post);
  50. if (!$isEditable) {
  51. api_not_allowed(true);
  52. }
  53. /* Header and Breadcrumbs */
  54. if (isset($_SESSION['gradebook'])) {
  55. $gradebook = $_SESSION['gradebook'];
  56. }
  57. if (!empty($gradebook) && $gradebook == 'view') {
  58. $interbreadcrumb[] = array(
  59. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  60. 'name' => get_lang('ToolGradebook')
  61. );
  62. }
  63. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  64. if ($origin == 'group') {
  65. $_clean['toolgroup'] = api_get_group_id();
  66. $interbreadcrumb[] = array(
  67. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  68. 'name' => get_lang('Groups'),
  69. );
  70. $interbreadcrumb[] = array(
  71. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  72. 'name' => get_lang('GroupSpace').' '.$group_properties['name'],
  73. );
  74. $interbreadcrumb[] = array(
  75. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']),
  76. 'name' => prepare4display($current_forum['forum_title']),
  77. );
  78. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  79. } else {
  80. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(), 'name' => $nameTools);
  81. $interbreadcrumb[] = array(
  82. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
  83. 'name' => prepare4display($current_forum_category['cat_title'])
  84. );
  85. $interbreadcrumb[] = array(
  86. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
  87. 'name' => prepare4display($current_forum['forum_title'])
  88. );
  89. $interbreadcrumb[] = array(
  90. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']),
  91. 'name' => prepare4display($current_thread['thread_title'])
  92. );
  93. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  94. }
  95. $table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  96. /* Header */
  97. $htmlHeadXtra[] = <<<JS
  98. <script>
  99. $(document).on('ready', function() {
  100. $('#reply-add-attachment').on('click', function(e) {
  101. e.preventDefault();
  102. var newInputFile = $('<input>', {
  103. type: 'file',
  104. name: 'user_upload[]'
  105. });
  106. $('[name="user_upload[]"]').parent().append(newInputFile);
  107. });
  108. });
  109. </script>
  110. JS;
  111. /* Is the user allowed here? */
  112. // The user is not allowed here if
  113. // 1. the forum category, forum or thread is invisible (visibility==0)
  114. // 2. the forum category, forum or thread is locked (locked <>0)
  115. // 3. if anonymous posts are not allowed
  116. // 4. if editing of replies is not allowed
  117. // The only exception is the course manager
  118. // I have split this is several pieces for clarity.
  119. if (!api_is_allowed_to_edit(null, true) &&
  120. (
  121. ($current_forum_category && $current_forum_category['visibility'] == 0) ||
  122. $current_forum['visibility'] == 0
  123. )
  124. ) {
  125. api_not_allowed(true);
  126. }
  127. if (!api_is_allowed_to_edit(null, true) &&
  128. (
  129. ($current_forum_category && $current_forum_category['locked'] <> 0) ||
  130. $current_forum['locked'] <> 0 ||
  131. $current_thread['locked'] <> 0
  132. )
  133. ) {
  134. api_not_allowed(true);
  135. }
  136. if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
  137. api_not_allowed(true);
  138. }
  139. $group_id = api_get_group_id();
  140. if (!api_is_allowed_to_edit(null, true) &&
  141. $current_forum['allow_edit'] == 0 &&
  142. !GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties)
  143. ) {
  144. api_not_allowed(true);
  145. }
  146. if ($origin == 'learnpath') {
  147. Display::display_reduced_header();
  148. } else {
  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. if ($origin == 'group') {
  156. echo '<a href="../group/group_space.php?'.api_get_cidreq().'">'.
  157. Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('Groups'), '', ICON_SIZE_MEDIUM).'</a>';
  158. } else {
  159. echo '<a href="index.php?'.api_get_cidreq().'">'.
  160. Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  161. }
  162. echo '<a href="viewforum.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq().'">'.
  163. Display::return_icon('forum.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
  164. echo '</div>';
  165. }
  166. /* Display Forum Category and the Forum information */
  167. /*New display forum div*/
  168. echo '<div class="forum_title">';
  169. echo '<h1>';
  170. echo Display::url(
  171. prepare4display($current_forum['forum_title']),
  172. 'viewforum.php?'.api_get_cidreq().'&'.http_build_query([
  173. 'origin' => $origin,
  174. 'forum' => $current_forum['forum_id']
  175. ]),
  176. ['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
  177. );
  178. echo '</h1>';
  179. echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
  180. echo '</div>';
  181. /* End new display forum */
  182. // Set forum attachment data into $_SESSION
  183. getAttachedFiles(
  184. $current_forum['forum_id'],
  185. $current_thread['thread_id'],
  186. $current_post['post_id']
  187. );
  188. show_edit_post_form(
  189. $forum_setting,
  190. $current_post,
  191. $current_thread,
  192. $current_forum,
  193. isset($_SESSION['formelements']) ? $_SESSION['formelements'] : ''
  194. );
  195. // Footer
  196. if (isset($origin) && $origin == 'learnpath') {
  197. Display::display_reduced_footer();
  198. } else {
  199. Display::display_footer();
  200. }