Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / grade / edit / category.php
blob1a576da802afc9d92b074727df1c748e536f2f11
1 <?php //$Id$
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 'category_form.php';
8 $courseid = required_param('courseid', PARAM_INT);
9 $id = optional_param('id', 0, PARAM_INT);
11 if (!$course = get_record('course', 'id', $courseid)) {
12 print_error('nocourseid');
15 require_login($course);
16 $context = get_context_instance(CONTEXT_COURSE, $course->id);
17 require_capability('moodle/grade:manage', $context);
19 // default return url
20 $gpr = new grade_plugin_return();
21 $returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
24 $mform = new edit_category_form(null, array('gpr'=>$gpr));
25 if ($category = get_record('grade_categories', 'id', $id, 'courseid', $course->id)) {
26 // Get Category preferences
27 $category->pref_aggregationview = grade_report::get_pref('aggregationview', $id);
29 $mform->set_data($category);
30 } else {
31 $mform->set_data(array('courseid'=>$course->id));
34 if ($mform->is_cancelled()) {
35 redirect($returnurl);
37 } else if ($data = $mform->get_data()) {
38 $grade_category = new grade_category(array('id'=>$id, 'courseid'=>$course->id));
39 grade_category::set_properties($grade_category, $data);
41 if (empty($grade_category->id)) {
42 $grade_category->insert();
44 } else {
45 $grade_category->update();
48 // Handle user preferences
49 if (isset($data->pref_aggregationview)) {
50 if (!grade_report::set_pref('aggregationview', $data->pref_aggregationview, $grade_category->id)) {
51 error("Could not set preference aggregationview to $value for this grade category");
55 redirect($returnurl);
59 $strgrades = get_string('grades');
60 $strgraderreport = get_string('graderreport', 'grades');
61 $strcategoriesedit = get_string('categoriesedit', 'grades');
63 $nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
64 array('name'=>$strcategoriesedit, 'link'=>'', 'type'=>'misc'));
66 $navigation = build_navigation($nav);
69 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
71 $mform->display();
73 print_footer($course);
74 die;