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. $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. // Check to see if autoassignstatus is in use and no password required.
if ($attforsession->autoassignstatus && empty($attforsession->studentpassword)) { if ($attforsession->autoassignstatus && empty($attforsession->studentpassword)) {
$statusid = attendance_session_get_highest_status($att, $attforsession); $statusid = attendance_session_get_highest_status($att, $attforsession);

31
locallib.php

@ -1042,3 +1042,34 @@ function construct_session_full_date_time($datetime, $duration) {
return $sessinfo; 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')); $PAGE->set_title(get_string('password', 'attendance'));
echo $OUTPUT->header(); 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) { $showpassword = (isset($session->studentpassword) && strlen($session->studentpassword) > 0);
$qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?qrpass=' . $session->studentpassword . '&sessid=' . $session->id; $showqr = (isset($session->includeqrcode) && $session->includeqrcode == 1);
echo html_writer::tag('h3', get_string('qrcode', 'attendance'));
$barcode = new TCPDF2DBarcode($qrcodeurl, 'QRCODE'); if ($showpassword) {
$image = $barcode->getBarcodePngData(15, 15); attendance_renderpassword($session);
echo html_writer::img('data:image/png;base64,' . base64_encode($image), get_string('qrcode', 'attendance'));
} }
if ($showqr) {
attendance_renderqrcode($session);
}
echo $OUTPUT->footer(); 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) { private function construct_date_time_actions(attendance_manage_data $sessdata, $sess) {
$actions = ''; $actions = '';
if (!empty($sess->studentpassword) && if ((!empty($sess->studentpassword) || ($sess->includeqrcode == 1)) &&
(has_capability('mod/attendance:manageattendances', $sessdata->att->context) || (has_capability('mod/attendance:manageattendances', $sessdata->att->context) ||
has_capability('mod/attendance:takeattendances', $sessdata->att->context) || has_capability('mod/attendance:takeattendances', $sessdata->att->context) ||
has_capability('mod/attendance:changeattendances', $sessdata->att->context))) { has_capability('mod/attendance:changeattendances', $sessdata->att->context))) {

Loading…
Cancel
Save