pdf_horariogrupo.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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_horariogrupo.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["grupo"])){
  26. header("Location: ".$pag."?error=0");
  27. exit();
  28. }
  29. $filter_grupo = filter_input(INPUT_POST, "grupo", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  30. if(isset($_POST["filter_fecha"]) && $_POST["filter_fecha"]!= "")
  31. $filter_fecha = fechaGuion(trim(filter_input(INPUT_POST, "filter_fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  32. $stmt = $pdo->prepare('Select * from fs_grupo(:grupo, :periodo)');
  33. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  34. $stmt->bindParam(":grupo", $filter_grupo);
  35. if(!$stmt->execute()){
  36. $errorDesc = "Ocurrió un error al cargar el grupo.";
  37. }
  38. $grupo_rs = $stmt->fetch();
  39. $stmt->closeCursor();
  40. //Obtiene horario del grupo
  41. $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, NULL, false)');
  42. $stmt->bindParam(":gpo", $filter_grupo);
  43. if(!$stmt->execute()){
  44. //header("Location: materias.php?error=2");
  45. $errorDesc = "Error al cargar el horario del grupo";
  46. print_r($stmt->errorInfo());
  47. exit();
  48. }
  49. $horario_rs = $stmt->fetchAll();
  50. $horaMin = horaMin($horario_rs);
  51. $horaMax = horaMax($horario_rs);
  52. $stmt->closeCursor();
  53. $stmt = $pdo->prepare('Select * from fs_dia(NULL)');
  54. if(!$stmt->execute()){
  55. echo "Error al obtener los días";
  56. print_r($stmt->errorInfo());
  57. }
  58. $dias_rs = $stmt->fetchAll();
  59. $stmt->closeCursor();
  60. //-----
  61. $mpdf = new \Mpdf\Mpdf([
  62. 'mode' => 'utf-8',
  63. 'format' => [215, 279],
  64. 'orientation' => 'P'
  65. ]);
  66. //$mpdf->SetDisplayMode('fullpage');
  67. $stylesheet = "<style>";
  68. $stylesheet .= file_get_contents('../../css/indivisa.css'); // external css
  69. $stylesheet .= file_get_contents('../css/horario_reporte.css'); // external css
  70. $stylesheet .= "</style>";
  71. //echo $stylesheet;
  72. $xtpl = new XTemplate('../tpl/horario_reporte.tpl.html');
  73. if($_SESSION["nivel_id"] == 1)
  74. $xtpl->assign("LEFT", "Grupo: ".$grupo_rs["Grupo_desc"]." ".$grupo_rs["Carrera_prefijo"]);
  75. else
  76. $xtpl->assign("LEFT", "Grupo: ".$grupo_rs["Grupo_desc"]." ".$grupo_rs["Carrera_desc"]);
  77. if(intval($grupo_rs["Grupo_semestre"]) > 0){
  78. if($_SESSION["nivel_id"] == 1)
  79. $xtpl->assign("RIGHT", "Semestre: ".$grupo_rs["Grupo_semestre"]);
  80. else
  81. $xtpl->assign("RIGHT", "Cuatrimestre: ".$grupo_rs["Grupo_semestre"]);
  82. }else
  83. $xtpl->assign("RIGHT", "Propedéutico");
  84. $xtpl->parse("main.top");
  85. foreach($dias_rs as $dia){
  86. $xtpl->assign("DIA", $dia["Dia_desc"]);
  87. $xtpl->parse("main.header");
  88. }
  89. $rs_i = 0;
  90. $spacerArr = array(1=>0,0,0,0,0,0);
  91. $pendiente = "<em>Pendiente</em>";
  92. $horas_dif = intval(date('H', strtotime($horaMax))) - intval(date('H', strtotime($horaMin)));
  93. $sub_prof_num = 0;
  94. $sub_num = 0;
  95. $tiene_submaterias = false;
  96. for($h = date('H', strtotime($horaMin)); $h <= date('H', strtotime($horaMax)); $h++){
  97. $xtpl->assign("HORA", date('H', strtotime($h.":00")));
  98. $xtpl->assign("FRACCIONES", FRACCION_HORA);
  99. $xtpl->parse("main.hora_row.hora");
  100. for($f = 0; $f < FRACCION_HORA; $f++){
  101. foreach($dias_rs as $dia){
  102. 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"]){
  103. if((isset($filter_fecha) && strtotime($filter_fecha) >= strtotime($horario_rs[$rs_i]["fecha_inicial"]) && strtotime($filter_fecha) <= strtotime($horario_rs[$rs_i]["fecha_final"]) ) || !isset($filter_fecha)){
  104. $size = $horario_rs[$rs_i]["Horario_duracion"]/(60/FRACCION_HORA);
  105. $spacerArr[$dia["Dia_id"]] = $size -1;
  106. $xtpl->assign("COLOR", '#e9e7e8');
  107. $xtpl->assign("DURACION_SIZE", $size);
  108. $xtpl->assign("MATERIA", $horario_rs[$rs_i]["Materia_desc"]);
  109. $xtpl->assign("HORA_I", substr($horario_rs[$rs_i]["Horario_hora"], 0, 5));
  110. $xtpl->assign("HORA_F", substr($horario_rs[$rs_i]["Horario_hora_final"], 0, 5));
  111. if($horario_rs[$rs_i]["Salon_desc"] != "")
  112. if($horario_rs[$rs_i]["Salon_desc_larga"] != "")
  113. $xtpl->assign("SALON", $horario_rs[$rs_i]["Salon_desc"]." [".$horario_rs[$rs_i]["Salon_desc_larga"]."]");
  114. else
  115. $xtpl->assign("SALON", $horario_rs[$rs_i]["Salon_desc"]);
  116. else{
  117. if($horario_rs[$rs_i]["TipoSubmateria_id"] == 0)
  118. $xtpl->assign("SALON", $pendiente);
  119. else
  120. $xtpl->assign("SALON", "*");
  121. }
  122. //----- Carga profesores ----
  123. if($horario_rs[$rs_i]["TipoSubmateria_id"] == 0){
  124. $stmt = $pdo->prepare('Select * from fs_profesorhorariogrupo(:id)');
  125. $stmt->bindParam(":id", $horario_rs[$rs_i]["HorarioGrupo_id"]);
  126. if(!$stmt->execute()){
  127. $t = $stmt->errorInfo();
  128. $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  129. break;
  130. }
  131. $profesores_rs = $stmt->fetchAll();
  132. $stmt->closeCursor();
  133. }else{//Con submaterias
  134. //----- Carga submaterias ----
  135. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupo(:id)');
  136. $stmt->bindParam(":id", $horario_rs[$rs_i]["HorarioGrupo_id"]);
  137. if(!$stmt->execute()){
  138. $t = $stmt->errorInfo();
  139. $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  140. break;
  141. }
  142. $submaterias_rs = $stmt->fetchAll();
  143. $stmt->closeCursor();
  144. $sub_prof_num = 0;
  145. $nombre_impreso = false;
  146. if(count($submaterias_rs) > 0){
  147. $tiene_submaterias = true;
  148. foreach($submaterias_rs as $submateria){
  149. $xtpl->assign("SUBMATERIA", $submateria["Submateria_desc"]);
  150. $xtpl->assign("DIA", diaNombre($submateria["Dia_id"]));
  151. //---
  152. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupoprofesor(:id,:sub)');
  153. $stmt->bindParam(":id", $horario_rs[$rs_i]["HorarioGrupo_id"]);
  154. $stmt->bindParam(":sub", $submateria["Submateria_id"]);
  155. if(!$stmt->execute()){
  156. $t = $stmt->errorInfo();
  157. $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  158. break;
  159. }
  160. $profesores_rs = $stmt->fetchAll();
  161. $stmt->closeCursor();
  162. $sub_prof_num += count($profesores_rs);
  163. if(isset($profesores_rs) && count($profesores_rs) > 0){
  164. $profesores_all = "";
  165. foreach($profesores_rs as $profesor){
  166. $prof_nombre = "&bull; ".$profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
  167. $profesores_all .= $prof_nombre."<br>";
  168. }
  169. $xtpl->assign("PROFESOR_SUB", $profesores_all);
  170. /*}else{
  171. $xtpl->assign("PROFESOR_SUB", $pendiente);
  172. }*/
  173. $xtpl->assign("SALON_SUB", $submateria["Salon_desc"]);
  174. $xtpl->parse("main.submaterias_block.row.submateria");
  175. if(!$nombre_impreso){
  176. $nombre_impreso = true;
  177. $xtpl->assign("MAT_ROWSPAN", count($submaterias_rs));
  178. $xtpl->parse("main.submaterias_block.row.materia");
  179. }
  180. $xtpl->parse("main.submaterias_block.row");
  181. }//solo si hay profesor
  182. }
  183. }
  184. unset($profesores_rs);
  185. }//fin con submaterias
  186. if(isset($profesores_rs) && count($profesores_rs) > 0){
  187. foreach($profesores_rs as $profesor){
  188. $prof_nombre = "&bull; ".$profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
  189. $xtpl->assign("PROFESOR", $prof_nombre);
  190. $xtpl->parse("main.hora_row.td.td_horario.profesor");
  191. }
  192. }else{
  193. if($horario_rs[$rs_i]["TipoSubmateria_id"] == 0){//no pinta maestros electivas o secuenciales
  194. $prof_nombre = $pendiente;
  195. $xtpl->assign("PROFESOR", $prof_nombre);
  196. $xtpl->parse("main.hora_row.td.td_horario.profesor");
  197. }
  198. }
  199. $xtpl->parse("main.hora_row.td.td_horario.hora");
  200. $xtpl->parse("main.hora_row.td.td_horario.texto");
  201. $xtpl->parse("main.hora_row.td.td_horario.spacer");
  202. $xtpl->parse("main.hora_row.td.td_horario");
  203. }else
  204. $xtpl->parse("main.hora_row.td.td_vacio");
  205. $rs_i++;
  206. }else{
  207. if(!isset($spacerArr[$dia["Dia_id"]]) || $spacerArr[$dia["Dia_id"]] == 0)
  208. $xtpl->parse("main.hora_row.td.td_vacio");
  209. else
  210. $spacerArr[$dia["Dia_id"]]--;
  211. }
  212. $xtpl->parse("main.hora_row.td");
  213. }
  214. $xtpl->parse("main.hora_row");
  215. }
  216. }
  217. if($tiene_submaterias){
  218. $xtpl->parse("main.submaterias_block");
  219. }
  220. $xtpl->parse("main");
  221. //$xtpl->out("main");
  222. $mpdf->WriteHTML($stylesheet);
  223. if(!isset($errorDesc))
  224. $mpdf->WriteHTML($xtpl->text("main"));
  225. else
  226. $mpdf->WriteHTML($errorDesc);
  227. $mpdf->Output("horariogrupo.pdf", 'I');
  228. ?>