Añadir justificaciones

This commit is contained in:
2023-08-16 19:19:00 +00:00
parent 094cf8b611
commit 9ce1dee313
5 changed files with 422 additions and 137 deletions

View File

@@ -1,33 +1,80 @@
<?php
<?
header('Content-Type: application/json charset=utf-8');
#return html
$ruta = "../";
require_once "../class/c_login.php";
// check method
extract($_POST);
/* print_r($claves);
exit; */
$fecha = DateTime::createFromFormat('d/m/Y', $fecha);
if (isset($hora)) {
$claves = [[
'clave' => $clave,
'hora' => $hora,
'id' => $id
]];
if (!isset($_SESSION['user'])) {
http_response_code(401);
echo json_encode(['error' => 'unauthorized']);
exit;
}
foreach ($claves as $horario)
try {
$profesor_id = $horario["clave"];
query("SELECT fi_registrar_asistencia(:id::INT, FALSE, ARRAY[ NOW(), :fecha::DATE + :hora::TIME ]::TIMESTAMP[], :profesor_id::INT, TRUE)", [
":fecha" => $fecha->format('Y-m-d'),
":hora" => $horario["hora"],
":id" => $horario["id"],
":profesor_id" => $profesor_id
]);
}
catch (Exception $e) {
die( json_encode(["error" => $e->getMessage()]) );
$user = unserialize($_SESSION['user']);
try {
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
// check parameters
$raw = file_get_contents('php://input');
$post_data = json_decode($raw, true);
// if it's a list
// step 1: get subrutas
if (empty($post_data)) {
http_response_code(400);
echo json_encode(['error' => 'No hay clases pendientes']);
exit;
}
$data = $db->querySingle(
'INSERT INTO registro (profesor_id, horario_id, registro_fecha_ideal, registro_justificada, justificador_id, registro_fecha_justificacion, justificacion)
VALUES (:profesor_id, :horario_id, :registro_fecha_ideal, :registro_justificada, :justificador_id, NOW(), :justificacion)
ON CONFLICT (profesor_id, horario_id, registro_fecha_ideal)
DO UPDATE SET registro_justificada = :registro_justificada, justificador_id = :justificador_id, registro_fecha_justificacion = NOW(), justificacion = :justificacion
RETURNING *',
array(
'profesor_id' => $post_data['profesor_id'],
'horario_id' => $post_data['horario_id'],
'registro_fecha_ideal' => $post_data['registro_fecha_ideal'],
'registro_justificada' => $post_data['registro_justificada'],
'justificador_id' => $user->user['id'],
'justificacion' => empty($post_data['justificacion']) ? null : $post_data['justificacion'],
)
);
$data_justificador = $db->querySingle(
"SELECT 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 USUARIO JUSTIFICADOR
JOIN ROL on ROL.rol_id = justificador.rol_id
LEFT JOIN facultad on facultad.facultad_id = justificador.facultad_id
where justificador.usuario_id = :justificador_id",
array(
'justificador_id' => $user->user['id'],
)
);
echo json_encode(array_merge($data, $data_justificador), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} else {
http_response_code(405);
echo json_encode(['error' => 'method not allowed']);
exit;
}
die(json_encode(["success" => true]));
} catch (PDOException $th) {
http_response_code(500);
echo json_encode([
'error' => $th->getMessage(),
'query' => $db->getLastQuery(),
'post_data' => $post_data,
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
exit;
} catch (Exception $th) {
http_response_code(500);
echo json_encode([
'error' => $th->getMessage(),
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
exit;
}