weekly release 4.1dev
[moodle.git] / grade / edit / settings / index.php
CommitLineData
e060e33d 1<?php
e060e33d 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/>.
8ad36f4c 16
a153c9f2
AD
17/**
18 * A page for editing course grade settings
19 *
20 * @package core_grades
21 * @copyright 2007 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
e0724506 25require_once '../../../config.php';
26require_once $CFG->dirroot.'/grade/lib.php';
27require_once $CFG->libdir.'/gradelib.php';
28require_once 'form.php';
29
30$courseid = optional_param('id', SITEID, PARAM_INT);
e0724506 31
a2ec0b8d 32$PAGE->set_url('/grade/edit/settings/index.php', array('id'=>$courseid));
4d5059d4 33$PAGE->set_pagelayout('admin');
beebcf26 34
d24832f9 35if (!$course = $DB->get_record('course', array('id' => $courseid))) {
73d60436 36 throw new \moodle_exception('invalidcourseid');
e0724506 37}
38require_login($course);
d4060472 39$context = context_course::instance($course->id);
e0724506 40
41require_capability('moodle/grade:manage', $context);
42
43$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'settings', 'courseid'=>$courseid));
44
45$strgrades = get_string('grades');
46$pagename = get_string('coursesettings', 'grades');
47
e0724506 48$mform = new course_settings_form();
49
26ed0305 50$settings = grade_get_settings($course->id);
e0724506 51
26ed0305 52$mform->set_data($settings);
e0724506 53
c94ba3ee 54if ($data = $mform->get_data()) {
26ed0305 55 $data = (array)$data;
ebea19cb 56 $general = array('displaytype', 'decimalpoints', 'aggregationposition', 'minmaxtouse');
26ed0305 57 foreach ($data as $key=>$value) {
58 if (!in_array($key, $general) and strpos($key, 'report_') !== 0
59 and strpos($key, 'import_') !== 0
60 and strpos($key, 'export_') !== 0) {
61 continue;
62 }
63 if ($value == -1) {
64 $value = null;
65 }
66 grade_set_setting($course->id, $key, $value);
ebea19cb
FM
67
68 $previousvalue = isset($settings->{$key}) ? $settings->{$key} : null;
69 if ($key == 'minmaxtouse' && $previousvalue != $value) {
70 // The min max has changed, we need to regrade the grades.
71 grade_force_full_regrading($courseid);
72 }
e0724506 73 }
e0724506 74}
75
8faa560c 76print_grade_page_head($courseid, 'settings', 'coursesettings', get_string('coursegradesettings', 'grades'));
e0724506 77
ebea19cb
FM
78// The settings could have been changed due to a notice shown in print_grade_page_head, we need to refresh them.
79$settings = grade_get_settings($course->id);
80$mform->set_data($settings);
81
291fa827 82echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal centerpara');
c4c97a6d 83echo get_string('coursesettingsexplanation', 'grades');
291fa827 84echo $OUTPUT->box_end();
c4c97a6d 85
e0724506 86$mform->display();
87
5a931394 88echo $OUTPUT->footer();
e0724506 89
6c3ef410 90