document.addEventListener("DOMContentLoaded", pagePrete); const DUREE_SESSION = 1800; // En secondes; var timerSessions; var timerDeconnexion; // En secondes var inactivite = -1; function pagePrete() { timerSessions = setInterval(() => { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { var currentStrong = document.querySelector("#utilisateursEnLigne strong"); var nouveauStrong = currentStrong.cloneNode(true); //console.log(this.responseText); $DATAS = this.responseText.split(";"); sessionsActives = $DATAS[0]; if (parseInt($DATAS[1]) != -1) { inactivite = parseInt($DATAS[1]); } nouveauStrong.innerHTML = sessionsActives; currentStrong.parentNode.replaceChild(nouveauStrong , currentStrong); /* if (sessionsActives == "0") { //-- On doit se deconnecter si on n'est pas sur la page d'identification let $PAGE_COURANTE = window.location.href.split("/").pop(); if ( ($PAGE_COURANTE != "IDENTIFICATION.php") && ($PAGE_COURANTE != "PLANNING.php") ) { //-- Se deconnecter ! alert("Comme t'étais plus là, j'ai fermé ta session... \nM'en veux pas !"); window.location = "https://spvinay.sipea.fr/?seDeconnecter"; } } else { nouveauStrong.innerHTML = sessionsActives; currentStrong.parentNode.replaceChild(nouveauStrong , currentStrong); } */ } xhttp.open("GET", "https://spvinay.sipea.fr/Ajax/getSessionsActives.php", true); xhttp.send(); } ,10 * 1000); let $PAGE_COURANTE = window.location.href.split("/").pop(); if ( ($PAGE_COURANTE != "IDENTIFICATION.php") && ($PAGE_COURANTE != "PLANNING.php") ) { timerDeconnexion = setInterval(() => { if (inactivite != -1) { inactivite += 1; //console.log(inactivite); let BUTTON = document.getElementById("prolongerSession"); let dureeRestante = (DUREE_SESSION - inactivite); if (dureeRestante >= 60) { BUTTON.style.display = "none"; } else if (0 >= dureeRestante) { BUTTON.style.display = "none"; clearInterval(timerDeconnexion); alert("Comme t'étais plus là, j'ai fermé ta session... \nM'en veux pas !"); window.location = "https://spvinay.sipea.fr/?seDeconnecter"; } else { BUTTON.style.display = "block"; BUTTON.innerHTML = "Déconnexion automatique dans "+dureeRestante+" secondes
Je suis toujours là !"; //-- On scale les 30 dernières secondes seulement ! let scale = 1 + (Math.max(0, 30 - dureeRestante)/30) * 3; BUTTON.style.transform = "scale("+scale.toFixed(2)+")"; } } } ,1000); } } function prolongerSession() { clearInterval(timerSessions); clearInterval(timerDeconnexion); let BUTTON = document.getElementById("prolongerSession"); BUTTON.style.display = "none"; inactivite = 0; let xhttp_local = new XMLHttpRequest(); xhttp_local.onload = function() { pagePrete(); } xhttp_local.open("GET", "https://spvinay.sipea.fr/Ajax/prolongerSession.php", true); xhttp_local.send(); }