Files
paad/action/action_auditoria.php
Your Name c980c5aecd Final
2025-02-17 14:55:02 -06:00

94 lines
3.1 KiB
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') {
// pg_send_query($db->getConnection(), "REFRESH MATERIALIZED VIEW CONCURRENTLY PUBLIC.AUDITORIA_MAT");
$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',
'registro_fecha_ideal',
'horario_id',
'profesor_id',
'salon',
'profesor_clave',
'profesor_nombre',
'horario_hora',
'horario_fin',
'registro_fecha',
'color',
'estado_color',
'estado_icon',
'estado_supervisor_id',
'facultad_id',
'usuario_nombre',
'registro_fecha_supervisor',
'comentario',
'registro_justificada',
'justificacion',
'reposicion_id'
];
$relevant_columns_string = implode(', ', $relevant_columns);
$_SESSION['fecha_inicio'] = $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d');
$_SESSION['fecha_fin'] = date('Y-m-d H:i:s', strtotime(($baseDate ?? 'now') . ' +24 hours'));
$data = $db->query(
"SELECT $relevant_columns_string FROM PUBLIC.AUDITORIA_MAT
WHERE FACULTAD_ID = COALESCE(:facultad_id, FACULTAD_ID)
AND REGISTRO_FECHA_IDEAL + HORARIO_HORA between :fecha_inicio AND :fecha_fin
ORDER BY registro_fecha_ideal, horario_hora",
[
':facultad_id' => $user->facultad['facultad_id'],
':fecha_inicio' => $_SESSION['fecha_inicio'],
':fecha_fin' => $_SESSION['fecha_fin'],
]
);
echo json_encode($data);
} 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;
}