calendario_delete.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /* AJAX
  3. * Inserta datos del objeto para el calendario
  4. * Recibe:
  5. * json
  6. * Return:
  7. * id insertado o cadena de error
  8. */
  9. require_once("../../include/constantes.php");
  10. require_once("../../include/nocache.php");
  11. require_once("../../include/bd_pdo.php");
  12. require_once("../../include/util.php");
  13. require_once("../../classes/ValidaSesion.php");
  14. require_once("../classes/LogActividad.php");//die on error
  15. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  16. $objSesion = new ValidaSesion($pdo, 57, APSA);
  17. if(!$objSesion->tieneAcceso() || !$objSesion->puedeEditar()){
  18. $return["error"] = "Error! No tienes permisos para realizar esta acción.";
  19. }else if(!isset($_POST["id"], $_POST["fecha"])){
  20. $return["error"] = "Error! No se recibió la información del evento.";
  21. }else{
  22. $id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  23. $fecha = fechaGuion(trim(filter_input(INPUT_POST, "fecha", FILTER_SANITIZE_STRING, array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  24. $hora = trim(filter_input(INPUT_POST, "hora", FILTER_SANITIZE_STRING, array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  25. $fechas_total = filter_input(INPUT_POST, "fechas_total", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  26. $return["error"] = "";
  27. try {
  28. $pdo->beginTransaction();
  29. $error = false;
  30. //---- Borrar ----------
  31. if($fecha == "" || $fechas_total == 1){//no hay fecha, son todos
  32. $stmt = $pdo->prepare('Select * from fd_calendarioevento(:id)');
  33. $stmt->bindParam(":id", $id);
  34. if(!$stmt->execute()){
  35. $t = $stmt->errorInfo();
  36. $return["error"] .= "Ocurrió un error al borrar el evento único.".$t[2];
  37. $error = true;
  38. }
  39. $stmt->closeCursor();
  40. }else{//solo un evento
  41. if($hora == "")
  42. $fecha_db = $fecha;
  43. else
  44. $fecha_db = $fecha." ".$hora.":00";
  45. $stmt = $pdo->prepare('Select * from fu_calendarioevento_ex(:id, :fecha)');
  46. $stmt->bindParam(":id", $id);
  47. $stmt->bindParam(":fecha", $fecha_db);
  48. if(!$stmt->execute()){
  49. $t = $stmt->errorInfo();
  50. $return["error"] .= "Ocurrió un error al borrar el evento.".$t[2];
  51. $error = true;
  52. }else{
  53. //Si se modificó, borrarla porque no se va a usar
  54. $stmt = $pdo->prepare('Select * from fd_calendarioeventoeditado(:id, :fecha)');
  55. $stmt->bindParam(":id", $id);
  56. $stmt->bindParam(":fecha", $fecha);
  57. if(!$stmt->execute()){
  58. $t = $stmt->errorInfo();
  59. $return["error"] .= "Ocurrió un error al borrar el evento modificado.".$t[2];
  60. $error = true;
  61. }
  62. }
  63. }
  64. if(!$error){
  65. $pdo->commit();
  66. unset($return["error"]);
  67. $return["ok"] = "El evento se borró correctamente";
  68. //Inserta Log
  69. /*$log = new LogActividad();
  70. $desc_log = "Actualiza evento EventoID[".$clase["id_db"]."] Titulo[".$clase["titulo"]."] Original[".$clase["fecha_orig"]."] Día[".$clase["fecha_nueva"]."] HoraIni[".$clase["hora_ini"]."] HoraFin[".$clase["hora_fin"]."]";
  71. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
  72. */
  73. }else
  74. $pdo->rollBack();
  75. $stmt = null; // cierra conexion
  76. } catch(PDOException $e) {
  77. $pdo->rollBack();
  78. $return["error"] = "Ocurrió un error al borrar los datos del evento.";
  79. }
  80. }
  81. $return["json"] = json_encode($return);
  82. echo json_encode($return);
  83. ?>