newthread.php 6.8 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. * @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. // javascript
  43. $htmlHeadXtra[] = '<script>
  44. function advanced_parameters() {
  45. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  46. document.getElementById(\'id_qualify\').style.display = \'block\';
  47. 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').'\';
  48. } else {
  49. document.getElementById(\'id_qualify\').style.display = \'none\';
  50. 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').'\';
  51. }
  52. }
  53. </script>';
  54. /* MAIN DISPLAY SECTION */
  55. /* Retrieving forum and forum category information */
  56. $current_forum = get_forum_information($_GET['forum']); // Note: This has to be validated that it is an existing forum.
  57. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  58. /* Breadcrumbs */
  59. if (isset($_SESSION['gradebook'])){
  60. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  61. }
  62. if (!empty($gradebook) && $gradebook == 'view') {
  63. $interbreadcrumb[] = array (
  64. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  65. 'name' => get_lang('ToolGradebook')
  66. );
  67. }
  68. if (!empty($_GET['gidReq'])) {
  69. $toolgroup = intval($_GET['gidReq']);
  70. Session::write('toolgroup',$toolgroup);
  71. }
  72. /* Is the user allowed here? */
  73. // The user is not allowed here if:
  74. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  75. if (!api_is_allowed_to_edit(false, true) && (($current_forum_category['visibility'] && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)) {
  76. api_not_allowed();
  77. }
  78. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  79. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category['visibility'] && $current_forum_category['locked'] <> 0) OR $current_forum['locked'] <> 0)) {
  80. api_not_allowed();
  81. }
  82. // 3. new threads are not allowed and the user is not a course manager
  83. if (!api_is_allowed_to_edit(false, true) AND $current_forum['allow_new_threads'] <> 1) {
  84. api_not_allowed();
  85. }
  86. // 4. anonymous posts are not allowed and the user is not logged in
  87. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] <> 1) {
  88. api_not_allowed();
  89. }
  90. // 5. Check user access
  91. if ($current_forum['forum_of_group'] != 0) {
  92. $show_forum = GroupManager::user_has_access(api_get_user_id(), $current_forum['forum_of_group'], GroupManager::GROUP_TOOL_FORUM);
  93. if (!$show_forum) {
  94. api_not_allowed();
  95. }
  96. }
  97. $session_toolgroup = 0;
  98. if ($origin == 'group') {
  99. $session_toolgroup = intval($_SESSION['toolgroup']);
  100. $group_properties = GroupManager :: get_group_properties($session_toolgroup);
  101. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  102. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$session_toolgroup, 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  103. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;gidReq='.$session_toolgroup.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  104. $interbreadcrumb[] = array('url' => 'newthread.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']),'name' => get_lang('NewTopic'));
  105. } else {
  106. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook, 'name' => $nameTools);
  107. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => $current_forum_category['cat_title']);
  108. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  109. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewTopic'));
  110. }
  111. /* Resource Linker */
  112. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  113. $_SESSION['formelements'] = $_POST;
  114. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  115. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  116. header('Location: ../resourcelinker/resourcelinker.php');
  117. }
  118. /* Header */
  119. if ($origin == 'learnpath') {
  120. Display::display_reduced_header();
  121. } else {
  122. Display :: display_header(null);
  123. //api_display_tool_title($nameTools);
  124. }
  125. /* Display forms / Feedback Messages */
  126. handle_forum_and_forumcategories();
  127. // Action links
  128. echo '<div class="actions">';
  129. echo '<span style="float:right;">'.search_link().'</span>';
  130. echo '<a href="viewforum.php?origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'">'.Display::return_icon('back.png',get_lang('BackToForum'),'',ICON_SIZE_MEDIUM).'</a>';
  131. echo '</div>';
  132. $values = show_add_post_form('newthread', '', isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null);
  133. if (!empty($values) && isset($values['SubmitPost'])) {
  134. // Add new thread in table forum_thread.
  135. store_thread($values);
  136. }
  137. /* FOOTER */
  138. if ($origin != 'learnpath') {
  139. Display :: display_footer();
  140. }