editpost.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. // javascript
  46. $htmlHeadXtra[] = '<script>
  47. function advanced_parameters() {
  48. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  49. document.getElementById(\'id_qualify\').style.display = \'block\';
  50. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif', get_lang('Hide'), array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  51. } else {
  52. document.getElementById(\'id_qualify\').style.display = \'none\';
  53. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif', get_lang('Show'), array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  54. }
  55. }
  56. </script>';
  57. /* MAIN DISPLAY SECTION */
  58. /* Retrieving forum and forum categorie information */
  59. // We are getting all the information about the current forum and forum category.
  60. // Note pcool: I tried to use only one sql statement (and function) for this,
  61. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  62. $current_thread = get_thread_information($_GET['thread']); // Note: This has to be validated that it is an existing thread.
  63. $current_forum = get_forum_information($_GET['forum']); // Note: This has to be validated that it is an existing forum.
  64. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  65. $current_post = get_post_information($_GET['post']);
  66. api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
  67. /* Header and Breadcrumbs */
  68. if (isset($_SESSION['gradebook'])) {
  69. $gradebook = $_SESSION['gradebook'];
  70. }
  71. if (!empty($gradebook) && $gradebook == 'view') {
  72. $interbreadcrumb[] = array(
  73. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  74. 'name' => get_lang('ToolGradebook')
  75. );
  76. }
  77. if ($origin == 'group') {
  78. $_clean['toolgroup'] = (int) $_SESSION['toolgroup'];
  79. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  80. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  81. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['toolgroup'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  82. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;gidReq='.$_SESSION['toolgroup'].'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title']));
  83. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  84. } else {
  85. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook, 'name' => $nameTools);
  86. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => prepare4display($current_forum_category['cat_title']));
  87. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title']));
  88. $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']));
  89. $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost'));
  90. }
  91. /* Resource Linker */
  92. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  93. $_SESSION['formelements'] = $_POST;
  94. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  95. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  96. header('Location: ../resourcelinker/resourcelinker.php');
  97. }
  98. $table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  99. /* Header */
  100. // Are we in a lp ?
  101. $origin = '';
  102. if (isset($_GET['origin'])) {
  103. $origin = Security::remove_XSS($_GET['origin']);
  104. }
  105. if ($origin == 'learnpath') {
  106. Display::display_reduced_header();
  107. } else {
  108. Display :: display_header(null);
  109. }
  110. /* Is the user allowed here? */
  111. // The user is not allowed here if
  112. // 1. the forumcategory, forum or thread is invisible (visibility==0)
  113. // 2. the forumcategory, forum or thread is locked (locked <>0)
  114. // 3. if anonymous posts are not allowed
  115. // 4. if editing of replies is not allowed
  116. // The only exception is the course manager
  117. // I have split this is several pieces for clarity.
  118. //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))) {
  119. if (!api_is_allowed_to_edit(null, true) AND (($current_forum_category && $current_forum_category['visibility'] == 0) OR $current_forum['visibility'] == 0)) {
  120. $forum_allow = forum_not_allowed_here();
  121. if ($forum_allow === false) {
  122. exit;
  123. }
  124. }
  125. 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)) {
  126. $forum_allow = forum_not_allowed_here();
  127. if ($forum_allow === false) {
  128. exit;
  129. }
  130. }
  131. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] == 0) {
  132. $forum_allow = forum_not_allowed_here();
  133. if ($forum_allow === false) {
  134. exit;
  135. }
  136. }
  137. $group_id = api_get_group_id();
  138. 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)) {
  139. $forum_allow = forum_not_allowed_here();
  140. if ($forum_allow === false) {
  141. exit;
  142. }
  143. }
  144. // Action links
  145. if ($origin != 'learnpath') {
  146. echo '<div class="actions">';
  147. echo '<span style="float:right;">'.search_link().'</span>';
  148. if ($origin == 'group') {
  149. 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>';
  150. } else {
  151. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  152. }
  153. 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>';
  154. echo '</div>';
  155. }
  156. /* Display Forum Category and the Forum information */
  157. echo "<table class=\"forum_table\" width=\"100%\">";
  158. // The forum category
  159. echo "<tr><th class=\"forum_head\" colspan=\"2\">";
  160. 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 />';
  161. echo '<span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
  162. echo "</th>";
  163. echo "</tr>";
  164. echo '</table>';
  165. // The form for the reply
  166. $values = show_edit_post_form($current_post, $current_thread, $current_forum, isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '');
  167. if (!empty($values) and isset($_POST['SubmitPost'])) {
  168. store_edit_post($values);
  169. $option_chek = isset($values['thread_qualify_gradebook']) ? $values['thread_qualify_gradebook'] : null; // values 1 or 0
  170. if (1 == $option_chek) {
  171. $id = $values['thread_id'];
  172. $title_gradebook = Security::remove_XSS(stripslashes($values['calification_notebook_title']));
  173. $value_calification = $values['numeric_calification'];
  174. $weight_calification = $values['weight_calification'];
  175. $description = '';
  176. $session_id = api_get_session_id();
  177. $link_info = is_resource_in_course_gradebook(api_get_course_id(), 5, $id, $session_id);
  178. $link_id = $link_info['id'];
  179. if (!$link_info) {
  180. 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());
  181. } else {
  182. Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
  183. }
  184. }
  185. }
  186. // Footer
  187. if ($origin != 'learnpath') {
  188. Display :: display_footer();
  189. }