Añadir justificaciones
This commit is contained in:
@@ -25,18 +25,29 @@ try {
|
||||
SELECT fechas_clase(h.horario_id) as registro_fecha_ideal, h.horario_id
|
||||
FROM horarios h
|
||||
)
|
||||
SELECT estado_supervisor.*, usuario.*, registro.*, profesor.*, horarios.*, fechas.*
|
||||
SELECT estado_supervisor.*, usuario.*, registro.*, profesor.*, horarios.*, fechas.*,
|
||||
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)
|
||||
LEFT join estado_supervisor using (estado_supervisor_id)
|
||||
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 BETWEEN COALESCE(:fecha_inicio, LEAST(CURRENT_DATE, PERIODO_FECHA_FIN)) AND COALESCE(:fecha_fin, LEAST(CURRENT_DATE, PERIODO_FECHA_FIN))
|
||||
ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
|
||||
[
|
||||
':periodo_id' => $user->periodo_id,
|
||||
':facultad_id' => $user->facultad['facultad_id'],
|
||||
':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? null,
|
||||
':fecha_fin' => $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user