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 $CFG->libdir
.'/gradelib.php';
7 require_once 'category_form.php';
9 $courseid = required_param('courseid', PARAM_INT
);
10 $id = optional_param('id', 0, PARAM_INT
);
12 if (!$course = get_record('course', 'id', $courseid)) {
13 print_error('nocourseid');
16 require_login($course);
18 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
19 //require_capability() here!!
22 $gpr = new grade_plugin_return();
23 $returnurl = $gpr->get_return_url('tree.php?id='.$course->id
);
26 $mform = new edit_category_form(null, array('gpr'=>$gpr));
27 if ($category = get_record('grade_categories', 'id', $id, 'courseid', $course->id
)) {
28 // Get Category preferences
29 $category->pref_aggregationview
= grade_report
::get_pref('aggregationview', $id);
31 $mform->set_data($category);
33 $mform->set_data(array('courseid'=>$course->id
));
36 if ($mform->is_cancelled()) {
39 } else if ($data = $mform->get_data()) {
40 $grade_category = new grade_category(array('id'=>$id, 'courseid'=>$course->id
));
41 grade_category
::set_properties($grade_category, $data);
43 if (empty($grade_category->id
)) {
44 $grade_category->insert();
47 $grade_category->update();
50 // Handle user preferences
51 if (isset($data->pref_aggregationview
)) {
52 if (!grade_report
::set_pref('aggregationview', $data->pref_aggregationview
, $grade_category->id
)) {
53 error("Could not set preference aggregationview to $value for this grade category");
61 $strgrades = get_string('grades');
62 $strgraderreport = get_string('graderreport', 'grades');
63 $strcategoriesedit = get_string('categoriesedit', 'grades');
65 $nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot
.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
66 array('name'=>$strcategoriesedit, 'link'=>'', 'type'=>'misc'));
68 $navigation = build_navigation($nav);
71 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
75 print_footer($course);