Qrcode scanner

This commit is contained in:
Ibnu Maksum 2024-06-20 11:33:15 +07:00
parent 605a8f522f
commit f3349b50c8
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
12 changed files with 327 additions and 33 deletions

281
scan/index.html Normal file
View File

@ -0,0 +1,281 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>QR Scanner</title>
<style>
video {
width: 100% !important;
height: auto !important
}
#reload {
margin-top: 5px;
margin-bottom: 10px;
padding: 5px;
background-color: #0336FF;
color: #f3f4f5;
border-radius: 3px;
width: 150px;
cursor: pointer
}
a {
text-decoration: none;
color: #0336FF
}
.progress {
padding: 10px;
margin-top: 5px
}
#camera {
position: relative;
width: auto;
height: 100%
}
#camera:after,
#camera:before,
#camera>:first-child:after,
#camera>:first-child:before {
position: absolute;
width: 80px;
height: 80px;
border-color: red;
border-style: solid;
content: ' '
}
#camera:before {
top: 0;
left: 0;
border-width: 5px 0 0 5px
}
#camera:after {
top: 0;
right: 0;
border-width: 5px 5px 0 0
}
#camera>:first-child:before {
bottom: 0;
right: 0;
border-width: 0 5px 5px 0
}
#camera>:first-child:after {
bottom: 0;
left: 0;
border-width: 0 0 5px 5px
}
#camera-inside {
padding: 10px;
margin-bottom: -5px
}
#hasil {
font-size: 20px;
font-weight: 600px;
background-color: #76ff03;
color: #202020
}
</style>
<script type="text/javascript" src="llqrcode.js"></script>
</head>
<body>
<center>
<div id="main">
<div id="mainbody">
<div class="progress">
<div id="hasil"></div>
</div>
<div id="camera">
<div id="camera-inside"></div>
</div>
</div>
</div>
<br>
<div id="reload" onclick="location.reload();">Refresh Camera</div>
<p><small>Point Camera to Barcode</small></p>
<br>
</center>
<canvas style="display:none;" id="qr-canvas" width="800" height="600"></canvas>
<script type="text/javascript">
function getAllUrlParams(e) {
var t = e ? e.split("?")[1] : window.location.search.slice(1),
a = {};
if (t)
for (var n = (t = t.split("#")[0]).split("&"), o = 0; o < n.length; o++) {
var i = n[o].split("="),
r = void 0,
d = i[0].replace(/\[\d*\]/, function (e) {
return (r = e.slice(1, -1)), "";
}),
s = void 0 === i[1] || i[1];
a[(d = d.toLowerCase())]
? ("string" == typeof a[d] && (a[d] = [a[d]]),
void 0 === r ? a[d].push(s) : (a[d][r] = s))
: (a[d] = s);
}
return a;
}
var gCtx = null,
gCanvas = null,
c = 0,
stype = 0,
gUM = !1,
webkit = !1,
moz = !1,
v = null,
imghtml =
'<div id="qrfile"><canvas id="out-canvas" width="320" height="240"></canvas><div id="imghelp">drag and drop a QRCode here<br>or select a file<input type="file" onchange="handleFiles(this.files)"/></div></div>',
vidhtml = '<video id="v" autoplay></video>';
function dragenter(e) {
e.stopPropagation(), e.preventDefault();
}
function dragover(e) {
e.stopPropagation(), e.preventDefault();
}
function drop(e) {
e.stopPropagation(), e.preventDefault();
var t = e.dataTransfer,
a = t.files;
a.length > 0
? handleFiles(a)
: t.getData("URL") && qrcode.decode(t.getData("URL"));
}
function handleFiles(e) {
for (var t = 0; t < e.length; t++) {
var a = new FileReader();
(a.onload =
(e[t],
function (e) {
gCtx.clearRect(0, 0, gCanvas.width, gCanvas.height),
qrcode.decode(e.target.result);
})),
a.readAsDataURL(e[t]);
}
}
function initCanvas(e, t) {
((gCanvas = document.getElementById("qr-canvas")).style.width = e + "px"),
(gCanvas.style.height = t + "px"),
(gCanvas.width = e),
(gCanvas.height = t),
(gCtx = gCanvas.getContext("2d")).clearRect(0, 0, e, t);
}
function captureToCanvas() {
if (1 == stype && gUM)
try {
gCtx.drawImage(v, 0, 0);
try {
qrcode.decode();
} catch (e) {
console.log(e), setTimeout(captureToCanvas, 500);
}
} catch (e) {
console.log(e), setTimeout(captureToCanvas, 500);
}
}
function htmlEntities(e) {
return String(e)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
}
function read(e) {
(document.getElementById("hasil").innerHTML =
e),
(window.location = unescape(getAllUrlParams().back) + e)
;
}
function isCanvasSupported() {
var e = document.createElement("canvas");
return !(!e.getContext || !e.getContext("2d"));
}
function success(e) {
(v.srcObject = e), v.play(), (gUM = !0), setTimeout(captureToCanvas, 500);
}
function error(e) {
gUM = !1;
}
function load() {
isCanvasSupported() && window.File && window.FileReader
? (initCanvas(800, 600),
(qrcode.callback = read),
(document.getElementById("mainbody").style.display = "inline"),
setwebcam())
: ((document.getElementById("mainbody").style.display = "inline"),
(document.getElementById("mainbody").innerHTML =
'<p id="mp1">QR code scanner for HTML5 capable browsers</p><br><br><p id="mp2">sorry your browser is not supported</p><br><br><p id="mp1">try <a href="http://www.mozilla.com/firefox"><img src="firefox.png"/></a> or <a href="http://chrome.google.com"><img src="chrome_logo.gif"/></a> or <a href="http://www.opera.com"><img src="Opera-logo.png"/></a></p>'));
}
function setwebcam() {
var e = !0;
if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices)
try {
navigator.mediaDevices.enumerateDevices().then(function (t) {
t.forEach(function (t) {
"videoinput" === t.kind &&
t.label.toLowerCase().search("back") > -1 &&
(e = {
deviceId: { exact: t.deviceId },
facingMode: "environment",
}),
console.log(t.kind + ": " + t.label + " id = " + t.deviceId);
}),
setwebcam2(e);
});
} catch (e) {
console.log(e);
}
else console.log("no navigator.mediaDevices.enumerateDevices"), setwebcam2(e);
}
function setwebcam2(e) {
if ((console.log(e), 1 != stype)) {
var t = navigator;
(document.getElementById("camera-inside").innerHTML = vidhtml),
(v = document.getElementById("v")),
t.mediaDevices.getUserMedia
? t.mediaDevices
.getUserMedia({ video: e, audio: !1 })
.then(function (e) {
success(e);
})
.catch(function (e) {
e(e);
})
: t.getUserMedia
? ((webkit = !0),
t.getUserMedia({ video: e, audio: !1 }, success, error))
: t.webkitGetUserMedia &&
((webkit = !0),
t.webkitGetUserMedia({ video: e, audio: !1 }, success, error)),
(stype = 1),
setTimeout(captureToCanvas, 500);
} else setTimeout(captureToCanvas, 500);
}
function setimg() {
if (((document.getElementById("result").innerHTML = ""), 2 != stype)) {
(document.getElementById("camera-inside").innerHTML = imghtml),
(document.getElementById("qrimg").style.opacity = 1),
(document.getElementById("webcamimg").style.opacity = 0.2);
var e = document.getElementById("qrfile");
e.addEventListener("dragenter", dragenter, !1),
e.addEventListener("dragover", dragover, !1),
e.addEventListener("drop", drop, !1),
(stype = 2);
}
}
load();
</script>
</body>
</html>

1
scan/llqrcode.js Normal file

File diff suppressed because one or more lines are too long

0
scan/webqr.js Normal file
View File

View File

@ -17,10 +17,11 @@ switch ($action) {
case 'isLogin':
$bill = ORM::for_table('tbl_user_recharges')->where('id', $routes['2'])->where('username', $user['username'])->findOne();
if ($bill['type'] == 'Hotspot' && $bill['status'] == 'on') {
$dvc = Package::getDevice($d);
$p = ORM::for_table('tbl_plans')->find_one($bill['plan_id']);
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
require_once $dvc;
if ((new $d['device'])->online_customer($user, $bill['routers'])) {
if ((new $p['device'])->online_customer($user, $bill['routers'])) {
die('<a href="' . U . 'home&mikrotik=logout&id='.$bill['id'].'" onclick="return confirm(\''.Lang::T('Disconnect Internet?').'\')" class="btn btn-success btn-xs btn-block">'.Lang::T('You are Online, Logout?').'</a>');
} else {
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {

View File

@ -24,7 +24,7 @@ $reset_day = $config['reset_day'];
if(empty($reset_day)){
$reset_day = 1;
}
$reset_day = 20;
//first day of month
if($reset_day >= date("d")){
$first_day_month = date('Y-m-'.$reset_day);

View File

@ -230,5 +230,6 @@ $ui->assign('unpaid', ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->where('status', 1)
->find_one());
$ui->assign('code', alphanumeric(_get('code')));
run_hook('view_customer_dashboard'); #HOOK
$ui->display('user-dashboard.tpl');

View File

@ -182,6 +182,7 @@ switch ($do) {
default:
run_hook('customer_view_login'); #HOOK
if ($config['disable_registration'] == 'yes') {
$ui->assign('code', alphanumeric(_get('code')));
$ui->display('user-login-noreg.tpl');
} else {
$ui->display('user-login.tpl');

View File

@ -17,6 +17,7 @@ switch ($action) {
case 'activation':
run_hook('view_activate_voucher'); #HOOK
$ui->assign('code', alphanumeric(_get('code')));
$ui->display('user-activation.tpl');
break;

View File

@ -642,5 +642,7 @@
"Time": "Time",
"Data": "Data",
"Category": "Category",
"later": "later"
"later": "later",
"Package_Details": "Package Details",
"Summary": "Summary"
}

View File

@ -2,34 +2,33 @@
<!-- user-activation -->
<div class="row">
<div class="col-sm-12">
<div class="col-md-8">
<div class="box box-primary box-solid">
<div class="box-header"><h3 class="box-title">{Lang::T('Order Voucher')}</h3></div>
<div class="box-header">
<h3 class="box-title">{Lang::T('Order Voucher')}</h3>
</div>
<div class="box-body">
{include file="$_path/../pages/Order_Voucher.html"}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="panel panel-success panel-hovered panel-stacked mb30">
<div class="panel-heading">{Lang::T('Voucher Activation')}</div>
<div class="panel-body">
<form class="form-horizontal" method="post" role="form" action="{$_url}voucher/activation-post">
<div class="col-md-4">
<div class="box box-primary box-solid">
<div class="box-header">{Lang::T('Voucher Activation')}</div>
<div class="box-body">
<form method="post" role="form" action="{$_url}voucher/activation-post">
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Code Voucher')}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="code" name="code"
<div class="input-group">
<input type="text" class="form-control" id="code" name="code" value="{$code}"
placeholder="{Lang::T('Enter voucher code here')}">
<span class="input-group-btn">
<a class="btn btn-default" href="{APP_URL}/scan/?back={urlencode($_url)}{urlencode("voucher/activation&code=")}"><i class="glyphicon glyphicon-qrcode"></i></a>
</span>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success"
type="submit">{Lang::T('Recharge')}</button>
<button class="btn btn-success" type="submit">{Lang::T('Recharge')}</button>
Or <a href="{$_url}home">{Lang::T('Cancel')}</a>
</div>
</div>

View File

@ -288,26 +288,28 @@
</div>
<div class="box-body">
<form method="post" role="form" class="form-horizontal" action="{$_url}voucher/activation-post">
<div class="form-group">
<label class="col-sm-4 control-label text-center">{Lang::T('Code Voucher')}</label>
<div class="col-sm-7">
<input type="text" id="code" name="code" class="form-control"
placeholder="{Lang::T('Enter voucher code here')}">
</div>
</div>
<div class="form-group" align="center">
<button class="btn btn-success" type="submit">{Lang::T('Recharge')}</button>
<div class="input-group">
<span class="input-group-btn">
<a class="btn btn-default"
href="{APP_URL}/scan/?back={urlencode($_url)}{urlencode("home&code=")}"><i
class="glyphicon glyphicon-qrcode"></i></a>
</span>
<input type="text" id="code" name="code" class="form-control"
placeholder="{Lang::T('Enter voucher code here')}" value="{$code}">
<span class="input-group-btn">
<button class="btn btn-primary" type="submit">{Lang::T('Recharge')}</button>
</span>
</div>
</form>
</div>
<div class="box-body">
<div class="btn-group btn-group-justified" role="group">
<a class="btn btn-warning" href="{$_url}voucher/activation">
<a class="btn btn-default" href="{$_url}voucher/activation">
<i class="ion ion-ios-cart"></i>
{Lang::T('Order Voucher')}
</a>
{if $_c['payment_gateway'] != 'none' or $_c['payment_gateway'] == '' }
<a href="{$_url}order/package" class="btn btn-primary">
<a href="{$_url}order/package" class="btn btn-default">
<i class="ion ion-ios-cart"></i>
{Lang::T('Order Package')}
</a>

View File

@ -59,8 +59,13 @@
</div>
<div class="form-group">
<label>{Lang::T('Enter voucher code here')}</label>
<input type="text" class="form-control" name="voucher" required autocomplete="off"
placeholder="{Lang::T('Code Voucher')}">
<div class="input-group">
<input type="text" class="form-control" id="voucher" name="voucher" required value="{$code}"
placeholder="{Lang::T('Enter voucher code here')}">
<span class="input-group-btn">
<a class="btn btn-default" href="{APP_URL}/scan/?back={urlencode($_url)}{urlencode("login&code=")}"><i class="glyphicon glyphicon-qrcode"></i></a>
</span>
</div>
</div>
<div class="btn-group btn-group-justified mb15">
<div class="btn-group">