pdf_horariosalon.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /* AJAX
  3. * Genera nombramientos en pdf
  4. * Recibe:
  5. * grupo
  6. * Return:
  7. * imprime pdf
  8. */
  9. setlocale(LC_TIME, 'es_MX.UTF-8');
  10. require_once("../../include/nocache.php");
  11. require_once("../../include/constantes.php");
  12. require_once("../../include/bd_pdo.php");
  13. require_once("../../include/util.php");
  14. require_once("../../classes/ValidaSesion.php");
  15. include_once('../../include/xTemplate/xtemplate.class.php'); // including mpdf.php
  16. include_once('../../include/mpdf/autoload.php'); // including mpdf.php
  17. $pag = "../reporte_salones.php";
  18. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  19. $objSesion = new ValidaSesion($pdo, 272, APSA);
  20. if(!$objSesion->tieneAcceso()){
  21. header("Location: ".$pag."?error=3");
  22. exit();
  23. }
  24. unset($objValida);
  25. if(!isset($_POST["id"]) || !isset($_POST["fecha"])){
  26. header("Location: ".$pag."?error=0");
  27. exit();
  28. }
  29. $id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  30. $fecha = trim(filter_input(INPUT_POST, "fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  31. //Obtiene horario del salon
  32. $stmt = $pdo->prepare('Select * from fs_horariosalon(:salon, :fecha)');
  33. $stmt->bindParam(":salon", $id);
  34. $stmt->bindParam(":fecha", $fecha);
  35. if(!$stmt->execute()){
  36. //header("Location: materias.php?error=2");
  37. $errorDesc = "Error al cargar el horario del salón";
  38. print_r($stmt->errorInfo());
  39. exit();
  40. }
  41. $horario_rs = $stmt->fetchAll();
  42. $horaMin = horaMin($horario_rs);
  43. $horaMax = horaMax($horario_rs);
  44. $stmt->closeCursor();
  45. $stmt = $pdo->prepare('Select * from fs_salon(:salon, NULL, 0, 1)');
  46. $stmt->bindParam(":salon", $id);
  47. if(!$stmt->execute()){
  48. $errorDesc = "Ocurrió un error al cargar el salón.";
  49. }
  50. $salon_rs = $stmt->fetch();
  51. $stmt->closeCursor();
  52. $stmt = $pdo->prepare('Select * from fs_dia(NULL)');
  53. if(!$stmt->execute()){
  54. echo "Error al obtener los días";
  55. print_r($stmt->errorInfo());
  56. }
  57. $dias_rs = $stmt->fetchAll();
  58. $stmt->closeCursor();
  59. //-----
  60. $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
  61. $fontDirs = $defaultConfig['fontDir'];
  62. $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
  63. $fontData = $defaultFontConfig['fontdata'];
  64. $mpdf = new \Mpdf\Mpdf([
  65. 'mode' => 'utf-8',
  66. 'format' => [215, 279],
  67. 'orientation' => 'P',
  68. 'fontDir' => array_merge($fontDirs, [
  69. __DIR__ . '/../../fonts/indivisaFont/ttf',
  70. ]),
  71. 'fontdata' => $fontData + [
  72. 'indivisa-display' => [
  73. 'R' => 'IndivisaDisplaySans-Regular.ttf',
  74. ],
  75. 'indivisa-title' => [
  76. 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
  77. ],
  78. 'indivisa-text' => [
  79. 'R' => 'IndivisaTextSans-Regular.ttf',
  80. ]
  81. ],
  82. 'default_font' => 'indivisa-text',
  83. ]);
  84. //$mpdf->SetDisplayMode('fullpage');
  85. $stylesheet = "<style>";
  86. $stylesheet .= file_get_contents('../../css/indivisa.css'); // external css
  87. $stylesheet .= file_get_contents('../css/mihorario_reporte.css'); // external css
  88. $stylesheet .= "</style>";
  89. //echo $stylesheet;
  90. $xtpl = new XTemplate('../tpl/horario_reporte.tpl.html');
  91. $salon = $salon_rs["Salon_desc"];
  92. if($salon_rs["Salon_desc_larga"] != "")
  93. $salon.= " (".$salon_rs["Salon_desc_larga"].")";
  94. $xtpl->assign("LEFT", "Salon: ".$salon);
  95. $xtpl->parse("main.top");
  96. foreach($dias_rs as $dia){
  97. $xtpl->assign("DIA", $dia["Dia_desc"]);
  98. $xtpl->parse("main.header");
  99. }
  100. $rs_i = 0;
  101. $spacerArr = array(1=>0,0,0,0,0,0);
  102. $pendiente = "<em>Pendiente</em>";
  103. $horas_dif = intval(date('H', strtotime($horaMax))) - intval(date('H', strtotime($horaMin)));
  104. $sub_prof_num = 0;
  105. $sub_num = 0;
  106. $tiene_submaterias = false;
  107. for($h = date('H', strtotime($horaMin)); $h <= date('H', strtotime($horaMax)) && $h < HORA_FINAL; $h++){
  108. $xtpl->assign("HORA", date('H', strtotime($h.":00")));
  109. $xtpl->assign("FRACCIONES", FRACCION_HORA);
  110. $xtpl->parse("main.hora_row.hora");
  111. for($f = 0; $f < FRACCION_HORA; $f++){
  112. foreach($dias_rs as $dia){
  113. 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"]){
  114. $size = $horario_rs[$rs_i]["Horario_duracion"]/(60/FRACCION_HORA);
  115. $spacerArr[$dia["Dia_id"]] = $size -1;
  116. $xtpl->assign("COLOR", '#7FD6F7');
  117. $xtpl->assign("DURACION_SIZE", $size);
  118. $xtpl->assign("SALON", $salon);
  119. /*
  120. if($horario_rs[$rs_i]["Salon_desc"] != ""){
  121. if($horario_rs[$rs_i]["Salon_desc_larga"] != "")
  122. $xtpl->assign("SALON", $horario_rs[$rs_i]["Salon_desc"]." [".$horario_rs[$rs_i]["Salon_desc_larga"]."]");
  123. else
  124. $xtpl->assign("SALON", $horario_rs[$rs_i]["Salon_desc"]);
  125. }else{
  126. if($horario_rs[$rs_i]["TipoSubmateria_id"] == 0)
  127. $xtpl->assign("SALON", $pendiente);
  128. else
  129. $xtpl->assign("SALON", "*");
  130. }*/
  131. $tmp_i = $rs_i;
  132. //busca todos los profesores
  133. $profesores = array();
  134. do{
  135. $new = $horario_rs[$tmp_i]["Usuario_nombre"]." ".$horario_rs[$tmp_i]["Usuario_apellidos"];
  136. if(!empty($horario_rs[$tmp_i]["Usuario_nombre"]) && !in_array($new, $profesores)){
  137. $profesores[] = $new;
  138. $xtpl->assign("PROFESOR", "&bull; ".$new);
  139. $xtpl->parse("main.hora_row.td.td_horario.profesor");
  140. }
  141. $tmp_i++;
  142. }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"]);
  143. //concatena nombres de materias relacionadas
  144. do{
  145. $xtpl->assign("MATERIA", $horario_rs[$rs_i]["Materia_desc"]." (".$horario_rs[$rs_i]["Grupo_desc"]." ".$horario_rs[$rs_i]["Carrera_prefijo"].")");
  146. if($horario_rs[$rs_i]["Materia_desc"] != "")
  147. $xtpl->parse("main.hora_row.td.td_horario.texto");
  148. $rs_i++;
  149. }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"]);
  150. $xtpl->parse("main.hora_row.td.td_horario.spacer");
  151. $xtpl->parse("main.hora_row.td.td_horario");
  152. }else{
  153. if(!isset($spacerArr[$dia["Dia_id"]]) || $spacerArr[$dia["Dia_id"]] == 0)
  154. $xtpl->parse("main.hora_row.td.td_vacio");
  155. else
  156. $spacerArr[$dia["Dia_id"]]--;
  157. }
  158. $xtpl->parse("main.hora_row.td");
  159. }
  160. $xtpl->parse("main.hora_row");
  161. }
  162. }
  163. if($tiene_submaterias){
  164. $xtpl->parse("main.submaterias_block");
  165. }
  166. $xtpl->parse("main");
  167. //$xtpl->out("main");
  168. $mpdf->SHYlang = 'es';
  169. $mpdf-> SetTitle('Ocupación de salones -' . $salon);
  170. $mpdf-> SetAuthor('Facultad de Ingeniería. © Universidad La Salle A.C. '.date("Y").' Todos los derechos Reservados.');
  171. $mpdf->SetHTMLHeader('<img src="../../img/logopdf.png" width="40mm" style="float:right">');//se pone como fondo
  172. $mpdf->WriteHTML($stylesheet);
  173. if(!isset($errorDesc))
  174. $mpdf->WriteHTML($xtpl->text("main"));
  175. else
  176. $mpdf->WriteHTML($errorDesc);
  177. $mpdf->Output("horariogrupo.pdf", 'I');
  178. ?>