Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / grade / edit / item.php
blob4865d23077696ea93836dbeba535c0e4fd93e443
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 '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);
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);
23 $mform = new edit_item_form(null, array('gpr'=>$gpr));
25 if ($mform->is_cancelled()) {
26 redirect($returnurl);
29 if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
30 // redirect if outcomeid present
31 if (!empty($item->outcomeid)) {
32 $url = $CFG->wwwroot.'/grade/edit/outcome.php?id='.$id.'&amp;courseid='.$courseid;
33 redirect($gpr->add_url_params($url));
36 // Get Item preferences
37 $item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype', $id);
38 $item->pref_decimalpoints = grade_report::get_pref('decimalpoints', $id);
40 $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
41 $mform->set_data($item);
44 if ($data = $mform->get_data()) {
45 if (array_key_exists('calculation', $data)) {
46 $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
49 $grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
50 grade_item::set_properties($grade_item, $data);
52 if (empty($grade_item->id)) {
53 $grade_item->itemtype = 'manual'; // all new items to be manual only
54 $grade_item->insert();
56 } else {
57 $grade_item->update();
60 // Handle user preferences
61 if (isset($data->pref_gradedisplaytype)) {
62 if (!grade_report::set_pref('gradedisplaytype', $data->pref_gradedisplaytype, $grade_item->id)) {
63 error("Could not set preference gradedisplaytype to $value for this grade item");
67 if (isset($data->pref_decimalpoints)) {
68 if (!grade_report::set_pref('decimalpoints', $data->pref_decimalpoints, $grade_item->id)) {
69 error("Could not set preference decimalpoints to $value for this grade item");
73 redirect($returnurl, 'temporary debug delay', 5);
76 $strgrades = get_string('grades');
77 $strgraderreport = get_string('graderreport', 'grades');
78 $stritemsedit = get_string('itemsedit', 'grades');
80 $nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
81 array('name'=>$stritemsedit, 'link'=>'', 'type'=>'misc'));
83 $navigation = build_navigation($nav);
86 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $stritemsedit, $navigation, '', '', true, '', navmenu($course));
88 $mform->display();
90 print_footer($course);