reply.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /* MAIN DISPLAY SECTION */
  37. /* Retrieving forum and forum categorie information */
  38. // We are getting all the information about the current forum and forum category.
  39. // Note pcool: I tried to use only one sql statement (and function) for this,
  40. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  41. $current_thread = get_thread_information($_GET['thread']); // Note: This has to be validated that it is an existing thread.
  42. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
  43. $current_forum_category = get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
  44. /* Is the user allowed here? */
  45. // The user is not allowed here if
  46. // 1. the forumcategory, forum or thread is invisible (visibility==0
  47. // 2. the forumcategory, forum or thread is locked (locked <>0)
  48. // 3. if anonymous posts are not allowed
  49. // The only exception is the course manager
  50. // I have split this is several pieces for clarity.
  51. //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))) {
  52. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category && $current_forum_category['visibility'] == 0) OR $current_forum['visibility'] == 0)) {
  53. api_not_allowed();
  54. }
  55. 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)) {
  56. api_not_allowed();
  57. }
  58. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] == 0) {
  59. api_not_allowed();
  60. }
  61. if ($current_forum['forum_of_group'] != 0) {
  62. $show_forum = GroupManager::user_has_access(api_get_user_id(), $current_forum['forum_of_group'], GroupManager::GROUP_TOOL_FORUM);
  63. if (!$show_forum) {
  64. api_not_allowed();
  65. }
  66. }
  67. /* Breadcrumbs */
  68. $gradebook = null;
  69. if (isset($_SESSION['gradebook'])){
  70. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  71. }
  72. if (!empty($gradebook) && $gradebook == 'view') {
  73. $interbreadcrumb[] = array (
  74. 'url' => '../gradebook/'.Security::remove_XSS($_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;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  84. $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']);
  85. $interbreadcrumb[] = array('url' => 'javascript: void(0);', 'name' => get_lang('Reply'));
  86. } else {
  87. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook, 'name' => $nameTools);
  88. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => $current_forum_category['cat_title']);
  89. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  90. $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']);
  91. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
  92. }
  93. /* Resource Linker */
  94. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  95. $_SESSION['formelements'] = $_POST;
  96. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  97. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  98. header('Location: ../resourcelinker/resourcelinker.php');
  99. exit;
  100. }
  101. /* Header */
  102. if ($origin == 'learnpath') {
  103. Display :: display_reduced_header('');
  104. } else {
  105. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
  106. Display :: display_header('');
  107. }
  108. /* Action links */
  109. if ($origin != 'learnpath') {
  110. echo '<div class="actions">';
  111. echo '<span style="float:right;">'.search_link().'</span>';
  112. 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>';
  113. echo '</div>';
  114. } else {
  115. echo '<div style="height:15px">&nbsp;</div>';
  116. }
  117. // The form for the reply
  118. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  119. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  120. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  121. $values = show_add_post_form($current_forum, $forum_setting, $my_action, $my_post, $my_elements);
  122. if (!empty($values) AND isset($_POST['SubmitPost'])) {
  123. $result = store_reply($current_forum, $values);
  124. //@todo split the show_add_post_form function
  125. $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'];
  126. echo '
  127. <script>
  128. window.location = "'.$url.'";
  129. </script>';
  130. }
  131. if ($origin != 'learnpath') {
  132. Display :: display_footer();
  133. }