editpost.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * These files are a complete rework of the forum. The database structure is
  6. * based on phpBB but all the code is rewritten. A lot of new functionalities
  7. * are added:
  8. * - forum categories and forums can be sorted up or down, locked or made invisible
  9. * - consistent and integrated forum administration
  10. * - forum options: are students allowed to edit their post?
  11. * moderation of posts (approval)
  12. * reply only forums (students cannot create new threads)
  13. * multiple forums per group
  14. * - sticky messages
  15. * - new view option: nested view
  16. * - quoting a message
  17. *
  18. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  19. * @Copyright Ghent University
  20. * @Copyright Patrick Cool
  21. *
  22. * @package chamilo.forum
  23. */
  24. // Including the global initialization file.
  25. //require_once '../inc/global.inc.php';
  26. // The section (tabs).
  27. $this_section = SECTION_COURSES;
  28. // Notification for unauthorized people.
  29. api_protect_course_script(true);
  30. $nameTools = get_lang('ToolForum');
  31. /* Including necessary files */
  32. require_once 'forumconfig.inc.php';
  33. require_once 'forumfunction.inc.php';
  34. $origin = '';
  35. if (isset($_GET['origin'])) {
  36. $origin = Security::remove_XSS($_GET['origin']);
  37. }
  38. /* MAIN DISPLAY SECTION */
  39. /* Retrieving forum and forum category information */
  40. // We are getting all the information about the current forum and forum category.
  41. // Note pcool: I tried to use only one sql statement (and function) for this,
  42. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  43. $current_thread = get_thread_information($_GET['thread']);
  44. $current_forum = get_forum_information($_GET['forum']);
  45. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  46. $current_post = get_post_information($_GET['post']);
  47. api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
  48. $em = Database::getManager();
  49. /* Header and Breadcrumbs */
  50. if (api_is_in_gradebook()) {
  51. $interbreadcrumb[]= array(
  52. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  53. 'name' => get_lang('ToolGradebook')
  54. );
  55. }
  56. $groupId = api_get_group_id();
  57. if (!empty($groupId)) {
  58. $group_properties = GroupManager::get_group_properties($groupId);
  59. $interbreadcrumb[] = array(
  60. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  61. 'name' => get_lang('Groups'),
  62. );
  63. $interbreadcrumb[] = array(
  64. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  65. 'name' => get_lang('GroupSpace').' '.$group_properties['name'],
  66. );
  67. $interbreadcrumb[] = array(
  68. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']),
  69. 'name' => prepare4display($current_forum['forum_title']),
  70. );
  71. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  72. } else {
  73. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(), 'name' => $nameTools);
  74. $interbreadcrumb[] = array(
  75. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
  76. 'name' => prepare4display($current_forum_category['cat_title'])
  77. );
  78. $interbreadcrumb[] = array(
  79. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq(),
  80. 'name' => prepare4display($current_forum['forum_title'])
  81. );
  82. $interbreadcrumb[] = array(
  83. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']),
  84. 'name' => prepare4display($current_thread['thread_title'])
  85. );
  86. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  87. }
  88. $table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  89. /* Header */
  90. $htmlHeadXtra[] = <<<JS
  91. <script>
  92. $(document).on('ready', function() {
  93. $('#reply-add-attachment').on('click', function(e) {
  94. e.preventDefault();
  95. var newInputFile = $('<input>', {
  96. type: 'file',
  97. name: 'user_upload[]'
  98. });
  99. $('[name="user_upload[]"]').parent().append(newInputFile);
  100. });
  101. });
  102. </script>
  103. JS;
  104. if ($origin == 'learnpath') {
  105. Display::display_reduced_header();
  106. } else {
  107. Display::display_header();
  108. }
  109. /* Is the user allowed here? */
  110. // The user is not allowed here if
  111. // 1. the forum category, forum or thread is invisible (visibility==0)
  112. // 2. the forum category, forum or thread is locked (locked <>0)
  113. // 3. if anonymous posts are not allowed
  114. // 4. if editing of replies is not allowed
  115. // The only exception is the course manager
  116. // I have split this is several pieces for clarity.
  117. //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))) {
  118. if (!api_is_allowed_to_edit(null, true) &&
  119. (($current_forum_category && $current_forum_category['visibility'] == 0) ||
  120. $current_forum['visibility'] == 0)
  121. ) {
  122. $forum_allow = forum_not_allowed_here();
  123. if ($forum_allow === false) {
  124. exit;
  125. }
  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. $forum_allow = forum_not_allowed_here();
  135. if ($forum_allow === false) {
  136. exit;
  137. }
  138. }
  139. if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
  140. $forum_allow = forum_not_allowed_here();
  141. if ($forum_allow === false) {
  142. exit;
  143. }
  144. }
  145. $group_id = api_get_group_id();
  146. if (!api_is_allowed_to_edit(null, true) &&
  147. $current_forum['allow_edit'] == 0 &&
  148. !GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties['iid'])
  149. ) {
  150. $forum_allow = forum_not_allowed_here();
  151. if ($forum_allow === false) {
  152. exit;
  153. }
  154. }
  155. // Action links
  156. if ($origin != 'learnpath') {
  157. echo '<div class="actions">';
  158. echo '<span style="float:right;">'.search_link().'</span>';
  159. if ($origin == 'group') {
  160. echo '<a href="../group/group_space.php?'.api_get_cidreq().'">'.
  161. Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('Groups'), '', ICON_SIZE_MEDIUM).'</a>';
  162. } else {
  163. echo '<a href="index.php?'.api_get_cidreq().'">'.
  164. Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  165. }
  166. echo '<a href="viewforum.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq().'&origin='.$origin.'">'.
  167. Display::return_icon('forum.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
  168. echo '</div>';
  169. }
  170. /* Display Forum Category and the Forum information */
  171. /*New display forum div*/
  172. echo '<div class="forum_title">';
  173. echo '<h1>';
  174. echo Display::url(
  175. prepare4display($current_forum['forum_title']),
  176. 'viewforum.php?' . api_get_cidreq() . '&' . http_build_query([
  177. 'origin' => $origin,
  178. 'forum' => $current_forum['forum_id']
  179. ]),
  180. ['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
  181. );
  182. echo '</h1>';
  183. echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
  184. echo '</div>';
  185. /* End new display forum */
  186. // Set forum attachment data into $_SESSION
  187. getAttachedFiles(
  188. $current_forum['forum_id'],
  189. $current_thread['thread_id'],
  190. $current_post['post_id']
  191. );
  192. $values = show_edit_post_form(
  193. $forum_setting,
  194. $current_post,
  195. $current_thread,
  196. $current_forum,
  197. isset($_SESSION['formelements']) ? $_SESSION['formelements'] : ''
  198. );
  199. if (!empty($values) and isset($_POST['SubmitPost'])) {
  200. store_edit_post($current_forum, $values);
  201. }
  202. // Footer
  203. if (isset($origin) && $origin == 'learnpath') {
  204. Display::display_reduced_footer();
  205. } else {
  206. Display::display_footer();
  207. }