var busquedaLanzada=false; var temporizador; var velocidadTemporizador=1000; var idHistorialActual=0; var idHistorialAnterior=0; var idHistorialAnteriorIE=0; var RUTA_EXTERNA='http://prueba.ennera.com'; var historial = new Array(); var sinHistorial = true; function GuardianUrl(){ temporizador=setTimeout("GuardianUrl()", velocidadTemporizador); var urlActual = window.location.toString(); var busquedaUrl = window.location.hash.substr(1); var urlActualIframe = document.getElementById('historial').contentWindow.document.location; var busquedaUrlIE = String(urlActualIframe.hash.substr(1)); console.log(busquedaUrlIE+" - "+idHistorialAnteriorIE+" - "+busquedaUrl+" - "+idHistorialActual+" - "+idHistorialAnterior); if((busquedaUrlIE != idHistorialAnteriorIE && idHistorialAnteriorIE>=0) || busquedaUrl!=idHistorialActual && idHistorialAnterior!=busquedaUrl && busquedaUrl>=0 && idHistorialActual>=0){ if(!busquedaLanzada){ if(Obtenir('buscador')){ if((busquedaUrlIE != idHistorialAnteriorIE && idHistorialAnteriorIE>0)){ Obtenir('buscador').value=historial[busquedaUrlIE]; } else{ Obtenir('buscador').value=historial[busquedaUrl]; } idHistorialActual=busquedaUrl; console.log(dameIdMenu(historial[busquedaUrl])); if(historial[busquedaUrl]==undefined || historial[busquedaUrl]==""){ desplazarMenu("menuHome"); cargarPagina("/user/informes/templateTabla.php?tabla=home",true); } else{ desplazarMenu(dameIdMenu(historial[busquedaUrl])); cargarPagina(historial[busquedaUrl],false) } } } else{ busquedaLanzada = false; } } else{ busquedaLanzada=false; } idHistorialAnterior = busquedaUrl; idHistorialAnteriorIE = false; } function LimpiarUrl() { var urlSinId = ''; // buscando la # var urlActual = new String(window.location); urlSinId = urlActual.replace(/(\#[\w |\W ]{0,}){0,}/g, ''); return urlSinId; } Obtenir = function(id) { // Retorna un elemento en base al id return document.getElementById(id); } ////////////////////////////////// //Login function compruebaUsuarioEnter(evt, usuario, password,grupo){ if (evt.keyCode == 13) { compruebaUsuario(usuario,password,grupo); return false; } } function compruebaUsuario(usuario, password, grupo){ //alert(password); enablePrecarga(); $.ajax({ type: "POST", url: "/includes/ajax/validaUsuario.php", data: { user: usuario, password: password, grupo: grupo }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ //cargarPagina("/user/informes/templateTabla.php?tabla=home",true); window.location.href = "../../"; cargarPagina("/user/informes/templateTabla.php?tabla=home",true); } else { //alert("Error al autenticarse:"+" " + data.usuario + ""); $("#error").html(""); } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ console.log("Error en la respuesta:"+ textStatus); $("#ajaxResponse").html(jqXHR.responseText); }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } function rehazContrasenya(usuario){ $.ajax({ type: "POST", url: "/includes/ajax/rehazContrasenya_App.php", data: { user: usuario, }, dataType: "jsonp", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ //alert("Sesion ok"); //window.location.href = "./user/index.html"; //alert("Su nueva contraseñya ha sido enviada a su cuenta de correo."); alert(data.usuario); //$("#error").html("
En breve recibirá un mail en su cuenta de correo.
"); $("#error").html("
" + data.usuario + "
"); } else { //alert("Error al solicitar nueva contraseña: " + data.usuario + ""); alert(data.usuario); $("#error").html("
" + data.usuario + "
"); } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ console.log("Something really bad happened " + textStatus); $("#ajaxResponse").html(jqXHR.responseText); }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } function updateUsuarioRecuperar(login,password,nombre,apellidos,telefono,email,idioma){ $.ajax({ type: "POST", url: "/user/updateUsuarioRecuperar.php", data: { login: login, password: hex_md5(password), nombre: nombre, apellidos: apellidos, telefono: telefono, email: email, idioma: idioma }, dataType: "jsonp", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("Los datos del usuario han sido actualizados correctamente."); window.location = "/"; return true; } else { alert("No se han podido actualizar los datos del usuario."); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } //MiPerfil function updateUsuarioPerfil(login,password,nombre,apellidos,telefono,email,idioma){ $.ajax({ type: "POST", url: "/user/updateUsuario.php", data: { login: login, password: hex_md5(password), nombre: nombre, apellidos: apellidos, telefono: telefono, email: email, idioma: idioma }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("Su información de perfil ha sido actualizada correctamente."); refrescarPagina(); return true; } else { alert("No se ha podido actualizar su información de perfil."); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } //Administración/Gestion de Usuarios function createUsuario(login,password,nombre,apellidos,telefono,email,idioma,group){ $.ajax({ type: "POST", url: "/user/createUsuario.php", data: { login: login, password: password, nombre: nombre, apellidos: apellidos, telefono: telefono, email: email, idioma: idioma, group: group }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("El nuevo usuario ha sido registrado correctamente."); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminUsers&desplazar_a=menuUsuario'; return true; } else { alert(data.info); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } function updateUsuario(login,password,nombre,apellidos,telefono,email,idioma){ $.ajax({ type: "POST", url: "/user/updateUsuario.php", data: { login: login, password: hex_md5(password), nombre: nombre, apellidos: apellidos, telefono: telefono, email: email, idioma: idioma }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("Los datos del usuario han sido actualizados correctamente."); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminUsers&desplazar_a=menuUsuario'; return true; } else { alert("No se han podido actualizar los datos del usuario."); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } function deleteUsuarios(idUsuarios){ $.ajax({ url: '/user/deleteUser.php', type: 'POST', data: {idUsuario:idUsuarios}, }) .done(function(data) { alert("Los usuarios seleccionados han sido eliminados correctamente."); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminUsers&desplazar_a=menuUsuario'; }); } //Administración/Gestion de Instalaciones function createInstalacion(instalacion,tipo,listDevices,cliente,latitud,longitud,instalador){ var devices=""; if(listDevices.length>1){ listDevices.each(function(){ devices+=$(this).attr('value')+"|"; }); }else{ listDevices.each(function(){ devices=$(this).attr('value'); }); } $.ajax({ type: "POST", url: "/user/createInstalacion.php", data: { instalacion: instalacion, tipo:tipo, devices: devices, cliente: cliente, latitud: latitud, longitud: longitud, instalador: instalador }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("La nueva instalación ha sido registrada correctamente."); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminInstallations&desplazar_a=menuInstalacion'; return true; } else { alert(data.info); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } function updateInstalacion(idInstalacion,instalacion,tipo,listDevices,cliente,latitud,longitud,instalador){ var devices=""; if(listDevices.length>1){ listDevices.each(function(){ devices+=$(this).attr('value')+"|"; }); }else{ listDevices.each(function(){ devices=$(this).attr('value'); }); } $.ajax({ type: "POST", url: "/user/updateInstalacion.php", data: { idInstalacion: idInstalacion, instalacion: instalacion, tipo: tipo, devices: devices, cliente: cliente, latitud: latitud, longitud: longitud, instalador: instalador }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("Los datos de la instalación han sido actualizados correctamente."); cargarPagina("/user/informes/templateTabla.php?tabla=adminInstallations",true); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminInstallations&desplazar_a=menuInstalacion'; return true; } else { alert("No se han podido actualizar los datos de la instalación."); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } function deleteInstalaciones(idInstalacion,idTipo){ $.ajax({ url: '/user/deleteInstalacion.php', type: 'POST', data: {idInstalacion:idInstalacion, idTipo:idTipo }, }) .done(function(data) { alert("Las instalaciones seleccionadas han sido eliminadas correctamente."); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminInstallations&desplazar_a=menuInstalacion'; }); } //Administración/Gestion de Productos function createProducto(tipo,serialnumber,deviceId,instalador,torre){ $.ajax({ type: "POST", url: "/user/createProducto.php", data: { tipo: tipo, serialnumber: serialnumber, deviceId: deviceId, instalador: instalador, torre:torre }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("El nuevo producto ha sido registrado correctamente."); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminProductos&desplazar_a=menuProducto'; return true; } else { alert(data.info); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } function updateProducto(tipo,serialnumber,deviceId,instalador,torre){ //alert("AAA"); //alert(torre); $.ajax({ type: "POST", url: "/user/updateProducto.php", data: { tipo: tipo, serialnumber: serialnumber, deviceId: deviceId, instalador: instalador, torre:torre }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("Los datos de producto han sido actualizados correctamente."); cargarPagina("/user/informes/templateTabla.php?tabla=adminProductos",true); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminProductos&desplazar_a=menuProducto'; return true; } else { alert("No se han podido actualizar los datos de producto."); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; }, //capture the request before it was sent to server beforeSend: function(jqXHR, settings){ //adding some Dummy data to the request settings.data += "&dummyData=whatever"; //disable the button until we get the response $('#myButton').attr("disabled", true); }, //this is called after the response or error functions are finsihed //so that we can take some action complete: function(jqXHR, textStatus){ //enable the button $('#myButton').attr("disabled", false); } }); } function deleteProductos(idProductos,idTipo){ $.ajax({ url: '/user/deleteProductos.php', type: 'POST', data: {idProductos:idProductos, idTipo:idTipo }, }) .done(function(data) { //console.log(data); alert("Los productos seleccionados han sido eliminados correctamente."); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=adminProductos&desplazar_a=menuProducto'; }); } /////////////////////////////////// //Incidencias function createIssue(id,createdby,date,product,comptype,installer,installation,arrDevices,issueGroup,status,description,solution,solutionDate,coste,ncrStatus,ncr,arrActions){ $.ajax({ type: "POST", url: "/user/createIssueController.php", data: { id:id, createdby:createdby, date:date, idProduct:product, idComptype:comptype, idInstaller:installer, idInstallation:installation, arrDevices:arrDevices, idIssueGroup:issueGroup, idStatus:status, description:description, solution:solution, solutionDate:solutionDate, coste:coste, idNCRStatus:ncrStatus, idNCR:ncr, arrActions:arrActions }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ alert("Incidencia creada correctamente"); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=issues'; return true; } else { alert(data.info); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; } }); } function unblockIssue(id){ $.ajax({ type: "POST", url: "/user/unblockIssueController.php", data: { id:id }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ //alert("NEWISSUEOK"); //alert("Incidencia desbloqueada"); return true; } else { alert(data.info); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; } }); } function updateIssue(id,date,product,comptype,installer,installation,arrDevices,issueGroup,status, statusChange, description,solution,solutionDate,coste,ncrStatus,ncr,arrActions){ $.ajax({ type: "POST", url: "/user/updateIssueController.php", data: { id:id, date:date, idProduct:product, idComptype:comptype, idInstaller:installer, idInstallation:installation, arrDevices:arrDevices, idIssueGroup:issueGroup, idStatus:status, statusChange:statusChange, description:description, solution:solution, solutionDate:solutionDate, coste:coste, idNCRStatus:ncrStatus, idNCR:ncr, arrActions:arrActions }, dataType: "json", //if received a response from the server success: function( data, textStatus, jqXHR) { if(data.success){ //alert("NEWISSUEOK"); alert("Incidencia modificada correctamente"); document.location='index.php?go_to_url=../user/informes/templateTabla.php?tabla=issues'; return true; } else { alert(data.info); return false; } }, //If there was no resonse from the server error: function(jqXHR, textStatus, errorThrown){ return false; } }); } //////////////////////////////// function cargarPagina(pagina,nueva){ console.log(pagina); if (sinHistorial == true) { busquedaLanzada = false; //para indicar que se no hay que voler a lanzarla sinHistorial=false; } else { if(nueva){ historial[idHistorialActual]=Obtenir("buscador").value; idHistorialActual++; //contador para explorer Obtenir("buscador").value=pagina; } var busqueda = Obtenir("buscador").value; // Ahora segun el navegador cambiamos la ur del iframe o la del document if (esNavegadorIE() && busqueda != idHistorialAnteriorIE) { var rutaExterna = ObtenerRutaExterna(); //Obtenir("historial").src=rutaExterna + "/historial.php?paginaActual=" + idHistorialActual+ "#"+idHistorialActual; Obtenir("historial").src = rutaExterna + "/historial.php?paginaActual=" + idHistorialActual + "#" + busqueda; busquedaLanzada = true; //indica al guardianURL que esta peticion se ha realizado ya. } else if (!esNavegadorIE() && busqueda != idHistorialAnterior) { //window.location=LimpiarUrl(window.location)+'#'+idHistorialActual; window.location = LimpiarUrl(window.location) + '#' + idHistorialActual; busquedaLanzada = true; //indica al guardianURL que esta peticion se ha realizado ya. } } enablePrecarga(); $('#currentPageUrl').val(pagina); $("#contenidoPagina").load(pagina, disablePrecarga); } var enablePrecarga = function(){ $("#carga").css("display","block"); }; var disablePrecarga = function(){ $("#carga").css("display","none"); var conTop=$('.content').position().top; $('#page').css('margin-top','-'+$('.content').position().top+'px'); $('.menuCabecera').parent().css('margin-top',$('.content').position().top+'px'); }; function obtenerRutaExterna(){ var protocoloUrlPrincipal = document.location.protocol; var dominioUrlPrincipal = document.location.host; return protocoloUrlPrincipal+"//"+dominioUrlPrincipal; } function esNavegadorIE(){ if(window.ActiveXObject){ return true; } else{ return false; } } /** * * @param {type} idDato Id del li que se encuentra en el panel que queremos desplegar * @returns {undefined} */ function desplazarMenu(idDato){ var api = $('#menu2').data('mmenu'); var select = $('#'+idDato); $('.mm-selected').removeClass('mm-selected'); select.addClass('mm-selected'); api.openPanel(select.closest(".mm-panel")); } /** * * @param {type} url a partir de la cual obtendremos el id del menú * @returns {String} Devuelve el id del menú al que debemos desplazarnos */ function dameIdMenu(url){ //Vamos a comprobar hacia qué panel tenemos que ir para cargar en el menú. var idMenuTmp=""; if(url==undefined){ idMenuTmp = "menuHome"; } else{ if(url.indexOf("?tabla=home")>-1){ idMenuTmp = "menuHome"; } else if(url.indexOf("totalPerformance.php")>-1){ idMenuTmp = "menuTotalPerformance"; } else if(url.indexOf("?tabla=instalaciones")>-1){ idMenuTmp = "menuTotalPerformance"; } else if(url.indexOf("detalleInstalacion.php")>-1){ //Voy a buscar el id de la instalación. var arrTmp = url.split("id="); idMenuTmp = "instalacion"+arrTmp[1]; } else if(url.indexOf("?tabla=detalleInstalacion")>-1){ //Voy a buscar el id de la instalación. var arrTmp = url.split("id="); idMenuTmp = "instalacion"+arrTmp[1]; } else if(url.indexOf("detalleGenerador.php")>-1){ //Voy a buscar el id de la instalación. var arrTmp = url.split("id="); arrTmp = arrTmp[1].split("&"); idMenuTmp = "generador"+arrTmp[0]; } else if(url.indexOf("templateTabla.php?tabla=alarmasGenerador")>-1){ //Voy a buscar el id de la instalación. var arrTmp = url.split("id="); idMenuTmp = "generador"+arrTmp[1]; } else if(url.indexOf("online_info.php")>-1){ //Voy a buscar el id de la instalación. var arrTmp = url.split("id="); idMenuTmp = "generador"+arrTmp[1]; } else if(url.indexOf("start-stop.php")>-1){ //Voy a buscar el id de la instalación. var arrTmp = url.split("id="); idMenuTmp = "generador"+arrTmp[1]; } else if(url.indexOf("?tabla=parameters")>-1){ //Voy a buscar el id de la instalación. var arrTmp = url.split("id="); arrTmp = arrTmp[1].split("&"); idMenuTmp = "generador"+arrTmp[0]; } else if(url.indexOf("ubicaciones.php")>-1){ idMenuTmp = "menuUbicaciones"; } else if(url.indexOf("homeSmartphone.php")>-1){ idMenuTmp = "menuAdministracion"; } else if(url.indexOf("adminUsuario.php")>-1){ idMenuTmp = "menuUsuario"; } else if(url.indexOf("adminInstalacion.php")>-1){ idMenuTmp = "menuInstalacion"; } else if(url.indexOf("adminPerfil.php")>-1){ idMenuTmp = "menuPerfil"; } else if(url.indexOf("administracion.php")>-1){ idMenuTmp = "menuAdministracion"; } else if(url.indexOf("documentacion.php")>-1){ idMenuTmp = "menuDocumentacion"; } } return idMenuTmp; } function refrescarPagina(){ var urlRefresco='index.php?go_to_url='+$('#currentPageUrl').val()+'&desplazar_a='+$('.mm-selected:first').attr('id'); //console.log(urlRefresco); document.location=urlRefresco; }