asignacion_insert.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. $duracion_id = filter_input(INPUT_POST, "duracion", FILTER_SANITIZE_NUMBER_INT);//Id reposicion
  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. $alumnos = filter_input(INPUT_POST, "alumnos", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  22. $aula = filter_input(INPUT_POST, "aula", FILTER_SANITIZE_NUMBER_INT);//1 regular , 2 sala computo, 3 otro facultad
  23. if(empty($_POST["prof"]))
  24. $prof = $user["id"];
  25. else
  26. $prof = filter_input(INPUT_POST, "prof", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  27. //if(isset($_POST["salon"]) && $_POST["salon"] != "")
  28. //$salon = trim(filter_input(INPUT_POST, "salon", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  29. $comentario = trim(htmlspecialchars($_POST["comentario"], ENT_QUOTES, "UTF-8"));//limpia texto
  30. $duracion_rs = $db->querySingle("select * from duracion where duracion_id = :id", [":id"=>$duracion_id]);
  31. $duracion_tiempo = $duracion_rs["duracion_interval"];
  32. //-- Obtiene datos de horario regular de clase
  33. $horario_rs = $db->querySingle('SELECT * from horario_view where horario_id = :hor',
  34. [':hor' => $hor]
  35. );
  36. $materia = $horario_rs["materia_id"];
  37. $dia = $horario_rs["horario_dia"];
  38. $hora = $hora_ini.":".$min_ini.":00";
  39. $fecha_new = DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d')." ".$hora;
  40. $fecha_fin_new = date("Y-m-d", strtotime($fecha_new))." ".$duracion_tiempo;
  41. $dia_new = date('w', strtotime($fecha_new));
  42. $fecha_falta = DateTime::createFromFormat('d/m/Y', $fecha_falta)->format('Y-m-d');
  43. $dia_falta = date('w', strtotime($fecha_falta));
  44. //Valida que tenga clase en la fecha de falta
  45. if(intval($dia) != intval($dia_falta)){
  46. header("Location:".$pag."?error=11");
  47. /*print_r($_POST);
  48. echo 'SELECT * from horario_view where horario_id = '.$hor;
  49. echo intval($dia)." != ".intval($dia_falta);*/
  50. exit();
  51. }
  52. //Obtiene materia
  53. $materia_rs = $db->querySingle('SELECT materia_nombre from materia where materia_id = :mat',[':mat' => $materia]);
  54. //Obtiene correo
  55. $correos_rs = $db->querySingle('SELECT coor.usuario_correo, coor.usuario_nombre from usuario coor where rol_id = :rol_coord and facultad_id = (
  56. select coalesce(facultad_id,0) from usuario u where u.usuario_id = :id_usr)',[':rol_coord' => COORDINADOR, ':id_usr' => $user->user["id"]]
  57. );
  58. if( count($correos_rs) > 0 ){
  59. $to = $correos_rs["usuario_correo"];
  60. }
  61. if($tipo == 1){//Reposición
  62. // Valida que grupo no tenga clases
  63. /*$result = validaConflictoHoras($pdo, $gpo, $dia_new, $hora, $materia, "-", $fecha_new, $fecha_fin_new, $duracion);
  64. if($result != ""){//error
  65. //echo $result;
  66. header("Location:".$pag."?error=7");
  67. exit();
  68. }
  69. */
  70. //Valida que profesor no este en 2 reposiciones al mismo tiempo en la fecha nueva
  71. $traslape = $db->querySingle('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('SELECT * from fi_asignacion_solicitud(:f_nueva, :hora_nueva, :prof, 1, :desc, :alumnos, :aula, :duracion, :usr)',
  82. [':f_nueva' => $fecha_new, ':hora_nueva' => $hora,
  83. ':prof' => $prof, ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula, ':duracion' => $duracion_tiempo, ':usr'=>$user->user["id"]
  84. ]
  85. );
  86. }catch(Exception $e){
  87. echo $e->getMessage();
  88. //header("Location: ".$pag."?error=1");
  89. exit();
  90. }
  91. $texto = "<p>Se creó una reposición nueva.</p>";
  92. $texto .= "<p><b>".mb_strtoupper($materia_rs["materia_nombre"])."</b> del día <b>".$fecha_falta." a las ".$hor." hrs. </b> se propone reponer el <b>".$fecha_new." a las ".$hora." hrs.</b>";
  93. $texto .= "<p>Ingresa al <a href='https://paad.lci.ulsa.mx'>sistema PAAD</a> para autorizarla.</p>";
  94. /*
  95. $log = new LogActividad();
  96. $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."]";
  97. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);*/
  98. }else{//Cambio salón / hora
  99. try{
  100. $db->query('SELECT * from fi_reposicion_solicitud(:f_nueva, :hora_nueva, :hor, :prof, 1, :desc, :alumnos, true, :aula, :duracion, :usr)',
  101. [':f_nueva' => $fecha_cambio, ':hora_nueva' => $hora, ':hor' => $hor,
  102. ':prof' => $prof, ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula, ':duracion' => $duracion_tiempo, ':usr'=>$user->user["id"],
  103. ]
  104. );
  105. }catch(Exception $e){
  106. header("Location: ".$pag."?error=1");
  107. exit();
  108. }
  109. $texto = "<p>Se creó un cambio de salón nuevo.</p>";
  110. $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_nueva." hrs.</b>";
  111. $texto .= "<p>Ingresa al <a href='https://paad.lci.ulsa.mx'>sistema PAAD</a> para autorizarlo.</p>";
  112. /*
  113. $log = new LogActividad();
  114. $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."]";
  115. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
  116. */
  117. }
  118. if($to!= "" && ENVIO_CORREOS){
  119. $asunto = "Reposición nueva - solicitud";
  120. //crear plantilla
  121. $texto = '<body >
  122. <img src="https://paad.lci.ulsa.mx/imagenes/logo_lasalle.png" alt="La Salle" style="margin-bottom:60px">
  123. '.$texto.'
  124. </body>';
  125. require_once('../include/phpmailer/PHPMailerAutoload.php');
  126. if($_ENV['DB_NAME'] == "paad_pruebas"){
  127. $asunto = "PRUEBAS-".$asunto;
  128. Mailer::enviarCorreo("alejandro.rosales@lasalle.mx", $asunto, $texto, true);
  129. }else{
  130. Mailer::enviarCorreo($to, $asunto, $texto, true);
  131. }
  132. }
  133. exit();
  134. header("Location: ".$pag."?ok=0");
  135. ?>