Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / grade / edit / outcome / edit.php
blobac0eaf80137765c203b09581c3eefef4d85819b2
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->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
37 if ($id) {
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;
51 } else {
52 if ($courseid) {
53 if (!$course = get_record('course', 'id', $courseid)) {
54 error('Incorrect course id');
57 $outcome_rec->standard = 1;
58 $outcome_rec->courseid = $courseid;
59 require_login();
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);
75 } else {
76 /// adding new outcome from admin section
77 $outcome_rec = new object();
78 $outcome_rec->standard = 1;
79 $outcome_rec->courseid = 0;
80 require_login();
81 require_capability('moodle/grade:manage', $systemcontext);
84 // default return url
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()) {
93 redirect($returnurl);
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)) {
102 $data->standard = 0;
104 $outcome->courseid = !empty($data->standard) ? null : $courseid;
105 if (empty($outcome->courseid)) {
106 $outcome->courseid = null;
108 $outcome->insert();
110 } else {
111 if (isset($data->standard)) {
112 $outcome->courseid = !empty($data->standard) ? null : $courseid;
113 } else {
114 unset($outcome->couseid); // keep previous
116 $outcome->update();
119 redirect($returnurl);
122 $strgrades = get_string('grades');
123 $strgraderreport = get_string('graderreport', 'grades');
124 $stroutcomeedit = get_string('outcome', 'grades');
126 if ($courseid) {
127 $navigation = grade_build_nav(__FILE__, $stroutcomeedit, array('courseid' => $courseid));
128 print_header_simple($strgrades.': '.$strgraderreport, ': '.$stroutcomeedit, $navigation, '', '', true, '', navmenu($course));
130 } else {
131 require_once $CFG->libdir.'/adminlib.php';
132 admin_externalpage_setup('outcomes');
133 admin_externalpage_print_header();
136 $mform->display();
138 if ($courseid) {
139 print_footer($course);
140 } else {
141 admin_externalpage_print_footer();