var msgTime = 0; var modalVisible=false; var ultimos = []; var checkInterval = null; function az(i) {if (i<10) {i = "0" + i};return i;} function init() { setInterval(function(){ var current_time = new Date().getTime(); var excecution_time = parseInt((current_time - started_at) / 1000); var s = new Date((server_time + excecution_time) * 1000); drawClock(az(s.getHours()), az(s.getMinutes())); drawFecha(az(s.getDate()), s.getDay(), s.getMonth(), s.getFullYear()); //document.getElementById('server-time').innerHTML = az(s.getDate())+'/'+az(s.getMonth()+1)+'/'+s.getFullYear()+' '+az(s.getHours())+':'+az(s.getMinutes())+':'+az(s.getSeconds()); }, 1000); } function drawClock(hora, min){ $('#min').text(min); $('#hr').text(hora); } function drawFecha(dd, dnum, mm, yyyy){ //var dias = ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá']; var meses = ['Ene', 'Feb', 'Mzo', 'Abr', 'Mayo', 'Jun', 'Jul', 'Agt', 'Sep', 'Oct', 'Nov', 'Dic']; $('#fecha').text(/*dias[dnum] + ' ' + */dd + ' ' + meses[mm]); $('#ano').text(yyyy); } function modalTimer() { if(checkInterval == null){//no es error de internet setTimeout(function() { $(".sub-bloque ").addClass("d-none"); $("#registro").removeClass("d-none"); } , 5000+msgTime); } } //--Sin conexión de internet --- function checadorAlive() { if(checkInterval == null){ checkInterval = setInterval(isAlive, 2500); } } function isAlive() { var alive = false; try{ $.ajax({ url: 'checador_alive.php', type: 'POST', dataType: 'json', async: false, timeout: 500,/*ms*/ success: function(result) { if(result["ok"]!= "" && result["ok"] !== undefined){ cambiaVista('#internet', '#registro'); alive = true; clearInterval(checkInterval); checkInterval = null; } }, error: function(jqXHR, textStatus, errorThrown ){ console.log("Sin internet"); } });//ajax*/ }catch(e){ console.log("error! ",e); } return alive; } //--Fin sin conexión de internet --- function cambiaVista(objHide, objShow){ $(objHide).addClass("d-none"); $(objShow).removeClass("d-none"); } $(document).on('click', '#btnChecar', function(e){ console.log("click!"); //e.preventDefault(); var clave = $("#cve").val(); $.ajax({ url: 'checador_action.php', type: 'POST', dataType: 'json', data: { id: $("#id").val(),}, timeout: 3500,/*ms*/ success: function(result) { //$("#cve").val(''); if(result["error"]!= "" && result["error"] !== undefined){ console.log(result["error"]); cambiaVista('#registro', '#result_no'); $('#result_no .clave').text(clave); $("#last-error").text(result["error"]); }else{ //---------- var retardo = false; var hayHorario = false; //hay elementos checado nuevo? if(result["result"] !== undefined && result["result"]!= null && result["result"].length != 0){ cambiaVista('#registro', '#result_ok'); hayHorario = true; //setTimeout(cambiaVista('#result_ok', '#registro'), 4000); $("#list-result").children().each(function(index) { if(index < result["result"].length){//llenar info if(result["result"][index]["grupo"] != ""){ if(result["result"][index]["retardo"]){ retardo = true; }else{ retardo = false; } //$(this).find(".mat-gpo").html("Grupo: "+result["result"][index]["grupo"]); } /*$(this).find(".mat-desc").html(result["result"][index]["materia"]); $(this).find(".mat-fecha").html("Inicia "+result["result"][index]["hora_inicio"]); if(result["result"][index]["salon"] != "") $(this).find(".mat-salon").html("Salón: "+result["result"][index]["salon"]); */ } }); } //hay elementos checado anterior? if(result["asistencias"] !== undefined && result["asistencias"]!= null && result["asistencias"].length != 0){ cambiaVista('#registro', '#result_ok'); hayHorario = true; //setTimeout(cambiaVista('#result_ok', '#registro'), 4000); $("#list-result").children().each(function(index) { if(index < result["asistencias"].length){//llenar info if(result["asistencias"][index]["grupo"] != ""){ if(result["asistencias"][index]["retardo"]){ retardo = true; }else{ retardo = false; } //$(this).find(".mat-gpo").html("Grupo: "+result["asistencias"][index]["grupo"]); } /*$(this).find(".mat-desc").html(result["asistencias"][index]["materia"]); $(this).find(".mat-fecha").html("Inicia "+result["asistencias"][index]["hora_inicio"]); if(result["asistencias"][index]["salon"] !== undefined && result["asistencias"][index]["salon"] != "") $(this).find(".mat-salon").html("Salón: "+result["asistencias"][index]["salon"]); */ } }); } if(retardo){ $("#estado").find("img").prop("src", "imagenes/tarde.png"); $("#estado").find("h2").text("Retardo").removeClass("text-success").addClass("text-warning"); }else{ $("#estado").find("img").prop("src", "imagenes/atiempo.png"); $("#estado").find("h2").text("Asistencia").removeClass("text-warning").addClass("text-success"); } //sin horario if(!hayHorario){ cambiaVista('#registro', '#result_no'); //setTimeout(cambiaVista('#result_no', '#registro'), 4000); } $(".list-result").remove(); $("#btnChecar").remove(); $(".sin-horario").removeClass("d-none"); } }, error: function(jqXHR, textStatus, errorThrown ){ cambiaVista('#registro', '#internet'); checadorAlive();//Muestra mensaje sin internet y comienza a checar hasta que haya }, complete: function( jqXHR, textStatus ){ modalTimer(); } });//ajax*/ });