Browse Source

Convert to using tcpdf lib to generate qrcodes.

MOODLE_35_STABLE
Dan Marsden 6 years ago
parent
commit
8e513a7b6b
  1. 3
      lang/en/attendance.php
  2. 27
      password.php
  3. 3
      settings.php

3
lang/en/attendance.php

@ -343,9 +343,6 @@ $string['preventsharederror'] = 'Self-marking has been disabled for a session be
$string['priorto'] = 'The session date is prior to the course start date ({$a}) so that the new sessions scheduled before this date will be hidden (not accessible). You can change the course start date at any time (see course settings) in order to have access to earlier sessions.<br><br>Please change the session date or just click the "Add session" button again to confirm?'; $string['priorto'] = 'The session date is prior to the course start date ({$a}) so that the new sessions scheduled before this date will be hidden (not accessible). You can change the course start date at any time (see course settings) in order to have access to earlier sessions.<br><br>Please change the session date or just click the "Add session" button again to confirm?';
$string['processingfile'] = 'Processing file'; $string['processingfile'] = 'Processing file';
$string['qrcode'] = 'QR Code'; $string['qrcode'] = 'QR Code';
$string['qrcodemissing'] = 'QR Code not available. Please ask your administrator to install the <a href="https://moodle.org/plugins/local_qrlinks">QR Links</a> plugin.';
$string['qrcodewarning'] = 'This QR code was generated using the 3rd-party service <a href="http://goqr.me/?refer=moodle-mod_attendance">goQR.me</a>.';
$string['qrcodeadminwarning'] = 'Warning: QR codes for student self-marking will be generated using the external service <a href="http://goqr.me/?refer=moodle-mod_attendance">goQR.me</a>. Install the <a href="https://moodle.org/plugins/local_qrlinks">QR Links</a> plugin to generate them locally.';
$string['randompassword'] = 'Random password'; $string['randompassword'] = 'Random password';
$string['remark'] = 'Remark for: {$a}'; $string['remark'] = 'Remark for: {$a}';
$string['remarks'] = 'Remarks'; $string['remarks'] = 'Remarks';

27
password.php

@ -26,6 +26,8 @@
*/ */
require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->libdir.'/tcpdf/tcpdf_barcodes_2d.php'); // Used for generating qrcode.
$session = required_param('session', PARAM_INT); $session = required_param('session', PARAM_INT);
$session = $DB->get_record('attendance_sessions', array('id' => $session), '*', MUST_EXIST); $session = $DB->get_record('attendance_sessions', array('id' => $session), '*', MUST_EXIST);
@ -54,27 +56,8 @@ if (isset($session->includeqrcode) && $session->includeqrcode == 1) {
$qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?qrpass=' . $session->studentpassword . '&sessid=' . $session->id; $qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?qrpass=' . $session->studentpassword . '&sessid=' . $session->id;
echo html_writer::tag('h3', get_string('qrcode', 'attendance')); echo html_writer::tag('h3', get_string('qrcode', 'attendance'));
// If the local_qrlinks plugin is installed, use it to create the QR code. $barcode = new TCPDF2DBarcode($qrcodeurl, 'QRCODE');
$plugininfos = core_plugin_manager::instance()->get_plugins_of_type('local'); $image = $barcode->getBarcodePngData(15, 15);
$qrlinklib = dirname(__FILE__).'/../../local/qrlinks/thirdparty/QrCode/src/QrCode.php'; echo html_writer::img('data:image/png;base64,' . base64_encode($image), get_string('qrcode', 'attendance'));
if (isset($plugininfos['qrlinks']) && file_exists($qrlinklib)) {
require_once($qrlinklib);
$code = new QrCode($qrcodeurl);
$code->setSize(500);
echo html_writer::img('data:image/png;base64,' . base64_encode($code->get()));
} else {
// Otherwise try using an external API service to create the QR code instead.
try {
$qrcode = file_get_contents('https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=' . urlencode($qrcodeurl));
if ($qrcode === false) {
echo html_writer::tag('p', get_string('qrcodemissing', 'attendance'));
} else {
echo html_writer::img('data:image/png;base64,' . base64_encode($qrcode), get_string('qrcode', 'attendance'));
echo html_writer::tag('p', get_string('qrcodewarning', 'attendance'));
}
} catch (Exception $e) {
echo html_writer::tag('p', get_string('qrcodemissing', 'attendance'));
}
}
} }
echo $OUTPUT->footer(); echo $OUTPUT->footer();

3
settings.php

@ -30,9 +30,6 @@ if ($ADMIN->fulltree) {
$tabmenu = attendance_print_settings_tabs(); $tabmenu = attendance_print_settings_tabs();
if (empty($plugininfos['qrlinks'])) {
$tabmenu = '<div class="alert alert-warning">'.get_string('qrcodeadminwarning', 'mod_attendance').'</div>'.$tabmenu;
}
$settings->add(new admin_setting_heading('attendance_header', '', $tabmenu)); $settings->add(new admin_setting_heading('attendance_header', '', $tabmenu));
$plugininfos = core_plugin_manager::instance()->get_plugins_of_type('local'); $plugininfos = core_plugin_manager::instance()->get_plugins_of_type('local');

Loading…
Cancel
Save