3 ///////////////////////////////////////////////////////////////////////////
4 // NOTICE OF COPYRIGHT //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
9 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
21 // http://www.gnu.org/copyleft/gpl.html //
23 ///////////////////////////////////////////////////////////////////////////
25 require_once '../../../config.php';
26 require_once $CFG->libdir
.'/gradelib.php';
27 require_once $CFG->dirroot
.'/grade/lib.php';
28 require_once $CFG->dirroot
.'/grade/report/user/lib.php';
30 $courseid = required_param('id');
31 $userid = optional_param('userid', $USER->id
, PARAM_INT
);
33 /// basic access checks
34 if (!$course = get_record('course', 'id', $courseid)) {
35 print_error('nocourseid');
37 require_login($course);
39 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
40 require_capability('gradereport/user:view', $context);
43 require_capability('moodle/grade:viewall', $context);
46 if (!get_complete_user_data('id', $userid)) {
47 error("Incorrect userid");
52 if (has_capability('moodle/grade:viewall', $context)) {
53 //ok - can view all course grades
55 } else if ($userid == $USER->id
and has_capability('moodle/grade:view', $context) and $course->showgrades
) {
56 //ok - can view own grades
58 } else if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_USER
, $userid)) and $course->showgrades
) {
59 // ok - can view grades of this user- parent most probably
65 /// return tracking object
66 $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$courseid, 'userid'=>$userid));
68 /// last selected report session tracking
69 if (!isset($USER->grade_last_report
)) {
70 $USER->grade_last_report
= array();
72 $USER->grade_last_report
[$course->id
] = 'user';
75 $strgrades = get_string('grades');
76 $reportname = get_string('modulename', 'gradereport_user');
78 $navigation = grade_build_nav(__FILE__
, $reportname, $courseid);
81 print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
82 '', '', true, '', navmenu($course));
84 /// Print the plugin selector at the top
85 print_grade_plugin_selector($courseid, 'report', 'user');
90 //first make sure we have proper final grades - this must be done before constructing of the grade tree
91 grade_regrade_final_grades($courseid);
93 if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports
94 /// Print graded user selector at the top
95 echo '<div id="graded_users_selector">';
96 print_graded_users_selector($course, 'report/user/index.php?id=' . $course->id
, $userid);
98 echo "<p style = 'page-break-after: always;'></p>";
101 $gui = new graded_users_iterator($course);
103 while ($userdata = $gui->next_user()) {
104 $user = $userdata->user
;
105 $report = new grade_report_user($courseid, $gpr, $context, $user->id
);
106 print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user
));
107 if ($report->fill_table()) {
108 echo $report->print_table(true);
110 echo "<p style = 'page-break-after: always;'></p>";
113 } elseif ($userid) { // Only show one user's report
114 $report = new grade_report_user($courseid, $gpr, $context, $userid);
115 print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user
));
116 if ($report->fill_table()) {
117 echo $report->print_table(true);
120 } else { //Students will see just their own report
122 // Create a report instance
123 $report = new grade_report_user($courseid, $gpr, $context, $userid);
126 print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user
));
128 if ($report->fill_table()) {
129 echo $report->print_table(true);
134 // no access to grades!
135 echo "Can not view grades."; //TODO: localize
137 print_footer($course);