Files
paad/action/action_auditoria.php
2023-09-04 14:50:00 +00:00

101 lines
4.7 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') {
$baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null;
$params = [
':periodo_id' => $user->periodo_id,
':facultad_id' => $user->facultad['facultad_id'],
':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d'),
':fecha_fin' => $baseDate ? date('Y-m-d H:i:s', strtotime($baseDate . ' +24 hours')) : date('Y-m-d H:i:s'),
];
$data = $db->query(
"WITH horarios AS (
SELECT *,
materia_nombre as materia,
carrera_nombre as carrera,
facultad_nombre as facultad,
nivel_nombre as nivel,
horario_hora + duracion_interval as horario_fin
FROM horario
left JOIN materia USING (materia_id)
JOIN carrera USING (carrera_id)
JOIN nivel USING (nivel_id)
JOIN facultad ON facultad.facultad_id = carrera.facultad_id
JOIN PERIODO_CARRERA USING (carrera_id)
JOIN PERIODO USING (periodo_id)
JOIN SALON USING (salon_id)
JOIN duracion USING (duracion_id)
WHERE (periodo_id, facultad.facultad_id) = (:periodo_id, COALESCE(:facultad_id, facultad.facultad_id))
),
fechas AS (
SELECT fechas_clase(h.horario_id, true) as registro_fecha_ideal, h.horario_id
FROM horarios h
),
sin_registro AS (
SELECT * FROM ESTADO_SUPERVISOR WHERE (estado_color, estado_icon) = ('dark', 'ing-cancelar')
)
SELECT
usuario.*, registro.*, profesor.*, horarios.*, fechas.*,
COALESCE(estado_supervisor.estado_supervisor_id, sin_registro.estado_supervisor_id) as estado_supervisor_id,
COALESCE(estado_supervisor.nombre, sin_registro.nombre) as nombre,
COALESCE(estado_supervisor.estado_color, sin_registro.estado_color) as estado_color,
COALESCE(estado_supervisor.estado_icon, sin_registro.estado_icon) as estado_icon,
justificador.usuario_nombre as justificador_nombre,
justificador.usuario_clave as justificador_clave,
facultad.facultad_nombre as justificador_facultad,
rol.rol_titulo as justificador_rol
FROM horarios
JOIN fechas using (horario_id)
JOIN horario_profesor using (horario_id)
JOIN profesor using (profesor_id)
LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
LEFT join estado_supervisor using (estado_supervisor_id)
CROSS JOIN sin_registro
LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id
LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id
LEFT JOIN ROL on ROL.rol_id = justificador.rol_id
left join facultad on facultad.facultad_id = justificador.facultad_id
WHERE (fechas.registro_fecha_ideal + HORARIO_HORA) BETWEEN
GREATEST(HORARIO_FECHA_INICIO, PERIODO_FECHA_INICIO, :fecha_inicio) AND LEAST(:fecha_fin, PERIODO_FECHA_FIN, HORARIO_FECHA_FIN)
ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
$params
);
// $user->print_to_log(json_encode($params));
echo json_encode(array_merge($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} 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;
}