reply.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. * @package chamilo.forum
  18. */
  19. // Language files that need to be included.
  20. $language_file = array('forum', 'document');
  21. // Including the global initialization file.
  22. require_once '../inc/global.inc.php';
  23. // The section (tabs).
  24. $this_section = SECTION_COURSES;
  25. // Notification for unauthorized people.
  26. api_protect_course_script(true);
  27. $nameTools = get_lang('ForumCategories');
  28. $origin = '';
  29. if (isset($_GET['origin'])) {
  30. $origin = Security::remove_XSS($_GET['origin']);
  31. $origin_string = '&amp;origin='.$origin;
  32. }
  33. /* Including necessary files */
  34. require_once 'forumconfig.inc.php';
  35. require_once 'forumfunction.inc.php';
  36. // javascript
  37. $htmlHeadXtra[] = '<script>
  38. function advanced_parameters() {
  39. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  40. document.getElementById(\'id_qualify\').style.display = \'block\';
  41. 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').'\';
  42. } else {
  43. document.getElementById(\'id_qualify\').style.display = \'none\';
  44. 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').'\';
  45. }
  46. }
  47. </script>';
  48. /* MAIN DISPLAY SECTION */
  49. /* Retrieving forum and forum categorie information */
  50. // We are getting all the information about the current forum and forum category.
  51. // Note pcool: I tried to use only one sql statement (and function) for this,
  52. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  53. $current_thread = get_thread_information($_GET['thread']); // Note: This has to be validated that it is an existing thread.
  54. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
  55. $current_forum_category = get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
  56. /* Is the user allowed here? */
  57. // The user is not allowed here if
  58. // 1. the forumcategory, forum or thread is invisible (visibility==0
  59. // 2. the forumcategory, forum or thread is locked (locked <>0)
  60. // 3. if anonymous posts are not allowed
  61. // The only exception is the course manager
  62. // I have split this is several pieces for clarity.
  63. //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))) {
  64. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category && $current_forum_category['visibility'] == 0) OR $current_forum['visibility'] == 0)) {
  65. api_not_allowed();
  66. }
  67. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category && $current_forum_category['locked'] <> 0) OR $current_forum['locked'] <> 0 OR $current_thread['locked'] <> 0)) {
  68. api_not_allowed();
  69. }
  70. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] == 0) {
  71. api_not_allowed();
  72. }
  73. if ($current_forum['forum_of_group'] != 0) {
  74. $show_forum = GroupManager::user_has_access(api_get_user_id(), $current_forum['forum_of_group'], GroupManager::GROUP_TOOL_FORUM);
  75. if (!$show_forum) {
  76. api_not_allowed();
  77. }
  78. }
  79. /* Breadcrumbs */
  80. if (isset($_SESSION['gradebook'])){
  81. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  82. }
  83. if (!empty($gradebook) && $gradebook == 'view') {
  84. $interbreadcrumb[] = array (
  85. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  86. 'name' => get_lang('ToolGradebook')
  87. );
  88. }
  89. if ($origin == 'group') {
  90. $_clean['toolgroup'] = (int)$_SESSION['toolgroup'];
  91. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  92. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  93. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['toolgroup'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  94. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  95. $interbreadcrumb[] = array('url' => 'viewthread.php?origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']), 'name' => $current_thread['thread_title']);
  96. $interbreadcrumb[] = array('url' => 'javascript: void(0);', 'name' => get_lang('Reply'));
  97. } else {
  98. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook, 'name' => $nameTools);
  99. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => $current_forum_category['cat_title']);
  100. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  101. $interbreadcrumb[] = array('url' => 'viewthread.php?origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']), 'name' => $current_thread['thread_title']);
  102. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
  103. }
  104. /* Resource Linker */
  105. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  106. $_SESSION['formelements'] = $_POST;
  107. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  108. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  109. header('Location: ../resourcelinker/resourcelinker.php');
  110. exit;
  111. }
  112. /* Header */
  113. if ($origin == 'learnpath') {
  114. Display :: display_reduced_header('');
  115. } else {
  116. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
  117. Display :: display_header('');
  118. }
  119. /* Action links */
  120. if ($origin != 'learnpath') {
  121. echo '<div class="actions">';
  122. echo '<span style="float:right;">'.search_link().'</span>';
  123. echo '<a href="viewthread.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;origin='.$origin.'">'.Display::return_icon('back.png', get_lang('BackToThread'), '', ICON_SIZE_MEDIUM).'</a>';
  124. echo '</div>';
  125. } else {
  126. echo '<div style="height:15px">&nbsp;</div>';
  127. }
  128. // The form for the reply
  129. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  130. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  131. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  132. $values = show_add_post_form($my_action, $my_post, $my_elements); // Note: This has to be cleaned first.
  133. if (!empty($values) AND isset($_POST['SubmitPost'])) {
  134. $result = store_reply($values);
  135. //@todo split the show_add_post_form function
  136. $url = 'viewthread.php?forum='.$current_thread['forum_id'].'&gradebook='.$gradebook.'&thread='.intval($_GET['thread']).'&gidReq='.api_get_group_id().'&origin='.$origin.'&msg='.$result['msg'].'&type='.$result['type'];
  137. echo '
  138. <script>
  139. window.location = "'.$url.'";
  140. </script>';
  141. }
  142. if ($origin != 'learnpath') {
  143. Display :: display_footer();
  144. }