Files
paad/action/action_horario.php
2023-08-28 15:26:15 +00:00

56 lines
1.9 KiB
PHP

<?
#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'])) {
throw new Exception('missing parameters');
}
$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'],
]
);
$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;
}