$this->print_header_and_tabs($cm, $course, $quiz, $reportmode="grading");
+ // Check permissions
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ if (!has_capability('mod/quiz:grade', $context)) {
+ notify(get_string('gradingnotallowed', 'quiz_grading'));
+ return true;
+ }
+
if (!empty($questionid)) {
if (! $question = get_record('question', 'id', $questionid)) {
error("Question with id $questionid not found");
$inactive[] = 'reports';
$activated[] = 'reports';
- $allreports = get_list_of_plugins("mod/quiz/report");
- $reportlist = array ('overview', 'regrade', 'grading', 'analysis'); // Standard reports we want to show first
+ // Standard reports we want to show first.
+ $reportlist = array ('overview', 'regrade', 'grading', 'analysis');
+ // Reports that are restricted by capability.
+ $reportrestrictions = array(
+ 'regrade' => 'mod/quiz:grade',
+ 'grading' => 'mod/quiz:grade'
+ );
+ $allreports = get_list_of_plugins("mod/quiz/report");
foreach ($allreports as $report) {
if (!in_array($report, $reportlist)) {
$reportlist[] = $report;
$row = array();
$currenttab = '';
foreach ($reportlist as $report) {
- $row[] = new tabobject($report, "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id&mode=$report",
- get_string($report, 'quiz_'.$report));
- if ($report == $mode) {
- $currenttab = $report;
+ if (!isset($reportrestrictions[$report]) || has_capability($reportrestrictions[$report], $context)) {
+ $row[] = new tabobject($report, "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id&mode=$report",
+ get_string($report, 'quiz_'.$report));
+ if ($report == $mode) {
+ $currenttab = $report;
+ }
}
}
$tabs[] = $row;