123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- require_once "{$_SERVER['DOCUMENT_ROOT']}/class/c_login.php";
- header('Content-Type: application/json');
- if (!Login::is_logged()) {
- header('HTTP/1.1 401 Unauthorized');
- echo json_encode(['error' => 'No se ha iniciado sesión']);
- exit();
- }
- $user = Login::get_user();
- try {
- switch ($_SERVER['REQUEST_METHOD']) {
- case 'GET':
- // Fetch all puestos
- $facultad_id = $user->facultad['facultad_id'];
- $carreras = $db->query(<<<SQL
- SELECT carrera_id, carrera_nombre, clave_carrera, facultad_id
- FROM carrera
- WHERE facultad_id = :facultad_id OR :facultad_id IS NULL
- SQL, ['facultad_id' => $facultad_id]);
- echo json_encode($carreras);
- break;
- default:
- header('HTTP/1.1 405 Method Not Allowed');
- echo json_encode(['error' => 'Método no permitido']);
- break;
- }
- } catch (PDOException $e) {
- echo json_encode([
- 'error' => $e->getMessage(),
- 'query' => $db->getLastQuery(),
- 'exception' => $e->getTraceAsString()
- ]);
- }
|