// file = actions // The different items of the // right-side menu var connection; var subscribe; var lostPassword; var deconnection; var profile; // The background "calque" var calque; // The howto var howto; // The login form var login; var loginForm; var waitingLogin; var badIdentification; // The registration form var register; var registerForm; var errorForm; var emptyLogin; var invalidLogin; var emptyPass; var invalidConfirmPass; var invalidMail; var badMail; var waitingRegister; var registrationOk; var registrationNotOk; // The form for a new password var lostPasswd; var lostPasswdForm; var waitingNewPass; var sendPassOk; var sendPassNotOk; // The publish form var publish; var publishForm; var idNeeded; var loginNeeded; var errorLogin; var errorPublish; var successPublish; var alreadyPublished; var waitingPublish; var update; var updateForm; var emptyPassUp; var invalidMailUp; var badMailUp; var depUp; var waitingUpdate; var updateOk; var updateNotOk; var profileUser; // Initialize all the DIVs and forms in the document function initForms() { // Right-side menu connection = document.getElementById("connection"); subscribe = document.getElementById("subscribe"); lostPassword = document.getElementById("lostPassword"); deconnection = document.getElementById("deconnection"); profileUser = document.getElementById("profileUser"); // The howto howto = document.getElementById("howTo"); // Login form login = document.getElementById("login"); loginForm = document.getElementById("loginForm"); waitingLogin = document.getElementById("waitingLogin"); badIdentification = document.getElementById("badIdentification"); // Registration form calque = document.getElementById("calque"); register = document.getElementById("register"); registerForm = document.getElementById("registerForm"); errorForm = document.getElementById("incompleteForm"); emptyLogin = document.getElementById("emptyLogin"); invalidLogin = document.getElementById("invalidLogin"); emptyPass = document.getElementById("emptyPass"); invalidConfirmPass = document.getElementById("invalidConfirmPass"); invalidMail = document.getElementById("invalidMail"); badMail = document.getElementById("badMail"); waitingRegister = document.getElementById("waitingRegister"); registrationOk = document.getElementById("registrationOk"); registrationNotOk = document.getElementById("registrationNotOk"); // New pass form lostPasswd = document.getElementById("lostPasswd"); lostPasswdForm = document.getElementById("lostPasswdForm"); waitingNewPass = document.getElementById("waitingNewPass"); sendPassOk = document.getElementById("sendPassOk"); sendPassNotOk = document.getElementById("sendPassNotOk"); // Publish form publish = document.getElementById("publish"); publishForm = document.getElementById("publishForm"); idNeeded = document.getElementById("idNeeded"); loginNeeded = document.getElementById("loginNeeded"); errorLogin = document.getElementById("errorLogin"); errorPublish = document.getElementById("errorPublish"); successPublish = document.getElementById("successPublish"); alreadyPublished = document.getElementById("alreadyP"); waitingPublish = document.getElementById("waitingPublish"); // Update form update = document.getElementById("update"); updateForm = document.getElementById("updateForm"); emptyPassUp = document.getElementById("emptyPassUp"); invalidMailUp = document.getElementById("invalidMailUp"); badMailUp = document.getElementById("badMailUp"); depUp = document.getElementById("depUp"); waitingUpdate = document.getElementById("waitingUpdate"); updateOk = document.getElementById("updateOk"); updateNotOk = document.getElementById("updateNotOk"); profile = document.getElementById("profile"); if (document.body) { var haut = (document.body.clientHeight); calque.style.height = haut +"px"; } if (DEFAULT_NODE_NAME == "Temporaire") { showMenu(DECONNECTED); } else { showMenu(CONNECTED); } } /**************************************************** Marche pas *********************************/ //window.captureEvents(Event.RESIZE); //window.onresize = function() { // if (document.body) { // var haut = document.body.clientHeight; // calque.style.height = haut +"px"; // } //} // Display the right-side menu depending on the user's status function showMenu(state) { if (state == CONNECTED) { calque.style.display = "none"; login.style.display = "none"; loginForm.style.display = "none"; waitingLogin.style.display = "none"; badIdentification.style.display = "none"; register.style.display = "none"; lostPasswd.style.display = "none"; connection.style.display = "none"; subscribe.style.display = "none"; lostPassword.style.display = "none"; deconnection.style.display = "list-item"; profile.style.display = "list-item"; loginForm.style.display = "none"; publish.style.display = "none"; successPublish.style.display = "none"; alreadyPublished.style.display = "none"; } else if (state == DECONNECTED) { calque.style.display = "none"; login.style.display = "none"; loginForm.style.display = "none"; badIdentification.style.display = "none"; waitingLogin.style.display = "none"; register.style.display = "none"; lostPasswd.style.display = "none"; connection.style.display = "list-item"; subscribe.style.display = "list-item"; lostPassword.style.display = "list-item"; deconnection.style.display = "none"; profile.style.display = "none"; } else if (state == LOGIN) { document.loginForm.reset(); calque.style.display = "block"; login.style.display = "block"; loginForm.style.display = "block"; waitingLogin.style.display = "none"; badIdentification.style.display = "none"; // register.style.display = "none"; document.loginForm.login.focus(); } else if (state == SUBSCRIBE) { document.registerForm.reset(); calque.style.display = "block"; register.style.display = "block"; registerForm.style.display = "block"; errorForm.style.display = "none"; emptyLogin.style.display = "none"; invalidLogin.style.display = "none"; emptyPass.style.display = "none"; invalidConfirmPass.style.display = "none"; invalidMail.style.display = "none"; badMail.style.display = "none"; waitingRegister.style.display = "none"; registrationOk.style.display = "none"; registrationNotOk.style.display = "none"; document.registerForm.login.focus(); } else if (state == NEWPASS) { document.lostPasswdForm.reset(); calque.style.display = "block"; lostPasswd.style.display = "block"; lostPasswdForm.style.display = "block"; waitingNewPass.style.display = "none"; sendPassOk.style.display = "none"; sendPassNotOk.style.display = "none"; document.lostPasswdForm.loginMail.focus(); } else if (state == HOWTO) { calque.style.display = "block"; howto.style.display = "block"; } else if (state == PUBLISH) { calque.style.display = "block"; publish.style.display = "block"; if (document.publishForm.lon) { idNeeded.style.display = "none"; loginNeeded.style.display = "none"; } } else if (state == PROFILE) { calque.style.display = "block"; update.style.display = "block"; } } // Validates if the login form is correct function validateLogin() { badIdentification.style.display = "none"; var login = document.loginForm.login.value; var pass = document.loginForm.pass.value; var request = GXmlHttp.create (); request.open('GET', 'connection.php?login='+login+'&pass='+pass, true); request.onreadystatechange = function() { if (request.readyState == 4) { /* 4 : complete state */ if (request.status == 200) { /* 200 : HTTP code OK */ checkResponseLogin(request, login); } else { waitingLogin.style.display = "none"; loginForm.style.display = "block"; alert('Erreur : veuillez réessayer plus tard, merci…'); } } } request.send(null); loginForm.style.display = "none"; waitingLogin.style.display = "block"; } function checkUpdate(JSONObject) { if (JSONObject.Status.code == 200) { if (JSONObject.Infos.success) { waitingUpdate.style.display = "none"; updateOk.style.display = "block"; document.updateForm.passUp.value = ""; } else { waitingUpdate.style.display = "none"; updateNotOk.style.display = "block"; } } else { waitingUpdate.style.display = "none"; updateNotOk.style.display = "block"; } } function validateUpdate() { updateForm.style.display = "none"; waitingUpdate.style.display = "block"; var pass = document.updateForm.passUp.value; var mail = document.updateForm.mailUp.value; var site = document.updateForm.siteUp.value; var dep = document.updateForm.depUp.value; var ffw = (document.updateForm.ffwUp.checked) ? 1 : 0; UserManager.update(pass, "", mail, site, dep, ffw, checkUpdate); } function loadPerso(idU) { var request = GXmlHttp.create (); request.open('GET', 'perso.php?idU='+idU+'&idMarkers='+idMarkers, true); idMarkers = ""; request.onreadystatechange = function() { if (request.readyState == 4) { /* 4 : complete state */ if (request.status == 200) { /* 200 : HTTP code OK */ //var xmlDoc = request.responseXML; var xmlDoc = GXml.parse(request.responseText); // Add Nodes which come from the database var markersFromXml = xmlDoc.documentElement.getElementsByTagName ("nodes")[0].getElementsByTagName ("node"); var temp; for (var i = 0; i < markersFromXml.length; i++) { nb++; var idUser = parseInt(markersFromXml[i].getAttribute("idUser")); var idMarker = parseInt(markersFromXml[i].getAttribute("idMarker")); idMarkers += idMarker+','; var name = markersFromXml[i].getAttribute("name"); var lat = parseFloat(markersFromXml[i].getAttribute("lat")); var lng = parseFloat(markersFromXml[i].getAttribute("lng")); var status = parseInt(markersFromXml[i].getAttribute("status")); var desc = unescape(markersFromXml[i].getAttribute("description")); var IPAddr = markersFromXml[i].getAttribute("IPAddr"); var modemType= parseInt(markersFromXml[i].getAttribute("modemType")); var actif; temp = parseInt(markersFromXml[i].getAttribute("actif")); if (temp != 0) { actif = true; } else { actif = false; } var site = markersFromXml[i].getAttribute("Site"); var perso; temp = markersFromXml[i].getAttribute("perso"); if (temp != 0) { perso = true; } else { perso = false; } if (markers[name]) { updateMyPersoMarker(CONNECT); nb--; } else { var markerTemp = new NodeMarker (name, idUser, idMarker, desc, status, lng, lat, IPAddr, modemType, actif, site, perso); markers[markerTemp.name] = markerTemp ; if (markerTemp.perso) { currentMarker = markerTemp; } addMarkerInMap(markerTemp, showWiFiCoverage.checked); } if (!note) { note = document.createElement("span"); note.style.position = "absolute"; note.style.bottom = 30+"px"; note.style.left = "0px"; note.style.fontSize= "20px"; if (isIE) { //note.filters.alpha.opacity = 60; } else { note.style.opacity = 0.6; } note.style.zIndex = "1000000"; note.style.textAlign = "left"; note.id = "note"; note.style.background = "white"; map.container.appendChild(note); } note.innerHTML = nb + " marqueurs affichés sur "+nbTotal; } } else { waitingLogin.style.display = "none"; loginForm.style.display = "block"; alert('Erreur : veuillez réessayer plus tard, merci…'); } } } request.send(null); } // Checks the response from the server for the login request function checkResponseLogin(request, login) { var respT = request.responseText; if (respT == 'null') { waitingLogin.style.display = "none"; loginForm.style.display = "block"; document.loginForm.pass.value = ""; badIdentification.style.display = "block"; } else { ID_USER = parseInt(respT); DEFAULT_NODE_NAME = login; loadPerso(ID_USER); // updateMyPersoMarker(CONNECT); document.loginForm.reset(); showMenu(CONNECTED); } } // Deconnects the user from the site function deconnect() { var request = GXmlHttp.create (); request.open('GET', 'deconnection.php', true); request.onreadystatechange = function() { if (request.readyState == 4) { /* 4 : complete state */ if (request.status == 200) { /* 200 : HTTP code OK */ waitingLogin.style.display = "none"; ID_USER = -1; DEFAULT_NODE_NAME = "Temporaire"; showMenu(DECONNECTED); updateMyPersoMarker(DECONNECT); } else { waitingLogin.style.display = "none"; alert('Erreur : petit problème technique...'); } } } request.send(null); waitingLogin.style.display = "block"; } // Checks if an email is valid function isValidEmail(mail) { var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i; return email.test(mail); } function trim(string) { pattern1 = /^\s{1,}|\s{1,}$/g; pattern2 = /\s{2,}/g; return string.replace(pattern1, '').replace(pattern2, ' '); } function validateRegistration() { var formOk = true; errorForm.style.display = "none"; emptyLogin.style.display = "none"; invalidLogin.style.display = "none"; emptyPass.style.display = "none"; invalidConfirmPass.style.display = "none"; invalidMail.style.display = "none"; var login = trim(document.registerForm.login.value); var pass = trim(document.registerForm.pass.value); var confirmPass = trim(document.registerForm.confirmPass.value); var mail = trim(document.registerForm.mail.value); var site = trim(document.registerForm.site.value); var dep = document.registerForm.dep.value; var ffw = (document.registerForm.ffw.checked) ? 1 : 0; if (login == '') { formOk = false; emptyLogin.style.display = "inline"; } if (pass == '') { formOk = false; emptyPass.style.display = "inline"; } if (pass != confirmPass) { formOk = false; invalidConfirmPass.style.display = "inline"; } if (!isValidEmail(mail)) { formOk = false; invalidMail.style.display = "inline"; } if (!formOk) { errorForm.style.display = "block"; } else { var request = GXmlHttp.create (); request.open('GET', 'registration.php?login='+login+'&pass='+pass+'&mail='+mail+'&site='+site+'&dep='+dep+'&ffw='+ffw, true); request.onreadystatechange = function() { if (request.readyState == 4) { /* 4 : complete state */ if (request.status == 200) { /* 200 : HTTP code OK */ checkResponseRegistration(request, login); } else { waitingRegister.style.display = "none"; registrationNotOk.style.display = "block"; } } } request.send(null); registerForm.style.display = "none"; waitingRegister.style.display = "block"; } } function checkResponseRegistration(request, login) { var respT = request.responseText; waitingRegister.style.display = "none"; if (respT != 'ok') { if (respT == 'loginmail') { errorForm.style.display = "block"; badMail.style.display = "block"; invalidLogin.style.display = "block"; returnToForm(); } else if (respT == 'login') { errorForm.style.display = "block"; invalidLogin.style.display = "block"; returnToForm(); } else if (respT == 'mail') { errorForm.style.display = "block"; badMail.style.display = "block"; returnToForm(); } else { registrationNotOk.style.display = "block"; } } else { registrationOk.style.display = "block"; } } function sendNewPass() { var pattern = /^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i; var entry = trim(document.lostPasswdForm.loginMail.value); if (entry != '') { var type = "login"; if (entry.match(pattern)) { type = "mail"; } var request = GXmlHttp.create (); request.open('GET', 'sendnewpass.php?type='+type+'&entry='+entry, true); request.onreadystatechange = function() { if (request.readyState == 4) { /* 4 : complete state */ if (request.status == 200) { /* 200 : HTTP code OK */ checkResponseNewPass(request); } else { waitingNewPass.style.display = "none"; sendPassNotOk.style.display = "block"; } } } request.send(null); lostPasswdForm.style.display = "none"; waitingNewPass.style.display = "block"; } else { lostPasswdForm.style.display = "none"; sendPassNotOk.style.display = "block"; } } function checkResponseNewPass(request) { var respT = request.responseText; waitingNewPass.style.display = "none"; if (respT != 'ok') { sendPassNotOk.style.display = "block"; } else { sendPassOk.style.display = "block"; } } function checkBefore() { idNeeded.style.display = "none"; errorLogin.style.display = "none"; errorPublish.style.display = "none"; alreadyPublished.style.display = "none"; successPublish.style.display = "none"; document.publishForm.reset(); if (document.publishForm.lng) { document.publishForm.lng.value = currentMarker.lng; document.publishForm.lat.value = currentMarker.lat; document.publishForm.description.value = currentMarker.description; document.publishForm.typeModem.value = FreeBoxTypeText[parseInt(""+currentMarker.modemType)-1]; var request = GXmlHttp.create (); request.open('GET', 'isconnected.php', true); request.onreadystatechange = function() { if (request.readyState == 4) { /* 4 : complete state */ if (request.status == 200) { /* 200 : HTTP code OK */ checkIfConnected(request); } else { waitingPublish.style.display = "none"; errorPublish.style.display = "block"; } } } request.send(null); publishForm.style.display = "none"; waitingPublish.style.display = "block"; } else { waitingPublish.style.display = "none"; publishForm.style.display = "block"; } showMenu(PUBLISH); } function checkIfConnected(request) { respT = request.responseText; waitingPublish.style.display = "none"; publishForm.style.display = "block"; if (respT == "true") { loginNeeded.style.display = "none"; } else { idNeeded.style.display = "block"; if (document.all) { loginNeeded.style.display = "block"; } else { loginNeeded.style.display = "table"; } } } function treatResponse(resp) { var tab = new Array(); temp = resp.split(','); tab['state'] = temp[0]; tab['idUser'] = temp[1]; tab['idMarker'] = temp[2]; tab['site'] = temp[3]; return tab; } function publishMarker() { var urlSupp = "&type=publish"; if (loginNeeded.style.display != "none") { urlSupp = "&type=loginPublish&login="+document.publishForm.login.value+"&pass="+document.publishForm.pass.value; } var request = GXmlHttp.create (); request.open('GET', 'submitmarker.php' + currentMarker.getSubmitURL() + urlSupp, true); request.onreadystatechange = function() { if (request.readyState == 4) { /* 4 : complete state */ if (request.status == 200) { /* 200 : HTTP code OK */ checkResponsePublish(request); } else { waitingPublish.style.display = "none"; errorPublish.style.display = "block"; } } } request.send(null); waitingPublish.style.display = "block"; document.publishForm.style.display = "none"; idNeeded.style.display = "none"; } function checkResponsePublish(request) { var respT = request.responseText; var tab = treatResponse(respT); waitingPublish.style.display = "none"; idNeeded.style.display = "none"; errorLogin.style.display = "none"; // alert(respT); if (tab['state'] == 'null') { document.publishForm.style.display = "block"; errorPublish.style.display = "block"; DEFAULT_NODE_NAME = document.publishForm.login.value; } else if (tab['state'] == 'login') { document.publishForm.style.display = "block"; errorLogin.style.display = "block"; } else if (tab['state'] == 'already') { alreadyPublished.style.display = "block"; DEFAULT_NODE_NAME = document.publishForm.login.value; ID_USER = parseInt(tab['idUser']); var myMarker = null; for (key in markers) { if (markers[key].idUser == ID_USER) { myMarker = markers[key]; break; } } removeMarkerFromMap(encode64(myMarker.name)); removeMarkerFromMap(encode64(currentMarker.name)); currentMarker= new NodeMarker(DEFAULT_NODE_NAME, ID_USER, myMarker.idMarker, currentMarker.description, POTENTIAL, currentMarker.getPoint().lng(), currentMarker.getPoint().lat(), ip_addr, currentMarker.modemType, currentMarker.actif, tab['site'], true); addMarkerInMap(currentMarker, showWiFiCoverage.checked); markers[currentMarker.name] = currentMarker; updateMyPersoMarker(CONNECT); alreadyPublished.style.display = "block"; currentMarker.destroyTooltip(); currentMarker.select(); } else if (tab['state'] == 'ok') { if (loginNeeded.style.display != "none") { DEFAULT_NODE_NAME = document.publishForm.login.value; } ID_USER = parseInt(tab['idUser']); removeMarkerFromMap(encode64(currentMarker.name)); currentMarker= new NodeMarker(DEFAULT_NODE_NAME, ID_USER, parseInt(tab['idMarker']), currentMarker.description, POTENTIAL, currentMarker.getPoint().lng(), currentMarker.getPoint().lat(), ip_addr, currentMarker.modemType, currentMarker.actif, tab['site'], true); addMarkerInMap(currentMarker, showWiFiCoverage.checked); markers[currentMarker.name] = currentMarker; updateMyPersoMarker(CONNECT); successPublish.style.display = "block"; currentMarker.destroyTooltip(); currentMarker.select(); } } function returnToMap() { calque.style.display='none'; howto.style.display = 'none'; login.style.display = 'none'; register.style.display='none'; lostPasswd.style.display = 'none'; publish.style.display = "none"; successPublish.style.display = "none"; alreadyPublished.style.display = "none"; update.style.display = "none"; updateForm.style.display = "block"; updateOk.style.display = "none"; updateNotOk.style.display = "none"; waitingUpdate.style.display = "none"; } function returnToForm() { registrationNotOk.style.display='none'; registerForm.style.display='block'; document.registerForm.pass.value = ""; document.registerForm.confirmPass.value = ""; } function returnToUpdateForm() { updateNotOk.style.display='none'; updateForm.style.display='block'; document.updateForm.pass.value = ""; } function returnToPassForm() { sendPassNotOk.style.display = 'none'; lostPasswdForm.style.display = 'block'; document.lostPasswdForm.loginMail.value = ''; }