3 require_once '../../../config.php';
4 require_once $CFG->dirroot
.'/grade/lib.php';
5 require_once $CFG->dirroot
.'/grade/report/lib.php';
6 require_once 'edit_form.php';
8 $courseid = optional_param('courseid', 0, PARAM_INT
);
9 $id = optional_param('id', 0, PARAM_INT
);
11 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
13 // a bit complex access control :-O
15 /// editing existing scale
16 if (!$scale_rec = get_record('scale', 'id', $id)) {
17 error('Incorrect scale id');
19 if ($scale_rec->courseid
) {
20 $scale_rec->standard
= 0;
21 if (!$course = get_record('course', 'id', $scale_rec->courseid
)) {
22 error('Incorrect course id');
24 require_login($course);
25 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
26 require_capability('moodle/course:managescales', $context);
27 $courseid = $course->id
;
30 if (!$course = get_record('course', 'id', $courseid)) {
31 error('Incorrect course id');
34 $scale_rec->standard
= 1;
35 $scale_rec->courseid
= $courseid;
36 require_login($courseid);
37 require_capability('moodle/course:managescales', $systemcontext);
40 } else if ($courseid){
41 /// adding new scale from course
42 if (!$course = get_record('course', 'id', $courseid)) {
43 print_error('nocourseid');
45 $scale_rec = new object();
46 $scale_rec->standard
= 0;
47 $scale_rec->courseid
= $courseid;
48 require_login($course);
49 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
50 require_capability('moodle/course:managescales', $context);
53 /// adding new scale from admin section
54 $scale_rec = new object();
55 $scale_rec->standard
= 1;
56 $scale_rec->courseid
= 0;
58 require_capability('moodle/course:managescales', $systemcontext);
62 $gpr = new grade_plugin_return();
63 $returnurl = $gpr->get_return_url('index.php?id='.$courseid);
65 $mform = new edit_scale_form(null, array('gpr'=>$gpr));
67 $mform->set_data($scale_rec);
69 if ($mform->is_cancelled()) {
72 } else if ($data = $mform->get_data(false)) {
73 $scale = new grade_scale(array('id'=>$id));
74 $data->userid
= $USER->id
;
75 grade_scale
::set_properties($scale, $data);
77 if (empty($scale->id
)) {
78 if (!has_capability('moodle/grade:manage', $systemcontext)) {
81 $scale->courseid
= !empty($data->standard
) ?
0 : $courseid;
85 if (isset($data->standard
)) {
86 $scale->courseid
= !empty($data->standard
) ?
0 : $courseid;
88 unset($scale->couseid
); // keep previous
96 $strgrades = get_string('grades');
97 $strgraderreport = get_string('graderreport', 'grades');
98 $strscaleedit = get_string('scale');
101 $navigation = grade_build_nav(__FILE__
, $strscaleedit, $courseid);
102 print_header_simple($strgrades.': '.$strgraderreport, ': '.$strscaleedit, $navigation, '', '', true, '', navmenu($course));
105 require_once $CFG->libdir
.'/adminlib.php';
106 admin_externalpage_setup('outcomes');
107 admin_externalpage_print_header();
113 print_footer($course);
115 admin_externalpage_print_footer();