123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- var msgTime = 0;
- var modalVisible=false;
- var ultimos = [];
- var checkInterval = null;
- function az(i) {if (i<10) {i = "0" + i};return i;}
- function init() {
- var clockInterval = 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");
- $("#cve").focus();
- }
- , 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');
- $("#cve").focus();
- 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");
- }
- $('#formaChecador').on('submit',function(e){
- e.preventDefault();
- var clave = $("#cve").val();
- $.ajax({
- url: 'checador_action.php',
- type: 'POST',
- dataType: 'json',
- data: { cve: $("#cve").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{
- $("#list-result").find(".mat-desc").html("");
- $("#list-result").find(".mat-fecha").html("");
- $("#list-result").find(".mat-salon").html("");
- $("#list-result").find(".mat-gpo").html("");
-
- $("#nombre").html(result["nombre"]);
-
- var rows = $("#list-result > li").length;//limpia tabla actual
- var resultRows = 0;
- //nuevas
- if(result["result"] !== undefined && result["result"]!= null) resultRows += result["result"].length;
- //viejas
- if(result["asistencias"] !== undefined && result["asistencias"]!= null) resultRows += result["asistencias"].length;
- if(rows > resultRows){//sobran
- //borrar renglones extra (rows - result.length) pero dejar al menos 1
- while(rows > resultRows && rows > 1){
- $("#list-result li:last-child").remove();
- rows--;
- }
- }else{//faltan, clonar
- for(var i=rows; i<resultRows; i++){
- $("#list-result li:first-child").clone(true).appendTo("#list-result");
- }
- }
-
- //----------
- var retardo = false;
- //hay elementos checado nuevo?
- if(result["result"] !== undefined && result["result"]!= null && result["result"].length != 0){
- cambiaVista('#registro', '#result_ok');
- $("#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("<b>Grupo:</b> "+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("<b>Salón:</b> "+result["result"][index]["salon"]);
- /*else
- $(this).find(".mat-salon").html("");*/
- }
- });
- }
- //hay elementos checado anterior?
- if(result["asistencias"] !== undefined && result["asistencias"]!= null && result["asistencias"].length != 0){
- cambiaVista('#registro', '#result_ok');
- $("#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("<b>Grupo:</b> "+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("<b>Salón:</b> "+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(resultRows == 0){
- cambiaVista('#registro', '#result_no');
- }
- }
- //Avisos
- if(result["avisoArr"] && result["avisoArr"].length != 0 ){//hay aviso
- $("#aviso-texto").removeClass("d-none");
- msgTime = 2500 * result["avisoArr"].length;//aumenta el tiempo por cada aviso
- $("#aviso-texto").html("");
- for(var i = 0; i < result["avisoArr"].length; i++){
- $("#aviso-texto").append("<div class='alert alert-warning' role='alert'>"+result["avisoArr"][i]+"</div>");
- }
- }else{
- msgTime = 0;//no tiempo extra
- $("#aviso-texto").addClass("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 ){
- $("#cve").val('');
- modalTimer();
- }
- });//ajax*/
- });
|