3 require_once '../../config.php';
4 require_once $CFG->dirroot
.'/grade/lib.php';
5 require_once 'calculation_form.php';
7 $courseid = required_param('courseid', PARAM_INT
);
8 $id = required_param('id', PARAM_INT
);
10 if (!$course = get_record('course', 'id', $courseid)) {
11 print_error('nocourseid');
14 require_login($course);
15 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
16 require_capability('moodle/grade:manage', $context);
19 $gpr = new grade_plugin_return();
20 $returnurl = $gpr->get_return_url($CFG->wwwroot
.'/grade/report.php?id='.$course->id
);
22 if (!$grade_item = grade_item
::fetch(array('id'=>$id, 'courseid'=>$course->id
))) {
23 error('Incorect item id');
26 // module items and items without grade can not have calculation
27 if ($grade_item->is_normal_item() or ($grade_item->gradetype
!= GRADE_TYPE_VALUE
and $grade_item->gradetype
!= GRADE_TYPE_SCALE
)) {
28 redirect($returnurl, get_string('erornocalculationallowed', 'grades')); //TODO: localize
31 $mform = new edit_calculation_form(null, array('gpr'=>$gpr));
33 if ($mform->is_cancelled()) {
36 } else if (!$mform->is_submitted()) {
37 $calculation = grade_item
::denormalize_formula($grade_item->calculation
, $grade_item->courseid
);
38 $mform->set_data(array('courseid'=>$grade_item->courseid
, 'calculation'=>$calculation, 'id'=>$grade_item->id
, 'itemname'=>$grade_item->itemname
));
40 } else if ($data = $mform->get_data()) {
41 $grade_item->set_calculation($data->calculation
);
45 $strgrades = get_string('grades');
46 $strgraderreport = get_string('graderreport', 'grades');
47 $strcalculationedit = get_string('editcalculation', 'grades');
49 $nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot
.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
50 array('name'=>$strcalculationedit, 'link'=>'', 'type'=>'misc'));
52 $navigation = build_navigation($nav);
55 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcalculationedit, $navigation, '', '', true, '', navmenu($course));
59 print_footer($course);