157 lines
4.1 KiB
PHP
157 lines
4.1 KiB
PHP
<?php
|
|
|
|
session_start();
|
|
|
|
$_SESSION['history'] = [];
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Virtual Client</title>
|
|
|
|
|
|
<script type='text/javascript' src='/js/lib/reset.js' ></script> <!-- Corrections Javascript natif (ajouts) -->
|
|
<script type='text/javascript' src='/js/lib/api.js' ></script> <!-- Gestion des transactions avec le serveur -->
|
|
<script type='text/javascript' src='/js/lib/page-manager.js' ></script> <!-- Gestion réseau/chargement/liens/URL -->
|
|
<script type='text/javascript' src='/js/lib/form-deflater.js' ></script> <!-- Gestion des formulaires (Object) -->
|
|
</head>
|
|
<body>
|
|
|
|
<input type='text' data-name='user-code' placeholder='Code RFID utilisateur'><br><br>
|
|
|
|
<br><br>
|
|
|
|
<input type='button' data-name='start-stop' value='Start/Stop'><br><br>
|
|
<input type='button' data-name='signal' value='Signaler' ><br><br>
|
|
<input type='button' data-name='lock' value='Bloquer' ><br><br>
|
|
<input type='button' data-name='unlock' value='Débloquer' ><br><br>
|
|
<input type='button' data-name='sync' value='Synchroniser'><br><br>
|
|
|
|
<br><br>
|
|
<span id='status-box'></span><br><br>
|
|
<hr>
|
|
<span id='history-box'></span><br><br>
|
|
|
|
|
|
<script type='text/javascript'>
|
|
/* (0) Initialisation des éléments du DOM */
|
|
var tCode = document.querySelector('input[data-name="user-code"]');
|
|
|
|
var bStartStop = document.querySelector('input[data-name="start-stop"]');
|
|
var bSignal = document.querySelector('input[data-name="signal"]');
|
|
var bLock = document.querySelector('input[data-name="lock"]');
|
|
var bUnlock = document.querySelector('input[data-name="unlock"]');
|
|
var bSync = document.querySelector('input[data-name="sync"]');
|
|
|
|
var sBox = document.querySelector('#status-box');
|
|
var hBox = document.querySelector('#history-box');
|
|
|
|
var FD = new FormDeflater(document.body, ['input'], ['data-name']);
|
|
|
|
var selfApi = new APIClass('/test/clientBackground.php');
|
|
var remoteApi = new APIClass('/api/');
|
|
|
|
var state = false;
|
|
var locked = false;
|
|
var signaled = false;
|
|
|
|
/* (1) Gestion du StartStop */
|
|
bStartStop.addEventListener('click', function(e){
|
|
if( locked ) return;
|
|
|
|
var data = FD.deflate();
|
|
|
|
var req = {
|
|
'code' : data['user-code'],
|
|
'action' : state ? 'stop' : 'start'
|
|
};
|
|
|
|
state = !state;
|
|
|
|
selfApi.send(req, function(res){
|
|
hBox.innerHTML = res.data;
|
|
});
|
|
|
|
sBox.innerHTML = '- bloqué : '+locked+'<br> - signalé : '+signaled+'<br> - en marche : '+state;
|
|
|
|
}, false);
|
|
|
|
/* (2) Gestion du Signalement */
|
|
bSignal.addEventListener('click', function(e){
|
|
if( locked || signaled ) return;
|
|
|
|
var data = FD.deflate();
|
|
|
|
var req = {
|
|
'code' : data['user-code'],
|
|
'action' : 'signal'
|
|
};
|
|
|
|
selfApi.send(req, function(res){
|
|
hBox.innerHTML = res.data;
|
|
});
|
|
|
|
signaled = true;
|
|
|
|
sBox.innerHTML = '- bloqué : '+locked+'<br> - signalé : '+signaled+'<br> - en marche : '+state;
|
|
|
|
}, false);
|
|
|
|
/* (3) Gestion du blocage */
|
|
bLock.addEventListener('click', function(e){
|
|
if( locked ) return;
|
|
|
|
var data = FD.deflate();
|
|
|
|
var req = {
|
|
'code' : data['user-code'],
|
|
'action' : 'lock'
|
|
};
|
|
|
|
selfApi.send(req, function(res){
|
|
hBox.innerHTML = res.data;
|
|
});
|
|
|
|
locked = true;
|
|
state = false;
|
|
signaled = false;
|
|
|
|
sBox.innerHTML = '- bloqué : '+locked+'<br> - signalé : '+signaled+'<br> - en marche : '+state;
|
|
|
|
}, false);
|
|
|
|
/* (4) Gestion du déblocage */
|
|
bUnlock.addEventListener('click', function(e){
|
|
if( !locked && !signaled ) return;
|
|
|
|
|
|
var data = FD.deflate();
|
|
|
|
var req = {
|
|
'code' : data['user-code'],
|
|
'action' : 'unlock'
|
|
};
|
|
|
|
selfApi.send(req, function(res){
|
|
hBox.innerHTML = res.data;
|
|
});
|
|
|
|
locked = false;
|
|
state = false;
|
|
signaled = false;
|
|
|
|
sBox.innerHTML = '- bloqué : '+locked+'<br> - signalé : '+signaled+'<br> - en marche : '+state;
|
|
|
|
}, false);
|
|
|
|
/* (5) Gestion de la synchro */
|
|
bSync.addEventListener('click', function(e){
|
|
|
|
}, false);
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|