e060e33d |
1 | <?php |
aa330ebb |
2 | |
e060e33d |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // |
5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by |
7 | // the Free Software Foundation, either version 3 of the License, or |
8 | // (at your option) any later version. |
9 | // |
10 | // Moodle is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | // |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
aa330ebb |
17 | |
18 | require_once '../../../config.php'; |
19 | require_once $CFG->libdir.'/gradelib.php'; |
20 | require_once $CFG->dirroot.'/grade/lib.php'; |
21 | require_once $CFG->dirroot.'/grade/report/overview/lib.php'; |
22 | |
7ac88172 |
23 | $courseid = required_param('id', PARAM_INT); |
aa330ebb |
24 | $userid = optional_param('userid', $USER->id, PARAM_INT); |
25 | |
a6855934 |
26 | $url = new moodle_url('/grade/report/overview/index.php', array('id'=>$courseid)); |
beebcf26 |
27 | if ($userid !== $USER->id) { |
28 | $url->param('userid', $userid); |
29 | } |
30 | $PAGE->set_url($url); |
31 | |
aa330ebb |
32 | /// basic access checks |
5c75a0a3 |
33 | if (!$course = $DB->get_record('course', array('id' => $courseid))) { |
aa330ebb |
34 | print_error('nocourseid'); |
35 | } |
36 | require_login($course); |
37 | |
7ac88172 |
38 | $context = get_context_instance(CONTEXT_COURSE, $course->id); |
02b5087e |
39 | $systemcontext = get_context_instance(CONTEXT_SYSTEM); |
aa330ebb |
40 | require_capability('gradereport/overview:view', $context); |
41 | |
7ac88172 |
42 | if (empty($userid)) { |
02b5087e |
43 | require_capability('moodle/grade:viewall', $systemcontext); |
7ac88172 |
44 | |
45 | } else { |
b0639b78 |
46 | if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) { |
cac0c3ef |
47 | print_error('invaliduserid'); |
7ac88172 |
48 | } |
49 | } |
50 | |
51 | $access = false; |
02b5087e |
52 | if (has_capability('moodle/grade:viewall', $systemcontext)) { |
aa330ebb |
53 | //ok - can view all course grades |
7ac88172 |
54 | $access = true; |
aa330ebb |
55 | |
02b5087e |
56 | } else if ($userid == $USER->id and has_capability('moodle/grade:viewall', $context)) { |
57 | //ok - can view any own grades |
58 | $access = true; |
6c3ef410 |
59 | |
7ac88172 |
60 | } else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) { |
02b5087e |
61 | //ok - can view own course grades |
7ac88172 |
62 | $access = true; |
aa330ebb |
63 | |
7ac88172 |
64 | } else if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_USER, $userid)) and $course->showgrades) { |
aa330ebb |
65 | // ok - can view grades of this user- parent most probably |
7ac88172 |
66 | $access = true; |
67 | } |
aa330ebb |
68 | |
7ac88172 |
69 | if (!$access) { |
70 | // no access to grades! |
cac0c3ef |
71 | print_error('nopermissiontoviewgrades', 'error', $CFG->wwwroot.'/course/view.php?id='.$courseid); |
aa330ebb |
72 | } |
73 | |
74 | /// return tracking object |
bc430af2 |
75 | $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid)); |
aa330ebb |
76 | |
77 | /// last selected report session tracking |
78 | if (!isset($USER->grade_last_report)) { |
79 | $USER->grade_last_report = array(); |
80 | } |
bc430af2 |
81 | $USER->grade_last_report[$course->id] = 'overview'; |
aa330ebb |
82 | |
7ac88172 |
83 | //first make sure we have proper final grades - this must be done before constructing of the grade tree |
84 | grade_regrade_final_grades($courseid); |
85 | |
02b5087e |
86 | if (has_capability('moodle/grade:viewall', $systemcontext)) { //Admins will see all student reports |
87 | // please note this would be extremely slow if we wanted to implement this properly for all teachers |
7ac88172 |
88 | $groupmode = groups_get_course_groupmode($course); // Groups are being used |
89 | $currentgroup = groups_get_course_group($course, true); |
aa330ebb |
90 | |
7ac88172 |
91 | if (!$currentgroup) { // To make some other functions work better later |
92 | $currentgroup = NULL; |
93 | } |
aa330ebb |
94 | |
7ac88172 |
95 | $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)); |
96 | |
97 | if ($isseparategroups and (!$currentgroup)) { |
48a4c849 |
98 | // no separate group access, can view only self |
99 | $userid = $USER->id; |
100 | $user_selector = ''; |
101 | } else { |
102 | /// Print graded user selector at the top |
103 | $user_selector = '<div id="graded_users_selector">'; |
104 | $user_selector .= print_graded_users_selector($course, 'report/overview/index.php?id=' . $course->id, $userid, $currentgroup, true, true); |
105 | $user_selector .= '</div>'; |
106 | $user_selector .= "<p style = 'page-break-after: always;'></p>"; |
7ac88172 |
107 | } |
108 | |
109 | /// Print graded user selector at the top |
110 | $user_selector = '<div id="graded_users_selector">'; |
111 | $user_selector .= print_graded_users_selector($course, 'report/overview/index.php?id=' . $course->id, $userid, $currentgroup, false, true); |
112 | $user_selector .= '</div>'; |
113 | $user_selector .= "<p style = 'page-break-after: always;'></p>"; |
114 | |
115 | if (empty($userid)) { |
116 | // Add tabs |
117 | print_grade_page_head($courseid, 'report', 'overview'); |
118 | groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0))); |
119 | echo $user_selector.'<br />'; |
120 | // do not list all users |
121 | |
122 | } else { // Only show one user's report |
123 | $report = new grade_report_overview($userid, $gpr, $context); |
124 | print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user)); |
125 | groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0))); |
126 | |
127 | echo $user_selector; |
128 | |
129 | if ($currentgroup and !groups_is_member($currentgroup, $userid)) { |
c3b834b4 |
130 | echo $OUTPUT->notification(get_string('groupusernotmember', 'error')); |
7ac88172 |
131 | } else { |
132 | if ($report->fill_table()) { |
133 | echo '<br />'.$report->print_table(true); |
134 | } |
135 | } |
136 | } |
02b5087e |
137 | } else { //Non-admins will see just their own report |
aa330ebb |
138 | |
139 | // Create a report instance |
140 | $report = new grade_report_overview($userid, $gpr, $context); |
7ac88172 |
141 | |
142 | // print the page |
dc482cfa |
143 | print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user)); |
aa330ebb |
144 | |
145 | if ($report->fill_table()) { |
7ac88172 |
146 | echo '<br />'.$report->print_table(true); |
aa330ebb |
147 | } |
aa330ebb |
148 | } |
7ac88172 |
149 | |
5a931394 |
150 | echo $OUTPUT->footer(); |
aa330ebb |
151 | |
02b5087e |
152 | |