action_horario_update.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. header('Content-Type: application/json');
  3. $ruta = "../";
  4. require_once "../class/c_login.php";
  5. // check if the session is started
  6. if (!isset($_SESSION['user']))
  7. die(json_encode(['error' => 'No se ha iniciado sesión']));
  8. $user = unserialize($_SESSION['user']);
  9. $horario = array_map(fn ($value) => $_POST[$value], array_filter([
  10. "hora" => "hora",
  11. "dia" => "día",
  12. "salon" => "salón",
  13. "duracion" => "duración",
  14. ], fn ($value) => !empty($_POST[$value])));
  15. if (!empty($_POST['profesores']))
  16. $horario["profesores"] = "{ {$_POST['profesores']} }";
  17. try {
  18. $id = $_POST['id'] ?? 0;
  19. $old = $db
  20. ->where("horario_id", $id)
  21. ->getOne("horario");
  22. $horario = $db
  23. ->where("id", $id)
  24. ->update("fs_horario", $horario);
  25. $new = $db
  26. ->orderBy("horario_id", "DESC")
  27. ->getOne("horario");
  28. $user->print_to_log("Actualización de horario", old: $old, new: $new);
  29. } catch (Exception $e) {
  30. die(json_encode([
  31. "status" => "error",
  32. "message" => $e->getMessage(),
  33. 'POST' => $_POST,
  34. ]));
  35. }
  36. die(json_encode([
  37. "status" => "success",
  38. ]));