MDL-78962 core/loadingicon: remove jQuery requirement in the API
[moodle.git] / course / modregrade.php
blob2361d051704400c384240653e6b2847bcd0084c8
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.
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/>.
17 /**
18 * Regrades a module that has been added or updated when it might take a long time.
20 * A progress bar will be displayed in that case, and then the user can click 'Continue' to proceed.
21 * If for some reason you get to this page when regrading will not take a long time, then it will
22 * redirect immediately.
24 * @package core_course
25 * @copyright 2022 The Open University
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 define('NO_OUTPUT_BUFFERING', true);
30 require('../config.php');
31 require_once($CFG->libdir . '/gradelib.php');
33 $cmid = required_param('id', PARAM_INT);
34 $urlpath = required_param('url', PARAM_LOCALURL);
35 $url = new moodle_url($urlpath);
37 // Check that an absolute url/path was specified e.g. /course/view.php (it probably isn't a
38 // security risk to allow a relative one, but isn't necessary here).
39 if (!$url->get_host()) {
40 throw new moodle_exception('missingparam', 'error', '', 'url');
43 // Get course.
44 [$course, $cm] = get_course_and_cm_from_cmid($cmid);
45 $context = \context_module::instance($cm->id);
47 // Set up page for display.
48 $PAGE->set_url(new moodle_url('/course/modregrade.php', ['id' => $cmid, 'url' => $url]));
49 $PAGE->set_context($context);
50 $PAGE->set_title($course->shortname . ': ' . get_string('recalculatinggrades', 'grades'));
52 // Security check: must be logged in with manage activities permission.
53 require_login($course, false, $cm);
54 require_capability('moodle/course:manageactivities', $context);
56 // Do the regrade if necessary.
57 grade_regrade_final_grades_if_required($course);
59 // Redirect back to the target URL.
60 redirect($url);