editpost.php 10 KB

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