MDL-10478 Added category preference aggregationview. This one is linked with the...
[moodle-pu.git] / grade / edit / item.php
blobb7ca41d1ac1278353fdcad5569d868e1e2b2f7fe
1 <?php //$Id$
2 require_once '../../config.php';
3 require_once $CFG->dirroot.'/grade/lib.php';
4 require_once $CFG->dirroot.'/grade/report/lib.php';
5 require_once $CFG->libdir.'/gradelib.php';
6 require_once 'item_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);
17 $context = get_context_instance(CONTEXT_COURSE, $course->id);
18 //require_capability() here!!
20 // default return url
21 $gpr = new grade_plugin_return();
22 $returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
24 $mform = new edit_item_form(null, array('gpr'=>$gpr));
26 if ($mform->is_cancelled()) {
27 redirect($returnurl);
30 if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
31 // Get Item preferences
32 $item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype', $id);
33 $item->pref_decimalpoints = grade_report::get_pref('decimalpoints', $id);
35 $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
36 $mform->set_data($item);
38 } else {
39 // defaults for new items
40 $mform->set_data(array('courseid'=>$course->id, 'itemtype'=>'manual'));
43 if ($data = $mform->get_data()) {
44 if (array_key_exists('calculation', $data)) {
45 $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
48 $grade_item = new grade_item(array('id'=>$id, 'courseid'=>$course->id));
49 grade_item::set_properties($grade_item, $data);
51 if (empty($grade_item->id)) {
52 $grade_item->itemtype = 'manual'; // all new items to be manual only
53 $grade_item->insert();
55 } else {
56 $grade_item->update();
59 // Handle user preferences
60 if (isset($data->pref_gradedisplaytype)) {
61 if (!grade_report::set_pref('gradedisplaytype', $data->pref_gradedisplaytype, $grade_item->id)) {
62 error("Could not set preference gradedisplaytype to $value for this grade item");
66 if (isset($data->pref_decimalpoints)) {
67 if (!grade_report::set_pref('decimalpoints', $data->pref_decimalpoints, $grade_item->id)) {
68 error("Could not set preference decimalpoints to $value for this grade item");
72 redirect($returnurl, 'temporary debug delay', 50);
75 $strgrades = get_string('grades');
76 $strgraderreport = get_string('graderreport', 'grades');
77 $stritemsedit = get_string('itemsedit', 'grades');
79 $nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
80 array('name'=>$stritemsedit, 'link'=>'', 'type'=>'misc'));
82 $navigation = build_navigation($nav);
85 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $stritemsedit, $navigation, '', '', true, '', navmenu($course));
87 $mform->display();
89 print_footer($course);