123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- <?php
- //no index
- header("X-Robots-Tag: noindex, nofollow", true);
- //no caché
- header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- header('Cache-Control: no-store, no-cache, must-revalidate');
- header('Cache-Control: post-check=0, pre-check=0', false);
- header('Pragma: no-cache');
- date_default_timezone_set('America/Mexico_City');
- //header("Content-Type: text/xml; charset=UTF-8");
- require_once("../include/util.php");
- require_once("../include/nusoap/nusoap.php");
- require_once("../include/bd_pdo.php");
- //define("PAG", "http://200.13.89.27/webservice/materiainfo_service");//pruebas
- define("PAG", "http://200.13.89.8/webservice/materiainfo_service");
- $server = new soap_server();
- $server->configureWSDL("checador_service", PAG);
- //Create a complex types
- $server->wsdl->addComplexType('HorarioComplex', 'complexType', 'struct', 'all','',
- array( 'salon' => array('name' => 'salon','type' => 'xsd:string'),
- 'hora' => array('name' => 'hora','type' => 'xsd:string'),
- 'hora_inicio' => array('name' => 'hora_inicio','type' => 'xsd:string'),
- 'tipo' => array('name' => 'tipo','type' => 'xsd:integer'),
- 'fecha' => array('name' => 'fecha','type' => 'xsd:string'),
- 'retardo' => array('name' => 'retardo','type' => 'xsd:boolean'),
- 'materia' => array('name' => 'materia','type' => 'xsd:string'),
- 'grupo' => array('name' => 'grupo','type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType('HorariosList', 'complexType', 'array', '', 'SOAP-ENC:Array', array(),
- array(
- array('ref' => 'SOAP-ENC:arrayType',
- 'wsdl:arrayType' => 'tns:HorarioComplex[]')
- ),
- 'tns:HorarioComplex'
- );
- $server->wsdl->addComplexType('MensajeComplex', 'complexType', 'struct', 'all','',
- array(
- 'texto' => array('name' => 'texto','type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType('MensajesList', 'complexType', 'array', '', 'SOAP-ENC:Array', array(),
- array(
- array('ref' => 'SOAP-ENC:arrayType',
- 'wsdl:arrayType' => 'tns:MensajeComplex[]')
- ),
- 'tns:MensajeComplex'
- );
- //---------
- function registraAsistencia($pdo, $usr_id){
- try {
- $fecha = date("Y-m-d");
- $hora = date("H:i");
- $fecha = '2022-08-09';
- $hora = '18:53:40';
- $fecha_hora = $fecha." ".$hora;
- $esProf = false;
- $esAdmin = false;
- $asistRegistrada = false;
- $msg = 0;
-
- $error = false;
- $resultMsg = "";
- $hasAsistencia = false;//revisa si tiene asistenias nuevas
-
- //Arrelo para guardar los resultados de las validaciones
- $asistenciasArr = array(
- "asistencia" => array("profesor"=>array(), "administrativo"=>array()),
- "retardo" => array("profesor"=>array(), "administrativo"=>array())
- );
-
- //--Profesor LICENCIATURA
- if(!$error){
- //Lee asistencias
- $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, -30, 16, 1)');//Limite inferior es incluyente, limite superior excluyente
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $resultMsg = "No se pudieron leer los horarios.";
- $error = true;
- }else{
- $esProf = true;
- $rs = $stmt->fetchAll();
- if(count($rs) > 0) $hasAsistencia = true;
- $asistenciasArr["asistencia"]["profesor"] = array_merge($asistenciasArr["asistencia"]["profesor"], $rs);
- }
- $stmt->closeCursor();
- }
- if(!$error){
- //Lee retardos
- $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, 16, 31, 1)');//Limite inferior es incluyente, limite superior excluyente
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $resultMsg = "No se pudieron leer los horarios. ";
- $error = true;
- }else{
- $esProf = true;
- $rs = $stmt->fetchAll();
- if(count($rs) > 0) $hasAsistencia = true;
- $asistenciasArr["retardo"]["profesor"] = array_merge($asistenciasArr["retardo"]["profesor"], $rs);
- }
- $stmt->closeCursor();
- }
-
- //--Profesor POSGRADO
- if(!$error){
- //Lee asistencias
- $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, -60, 10, 2)');//Limite inferior es incluyente, limite superior excluyente
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $resultMsg = "No se pudieron leer los horarios. ";
- $error = true;
- }else{
- $esProf = true;
- $rs = $stmt->fetchAll();
- if(count($rs) > 0) $hasAsistencia = true;
- $asistenciasArr["asistencia"]["profesor"] = array_merge($asistenciasArr["asistencia"]["profesor"], $rs);
- }
- $stmt->closeCursor();
- }
- if(!$error){
- //Lee retardos
- $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_busca(:fecha, :hora, :usr, 10, 31, 2)');//Limite inferior es incluyente, limite superior excluyente
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $resultMsg = "No se pudieron leer los horarios. ";
- $error = true;
- }else{
- $esProf = true;
- $rs = $stmt->fetchAll();
- if(count($rs) > 0) $hasAsistencia = true;
- $asistenciasArr["retardo"]["profesor"] = array_merge($asistenciasArr["retardo"]["profesor"], $rs);
- }
- $stmt->closeCursor();
- }
-
- //--Administrativo
- if(!$error){
- //Lee asistencias
- $stmt = $pdo->prepare('Select * from fs_asistenciaadministrativo_busca(:fecha, :hora, :usr)');//Limite inferior es incluyente, limite superior excluyente
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $resultMsg = "No se pudieron leer los horarios administrativos. ";
- $error = true;
- }else{
- $esAdmin = true;
- $rs = $stmt->fetchAll();
- if(count($rs) > 0) $hasAsistencia = true;
- $asistenciasArr["asistencia"]["administrativo"] = array_merge($asistenciasArr["asistencia"]["administrativo"], $rs);
- }
- $stmt->closeCursor();
- }
- /*if(!$error){
- //Lee retardos no se usan
- $stmt = $pdo->prepare('Select * from fs_asistenciaadministrativo_busca(:fecha, :hora, :usr, 16, 31)');//Limite inferior es incluyente, limite superior excluyente
- $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $error = 2; // "No se pudieron leer los horarios. ";
- $error = true;
- }else{
- $rs = $stmt->fetchAll();
- if(count($rs) > 0) $hasAsistencia = true;
- $asistenciasArr["retardo"]["administrativo"] = array_merge($asistenciasArr["retardo"]["administrativo"], $rs);
- }
- $stmt->closeCursor();
- }*/
- //--Inserta en tabla de asistencia
- $resultArr = array();
- if($hasAsistencia){
- $pdo->beginTransaction();
- foreach($asistenciasArr as $keyAsist=>$asistArr){
- if($keyAsist == "asistencia") $retardo = 'false'; else $retardo = 'true';
- if($keyAsist != "asistencia") $retardo = 'true';
- foreach($asistArr as $keyTipo=>$tipoArr){
- if($keyTipo == "profesor") $tipo = 1; else $tipo = 2;
- foreach($tipoArr as $horario){
- $query = "";
- if($tipo == 1 && isset($horario["Reposicion_id"]) && $horario["Reposicion_id"] != "") $query .= ":rep_id";
- else $query .= "NULL";
- $isRepo = "false";
- if($tipo == 1 && isset($horario["Asistencia_isReposicion"]) && $horario["Asistencia_isReposicion"]){
- $isRepo = "true";
- }
- if($horario["HorarioGrupo_id"] != ""){
- $stmt = $pdo->prepare('Select * from fi_asistenciausuario(:usr, :tipo, :fecha_evento, :horario, :retardo, '.$isRepo.', :fecha_reg,'.$query.')');
- $stmt->bindParam(":horario", $horario["HorarioGrupo_id"]);
- }else
- $stmt = $pdo->prepare('Select * from fi_asistenciausuario(:usr, :tipo, :fecha_evento, NULL, :retardo, '.$isRepo.', :fecha_reg,'.$query.')');
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":tipo", $tipo);
- $stmt->bindParam(":fecha_evento", $horario["Fecha"]);
- $stmt->bindParam(":retardo", $retardo);
- $stmt->bindParam(":fecha_reg", $fecha_hora);
- if($tipo == 1 && isset($horario["Reposicion_id"]) && $horario["Reposicion_id"] != "") $stmt->bindParam(":rep_id", $horario["Reposicion_id"]);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $error = 3; // "No se pudo insertar la asistencia. ";
- $error = true;
- break;
- }else{
- $asist_rs = $stmt->fetch();
- $stmt->closeCursor();
- if($asist_rs["fi_asistenciausuario"] != 0){//insertó algo
- $salon = "";
- if(isset($horario["Salon_desc"])){//para profesores
- if($horario["Salon_desc_larga"]!= ""){
- $salon = $horario["Salon_desc"]." (".$horario["Salon_desc_larga"].")";
- }else{
- $salon = $horario["Salon_desc"];
- }
- }
- if($tipo == 1){
- $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"]);
- }
- else{
- $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"=>'');
- }
- $asistRegistrada = true;
- }/*else{
- $resultMsg = "Ya se registró la asistencia para los horarios disponibles. ";
- }*/
- }
- }//foreach horario
- }//foreach prof/admin
- }//foreach asistencia/retardo
- if($error){
- $pdo->rollBack();
- }else
- $pdo->commit();
- }else{
- //revisa si ya se había registrado
-
- //Profesor Lic
- $registradasArr = null;
- $registradasArr = array();
- $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_registrada(:fecha, :hora, :usr, -30, 31, 1)');//Limite inferior es incluyente, limite superior excluyente
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $resultMsg = "No se pudieron leer los horarios.";
- $error = true;
- }else{
- $rs = $stmt->fetchAll();
- foreach($rs as $row){
- $salon = "";
- if(isset($row["Salon_desc"])){//para profesores
- if($row["Salon_desc_larga"]!= ""){
- $salon = $row["Salon_desc"]." (".$row["Salon_desc_larga"].")";
- }else{
- $salon = $row["Salon_desc"];
- }
- }
- $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"]);
- }
- }
- $stmt->closeCursor();
- //Profesor Posgrado
- $stmt = $pdo->prepare('Select * from fs_asistenciaprofesor_registrada(:fecha, :hora, :usr, -60, 31, 2)');//Limite inferior es incluyente, limite superior excluyente
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $resultMsg = "No se pudieron leer los horarios.";
- $error = true;
- }else{
- $rs = $stmt->fetchAll();
- foreach($rs as $row){
- $salon = "";
- if(isset($row["Salon_desc"])){//para profesores
- if($row["Salon_desc_larga"]!= ""){
- $salon = $row["Salon_desc"]." (".$row["Salon_desc_larga"].")";
- }else{
- $salon = $row["Salon_desc"];
- }
- }
- $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"]);
- }
- }
- $stmt->closeCursor();
-
- //Administrativo
- $stmt = $pdo->prepare('Select * from fs_asistenciaadministrativo_registrada(:fecha, :hora, :usr)');//Sin límites administrativos
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":fecha", $fecha);
- $stmt->bindParam(":hora", $hora);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $resultMsg = "No se pudieron leer los horarios.";// (Select * from fs_asistenciaadministrativo_registrada('$fecha', '$hora', ".$usr_rs["Usuario_id"]."))".$t[2];
- $error = true;
- }else{
- $rs = $stmt->fetchAll();
- foreach($rs as $row){
- $salon = "";
- $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"=>"");
- }
- }
- $stmt->closeCursor();
- }//fin asistencias registrdas
- if(!$error){
- if(count($resultArr) == 0){
- if(!isset($resultMsg)) $resultMsg = "";
- if(count($registradasArr) > 0){
- $resultMsg .= "Ya se registraron asistencias.";
- }else{
- $resultMsg .= "No hay más horarios para registrar.";
- //$pdo->rollBack();
- $error = true;
- }
- }else{
- $resultMsg = "Registrado [".$hora."]";
- //$return["result"] = $resultArr;
- //$pdo->commit();//comment to test
- }
- }/*else{
- $pdo->rollBack();
- }*/
- }catch(PDOException $e) {
- $pdo->rollBack();
- $resultMsg = "Ocurrió un error al insertar la asistencia ";
- $error = true;
- }
-
- //Inserta log de asistencias
- /*$log = new LogAsistencias();
- if($asistRegistrada)
- $log->appendLog($clave, "Registrada");
- else
- $log->appendLog($clave, "No registrada");*/
-
- return array(
- 'result' => !$error,
- 'horario_array' => $resultArr,
- 'asistencia_array' => $registradasArr,
- 'result_msg' => $resultMsg
- );
- }
- //---------
- //Recibe clave::string, regresa HorarioComplex
- function gethorarios($clave = ""){
- global $pdo;
-
- $clave = intval($clave);
- //Manda clave ULSA y recibe id de Usuario
- $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:clave) AS "Usuario_id"');//Obtiene todo el calendario
- $stmt->bindParam(":clave", $clave);
- if(!$stmt->execute()){
- $resultMsg = "No existe la clave";
- $error = true;
- }else{
- $usr_rs = $stmt->fetch();
- }
- $stmt->closeCursor();
-
- //Datos de usuario
- if(!$error){
- $stmt = $pdo->prepare('Select * from fs_usuario(:id)');
- $stmt->bindParam(":id", $usr_rs["Usuario_id"]);
- if(!$stmt->execute()){
- $resultMsg = "No existe el usuario";
- $error = true;
- }else{
- $usr_datos = $stmt->fetch();//Devuelve sólo 1 resultado
- $stmt->closeCursor(); // cierra conexion de resultado
- $stmt = null; // cierra conexion
- }
- }
- //Avisos
- //Busca avisos de hoy
- $avisoArr = array();
- $stmt = $pdo->prepare('Select * from fs_avisochecador(:usr, now()::date)');
- $stmt->bindParam(":usr", $usr_rs["Usuario_id"]);
- if($stmt->execute()){
- $aviso_rs = $stmt->fetchAll();
- foreach($aviso_rs as $aviso){
- $avisoArr[] = $aviso["Aviso_texto"];
- }
- //$return["avisoArr"] = $avisoArr;
- }else{
- $t = $stmt->errorInfo();
- //$return["errorAviso"] = "error: ".$t[2];
- $resultMsg = "No se pudieron obtener los avisos".$t[2];
- }
- $stmt->closeCursor();
-
-
- $array = registraAsistencia($pdo, $usr_rs["Usuario_id"]);
- $array['usuario_nombre'] = $usr_datos["Usuario_apellidos"]." ".$usr_datos["Usuario_nombre"];
- $array['mensaje_array'] = $avisoArr;
- return $array;
- }
- //Recibe clave::string, regresa HorarioComplex
- function checahorarios($usr_id = ""){
- global $pdo;
- $usr_id = intval($usr_id);
- return registraAsistencia($pdo, $usr_id);
- }
- // Parametros de salida
- $server->register("gethorarios",
- array("clave" => "xsd:integer"),//recibe clave ulsa
- 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
- PAG,
- PAG."#gethorarios",
- "rpc",
- "encoded",
- "Obtiene listado de materias checadas y listado de mensajes para la clave de usuario");
-
- $server->register("checahorarios",
- array("usr_id" => "xsd:integer"),//recibe id de usuario
- array('result' => 'xsd:boolean', 'horario_array' => 'tns:HorariosList', 'asistencia_array' => 'tns:HorariosList', 'result_msg' => 'xsd:string'),//regresa
- PAG,
- PAG."#checahorarios",
- "rpc",
- "encoded",
- "Obtiene listado de materias checadas para el id de usuario");
- @$server->service(file_get_contents("php://input"));
- ?>
|