diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php
index 239c5cb5093..06a5abd8320 100644
--- a/mod/quiz/report/attemptsreport.php
+++ b/mod/quiz/report/attemptsreport.php
@@ -391,10 +391,10 @@ abstract class quiz_attempt_report_table extends table_sql {
protected $groupstudents;
protected $students;
protected $questions;
- protected $candelete;
+ protected $includecheckboxes;
public function __construct($uniqueid, $quiz, $context, $qmsubselect, $groupstudents,
- $students, $questions, $candelete, $reporturl, $displayoptions) {
+ $students, $questions, $includecheckboxes, $reporturl, $displayoptions) {
parent::__construct($uniqueid);
$this->quiz = $quiz;
$this->context = $context;
@@ -402,7 +402,7 @@ abstract class quiz_attempt_report_table extends table_sql {
$this->groupstudents = $groupstudents;
$this->students = $students;
$this->questions = $questions;
- $this->candelete = $candelete;
+ $this->includecheckboxes = $includecheckboxes;
$this->reporturl = $reporturl;
$this->displayoptions = $displayoptions;
}
@@ -683,4 +683,50 @@ abstract class quiz_attempt_report_table extends table_sql {
$sortcolumns['quiza.id'] = SORT_ASC;
return $sortcolumns;
}
+
+ public function wrap_html_start() {
+ if ($this->is_downloading() || !$this->includecheckboxes) {
+ return;
+ }
+
+ $url = new moodle_url($this->reporturl, $this->displayoptions);
+ $url->param('sesskey', sesskey());
+
+ echo '
';
+ }
+
+ /**
+ * Output any submit buttons required by the $this->includecheckboxes form.
+ */
+ protected function submit_buttons() {
+ global $PAGE;
+ if (has_capability('mod/quiz:deleteattempts', $this->context)) {
+ echo '';
+ $PAGE->requires->event_handler('#deleteattemptsbutton', 'click', 'M.util.show_confirm_dialog',
+ array('message' => get_string('deleteattemptcheck', 'quiz')));
+ }
+ }
}
diff --git a/mod/quiz/report/overview/overview_table.php b/mod/quiz/report/overview/overview_table.php
index 55aacb34f49..7efa3d8b79f 100644
--- a/mod/quiz/report/overview/overview_table.php
+++ b/mod/quiz/report/overview/overview_table.php
@@ -35,13 +35,12 @@ defined('MOODLE_INTERNAL') || die();
*/
class quiz_report_overview_table extends quiz_attempt_report_table {
- protected $candelete;
protected $regradedqs = array();
public function __construct($quiz, $context, $qmsubselect, $groupstudents,
- $students, $detailedmarks, $questions, $candelete, $reporturl, $displayoptions) {
+ $students, $detailedmarks, $questions, $includecheckboxes, $reporturl, $displayoptions) {
parent::__construct('mod-quiz-report-overview-report', $quiz , $context,
- $qmsubselect, $groupstudents, $students, $questions, $candelete,
+ $qmsubselect, $groupstudents, $students, $questions, $includecheckboxes,
$reporturl, $displayoptions);
$this->detailedmarks = $detailedmarks;
}
@@ -147,45 +146,12 @@ class quiz_report_overview_table extends quiz_attempt_report_table {
}
}
- public function wrap_html_start() {
- if ($this->is_downloading() || !$this->candelete) {
- return;
- }
-
- // Start form
- $url = new moodle_url($this->reporturl, $this->displayoptions +
- array('sesskey' => sesskey()));
- echo '';
+ parent::submit_buttons();
}
public function col_sumgrades($attempt) {
diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php
index b62878d8de1..b7c0405b5d0 100644
--- a/mod/quiz/report/overview/report.php
+++ b/mod/quiz/report/overview/report.php
@@ -106,7 +106,8 @@ class quiz_overview_report extends quiz_attempt_report {
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
- $candelete = has_capability('mod/quiz:deleteattempts', $this->context)
+ $includecheckboxes = has_any_capability(
+ array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), $this->context)
&& ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
@@ -126,7 +127,7 @@ class quiz_overview_report extends quiz_attempt_report {
$questions = quiz_report_get_significant_questions($quiz);
$table = new quiz_report_overview_table($quiz, $this->context, $qmsubselect,
- $groupstudents, $students, $detailedmarks, $questions, $candelete,
+ $groupstudents, $students, $detailedmarks, $questions, $includecheckboxes,
$reporturl, $displayoptions);
$filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'),
$courseshortname, $quiz->name);
@@ -288,7 +289,7 @@ class quiz_overview_report extends quiz_attempt_report {
$columns = array();
$headers = array();
- if (!$table->is_downloading() && $candelete) {
+ if (!$table->is_downloading() && $includecheckboxes) {
$columns[] = 'checkbox';
$headers[] = null;
}
diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php
index 105bd73f917..3efd1d80a12 100644
--- a/mod/quiz/report/responses/report.php
+++ b/mod/quiz/report/responses/report.php
@@ -105,7 +105,7 @@ class quiz_responses_report extends quiz_attempt_report {
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
- $candelete = has_capability('mod/quiz:deleteattempts', $this->context)
+ $includecheckboxes = has_capability('mod/quiz:deleteattempts', $this->context)
&& ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
$displayoptions = array();
@@ -124,10 +124,14 @@ class quiz_responses_report extends quiz_attempt_report {
$allowed = array();
}
- if ($attemptids = optional_param('attemptid', array(), PARAM_INT) && confirm_sesskey()) {
- require_capability('mod/quiz:deleteattempts', $this->context);
- $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
- redirect($reporturl->out(false, $displayoptions));
+ if (empty($currentgroup) || $groupstudents) {
+ if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
+ if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
+ require_capability('mod/quiz:deleteattempts', $this->context);
+ $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
+ redirect($reporturl->out(false, $displayoptions));
+ }
+ }
}
// Load the required questions.
@@ -140,7 +144,7 @@ class quiz_responses_report extends quiz_attempt_report {
$displaycourseshortname = format_string($COURSE->shortname, true, array('context' => $displaycoursecontext));
$table = new quiz_report_responses_table($quiz, $this->context, $qmsubselect,
- $groupstudents, $students, $questions, $candelete, $reporturl, $displayoptions);
+ $groupstudents, $students, $questions, $includecheckboxes, $reporturl, $displayoptions);
$filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
$courseshortname, $quiz->name);
$table->is_downloading($download, $filename,
@@ -202,7 +206,7 @@ class quiz_responses_report extends quiz_attempt_report {
$columns = array();
$headers = array();
- if (!$table->is_downloading() && $candelete) {
+ if (!$table->is_downloading() && $includecheckboxes) {
$columns[] = 'checkbox';
$headers[] = null;
}
diff --git a/mod/quiz/report/responses/responses_table.php b/mod/quiz/report/responses/responses_table.php
index c994908e603..cfb4633ddcf 100644
--- a/mod/quiz/report/responses/responses_table.php
+++ b/mod/quiz/report/responses/responses_table.php
@@ -36,9 +36,9 @@ defined('MOODLE_INTERNAL') || die();
class quiz_report_responses_table extends quiz_attempt_report_table {
public function __construct($quiz, $context, $qmsubselect, $groupstudents,
- $students, $questions, $candelete, $reporturl, $displayoptions) {
+ $students, $questions, $includecheckboxes, $reporturl, $displayoptions) {
parent::__construct('mod-quiz-report-responses-report', $quiz, $context,
- $qmsubselect, $groupstudents, $students, $questions, $candelete,
+ $qmsubselect, $groupstudents, $students, $questions, $includecheckboxes,
$reporturl, $displayoptions);
}
@@ -49,43 +49,6 @@ class quiz_report_responses_table extends quiz_attempt_report_table {
}
}
- public function wrap_html_start() {
- global $PAGE;
- if ($this->is_downloading() || !$this->candelete) {
- return;
- }
-
- // Start form
- $url = new moodle_url($this->reporturl, $this->displayoptions);
- $url->param('sesskey', sesskey());
-
- echo '';
- // Close form
- echo '';
- echo '';
- }
-
public function col_sumgrades($attempt) {
if (!$attempt->timefinish) {
return '-';