action_profesor.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?
  2. #input $_GET['id_espacio_sgu']
  3. #output rutas: [ ...ruta, salones: [{...salon}] ]
  4. header('Content-Type: application/json charset=utf-8');
  5. ini_set('display_errors', 1);
  6. ini_set('display_startup_errors', 1);
  7. error_reporting(E_ALL);
  8. $ruta = "../";
  9. require_once $ruta . "class/c_login.php";
  10. if (!isset($_SESSION['user'])) {
  11. http_response_code(401);
  12. die(json_encode(['error' => 'unauthorized']));
  13. }
  14. $user = unserialize($_SESSION['user']);
  15. // check method
  16. try {
  17. if ($_SERVER['REQUEST_METHOD'] === 'GET') {
  18. $data = $db->query(
  19. "SELECT DISTINCT profesor.*
  20. FROM profesor
  21. JOIN horario_profesor using (profesor_id)
  22. JOIN horario using (horario_id)
  23. JOIN materia using (materia_id)
  24. JOIN carrera using (carrera_id)
  25. WHERE carrera.facultad_id = :facultad_id OR :facultad_id IS NULL
  26. ORDER BY profesor.profesor_nombre",
  27. array(
  28. ":facultad_id" => $user->facultad['facultad_id']
  29. )
  30. );
  31. $last_query = [
  32. 'query' => $db->getLastQuery(),
  33. ];
  34. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  35. } else {
  36. http_response_code(405);
  37. echo json_encode(['error' => 'method not allowed']);
  38. exit;
  39. }
  40. } catch (PDOException $th) {
  41. http_response_code(500);
  42. echo json_encode([
  43. 'error' => $th->getMessage(),
  44. 'query' => $db->getLastQuery(),
  45. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  46. exit;
  47. } catch (Exception $th) {
  48. http_response_code(500);
  49. echo json_encode([
  50. 'error' => $th->getMessage(),
  51. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  52. exit;
  53. }