editpost.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. /* INIT SECTION */
  24. // Language files that need to be included.
  25. $language_file = array('forum', 'group', 'gradebook');
  26. // Including the global initialization file.
  27. //require_once '../inc/global.inc.php';
  28. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  29. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
  30. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
  31. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
  32. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  33. // The section (tabs).
  34. $this_section = SECTION_COURSES;
  35. // Notification for unauthorized people.
  36. api_protect_course_script(true);
  37. $nameTools = get_lang('ToolForum');
  38. /* Including necessary files */
  39. require_once 'forumconfig.inc.php';
  40. require_once 'forumfunction.inc.php';
  41. $origin = '';
  42. if (isset($_GET['origin'])) {
  43. $origin = Security::remove_XSS($_GET['origin']);
  44. }
  45. /* MAIN DISPLAY SECTION */
  46. /* Retrieving forum and forum category information */
  47. // We are getting all the information about the current forum and forum category.
  48. // Note pcool: I tried to use only one sql statement (and function) for this,
  49. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  50. $current_thread = get_thread_information($_GET['thread']); // Note: This has to be validated that it is an existing thread.
  51. $current_forum = get_forum_information($_GET['forum']); // Note: This has to be validated that it is an existing forum.
  52. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  53. $current_post = get_post_information($_GET['post']);
  54. api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
  55. /* Header and Breadcrumbs */
  56. if (isset($_SESSION['gradebook'])) {
  57. $gradebook = $_SESSION['gradebook'];
  58. }
  59. if (!empty($gradebook) && $gradebook == 'view') {
  60. $interbreadcrumb[] = array(
  61. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  62. 'name' => get_lang('ToolGradebook')
  63. );
  64. }
  65. if ($origin == 'group') {
  66. $_clean['toolgroup'] = (int) $_SESSION['toolgroup'];
  67. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  68. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  69. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['toolgroup'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  70. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;gidReq='.$_SESSION['toolgroup'].'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title']));
  71. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  72. } else {
  73. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook, 'name' => $nameTools);
  74. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => prepare4display($current_forum_category['cat_title']));
  75. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title']));
  76. $interbreadcrumb[] = array('url' => 'viewthread.php?gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']), 'name' => prepare4display($current_thread['thread_title']));
  77. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  78. }
  79. /* Resource Linker */
  80. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  81. $_SESSION['formelements'] = $_POST;
  82. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  83. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  84. header('Location: ../resourcelinker/resourcelinker.php');
  85. }
  86. $table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  87. /* Header */
  88. // Are we in a lp ?
  89. $origin = '';
  90. if (isset($_GET['origin'])) {
  91. $origin = Security::remove_XSS($_GET['origin']);
  92. }
  93. if ($origin == 'learnpath') {
  94. Display::display_reduced_header();
  95. } else {
  96. Display :: display_header(null);
  97. }
  98. /* Is the user allowed here? */
  99. // The user is not allowed here if
  100. // 1. the forumcategory, forum or thread is invisible (visibility==0)
  101. // 2. the forumcategory, forum or thread is locked (locked <>0)
  102. // 3. if anonymous posts are not allowed
  103. // 4. if editing of replies is not allowed
  104. // The only exception is the course manager
  105. // I have split this is several pieces for clarity.
  106. //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))) {
  107. if (!api_is_allowed_to_edit(null, true) AND (($current_forum_category && $current_forum_category['visibility'] == 0) OR $current_forum['visibility'] == 0)) {
  108. $forum_allow = forum_not_allowed_here();
  109. if ($forum_allow === false) {
  110. exit;
  111. }
  112. }
  113. if (!api_is_allowed_to_edit(null, true) AND (($current_forum_category && $current_forum_category['locked'] <> 0 ) OR $current_forum['locked'] <> 0 OR $current_thread['locked'] <> 0)) {
  114. $forum_allow = forum_not_allowed_here();
  115. if ($forum_allow === false) {
  116. exit;
  117. }
  118. }
  119. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] == 0) {
  120. $forum_allow = forum_not_allowed_here();
  121. if ($forum_allow === false) {
  122. exit;
  123. }
  124. }
  125. $group_id = api_get_group_id();
  126. if (!api_is_allowed_to_edit(null, true) AND $current_forum['allow_edit'] == 0 && !GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)) {
  127. $forum_allow = forum_not_allowed_here();
  128. if ($forum_allow === false) {
  129. exit;
  130. }
  131. }
  132. // Action links
  133. if ($origin != 'learnpath') {
  134. echo '<div class="actions">';
  135. echo '<span style="float:right;">'.search_link().'</span>';
  136. if ($origin == 'group') {
  137. echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('Groups'), '', ICON_SIZE_MEDIUM).'</a>';
  138. } else {
  139. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  140. }
  141. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;origin='.$origin.'">'.Display::return_icon('forum.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
  142. echo '</div>';
  143. }
  144. /* Display Forum Category and the Forum information */
  145. echo "<table class=\"forum_table\" width=\"100%\">";
  146. // The forum category
  147. echo "<tr><th class=\"forum_head\" colspan=\"2\">";
  148. echo '<a href="viewforum.php?&amp;origin='.$origin.'&amp;forum='.$current_forum['forum_id'].'" '.class_visible_invisible($current_forum['visibility']).'>'.prepare4display($current_forum['forum_title']).'</a><br />';
  149. echo '<span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
  150. echo "</th>";
  151. echo "</tr>";
  152. echo '</table>';
  153. // The form for the reply
  154. $values = show_edit_post_form($forum_setting, $current_post, $current_thread, $current_forum, isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '');
  155. if (!empty($values) and isset($_POST['SubmitPost'])) {
  156. store_edit_post($values);
  157. $option_chek = isset($values['thread_qualify_gradebook']) ? $values['thread_qualify_gradebook'] : null; // values 1 or 0
  158. if (1 == $option_chek) {
  159. $id = $values['thread_id'];
  160. $title_gradebook = Security::remove_XSS(stripslashes($values['calification_notebook_title']));
  161. $value_calification = $values['numeric_calification'];
  162. $weight_calification = $values['weight_calification'];
  163. $description = '';
  164. $session_id = api_get_session_id();
  165. $link_info = is_resource_in_course_gradebook(api_get_course_id(), 5, $id, $session_id);
  166. $link_id = $link_info['id'];
  167. if (!$link_info) {
  168. add_resource_to_course_gradebook($values['category_id'], api_get_course_id(), 5, $id, $title_gradebook, $weight_calification, $value_calification, $description, 1, api_get_session_id());
  169. } else {
  170. Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
  171. }
  172. }
  173. }
  174. // Footer
  175. if ($origin != 'learnpath') {
  176. Display :: display_footer();
  177. }