From 5e95c44185e565a9e9f6813701909bcfa9c6d29d Mon Sep 17 00:00:00 2001
From: maksudr <12033826+maksudr@users.noreply.github.com>
Date: Fri, 26 Jul 2019 09:37:15 +0100
Subject: [PATCH] QR rotation dev - timer, rotate text password, expiry time
margin setting (#414)
* Adding expiry time margin to setting and updating settings text.
* Add rotateqrcode to class structure
* Add submit password text to lang
* Form to allow users to enter rotating passwords
* Display text password on password.php
* Add timer for rotate password/qrcode on password.php
---
js/password/attendance_QRCodeRotate.js | 14 ++++++++++++--
lang/en/attendance.php | 2 ++
locallib.php | 8 ++++++--
renderer.php | 23 +++++++++++++++++------
4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/js/password/attendance_QRCodeRotate.js b/js/password/attendance_QRCodeRotate.js
index 4b17ac1..33020b3 100644
--- a/js/password/attendance_QRCodeRotate.js
+++ b/js/password/attendance_QRCodeRotate.js
@@ -3,7 +3,7 @@
* @copyright 2019 Maksud R
* @package mod_attendance
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- *
+ *
*/
class attendance_QRCodeRotate {
@@ -15,9 +15,11 @@ class attendance_QRCodeRotate {
this.qrCodeHTMLElement = "";
}
- start(sessionId, qrCodeHTMLElement) {
+ start(sessionId, qrCodeHTMLElement, textPasswordHTMLElement, timerHTMLElement) {
this.sessionId = sessionId;
this.qrCodeHTMLElement = qrCodeHTMLElement;
+ this.textPasswordHTMLElement = textPasswordHTMLElement;
+ this.timerHTMLElement = timerHTMLElement;
this.fetchAndRotate();
}
@@ -36,6 +38,12 @@ class attendance_QRCodeRotate {
var qrcodeurl = document.URL.substr(0,document.URL.lastIndexOf('/')) + '/attendance.php?qrpass=' + password + '&sessid=' + this.sessionId;
this.qrCodeInstance.clear();
this.qrCodeInstance.makeCode(qrcodeurl);
+ // display new password
+ this.textPasswordHTMLElement.innerHTML = '
'+password+'
';
+ }
+
+ updateTimer(timeLeft) {
+ this.timerHTMLElement.innerHTML = 'Time left: '+timeLeft+'
';
}
startRotating() {
@@ -53,6 +61,8 @@ class attendance_QRCodeRotate {
location.reload(true);
} else {
parent.changeQRCode(found.password);
+ parent.updateTimer(found.expirytime - Math.round(new Date().getTime() / 1000));
+
}
}, 1000);
diff --git a/lang/en/attendance.php b/lang/en/attendance.php
index 3c5cfd2..d299db4 100644
--- a/lang/en/attendance.php
+++ b/lang/en/attendance.php
@@ -485,6 +485,8 @@ $string['studentscanmarksessiontime_desc'] = 'If checked students can only recor
$string['studentscanmarksessiontimeend'] = 'Session end (minutes)';
$string['studentscanmarksessiontimeend_desc'] = 'If the session does not have an end time, how many minutes should the session be available for students to record their attendance.';
$string['submitattendance'] = 'Submit attendance';
+$string['submitpassword'] = 'Submit password';
+$string['submit'] = 'Submit';
$string['subnet'] = 'Subnet';
$string['subnetactivitylevel'] = 'Allow subnet config at activity level';
$string['subnetactivitylevel_desc'] = 'If enabled, teachers can override the default subnet at the activity level when creating an attendance. Otherwise the site default will be used when creating a session.';
diff --git a/locallib.php b/locallib.php
index 619fe27..426ab05 100644
--- a/locallib.php
+++ b/locallib.php
@@ -1139,7 +1139,6 @@ function attendance_generate_passwords($session) {
* @param stdClass $session
*/
function attendance_renderqrcoderotate($session) {
- echo html_writer::tag('h3', get_string('qrcode', 'attendance'));
// load requered js
echo html_writer::tag('script', '',
[
@@ -1153,12 +1152,17 @@ function attendance_renderqrcoderotate($session) {
'type' => 'text/javascript'
]
);
+ echo html_writer::tag('div', '', ['id' => 'rotate-time']); // div to display timer
+ echo html_writer::tag('h3', get_string('passwordgrp', 'attendance'));
+ echo html_writer::tag('div', '', ['id' => 'text-password']); // div to display password
+ echo html_writer::tag('h3', get_string('qrcode', 'attendance'));
echo html_writer::tag('div', '', ['id' => 'qrcode']); // div to display qr code
// js to start the password manager
echo '
';
}
diff --git a/renderer.php b/renderer.php
index 5af41d4..ac5cf44 100644
--- a/renderer.php
+++ b/renderer.php
@@ -1121,12 +1121,23 @@ class mod_attendance_renderer extends plugin_renderer_base {
} else {
list($canmark, $reason) = attendance_can_student_mark($sess, false);
if ($canmark) {
- // Student can mark their own attendance.
- // URL to the page that lets the student modify their attendance.
-
- $url = new moodle_url('/mod/attendance/attendance.php',
- array('sessid' => $sess->id, 'sesskey' => sesskey()));
- $cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attendance')));
+ if ($sess->rotateqrcode == 1) {
+ $url = new moodle_url('/mod/attendance/attendance.php');
+ $output = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sessid',
+ 'value' => $sess->id));
+ $output .= html_writer::empty_tag('input', array('type' => 'text', 'name' => 'qrpass',
+ 'placeholder' => "Enter password"));
+ $output .= html_writer::empty_tag('input', array('type' => 'submit',
+ 'value' => get_string('submit'),
+ 'class' => 'btn btn-secondary'));
+ $cell = new html_table_cell(html_writer::tag('form', $output, array('action' => $url->out(), 'method' => 'get')));
+ } else {
+ // Student can mark their own attendance.
+ // URL to the page that lets the student modify their attendance.
+ $url = new moodle_url('/mod/attendance/attendance.php',
+ array('sessid' => $sess->id, 'sesskey' => sesskey()));
+ $cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attendance')));
+ }
$cell->colspan = 3;
$row->cells[] = $cell;
} else { // Student cannot mark their own attendace.