editpost.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. if (api_is_in_gradebook()) {
  54. $interbreadcrumb[] = array(
  55. 'url' => Category::getUrl(),
  56. 'name' => get_lang('ToolGradebook')
  57. );
  58. }
  59. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  60. if ($origin == 'group') {
  61. $_clean['toolgroup'] = api_get_group_id();
  62. $interbreadcrumb[] = array(
  63. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  64. 'name' => get_lang('Groups'),
  65. );
  66. $interbreadcrumb[] = array(
  67. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  68. 'name' => get_lang('GroupSpace').' '.$group_properties['name'],
  69. );
  70. $interbreadcrumb[] = array(
  71. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']),
  72. 'name' => prepare4display($current_forum['forum_title']),
  73. );
  74. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  75. } else {
  76. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(), 'name' => $nameTools);
  77. $interbreadcrumb[] = array(
  78. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
  79. 'name' => prepare4display($current_forum_category['cat_title'])
  80. );
  81. $interbreadcrumb[] = array(
  82. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
  83. 'name' => prepare4display($current_forum['forum_title'])
  84. );
  85. $interbreadcrumb[] = array(
  86. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']),
  87. 'name' => prepare4display($current_thread['thread_title'])
  88. );
  89. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  90. }
  91. $table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  92. /* Header */
  93. $htmlHeadXtra[] = <<<JS
  94. <script>
  95. $(document).on('ready', function() {
  96. $('#reply-add-attachment').on('click', function(e) {
  97. e.preventDefault();
  98. var newInputFile = $('<input>', {
  99. type: 'file',
  100. name: 'user_upload[]'
  101. });
  102. $('[name="user_upload[]"]').parent().append(newInputFile);
  103. });
  104. });
  105. </script>
  106. JS;
  107. /* Is the user allowed here? */
  108. // The user is not allowed here if
  109. // 1. the forum category, forum or thread is invisible (visibility==0)
  110. // 2. the forum category, forum or thread is locked (locked <>0)
  111. // 3. if anonymous posts are not allowed
  112. // 4. if editing of replies is not allowed
  113. // The only exception is the course manager
  114. // I have split this is several pieces for clarity.
  115. if (!api_is_allowed_to_edit(null, true) &&
  116. (
  117. ($current_forum_category && $current_forum_category['visibility'] == 0) ||
  118. $current_forum['visibility'] == 0
  119. )
  120. ) {
  121. api_not_allowed(true);
  122. }
  123. if (!api_is_allowed_to_edit(null, true) &&
  124. (
  125. ($current_forum_category && $current_forum_category['locked'] <> 0) ||
  126. $current_forum['locked'] <> 0 ||
  127. $current_thread['locked'] <> 0
  128. )
  129. ) {
  130. api_not_allowed(true);
  131. }
  132. if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
  133. api_not_allowed(true);
  134. }
  135. $group_id = api_get_group_id();
  136. if (!api_is_allowed_to_edit(null, true) &&
  137. $current_forum['allow_edit'] == 0 &&
  138. !GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties)
  139. ) {
  140. api_not_allowed(true);
  141. }
  142. if ($origin == 'learnpath') {
  143. Display::display_reduced_header();
  144. } else {
  145. Display::display_header();
  146. }
  147. // Action links
  148. if ($origin != 'learnpath') {
  149. echo '<div class="actions">';
  150. echo '<span style="float:right;">'.search_link().'</span>';
  151. if ($origin == 'group') {
  152. echo '<a href="../group/group_space.php?'.api_get_cidreq().'">'.
  153. Display::return_icon(
  154. 'back.png',
  155. get_lang('BackTo').' '.get_lang('Groups'),
  156. '',
  157. ICON_SIZE_MEDIUM
  158. ).
  159. '</a>';
  160. } else {
  161. echo '<a href="index.php?'.api_get_cidreq().'">'.
  162. Display::return_icon(
  163. 'back.png',
  164. get_lang('BackToForumOverview'),
  165. '',
  166. ICON_SIZE_MEDIUM
  167. ).
  168. '</a>';
  169. }
  170. echo '<a href="viewforum.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq().'">'.
  171. Display::return_icon(
  172. 'forum.png',
  173. get_lang('BackToForum'),
  174. '',
  175. ICON_SIZE_MEDIUM
  176. ).
  177. '</a>';
  178. echo '</div>';
  179. }
  180. /* Display Forum Category and the Forum information */
  181. /*New display forum div*/
  182. echo '<div class="forum_title">';
  183. echo '<h1>';
  184. echo Display::url(
  185. prepare4display($current_forum['forum_title']),
  186. 'viewforum.php?'.api_get_cidreq().'&'.http_build_query([
  187. 'origin' => $origin,
  188. 'forum' => $current_forum['forum_id']
  189. ]),
  190. ['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
  191. );
  192. echo '</h1>';
  193. echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
  194. echo '</div>';
  195. /* End new display forum */
  196. // Set forum attachment data into $_SESSION
  197. getAttachedFiles(
  198. $current_forum['forum_id'],
  199. $current_thread['thread_id'],
  200. $current_post['post_id']
  201. );
  202. show_edit_post_form(
  203. $forum_setting,
  204. $current_post,
  205. $current_thread,
  206. $current_forum,
  207. isset($_SESSION['formelements']) ? $_SESSION['formelements'] : ''
  208. );
  209. // Footer
  210. if (isset($origin) && $origin == 'learnpath') {
  211. Display::display_reduced_footer();
  212. } else {
  213. Display::display_footer();
  214. }