From dafa5d9213b3229cdfc2a03941af1778a6fba011 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 13 Sep 2018 11:54:03 +1200 Subject: [PATCH] Convert to using tcpdf lib to generate qrcodes. --- lang/en/attendance.php | 3 --- password.php | 27 +++++---------------------- settings.php | 3 --- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/lang/en/attendance.php b/lang/en/attendance.php index f65c7f2..d9a2522 100644 --- a/lang/en/attendance.php +++ b/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.

Please change the session date or just click the "Add session" button again to confirm?'; $string['processingfile'] = 'Processing file'; $string['qrcode'] = 'QR Code'; -$string['qrcodemissing'] = 'QR Code not available. Please ask your administrator to install the QR Links plugin.'; -$string['qrcodewarning'] = 'This QR code was generated using the 3rd-party service goQR.me.'; -$string['qrcodeadminwarning'] = 'Warning: QR codes for student self-marking will be generated using the external service goQR.me. Install the QR Links plugin to generate them locally.'; $string['randompassword'] = 'Random password'; $string['remark'] = 'Remark for: {$a}'; $string['remarks'] = 'Remarks'; diff --git a/password.php b/password.php index cc3de68..4e92d9b 100644 --- a/password.php +++ b/password.php @@ -26,6 +26,8 @@ */ 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 = $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; echo html_writer::tag('h3', get_string('qrcode', 'attendance')); - // If the local_qrlinks plugin is installed, use it to create the QR code. - $plugininfos = core_plugin_manager::instance()->get_plugins_of_type('local'); - $qrlinklib = dirname(__FILE__).'/../../local/qrlinks/thirdparty/QrCode/src/QrCode.php'; - 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')); - } - } + $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')); } echo $OUTPUT->footer(); diff --git a/settings.php b/settings.php index e170374..4d28ad6 100644 --- a/settings.php +++ b/settings.php @@ -30,9 +30,6 @@ if ($ADMIN->fulltree) { $tabmenu = attendance_print_settings_tabs(); - if (empty($plugininfos['qrlinks'])) { - $tabmenu = '
'.get_string('qrcodeadminwarning', 'mod_attendance').'
'.$tabmenu; - } $settings->add(new admin_setting_heading('attendance_header', '', $tabmenu)); $plugininfos = core_plugin_manager::instance()->get_plugins_of_type('local');