Browse Source

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
MOODLE_36_STABLE
maksudr 6 years ago
committed by Dan Marsden
parent
commit
f3dd70d17e
  1. 5
      attendance.php
  2. 31
      locallib.php
  3. 17
      password.php
  4. 2
      renderer.php

5
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);

31
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'));
}

17
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();

2
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))) {

Loading…
Cancel
Save