reposicion_insert.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /*ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);*/
  5. /*
  6. * Inserta los datos de una reposición
  7. * Recibe:
  8. * fecha_falta,
  9. * fecha_inicial,
  10. * hora_ini,
  11. * min_ini,
  12. * materia
  13. * salon
  14. * gpo
  15. * prof
  16. *
  17. * Error:
  18. * 0 - No se recibieron los datos
  19. * 1 - Error de base de datos
  20. * Success:
  21. */
  22. require_once("../../include/constantes.php");
  23. require_once("../../include/bd_pdo.php");
  24. require_once("../../classes/ValidaSesion.php");
  25. require_once("../classes/LogActividad.php");//die on error
  26. require_once("../../include/util.php");
  27. require_once("../include/validacionesHorario.php");
  28. require_once("../../include/nusoap/nusoap.php");
  29. $pag = "../mireposicion.php";
  30. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  31. $objSesion = new ValidaSesion($pdo, 23, APSA);
  32. if(!$objSesion->tieneAcceso()){
  33. $objSesion->terminaSesion();
  34. //print_r($objSesion->getError());
  35. }
  36. if(!$objSesion->puedeEditar()){
  37. header("Location: ".$pag);
  38. exit();
  39. }
  40. unset($objValida);
  41. if(/*empty($_POST["fecha_inicial"]) ||*/ empty($_POST["hora_ini"]) || empty($_POST["min_ini"]) || empty($_POST["horario"]) ){
  42. header("Location: ".$pag."?error=0");
  43. exit();
  44. }
  45. $fecha_falta = trim(filter_input(INPUT_POST, "fecha_falta", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  46. $fecha = trim(filter_input(INPUT_POST, "fecha_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  47. $fecha_cambio = trim(filter_input(INPUT_POST, "fecha_cambio", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  48. $hora_ini = filter_input(INPUT_POST, "hora_ini", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  49. $min_ini = filter_input(INPUT_POST, "min_ini", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  50. $hor = filter_input(INPUT_POST, "horario", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  51. $alumnos = filter_input(INPUT_POST, "alumnos", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  52. $tipo = filter_input(INPUT_POST, "tipo", FILTER_SANITIZE_NUMBER_INT);//1 Repo , 0 Cambio
  53. $aula = filter_input(INPUT_POST, "aula", FILTER_SANITIZE_NUMBER_INT);//1 regular , 2 sala computo, 3 otro facultad
  54. if(empty($_POST["prof"]))
  55. $prof = $_SESSION["usuario_id"];
  56. else
  57. $prof = filter_input(INPUT_POST, "prof", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  58. //if(isset($_POST["salon"]) && $_POST["salon"] != "")
  59. //$salon = trim(filter_input(INPUT_POST, "salon", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  60. $comentario = trim(filter_input(INPUT_POST, "comentario", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  61. $stmt = $pdo->prepare('Select * from fs_horario(:hor)');
  62. $stmt->bindParam(":hor", $hor);
  63. if(!$stmt->execute()){
  64. print_r($stmt->errorInfo());
  65. header("Location:".$pag."?error=4");
  66. exit();
  67. }
  68. $horario_rs = $stmt->fetch();
  69. $stmt->closeCursor();
  70. $materia = $horario_rs["Materia_id"];
  71. $materia_id_sgu = $horario_rs["Materia_id_sgu"];
  72. $gpo = $horario_rs["Grupo_id"];
  73. $duracion = $horario_rs["Horario_duracion"];
  74. $hora = $horario_rs["Horario_hora"];
  75. //$duracion = 90;
  76. $hora_new = $hora_ini.":".$min_ini;
  77. $fecha_new = fechaGuion($fecha);
  78. $fecha_ini = fechaGuion($fecha)." ".$hora_ini.":".$min_ini.":00";
  79. $fecha_fin = date('Y-m-d H:i:00', strtotime($fecha_ini.' + '.$duracion.' minute'));
  80. $dia = date('w', strtotime($fecha_ini));
  81. if($tipo == 1){//Reposición
  82. $fecha_falta = fechaGuion($fecha_falta);
  83. $dia_falta = date('w', strtotime($fecha_falta));
  84. }else{
  85. $fecha_cambio = fechaGuion($fecha_cambio);
  86. $dia_falta = date('w', strtotime($fecha_cambio));
  87. }
  88. //Obtiene clave ULSA
  89. $stmt = $pdo->prepare('SELECT * from fs_usuario(:id)');
  90. $stmt->bindParam(":id", $prof);
  91. if(!$stmt->execute()){
  92. //print_r($stmt->errorInfo());
  93. header("Location:".$pag."?error=0");
  94. exit();
  95. }
  96. $prof_rs = $stmt->fetch();
  97. $prof_clave = $prof_rs["Usuario_claveULSA"];
  98. $stmt->closeCursor();
  99. $stmt = null;
  100. unset($prof_rs);
  101. //Valida que tenga clase en la fecha de falta
  102. $stmt = $pdo->prepare('SELECT COUNT("HorarioGrupo_id") as total FROM "HorarioGrupo" hg WHERE "Grupo_id" = :gpo and "Materia_id" = :mat and "Dia_id" = :dia');
  103. $stmt->bindParam(":mat", $materia);
  104. $stmt->bindParam(":gpo", $gpo);
  105. $stmt->bindParam(":dia", $dia_falta);
  106. if(!$stmt->execute()){
  107. //print_r($stmt->errorInfo());
  108. header("Location:".$pag."?error=1");
  109. exit();
  110. }
  111. $total_rs = $stmt->fetch();
  112. $stmt->closeCursor();
  113. $stmt = null;
  114. if(empty($total_rs["total"]) || $total_rs["total"] == 0){
  115. //echo 'SELECT COUNT("HorarioGrupo_id") as total FROM "HorarioGrupo" hg WHERE "Grupo_id" = '.$gpo.' and "Materia_id" = '.$materia.' and "Dia_id" = '.$dia_falta;
  116. header("Location:".$pag."?error=11");
  117. exit();
  118. }
  119. // Valida que salón esté disponible
  120. /*
  121. if(!empty($salon)){
  122. $result = validaConflictoSalon($pdo, $gpo, $dia, $hora_new, $materia, '-', $fecha_ini, $fecha_fin, $duracion, $salon, NULL, NULL);
  123. if($result != ""){//error
  124. //echo $result;
  125. header("Location:".$pag."?error=8");
  126. exit();
  127. }
  128. //Valida que no esté ocupado el salón con reposición
  129. $result = validaConflictoReposicionSalon($pdo, NULL, $_SESSION["periodo_id"], $fecha_ini, $duracion, $salon);
  130. if($result != ""){//error
  131. //echo $result;
  132. header("Location:".$pag."?error=8");
  133. exit();
  134. }
  135. }*/
  136. /*
  137. $result = validaConflictoProfesorSalon($pdo, $gpo, $dia, $hora_new, $materia, $salon, '-', $fecha_ini, $fecha_fin, $duracion, array(array("profesor"=>$prof) ), null, 0);
  138. if($result != ""){//error
  139. //echo $result;
  140. header("Location:".$pag."?error=10");
  141. exit();
  142. }
  143. */
  144. $client = new nusoap_client('http://200.13.89.27/checador_otros/admin_checador/webservice/reposiciones_service.php?wsdl', 'wsdl');
  145. $error = $client->getError();
  146. if ($error) {
  147. header("Location:".$pag."?error=12");
  148. exit();
  149. }
  150. $token = password_hash("W3bS3rv1c3.R3p0##", PASSWORD_DEFAULT);
  151. if($tipo == 1){//Reposición
  152. // Valida que grupo no tenga clases
  153. $result = validaConflictoHoras($pdo, $gpo, $dia, $hora_new, $materia, "-", $fecha_ini, $fecha_fin, $duracion);
  154. if($result != ""){//error
  155. //echo $result;
  156. header("Location:".$pag."?error=7");
  157. exit();
  158. }
  159. //Valida que profesor no este en 2 reposiciones al mismo tiempo
  160. $result = validaConflictoReposicionProfesorSalon($pdo, NULL, $_SESSION["periodo_id"], $fecha_ini, $duracion, $prof);
  161. if($result != ""){//error
  162. //echo $result;
  163. header("Location:".$pag."?error=9");
  164. exit();
  165. }
  166. $result = $client->call("reposicion_crea", array($token, $_SESSION["periodo_shortname"],$prof_clave, $materia_id_sgu, $tipo, $fecha_falta, $fecha_new, $hora, $hora_new, $alumnos, $aula, $comentario, $duracion ));
  167. //print_r(array($token, $_SESSION["periodo_shortname"],$prof_clave, $materia_id_sgu, $tipo, $fecha_falta, $fecha_new, $hora, $hora_new, $alumnos, $aula, $comentario, $duracion ));
  168. //print_r($result);
  169. //exit();
  170. if ($client->fault) {
  171. //echo "fault";
  172. header("Location:".$pag."?error=12");
  173. exit();
  174. } else {
  175. $error = $client->getError();
  176. if ($error) {
  177. //echo "error [$error] ";
  178. header("Location:".$pag."?error=12");
  179. exit();
  180. } else {
  181. $ok = $result["result"];
  182. $id_cronos = $result["id_result"];
  183. if(!$ok || empty($id_cronos)){
  184. //print_r($result);
  185. //echo "Not OK [$ok][$id_cronos]";
  186. header("Location:".$pag."?error=12");
  187. exit();
  188. }
  189. }
  190. }
  191. $fecha_falta = $fecha_falta." ".$horario_rs["Horario_hora"];
  192. $stmt = $pdo->prepare('Select * from fi_reposicion(:f_falta, :f_nueva, :hor, NULL, :prof, 1, :com, :alumnos, true, :aula, NULL, :id_cronos)');
  193. $stmt->bindParam(":f_falta", $fecha_falta);
  194. $stmt->bindParam(":f_nueva", $fecha_ini);
  195. $stmt->bindParam(":hor", $hor);
  196. //$stmt->bindParam(":salon", $salon);
  197. $stmt->bindParam(":prof", $prof);
  198. $stmt->bindParam(":com", $comentario);
  199. $stmt->bindParam(":alumnos", $alumnos);
  200. $stmt->bindParam(":aula", $aula);
  201. $stmt->bindParam(":id_cronos", $id_cronos);
  202. if(!$stmt->execute()){
  203. //echo $fecha_falta." ".$fecha_ini." ".$materia." ".$salon." ".$prof." ".$gpo." ".$com;
  204. //print_r($stmt->errorInfo());
  205. header("Location:".$pag."?error=1");
  206. exit();
  207. }
  208. $rs = $stmt->fetch();
  209. $stmt->closeCursor();
  210. $stmt = null;
  211. $log = new LogActividad();
  212. $desc_log = "Inserta reposición nueva ID[".$rs["fi_reposicion"]."] Fechas[".$fecha_falta.">".$fecha_ini."] Periodo[".$_SESSION["periodo_id"]."] Materia[".$materia."] Profesor[".$prof."] Salon[".$salon."] Horario[".$hor."] Alumnos[".$alumnos."]";
  213. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
  214. }else{//Cambio salón / hora
  215. $result = $client->call("reposicion_crea", array($token, $_SESSION["periodo_shortname"],$prof, $materia_id_sgu, $tipo, $fecha_cambio, $fecha_cambio, $hora ,$hora_new, $alumnos,$aula, $comentario, $duracion ));
  216. if ($client->fault) {
  217. header("Location:".$pag."?error=12");
  218. exit();
  219. } else {
  220. $error = $client->getError();
  221. if ($error) {
  222. header("Location:".$pag."?error=12");
  223. exit();
  224. } else {
  225. $ok = $result["result"];
  226. $id_cronos = $result["id_result"];
  227. if(!$ok || empty($id_cronos)){
  228. header("Location:".$pag."?error=12");
  229. exit();
  230. }
  231. }
  232. }
  233. $fecha_cambio_nueva = $fecha_cambio." ".$hora_ini.":".$min_ini.":00";
  234. $stmt = $pdo->prepare('Select * from fi_reposicion(:f_falta, :f_nueva, :hor, NULL, :prof, 1, :com, :alumnos, false, :aula, NULL, :id_cronos)');
  235. $stmt->bindParam(":f_falta", $fecha_cambio);
  236. $stmt->bindParam(":f_nueva", $fecha_cambio_nueva);
  237. $stmt->bindParam(":hor", $hor);
  238. //$stmt->bindParam(":salon", $salon);
  239. $stmt->bindParam(":prof", $prof);
  240. $stmt->bindParam(":com", $comentario);
  241. $stmt->bindParam(":alumnos", $alumnos);
  242. $stmt->bindParam(":aula", $aula);
  243. $stmt->bindParam(":id_cronos", $id_cronos);
  244. if(!$stmt->execute()){
  245. //echo $fecha_falta." ".$fecha_ini." ".$materia." ".$salon." ".$prof." ".$gpo." ".$com;
  246. //print_r($stmt->errorInfo());
  247. header("Location:".$pag."?error=1");
  248. exit();
  249. }
  250. $rs = $stmt->fetch();
  251. $stmt->closeCursor();
  252. $stmt = null;
  253. $log = new LogActividad();
  254. $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."]";
  255. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
  256. }
  257. header("Location: ".$pag);
  258. exit();
  259. ?>