solicitud_insert.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /*
  3. * Inserta reposición
  4. */
  5. $pag = "../reposiciones_crear.php";
  6. $ruta = "../";
  7. require_once "../class/c_login.php";
  8. require_once "../class/mailer.php";
  9. define("COORDINADOR", 9);
  10. define("ENVIO_CORREOS", true);
  11. // check if the session is started
  12. if (!isset($_SESSION['user']))
  13. die('No se ha iniciado sesión');
  14. $user = unserialize($_SESSION['user']);
  15. //$user->access();
  16. $estado = filter_input(INPUT_POST, "estado", FILTER_SANITIZE_NUMBER_INT);//
  17. $tipo = filter_input(INPUT_POST, "tipo", FILTER_SANITIZE_NUMBER_INT);//
  18. $duracion_id = filter_input(INPUT_POST, "duracion", FILTER_SANITIZE_NUMBER_INT);//Id reposicion
  19. $bloque = filter_input(INPUT_POST, "bloque", FILTER_SANITIZE_NUMBER_INT);//
  20. $ciclo = filter_input(INPUT_POST, "ciclo", FILTER_SANITIZE_NUMBER_INT);//
  21. $fecha_falta = trim(htmlspecialchars($_POST["fecha_falta"], ENT_QUOTES, "UTF-8"));//Reposicion
  22. $fecha = trim(htmlspecialchars($_POST["fecha_nueva"], ENT_QUOTES, "UTF-8"));//Reposicion
  23. $fecha_cambio = trim(htmlspecialchars($_POST["fecha_cambio"], ENT_QUOTES, "UTF-8"));//Cambio salón
  24. $hora_ini = filter_input(INPUT_POST, "hora_ini", FILTER_SANITIZE_NUMBER_INT);//limpia texto hora reposicion
  25. $min_ini = filter_input(INPUT_POST, "min_ini", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  26. $horario = filter_input(INPUT_POST, "horario", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  27. $alumnos = filter_input(INPUT_POST, "alumnos", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  28. $aula = filter_input(INPUT_POST, "aula", FILTER_SANITIZE_NUMBER_INT);//1 regular , 2 sala computo, 3 otro facultad
  29. $salon = NULL;
  30. if(!$user->jefe_carrera){//coordinador
  31. if(isset($_POST["salon"]) && $_POST["salon"] != "")
  32. $salon = filter_input(INPUT_POST, "dlSalon", FILTER_SANITIZE_NUMBER_INT);//1 regular , 2 sala computo, 3 otro facultad
  33. }
  34. if(empty($_POST["prof"]))
  35. $prof = $user->user["id"];
  36. else
  37. $prof = filter_input(INPUT_POST, "prof", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  38. $comentario = trim(htmlspecialchars($_POST["comentario"], ENT_QUOTES, "UTF-8"));//limpia texto
  39. $duracion_rs = $db->querySingle("select * from duracion where duracion_id = :id", [":id"=>$duracion_id]);
  40. $duracion_tiempo = $duracion_rs["duracion_interval"];
  41. //-- Obtiene datos de horario regular de clase
  42. if($horario!= null)
  43. {
  44. $horario_rs = $db->querySingle('SELECT * from horario_view where horario_id = :hor',
  45. [':hor' => $horario]
  46. );
  47. $materia = $horario_rs["materia_id"];
  48. $dia = $horario_rs["horario_dia"];
  49. }else{
  50. $dia = date('w', strtotime($fecha));
  51. }
  52. $hora = $hora_ini.":".$min_ini.":00";
  53. if($tipo == 2){//Cambio
  54. $fecha_cambio = DateTime::createFromFormat('d/m/Y', $fecha_cambio)->format('Y-m-d');
  55. $dia_falta = date('w', strtotime($fecha_cambio));
  56. }else{
  57. $fecha_new = DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d')." ".$hora;
  58. $fecha_fin_new = date("Y-m-d", strtotime($fecha_new))." ".$duracion_tiempo;
  59. $dia_new = date('w', strtotime($fecha_new));
  60. $fecha_falta = DateTime::createFromFormat('d/m/Y', $fecha_falta)->format('Y-m-d');
  61. $dia_falta = date('w', strtotime($fecha_falta));
  62. }
  63. //Valida que tenga clase en la fecha de falta
  64. if(intval($dia) != intval($dia_falta)){
  65. header("Location:".$pag."?error=11");
  66. /*print_r($_POST);
  67. echo 'SELECT * from horario_view where horario_id = '.$horario;
  68. echo intval($dia)." != ".intval($dia_falta);*/
  69. exit();
  70. }
  71. //Obtiene materia
  72. $materia_rs = $db->querySingle('SELECT materia_nombre from materia where materia_id = :mat',[':mat' => $materia]);
  73. //Obtiene correo
  74. $correos_rs = $db->querySingle('SELECT coor.usuario_correo, coor.usuario_nombre from usuario coor where rol_id = :rol_coord and facultad_id = (
  75. select coalesce(facultad_id,0) from usuario u where u.usuario_id = :id_usr) and coor.usuario_correo != \'\'',[':rol_coord' => COORDINADOR, ':id_usr' => $user->user["id"]]
  76. );
  77. if( count($correos_rs) > 0 ){
  78. $to = $correos_rs["usuario_correo"];
  79. }
  80. if($tipo == 1){//Reposición
  81. // Valida que grupo no tenga clases
  82. /*$result = validaConflictoHoras($pdo, $gpo, $dia_new, $hora, $materia, "-", $fecha_new, $fecha_fin_new, $duracion);
  83. if($result != ""){//error
  84. //echo $result;
  85. header("Location:".$pag."?error=7");
  86. exit();
  87. }
  88. */
  89. //Valida que profesor no este en 2 reposiciones al mismo tiempo en la fecha nueva
  90. $traslape = $db->querySingle('SELECT * from traslape_profesor_reposicion(:prof, :fecha, :hora, :dur)',
  91. [':prof' => $prof, ':fecha'=>DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d'), ':hora'=>$hora, ':dur'=>$duracion_tiempo]
  92. )["traslape_profesor_reposicion"];
  93. if($traslape){
  94. //print_r($_POST);
  95. //echo "SELECT * from traslape_profesor_reposicion($prof,'".DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d')."' , '$hora', $duracion)";
  96. header("Location:".$pag."?error=9");
  97. exit();
  98. }
  99. try{
  100. if($user->jefe_carrera){//jefe
  101. $db->query('SELECT * from fi_reposicion_solicitud(:f_falta, :f_nueva, :hora_nueva, :hor, :prof, 1, :desc, :alumnos, true, :aula, :duracion, :usr, :bloque, :ciclo)',
  102. [':f_falta' => $fecha_falta, ':f_nueva' => $fecha_new, ':hora_nueva' => $hora, ':hor' => $horario,
  103. ':prof' => $prof, ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula, ':duracion' => $duracion_tiempo, ':usr'=>$user->user["id"],
  104. ':bloque' => $bloque, ':ciclo' => $ciclo
  105. ]
  106. );
  107. }else{//coordinador
  108. echo 'SELECT * from fi_reposicion_solicitud(:f_falta, :f_nueva, :hora_nueva, :hor, :prof, 2, :desc, :alumnos, true, :aula, :duracion, :usr, :bloque, :ciclo, '.$salon.')';
  109. $db->query('SELECT * from fi_reposicion_solicitud(:f_falta, :f_nueva, :hora_nueva, :hor, :prof, 2, :desc, :alumnos, true, :aula, :duracion, :usr, :bloque, :ciclo, :salon)',
  110. [':f_falta' => $fecha_falta, ':f_nueva' => $fecha_new, ':hora_nueva' => $hora, ':hor' => $horario,
  111. ':prof' => $prof, ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula, ':duracion' => $duracion_tiempo, ':usr'=>$user->user["id"],
  112. ':bloque' => $bloque, ':ciclo' => $ciclo, ':salon'=>$salon
  113. ]
  114. );
  115. }
  116. }catch(Exception $e){
  117. echo "ERROR Reposición<br>".$e->getMessage();
  118. //header("Location: ".$pag."?error=1");
  119. exit();
  120. }
  121. $fecha_clase = date('d/m/Y', strtotime($fecha_falta));
  122. $fecha_nueva = date('d/m/Y', strtotime($fecha_new));
  123. $texto = "<p>Se creó una reposición nueva.</p>";
  124. $texto .= "<p><b>".mb_strtoupper($materia_rs["materia_nombre"])."</b> del día <b>".$fecha_clase." a las ".$horario_rs["horario_hora"]." hrs. </b> se propone reponer el <b>".$fecha_nueva." a las ".$hora." hrs.</b>";
  125. $texto .= "<p>Ingresa al <a href='https://paad.lci.ulsa.mx'>sistema PAAD</a> para autorizarla.</p>";
  126. /*
  127. $log = new LogActividad();
  128. $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[".$horario."] Alumnos[".$alumnos."]";
  129. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);*/
  130. }else{//Cambio salón / hora
  131. try{
  132. if($user->jefe_carrera){//jefe
  133. $db->query('SELECT * from fi_reposicion_solicitud(:f_falta, :f_nueva, :hora_nueva, :hor, :prof, 1, :desc, :alumnos, false, :aula, :duracion, :usr, :bloque, :ciclo)',
  134. [':f_falta' => $fecha_cambio, ':f_nueva' => $fecha_cambio, ':hora_nueva' => $hora, ':hor' => $horario,
  135. ':prof' => $prof, ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula, ':duracion' => $duracion_tiempo, ':usr'=>$user->user["id"],
  136. ':bloque' => $bloque, ':ciclo' => $ciclo
  137. ]
  138. );
  139. }else{//coordinador
  140. $db->query('SELECT * from fi_reposicion_solicitud(:f_falta, :f_nueva, :hora_nueva, :hor, :prof, 2, :desc, :alumnos, false, :aula, :duracion, :usr, :bloque, :ciclo, :salon)',
  141. [':f_falta' => $fecha_cambio, ':f_nueva' => $fecha_cambio, ':hora_nueva' => $hora, ':hor' => $horario,
  142. ':prof' => $prof, ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula, ':duracion' => $duracion_tiempo, ':usr'=>$user->user["id"],
  143. ':bloque' => $bloque, ':ciclo' => $ciclo, ':salon'=>$salon
  144. ]
  145. );
  146. }
  147. }catch(Exception $e){
  148. echo "ERROR Cambio<br>".$e->getMessage();
  149. //header("Location: ".$pag."?error=1");
  150. exit();
  151. }
  152. $texto = "<p>Se creó un cambio de salón nuevo.</p>";
  153. $texto .= "<p><b>".mb_strtoupper($materia_rs["materia_nombre"])."</b> del día <b>".$fecha_falta." a las ".$hora." hrs. </b> se propone reponer el <b>".$fecha_nueva." a las ".$hora." hrs.</b>";
  154. $texto .= "<p>Ingresa al <a href='https://paad.lci.ulsa.mx'>sistema PAAD</a> para autorizarlo.</p>";
  155. /*
  156. $log = new LogActividad();
  157. $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[".$horario."] Alumnos[".$alumnos."]";
  158. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
  159. */
  160. }
  161. if($to!= "" && ENVIO_CORREOS){
  162. $asunto = "Reposición nueva - solicitud";
  163. //crear plantilla
  164. $texto = '<body >
  165. <img src="https://paad.lci.ulsa.mx/imagenes/logo_lasalle.png" alt="La Salle" style="margin-bottom:60px">
  166. '.$texto.'
  167. </body>';
  168. require_once('../include/phpmailer/PHPMailerAutoload.php');
  169. if($_ENV['DB_NAME'] == "paad_pruebas"){
  170. $asunto = "PRUEBAS-".$asunto;
  171. Mailer::enviarCorreo("alejandro.lara@lasalle.mx", $asunto, $texto, true);
  172. }else{
  173. Mailer::enviarCorreo($to, $asunto, $texto, true);
  174. }
  175. }
  176. header("Location: ".$pag."?ok=0");
  177. exit();
  178. ?>