3 include_once('../../../config.php');
4 require_once $CFG->libdir
.'/formslib.php';
6 // courseid needs to be passed in to know whether this should be tied to a course
7 class edit_outcomes_form
extends moodleform
{
9 function definition() {
12 $mform =& $this->_form
;
13 $mform->addElement('header', 'general', get_string('outcomes'));
15 $mform->addElement('text', 'shortname', get_string('shortname'));
16 $mform->addRule('shortname', get_string('required'), 'required');
17 $mform->setType('shortname', PARAM_TEXT
);
19 $mform->addElement('text', 'fullname', get_string('fullname'));
20 $mform->addRule('fullname', get_string('required'), 'required');
21 $mform->setType('fullname', PARAM_TEXT
);
24 if ($scales = get_records('scale')) {
25 foreach ($scales as $scale) {
26 $scalearr[$scale->id
] = $scale->name
;
30 $mform->addElement('select', 'scaleid', get_string('scale'), $scalearr);
31 $mform->addRule('scaleid', get_string('required'), 'required');
32 $mform->setType('scaleid', PARAM_INT
);
33 $mform->addElement('hidden', 'id');
34 $mform->setType('id', PARAM_INT
);
35 $mform->addElement('hidden', 'courseid');
36 $mform->setType('courseid', PARAM_INT
);
37 //-------------------------------------------------------------------------------
39 $this->add_action_buttons();
43 $id = optional_param('id', 0, PARAM_INT
); // id of the outcome
44 if ($courseid = optional_param('courseid', 0, PARAM_INT
)) {
45 // optional course id, if set, editting from course
46 require_login($courseid);
47 require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE
, $courseid));
48 $returnurl = $CFG->wwwroot
."/grade/report/outcomes/course.php?id=$courseid";
50 // admin editting site level outcomes
51 require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_SYSTEM
));
52 $returnurl = $CFG->wwwroot
."/grade/report/outcomes/site.php";
56 $mform = new edit_outcomes_form();
59 $mform->set_data(get_record('grade_outcomes', 'id', $id));
61 // if courseid is provided, set it in the form
63 $data->courseid
= $courseid;
64 $mform->set_data($data);
67 if ($mform->is_cancelled()) {
70 if ($data = $mform->get_data()) {
71 if ($data->courseid
== 0) {
72 $data->courseid
= NULL;
76 update_record('grade_outcomes', $data);
78 insert_record('grade_outcomes', $data);
84 $strgrades = get_string('grades');
85 $stroutcomes = get_string('outcomes', 'grades');
87 $navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot
. '/grade/index.php?id='.$courseid, 'type' => 'misc');
88 $navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
90 $navigation = build_navigation($navlinks);
92 print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
94 $currenttab = 'editoutcomes';