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 outcome
39 if (!$outcome_rec = get_record('grade_outcomes', 'id', $id)) {
40 error('Incorrect outcome id');
42 if ($outcome_rec->courseid
) {
43 $outcome_rec->standard
= 0;
44 if (!$course = get_record('course', 'id', $outcome_rec->courseid
)) {
45 error('Incorrect course id');
47 require_login($course);
48 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
49 require_capability('moodle/grade:manage', $context);
50 $courseid = $course->id
;
53 if (!$course = get_record('course', 'id', $courseid)) {
54 error('Incorrect course id');
57 $outcome_rec->standard
= 1;
58 $outcome_rec->courseid
= $courseid;
60 require_capability('moodle/grade:manage', $systemcontext);
63 } else if ($courseid){
64 /// adding new outcome from course
65 if (!$course = get_record('course', 'id', $courseid)) {
66 print_error('nocourseid');
68 $outcome_rec = new object();
69 $outcome_rec->standard
= 0;
70 $outcome_rec->courseid
= $courseid;
71 require_login($course);
72 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
73 require_capability('moodle/grade:manage', $context);
76 /// adding new outcome from admin section
77 $outcome_rec = new object();
78 $outcome_rec->standard
= 1;
79 $outcome_rec->courseid
= 0;
81 require_capability('moodle/grade:manage', $systemcontext);
85 $gpr = new grade_plugin_return();
86 $returnurl = $gpr->get_return_url('index.php?id='.$courseid);
88 $mform = new edit_outcome_form(null, array('gpr'=>$gpr));
90 $mform->set_data($outcome_rec);
92 if ($mform->is_cancelled()) {
95 } else if ($data = $mform->get_data(false)) {
96 $outcome = new grade_outcome(array('id'=>$id));
97 $data->usermodified
= $USER->id
;
98 grade_outcome
::set_properties($outcome, $data);
100 if (empty($outcome->id
)) {
101 if (!has_capability('moodle/grade:manage', $systemcontext)) {
104 $outcome->courseid
= !empty($data->standard
) ?
null : $courseid;
105 if (empty($outcome->courseid
)) {
106 $outcome->courseid
= null;
111 if (isset($data->standard
)) {
112 $outcome->courseid
= !empty($data->standard
) ?
null : $courseid;
114 unset($outcome->couseid
); // keep previous
119 redirect($returnurl);
122 $strgrades = get_string('grades');
123 $strgraderreport = get_string('graderreport', 'grades');
124 $stroutcomeedit = get_string('outcome', 'grades');
127 $navigation = grade_build_nav(__FILE__
, $stroutcomeedit, array('courseid' => $courseid));
128 print_header_simple($strgrades.': '.$strgraderreport, ': '.$stroutcomeedit, $navigation, '', '', true, '', navmenu($course));
131 require_once $CFG->libdir
.'/adminlib.php';
132 admin_externalpage_setup('outcomes');
133 admin_externalpage_print_header();
139 print_footer($course);
141 admin_externalpage_print_footer();