SMMP/test/client/interface.php

182 lines
4.8 KiB
PHP
Raw Normal View History

<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
require_once __ROOT__.'/manager/autoloader.php';
$_SESSION['history'] = [];
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');
}
?>
<!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='cookie-box'>
<?= $_COOKIE['mac_password']; ?>
<br>
<?= $_COOKIE['mac_count']; ?>
</span><br><br>
<hr>
<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 cBox = document.querySelector('#cookie-box');
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/client/background.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){
var req = {
'sync' : null,
};
selfApi.send(req, function(res){
cBox.innerHTML = res.pwd+'<br>'+res.count;
console.log(res);
});
}, false);
</script>
</body>
</html>