reposicion_insert.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /*
  3. * Inserta reposición
  4. */
  5. $pag = "../reposiciones_crear.php";
  6. $ruta = "../";
  7. require_once "../class/c_login.php";
  8. // check if the session is started
  9. if (!isset($_SESSION['user']))
  10. die('No se ha iniciado sesión');
  11. $user = unserialize($_SESSION['user']);
  12. //$user->access();
  13. $duracion_id = filter_input(INPUT_POST, "duracion", FILTER_SANITIZE_NUMBER_INT); //Id reposicion
  14. $bloque = filter_input(INPUT_POST, "bloque", FILTER_SANITIZE_NUMBER_INT); //
  15. $ciclo = filter_input(INPUT_POST, "ciclo", FILTER_SANITIZE_NUMBER_INT); //
  16. $fecha_falta = trim(htmlspecialchars($_POST["fecha_falta"], ENT_QUOTES, "UTF-8")); //limpia texto
  17. $fecha = trim(htmlspecialchars($_POST["fecha_inicial"], ENT_QUOTES, "UTF-8")); //limpia texto
  18. $fecha_cambio = trim(htmlspecialchars($_POST["fecha_cambio"], ENT_QUOTES, "UTF-8")); //limpia texto
  19. $hora_ini = filter_input(INPUT_POST, "hora_ini", FILTER_SANITIZE_NUMBER_INT); //limpia texto
  20. $min_ini = filter_input(INPUT_POST, "min_ini", FILTER_SANITIZE_NUMBER_INT); //limpia texto
  21. $hor = filter_input(INPUT_POST, "horario", FILTER_SANITIZE_NUMBER_INT); //limpia texto
  22. $alumnos = filter_input(INPUT_POST, "alumnos", FILTER_SANITIZE_NUMBER_INT); //limpia texto
  23. $tipo = filter_input(INPUT_POST, "tipo", FILTER_SANITIZE_NUMBER_INT); //1 Repo , 0 Cambio
  24. $aula = filter_input(INPUT_POST, "aula", FILTER_SANITIZE_NUMBER_INT); //1 regular , 2 sala computo, 3 otro facultad
  25. if (empty($_POST["prof"]))
  26. $prof = $user["id"];
  27. else
  28. $prof = filter_input(INPUT_POST, "prof", FILTER_SANITIZE_NUMBER_INT); //limpia texto
  29. //if(isset($_POST["salon"]) && $_POST["salon"] != "")
  30. //$salon = trim(filter_input(INPUT_POST, "salon", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  31. $comentario = trim(htmlspecialchars($_POST["comentario"], ENT_QUOTES, "UTF-8")); //limpia texto
  32. $duracion_rs = $db->querySingle("select * from duracion where duracion_id = :id", [":id" => $duracion_id]);
  33. $duracion_tiempo = $duracion_rs["duracion_interval"];
  34. //-- Obtiene datos de horario regular de clase
  35. $horario_rs = $db->querySingle(
  36. 'SELECT * from horario_view where horario_id = :hor',
  37. [':hor' => $hor]
  38. );
  39. $materia = $horario_rs["materia_id"];
  40. $dia = $horario_rs["horario_dia"];
  41. $hora = $hora_ini . ":" . $min_ini . ":00";
  42. $fecha_new = DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d') . " " . $hora;
  43. $fecha_fin_new = date("Y-m-d", strtotime($fecha_new)) . " " . $duracion_tiempo;
  44. $dia_new = date('w', strtotime($fecha_new));
  45. if ($tipo == 1) { //Reposición
  46. $fecha_falta = DateTime::createFromFormat('d/m/Y', $fecha_falta)->format('Y-m-d');
  47. $dia_falta = date('w', strtotime($fecha_falta));
  48. } else {
  49. $fecha_cambio = DateTime::createFromFormat('d/m/Y', $fecha_cambio)->format('Y-m-d');
  50. $dia_falta = date('w', strtotime($fecha_cambio));
  51. }
  52. //Valida que tenga clase en la fecha de falta
  53. if (intval($dia) != intval($dia_falta)) {
  54. header("Location:" . $pag . "?error=11");
  55. /*print_r($_POST);
  56. echo 'SELECT * from horario_view where horario_id = '.$hor;
  57. echo intval($dia)." != ".intval($dia_falta);*/
  58. exit();
  59. }
  60. if ($tipo == 1) { //Reposición
  61. // Valida que grupo no tenga clases
  62. /*$result = validaConflictoHoras($pdo, $gpo, $dia_new, $hora, $materia, "-", $fecha_new, $fecha_fin_new, $duracion);
  63. if($result != ""){//error
  64. //echo $result;
  65. header("Location:".$pag."?error=7");
  66. exit();
  67. }
  68. */
  69. //Valida que profesor no este en 2 reposiciones al mismo tiempo en la fecha nueva
  70. $traslape = $db->querySingle(
  71. 'SELECT * from traslape_profesor_reposicion(:prof, :fecha, :hora, :dur)',
  72. [':prof' => $prof, ':fecha' => DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d'), ':hora' => $hora, ':dur' => $duracion_tiempo]
  73. )["traslape_profesor_reposicion"];
  74. if ($traslape) {
  75. //print_r($_POST);
  76. //echo "SELECT * from traslape_profesor_reposicion($prof,'".DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d')."' , '$hora', $duracion)";
  77. header("Location:" . $pag . "?error=9");
  78. exit();
  79. }
  80. try {
  81. $db->query(
  82. 'SELECT * from fi_reposicion_solicitud(:f_falta, :f_nueva, :hora_nueva, :hor, :prof, 1, :desc, :alumnos, true, :aula, :duracion, :usr, :bloque, :ciclo)',
  83. [
  84. ':f_falta' => $fecha_falta,
  85. ':f_nueva' => $fecha_new,
  86. ':hora_nueva' => $hora,
  87. ':hor' => $hor,
  88. ':prof' => $prof,
  89. ':desc' => $comentario,
  90. ':alumnos' => $alumnos,
  91. ':aula' => $aula,
  92. ':duracion' => $duracion_tiempo,
  93. ':usr' => $user->user["id"],
  94. ':bloque' => $bloque,
  95. ':ciclo' => $ciclo
  96. ]
  97. );
  98. } catch (Exception $e) {
  99. echo $e->getMessage();
  100. //header("Location: ".$pag."?error=1");
  101. exit();
  102. }
  103. /*
  104. $log = new LogActividad();
  105. $desc_log = "Inserta reposición nueva ID[".$rs["fi_reposicion"]."] Fechas[".$fecha_falta.">".$fecha_new."] Periodo[".$_SESSION["periodo_id"]."] Materia[".$materia."] Profesor[".$prof."] Salon[".$salon."] Horario[".$hor."] Alumnos[".$alumnos."]";
  106. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);*/
  107. } else { //Cambio salón / hora
  108. try {
  109. $db->query(
  110. 'SELECT * from fi_reposicion_solicitud(:f_falta, :f_nueva, :hora_nueva, :hor, :prof, 1, :desc, :alumnos, true, :aula, :duracion, :usr, :bloque, :ciclo)',
  111. [
  112. ':f_falta' => $fecha_falta,
  113. ':f_nueva' => $fecha_cambio,
  114. ':hora_nueva' => $hora,
  115. ':hor' => $hor,
  116. ':prof' => $prof,
  117. ':desc' => $comentario,
  118. ':alumnos' => $alumnos,
  119. ':aula' => $aula,
  120. ':duracion' => $duracion_tiempo,
  121. ':usr' => $user->user["id"],
  122. ':bloque' => $bloque,
  123. ':ciclo' => $ciclo
  124. ]
  125. );
  126. } catch (Exception $e) {
  127. header("Location: " . $pag . "?error=1");
  128. exit();
  129. }
  130. /*
  131. $log = new LogActividad();
  132. $desc_log = "Inserta reposición nueva ID[".$rs["fi_reposicion"]."] Fechas[".$fecha_cambio.">".$fecha_cambio_nueva."] Periodo[".$_SESSION["periodo_id"]."] Materia[".$materia."] Profesor[".$prof."] Salon[".$salon."] Horario[".$hor."] Alumnos[".$alumnos."]";
  133. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
  134. */
  135. }
  136. header("Location: " . $pag . "?ok=0");
  137. exit();
  138. ?>