From f3dd70d17e1f6da13539e112d0f781547aca61f5 Mon Sep 17 00:00:00 2001 From: maksudr <12033826+maksudr@users.noreply.github.com> Date: Tue, 28 May 2019 01:33:04 +0100 Subject: [PATCH] Fixes #378 - Enable QR Code without filling Student Password field (#381) * Fix #378 - Removing sesskey requirement for viewing attendance.php * Fix #378 - Show password icon when only QR code is selected. * Fix #378 - Refactor/Add functionality for QR Code & No Password --- attendance.php | 5 ----- locallib.php | 31 +++++++++++++++++++++++++++++++ password.php | 17 +++++++++-------- renderer.php | 2 +- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/attendance.php b/attendance.php index c7b15df..9562543 100644 --- a/attendance.php +++ b/attendance.php @@ -60,11 +60,6 @@ if (empty($attforsession->includeqrcode)) { $qrpass = ''; // Override qrpass if set, as it is not allowed. } -if (empty($qrpass)) { - // Sesskey is required on this page when QR code not in use. - require_sesskey(); -} - // Check to see if autoassignstatus is in use and no password required. if ($attforsession->autoassignstatus && empty($attforsession->studentpassword)) { $statusid = attendance_session_get_highest_status($att, $attforsession); diff --git a/locallib.php b/locallib.php index bc3a7e7..589cd40 100644 --- a/locallib.php +++ b/locallib.php @@ -1041,4 +1041,35 @@ function construct_session_full_date_time($datetime, $duration) { $sessinfo .= ' '.attendance_construct_session_time($datetime, $duration); return $sessinfo; +} + +/** + * Render the session password. + * + * @param stdClass $session + */ +function attendance_renderpassword($session) { + echo html_writer::tag('h2', get_string('passwordgrp', 'attendance')); + echo html_writer::span($session->studentpassword, 'student-password'); +} + +/** + * Render the session QR code. + * + * @param stdClass $session + */ +function attendance_renderqrcode($session) { + global $CFG; + + if (strlen($session->studentpassword) > 0) { + $qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?qrpass=' . $session->studentpassword . '&sessid=' . $session->id; + } else { + $qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?sessid=' . $session->id; + } + + echo html_writer::tag('h3', get_string('qrcode', 'attendance')); + + $barcode = new TCPDF2DBarcode($qrcodeurl, 'QRCODE'); + $image = $barcode->getBarcodePngData(15, 15); + echo html_writer::img('data:image/png;base64,' . base64_encode($image), get_string('qrcode', 'attendance')); } \ No newline at end of file diff --git a/password.php b/password.php index 4e92d9b..f15be09 100644 --- a/password.php +++ b/password.php @@ -49,15 +49,16 @@ $PAGE->set_context(context_system::instance()); $PAGE->set_title(get_string('password', 'attendance')); echo $OUTPUT->header(); -echo html_writer::tag('h2', get_string('passwordgrp', 'attendance')); -echo html_writer::span($session->studentpassword, 'student-password'); -if (isset($session->includeqrcode) && $session->includeqrcode == 1) { - $qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?qrpass=' . $session->studentpassword . '&sessid=' . $session->id; - echo html_writer::tag('h3', get_string('qrcode', 'attendance')); +$showpassword = (isset($session->studentpassword) && strlen($session->studentpassword) > 0); +$showqr = (isset($session->includeqrcode) && $session->includeqrcode == 1); - $barcode = new TCPDF2DBarcode($qrcodeurl, 'QRCODE'); - $image = $barcode->getBarcodePngData(15, 15); - echo html_writer::img('data:image/png;base64,' . base64_encode($image), get_string('qrcode', 'attendance')); +if ($showpassword) { + attendance_renderpassword($session); } + +if ($showqr) { + attendance_renderqrcode($session); +} + echo $OUTPUT->footer(); diff --git a/renderer.php b/renderer.php index d11caa9..18d4261 100644 --- a/renderer.php +++ b/renderer.php @@ -312,7 +312,7 @@ class mod_attendance_renderer extends plugin_renderer_base { */ private function construct_date_time_actions(attendance_manage_data $sessdata, $sess) { $actions = ''; - if (!empty($sess->studentpassword) && + if ((!empty($sess->studentpassword) || ($sess->includeqrcode == 1)) && (has_capability('mod/attendance:manageattendances', $sessdata->att->context) || has_capability('mod/attendance:takeattendances', $sessdata->att->context) || has_capability('mod/attendance:changeattendances', $sessdata->att->context))) {