0index.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <?php
  2. header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
  3. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  4. header('Cache-Control: no-store, no-cache, must-revalidate');
  5. header('Cache-Control: post-check=0, pre-check=0', false);
  6. header('Pragma: no-cache');
  7. require_once("../include/bd_pdo.php");//die on error
  8. require_once("../include/nusoap/nusoap.php");
  9. define("COOKIE_N", "checador");
  10. date_default_timezone_set('America/Mexico_City');
  11. function limpiaClave($clave){
  12. return intval(str_ireplace(array("ad", "al", "do"), array("","",""), $clave));
  13. }
  14. //Valida usuario en windows, regresa falso con error, 1 si es aceptado, 0 si es rechazado
  15. function validaUsuario($user, $pass){
  16. //$client = new nusoap_client('http://200.13.89.2/validacion.php?wsdl', 'wsdl');
  17. $client = new nusoap_client('http://validacion.lci.ulsa.mx/validacion.php?wsdl', 'wsdl');
  18. $error = $client->getError();
  19. if ($error) {
  20. return false;
  21. }
  22. $pass = utf8_decode($pass);
  23. $result = $client->call("valida_user_addo", array($user, $pass));
  24. if ($client->fault) {
  25. return false;
  26. } else {
  27. $error = $client->getError();
  28. if ($error) {
  29. return false;
  30. } else {
  31. if($result) return 1;
  32. else return 0;
  33. }
  34. }
  35. }
  36. $auth = false;
  37. if(!empty($_POST["username"]) && !empty($_POST["passwd"])){
  38. //Existe usuario y contraseña
  39. $usr = trim(filter_input(INPUT_POST, "username"));//limpia texto
  40. $usr_db = limpiaClave($usr);
  41. $pass = $_POST["passwd"]; //trim(filter_input(INPUT_POST, "passwd"));//limpia texto
  42. $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:usr) AS "Usuario_id"');
  43. $stmt->bindParam(":usr", $usr_db);
  44. if(!$stmt->execute()){
  45. //print_r($stmt->errorInfo());
  46. header("Location: ../index.php?error=2");
  47. exit();
  48. }
  49. $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  50. $stmt->closeCursor(); // cierra conexion de resultado
  51. $stmt = null; // cierra conexion
  52. $usr_id = $usr_rs["Usuario_id"];
  53. $usr_nombre = $usr_rs["Usuario_nombre"]." ".$usr_rs["Usuario_apellidos"];
  54. //----
  55. $stmt = $pdo->prepare('Select * from fs_usuario(:usr)');
  56. $stmt->bindParam(":usr", $usr_id);
  57. if(!$stmt->execute()){
  58. //print_r($stmt->errorInfo());
  59. header("Location: ../index.php?error=2");
  60. exit();
  61. }
  62. $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  63. $stmt->closeCursor(); // cierra conexion de resultado
  64. $stmt = null; // cierra conexion
  65. $usr_nombre = $usr_rs["Usuario_nombre"]." ".$usr_rs["Usuario_apellidos"];
  66. unset($usr_rs);
  67. if(!empty($usr_id)){//Si existe el usuario
  68. //if(password_verify($pass, $rs["Usuario_password"])){//Obtiene pass de la BD para comparar con función de PHP
  69. $valido = validaUsuario($usr, $pass);//false = error, 0 = sin permiso, 1 = con permiso
  70. if($valido === false){
  71. $errorDesc = "El usuario/contraseña son incorrectos";
  72. }else if($valido === 1){
  73. $auth = true;
  74. //$pass_new = password_hash($pass, PASSWORD_BCRYPT);
  75. setcookie(COOKIE_N, $usr_id, strtotime('today 23:59'), "/");
  76. }else{
  77. $errorDesc = "El usuario/contraseña son incorrectos";
  78. }
  79. }else{
  80. $errorDesc = "El usuario no está registrado en el sistema";
  81. }
  82. }else if (isset($_COOKIE[COOKIE_N])){
  83. $usr_id = $_COOKIE[COOKIE_N];
  84. $auth=true;
  85. $stmt = $pdo->prepare('Select * from fs_usuario(:usr)');
  86. $stmt->bindParam(":usr", $usr_id);
  87. if(!$stmt->execute()){
  88. //print_r($stmt->errorInfo());
  89. header("Location: ../index.php?error=2");
  90. exit();
  91. }
  92. $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  93. $stmt->closeCursor(); // cierra conexion de resultado
  94. $stmt = null; // cierra conexion
  95. $usr_nombre = $usr_rs["Usuario_nombre"]." ".$usr_rs["Usuario_apellidos"];
  96. unset($usr_rs);
  97. }
  98. if($auth && !empty($usr_id)){
  99. //Buscar las materias que puede checar
  100. $error = false;
  101. $fecha = '2021-03-31';//17
  102. $hora = '08:45';
  103. //$fecha = date("Y-m-d");
  104. //$hora = date("H:i");
  105. $esProf = false;
  106. $esAdmin = false;
  107. $asistRegistrada = false;
  108. $msg = 0;
  109. $fecha_hora = $fecha." ".$hora;
  110. $hasAsistencia = false;
  111. //Arrelo para guardar los resultados de las validaciones
  112. $asistenciasArr = array(
  113. "asistencia" => array("profesor"=>array(), "administrativo"=>array()),
  114. "retardo" => array("profesor"=>array(), "administrativo"=>array())
  115. );
  116. //--Profesor LICENCIATURA
  117. if(!$error){
  118. //Lee asistencias
  119. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, -30, 16, 1)');//Limite inferior es incluyente, limite superior excluyente
  120. $stmt->bindParam(":usr", $usr_id);
  121. $stmt->bindParam(":fecha", $fecha);
  122. $stmt->bindParam(":hora", $hora);
  123. if(!$stmt->execute()){
  124. //$t = $stmt->errorInfo();
  125. $resultMsg = "No se pudieron leer los horarios.";
  126. $error = true;
  127. }else{
  128. $esProf = true;
  129. $rs = $stmt->fetchAll();
  130. if(count($rs) > 0) $hasAsistencia = true;
  131. $asistenciasArr["asistencia"]["profesor"] = array_merge($asistenciasArr["asistencia"]["profesor"], $rs);
  132. }
  133. $stmt->closeCursor();
  134. }
  135. if(!$error){
  136. //Lee retardos
  137. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, 16, 31, 1)');//Limite inferior es incluyente, limite superior excluyente
  138. $stmt->bindParam(":usr", $usr_id);
  139. $stmt->bindParam(":fecha", $fecha);
  140. $stmt->bindParam(":hora", $hora);
  141. if(!$stmt->execute()){
  142. //$t = $stmt->errorInfo();
  143. $resultMsg = "No se pudieron leer los horarios. ";
  144. $error = true;
  145. }else{
  146. $esProf = true;
  147. $rs = $stmt->fetchAll();
  148. if(count($rs) > 0) $hasAsistencia = true;
  149. $asistenciasArr["retardo"]["profesor"] = array_merge($asistenciasArr["retardo"]["profesor"], $rs);
  150. }
  151. $stmt->closeCursor();
  152. }
  153. //--Profesor POSGRADO
  154. if(!$error){
  155. //Lee asistencias
  156. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, -60, 10, 2)');//Limite inferior es incluyente, limite superior excluyente
  157. $stmt->bindParam(":usr", $usr_id);
  158. $stmt->bindParam(":fecha", $fecha);
  159. $stmt->bindParam(":hora", $hora);
  160. if(!$stmt->execute()){
  161. //$t = $stmt->errorInfo();
  162. $resultMsg = "No se pudieron leer los horarios. ";
  163. $error = true;
  164. }else{
  165. $esProf = true;
  166. $rs = $stmt->fetchAll();
  167. if(count($rs) > 0) $hasAsistencia = true;
  168. $asistenciasArr["asistencia"]["profesor"] = array_merge($asistenciasArr["asistencia"]["profesor"], $rs);
  169. }
  170. $stmt->closeCursor();
  171. }
  172. if(!$error){
  173. //Lee retardos
  174. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, 10, 31, 2)');//Limite inferior es incluyente, limite superior excluyente
  175. $stmt->bindParam(":usr", $usr_id);
  176. $stmt->bindParam(":fecha", $fecha);
  177. $stmt->bindParam(":hora", $hora);
  178. if(!$stmt->execute()){
  179. //$t = $stmt->errorInfo();
  180. $resultMsg = "No se pudieron leer los horarios. ";
  181. $error = true;
  182. }else{
  183. $esProf = true;
  184. $rs = $stmt->fetchAll();
  185. if(count($rs) > 0) $hasAsistencia = true;
  186. $asistenciasArr["retardo"]["profesor"] = array_merge($asistenciasArr["retardo"]["profesor"], $rs);
  187. }
  188. $stmt->closeCursor();
  189. }
  190. //--Administrativo
  191. if(!$error){
  192. //Lee avisos de hoy
  193. $avisoArr = array();
  194. $stmt = $pdo->prepare('Select * from fs_avisochecador(:usr, :fecha)');
  195. $stmt->bindParam(":usr", $usr_id);
  196. $stmt->bindParam(":fecha", $fecha);
  197. if($stmt->execute()){
  198. $aviso_rs = $stmt->fetchAll();
  199. foreach($aviso_rs as $aviso){
  200. $avisoArr[] = $aviso["Aviso_texto"];
  201. }
  202. }else{
  203. $t = $stmt->errorInfo();
  204. $resultMsg = "No se pudieron obtener los avisos".$t[2];
  205. }
  206. $stmt->closeCursor();
  207. //Lee asistencias
  208. $stmt = $pdo->prepare('Select * from fs_asistenciaadministrativo_busca(:fecha, :hora, :usr)');//Limite inferior es incluyente, limite superior excluyente
  209. $stmt->bindParam(":usr", $usr_id);
  210. $stmt->bindParam(":fecha", $fecha);
  211. $stmt->bindParam(":hora", $hora);
  212. if(!$stmt->execute()){
  213. $t = $stmt->errorInfo();
  214. $resultMsg = "No se pudieron leer los horarios administrativos. ";
  215. $error = true;
  216. }else{
  217. $esAdmin = true;
  218. $rs = $stmt->fetchAll();
  219. if(count($rs) > 0) $hasAsistencia = true;
  220. $asistenciasArr["asistencia"]["administrativo"] = array_merge($asistenciasArr["asistencia"]["administrativo"], $rs);
  221. }
  222. $stmt->closeCursor();
  223. }
  224. }
  225. function imprimeRegistro($grupo, $materia, $hora, $salon){
  226. $salon = (!empty($salon)) ? "<b>Salón:</b> $salon" : "";
  227. $grupo = (!empty($grupo)) ? $grupo : "";
  228. echo "<tr class='list-result'>
  229. <td style='width:120px; vertical-align:top'><h4 class='mb-1 '>$grupo</h4></td>
  230. <td><h4 class='mb-1 '>$materia</h4><p><b>Hora:</b> $hora <span class='mr-4'></span>$salon</p></td>
  231. </tr>";
  232. }
  233. ?>
  234. <html>
  235. <head>
  236. <meta charset="UTF-8" />
  237. <meta name="viewport" content="width=device-width, initial-scale=1">
  238. <title>.: CHKDOR - Facultad de Ingeniería :.</title>
  239. <link rel="icon" type="image/png" href="imagenes/favicon.png" />
  240. <link rel="stylesheet" href="./css/bootstrap-ulsa.min.css">
  241. <link rel="stylesheet" href="./css/indivisa.css">
  242. <link rel="stylesheet" href="./css/lasalle.css">
  243. <link rel="stylesheet" href="./css/sgi.css">
  244. <link rel="stylesheet" href="./css/checador.css">
  245. <link rel="stylesheet" href="./css/fa_all.css">
  246. </head>
  247. <!--body oncontextmenu="return false" onselectstart="return false" ondragstart="return false"-->
  248. <body>
  249. <header class="py-4 px-4 text-secondary bg-white">
  250. <div class="d-flex">
  251. <div class="my-auto mr-auto"><img id="logo" src="./imagenes/logo_lasalle.png" alt="La Salle" class="img-fluid"/></div>
  252. <div class="my-auto hora pr-3 text-nowrap"><span id="hr">00</span>:<span id="min">00</span> h</div>
  253. <div class="my-auto ml-4 fecha text-center"><span id="fecha">00 Xxx</span><br><span id="ano">2000</span></div>
  254. </div>
  255. </header>
  256. <div class="bg-light text-center py-2"><p class="facultad m-0">Facultad de Ingeniería</p></div>
  257. <div class="container-fluid">
  258. <div class="h-100 fondo-img">
  259. <div class="d-flex justify-content-center h-75">
  260. <div class="bg-white align-self-center checa-box rounded-sm py-4 px-5" id="box">
  261. <!-- ---------- -->
  262. <?php
  263. if ($auth == false){ ?>
  264. <div class="logSize p-5 bg-white defaultShadow">
  265. <div class="row mb-4">
  266. <div class="col-sm-12"><h1 class="subtitle text-big mb-1">Iniciar sesión</h1></div>
  267. </div>
  268. <form method="post" action="index.php">
  269. <div class="row">
  270. <div class="col">
  271. <p class="text-center font-weight-bold text-info">Utiliza tu usuario y contraseña institucionales</p>
  272. </div>
  273. </div>
  274. <div class="form-group row">
  275. <div class="input-group px-4">
  276. <div class="input-group-prepend secondary">
  277. <div class="input-group-text bg-primary text-white"><i class="ing-usuario ing-fw"></i></div>
  278. </div>
  279. <input class="form-control form-control-lg" type="text" autocomplete="username" placeholder="Usuario (ad ó do)" id="username" name="username" value="" autofocus="true" maxlength="10"/>
  280. </div>
  281. </div>
  282. <div class="form-group row">
  283. <div class="input-group mb-2 px-4">
  284. <div class="input-group-prepend">
  285. <div class="input-group-text bg-primary text-white"><i class="ing-pass ing-fw"></i></div>
  286. </div>
  287. <input class="form-control form-control-lg" type="password" autocomplete="current-password" placeholder="Contraseña" id="passwd" name="passwd" value="" maxlength="50"/>
  288. </div>
  289. </div>
  290. <?php if(isset($_GET["error"])){ ?>
  291. <p class="text-danger text-center font-weight-bold">¡ERROR! <?php echo $errorDesc;?></p>
  292. <?php } ?>
  293. <p class="text-center">
  294. <button type="submit" class="btn btn-lg btn-outline-primary btn-ing arrow">Ingresar</button>
  295. </p>
  296. </form>
  297. </div>
  298. <?php } else { //autenticado ?>
  299. <div id="registro" class="">
  300. <h1 class="subtitle"><?php echo $usr_nombre; ?></h1>
  301. <?php if(!empty($avisoArr) && count($avisoArr)>0){?>
  302. <div id="aviso-texto">
  303. <?php foreach($avisoArr as $aviso){
  304. echo "<div class='alert alert-warning' role='alert'>$aviso</div>";
  305. } ?>
  306. </div>
  307. <?php } ?>
  308. <form class="mt-4" id="formaChecador" autocomplete="off">
  309. <div class="row">
  310. <div class="col-12">
  311. <?php
  312. if(!empty($asistenciasArr) && $hasAsistencia){
  313. echo "<table class='table table-sm' >";
  314. foreach($asistenciasArr as $tipo=>$asist_rol){
  315. foreach($asist_rol as $rol=>$asist){
  316. foreach($asist as $mat){
  317. if($rol == 'profesor')
  318. imprimeRegistro($mat["Grupo_desc"].$mat["Carrera_prefijo"], $mat["Materia_desc"], substr($mat["Horario_hora"], 0, -3), $mat["Salon_desc"]);
  319. else
  320. imprimeRegistro(NULL, "HORARIO ADMINISTRATIVO", substr($mat["Horario_hora"], 0, -3), NULL);
  321. }
  322. }
  323. }
  324. echo "</table>";
  325. echo "<h2 class='text-center text-danger mt-4 d-none sin-horario'>No hay horarios por registrar</h2>";
  326. ?>
  327. <input type="hidden" name="cve" id="cve" value="<?php echo $usr_id; ?>">
  328. <div class="row justify-content-center mt-4">
  329. <div class="col-sm-4">
  330. <button type="button" onclick="recargar()" class="btn btn-outline-secondary btn-lg btn-block font-weight-bold btnRecargar"><i class="ing-regresar ml-2 text-danger mr-2"></i> Recargar</button>
  331. </div>
  332. <div class="col-sm-4">
  333. <button type="button" id="btnChecar" class="btn btn-outline-primary btn-lg btn-block font-weight-bold ">Checar <i class="icon icon-arrow font-weight-bold ml-2 text-danger"></i></button>
  334. </div>
  335. </div>
  336. <?php
  337. }else{
  338. echo "<h2 class='text-center text-danger mt-4'>No hay horarios por registrar</h2>";
  339. ?>
  340. <div class="row justify-content-center mt-5">
  341. <div class="col-sm-4">
  342. <button type="button" onclick="recargar()" class="btn btn-outline-secondary btn-lg btn-block font-weight-bold btnRecargar"><i class="ing-regresar ml-2 text-danger mr-2"></i> Recargar</button>
  343. </div>
  344. </div>
  345. <?php
  346. }
  347. ?>
  348. </div>
  349. </div>
  350. </form>
  351. </div>
  352. <!-- ---------- -->
  353. <div id="result_ok" class="sub-bloque d-none">
  354. <div class="row">
  355. <div class="col-12 text-center" id="estado">
  356. <img src="imagenes/atiempo.png" alt="resultado" class="img-fluid d-none d-sm-block mx-auto">
  357. <h2 class="indivisa-title text-big">Asistencia</h2>
  358. </div>
  359. </div>
  360. <div class="row justify-content-center mt-5">
  361. <div class="col-sm-4">
  362. <button type="button" onclick="recargar()" class="btn btn-outline-secondary btn-lg btn-block font-weight-bold btnRecargar"><i class="ing-regresar ml-2 text-danger mr-2"></i> Recargar</button>
  363. </div>
  364. </div>
  365. </div>
  366. <!-- ---------- -->
  367. <div id="result_no" class="sub-bloque row d-none">
  368. <div class="col-sm-8 my-auto">
  369. <h1 class="indivisa-title text-secondary text-big" id="nombre"><strong class="text-danger">No</strong> tiene horario asignado</h1>
  370. <p class="text-secondary sin-servicio">Verifique que la clave <span class="clave font-weight-bold">000</span> sea correcta.</p>
  371. </div>
  372. <div class="col-sm-4 text-center my-auto d-none d-sm-block">
  373. <img src="imagenes/sinregistro.png" alt="sin horario" class="img-fluid">
  374. </div>
  375. <div class="row justify-content-center mt-5">
  376. <div class="col-sm-4">
  377. <button type="button" onclick="recargar()" class="btn btn-outline-secondary btn-lg btn-block font-weight-bold btnRecargar"><i class="ing-regresar ml-2 text-danger mr-2"></i> Recargar</button>
  378. </div>
  379. </div>
  380. </div>
  381. <!-- ---------- -->
  382. <!-- ---------- -->
  383. <div id="internet" class="sub-bloque row d-none">
  384. <div class="col-sm-7">
  385. <h3 class="indivisa-title subtitle mb-5 text-big">Sin servicio</h3>
  386. <p class="text-secondary sin-servicio">Por el momento la conexión a internet está fallando, por favor inténtelo más tarde.</p>
  387. <div class="text-center">
  388. <div class="spinner-grow text-primary" role="status">
  389. <span class="sr-only">Loading...</span>
  390. </div>
  391. <em>Conectando</em>
  392. </div>
  393. </div>
  394. <div class="col-sm-5 text-center d-none d-sm-block">
  395. <img src="imagenes/nored.png" alt="sin red" class="img-fluid">
  396. </div>
  397. </div>
  398. <!-- ---------- -->
  399. <p id="last-error" class="text-white">-</p>
  400. <?php } ?>
  401. </div>
  402. </div>
  403. </div>
  404. </div>
  405. <div id="mensaje" class="modal fade" data-backdrop="static" data-keyboard="false">
  406. <div class="modal-dialog modal-dialog-centered modal-lg">
  407. <div class="modal-content">
  408. <div class="modal-body text-center">
  409. <!--h1 class="modal-title"><i class="fas fa-check-circle fa-3x text-success"></i></h1 ASISTENCIA-->
  410. <!--h1 class="modal-title"><i class="fas fa-exclamation-triangle fa-3x text-warning"></i></h1 -->
  411. <h2 class="modal-title text-danger mb-4" id="mensaje_error"><i class="far fa-times-circle fa-lg"></i> <span></span></h2>
  412. <div id="aviso-texto"></div>
  413. <div id="resultado">
  414. <h2 class="modal-title text-primary mb-4" id="mensaje_ok"><span></span></h2>
  415. <table class="table border border-info" style="width:100%;">
  416. <tbody id="table-result">
  417. <tr class="materia-row font-weight-bold">
  418. <td class="mat-desc"></td>
  419. <td class="mat-fecha"></td>
  420. <td class="mat-salon"></td>
  421. <td class="mat-icon">
  422. <span class="retardo text-warning"><span class="fas fa-clock fa-lg"></span> Retardo</span>
  423. <span class="asistencia text-success"><span class=" fas fa-check fa-lg"></span> Asistencia</span>
  424. </td>
  425. </tr>
  426. </tbody>
  427. </table>
  428. </div>
  429. <h3 class="my-3" id="resultado"></h3>
  430. <!--<button type="button" id="dismissModal" class="btn btn-primary" data-dismiss="modal"><i class="fas fa-check mr-2"></i>OK</button>-->
  431. </div>
  432. </div>
  433. </div>
  434. </div>
  435. <script>
  436. var d, h, m, s, animate;
  437. var started_at = new Date().getTime();
  438. var server_time = <?php echo time(); ?>;
  439. var ultimosMax = 6;
  440. </script>
  441. <script src="./js/jquery.min.js"></script>
  442. <script src="./js/bootstrap/popper.min.js"></script>
  443. <script src="./js/bootstrap/bootstrap.min.js"></script>
  444. <script type="text/javascript" src="checador.js"></script>
  445. <script>
  446. $(document).ready(function(){
  447. init();
  448. });
  449. function recargar(){
  450. window.location.reload();
  451. $("#btnChecar").attr("disabled", true);
  452. $("#btnRecargar").attr("disabled", true);
  453. }
  454. </script>
  455. </body>
  456. </html>