editthread.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Edit a Forum Thread
  6. * @Author José Loguercio <jose.loguercio@beeznest.com>
  7. *
  8. * @package chamilo.forum
  9. */
  10. require_once '../inc/global.inc.php';
  11. // The section (tabs).
  12. $this_section = SECTION_COURSES;
  13. // Notification for unauthorized people.
  14. api_protect_course_script(true);
  15. $cidreq = api_get_cidreq();
  16. $nameTools = get_lang('ToolForum');
  17. /* Including necessary files */
  18. require_once 'forumconfig.inc.php';
  19. require_once 'forumfunction.inc.php';
  20. // Are we in a lp ?
  21. $origin = '';
  22. if (isset($_GET['origin'])) {
  23. $origin = Security::remove_XSS($_GET['origin']);
  24. }
  25. /* MAIN DISPLAY SECTION */
  26. $currentForum = get_forum_information($_GET['forum']);
  27. $currentForumCategory = get_forumcategory_information($currentForum['forum_category']);
  28. // the variable $forum_settings is declared in forumconfig.inc.php
  29. $forumSettings = $forum_setting;
  30. /* Breadcrumbs */
  31. if (isset($_SESSION['gradebook'])) {
  32. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  33. }
  34. if (!empty($gradebook) && $gradebook == 'view') {
  35. $interbreadcrumb[] = array (
  36. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  37. 'name' => get_lang('ToolGradebook')
  38. );
  39. }
  40. $threadId = isset($_GET['thread']) ? intval($_GET['thread']) : 0;
  41. $courseInfo = isset($_GET['cidReq']) ? api_get_course_info($_GET['cidReq']) : 0;
  42. $cId = isset($courseInfo['real_id']) ? intval($courseInfo['real_id']) : 0;
  43. /* Is the user allowed here? */
  44. // The user is not allowed here if:
  45. // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
  46. if (!api_is_allowed_to_edit(false, true) &&
  47. (($currentForumCategory['visibility'] && $currentForumCategory['visibility'] == 0) || $currentForum['visibility'] == 0)
  48. ) {
  49. api_not_allowed();
  50. }
  51. // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
  52. if (!api_is_allowed_to_edit(false, true) &&
  53. (($currentForumCategory['visibility'] && $currentForumCategory['locked'] <> 0) OR $currentForum['locked'] <> 0)
  54. ) {
  55. api_not_allowed();
  56. }
  57. // 3. new threads are not allowed and the user is not a course manager
  58. if (!api_is_allowed_to_edit(false, true) &&
  59. $currentForum['allow_new_threads'] <> 1
  60. ) {
  61. api_not_allowed();
  62. }
  63. // 4. anonymous posts are not allowed and the user is not logged in
  64. if (!$_user['user_id'] && $currentForum['allow_anonymous'] <> 1) {
  65. api_not_allowed();
  66. }
  67. // 5. Check user access
  68. if ($currentForum['forum_of_group'] != 0) {
  69. $show_forum = GroupManager::user_has_access(
  70. api_get_user_id(),
  71. $currentForum['forum_of_group'],
  72. GroupManager::GROUP_TOOL_FORUM
  73. );
  74. if (!$show_forum) {
  75. api_not_allowed();
  76. }
  77. }
  78. // 6. Invited users can't create new threads
  79. if (api_is_invitee()) {
  80. api_not_allowed(true);
  81. }
  82. $groupId = api_get_group_id();
  83. if (!empty($groupId)) {
  84. $groupProperties = GroupManager :: get_group_properties($groupId);
  85. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.$cidreq, 'name' => get_lang('Groups'));
  86. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.$cidreq, 'name' => get_lang('GroupSpace').' '.$groupProperties['name']);
  87. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']), 'name' => $currentForum['forum_title']);
  88. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/newthread.php?'.$cidreq.'&forum='.intval($_GET['forum']),'name' => get_lang('EditThread'));
  89. } else {
  90. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.$cidreq, 'name' => $nameTools);
  91. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.$cidreq.'&forumcategory='.$currentForumCategory['cat_id'], 'name' => $currentForumCategory['cat_title']);
  92. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']), 'name' => $currentForum['forum_title']);
  93. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditThread'));
  94. }
  95. $tableLink = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  96. /* Header */
  97. $htmlHeadXtra[] = <<<JS
  98. <script>
  99. $(document).on('ready', function() {
  100. if ($('#thread_qualify_gradebook').is(':checked') == true) {
  101. document.getElementById('options_field').style.display = 'block';
  102. } else {
  103. document.getElementById('options_field').style.display = 'none';
  104. }
  105. $('#thread_qualify_gradebook').click(function() {
  106. if ($('#thread_qualify_gradebook').is(':checked') == true) {
  107. document.getElementById('options_field').style.display = 'block';
  108. } else {
  109. document.getElementById('options_field').style.display = 'none';
  110. $("[name='numeric_calification']").val(0);
  111. $("[name='calification_notebook_title']").val('');
  112. $("[name='weight_calification']").val(0);
  113. $("[name='thread_peer_qualify'][value='0']").prop('checked', true);
  114. }
  115. });
  116. });
  117. </script>
  118. JS;
  119. if ($origin == 'learnpath') {
  120. Display::display_reduced_header();
  121. } else {
  122. Display :: display_header(null);
  123. }
  124. handle_forum_and_forumcategories();
  125. // Action links
  126. echo '<div class="actions">';
  127. echo '<span style="float:right;">'.search_link().'</span>';
  128. echo '<a href="viewforum.php?forum='.intval($_GET['forum']).'&'.$cidreq.'">'.
  129. Display::return_icon('back.png',get_lang('BackToForum'),'',ICON_SIZE_MEDIUM).'</a>';
  130. echo '</div>';
  131. $threadData = getThreadInfo($threadId, $cId);
  132. $values = showUpdateThreadForm(
  133. $currentForum,
  134. $forumSettings,
  135. $threadData
  136. );
  137. if (!empty($values) && isset($values['SubmitPost'])) {
  138. // update thread in table forum_thread.
  139. updateThread($values);
  140. }
  141. if (isset($origin) && $origin != 'learnpath') {
  142. Display :: display_footer();
  143. }