2016-07-17 08:27:59 +00:00
|
|
|
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
2016-07-15 14:09:49 +00:00
|
|
|
|
|
|
|
$_SESSION['history'] = [];
|
|
|
|
|
2016-07-17 08:27:59 +00:00
|
|
|
if( !isset($_COOKIE['mac_password']) || !isset($_COOKIE['mac_count']) ){
|
|
|
|
$_COOKIE['mac_count'] = 9;
|
|
|
|
$_COOKIE['mac_password'] = 'macPassword';
|
|
|
|
|
|
|
|
setcookie('mac_count', $_COOKIE['mac_count'], time()+3600*24*365, '/');
|
|
|
|
setcookie('mac_password', $_COOKIE['mac_password'], time()+3600*24*365, '/');
|
|
|
|
|
|
|
|
header('Refresh: 0');
|
|
|
|
}
|
|
|
|
|
2016-07-15 14:09:49 +00:00
|
|
|
?>
|
|
|
|
<!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>
|
2016-07-17 08:27:59 +00:00
|
|
|
<span id='cookie-box'>
|
|
|
|
<?= $_COOKIE['mac_password']; ?>
|
|
|
|
<br>
|
|
|
|
<?= $_COOKIE['mac_count']; ?>
|
|
|
|
</span><br><br>
|
|
|
|
<hr>
|
2016-07-15 14:09:49 +00:00
|
|
|
<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"]');
|
|
|
|
|
2016-07-17 08:27:59 +00:00
|
|
|
var cBox = document.querySelector('#cookie-box');
|
2016-07-15 14:09:49 +00:00
|
|
|
var sBox = document.querySelector('#status-box');
|
|
|
|
var hBox = document.querySelector('#history-box');
|
|
|
|
|
|
|
|
var FD = new FormDeflater(document.body, ['input'], ['data-name']);
|
|
|
|
|
2016-07-17 08:27:59 +00:00
|
|
|
var selfApi = new APIClass('/test/client/background.php');
|
2016-07-15 14:09:49 +00:00
|
|
|
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){
|
2016-07-17 08:27:59 +00:00
|
|
|
var req = {
|
|
|
|
'sync' : null,
|
|
|
|
};
|
|
|
|
|
|
|
|
selfApi.send(req, function(res){
|
|
|
|
cBox.innerHTML = res.pwd+'<br>'+res.count;
|
|
|
|
console.log(res);
|
|
|
|
});
|
|
|
|
|
2016-07-15 14:09:49 +00:00
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|