209a5e34ecdd4b994bbf726bce42d0004a52d394
[moodle.git] / grade / edit / settings / index.php
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 //                                                                       //
5 // NOTICE OF COPYRIGHT                                                   //
6 //                                                                       //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
8 //          http://moodle.com                                            //
9 //                                                                       //
10 // Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
11 //                                                                       //
12 // This program is free software; you can redistribute it and/or modify  //
13 // it under the terms of the GNU General Public License as published by  //
14 // the Free Software Foundation; either version 2 of the License, or     //
15 // (at your option) any later version.                                   //
16 //                                                                       //
17 // This program is distributed in the hope that it will be useful,       //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
20 // GNU General Public License for more details:                          //
21 //                                                                       //
22 //          http://www.gnu.org/copyleft/gpl.html                         //
23 //                                                                       //
24 ///////////////////////////////////////////////////////////////////////////
26 require_once '../../../config.php';
27 require_once $CFG->dirroot.'/grade/lib.php';
28 require_once $CFG->libdir.'/gradelib.php';
29 require_once 'form.php';
31 $courseid  = optional_param('id', SITEID, PARAM_INT);
32 $action   = optional_param('action', '', PARAM_ALPHA);
34 if (!$course = get_record('course', 'id', $courseid)) {
35     print_error('nocourseid');
36 }
37 require_login($course);
38 $context = get_context_instance(CONTEXT_COURSE, $course->id);
40 require_capability('moodle/grade:manage', $context);
42 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'settings', 'courseid'=>$courseid));
44 $strgrades = get_string('grades');
45 $pagename  = get_string('coursesettings', 'grades');
47 $navigation = grade_build_nav(__FILE__, $pagename, $courseid);
49 $returnurl = $CFG->wwwroot.'/grade/index.php?id='.$course->id;
51 $mform = new course_settings_form();
53 $data = new object;
54 $data->id                  = $course->id;
55 $data->displaytype         = grade_get_setting($course->id, 'displaytype', -1);
56 $data->decimalpoints       = grade_get_setting($course->id, 'decimalpoints',- 1);
57 $data->aggregationposition = grade_get_setting($course->id, 'aggregationposition', -1);
59 $mform->set_data($data);
61 if ($mform->is_cancelled()) {
62     redirect($returnurl);
64 } else if ($data = $mform->get_data()) {
65     if ($data->displaytype == -1) {
66         $data->displaytype = null;
67     }
68     grade_set_setting($course->id, 'displaytype', $data->displaytype);
70     if ($data->decimalpoints == -1) {
71         $data->decimalpoints = null;
72     }
73     grade_set_setting($course->id, 'decimalpoints', $data->decimalpoints);
75     if ($data->aggregationposition == -1) {
76         $data->aggregationposition = null;
77     }
78     grade_set_setting($course->id, 'aggregationposition', $data->aggregationposition);
80     redirect($returnurl);
81 }
83 /// Print header
84 print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
85 /// Print the plugin selector at the top
86 print_grade_plugin_selector($courseid, 'edit', 'settings');
88 $mform->display();
90 print_footer($course);
92 ?>