carrera.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. require_once "{$_SERVER['DOCUMENT_ROOT']}/class/c_login.php";
  3. header('Content-Type: application/json');
  4. if (!Login::is_logged()) {
  5. header('HTTP/1.1 401 Unauthorized');
  6. echo json_encode(['error' => 'No se ha iniciado sesión']);
  7. exit();
  8. }
  9. $user = Login::get_user();
  10. try {
  11. switch ($_SERVER['REQUEST_METHOD']) {
  12. case 'GET':
  13. // Fetch all puestos
  14. $facultad_id = $user->facultad['facultad_id'];
  15. $carreras = $db->query(<<<SQL
  16. SELECT carrera_id, carrera_nombre, clave_carrera, facultad_id
  17. FROM carrera
  18. WHERE facultad_id = :facultad_id OR :facultad_id IS NULL
  19. SQL, ['facultad_id' => $facultad_id]);
  20. echo json_encode($carreras);
  21. break;
  22. default:
  23. header('HTTP/1.1 405 Method Not Allowed');
  24. echo json_encode(['error' => 'Método no permitido']);
  25. break;
  26. }
  27. } catch (PDOException $e) {
  28. echo json_encode([
  29. 'error' => $e->getMessage(),
  30. 'query' => $db->getLastQuery(),
  31. 'exception' => $e->getTraceAsString()
  32. ]);
  33. }