12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?
- #input $_GET['id_espacio_sgu']
- #output rutas: [ ...ruta, salones: [{...salon}] ]
- header('Content-Type: application/json charset=utf-8');
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- $ruta = "../";
- require_once $ruta . "class/c_login.php";
- if (!isset($_SESSION['user'])) {
- http_response_code(401);
- die(json_encode(['error' => 'unauthorized']));
- }
- $user = unserialize($_SESSION['user']);
- // check method
- try {
- if ($_SERVER['REQUEST_METHOD'] === 'GET') {
- if (!(isset($_GET['profesor_id']) || isset($_GET['grupo']))) {
- throw new Exception('missing parameters');
- }
- if (isset($_GET['profesor_id'])) {
- $data = $db->query(
- "SELECT *, (EXTRACT(EPOCH FROM (horario_fin - horario_hora) ) / EXTRACT(EPOCH FROM interval '15 minute'))::INT AS bloques
- FROM horario_view
- JOIN horario_profesor ON horario_profesor.horario_id = horario_view.horario_id
- WHERE horario_profesor.profesor_id = :profesor_id
- AND (facultad_id = :facultad_id OR :facultad_id IS NULL)",
- [
- 'profesor_id' => $_GET['profesor_id'],
- 'facultad_id' => $user->facultad['facultad_id'],
- ]
- );
- } else if (isset($_GET['grupo'])) {
- $data = $db->query(
- "SELECT *, (EXTRACT(EPOCH FROM (horario_fin - horario_hora) ) / EXTRACT(EPOCH FROM interval '15 minute'))::INT AS bloques
- FROM horario_view
- WHERE substring(horario_grupo, 7, 3) = (CAST(:grupo AS INT) + 1)::varchar
- AND (facultad_id = :facultad_id OR :facultad_id IS NULL) AND carrera_id = :carrera_id",
- [
- 'grupo' => $_GET['grupo'],
- 'facultad_id' => $user->facultad['facultad_id'],
- 'carrera_id' => $_GET['carrera_id'],
- ]
- );
- }
- $last_query = [
- 'query' => $db->getLastQuery(),
- ];
- echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
- } else {
- throw new Exception('invalid method');
- }
- } catch (PDOException $th) {
- http_response_code(500);
- echo json_encode([
- 'error' => $th->getMessage(),
- 'query' => $db->getLastQuery(),
- ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
- exit;
- } catch (Exception $th) {
- http_response_code(500);
- echo json_encode([
- 'error' => $th->getMessage(),
- ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
- exit;
- }
|