Moodle release 3.4.6
[moodle.git] / grade / edit / settings / index.php
blob5b73474a2b8dc48f369dde8ef571939876095b99
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 * A page for editing course grade settings
20 * @package core_grades
21 * @copyright 2007 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once '../../../config.php';
26 require_once $CFG->dirroot.'/grade/lib.php';
27 require_once $CFG->libdir.'/gradelib.php';
28 require_once 'form.php';
30 $courseid = optional_param('id', SITEID, PARAM_INT);
32 $PAGE->set_url('/grade/edit/settings/index.php', array('id'=>$courseid));
33 $PAGE->set_pagelayout('admin');
35 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
36 print_error('invalidcourseid');
38 require_login($course);
39 $context = context_course::instance($course->id);
41 require_capability('moodle/grade:manage', $context);
43 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'settings', 'courseid'=>$courseid));
45 $strgrades = get_string('grades');
46 $pagename = get_string('coursesettings', 'grades');
48 $returnurl = $CFG->wwwroot.'/grade/index.php?id='.$course->id;
50 $mform = new course_settings_form();
52 $settings = grade_get_settings($course->id);
54 $mform->set_data($settings);
56 if ($mform->is_cancelled()) {
57 redirect($returnurl);
59 } else if ($data = $mform->get_data()) {
60 $data = (array)$data;
61 $general = array('displaytype', 'decimalpoints', 'aggregationposition', 'minmaxtouse');
62 foreach ($data as $key=>$value) {
63 if (!in_array($key, $general) and strpos($key, 'report_') !== 0
64 and strpos($key, 'import_') !== 0
65 and strpos($key, 'export_') !== 0) {
66 continue;
68 if ($value == -1) {
69 $value = null;
71 grade_set_setting($course->id, $key, $value);
73 $previousvalue = isset($settings->{$key}) ? $settings->{$key} : null;
74 if ($key == 'minmaxtouse' && $previousvalue != $value) {
75 // The min max has changed, we need to regrade the grades.
76 grade_force_full_regrading($courseid);
80 redirect($returnurl);
83 print_grade_page_head($courseid, 'settings', 'coursesettings', get_string('coursegradesettings', 'grades'));
85 // The settings could have been changed due to a notice shown in print_grade_page_head, we need to refresh them.
86 $settings = grade_get_settings($course->id);
87 $mform->set_data($settings);
89 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal centerpara');
90 echo get_string('coursesettingsexplanation', 'grades');
91 echo $OUTPUT->box_end();
93 $mform->display();
95 echo $OUTPUT->footer();