diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index e5d30e9eea2..c7fafe5129e 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -408,6 +408,7 @@ $string['regrade'] = 'Regrade all attempts'; $string['regradecomplete'] = 'All attempts have been regraded'; $string['regradecount'] = '$a->changed out of $a->attempt grades were changed'; $string['regradedisplayexplanation'] = 'Attempts that change during regrading are displayed as hyperlinks to the question review window'; +$string['regradenotallowed'] = 'You do not have permission to regrade this quiz'; $string['regradingquestion'] = 'Regrading \"$a\".'; $string['regradingquiz'] = 'Regrading Quiz \"$a\"'; $string['relative'] = 'Relative'; diff --git a/mod/quiz/db/access.php b/mod/quiz/db/access.php index 720e0e6e86e..b6a9380bcc1 100644 --- a/mod/quiz/db/access.php +++ b/mod/quiz/db/access.php @@ -54,7 +54,7 @@ $mod_quiz_capabilities = array( ) ), - // Manually grade and comment on student attempts at a question. + // Manually grade and comment on student attempts at a question, and regrade quizzes. 'mod/quiz:grade' => array( 'captype' => 'write', diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index a364bc30861..2c3cb94d1e9 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -23,6 +23,8 @@ class quiz_report extends quiz_default_report { $strtimeformat = get_string('strftimedatetime'); $strreviewquestion = get_string('reviewresponse', 'quiz'); + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + // Only print headers if not asked to download data if (!$download = optional_param('download', NULL)) { $this->print_header_and_tabs($cm, $course, $quiz, $reportmode="overview"); @@ -33,10 +35,12 @@ class quiz_report extends quiz_default_report { switch($action) { case 'delete': // Some attempts need to be deleted + require_capability('mod/quiz:deleteattempts', $context); $attemptids = optional_param('attemptid', array(), PARAM_INT); foreach($attemptids as $attemptid) { if ($attemptid && $todelete = get_record('quiz_attempts', 'id', $attemptid)) { + add_to_log($course->id, 'quiz', 'delete attempt', 'report.php?id=' . $cm->id, $attemptid, $cm->id); delete_records('quiz_attempts', 'id', $attemptid); delete_attempt($todelete->uniqueid); @@ -513,14 +517,19 @@ class quiz_report extends quiz_default_report { // Print table $table->print_html(); + // Prepare list of available options. + $options = array(); + if (has_capability('mod/quiz:deleteattempts', $context)) { + $options['delete'] = get_string('delete'); + } + // Print "Select all" etc. - if (!empty($attempts)) { + if (!empty($attempts) && !empty($options)) { echo '
| '; echo ''.get_string('selectall', 'quiz').' / '; echo ''.get_string('selectnone', 'quiz').' '; echo ' '; - $options = array('delete' => get_string('delete')); echo choose_from_menu($options, 'action', '', get_string('withselected', 'quiz'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true); echo ''; diff --git a/mod/quiz/report/regrade/report.php b/mod/quiz/report/regrade/report.php index 5943921a342..6105807a12d 100644 --- a/mod/quiz/report/regrade/report.php +++ b/mod/quiz/report/regrade/report.php @@ -11,6 +11,13 @@ class quiz_report extends quiz_default_report { // Print header $this->print_header_and_tabs($cm, $course, $quiz, $reportmode="regrade"); + // Check permissions + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + if (!has_capability('mod/quiz:grade', $context)) { + notify(get_string('regradenotallowed', 'quiz')); + return true; + } + // Fetch all attempts if (!$attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = 0")) { print_heading(get_string('noattempts', 'quiz')); |