editpost.php 9.4 KB

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