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