3 require_once '../../config.php';
4 require_once $CFG->libdir
.'/gradelib.php';
5 require_once 'grade_form.php';
7 $courseid = required_param('courseid', PARAM_INT
);
8 $id = optional_param('id', 0, PARAM_INT
); // grade_grades id
9 $action = optional_param('action', 'view', PARAM_ALPHA
);
11 if (!$course = get_record('course', 'id', $courseid)) {
12 print_error('nocourseid');
16 require_login($course);
17 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
18 require_capability('gradereport/grader:manage', $context);
21 //TODO: implement proper return support
22 $returnurl = $CFG->wwwroot
.'/grade/report.php?report=grader&id='.$course->id
;
24 // TODO: add proper check that grade is editable
26 $grade_grades = get_record('grade_grades', 'id', $id);
27 $gradeitem = get_record('grade_items', 'id', $grade_grades->itemid
);
29 $mform = new edit_grade_form(qualified_me(), array('gradeitem'=>$gradeitem));
30 if ($grade_grades = get_record('grade_grades', 'id', $id)) {
31 if ($grade_text = get_record('grade_grades_text', 'gradeid', $id)) {
32 if (can_use_html_editor()) {
33 $options = new object();
34 $options->smiley
= false;
35 $options->filter
= false;
36 $grade_text->feedback
= format_text($grade_text->feedback
, $grade_text->feedbackformat
, $options);
37 $grade_text->feedbackformat
= FORMAT_HTML
;
39 $mform->set_data($grade_text);
42 $grade_grades->locked
= $grade_grades->locked
> 0 ?
1:0;
43 $grade_grades->courseid
= $courseid;
44 $mform->set_data($grade_grades);
47 $mform->set_data(array('courseid'=>$course->id
, 'id' => $id));
50 if ($mform->is_cancelled()) {
53 } else if ($data = $mform->get_data()) {
55 $grade_grades = new grade_grades(array('id'=>$id));
56 $grade_item = new grade_item(array('id'=>$grade_grades->itemid
));
57 $grade_item->update_final_grade($grade_grades->userid
, $data->finalgrade
, NULL, NULL, $data->feedback
, $data->feedbackformat
);
60 $grade_grades->set_locked($data->locked
);
62 $grade_grades->set_hidden($data->hidden
);
65 $grade_grades->set_locktime($data->locktime
);
67 redirect($returnurl, get_string('feedbacksaved', 'grades'), 1);
70 // Get extra data related to this feedback
71 $query = "SELECT a.id AS userid, a.firstname, a.lastname,
72 b.id AS itemid, b.itemname, b.grademin, b.grademax, b.iteminstance, b.itemmodule, b.scaleid,
74 FROM {$CFG->prefix}user a,
75 {$CFG->prefix}grade_items b,
76 {$CFG->prefix}grade_grades c
81 $extra_info = get_record_sql($query) ;
82 $extra_info->grademin
= round($extra_info->grademin
);
83 $extra_info->grademax
= round($extra_info->grademax
);
84 $extra_info->finalgrade
= round($extra_info->finalgrade
);
86 if (!empty($extra_info->itemmodule
) && !empty($extra_info->iteminstance
)) {
87 $extra_info->course_module
= get_coursemodule_from_instance($extra_info->itemmodule
, $extra_info->iteminstance
, $courseid);
90 $stronascaleof = get_string('onascaleof', 'grades', $extra_info);
91 $strgrades = get_string('grades');
92 $strgrade = get_string('grade');
93 $strgraderreport = get_string('graderreport', 'grades');
94 $strfeedback = get_string('feedback', 'grades');
95 $strfeedbackedit = get_string('feedbackedit', 'grades');
96 $strfeedbackview = get_string('feedbackview', 'grades');
97 $strfeedbackadd = get_string('feedbackadd', 'grades');
98 $strstudent = get_string('student', 'grades');
99 $strgradeitem = get_string('gradeitem', 'grades');
102 $heading = $
{"strfeedback$action"};
103 if (!empty($action) && $action == 'view' && !empty($grade_text->feedback
)) {
104 $feedback = "<p><strong>$strfeedback</strong>:</p><p>$grade_text->feedback</p>";
107 $nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot
.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
108 array('name'=>$heading, 'link'=>'', 'type'=>'misc'));
110 $navigation = build_navigation($nav);
112 /*********** BEGIN OUTPUT *************/
114 print_header_simple($strgrades . ': ' . $strgraderreport . ': ' . $heading,
115 ': ' . $heading , $navigation, '', '', true, '', navmenu($course));
117 print_heading($heading);
119 print_simple_box_start("center");
121 // Student name and link
122 echo "<p><strong>$strstudent:</strong> <a href=\"" . $CFG->wwwroot
. '/user/view.php?id='
123 . $extra_info->userid
. '">' . fullname($extra_info) . "</a></p>";
125 // Grade item name and link
126 if (!empty($extra_info->course_module
) && !empty($extra_info->itemmodule
)) {
127 echo "<p><strong>$strgradeitem:</strong> <a href=\"" . $CFG->wwwroot
. '/mod/' . $extra_info->itemmodule
128 . '/view.php?id=' . $extra_info->course_module
->id
. "&courseid=$courseid\">$extra_info->itemname</a></p>";
131 // Form if in edit or add modes
134 print_simple_box_end();
136 print_footer($course);