consulta_horario.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <?php
  2. require_once("../include/constantes.php");
  3. require_once("../include/util.php");
  4. require_once("../include/bd_pdo.php");
  5. require_once("../include/xTemplate/xtemplate.class.php");
  6. if(isset($_GET["nivel"])){
  7. $nivel = filter_input(INPUT_GET, "nivel", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  8. $stmt = $pdo->prepare('Select "Periodo_id", "Periodo_desc" from "Periodo" WHERE "Nivel_id" = :nivel AND "EstadoPeriodo_id" != 2 AND "Periodo_calendario_activo" = true');
  9. $stmt->bindParam(":nivel", $nivel);
  10. if(!$stmt->execute()){
  11. echo "Error al obtener los periodos activos.";
  12. exit();
  13. }else{
  14. $periodo_rs = $stmt->fetch();
  15. if(!is_array($periodo_rs) || count($periodo_rs) == 0){
  16. unset($periodo_rs);
  17. }
  18. }
  19. $stmt->closeCursor();
  20. //Obtiene grupos del periodo
  21. if(isset($periodo_rs)){
  22. $stmt = $pdo->prepare('Select * from fs_grupo(NULL, :periodo)');
  23. $stmt->bindParam(":periodo", $periodo_rs["Periodo_id"]);
  24. if(!$stmt->execute()){
  25. echo "Error al obtener los grupos.";
  26. exit();
  27. }else{
  28. $grupos_rs = $stmt->fetchAll();
  29. }
  30. $stmt->closeCursor();
  31. }
  32. $pendiente = "<em>Pendiente</em>";
  33. if(isset($periodo_rs) && isset($_POST["grupo"]) && is_numeric($_POST["grupo"]) && $_POST["grupo"] != ""){
  34. $filter_grupo = filter_input(INPUT_POST, "grupo", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  35. if(isset($_POST["filter_fecha"]) && $_POST["filter_fecha"]!= "")
  36. $filter_fecha = fechaGuion(trim(filter_input(INPUT_POST, "filter_fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  37. $stmt = $pdo->prepare('Select * from fs_grupo(:grupo, :periodo)');
  38. $stmt->bindParam(":periodo", $periodo_rs["Periodo_id"]);
  39. $stmt->bindParam(":grupo", $filter_grupo);
  40. if(!$stmt->execute()){
  41. $errorDesc = "Ocurrió un error al cargar el grupo.";
  42. }else{
  43. $grupo_actual_rs = $stmt->fetch();
  44. if(!is_array($grupo_actual_rs) || count($grupo_actual_rs) == 0){
  45. $stmt->closeCursor();
  46. header("Location: consulta_horario.php");
  47. exit();
  48. }
  49. }
  50. $stmt->closeCursor();
  51. //Obtiene horario del grupo
  52. $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, NULL, false)');
  53. $stmt->bindParam(":gpo", $filter_grupo);
  54. if(!$stmt->execute()){
  55. //header("Location: materias.php?error=2");
  56. $errorDesc = "Error al cargar el horario del grupo";
  57. print_r($stmt->errorInfo());
  58. exit();
  59. }else{
  60. $horario_rs = $stmt->fetchAll();
  61. $horaMin = horaMin($horario_rs);
  62. $horaMax = horaMax($horario_rs);
  63. }
  64. $stmt->closeCursor();
  65. }
  66. }else{//no existe nivel
  67. $stmt = $pdo->prepare('Select * from fs_nivel(NULL)');
  68. if(!$stmt->execute()){
  69. echo "Error al obtener los niveles.";
  70. exit();
  71. }else{
  72. $nivel_rs = $stmt->fetchAll();
  73. }
  74. $stmt->closeCursor();
  75. }
  76. ?>
  77. <!DOCTYPE html>
  78. <html lang="es" prefix="og: http://ogp.me/ns#">
  79. <head>
  80. <title>Horarios - Facultad de Ingeniería</title>
  81. <meta charset="utf-8">
  82. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  83. <link rel="icon" type="image/png" href="../img/favicon.png" />
  84. <link rel="stylesheet" href="../css/bootstrap-ulsa.min.css" type="text/css">
  85. <link rel="stylesheet" href="../css/indivisa.css" type="text/css">
  86. <link rel="stylesheet" href="../css/sgi.css?rand=<?php echo rand();?>" type="text/css">
  87. <link rel="stylesheet" href="../css/fa_all.css" type="text/css">
  88. <link rel="stylesheet" href="./css/horario_alumnos.css" type="text/css">
  89. <script src="../js/util.js"></script>
  90. </head>
  91. <body>
  92. <div>
  93. <main class="container content marco">
  94. <img src="img/horarios.jpg" alt="horarios" class="img-fluid"/>
  95. <?php if(!isset($_GET["nivel"])){ //no existe el nivel?>
  96. <!-- Filtro -->
  97. <div class="row justify-content-md-center my-3" style="height: 50px;">
  98. <div class="col-12 col-md-8">
  99. <?php if(isset($nivel_rs)){ ?>
  100. <form action="consulta_horario.php" method="get">
  101. <div class="form-group row">
  102. <label for="filter_nivel" class="col-3 col-form-label text-right font-weight-bold">Nivel</label>
  103. <div class="col-6">
  104. <select id="filter_nivel" name="nivel" class="form-control">
  105. <option value="">Selecciona un nivel</option>
  106. <?php foreach($nivel_rs as $nivel) { ?>
  107. <option value="<?php echo $nivel["Nivel_id"];?>" ><?php echo $nivel["Nivel_desc"];?></option>
  108. <?php } ?>
  109. </select>
  110. </div>
  111. <div class="col-3">
  112. <button type="submit" class="btn btn-outline-primary"><?php echo $ICO["buscar"]; ?> Ver grupos</button>
  113. </div>
  114. </div>
  115. </form>
  116. <?php }else{//fin hay periodos con horario para mostrar ?>
  117. <h3>No hay horarios para mostrar.</h3>
  118. <?php } ?>
  119. </div>
  120. </div>
  121. <?php }else { //si existe
  122. if($nivel == 1) $nivel_nombre = "Licenciatura";
  123. else $nivel_nombre = "Posgrado";
  124. ?>
  125. <h1 class="subtitle">Horarios de <?php echo $nivel_nombre;?> <?php if(isset($periodo_rs)){?> <small><span class="fas fa-angle-double-right"></span> <?php echo $periodo_rs["Periodo_desc"];?></small><?php } ?></h1>
  126. <!-- Filtro -->
  127. <div class="row justify-content-md-center my-3" style="height: 50px;">
  128. <div class="col-12 col-md-8">
  129. <?php if(isset($periodo_rs)){ ?>
  130. <form action="consulta_horario.php?nivel=<?php echo $nivel?>" method="post">
  131. <div class="form-group row">
  132. <label for="filter_grupo" class="col-3 col-form-label text-right font-weight-bold">Grupo</label>
  133. <div class="col-6">
  134. <select id="filter_grupo" name="grupo" class="form-control">
  135. <option value="">Selecciona un grupo</option>
  136. <?php foreach($grupos_rs as $grupo) {
  137. $nombre = "";
  138. if($nivel == 1)
  139. $nombre = $grupo["Grupo_desc"]." ".$grupo["Carrera_prefijo"];
  140. else
  141. $nombre = $grupo["Grupo_desc"]." - ".$grupo["Carrera_desc"];
  142. ?>
  143. <option value="<?php echo $grupo["Grupo_id"];?>" <?php if(isset($filter_grupo) && $filter_grupo == $grupo["Grupo_id"]){echo "selected='selected'";}?> ><?php echo $nombre;?></option>
  144. <?php } ?>
  145. </select>
  146. </div>
  147. <div class="col-3">
  148. <button type="submit" class="btn btn-outline-primary"><?php echo $ICO["buscar"]; ?> Ver horario</button>
  149. </div>
  150. </div>
  151. </form>
  152. <?php }else{//fin hay periodos con horario para mostrar ?>
  153. <h3>No hay horarios para mostrar.</h3>
  154. <?php } ?>
  155. </div>
  156. </div>
  157. <?php
  158. if(isset($grupo_actual_rs) && isset($horario_rs)){//Si existe grupo seleccionado carga horario
  159. ?>
  160. <?php
  161. $stmt = $pdo->prepare('Select * from fs_dia(NULL)');
  162. if(!$stmt->execute()){
  163. echo "Error al obtener los días";
  164. print_r($stmt->errorInfo());
  165. }
  166. $dias_rs = $stmt->fetchAll();
  167. $stmt->closeCursor();
  168. $stmt = null;
  169. $horas_dif = intval(date('H', strtotime($horaMax))) - intval(date('H', strtotime($horaMin)));
  170. $hora_ini = date('H', strtotime($horaMin));
  171. $hora_fin = date('H', strtotime($horaMax));
  172. if(intval(date('i', strtotime($horaMax))) != 0)
  173. $hora_fin++;
  174. /* Definidas en constantes.php
  175. HORA_INICIO = 7;
  176. HORA_FINAL = 22;
  177. FRACCION_HORA = 4;*/
  178. ?>
  179. <ul class="nav nav-tabs d-print-none mb-4" id="myTab" role="tablist">
  180. <li class="nav-item">
  181. <a class="nav-link active" id="tab1-tab" data-toggle="tab" href="#tab1" role="tab" aria-controls="calendario" aria-selected="true">Horario</a>
  182. </li>
  183. <li class="nav-item">
  184. <a class="nav-link" id="tab2-tab" data-toggle="tab" href="#tab2" role="tab" aria-controls="lista" aria-selected="false">Listado por materia</a>
  185. </li>
  186. </ul>
  187. <div class="tab-content" id="horariosTabContent">
  188. <div class="tab-pane fade show active" id="tab1" role="tabpanel" aria-labelledby="tab1-tab">
  189. <?php// ---- Como horario ---- ?>
  190. <div class="row justify-content-md-center">
  191. <div class="col-md-auto">
  192. <table class="table table-sm table-responsive table-borderless calendario" id="tabla-horario" data-hora-inicio="<?php echo $hora_ini;?>" data-fracciones = "<?php echo FRACCION_HORA; ?>">
  193. <thead class="thead-dark">
  194. <tr>
  195. <th>Hora</th>
  196. <?php foreach($dias_rs as $dia){
  197. echo "<th data='dia_".$dia["Dia_id"]."'>".$dia["Dia_desc"]."</th>";
  198. } ?>
  199. </tr>
  200. </thead>
  201. <tbody id="calendario-body">
  202. <?php
  203. $biccell = false;
  204. //for($h = HORA_INICIO, $i=0; $h < HORA_FINAL; $h++, $i++){
  205. for($h = $hora_ini, $i=0; $h < $hora_fin; $h++, $i++){
  206. ?>
  207. <tr>
  208. <td data-hora="<?php echo $h;?>" data-index="<?php echo $i;?>" class="hora" ><?php echo $h;?>:00 </td>
  209. <?php
  210. if(!$biccell){
  211. $biccell = true;
  212. ?>
  213. <td colspan='<?php echo count($dias_rs); ?>' rowspan='<?php echo ($hora_fin-$hora_ini)+1; ?>'>
  214. <div class='area-horario'>
  215. <table class="table table-borderless ">
  216. <tbody>
  217. <?php
  218. for($h2 = $hora_ini; $h2 < $hora_fin; $h2++){
  219. for($f = 0; $f < FRACCION_HORA; $f++){
  220. echo "<tr class='dia'>";
  221. foreach($dias_rs as $dia){
  222. echo "<td title='".$h2.":".sprintf("%02d", ($f*(60/FRACCION_HORA)))."' data-dia='".$dia["Dia_id"]."' data-hora='".$h2."' data-fraccion='".($f*(60/FRACCION_HORA))."' class='crea-horario fraccion '></td>";
  223. }
  224. echo "</tr>";
  225. }
  226. }
  227. ?>
  228. </tbody>
  229. </table>
  230. <div id="bloque-horarios"></div>
  231. </div>
  232. </td>
  233. <?php
  234. } ?>
  235. </tr>
  236. <?php } ?>
  237. </tbody>
  238. </table>
  239. </div>
  240. </div>
  241. </div>
  242. <div class="tab-pane fade" id="tab2" role="tabpanel" aria-labelledby="tab2-tab">
  243. <?php
  244. // --- Como listado ----
  245. $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, NULL, false) order by "Materia_desc", "Dia_id", "Horario_hora"');
  246. $stmt->bindParam(":gpo", $filter_grupo);
  247. if(!$stmt->execute()){
  248. //header("Location: materias.php?error=2");
  249. $errorDesc = "Error al cargar el horario del grupo";
  250. print_r($stmt->errorInfo());
  251. exit();
  252. }
  253. $horario_materia_rs = $stmt->fetchAll();
  254. $stmt->closeCursor();
  255. $materia_old = -1;
  256. $xtpl = new XTemplate('./tpl/horariolista_reporte.tpl.html');
  257. foreach($horario_materia_rs as $horario){
  258. if(intval($horario["Materia_id"]) != $materia_old && $materia_old != -1){
  259. if((isset($filter_fecha) && strtotime($filter_fecha) >= strtotime($horario["fecha_inicial"]) && strtotime($filter_fecha) <= strtotime($horario["fecha_final"]) ) || !isset($filter_fecha)){
  260. $xtpl->parse("main.table");
  261. }
  262. }
  263. $materia_old = intval($horario["Materia_id"]);
  264. $xtpl->assign("MATERIA", $horario["Materia_desc"]);
  265. $xtpl->assign("CLAVE", $horario["Materia_clave"]);
  266. //----- Carga profesores ----
  267. if($horario["TipoSubmateria_id"] == 0){
  268. $stmt = $pdo->prepare('Select * from fs_profesorhorariogrupo(:id)');
  269. $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
  270. if(!$stmt->execute()){
  271. $t = $stmt->errorInfo();
  272. $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  273. break;
  274. }
  275. $profesores_rs = $stmt->fetchAll();
  276. $stmt->closeCursor();
  277. $prof_nombre = "";
  278. if(isset($profesores_rs) && count($profesores_rs) > 0){
  279. $profesores_all = "";
  280. foreach($profesores_rs as $profesor){
  281. $prof_nombre = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
  282. $profesores_all .= $prof_nombre."<br>";
  283. }
  284. }else{
  285. $profesores_all = $pendiente;
  286. }
  287. $xtpl->assign("PROFESOR", $profesores_all);
  288. }else{//Con submaterias
  289. //----- Carga submaterias ----
  290. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupo(:id)');
  291. $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
  292. if(!$stmt->execute()){
  293. $t = $stmt->errorInfo();
  294. $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  295. break;
  296. }
  297. $submaterias_rs = $stmt->fetchAll();
  298. $stmt->closeCursor();
  299. $sub_prof_num = 0;
  300. $profesores_all = "";
  301. if(count($submaterias_rs) > 0){
  302. foreach($submaterias_rs as $submateria){
  303. //---
  304. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupoprofesor(:id,:sub)');
  305. $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
  306. $stmt->bindParam(":sub", $submateria["Submateria_id"]);
  307. if(!$stmt->execute()){
  308. $t = $stmt->errorInfo();
  309. $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  310. break;
  311. }
  312. $profesores_rs = $stmt->fetchAll();
  313. $stmt->closeCursor();
  314. $sub_prof_num += count($profesores_rs);
  315. if(isset($profesores_rs) && count($profesores_rs) > 0){
  316. foreach($profesores_rs as $profesor){
  317. $prof_nombre = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
  318. $profesores_all .= $prof_nombre."<br>";
  319. }
  320. //$xtpl->assign("PROFESOR", $profesores_all);
  321. }/*else{
  322. $xtpl->assign("PROFESOR", $pendiente);
  323. }*/
  324. }
  325. if($sub_prof_num > 0)
  326. $xtpl->assign("PROFESOR", $profesores_all);
  327. else
  328. $xtpl->assign("PROFESOR", $pendiente);
  329. }
  330. unset($profesores_rs);
  331. }//fin con submaterias
  332. $xtpl->assign("DIA", ucfirst(diaNombre($horario["Dia_id"])));
  333. $xtpl->assign("HORAI", date('H:i', strtotime($horario["Horario_hora"])));
  334. $xtpl->assign("HORAF", date('H:i', strtotime($horario["Horario_hora_final"])));
  335. if($horario["Salon_desc"]!= ""){
  336. if($horario["Salon_desc_larga"] != "")
  337. $xtpl->assign("SALON", $horario["Salon_desc"]." (".$horario["Salon_desc_larga"].")");
  338. else
  339. $xtpl->assign("SALON", $horario["Salon_desc"]);
  340. }else
  341. $xtpl->assign("SALON", $pendiente);
  342. $xtpl->parse("main.table.row");
  343. }//for each materias
  344. if($materia_old != -1){
  345. if((isset($filter_fecha) && strtotime($filter_fecha) >= strtotime($horario["fecha_inicial"]) && strtotime($filter_fecha) <= strtotime($horario["fecha_final"]) ) || !isset($filter_fecha))
  346. $xtpl->parse("main.table");
  347. }
  348. $xtpl->parse("main");
  349. $xtpl->out("main");
  350. ?>
  351. </div>
  352. </div><!-- End tabs-->
  353. <div class="row justify-content-md-center mt-4" id="electivasBlock">
  354. <div class="col-md-auto">
  355. <h3>Electivas</h3>
  356. <table class="table table-sm table-hover table-responsive text-80" id="tabla-horario" data-hora-inicio="<?php echo $hora_ini;?>" data-fracciones = "<?php echo FRACCION_HORA; ?>">
  357. <thead class="thead-light">
  358. <tr><th scope="col">Materia</th><th scope="col">Horario</th><th scope="col">Profesores</th><th scope="col">Salón</th></tr>
  359. </thead>
  360. <tbody>
  361. <?php
  362. foreach($horario_rs as $horario){
  363. if($horario["TipoSubmateria_id"] != 0){
  364. //----- Carga submaterias ----
  365. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupo(:id)');
  366. $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
  367. if(!$stmt->execute()){
  368. $t = $stmt->errorInfo();
  369. $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  370. break;
  371. }
  372. $submaterias_rs = $stmt->fetchAll();
  373. $stmt->closeCursor();
  374. $sub_prof_num = 0;
  375. $nombre_impreso = false;
  376. if(count($submaterias_rs) > 0){
  377. $tiene_submaterias = true;
  378. foreach($submaterias_rs as $submateria){
  379. $submateria_text = $submateria["Submateria_desc"];
  380. $dia_hora_text = ucfirst(diaNombre($submateria["Dia_id"]))." ".date('H:i', strtotime($horario["Horario_hora"]));
  381. $profesores_all = "";
  382. $salon_text = "";
  383. //---
  384. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupoprofesor(:id,:sub)');
  385. $stmt->bindParam(":id",$horario["HorarioGrupo_id"]);
  386. $stmt->bindParam(":sub", $submateria["Submateria_id"]);
  387. if(!$stmt->execute()){
  388. $t = $stmt->errorInfo();
  389. $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  390. break;
  391. }
  392. $profesores_rs = $stmt->fetchAll();
  393. $stmt->closeCursor();
  394. $sub_prof_num += count($profesores_rs);
  395. if(isset($profesores_rs) && count($profesores_rs) > 0){
  396. foreach($profesores_rs as $profesor){
  397. $prof_nombre = $ICO["profesor"].$profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
  398. $profesores_all .= $prof_nombre."<br>";
  399. }
  400. //$xtpl->assign("PROFESOR_SUB", $profesores_all);
  401. if($submateria["Salon_desc"]){
  402. $salon_text = $submateria["Salon_desc"];
  403. }else{
  404. $salon_text = $pendiente;
  405. }
  406. ?>
  407. <tr>
  408. <td class="align-middle"><?php echo $submateria_text;?> </td>
  409. <td class="text-center align-middle"><?php echo $dia_hora_text;?></td>
  410. <td class="align-middle"><?php echo $profesores_all;?></td>
  411. <td class="text-center align-middle"><?php echo $salon_text;?></td>
  412. </tr>
  413. <?php
  414. //$xtpl->parse("main.submaterias_block.row");
  415. }//se pinta sólo si tiene profesor
  416. }
  417. }//hay submaterias
  418. }//fin if
  419. }
  420. unset($profesores_rs);
  421. ?>
  422. </tbody>
  423. </table>
  424. </div>
  425. </div>
  426. <?php }//end if existe grupo_actual_rs ?>
  427. <?php }//hay nivel ?>
  428. </main>
  429. <script src="../js/jquery.min.js"></script>
  430. <script src="../js/bootstrap/popper.min.js"></script>
  431. <script src="../js/bootstrap/bootstrap.min.js"></script>
  432. <?php if(isset($grupo_actual_rs)){ ?>
  433. <script>
  434. var _w = 208, _h = 25;//tamaño de bloques
  435. var _tab_size = 25; //espaciado por cada elemento que colisiona
  436. var _frac = parseInt($('#tabla-horario').data('fracciones'));
  437. var _reloadOnClose = false;
  438. var id_obj = 0; //id de objeto actual
  439. var _hora_min = parseInt($('#tabla-horario').data('hora-inicio'));
  440. var clasesObj = [];
  441. //al imprimir pone horarios lado a lado, sólo soporta 2
  442. function imprime(){
  443. _tab_size = _w/2;
  444. loadHorario();
  445. setTimeout(function() {
  446. window.print()
  447. }, 250);
  448. setTimeout(function() {
  449. _tab_size = 25;
  450. loadHorario();
  451. }, 500);
  452. //window.print();
  453. }
  454. </script>
  455. <script src="./js/horario.js"></script>
  456. <script src="./js/consulta_horario.js"></script>
  457. <?php } ?>
  458. </body>
  459. </html>