Commit Bulk

This commit is contained in:
2023-08-28 15:26:15 +00:00
parent 6c15e330c4
commit 674fe5f264
54 changed files with 2838 additions and 1490 deletions

View File

@@ -1,35 +1,56 @@
<?php
header('Content-Type: application/json');
<?
#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("../include/bd_pdo.php");
extract($_POST);
$dias = array("domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado");
$horarios = $db
->get("fs_horario($periodo, $carrera, '$grupo', true)");
// get each id from $horarios (might be duplicate)
try {
$horarios = array_map(function ($horario) use ($dias, $db) {
$horario['profesores'] = array_map(
fn ($profesor) =>
$db->where("id", $profesor)->getOne("fs_profesor"),
explode(",", substr($horario['profesores'], 1, -1))
);
$horario['dia'] = $dias[$horario['dia']];
return $horario;
}, $horarios);
} catch (Exception $e) {
die(json_encode([
"status" => "error",
"message" => $e->getMessage(),
]));
require_once $ruta . "class/c_login.php";
if (!isset($_SESSION['user'])) {
http_response_code(401);
die(json_encode(['error' => 'unauthorized']));
}
?>
<?= json_encode([
"status" => "success",
"horario" => $horarios,
]) ?>
$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;
}