123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- /* AJAX
- * Genera nombramientos en pdf
- * Recibe:
- * grupo
- * 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
- $pag = "../reporte_salones.php";
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, 272, APSA);
- if(!$objSesion->tieneAcceso()){
- header("Location: ".$pag."?error=3");
- exit();
- }
- unset($objValida);
- if(!isset($_POST["id"]) || !isset($_POST["fecha"])){
- header("Location: ".$pag."?error=0");
- exit();
- }
- $id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $fecha = trim(filter_input(INPUT_POST, "fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
- //Obtiene horario del salon
- $stmt = $pdo->prepare('Select * from fs_horariosalon(:salon, :fecha)');
- $stmt->bindParam(":salon", $id);
- $stmt->bindParam(":fecha", $fecha);
- if(!$stmt->execute()){
- //header("Location: materias.php?error=2");
- $errorDesc = "Error al cargar el horario del salón";
- print_r($stmt->errorInfo());
- exit();
- }
- $horario_rs = $stmt->fetchAll();
- $horaMin = horaMin($horario_rs);
- $horaMax = horaMax($horario_rs);
- $stmt->closeCursor();
- $stmt = $pdo->prepare('Select * from fs_salon(:salon, NULL, 0, 1)');
- $stmt->bindParam(":salon", $id);
- if(!$stmt->execute()){
- $errorDesc = "Ocurrió un error al cargar el salón.";
- }
- $salon_rs = $stmt->fetch();
- $stmt->closeCursor();
- $stmt = $pdo->prepare('Select * from fs_dia(NULL)');
- if(!$stmt->execute()){
- echo "Error al obtener los días";
- print_r($stmt->errorInfo());
- }
- $dias_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- //-----
- $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
- $fontDirs = $defaultConfig['fontDir'];
- $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
- $fontData = $defaultFontConfig['fontdata'];
- $mpdf = new \Mpdf\Mpdf([
- 'mode' => 'utf-8',
- 'format' => [215, 279],
- 'orientation' => 'P',
- 'fontDir' => array_merge($fontDirs, [
- __DIR__ . '/../../fonts/indivisaFont/ttf',
- ]),
- 'fontdata' => $fontData + [
- 'indivisa-display' => [
- 'R' => 'IndivisaDisplaySans-Regular.ttf',
- ],
- 'indivisa-title' => [
- 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
- ],
- 'indivisa-text' => [
- 'R' => 'IndivisaTextSans-Regular.ttf',
- ]
- ],
- 'default_font' => 'indivisa-text',
- ]);
- //$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/horario_reporte.tpl.html');
- $salon = $salon_rs["Salon_desc"];
- if($salon_rs["Salon_desc_larga"] != "")
- $salon.= " (".$salon_rs["Salon_desc_larga"].")";
- $xtpl->assign("LEFT", "Salon: ".$salon);
- $xtpl->parse("main.top");
- 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);
- $pendiente = "<em>Pendiente</em>";
- $horas_dif = intval(date('H', strtotime($horaMax))) - intval(date('H', strtotime($horaMin)));
- $sub_prof_num = 0;
- $sub_num = 0;
- $tiene_submaterias = false;
- for($h = date('H', strtotime($horaMin)); $h <= date('H', strtotime($horaMax)) && $h < HORA_FINAL; $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]["Horario_hora"])) == date('H:i', strtotime($h.":".($f * (60/FRACCION_HORA)))) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]){
- $size = $horario_rs[$rs_i]["Horario_duracion"]/(60/FRACCION_HORA);
- $spacerArr[$dia["Dia_id"]] = $size -1;
- $xtpl->assign("COLOR", '#7FD6F7');
- $xtpl->assign("DURACION_SIZE", $size);
- $xtpl->assign("SALON", $salon);
- /*
- if($horario_rs[$rs_i]["Salon_desc"] != ""){
- if($horario_rs[$rs_i]["Salon_desc_larga"] != "")
- $xtpl->assign("SALON", $horario_rs[$rs_i]["Salon_desc"]." [".$horario_rs[$rs_i]["Salon_desc_larga"]."]");
- else
- $xtpl->assign("SALON", $horario_rs[$rs_i]["Salon_desc"]);
- }else{
- if($horario_rs[$rs_i]["TipoSubmateria_id"] == 0)
- $xtpl->assign("SALON", $pendiente);
- else
- $xtpl->assign("SALON", "*");
- }*/
- $tmp_i = $rs_i;
- //busca todos los profesores
- $profesores = array();
- do{
- $new = $horario_rs[$tmp_i]["Usuario_nombre"]." ".$horario_rs[$tmp_i]["Usuario_apellidos"];
- if(!empty($horario_rs[$tmp_i]["Usuario_nombre"]) && !in_array($new, $profesores)){
- $profesores[] = $new;
- $xtpl->assign("PROFESOR", "• ".$new);
- $xtpl->parse("main.hora_row.td.td_horario.profesor");
- }
- $tmp_i++;
- }while($tmp_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$tmp_i]["Horario_hora"])) == date('H:i', strtotime($h.":".($f * (60/FRACCION_HORA)))) && $horario_rs[$tmp_i]["Dia_id"] == $dia["Dia_id"]);
- //concatena nombres de materias relacionadas
- do{
- $xtpl->assign("MATERIA", $horario_rs[$rs_i]["Materia_desc"]." (".$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_horario.texto");
- $rs_i++;
- }while($rs_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$rs_i-1]["Horario_hora"])) == date('H:i', strtotime($horario_rs[$rs_i]["Horario_hora"])) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]);
- $xtpl->parse("main.hora_row.td.td_horario.spacer");
- $xtpl->parse("main.hora_row.td.td_horario");
- }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");
- }
- }
- if($tiene_submaterias){
- $xtpl->parse("main.submaterias_block");
- }
- $xtpl->parse("main");
- //$xtpl->out("main");
- $mpdf->SHYlang = 'es';
- $mpdf-> SetTitle('Ocupación de salones -' . $salon);
- $mpdf-> SetAuthor('Facultad de Ingeniería. © Universidad La Salle A.C. '.date("Y").' Todos los derechos Reservados.');
- $mpdf->SetHTMLHeader('<img src="../../img/logopdf.png" width="40mm" style="float:right">');//se pone como fondo
- $mpdf->WriteHTML($stylesheet);
- if(!isset($errorDesc))
- $mpdf->WriteHTML($xtpl->text("main"));
- else
- $mpdf->WriteHTML($errorDesc);
- $mpdf->Output("horariogrupo.pdf", 'I');
- ?>
|