newthread.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. use \ChamiloSession as Session;
  24. // Language file that need to be included.
  25. $language_file = array('forum', 'document', '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. // The section (tabs).
  30. $this_section = SECTION_COURSES;
  31. // Notification for unauthorized people.
  32. api_protect_course_script(true);
  33. $nameTools = get_lang('ToolForum');
  34. /* Including necessary files */
  35. require_once 'forumconfig.inc.php';
  36. require_once 'forumfunction.inc.php';
  37. // Are we in a lp ?
  38. $origin = '';
  39. if (isset($_GET['origin'])) {
  40. $origin = Security::remove_XSS($_GET['origin']);
  41. }
  42. /* MAIN DISPLAY SECTION */
  43. /* Retrieving forum and forum category information */
  44. $current_forum = get_forum_information($_GET['forum']); // Note: This has to be validated that it is an existing forum.
  45. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  46. /* Breadcrumbs */
  47. if (isset($_SESSION['gradebook'])){
  48. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  49. }
  50. if (!empty($gradebook) && $gradebook == 'view') {
  51. $interbreadcrumb[] = array (
  52. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  53. 'name' => get_lang('ToolGradebook')
  54. );
  55. }
  56. if (!empty($_GET['gidReq'])) {
  57. $toolgroup = intval($_GET['gidReq']);
  58. Session::write('toolgroup',$toolgroup);
  59. }
  60. /* Is the user allowed here? */
  61. // The user is not allowed here if:
  62. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  63. if (!api_is_allowed_to_edit(false, true) && (($current_forum_category['visibility'] && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)) {
  64. api_not_allowed();
  65. }
  66. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  67. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category['visibility'] && $current_forum_category['locked'] <> 0) OR $current_forum['locked'] <> 0)) {
  68. api_not_allowed();
  69. }
  70. // 3. new threads are not allowed and the user is not a course manager
  71. if (!api_is_allowed_to_edit(false, true) AND $current_forum['allow_new_threads'] <> 1) {
  72. api_not_allowed();
  73. }
  74. // 4. anonymous posts are not allowed and the user is not logged in
  75. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] <> 1) {
  76. api_not_allowed();
  77. }
  78. // 5. Check user access
  79. if ($current_forum['forum_of_group'] != 0) {
  80. $show_forum = GroupManager::user_has_access(api_get_user_id(), $current_forum['forum_of_group'], GroupManager::GROUP_TOOL_FORUM);
  81. if (!$show_forum) {
  82. api_not_allowed();
  83. }
  84. }
  85. $session_toolgroup = 0;
  86. if ($origin == 'group') {
  87. $session_toolgroup = intval($_SESSION['toolgroup']);
  88. $group_properties = GroupManager :: get_group_properties($session_toolgroup);
  89. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  90. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$session_toolgroup, 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  91. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;gidReq='.$session_toolgroup.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  92. $interbreadcrumb[] = array('url' => 'newthread.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']),'name' => get_lang('NewTopic'));
  93. } else {
  94. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook, 'name' => $nameTools);
  95. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => $current_forum_category['cat_title']);
  96. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  97. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewTopic'));
  98. }
  99. /* Resource Linker */
  100. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  101. $_SESSION['formelements'] = $_POST;
  102. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  103. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  104. header('Location: ../resourcelinker/resourcelinker.php');
  105. }
  106. /* Header */
  107. if ($origin == 'learnpath') {
  108. Display::display_reduced_header();
  109. } else {
  110. Display :: display_header(null);
  111. }
  112. handle_forum_and_forumcategories();
  113. // Action links
  114. echo '<div class="actions">';
  115. echo '<span style="float:right;">'.search_link().'</span>';
  116. echo '<a href="viewforum.php?origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']).'&'.api_get_cidreq().'">'.Display::return_icon('back.png',get_lang('BackToForum'),'',ICON_SIZE_MEDIUM).'</a>';
  117. echo '</div>';
  118. $values = show_add_post_form($current_forum, $forum_setting, 'newthread', '', isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null);
  119. if (!empty($values) && isset($values['SubmitPost'])) {
  120. // Add new thread in table forum_thread.
  121. store_thread($current_forum, $values);
  122. }
  123. /* FOOTER */
  124. if ($origin != 'learnpath') {
  125. Display :: display_footer();
  126. }