reposicion_update.php 9.7 KB

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