142 lines
5.2 KiB
PHP
142 lines
5.2 KiB
PHP
<?php
|
|
#input $_GET['id_espacio_sgu']
|
|
#output rutas: [ ...ruta, salones: [{...salon}] ]
|
|
header('Content-Type: application/json charset=utf-8');
|
|
ini_set('memory_limit', '2048M');
|
|
ini_set('post_max_size', '2048M');
|
|
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') {
|
|
$baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null;
|
|
|
|
$params = [
|
|
// ':periodo_id' => $_GET['periodo_id'] > 0 ? $user->periodo_id : null,
|
|
|
|
'usuario_id' => $user->user['id'],
|
|
];
|
|
|
|
$db->where('usuario_id', $user->user['id'])->delete('last_auditoria');
|
|
|
|
// Define relevant columns
|
|
$relevant_columns = [
|
|
'registro_id',
|
|
'fechas.fecha as registro_fecha_ideal',
|
|
'horario.horario_id',
|
|
'profesor.profesor_id',
|
|
'salon',
|
|
'profesor_clave',
|
|
'profesor_nombre',
|
|
'horario_hora',
|
|
'horario_fin',
|
|
'registro_fecha',
|
|
'estado_color',
|
|
'estado_icon',
|
|
'estado_supervisor.estado_supervisor_id',
|
|
'horario.facultad_id',
|
|
'usuario_nombre',
|
|
'registro_fecha_supervisor',
|
|
'comentario',
|
|
'registro_justificada',
|
|
'justificacion',
|
|
'reposicion_id'
|
|
];
|
|
$RelevantColumns = implode(', ', $relevant_columns);
|
|
|
|
$_SESSION['fecha_inicio'] = $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d');
|
|
$_SESSION['fecha_fin'] = date('Y-m-d 23:59:59', strtotime($baseDate ?? 'now'));
|
|
|
|
$fechas = [
|
|
'fecha_inicio' => $_SESSION['fecha_inicio'],
|
|
'fecha_fin' => $_SESSION['fecha_fin'],
|
|
];
|
|
|
|
|
|
$PeriodosHorarios = implode(',', array_column(
|
|
$db->query(
|
|
'SELECT periodo_id FROM periodo WHERE (:fecha_inicio, :fecha_fin) OVERLAPS (periodo_fecha_inicio, periodo_fecha_fin)',
|
|
$fechas
|
|
),
|
|
'periodo_id'
|
|
)) ?: 0;
|
|
|
|
|
|
$DaysWeek = implode(',', array_values(array_unique(array_map(
|
|
fn(DateTime $date) => (int) $date->format('w'),
|
|
iterator_to_array(new DatePeriod(
|
|
new DateTime($_SESSION['fecha_inicio']),
|
|
new DateInterval('P1D'),
|
|
(new DateTime($_SESSION['fecha_fin']))->modify('+1 day')
|
|
))
|
|
)))) ?: 0;
|
|
|
|
$_SESSION['horarios'] = $HorariosID = implode(',', array_column($db->query(
|
|
"SELECT horario_id FROM horario
|
|
WHERE horario_dia IN ($DaysWeek)
|
|
AND periodo_id IN ($PeriodosHorarios)
|
|
AND (:fecha_inicio, :fecha_fin) OVERLAPS (horario_fecha_inicio, COALESCE(horario_fecha_fin, :fecha_fin))
|
|
AND facultad_id = COALESCE(:facultad_id, facultad_id)",
|
|
array_merge($fechas, [
|
|
':facultad_id' => $user->facultad['facultad_id'],
|
|
])
|
|
), 'horario_id')) ?: 0;
|
|
|
|
|
|
$Horarios = $db->query(
|
|
"WITH fechas AS (
|
|
SELECT generate_series(:fecha_inicio, :fecha_fin, '1 day'::INTERVAL)::DATE AS fecha
|
|
)
|
|
SELECT
|
|
$RelevantColumns,
|
|
CASE
|
|
WHEN registro.registro_retardo THEN 'warning'
|
|
ELSE 'primary'
|
|
END AS color
|
|
FROM horario
|
|
JOIN horario_profesor USING (horario_id)
|
|
JOIN fechas ON EXTRACT(DOW FROM fechas.fecha) = horario.horario_dia
|
|
JOIN profesor USING (profesor_id)
|
|
JOIN salon USING (salon_id)
|
|
LEFT JOIN REGISTRO ON
|
|
REGISTRO.profesor_id = horario_profesor.profesor_id AND
|
|
REGISTRO.horario_id = horario.horario_id AND
|
|
REGISTRO.registro_fecha_ideal = fechas.fecha
|
|
LEFT JOIN usuario ON usuario.usuario_id = REGISTRO.supervisor_id
|
|
JOIN estado_supervisor ON estado_supervisor.estado_supervisor_id = COALESCE(REGISTRO.estado_supervisor_id, 0)
|
|
WHERE horario.horario_id IN ($HorariosID)
|
|
AND (FECHAS.fecha + horario.horario_hora) < NOW()
|
|
ORDER BY fechas.fecha, horario_hora, REGISTRO.estado_supervisor_id",
|
|
$fechas
|
|
);
|
|
|
|
echo json_encode($Horarios);
|
|
} else {
|
|
http_response_code(405);
|
|
echo json_encode(['error' => 'method not allowed']);
|
|
exit;
|
|
}
|
|
} 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;
|
|
} |