Stable 2-ago-2023

This commit is contained in:
2023-08-02 09:12:46 -06:00
parent 6a7c6b7ed9
commit f0cc3c585d
60 changed files with 6497 additions and 908 deletions

View File

@@ -0,0 +1,57 @@
<?
#input $_GET['id_espacio_sgu']
#output rutas: [ ...ruta, salones: [{...salon}] ]
header('Content-Type: application/json charset=utf-8');
$information = [
'GET' => [
#'periodo_id',
],
];
$ruta = "../";
require_once "../class/c_login.php";
// check method
try {
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
array_walk($information['GET'], function ($value) {
if (!array_key_exists($value, $_GET)) {
http_response_code(400);
echo json_encode(['error' => "$value is required"]);
exit;
}
});
$data = $db->query("SELECT *, horario_view.facultad_id FROM registro
JOIN horario_view USING (horario_id)
LEFT JOIN estado_supervisor USING (estado_supervisor_id)
LEFT JOIN profesor USING (profesor_id)
LEFT JOIN usuario ON usuario.usuario_id = registro.supervisor_id
ORDER BY registro_fecha_ideal DESC, horario_hora ASC, registro_fecha_supervisor ASC");
$last_query = [
'query' => $db->getLastQuery(),
];
echo json_encode($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);
exit;
} catch (Exception $th) {
http_response_code(500);
echo json_encode([
'error' => $th->getMessage(),
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
exit;
}

View File

@@ -0,0 +1,42 @@
<?
#input $_GET['id_espacio_sgu']
define("INFORMATION", [
'GET' => [
],
]);
#output rutas: [ ...ruta, salones: [{...salon}] ]
header('Content-Type: application/json charset=utf-8');
#return html
$ruta = "../";
require_once "../class/c_login.php";
// check method
try {
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// check parameters
$raw = file_get_contents('php://input');
$post_get = json_decode($raw, true);
$data = $db->get('estado_supervisor');
echo json_encode($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(),
'post_data' => $post_get,
], 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;
}

View File

@@ -1,11 +1,51 @@
<?php
<?
$information = [
'GET' => [],
];
header('Content-Type: application/json charset=utf-8');
$ruta = "../";
require_once "../class/c_login.php";
// check if the session is started
if (!isset($_SESSION['user']))
die(json_encode(['error' => 'No se ha iniciado sesión']));
if (!isset($_SESSION['user'])) {
http_response_code(500);
echo json_encode([
'error' => 'No se ha iniciado sesión'
]);
exit;
}
$user = unserialize($_SESSION['user']);
$ruta = "../";
require '../include/bd_pdo.php';
try {
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// check parameters
array_walk($information['GET'], function ($value) {
if (!array_key_exists($value, $_GET)) {
http_response_code(400);
echo json_encode(['error' => "$value is required"]);
exit;
}
});
// step 1: get subrutas
$data = $db->get('facultad');
echo json_encode($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);
exit;
} catch (Exception $th) {
http_response_code(500);
echo json_encode([
'error' => $th->getMessage(),
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
exit;
}

View File

@@ -0,0 +1,26 @@
<?php
$ruta = "../";
require_once "../class/c_login.php";
if (!isset($_SESSION['user']))
die(json_encode(['error' => 'No se ha iniciado sesión']));
$user = unserialize($_SESSION['user']);
$ruta = "../";
require_once "../include/bd_pdo.php";
// if method is get
header("Content-Type: application/json");
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$user->print_to_log("Acceso a reposiciones");
if (empty($_GET['horario_id']))
die(json_encode(['error' => 'No se ha enviado el id del horario']));
// fecha greater than today
$reposiciones = $db->query("SELECT fecha, EXTRACT(DOW FROM fecha) as day, EXTRACT(MONTH FROM fecha) as month, EXTRACT(YEAR FROM fecha) as year, EXTRACT(DAY FROM fecha) as dia_mes FROM fechas_clase(:horario_id) WHERE fecha > CURRENT_DATE", [
'horario_id' => $_GET['horario_id']
]);
echo json_encode([
'status' => 'success',
'data' => $reposiciones
]);
}

View File

@@ -10,13 +10,12 @@ $user = unserialize($_SESSION['user']);
$ruta = "../";
require_once("../include/bd_pdo.php");
extract($_POST);
$params = ['per' => $periodo, 'fac' => $facultad, 'car' => $carrera];
$params = ['per' => $_POST['periodo'], 'fac' => $_POST['facultad'], 'car' => $_POST['carrera']];
$user->print_to_log("Acceso a grupos", old: $params);
$grupos = queryAll("SELECT DISTINCT LENGTH(GRUPO), GRUPO FROM fs_horario_basic WHERE PERIODO_ID = COALESCE(:per, PERIODO_ID) AND FACULTAD_ID = COALESCE(:fac, FACULTAD_ID) AND CARRERA_ID = COALESCE(:car, CARRERA_ID) ORDER BY LENGTH(GRUPO), GRUPO", $params);
$grupos = array_map(function ($grupo) {
return $grupo['grupo'];
}, $grupos);
$grupos = array_map(fn ($grupo) => $grupo['grupo'], $grupos);
echo json_encode([
'status' => 'success',

View File

@@ -0,0 +1,28 @@
<?php
header('Content-Type: application/json');
$ruta = "../";
require_once("../include/bd_pdo.php");
$grupo = isset($_GET['grupo']) ? $_GET['grupo'] : 1;
$grupo_horarios = $db->querySingle(
"WITH bloques AS (
SELECT id, hora_inicio, hora_fin
FROM public.bloque_horario
WHERE grupo = ?
ORDER BY hora_inicio ASC
)
SELECT json_agg(json_build_object(
'id', id,
'hora_inicio', hora_inicio,
'hora_fin', hora_fin,
'selected', current_time between hora_inicio and hora_fin
)) AS bloque_horario
FROM bloques
",
[$grupo]
)['bloque_horario'];
echo $grupo_horarios;

View File

@@ -1,4 +1,38 @@
<?php
die(json_encode([
'message' => 'ok',
]));
header('Content-Type: application/json');
$ruta = "../";
require_once("../include/bd_pdo.php");
$dias = array("domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado");
try {
if(empty($_POST['profesor_id']))
throw new Exception("No se ha especificado un profesor");
// RECORD LAST QUERY
$horarios = $db->query("SELECT * FROM fs_horario(_periodo_id => ?, _last => true, _profesor_id => ?) ORDER BY MATERIA", [
$_POST['periodo_id'],
$_POST['profesor_id'],
]);
$horarios = array_map(function ($horario) use ($dias, $db) {
$horario['profesores'] = array_map(
fn ($profesor) =>
$db->where("id", $profesor)->getOne("fs_profesor"),
explode(",", substr($horario['profesores'], 1, -1))
);
$horario['dia'] = $dias[$horario['dia']];
return $horario;
}, $horarios);
die(json_encode([
"status" => "success",
"data" => $horarios,
// "data" => [],
]));
} catch (Exception $e) {
die(json_encode([
"status" => "error",
"message" => $e->getMessage(),
"query" => $db->getLastQuery(),
]));
}

View File

@@ -1,40 +1,43 @@
<?php
/*
* Valida usuario con la BD y devuelve contraseña para validar con PHP
*
* Recibe:
* POST: usuario, password
*
* Error:
* 0 - No se recibieron datos
* 1 - Usuario/Contraseña incorrectos
* 2 - Usuario no esta en BD
* 3 - No existe usuario
*
* Success:
* Redirecciona a inicio.php
*/
include_once("../include/nocache.php"); //continue on error
$ruta = "../";
require_once("../include/bd_pdo.php"); //die on error
require_once("../class/c_login.php");
require_once("../include/util.php");
require_once("../include/nusoap/nusoap.php");
<?php
/*
* Valida usuario con la BD y devuelve contraseña para validar con PHP
*
* Recibe:
* POST: usuario, password
*
* Error:
* 0 - No se recibieron datos
* 1 - Usuario/Contraseña incorrectos
* 2 - Usuario no esta en BD
* 3 - No existe usuario
*
* Success:
* Redirecciona a inicio.php
*/
include_once("../include/nocache.php"); //continue on error
$ruta = "../";
require_once("../include/bd_pdo.php"); //die on error
require_once("../class/c_login.php");
require_once("../include/util.php");
require_once("../include/nusoap/nusoap.php");
if (!isset($_POST["username"]) || !isset($_POST["passwd"]))
die(header("Location: ../index.php?error=0"));
if (!isset($_POST["username"]) || !isset($_POST["passwd"]))
die(header("Location: ../index.php?error=0"));
$usr = trim(filter_input(INPUT_POST, "username")); //limpia texto
$pass = $_POST["passwd"];
$usr = trim(filter_input(INPUT_POST, "username")); //limpia texto
$pass = $_POST["passwd"];
$user = Login::validUser($usr, $pass);
$user = Login::validUser($usr, $pass);
if ($user === false) {
$_SESSION['error'] = true;
header("Location: ../");
} else {
$_SESSION['user'] = serialize($user);
header("Location: ../main.php");
}
if (is_array($user)) {
$_SESSION['error'] = true;
// build query params
$params = http_build_query($user);
header("Location: ../index.php?$params");
} else {
$_SESSION['user'] = serialize($user);
exit;
header("Location: " . (isset($_SESSION['ruta']) ? $_SESSION['ruta'] : "../main.php"));
}
exit;

View File

@@ -0,0 +1,54 @@
<?php
$ruta = "../";
require_once "../class/c_login.php";
if (!isset($_SESSION['user']))
die(json_encode(['error' => 'No se ha iniciado sesión']));
$user = unserialize($_SESSION['user']);
$ruta = "../";
require_once "../include/bd_pdo.php";
// if method is get
header("Content-Type: application/json");
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$user->print_to_log("Acceso a reposiciones");
$reposiciones = $db
->where('periodo_id', $_GET['periodo_id'] ?? null)
->where('profesor_id', $_GET['profesor_id'] ?? [])
->get("reposicion");
echo json_encode([
'status' => 'success',
'reposiciones' => $reposiciones
]);
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$user->print_to_log("Creación de reposición", new: $params);
try {
$requiredParams = ['horario_id', 'fecha', 'hora', 'duracion_id', 'descripcion', 'profesor_id', 'salon', 'unidad', 'periodo_id', 'fecha_clase'];
// Filter params based on requiredParams
$params = array_filter($_POST, function ($key) use ($requiredParams) {
return in_array($key, $requiredParams);
}, ARRAY_FILTER_USE_KEY);
// Check if all required params are present
if (count($params) !== count($requiredParams)) {
throw new Exception('Falta uno o más parámetros requeridos');
}
$db->insert("reposicion", $params);
// Return success response
echo json_encode([
"status" => "success",
"message" => "Reposición creada correctamente",
]);
} catch (Exception $e) {
// Return error response
echo json_encode([
"status" => "error",
"message" => "No se pudo crear la reposición",
"error" => $e->getMessage(),
]);
}
}

View File

@@ -29,8 +29,8 @@ $user = [
];
$user = new Login($user, $facultad, $rol, $admin, $periodo);
session_start();
if (isset($_SESSION))
session_start();
$_SESSION['user'] = serialize($user);
header("Location: ../main.php");

View File

@@ -0,0 +1,60 @@
<?
#input $_GET['id_espacio_sgu']
define("INFORMATION", [
'POST' => [
'profesor_id',
'horario_id',
'estado',
'comentario',
'supervisor_id',
],
]);
#output rutas: [ ...ruta, salones: [{...salon}] ]
header('Content-Type: application/json charset=utf-8');
#return html
$ruta = "../";
require_once "../class/c_login.php";
// check method
try {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 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->query(
'INSERT INTO registro (profesor_id, horario_id, registro_fecha_supervisor, estado_supervisor_id, registro_fecha_ideal, supervisor_id, comentario)
VALUES' .
implode(',', array_map(fn($x) => "({$x['profesor_id']} , {$x['horario_id']}, NOW()," . (is_null($x['estado']) ? 'null' : $x['estado']) . ", NOW(), {$x['supervisor_id']}," . (empty($x['comentario']) ? 'null' : "'{$x['comentario']}'") . ')', $post_data))
. ' ON CONFLICT (profesor_id, horario_id, registro_fecha_ideal) DO UPDATE SET estado_supervisor_id = EXCLUDED.estado_supervisor_id, registro_fecha_supervisor = NOW(), comentario = EXCLUDED.comentario
RETURNING *'
);
echo json_encode($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(),
'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;
}

28
action/rutas.php Normal file
View File

@@ -0,0 +1,28 @@
<?
header('Content-Type: application/json charset=utf-8');
$ruta = "../";
require_once "../class/c_login.php";
$universidad_la_salle = $db
->where('salon', 'UNIVERSIDAD LA SALLE', 'ILIKE')
->getOne('salon_view');
$rutas =
array_map(
function (&$ruta) use ($db) {
$ruta['subrutas'] =
$db
->where('id_espacio_padre', $ruta['id_espacio_sgu'])
->orderBy('salon')
->get('salon_view');
return $ruta;
},
$db
->where('id_espacio_padre', $universidad_la_salle['id_espacio_sgu'])
->orderBy('salon')
->get('salon_view')
);
// echo json_encode($universidad_la_salle, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); EXIT;
echo json_encode($rutas, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

View File

@@ -0,0 +1,73 @@
<?
#input $_GET['id_espacio_sgu']
$information = [
'GET' => [
'id_espacio_sgu',
'bloque_horario_id',
],
];
#output rutas: [ ...ruta, salones: [{...salon}] ]
header('Content-Type: application/json charset=utf-8');
$ruta = "../";
require_once "../class/c_login.php";
// check method
try {
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// check parameters
array_walk($information['GET'], function ($value) {
if (!array_key_exists($value, $_GET)) {
http_response_code(400);
echo json_encode(['error' => "$value is required"]);
exit;
}
});
// step 1: get subrutas
$data = $db
->where('tiene_salones')
->where("{$_GET['id_espacio_sgu']} = ANY(id_espacio_sgu_array)")
->get('salon_view');
// step 3: get horarios
$data = array_map(
fn($ruta) => array_merge(
[
'horarios' => $db
->join('periodo', 'periodo.periodo_id = horario_view.periodo_id')
->join('bloque_horario', '(bloque_horario.hora_inicio, bloque_horario.hora_fin) OVERLAPS (horario_view.horario_hora, horario_view.horario_hora + horario_view.duracion)')
->join('salon_view', 'salon_view.salon_id = horario_view.salon_id')
->join('horario_profesor', 'horario_profesor.horario_id = horario_view.horario_id')
->join('profesor', 'profesor.profesor_id = horario_profesor.profesor_id')
->join('registro', '(registro.profesor_id, registro.horario_id, registro.registro_fecha_ideal) = (profesor.profesor_id, horario_view.horario_id, CURRENT_DATE)', 'LEFT')
->where('CURRENT_DATE BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin')
->where('horario_dia = EXTRACT(DOW FROM CURRENT_DATE)')
->where('bloque_horario.id', $_GET['bloque_horario_id'])
->where('id_espacio_padre', $ruta['id_espacio_sgu'])
->get('horario_view', null, '*, horario_view.horario_id, profesor.profesor_id'),
],
$ruta
),
$data
);
echo json_encode($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);
exit;
} catch (Exception $th) {
http_response_code(500);
echo json_encode([
'error' => $th->getMessage(),
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
exit;
}

View File

@@ -0,0 +1,24 @@
{
"type": "array",
"items": {
"type": "object",
"properties": {
"profesor_id": {
"type": "integer"
},
"horario_id": {
"type": "integer"
},
"estado": {
"type": ["integer", "null"]
},
"comentario": {
"type": "string"
},
"supervisor_id": {
"type": "integer"
}
},
"required": ["profesor_id", "horario_id", "comentario", "supervisor_id"]
}
}