horariogrupo_validahash.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /* AJAX
  3. * Selecciona los datos de la carrera
  4. * Recibe:
  5. * id - ID de grupo,
  6. * json
  7. * Return:
  8. * resultado o cadena de error
  9. */
  10. require_once("../../include/constantes.php");
  11. require_once("../../include/nocache.php");
  12. require_once("../../include/util.php");
  13. require_once("../../include/bd_pdo.php");
  14. require_once("../../classes/ValidaSesion.php");
  15. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  16. $objSesion = new ValidaSesion($pdo, 51, APSA);
  17. if($objSesion->tieneAcceso() && isset($_POST["id"]) && $_POST["id"]!="" && isset($_POST["check"]) && $_POST["check"]!=""){
  18. $grupo = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  19. $str_check = trim(filter_input(INPUT_POST, "check", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  20. $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, NULL, NULL)');
  21. $stmt->bindParam(":gpo", $grupo);
  22. $error = false;
  23. if(!$stmt->execute()){
  24. $t = $stmt->errorInfo();
  25. $return["error"] = "Ocurrió un error al obtener los horarios del grupo ".$t[2];
  26. $error = true;
  27. }
  28. $horario_rs = $stmt->fetchAll();
  29. $stmt->closeCursor();
  30. $horario_hash = "";
  31. foreach($horario_rs as $horario){//crea objeto json
  32. $tipo = 0;
  33. if(isset($horario["TipoSubmateria_id"]) && $horario["TipoSubmateria_id"] != "")
  34. $tipo = $horario["TipoSubmateria_id"];
  35. $horario_hash .= $horario["Dia_id"].substr($horario["Horario_hora"], 0, 5).$horario["Materia_id"].$horario["Horario_duracion"].fechaSlash($horario["fecha_inicial"]).fechaSlash($horario["fecha_final"]).$tipo;
  36. }
  37. if(!$error){
  38. $return["reload"] = !(md5($horario_hash) == $str_check);
  39. $return["compare"] = md5($horario_hash)." == ".$str_check;
  40. }
  41. }else{
  42. $return["reload"] = false;
  43. $return["error"] = "No se recibieron los parámetros esperados.";
  44. }
  45. $return["json"] = json_encode($return);
  46. echo json_encode($return);
  47. ?>