checadorclave copy.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <?php
  2. //no index
  3. header("X-Robots-Tag: noindex, nofollow", true);
  4. //no caché
  5. header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
  6. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  7. header('Cache-Control: no-store, no-cache, must-revalidate');
  8. header('Cache-Control: post-check=0, pre-check=0', false);
  9. header('Pragma: no-cache');
  10. date_default_timezone_set('America/Mexico_City');
  11. //header("Content-Type: text/xml; charset=UTF-8");
  12. require_once("../include/util.php");
  13. require_once("../include/nusoap/nusoap.php");
  14. require_once("../include/bd_pdo.php");
  15. //define("PAG", "http://200.13.89.27/webservice/materiainfo_service");//pruebas
  16. define("PAG", "http://200.13.89.8/webservice/materiainfo_service");
  17. $server = new soap_server();
  18. $server->configureWSDL("checador_service", PAG);
  19. //Create a complex types
  20. $server->wsdl->addComplexType('HorarioComplex', 'complexType', 'struct', 'all','',
  21. array( 'salon' => array('name' => 'salon','type' => 'xsd:string'),
  22. 'hora' => array('name' => 'hora','type' => 'xsd:string'),
  23. 'hora_inicio' => array('name' => 'hora_inicio','type' => 'xsd:string'),
  24. 'tipo' => array('name' => 'tipo','type' => 'xsd:integer'),
  25. 'fecha' => array('name' => 'fecha','type' => 'xsd:string'),
  26. 'retardo' => array('name' => 'retardo','type' => 'xsd:boolean'),
  27. 'materia' => array('name' => 'materia','type' => 'xsd:string'),
  28. 'grupo' => array('name' => 'grupo','type' => 'xsd:string')
  29. )
  30. );
  31. $server->wsdl->addComplexType('HorariosList', 'complexType', 'array', '', 'SOAP-ENC:Array', array(),
  32. array(
  33. array('ref' => 'SOAP-ENC:arrayType',
  34. 'wsdl:arrayType' => 'tns:HorarioComplex[]')
  35. ),
  36. 'tns:HorarioComplex'
  37. );
  38. $server->wsdl->addComplexType('MensajeComplex', 'complexType', 'struct', 'all','',
  39. array(
  40. 'texto' => array('name' => 'texto','type' => 'xsd:string')
  41. )
  42. );
  43. $server->wsdl->addComplexType('MensajesList', 'complexType', 'array', '', 'SOAP-ENC:Array', array(),
  44. array(
  45. array('ref' => 'SOAP-ENC:arrayType',
  46. 'wsdl:arrayType' => 'tns:MensajeComplex[]')
  47. ),
  48. 'tns:MensajeComplex'
  49. );
  50. //---------
  51. //Recibe clave::string, regresa HorarioComplex
  52. function gethorarios($clave = ""){
  53. global $pdo;
  54. try {
  55. $fecha = date("Y-m-d");
  56. $hora = date("H:i");
  57. $esProf = false;
  58. $esAdmin = false;
  59. $asistRegistrada = false;
  60. $msg = 0;
  61. $fecha = '2021-05-17';
  62. $hora = '08:45:00';
  63. $fecha_hora = $fecha." ".$hora;
  64. $clave = intval($clave);
  65. $error = false;
  66. $resultMsg = "";
  67. //Manda clave ULSA y recibe id de Usuario
  68. $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:clave) AS "Usuario_id"');//Obtiene todo el calendario
  69. $stmt->bindParam(":clave", $clave);
  70. if(!$stmt->execute()){
  71. $resultMsg = "No existe la clave";
  72. $error = true;
  73. }else{
  74. $usr_rs = $stmt->fetch();
  75. }
  76. $stmt->closeCursor();
  77. //Datos de usuario
  78. if(!$error){
  79. $stmt = $pdo->prepare('Select * from fs_usuario(:id)');
  80. $stmt->bindParam(":id", $usr_rs["Usuario_id"]);
  81. if(!$stmt->execute()){
  82. $resultMsg = "No existe el usuario";
  83. $error = true;
  84. }else{
  85. $usr_datos = $stmt->fetch();//Devuelve sólo 1 resultado
  86. $stmt->closeCursor(); // cierra conexion de resultado
  87. $stmt = null; // cierra conexion
  88. }
  89. }
  90. $hasAsistencia = false;//revisa si tiene asistenias nuevas
  91. //Arrelo para guardar los resultados de las validaciones
  92. $asistenciasArr = array(
  93. "asistencia" => array("profesor"=>array(), "administrativo"=>array()),
  94. "retardo" => array("profesor"=>array(), "administrativo"=>array())
  95. );
  96. //--Profesor LICENCIATURA
  97. if(!$error){
  98. //Lee asistencias
  99. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, -30, 16, 1)');//Limite inferior es incluyente, limite superior excluyente
  100. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  101. $stmt->bindParam(":fecha", $fecha);
  102. $stmt->bindParam(":hora", $hora);
  103. if(!$stmt->execute()){
  104. //$t = $stmt->errorInfo();
  105. $resultMsg = "No se pudieron leer los horarios.";
  106. $error = true;
  107. }else{
  108. $esProf = true;
  109. $rs = $stmt->fetchAll();
  110. if(count($rs) > 0) $hasAsistencia = true;
  111. $asistenciasArr["asistencia"]["profesor"] = array_merge($asistenciasArr["asistencia"]["profesor"], $rs);
  112. }
  113. $stmt->closeCursor();
  114. }
  115. if(!$error){
  116. //Lee retardos
  117. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, 16, 31, 1)');//Limite inferior es incluyente, limite superior excluyente
  118. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  119. $stmt->bindParam(":fecha", $fecha);
  120. $stmt->bindParam(":hora", $hora);
  121. if(!$stmt->execute()){
  122. //$t = $stmt->errorInfo();
  123. $resultMsg = "No se pudieron leer los horarios. ";
  124. $error = true;
  125. }else{
  126. $esProf = true;
  127. $rs = $stmt->fetchAll();
  128. if(count($rs) > 0) $hasAsistencia = true;
  129. $asistenciasArr["retardo"]["profesor"] = array_merge($asistenciasArr["retardo"]["profesor"], $rs);
  130. }
  131. $stmt->closeCursor();
  132. }
  133. //--Profesor POSGRADO
  134. if(!$error){
  135. //Lee asistencias
  136. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, -60, 10, 2)');//Limite inferior es incluyente, limite superior excluyente
  137. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  138. $stmt->bindParam(":fecha", $fecha);
  139. $stmt->bindParam(":hora", $hora);
  140. if(!$stmt->execute()){
  141. //$t = $stmt->errorInfo();
  142. $resultMsg = "No se pudieron leer los horarios. ";
  143. $error = true;
  144. }else{
  145. $esProf = true;
  146. $rs = $stmt->fetchAll();
  147. if(count($rs) > 0) $hasAsistencia = true;
  148. $asistenciasArr["asistencia"]["profesor"] = array_merge($asistenciasArr["asistencia"]["profesor"], $rs);
  149. }
  150. $stmt->closeCursor();
  151. }
  152. if(!$error){
  153. //Lee retardos
  154. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, 10, 31, 2)');//Limite inferior es incluyente, limite superior excluyente
  155. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  156. $stmt->bindParam(":fecha", $fecha);
  157. $stmt->bindParam(":hora", $hora);
  158. if(!$stmt->execute()){
  159. //$t = $stmt->errorInfo();
  160. $resultMsg = "No se pudieron leer los horarios. ";
  161. $error = true;
  162. }else{
  163. $esProf = true;
  164. $rs = $stmt->fetchAll();
  165. if(count($rs) > 0) $hasAsistencia = true;
  166. $asistenciasArr["retardo"]["profesor"] = array_merge($asistenciasArr["retardo"]["profesor"], $rs);
  167. }
  168. $stmt->closeCursor();
  169. }
  170. //--Administrativo
  171. if(!$error){
  172. //Lee asistencias
  173. $stmt = $pdo->prepare('Select * from fs_asistenciaadministrativo_busca(:fecha, :hora, :usr)');//Limite inferior es incluyente, limite superior excluyente
  174. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  175. $stmt->bindParam(":fecha", $fecha);
  176. $stmt->bindParam(":hora", $hora);
  177. if(!$stmt->execute()){
  178. $t = $stmt->errorInfo();
  179. $resultMsg = "No se pudieron leer los horarios administrativos. ";
  180. $error = true;
  181. }else{
  182. $esAdmin = true;
  183. $rs = $stmt->fetchAll();
  184. if(count($rs) > 0) $hasAsistencia = true;
  185. $asistenciasArr["asistencia"]["administrativo"] = array_merge($asistenciasArr["asistencia"]["administrativo"], $rs);
  186. }
  187. $stmt->closeCursor();
  188. }
  189. /*if(!$error){
  190. //Lee retardos no se usan
  191. $stmt = $pdo->prepare('Select * from fs_asistenciaadministrativo_busca(:fecha, :hora, :usr, 16, 31)');//Limite inferior es incluyente, limite superior excluyente
  192. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  193. $stmt->bindParam(":fecha", $fecha);
  194. $stmt->bindParam(":hora", $hora);
  195. if(!$stmt->execute()){
  196. //$t = $stmt->errorInfo();
  197. $error = 2; // "No se pudieron leer los horarios. ";
  198. $error = true;
  199. }else{
  200. $rs = $stmt->fetchAll();
  201. if(count($rs) > 0) $hasAsistencia = true;
  202. $asistenciasArr["retardo"]["administrativo"] = array_merge($asistenciasArr["retardo"]["administrativo"], $rs);
  203. }
  204. $stmt->closeCursor();
  205. }*/
  206. //--Inserta en tabla de asistencia
  207. $resultArr = array();
  208. if($hasAsistencia){
  209. $pdo->beginTransaction();
  210. foreach($asistenciasArr as $keyAsist=>$asistArr){
  211. if($keyAsist == "asistencia") $retardo = 'false'; else $retardo = 'true';
  212. foreach($asistArr as $keyTipo=>$tipoArr){
  213. if($keyTipo == "profesor") $tipo = 1; else $tipo = 2;
  214. foreach($tipoArr as $horario){
  215. $query = "";
  216. if($tipo == 1 && isset($horario["Reposicion_id"]) && $horario["Reposicion_id"] != "") $query .= ":rep_id";
  217. else $query .= "NULL";
  218. $isRepo = "false";
  219. if($tipo == 1 && isset($horario["Asistencia_isReposicion"]) && $horario["Asistencia_isReposicion"]){
  220. $isRepo = "true";
  221. }
  222. if($horario["HorarioGrupo_id"] != ""){
  223. $stmt = $pdo->prepare('Select * from fi_asistenciausuario(:usr, :tipo, :fecha_evento, :horario, :retardo, '.$isRepo.', :fecha_reg,'.$query.')');
  224. $stmt->bindParam(":horario", $horario["HorarioGrupo_id"]);
  225. }else
  226. $stmt = $pdo->prepare('Select * from fi_asistenciausuario(:usr, :tipo, :fecha_evento, NULL, :retardo, '.$isRepo.', :fecha_reg,'.$query.')');
  227. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  228. $stmt->bindParam(":tipo", $tipo);
  229. $stmt->bindParam(":fecha_evento", $horario["Fecha"]);
  230. $stmt->bindParam(":retardo", $retardo);
  231. $stmt->bindParam(":fecha_reg", $fecha_hora);
  232. if($tipo == 1 && isset($horario["Reposicion_id"]) && $horario["Reposicion_id"] != "") $stmt->bindParam(":rep_id", $horario["Reposicion_id"]);
  233. if(!$stmt->execute()){
  234. //$t = $stmt->errorInfo();
  235. $error = 3; // "No se pudo insertar la asistencia. ";
  236. $error = true;
  237. break;
  238. }else{
  239. $asist_rs = $stmt->fetch();
  240. $stmt->closeCursor();
  241. if($asist_rs["fi_asistenciausuario"] != 0){//insertó algo
  242. $salon = "";
  243. if(isset($horario["Salon_desc"])){//para profesores
  244. if($horario["Salon_desc_larga"]!= ""){
  245. $salon = $horario["Salon_desc"]." (".$horario["Salon_desc_larga"].")";
  246. }else{
  247. $salon = $horario["Salon_desc"];
  248. }
  249. }
  250. if($tipo == 1){
  251. $resultArr[] = array("salon"=>$salon, "hora"=>$hora, "hora_inicio"=>substr($horario["Horario_hora"], 0, 5), "tipo"=>$tipo, "fecha"=>$horario["Fecha"], "retardo"=>$retardo, "materia"=>$horario["Materia_desc"], "grupo"=>$horario["Grupo_desc"]." ".$horario["Carrera_prefijo"]);
  252. }
  253. else{
  254. $resultArr[] = array("salon"=>$salon, "hora"=>$hora, "hora_inicio"=>substr($horario["Horario_hora"], 0, 5), "tipo"=>$tipo, "fecha"=>$horario["Fecha"], "retardo"=>$retardo, "materia"=>'Horario administrativo', "grupo"=>'');
  255. }
  256. $asistRegistrada = true;
  257. }/*else{
  258. $resultMsg = "Ya se registró la asistencia para los horarios disponibles. ";
  259. }*/
  260. }
  261. }//foreach horario
  262. }//foreach prof/admin
  263. }//foreach asistencia/retardo
  264. if($error){
  265. $pdo->rollBack();
  266. }else
  267. $pdo->commit();
  268. }else{
  269. //revisa si ya se había registrado
  270. //Profesor Lic
  271. $registradasArr = null;
  272. $registradasArr = array();
  273. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_registrada(:fecha, :hora, :usr, -30, 31, 1)');//Limite inferior es incluyente, limite superior excluyente
  274. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  275. $stmt->bindParam(":fecha", $fecha);
  276. $stmt->bindParam(":hora", $hora);
  277. if(!$stmt->execute()){
  278. //$t = $stmt->errorInfo();
  279. $resultMsg = "No se pudieron leer los horarios.";
  280. $error = true;
  281. }else{
  282. $rs = $stmt->fetchAll();
  283. foreach($rs as $row){
  284. $salon = "";
  285. if(isset($row["Salon_desc"])){//para profesores
  286. if($row["Salon_desc_larga"]!= ""){
  287. $salon = $row["Salon_desc"]." (".$row["Salon_desc_larga"].")";
  288. }else{
  289. $salon = $row["Salon_desc"];
  290. }
  291. }
  292. $registradasArr[]= array("salon"=>$salon, "hora"=>$row["Asistencia_hora"], "hora_inicio"=>substr($row["Horario_hora"], 0, 5), "tipo"=>1, "fecha"=>$row["Fecha"], "retardo"=>$row["Asistencia_isRetardo"], "materia"=>$row["Materia_desc"], "grupo"=>$row["Grupo_desc"]." ".$row["Carrera_prefijo"]);
  293. }
  294. }
  295. $stmt->closeCursor();
  296. //Profesor Posgrado
  297. $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_registrada(:fecha, :hora, :usr, -60, 31, 2)');//Limite inferior es incluyente, limite superior excluyente
  298. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  299. $stmt->bindParam(":fecha", $fecha);
  300. $stmt->bindParam(":hora", $hora);
  301. if(!$stmt->execute()){
  302. //$t = $stmt->errorInfo();
  303. $resultMsg = "No se pudieron leer los horarios.";
  304. $error = true;
  305. }else{
  306. $rs = $stmt->fetchAll();
  307. foreach($rs as $row){
  308. $salon = "";
  309. if(isset($row["Salon_desc"])){//para profesores
  310. if($row["Salon_desc_larga"]!= ""){
  311. $salon = $row["Salon_desc"]." (".$row["Salon_desc_larga"].")";
  312. }else{
  313. $salon = $row["Salon_desc"];
  314. }
  315. }
  316. $registradasArr[]= array("salon"=>$salon, "hora"=>$row["Asistencia_hora"], "hora_inicio"=>substr($row["Horario_hora"], 0, 5), "tipo"=>1, "fecha"=>$row["Fecha"], "retardo"=>$row["Asistencia_isRetardo"], "materia"=>$row["Materia_desc"], "grupo"=>$row["Grupo_desc"]." ".$row["Carrera_prefijo"]);
  317. }
  318. }
  319. $stmt->closeCursor();
  320. //Administrativo
  321. $stmt = $pdo->prepare('Select * from fs_asistenciaadministrativo_registrada(:fecha, :hora, :usr)');//Sin límites administrativos
  322. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  323. $stmt->bindParam(":fecha", $fecha);
  324. $stmt->bindParam(":hora", $hora);
  325. if(!$stmt->execute()){
  326. $t = $stmt->errorInfo();
  327. $resultMsg = "No se pudieron leer los horarios. (Select * from fs_asistenciaadministrativo_registrada('$fecha', '$hora', ".$usr_rs["Usuario_id"]."))".$t[2];
  328. $error = true;
  329. }else{
  330. $rs = $stmt->fetchAll();
  331. foreach($rs as $row){
  332. $salon = "";
  333. $registradasArr[]= array("salon"=>$salon, "hora"=>$row["Asistencia_hora"], "hora_inicio"=>substr($row["Horario_hora"], 0, 5), "tipo"=>2, "fecha"=>$row["Fecha"], "retardo"=>$row["Asistencia_isRetardo"], "materia"=>"Horario administrativo", "grupo"=>"");
  334. }
  335. }
  336. $stmt->closeCursor();
  337. }//fin asistencias registrdas
  338. //Busca avisos de hoy
  339. $avisoArr = array();
  340. $stmt = $pdo->prepare('Select * from fs_avisochecador(:usr, now()::date)');
  341. $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
  342. if($stmt->execute()){
  343. $aviso_rs = $stmt->fetchAll();
  344. foreach($aviso_rs as $aviso){
  345. $avisoArr[] = $aviso["Aviso_texto"];
  346. }
  347. //$return["avisoArr"] = $avisoArr;
  348. }else{
  349. $t = $stmt->errorInfo();
  350. //$return["errorAviso"] = "error: ".$t[2];
  351. $resultMsg = "No se pudieron obtener los avisos".$t[2];
  352. }
  353. $stmt->closeCursor();
  354. if(!$error){
  355. if(count($resultArr) == 0){
  356. if(!isset($resultMsg)) $resultMsg = "";
  357. if(count($registradasArr) > 0){
  358. $resultMsg .= "Ya se registraron asistencias.";
  359. }else{
  360. $resultMsg .= "No hay más horarios para registrar.";
  361. //$pdo->rollBack();
  362. $error = true;
  363. }
  364. }else{
  365. $resultMsg = "Registrado [".$hora."]";
  366. //$return["result"] = $resultArr;
  367. //$pdo->commit();//comment to test
  368. }
  369. }/*else{
  370. $pdo->rollBack();
  371. }*/
  372. //Inserta log de asistencias
  373. /*$log = new LogAsistencias();
  374. if($asistRegistrada)
  375. $log->appendLog($clave, "Registrada");
  376. else
  377. $log->appendLog($clave, "No registrada");*/
  378. }catch(PDOException $e) {
  379. $pdo->rollBack();
  380. $resultMsg = "Ocurrió un error al insertar la asistencia ";
  381. $error = true;
  382. }
  383. return array(
  384. 'result' => !$error,
  385. 'usuario_nombre' => $usr_datos["Usuario_apellidos"]." ".$usr_datos["Usuario_nombre"],
  386. 'horario_array' => $resultArr,
  387. 'asistencia_array' => $registradasArr,
  388. "mensaje_array" => $avisoArr,
  389. 'result_msg' => $resultMsg
  390. );
  391. //array('result' => 'xsd:boolean', 'horario_array' => 'tns:HorariosList', 'mensaje_array' => 'tns:MensajesList', 'error' => 'xsd:string'),//regresa
  392. }
  393. // Parametros de salida
  394. $server->register("gethorarios",
  395. array("clave" => "xsd:integer"),//recibe
  396. array('result' => 'xsd:boolean', 'usuario_nombre' => 'xsd:string', 'horario_array' => 'tns:HorariosList', 'asistencia_array' => 'tns:HorariosList', 'mensaje_array' => 'tns:MensajesList', 'result_msg' => 'xsd:string'),//regresa
  397. PAG,
  398. PAG."#gethorarios",
  399. "rpc",
  400. "encoded",
  401. "Obtiene listado de materias y listado de mensajes para la clave de usuario");
  402. @$server->service(file_get_contents("php://input"));
  403. ?>