3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
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. //
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: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
26 require_once '../../../config.php';
27 require_once $CFG->dirroot
.'/grade/lib.php';
28 require_once $CFG->dirroot
.'/grade/report/lib.php';
29 require_once 'edit_form.php';
31 $courseid = optional_param('courseid', 0, PARAM_INT
);
32 $id = optional_param('id', 0, PARAM_INT
);
34 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
36 // a bit complex access control :-O
38 /// editing existing scale
39 if (!$scale_rec = get_record('scale', 'id', $id)) {
40 error('Incorrect scale id');
42 if ($scale_rec->courseid
) {
43 $scale_rec->standard
= 0;
44 if (!$course = get_record('course', 'id', $scale_rec->courseid
)) {
45 error('Incorrect course id');
47 require_login($course);
48 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
49 require_capability('moodle/course:managescales', $context);
50 $courseid = $course->id
;
53 if (!$course = get_record('course', 'id', $courseid)) {
54 error('Incorrect course id');
57 $scale_rec->standard
= 1;
58 $scale_rec->courseid
= $courseid;
59 require_login($courseid);
60 require_capability('moodle/course:managescales', $systemcontext);
63 } else if ($courseid){
64 /// adding new scale from course
65 if (!$course = get_record('course', 'id', $courseid)) {
66 print_error('nocourseid');
68 $scale_rec = new object();
69 $scale_rec->standard
= 0;
70 $scale_rec->courseid
= $courseid;
71 require_login($course);
72 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
73 require_capability('moodle/course:managescales', $context);
76 /// adding new scale from admin section
77 $scale_rec = new object();
78 $scale_rec->standard
= 1;
79 $scale_rec->courseid
= 0;
81 require_capability('moodle/course:managescales', $systemcontext);
85 $gpr = new grade_plugin_return();
86 $returnurl = $gpr->get_return_url('index.php?id='.$courseid);
88 $mform = new edit_scale_form(null, array('gpr'=>$gpr));
90 $mform->set_data($scale_rec);
92 if ($mform->is_cancelled()) {
95 } else if ($data = $mform->get_data(false)) {
96 $scale = new grade_scale(array('id'=>$id));
97 $data->userid
= $USER->id
;
98 grade_scale
::set_properties($scale, $data);
100 if (empty($scale->id
)) {
101 if (!has_capability('moodle/grade:manage', $systemcontext)) {
104 $scale->courseid
= !empty($data->standard
) ?
0 : $courseid;
108 if (isset($data->standard
)) {
109 $scale->courseid
= !empty($data->standard
) ?
0 : $courseid;
111 unset($scale->couseid
); // keep previous
116 redirect($returnurl);
119 $strgrades = get_string('grades');
120 $strgraderreport = get_string('graderreport', 'grades');
121 $strscaleedit = get_string('scale');
124 $navigation = grade_build_nav(__FILE__
, $strscaleedit, $courseid);
125 print_header_simple($strgrades.': '.$strgraderreport, ': '.$strscaleedit, $navigation, '', '', true, '', navmenu($course));
128 require_once $CFG->libdir
.'/adminlib.php';
129 admin_externalpage_setup('outcomes');
130 admin_externalpage_print_header();
136 print_footer($course);
138 admin_externalpage_print_footer();