1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Display the course home page.
|
|
|
19 |
*
|
|
|
20 |
* @copyright 1999 Martin Dougiamas http://dougiamas.com
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
* @package core_course
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once('../config.php');
|
|
|
26 |
require_once('lib.php');
|
1220 |
ariadna |
27 |
require_once($CFG->libdir . '/completionlib.php');
|
1 |
efrain |
28 |
|
|
|
29 |
redirect_if_major_upgrade_required();
|
|
|
30 |
|
|
|
31 |
$id = optional_param('id', 0, PARAM_INT);
|
|
|
32 |
$name = optional_param('name', '', PARAM_TEXT);
|
|
|
33 |
$edit = optional_param('edit', -1, PARAM_BOOL);
|
|
|
34 |
$hide = optional_param('hide', 0, PARAM_INT);
|
|
|
35 |
$show = optional_param('show', 0, PARAM_INT);
|
|
|
36 |
$duplicatesection = optional_param('duplicatesection', 0, PARAM_INT);
|
|
|
37 |
$idnumber = optional_param('idnumber', '', PARAM_RAW);
|
|
|
38 |
$sectionid = optional_param('sectionid', 0, PARAM_INT);
|
|
|
39 |
$section = optional_param('section', null, PARAM_INT);
|
|
|
40 |
$expandsection = optional_param('expandsection', -1, PARAM_INT);
|
|
|
41 |
$move = optional_param('move', 0, PARAM_INT);
|
1220 |
ariadna |
42 |
$marker = optional_param('marker', -1, PARAM_INT);
|
1 |
efrain |
43 |
$switchrole = optional_param('switchrole', -1, PARAM_INT); // Deprecated, use course/switchrole.php instead.
|
|
|
44 |
$return = optional_param('return', 0, PARAM_LOCALURL);
|
|
|
45 |
|
|
|
46 |
$params = [];
|
|
|
47 |
if (!empty($name)) {
|
|
|
48 |
$params = ['shortname' => $name];
|
|
|
49 |
} else if (!empty($idnumber)) {
|
|
|
50 |
$params = ['idnumber' => $idnumber];
|
|
|
51 |
} else if (!empty($id)) {
|
|
|
52 |
$params = ['id' => $id];
|
|
|
53 |
} else {
|
|
|
54 |
throw new \moodle_exception('unspecifycourseid', 'error');
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
$course = $DB->get_record('course', $params, '*', MUST_EXIST);
|
|
|
58 |
|
|
|
59 |
$urlparams = ['id' => $course->id];
|
|
|
60 |
|
|
|
61 |
// Sectionid should get priority over section number.
|
|
|
62 |
if ($sectionid) {
|
|
|
63 |
$section = $DB->get_field('course_sections', 'section', ['id' => $sectionid, 'course' => $course->id], MUST_EXIST);
|
|
|
64 |
}
|
|
|
65 |
if (!is_null($section)) {
|
|
|
66 |
$urlparams['section'] = $section;
|
|
|
67 |
}
|
|
|
68 |
if ($expandsection !== -1) {
|
|
|
69 |
$urlparams['expandsection'] = $expandsection;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
$PAGE->set_url('/course/view.php', $urlparams); // Defined here to avoid notices on errors etc.
|
|
|
73 |
|
|
|
74 |
// Prevent caching of this page to stop confusion when changing page after making AJAX changes.
|
|
|
75 |
$PAGE->set_cacheable(false);
|
|
|
76 |
|
|
|
77 |
context_helper::preload_course($course->id);
|
|
|
78 |
$context = context_course::instance($course->id, MUST_EXIST);
|
|
|
79 |
|
|
|
80 |
// Remove any switched roles before checking login.
|
|
|
81 |
if ($switchrole == 0 && confirm_sesskey()) {
|
|
|
82 |
role_switch($switchrole, $context);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
require_login($course);
|
|
|
86 |
|
|
|
87 |
// Switchrole - sanity check in cost-order...
|
|
|
88 |
$resetuserallowedediting = false;
|
1220 |
ariadna |
89 |
if (
|
|
|
90 |
$switchrole > 0 && confirm_sesskey() &&
|
|
|
91 |
has_capability('moodle/role:switchroles', $context)
|
|
|
92 |
) {
|
1 |
efrain |
93 |
// Is this role assignable in this context?
|
|
|
94 |
// Inquiring minds want to know.
|
|
|
95 |
$aroles = get_switchable_roles($context);
|
|
|
96 |
if (is_array($aroles) && isset($aroles[$switchrole])) {
|
|
|
97 |
role_switch($switchrole, $context);
|
|
|
98 |
// Double check that this role is allowed here.
|
|
|
99 |
require_login($course);
|
|
|
100 |
}
|
|
|
101 |
// Reset course page state. This prevents some weird problems.
|
|
|
102 |
$USER->activitycopy = false;
|
|
|
103 |
$USER->activitycopycourse = null;
|
|
|
104 |
unset($USER->activitycopyname);
|
|
|
105 |
unset($SESSION->modform);
|
|
|
106 |
$USER->editing = 0;
|
|
|
107 |
$resetuserallowedediting = true;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
// If course is hosted on an external server, redirect to corresponding
|
|
|
111 |
// url with appropriate authentication attached as parameter.
|
|
|
112 |
if (file_exists($CFG->dirroot . '/course/externservercourse.php')) {
|
|
|
113 |
include($CFG->dirroot . '/course/externservercourse.php');
|
|
|
114 |
if (function_exists('extern_server_course')) {
|
|
|
115 |
if ($externurl = extern_server_course($course)) {
|
|
|
116 |
redirect($externurl);
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
1220 |
ariadna |
121 |
require_once($CFG->dirroot . '/calendar/lib.php'); // This is after login because it needs $USER.
|
1 |
efrain |
122 |
|
|
|
123 |
// Must set layout before gettting section info. See MDL-47555.
|
|
|
124 |
$PAGE->set_pagelayout('course');
|
|
|
125 |
$PAGE->add_body_class('limitedwidth');
|
|
|
126 |
|
|
|
127 |
if ($section && $section > 0) {
|
|
|
128 |
|
|
|
129 |
// Get section details and check it exists.
|
|
|
130 |
$modinfo = get_fast_modinfo($course);
|
|
|
131 |
$coursesections = $modinfo->get_section_info($section, MUST_EXIST);
|
|
|
132 |
|
|
|
133 |
// Check user is allowed to see it.
|
|
|
134 |
if (!$coursesections->uservisible) {
|
|
|
135 |
// Check if coursesection has conditions affecting availability and if
|
|
|
136 |
// so, output availability info.
|
|
|
137 |
if ($coursesections->visible && $coursesections->availableinfo) {
|
|
|
138 |
$sectionname = get_section_name($course, $coursesections);
|
|
|
139 |
$message = get_string('notavailablecourse', '', $sectionname);
|
|
|
140 |
redirect(course_get_url($course), $message, null, \core\output\notification::NOTIFY_ERROR);
|
|
|
141 |
} else {
|
|
|
142 |
// Note: We actually already know they don't have this capability
|
|
|
143 |
// or uservisible would have been true; this is just to get the
|
|
|
144 |
// correct error message shown.
|
|
|
145 |
require_capability('moodle/course:viewhiddensections', $context);
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
// Fix course format if it is no longer installed.
|
|
|
151 |
$format = course_get_format($course);
|
|
|
152 |
$course->format = $format->get_format();
|
|
|
153 |
|
|
|
154 |
$PAGE->set_pagetype('course-view-' . $course->format);
|
|
|
155 |
$PAGE->set_other_editing_capability('moodle/course:update');
|
|
|
156 |
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
|
|
|
157 |
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
|
|
|
158 |
if (course_format_uses_sections($course->format)) {
|
|
|
159 |
$PAGE->set_other_editing_capability('moodle/course:sectionvisibility');
|
|
|
160 |
$PAGE->set_other_editing_capability('moodle/course:movesections');
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
// Preload course format renderer before output starts.
|
|
|
164 |
// This is a little hacky but necessary since
|
|
|
165 |
// format.php is not included until after output starts.
|
|
|
166 |
$renderer = $format->get_renderer($PAGE);
|
|
|
167 |
|
|
|
168 |
if ($resetuserallowedediting) {
|
|
|
169 |
// Ugly hack.
|
|
|
170 |
unset($PAGE->_user_allowed_editing);
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
if (!isset($USER->editing)) {
|
|
|
174 |
$USER->editing = 0;
|
|
|
175 |
}
|
|
|
176 |
if ($PAGE->user_allowed_editing()) {
|
|
|
177 |
if (($edit == 1) && confirm_sesskey()) {
|
|
|
178 |
$USER->editing = 1;
|
1220 |
ariadna |
179 |
|
1 |
efrain |
180 |
// Redirect to site root if Editing is toggled on frontpage.
|
|
|
181 |
if ($course->id == SITEID) {
|
1220 |
ariadna |
182 |
//redirect($CFG->wwwroot .'/?redirect=0');
|
|
|
183 |
$url = new moodle_url($PAGE->url, ['notifyeditingon' => 1]);
|
|
|
184 |
redirect($url);
|
1 |
efrain |
185 |
} else if (!empty($return)) {
|
|
|
186 |
redirect($CFG->wwwroot . $return);
|
|
|
187 |
} else {
|
|
|
188 |
$url = new moodle_url($PAGE->url, ['notifyeditingon' => 1]);
|
|
|
189 |
redirect($url);
|
|
|
190 |
}
|
|
|
191 |
} else if (($edit == 0) && confirm_sesskey()) {
|
|
|
192 |
$USER->editing = 0;
|
|
|
193 |
if (!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
|
|
|
194 |
$USER->activitycopy = false;
|
|
|
195 |
$USER->activitycopycourse = null;
|
|
|
196 |
}
|
|
|
197 |
// Redirect to site root if Editing is toggled on frontpage.
|
|
|
198 |
if ($course->id == SITEID) {
|
1220 |
ariadna |
199 |
redirect($CFG->wwwroot . '/?redirect=0');
|
1 |
efrain |
200 |
} else if (!empty($return)) {
|
|
|
201 |
redirect($CFG->wwwroot . $return);
|
|
|
202 |
} else {
|
|
|
203 |
redirect($PAGE->url);
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
if (has_capability('moodle/course:sectionvisibility', $context)) {
|
|
|
208 |
if ($hide && confirm_sesskey()) {
|
|
|
209 |
set_section_visible($course->id, $hide, '0');
|
|
|
210 |
if ($sectionid) {
|
|
|
211 |
redirect(course_get_url($course, $section, ['navigation' => true]));
|
|
|
212 |
} else {
|
|
|
213 |
redirect($PAGE->url);
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
if ($show && confirm_sesskey()) {
|
|
|
218 |
set_section_visible($course->id, $show, '1');
|
|
|
219 |
if ($sectionid) {
|
|
|
220 |
redirect(course_get_url($course, $section, ['navigation' => true]));
|
|
|
221 |
} else {
|
|
|
222 |
redirect($PAGE->url);
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
if ($marker >= 0 && confirm_sesskey()) {
|
|
|
228 |
course_set_marker($course->id, $marker);
|
|
|
229 |
if ($sectionid) {
|
|
|
230 |
redirect(course_get_url($course, $section, ['navigation' => true]));
|
|
|
231 |
} else {
|
|
|
232 |
redirect($PAGE->url);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
if (
|
|
|
237 |
!empty($section) && !empty($coursesections) && !empty($duplicatesection)
|
|
|
238 |
&& has_capability('moodle/course:update', $context) && confirm_sesskey()
|
|
|
239 |
) {
|
|
|
240 |
$newsection = $format->duplicate_section($coursesections);
|
|
|
241 |
redirect(course_get_url($course, $newsection->section));
|
|
|
242 |
}
|
|
|
243 |
|
1220 |
ariadna |
244 |
if (
|
|
|
245 |
!empty($section) && !empty($move) &&
|
|
|
246 |
has_capability('moodle/course:movesections', $context) && confirm_sesskey()
|
|
|
247 |
) {
|
1 |
efrain |
248 |
$destsection = $section + $move;
|
|
|
249 |
if (move_section_to($course, $section, $destsection)) {
|
|
|
250 |
if ($course->id == SITEID) {
|
|
|
251 |
redirect($CFG->wwwroot . '/?redirect=0');
|
|
|
252 |
} else {
|
|
|
253 |
if ($format->get_course_display() == COURSE_DISPLAY_MULTIPAGE) {
|
|
|
254 |
redirect(course_get_url($course));
|
|
|
255 |
} else {
|
|
|
256 |
redirect(course_get_url($course, $destsection));
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
} else {
|
|
|
260 |
echo $OUTPUT->notification('An error occurred while moving a section');
|
|
|
261 |
}
|
|
|
262 |
}
|
|
|
263 |
} else {
|
|
|
264 |
$USER->editing = 0;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
$SESSION->fromdiscussion = $PAGE->url->out(false);
|
|
|
268 |
|
|
|
269 |
|
|
|
270 |
if ($course->id == SITEID) {
|
|
|
271 |
// This course is not a real course.
|
1220 |
ariadna |
272 |
redirect($CFG->wwwroot . '/?redirect=0');
|
1 |
efrain |
273 |
}
|
|
|
274 |
|
|
|
275 |
// Determine whether the user has permission to download course content.
|
|
|
276 |
$candownloadcourse = \core\content::can_export_context($context, $USER);
|
|
|
277 |
|
|
|
278 |
// We are currently keeping the button here from 1.x to help new teachers figure out
|
|
|
279 |
// what to do, even though the link also appears in the course admin block. It also
|
|
|
280 |
// means you can back out of a situation where you removed the admin block.
|
|
|
281 |
if ($PAGE->user_allowed_editing()) {
|
|
|
282 |
$buttons = $OUTPUT->edit_button($PAGE->url);
|
|
|
283 |
$PAGE->set_button($buttons);
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
$editingtitle = '';
|
|
|
287 |
if ($PAGE->user_is_editing()) {
|
|
|
288 |
// Append this to the page title's lang string to get its equivalent when editing mode is turned on.
|
|
|
289 |
$editingtitle = 'editing';
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
// If viewing a section, make the title more specific.
|
|
|
293 |
if ($section && $section > 0 && course_format_uses_sections($course->format)) {
|
|
|
294 |
$sectionname = get_string('sectionname', "format_$course->format");
|
|
|
295 |
$sectiontitle = get_section_name($course, $section);
|
|
|
296 |
$PAGE->set_title(
|
|
|
297 |
get_string(
|
|
|
298 |
'coursesectiontitle' . $editingtitle,
|
|
|
299 |
'moodle',
|
|
|
300 |
['course' => $course->fullname, 'sectiontitle' => $sectiontitle, 'sectionname' => $sectionname]
|
|
|
301 |
)
|
|
|
302 |
);
|
|
|
303 |
} else {
|
|
|
304 |
$PAGE->set_title(get_string('coursetitle' . $editingtitle, 'moodle', ['course' => $course->fullname]));
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
// Add bulk editing control.
|
|
|
308 |
$bulkbutton = $renderer->bulk_editing_button($format);
|
|
|
309 |
if (!empty($bulkbutton)) {
|
|
|
310 |
$PAGE->add_header_action($bulkbutton);
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
$PAGE->set_heading($course->fullname);
|
|
|
314 |
echo $OUTPUT->header();
|
|
|
315 |
|
|
|
316 |
// Show communication room status notification.
|
|
|
317 |
if (has_capability('moodle/course:update', $context)) {
|
|
|
318 |
core_communication\helper::get_course_communication_status_notification($course);
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
if ($USER->editing == 1) {
|
|
|
322 |
|
|
|
323 |
// MDL-65321 The backup libraries are quite heavy, only require the bare minimum.
|
|
|
324 |
require_once($CFG->dirroot . '/backup/util/helper/async_helper.class.php');
|
|
|
325 |
|
|
|
326 |
if (async_helper::is_async_pending($id, 'course', 'backup')) {
|
|
|
327 |
echo $OUTPUT->notification(get_string('pendingasyncedit', 'backup'), 'warning');
|
|
|
328 |
}
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
// Course wrapper start.
|
|
|
332 |
echo html_writer::start_tag('div', ['class' => 'course-content']);
|
|
|
333 |
|
|
|
334 |
// Make sure that section 0 exists (this function will create one if it is missing).
|
|
|
335 |
course_create_sections_if_missing($course, 0);
|
|
|
336 |
|
|
|
337 |
// Get information about course modules and existing module types.
|
|
|
338 |
// format.php in course formats may rely on presence of these variables.
|
|
|
339 |
$modinfo = get_fast_modinfo($course);
|
|
|
340 |
$modnames = get_module_types_names();
|
|
|
341 |
$modnamesplural = get_module_types_names(true);
|
|
|
342 |
$modnamesused = $modinfo->get_used_module_names();
|
|
|
343 |
$mods = $modinfo->get_cms();
|
|
|
344 |
$sections = $modinfo->get_section_info_all();
|
|
|
345 |
|
|
|
346 |
// CAUTION, hacky fundamental variable defintion to follow!
|
|
|
347 |
// Note that because of the way course fromats are constructed though
|
|
|
348 |
// inclusion we pass parameters around this way.
|
|
|
349 |
$displaysection = $section;
|
|
|
350 |
|
|
|
351 |
// Include course AJAX.
|
|
|
352 |
include_course_ajax($course, $modnamesused);
|
|
|
353 |
|
|
|
354 |
// Include the actual course format.
|
1220 |
ariadna |
355 |
require($CFG->dirroot . '/course/format/' . $course->format . '/format.php');
|
1 |
efrain |
356 |
// Content wrapper end.
|
|
|
357 |
|
|
|
358 |
echo html_writer::end_tag('div');
|
|
|
359 |
|
|
|
360 |
// Trigger course viewed event.
|
|
|
361 |
// We don't trust $context here. Course format inclusion above executes in the global space. We can't assume
|
|
|
362 |
// anything after that point.
|
|
|
363 |
course_view(context_course::instance($course->id), $section);
|
|
|
364 |
|
|
|
365 |
// If available, include the JS to prepare the download course content modal.
|
|
|
366 |
if ($candownloadcourse) {
|
|
|
367 |
$PAGE->requires->js_call_amd('core_course/downloadcontent', 'init');
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
// Load the view JS module if completion tracking is enabled for this course.
|
|
|
371 |
$completion = new completion_info($course);
|
|
|
372 |
if ($completion->is_enabled()) {
|
|
|
373 |
$PAGE->requires->js_call_amd('core_course/view', 'init');
|
|
|
374 |
}
|
|
|
375 |
|
|
|
376 |
echo $OUTPUT->footer();
|