editpost.php 8.3 KB

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