123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <?php
- /* AJAX
- * Genera nombramientos en pdf
- * Recibe:
- * id (de usuario)
- * tipo (2 o 3)
- * Return:
- * imprime pdf
- */
- setlocale(LC_TIME, 'es_MX.UTF-8');
- require_once("../../include/nocache.php");
- require_once("../../include/constantes.php");
- require_once("../../include/bd_pdo.php");
- require_once("../../include/util.php");
- require_once("../../classes/ValidaSesion.php");
- include_once('../../include/xTemplate/xtemplate.class.php'); // including mpdf.php
- include_once('../../include/mpdf/autoload.php'); // including mpdf.php
- function validaHorarios(& $arr){
- $erroresArr = array();
- for($i = 0; $i < count($arr)-1; $i++){
- for($j = $i+1; $j < count($arr); $j++){
- if($arr[$i]["Dia_id"] == $arr[$j]["Dia_id"] && !($arr[$i]["TipoHorario_id"] == 3 && $arr[$i]["TipoHorario_id"] == $arr[$j]["TipoHorario_id"])){
- if( (date('H:i', strtotime($arr[$i]["Hora_inicio"])) <= date('H:i', strtotime($arr[$j]["Hora_inicio"])) && date('H:i', strtotime($arr[$i]["Hora_final"])) > date('H:i', strtotime($arr[$j]["Hora_inicio"])) )
- || (date('H:i', strtotime($arr[$j]["Hora_inicio"])) <= date('H:i', strtotime($arr[$i]["Hora_inicio"])) && date('H:i', strtotime($arr[$j]["Hora_final"])) > date('H:i', strtotime($arr[$i]["Hora_inicio"])) )
- ){
- if($arr[$i]["TipoHorario_id"] < $arr[$j]["TipoHorario_id"]){
- $erroresArr[] = array('id'=> $arr[$i]["Horario_id"], 'nombre'=>$arr[$i]["TipoHorario_desc"], 'dia'=> diaNombre($arr[$i]["Dia_id"]), 'hora_i'=>date('H:i', strtotime($arr[$i]["Hora_inicio"])), 'hora_f'=> date('H:i', strtotime($arr[$i]["Hora_final"])));
- $arr[$i]["Duracion"] = (strtotime('2019-01-01 '.$arr[$j]["Hora_inicio"]) - strtotime('2019-01-01 '.$arr[$i]["Hora_inicio"]))/60;
- if($arr[$i]["Duracion"] <= 0) array_splice($arr, $i, 1);
-
- }else{ //if($arr[$i]["TipoHorario_id"] < $arr[$j]["TipoHorario_id"])
- $erroresArr[] = array('id'=> $arr[$j]["Horario_id"], 'nombre'=>$arr[$j]["TipoHorario_desc"], 'dia'=> diaNombre($arr[$j]["Dia_id"]), 'hora_i'=>date('H:i', strtotime($arr[$j]["Hora_inicio"])), 'hora_f'=> date('H:i', strtotime($arr[$j]["Hora_final"])));
- $arr[$j]["Duracion"] = (strtotime('2019-01-01 '.$arr[$i]["Hora_inicio"]) - strtotime('2019-01-01 '.$arr[$j]["Hora_inicio"]))/60;
- if($arr[$j]["Duracion"] <= 0) array_splice($arr, $j, 1);
- }
- }
- }
- }
- }
- return $erroresArr;
- }
- $pag = "../horarioautorizacion.php";
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, NULL, APSA);
- if(!$objSesion->tieneAcceso()){
- header("Location: ".$pag."?error=3");
- exit();
- }
- unset($objValida);
- if(!isset($_POST["id"]) || !isset($_POST["tipo"]) || !isset($_POST["fecha"]) || $_POST["fecha"] == ""){
- header("Location: ".$pag."?error=0");
- exit();
- }
- $usr = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $tipo = filter_input(INPUT_POST, "tipo", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $filter_fecha = fechaGuion(trim(filter_input(INPUT_POST, "fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- if(isset($_POST["sup"]))
- $sup = filter_input(INPUT_POST, "sup", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $puesto ="";
- $area = "";
- $stmt = $pdo->prepare('Select * from fs_subordinadoHorario(:usr) WHERE "Usuario_id" = :usr_sub');//con horarios en autorizacion
- if($usr != $_SESSION["usuario_id"]){//No se busca a si mismo, busca subordinados
- //--- Valida que sea subordinado ---
- $stmt->bindParam(":usr", $_SESSION["usuario_id"]);
- }else{
- $stmt->bindParam(":usr", $sup);
- }
- $stmt->bindParam(":usr_sub", $usr);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- echo "Ocurrió un error al leer tus subordinados.";
- exit();
- }
- $rs = $stmt->fetch();
- $stmt->closeCursor();
- $stmt = $pdo->prepare('Select * from fs_director()');
- if(!$stmt->execute()){
- $return["error"] .= "Ocurrió un error al obtener datos del director.";
- $error = true;
- }
- $director_rs = $stmt->fetch();
- $stmt->closeCursor();
- if($director_rs["Usuario_id"] != $_SESSION["usuario_id"] && (!isset($rs) || !is_array($rs) || count($rs) == 0 || $rs["Usuario_id"] != $usr)){
- //print_r($rs);
- echo "No puedes revisar el horario para ese usuario.";
- exit();
- }
- if(!isset($_SESSION["periodo_id"]) || $_SESSION["periodo_id"] ==""){
- echo "Necesitas seleccionar un periodo.";
- exit();
- }
- $puesto = $rs["Puesto_desc"];
- $puesto_id = $rs["Puesto_id"];
- $area = $rs["AreaAdministrativa_desc"];
- if(isset($_POST["self"]) && $director_rs["Usuario_id"] == $_SESSION["usuario_id"]){
- $puesto = $director_rs["Puesto_desc"];
- $puesto_id = $director_rs["Puesto_id"];
- $area = $director_rs["AreaAdministrativa_desc"];
- }
- unset($rs);
- if($tipo != 3 && $tipo != 2){
- echo "Los parámetros del horario son incorrectos.";
- exit();
- }
- //Obtiene horario del usuario
- $stmt = $pdo->prepare('Select * from fs_mihorariofull(:usr, :fecha, :tipoauto)');//Obtiene todo el calendario
- $stmt->bindParam(":fecha", $filter_fecha);
- $stmt->bindParam(":usr", $usr);
- $stmt->bindParam(":tipoauto", $tipo);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- echo "Ocurrió un error al obtener los horarios ";
- exit();
- }
- $horario_rs = $stmt->fetchAll();
- /*$horaMin = horaMin($horario_rs, "Hora_inicio");
- $horaMax = horaMax($horario_rs, "Hora_final");*/
- $horaMin = HORA_INICIO.":00";
- $horaMax = HORA_FINAL.":00";
- $stmt->closeCursor();
- $erroresArr = validaHorarios($horario_rs);
- if(count($erroresArr) > 0){
- print_r($erroresArr);
- echo '<p>El calendario tiene conflitos con el periodo actual y no se puede mostrar.</p>';
- foreach($erroresArr as $err){
- echo '<p>El horario administrativo se sobrepone al bloque <b>'.$err['nombre'].' ( '.$err['dia'].' '.$err['hora_i'].' - '.$err['hora_f'].' )</b>';
- }
- echo '<p>Elige un periodo diferente, o solicita al usuario cambie su horario administrativo.</p>';
- echo '<p><button type="button" onclick="window.close();">Regresar</button></p>';
- exit();
- }
- //---
- $stmt = $pdo->prepare('Select * from fs_dia(NULL)');
- if(!$stmt->execute()){
- echo "Error al obtener los días";
- exit();
- }
- $dias_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- //---
- $stmt = $pdo->prepare('Select * from fs_usuario(:usr)');
- $stmt->bindParam(":usr", $usr);
- if(!$stmt->execute()){
- echo "Error al obtener los datos del usuario";
- exit();
- }
- $usr_rs = $stmt->fetch();
- $stmt->closeCursor();
- $nombre_usr = $usr_rs["Usuario_apellidos"]." ".$usr_rs["Usuario_nombre"];
- unset($usr_rs);
- //Obtiene 2 corrreos
- $stmt = $pdo->prepare('Select * from fs_contacto(:id, 3 , NULL) ORDER BY "PerfilContacto_id"');//3 correo, Null todos
- $stmt->bindParam(":id", $usr);
- if(!$stmt->execute()){
- echo "Error al obtener los datos del correo";
- exit();
- }else{
- $contacto_rs = $stmt->fetchAll();
- $correos = array();
- $c_i = 0;
- $c_j = 0;
- for($c_j=0; $c_j< count($contacto_rs); $c_j++ ){
- if( strpos($contacto_rs[$c_j]["Contacto_valor"], "lasalle.mx") !== false || strpos($contacto_rs[$c_j]["Contacto_valor"], "lasallistas.org.mx") !== false ){
- $correos[] = $contacto_rs[$c_j]["Contacto_valor"];
- $c_i++;
- }
- }
- $datos["correo1"] = "";
- $datos["correo2"] = "";
- if($c_i>0){
- $datos["correo1"] = $correos[0];
- }
- if($c_i>1){
- $datos["correo2"] = $correos[1];
- }
- /*$i = 1;
- foreach($contacto_rs as $correo){
- $datos["correo".$i] = $correo["Contacto_valor"];
- $i++;
- }
- //Si el primer correo no es institucional, es personal y se va a campo 2
- if( strpos($datos["correo1"], "lasalle.mx") === false && strpos($datos["correo1"], "lasallistas.org.mx") === false ){
- $tmp = $datos["correo2"];
- $datos["correo2"] = $datos["correo1"];
- $datos["correo1"] = $tmp;
- }*/
- }
- $stmt->closeCursor(); // cierra conexion de resultado
- //---
- if(!isset($sup)){
- $stmt = $pdo->prepare('Select * from fs_superiorusuario(:usr, :puesto)');
- $stmt->bindParam(":usr", $usr);
- $stmt->bindParam(":puesto", $puesto_id);
- if(!$stmt->execute()){
- echo "Error al obtener los datos del usuario superior";
- exit();
- }
- $usr_rs = $stmt->fetch();
- $stmt->closeCursor();
- }else{
- $stmt = $pdo->prepare('Select * from fs_usuario(:usr)');
- $stmt->bindParam(":usr", $sup);
- if(!$stmt->execute()){
- echo "Error al obtener los datos del usuario";
- exit();
- }
- $usr_rs = $stmt->fetch();
- $stmt->closeCursor();
- }
- $nombreSup_usr = $usr_rs["Usuario_apellidos"]." ".$usr_rs["Usuario_nombre"];
- unset($usr_rs);
- $stmt = $pdo->prepare('Select * from fs_tipoautorizacionhorario(:tipoauto)');
- $stmt->bindParam(":tipoauto", $tipo);
- $stmt->execute();
- $tipo_rs = $stmt->fetch();
- $stmt->closeCursor();
- $tipo_nombre = $tipo_rs["TipoAutorizacionHorario_desc"];
- unset($tipo_rs);
- //-----
- $mpdf = new \Mpdf\Mpdf([
- 'mode' => 'utf-8',
- 'format' => [215, 279],
- 'orientation' => 'P'
- ]);
- //$mpdf->SetDisplayMode('fullpage');
- $stylesheet = "<style>";
- $stylesheet .= file_get_contents('../../css/indivisa.css'); // external css
- $stylesheet .= file_get_contents('../css/mihorario_reporte.css'); // external css
- $stylesheet .= "</style>";
- //echo $stylesheet;
- $xtpl = new XTemplate('../tpl/mihorario_reporte.tpl.html');
- $xtpl->assign("NOMBRE", $nombre_usr);
- $xtpl->assign("PUESTO", $puesto);
- $xtpl->assign("AREA", $area);
- if($datos["correo1"] != ""){
- $xtpl->assign("CORREO", $datos["correo1"]);
- $xtpl->parse("main.datos.correo");
- }
- if($datos["correo2"] != ""){
- $xtpl->assign("CORREO", $datos["correo2"]);
- $xtpl->parse("main.datos.correo");
- }
- $xtpl->assign("SUPERIOR", $nombreSup_usr);
- $xtpl->assign("HOY", date("d/m/Y"));
- $xtpl->assign("PERIODO", $_SESSION["periodo_desc"]);
- //$xtpl->assign("RIGHT", "Horario: ".$tipo_nombre);
- $xtpl->parse("main.datos");
- foreach($dias_rs as $dia){
- $xtpl->assign("DIA", $dia["Dia_desc"]);
- $xtpl->parse("main.header");
- }
- $rs_i = 0;
- $spacerArr = array(1=>0,0,0,0,0,0);
- $total_tipo = array(1=>0,0,0);
- //$horas_dif = intval(date('H', strtotime($horaMax))) - intval(date('H', strtotime($horaMin)));
- for($h = date('H', strtotime($horaMin)); $h < date('H', strtotime($horaMax)); $h++){
- $xtpl->assign("HORA", date('H', strtotime($h.":00")));
- $xtpl->assign("FRACCIONES", FRACCION_HORA);
- $xtpl->parse("main.hora_row.hora");
- for($f = 0; $f < FRACCION_HORA; $f++){
- foreach($dias_rs as $dia){
- if($rs_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])) == date('H:i', strtotime($h.":".($f * (60/FRACCION_HORA)))) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]){
- $size = $horario_rs[$rs_i]["Duracion"]/(60/FRACCION_HORA);
- $spacerArr[$dia["Dia_id"]] = $size -1;
- $xtpl->assign("DURACION_SIZE", $size);
- $xtpl->assign("COLOR", $horario_rs[$rs_i]["TipoHorario_color"]);
- $xtpl->assign("TIPO", $horario_rs[$rs_i]["TipoHorario_desc"]);
- $total_tipo[$horario_rs[$rs_i]["TipoHorario_id"]]+= $horario_rs[$rs_i]["Duracion"]/60;
-
- $xtpl->assign("HORA_I", date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])));
- $xtpl->assign("HORA_F", date('H:i', strtotime($horario_rs[$rs_i]["Hora_final"])));
- $xtpl->parse("main.hora_row.td.td_mihorario.hora");
-
- $salon = "";
- do{
- if($horario_rs[$rs_i]["Salon_desc"] != "") $salon = "Salón: ".$horario_rs[$rs_i]["Salon_desc"];
- else if($horario_rs[$rs_i]["Materia_desc"] != "") $salon = "<em>Pendiente</em>";
- $xtpl->assign("MATERIA", $horario_rs[$rs_i]["Materia_desc"]);
- $xtpl->assign("GRUPO", $horario_rs[$rs_i]["Grupo_desc"]." ".$horario_rs[$rs_i]["Carrera_prefijo"]);
- if($horario_rs[$rs_i]["Materia_desc"] != "")
- $xtpl->parse("main.hora_row.td.td_mihorario.texto");
- $rs_i++;
- }while($rs_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$rs_i-1]["Hora_inicio"])) == date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]);
-
- $xtpl->assign("SALON", $salon);
- $xtpl->parse("main.hora_row.td.td_mihorario");
- }else{
- if(!isset($spacerArr[$dia["Dia_id"]]) || $spacerArr[$dia["Dia_id"]] == 0)
- $xtpl->parse("main.hora_row.td.td_vacio");
- else
- $spacerArr[$dia["Dia_id"]]--;
- }
- $xtpl->parse("main.hora_row.td");
- }
- $xtpl->parse("main.hora_row");
- }
- }
- $xtpl->parse("main.logo");
- $stmt = $pdo->prepare('Select * from fs_tipohorario(NULL, NULL)');
- $stmt->execute();
- $tipo_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- foreach($tipo_rs as $tipo){
- $xtpl->assign("COLOR", $tipo["TipoHorario_color"]);
- $xtpl->assign("DESC", $tipo["TipoHorario_desc"]);
- $xtpl->assign("TOTAL", $total_tipo[$tipo["TipoHorario_id"]]);
- $xtpl->parse("main.tipo_row");
- }
- $xtpl->assign("COLOR", '#fff');
- $xtpl->assign("DESC", "Total de horas");
- $xtpl->assign("TOTAL", $total_tipo[1]+$total_tipo[2]+$total_tipo[3]);
- $xtpl->parse("main.tipo_row");
- $xtpl->parse("main");
- //$xtpl->out("main");
- $mpdf->WriteHTML($stylesheet);
- if(!isset($errorDesc))
- $mpdf->WriteHTML($xtpl->text("main"));
- else
- $mpdf->WriteHTML($errorDesc);
- $mpdf->Output("horariousuario.pdf", 'I');
- ?>
|