-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.php
More file actions
151 lines (115 loc) · 4.17 KB
/
scanner.php
File metadata and controls
151 lines (115 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
require 'php/vendor/autoload.php';
use PontosDeVida\Connection as Connection;
use PontosDeVida\PontosDeVidaFuncoes as PontosDeVidaFuncoes;
session_start();
try {
$pdo = Connection::get()->connect();
$chamador = new PontosDeVidaFuncoes($pdo);
$dados = $chamador->meusDados();
} catch (\PDOException $e) {
echo $e->getMessage();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Pontos de Vida</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="mdl/material.min.css">
<script src="mdl/material.min.js" id="mdl-script"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="css/dialog-polyfill.css">
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<div id="qrCodeDialog">
<video autoplay id="camsource"></video>
</div>
</div>
<script src="js/jsqrcode.js"></script>
<script src="app.js"></script>
<script>
if(!iOS()){
let qrDialog = document.getElementById("qrCodeDialog");
// script que programa o funcionamento do leitor de QR Code //
// -- aqui cria um canvas que exibe a imagem da camera --
let qrCanvas = document.createElement('canvas');
qrCanvas.id = 'qr-canvas';
qrCanvas.style.display = 'none';
qrDialog.appendChild(qrCanvas);
addEventListener
// -- aqui configura a tag video para exibir a imagem da webcam --
let qrVideo = qrDialog.querySelector('#camsource');
let videoOptions = {
"audio": false,
"video": { facingMode: "environment" }
};
// -- aqui configura a webcam como fonte de imagem da tag vídeo
var stream = new MediaSource();
// console.assert(navigator.getUserMedia, 'navigator.getUserMedia not defined')
navigator.getUserMedia(videoOptions, function (stream) {
qrVideo.srcObject = stream;
}, (error)=> {
console.log(error);
alert('Camera traseira desativada');
});
// aqui armazena a informação recebida pelo Leitor
qrcode.callback = function read(qrCodeValue){
// console.log(qrCodeValue);
var parts = qrCodeValue.split('/');
var lastSegment = parts.pop() || parts.pop(); // handle potential trailing slash
// console.log(lastSegment);
if(lastSegment=='retorno.php'){
window.location.href = '/'+lastSegment;
}
};
// -- função que escaneia o vídeo
function scanVideoNow() {
if(qrVideo.videoWidth === 0) return;
let scale = 0.5
let qrCanvas = qrDialog.querySelector("#qr-canvas");
let context = qrCanvas.getContext('2d');
qrCanvas.width = qrVideo.videoWidth * scale;
qrCanvas.height = qrVideo.videoHeight * scale;
context.drawImage(qrVideo, 0, 0, qrCanvas.width, qrCanvas.height);
try {
qrcode.decode();
var foundResult = true;
} catch(error) {
console.log('jsqrcode', error);
// alert('Não consigo ler o QrCode');
var foundResult = false;
};
return foundResult;
}
// -- Iniciando o leitor
scanVideoNow()
setInterval(() => {scanVideoNow()}, 500);
}
else{
window.location.href = 'ios.php';
}
function iOS() {
var iDevices = [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
];
if (!!navigator.platform) {
while (iDevices.length) {
if (navigator.platform === iDevices.pop()){ return true; }
}
}
return false;
}
</script>
</body>
</html>