checador.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. var msgTime = 0;
  2. var modalVisible=false;
  3. var ultimos = [];
  4. var checkInterval = null;
  5. function az(i) {if (i<10) {i = "0" + i};return i;}
  6. function init() {
  7. setInterval(function(){
  8. var current_time = new Date().getTime();
  9. var excecution_time = parseInt((current_time - started_at) / 1000);
  10. var s = new Date((server_time + excecution_time) * 1000);
  11. drawClock(az(s.getHours()), az(s.getMinutes()));
  12. drawFecha(az(s.getDate()), s.getDay(), s.getMonth(), s.getFullYear());
  13. //document.getElementById('server-time').innerHTML = az(s.getDate())+'/'+az(s.getMonth()+1)+'/'+s.getFullYear()+' '+az(s.getHours())+':'+az(s.getMinutes())+':'+az(s.getSeconds());
  14. }, 1000);
  15. }
  16. function drawClock(hora, min){
  17. $('#min').text(min);
  18. $('#hr').text(hora);
  19. }
  20. function drawFecha(dd, dnum, mm, yyyy){
  21. //var dias = ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá'];
  22. var meses = ['Ene', 'Feb', 'Mzo', 'Abr', 'Mayo', 'Jun', 'Jul', 'Agt', 'Sep', 'Oct', 'Nov', 'Dic'];
  23. $('#fecha').text(/*dias[dnum] + ' ' + */dd + ' ' + meses[mm]);
  24. $('#ano').text(yyyy);
  25. }
  26. function modalTimer() {
  27. if(checkInterval == null){//no es error de internet
  28. setTimeout(function() {
  29. $(".sub-bloque ").addClass("d-none");
  30. $("#registro").removeClass("d-none");
  31. }
  32. , 5000+msgTime);
  33. }
  34. }
  35. //--Sin conexión de internet ---
  36. function checadorAlive() {
  37. if(checkInterval == null){
  38. checkInterval = setInterval(isAlive, 2500);
  39. }
  40. }
  41. function isAlive() {
  42. var alive = false;
  43. try{
  44. $.ajax({
  45. url: 'checador_alive.php',
  46. type: 'POST',
  47. dataType: 'json',
  48. async: false,
  49. timeout: 500,/*ms*/
  50. success: function(result) {
  51. if(result["ok"]!= "" && result["ok"] !== undefined){
  52. cambiaVista('#internet', '#registro');
  53. alive = true;
  54. clearInterval(checkInterval);
  55. checkInterval = null;
  56. }
  57. },
  58. error: function(jqXHR, textStatus, errorThrown ){
  59. console.log("Sin internet");
  60. }
  61. });//ajax*/
  62. }catch(e){
  63. console.log("error! ",e);
  64. }
  65. return alive;
  66. }
  67. //--Fin sin conexión de internet ---
  68. function cambiaVista(objHide, objShow){
  69. $(objHide).addClass("d-none");
  70. $(objShow).removeClass("d-none");
  71. }
  72. $(document).on('click', '#btnChecar', function(e){
  73. console.log("click!");
  74. //e.preventDefault();
  75. var clave = $("#cve").val();
  76. $.ajax({
  77. url: 'checador_action.php',
  78. type: 'POST',
  79. dataType: 'json',
  80. data: { id: $("#id").val(),},
  81. timeout: 3500,/*ms*/
  82. success: function(result) {
  83. //$("#cve").val('');
  84. if(result["error"]!= "" && result["error"] !== undefined){
  85. console.log(result["error"]);
  86. cambiaVista('#registro', '#result_no');
  87. $('#result_no .clave').text(clave);
  88. $("#last-error").text(result["error"]);
  89. }else{
  90. //----------
  91. var retardo = false;
  92. var hayHorario = false;
  93. //hay elementos checado nuevo?
  94. if(result["result"] !== undefined && result["result"]!= null && result["result"].length != 0){
  95. cambiaVista('#registro', '#result_ok');
  96. hayHorario = true;
  97. //setTimeout(cambiaVista('#result_ok', '#registro'), 4000);
  98. $("#list-result").children().each(function(index) {
  99. if(index < result["result"].length){//llenar info
  100. if(result["result"][index]["grupo"] != ""){
  101. if(result["result"][index]["retardo"]){
  102. retardo = true;
  103. }else{
  104. retardo = false;
  105. }
  106. //$(this).find(".mat-gpo").html("<b>Grupo:</b> "+result["result"][index]["grupo"]);
  107. }
  108. /*$(this).find(".mat-desc").html(result["result"][index]["materia"]);
  109. $(this).find(".mat-fecha").html("Inicia "+result["result"][index]["hora_inicio"]);
  110. if(result["result"][index]["salon"] != "")
  111. $(this).find(".mat-salon").html("<b>Salón:</b> "+result["result"][index]["salon"]);
  112. */
  113. }
  114. });
  115. }
  116. //hay elementos checado anterior?
  117. if(result["asistencias"] !== undefined && result["asistencias"]!= null && result["asistencias"].length != 0){
  118. cambiaVista('#registro', '#result_ok');
  119. hayHorario = true;
  120. //setTimeout(cambiaVista('#result_ok', '#registro'), 4000);
  121. $("#list-result").children().each(function(index) {
  122. if(index < result["asistencias"].length){//llenar info
  123. if(result["asistencias"][index]["grupo"] != ""){
  124. if(result["asistencias"][index]["retardo"]){
  125. retardo = true;
  126. }else{
  127. retardo = false;
  128. }
  129. //$(this).find(".mat-gpo").html("<b>Grupo:</b> "+result["asistencias"][index]["grupo"]);
  130. }
  131. /*$(this).find(".mat-desc").html(result["asistencias"][index]["materia"]);
  132. $(this).find(".mat-fecha").html("Inicia "+result["asistencias"][index]["hora_inicio"]);
  133. if(result["asistencias"][index]["salon"] !== undefined && result["asistencias"][index]["salon"] != "")
  134. $(this).find(".mat-salon").html("<b>Salón:</b> "+result["asistencias"][index]["salon"]);
  135. */
  136. }
  137. });
  138. }
  139. if(retardo){
  140. $("#estado").find("img").prop("src", "imagenes/tarde.png");
  141. $("#estado").find("h2").text("Retardo").removeClass("text-success").addClass("text-warning");
  142. }else{
  143. $("#estado").find("img").prop("src", "imagenes/atiempo.png");
  144. $("#estado").find("h2").text("Asistencia").removeClass("text-warning").addClass("text-success");
  145. }
  146. //sin horario
  147. if(!hayHorario){
  148. cambiaVista('#registro', '#result_no');
  149. //setTimeout(cambiaVista('#result_no', '#registro'), 4000);
  150. }
  151. $(".list-result").remove();
  152. $("#btnChecar").remove();
  153. $(".sin-horario").removeClass("d-none");
  154. }
  155. },
  156. error: function(jqXHR, textStatus, errorThrown ){
  157. cambiaVista('#registro', '#internet');
  158. checadorAlive();//Muestra mensaje sin internet y comienza a checar hasta que haya
  159. },
  160. complete: function( jqXHR, textStatus ){
  161. modalTimer();
  162. }
  163. });//ajax*/
  164. });