diff --git a/action/action_auditoria.php b/action/action_auditoria.php new file mode 100644 index 0000000..5ee4c21 --- /dev/null +++ b/action/action_auditoria.php @@ -0,0 +1,57 @@ + [ + #'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; +} \ No newline at end of file diff --git a/action/action_estado_supervisor.php b/action/action_estado_supervisor.php new file mode 100644 index 0000000..f15d457 --- /dev/null +++ b/action/action_estado_supervisor.php @@ -0,0 +1,42 @@ + [ + ], +]); +#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; +} \ No newline at end of file diff --git a/action/action_facultad.php b/action/action_facultad.php index 6592ffe..3b612e8 100644 --- a/action/action_facultad.php +++ b/action/action_facultad.php @@ -1,11 +1,51 @@ - [], +]; +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; +} \ No newline at end of file diff --git a/action/action_fechas_clase.php b/action/action_fechas_clase.php new file mode 100644 index 0000000..afefd3e --- /dev/null +++ b/action/action_fechas_clase.php @@ -0,0 +1,26 @@ + '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 + ]); +} diff --git a/action/action_grupo.php b/action/action_grupo.php index 89aab75..64b583f 100644 --- a/action/action_grupo.php +++ b/action/action_grupo.php @@ -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', diff --git a/action/action_grupo_horario.php b/action/action_grupo_horario.php new file mode 100644 index 0000000..b8a24e1 --- /dev/null +++ b/action/action_grupo_horario.php @@ -0,0 +1,28 @@ +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; \ No newline at end of file diff --git a/action/action_horario_profesor.php b/action/action_horario_profesor.php index 02945ec..2f19c48 100644 --- a/action/action_horario_profesor.php +++ b/action/action_horario_profesor.php @@ -1,4 +1,38 @@ 'ok', -])); \ No newline at end of file +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(), + ])); +} diff --git a/action/action_login.php b/action/action_login.php index ba30432..c18661d 100644 --- a/action/action_login.php +++ b/action/action_login.php @@ -1,40 +1,43 @@ - '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(), + ]); + } +} diff --git a/action/force_session.php b/action/force_session.php index 504ce04..5902baa 100644 --- a/action/force_session.php +++ b/action/force_session.php @@ -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"); diff --git a/action/registro_supervisor.php b/action/registro_supervisor.php new file mode 100644 index 0000000..0b8eb8b --- /dev/null +++ b/action/registro_supervisor.php @@ -0,0 +1,60 @@ + [ + '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; +} \ No newline at end of file diff --git a/action/rutas.php b/action/rutas.php new file mode 100644 index 0000000..de052f7 --- /dev/null +++ b/action/rutas.php @@ -0,0 +1,28 @@ +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); \ No newline at end of file diff --git a/action/rutas_salón_horario.php b/action/rutas_salón_horario.php new file mode 100644 index 0000000..e376af1 --- /dev/null +++ b/action/rutas_salón_horario.php @@ -0,0 +1,73 @@ + [ + '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; +} \ No newline at end of file diff --git a/action/schemas/registro_supervisor.json b/action/schemas/registro_supervisor.json new file mode 100644 index 0000000..90571c2 --- /dev/null +++ b/action/schemas/registro_supervisor.json @@ -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"] + } +} diff --git a/auditoría.php b/auditoría.php new file mode 100644 index 0000000..ea78891 --- /dev/null +++ b/auditoría.php @@ -0,0 +1,377 @@ + + + + + + + Supervisor + + + + + + + +
+
+
+
+ +
+
+
Selecciona una facultad
+ +
    +
  • + Todas las facultades +
  • +
  • + ( {{facultad.clave_dependencia}} ) {{ facultad.facultad_nombre }} +
  • +
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ + +
+ + +
+
+
+ +
+
+
+
Selecciona un estado de asistencia
+ +
    +
  • + Todos los registros +
  • +
  • + {{estado.nombre}} +
  • +
+ +
+
+
+
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Fecha + SalónProfesorHorarioRegistroSupervisor
No hay clases en este horario
{{ registro.registro_fecha_ideal }} + {{ registro.salon }} +
+ {{ registro.profesor_clave }} + {{ registro.profesor_nombre }} +
+
+ +
+
{{ registro.horario_hora.slice(0,5) }} - {{ + registro.horario_fin.slice(0,5) }} +
+
+ Registro {{ registro.registro_fecha.slice(11,16) }} +
+
+
+ +
+ +
+
+ Sin registro +
+
+
+
+
+
+
+ {{ registro.usuario_nombre }} +
+
+ Hora + {{ registro.registro_fecha_supervisor.slice(11,19) }} +
+
+ + + {{ registro.nombre }} + +
+
+ +
+
+ Observaciones: + {{registro.comentario.slice(0, + 25)}}{{registro.comentario.length > 10 ? '...' : ''}} +
+
+ + +
+
+ +
+
+ Sin registro +
+
+
+
+
+ + + + +
+ + + + + + + + + \ No newline at end of file diff --git a/bypass.php b/bypass.php index a9fa1af..0a6db29 100644 --- a/bypass.php +++ b/bypass.php @@ -1,5 +1,4 @@ appendLog($this->user["id"], $this->user["nombre"], $desc); } public function access(string $pagina = null): void @@ -25,63 +34,97 @@ class Login } # print_r( $access ); - $this->acceso = query('SELECT tipo FROM PERMISO_VIEW WHERE ID = :usr AND PAGINA_RUTA ILIKE :ruta', array( - ':usr' => $this->user["id"], - ':ruta' => $pagina ?? substr(basename($_SERVER['PHP_SELF']), 0, -4) - ))["tipo"] ?? 'n'; + $this->acceso = query( + 'SELECT tipo FROM PERMISO_VIEW WHERE ID = :usr AND PAGINA_RUTA ILIKE :ruta', + array( + ':usr' => $this->user["id"], + ':ruta' => $pagina ?? substr(basename($_SERVER['PHP_SELF']), 0, -4) + ) + )["tipo"] ?? 'n'; } public function __toString(): string { - return "Usuario: {$this->user["nombre"]} ({$this->user["id"]})"; + return "Usuario: {$this->user["nombre"]} ({$this->user["id"]}), Es admin: {$this->admin}, supervisor: {$this->supervisor}, jefe carrera: {$this->jefe_carrera}, profesor: {$this->profesor}"; } private static function validaUsuario($user, $pass): bool { file_put_contents('php://stderr', $user); - if (in_array($user, ['ad012821']) and $pass == "admin") return true; - if (in_array($user, ['ad017045']) and $pass == "admin") return true ; + if (in_array($user, ['ad017045']) and $pass == "admin") + return true; $client = new nusoap_client('http://200.13.89.2/validacion.php?wsdl', 'wsdl'); - $error = $client->getError(); - - if ($error) return false; - + $client->getError() and die('Error al crear el cliente: ' . $client->getError()); $pass = utf8_decode($pass); $result = $client->call("valida_user", array($user, $pass)); - - if ($client->fault) return false; - + $client->fault and die('Error al llamar al servicio: ' . $client->getError()); return $result; } - public static function validUser(string $user, string $pass): Login | false + public static function validUser(string $user, string $pass): Login|array { - $fs_validaclaveulsa = query( - 'SELECT * FROM FS_VALIDACLAVEULSA(:usr)', [':usr' => $user] - ); - - if (empty($fs_validaclaveulsa["id"])) return false; - #die (Login::validaUsuario($user, $pass)); - if (!Login::validaUsuario($user, $pass)) return false; - - $user = array( - 'id' => $fs_validaclaveulsa["id"], - 'nombre' => $fs_validaclaveulsa["nombre"], - ); - $facultades = query("SELECT FACULTAD_ID id, FACULTAD f FROM FS_PERIODO WHERE ID = :id", [':id' => $fs_validaclaveulsa["periodo_id"]]); - $facultad = array( - 'facultad_id' => $fs_validaclaveulsa["facultad_id"] ?? $facultades["id"], - 'facultad' => $fs_validaclaveulsa["facultad"] ?? $facultades["f"], - ); - $rol = array( - 'id' => $fs_validaclaveulsa["rol_id"], - 'rol' => $fs_validaclaveulsa["rol"] - ); + if (!Login::validaUsuario($user, $pass)) { + return [ + 'error' => true, + 'msg' => 'Error al autenticar usuario' + ]; + } + global $db; - $admin = $fs_validaclaveulsa["is_admin"]; - $periodo = $fs_validaclaveulsa["periodo_id"]; - return new Login($user, $facultad, $rol, $admin, $periodo); + if ($db->has("FS_VALIDACLAVEULSA('$user')")) { + #die (Login::validaUsuario($user, $pass)); + $fs_validaclaveulsa = $db->querySingle( + 'SELECT * FROM FS_VALIDACLAVEULSA(?)', + [$user] + ); + + $user = array( + 'id' => $fs_validaclaveulsa["id"], + 'nombre' => $fs_validaclaveulsa["nombre"], + ); + $facultad = array( + 'facultad_id' => $fs_validaclaveulsa["facultad_id"], + 'facultad' => $fs_validaclaveulsa["facultad"], + ); + $rol = array( + 'id' => $fs_validaclaveulsa["rol_id"], + 'rol' => $fs_validaclaveulsa["rol"] + ); + $supervisor = $db + ->join('rol', 'rol.rol_id = usuario.rol_id') + ->where('usuario_id', $user["id"]) + ->where('rol.rol_titulo', 'Supervisor') + ->has('usuario'); + $jefe_carrera = $db->where('usuario_id', $user["id"])->has('usuario_carrera'); + + $admin = $fs_validaclaveulsa["is_admin"]; + $periodo = $fs_validaclaveulsa["periodo_id"]; + + return new Login($user, $facultad, $rol, $admin, $periodo, $supervisor, $jefe_carrera, false); + } else if ($db->where('profesor_clave', preg_replace('/^do0*/', '', $user))->has("profesor")) { + $profesor = $db->where('profesor_clave', preg_replace('/^do0*/', '', $user))->getOne("profesor"); + $user = array( + 'id' => $profesor["profesor_clave"], + 'nombre' => $profesor["profesor_nombre"], + ); + $facultad = $rol = array( + 'facultad_id' => null, + 'facultad' => 'Docente', + ); + + $supervisor = false; + $jefe_carrera = false; + $admin = false; + $periodo = null; + // CREATE A COOKIE FOR THE REST OF THE day for example: 23:00 then duration will be 1 hour + setcookie("profesor", $user["id"], strtotime('today midnight') + 86400, "/"); + return new Login($user, $facultad, $rol, $admin, $periodo, $supervisor, $jefe_carrera, true); + } else + return [ + 'error' => true, + 'msg' => 'Usuario no encontrado' + ]; } public static function log_out(): void { session_start(); session_destroy(); } -} +} \ No newline at end of file diff --git a/composer.json b/composer.json index b138c13..89e8fe0 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "require": { "vlucas/phpdotenv": "^5.5", "phpoffice/phpspreadsheet": "^1.25", - "seinopsys/postgresql-database-class": "^3.1" + "seinopsys/postgresql-database-class": "^3.1", + "justinrainbow/json-schema": "^5.2" } } diff --git a/composer.lock b/composer.lock index 2e79493..8fc0a45 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5e701c768afe8ce8feabe1b539fa7234", + "content-hash": "2b67052b0f31b7059a262343c2640316", "packages": [ { "name": "ezyang/htmlpurifier", @@ -129,6 +129,76 @@ ], "time": "2022-07-30T15:56:11+00:00" }, + { + "name": "justinrainbow/json-schema", + "version": "5.2.12", + "source": { + "type": "git", + "url": "https://github.com/justinrainbow/json-schema.git", + "reference": "ad87d5a5ca981228e0e205c2bc7dfb8e24559b60" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/ad87d5a5ca981228e0e205c2bc7dfb8e24559b60", + "reference": "ad87d5a5ca981228e0e205c2bc7dfb8e24559b60", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", + "json-schema/json-schema-test-suite": "1.2.0", + "phpunit/phpunit": "^4.8.35" + }, + "bin": [ + "bin/validate-json" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "JsonSchema\\": "src/JsonSchema/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bruno Prieto Reis", + "email": "bruno.p.reis@gmail.com" + }, + { + "name": "Justin Rainbow", + "email": "justin.rainbow@gmail.com" + }, + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + }, + { + "name": "Robert Schönthal", + "email": "seroscho@googlemail.com" + } + ], + "description": "A library to validate a json schema.", + "homepage": "https://github.com/justinrainbow/json-schema", + "keywords": [ + "json", + "schema" + ], + "support": { + "issues": "https://github.com/justinrainbow/json-schema/issues", + "source": "https://github.com/justinrainbow/json-schema/tree/5.2.12" + }, + "time": "2022-04-13T08:02:27+00:00" + }, { "name": "maennchen/zipstream-php", "version": "2.2.1", diff --git a/consultar_horario.php b/consultar_horario.php index 5da5739..1b70d60 100644 --- a/consultar_horario.php +++ b/consultar_horario.php @@ -17,7 +17,9 @@ $write = $user->admin || in_array($user->acceso, ['w']); - Consultar horario | <?= $user->facultad['facultad'] ?? 'General' ?> + Consultar horario | + <?= $user->facultad['facultad'] ?? 'General' ?> + @@ -44,7 +46,7 @@ $write = $user->admin || in_array($user->acceso, ['w']); #$carreras = query("SELECT * FROM FS_CARRERA WHERE FACULTAD = :fac AND PERIODO = COALESCE(:per, PERIODO) ORDER BY CARRERA", [":fac" => $user->facultad['facultad_id'], ":per" => $user->periodo], single: false); // repliaction of the query in the database with database class $nivel = $user->periodo ? $db->where('id', $user->periodo)->getOne('fs_periodo') : false; - + $carreras = $nivel ? $db ->orderBy('carrera') ->where('facultad', $nivel['facultad_id']) @@ -61,11 +63,11 @@ $write = $user->admin || in_array($user->acceso, ['w']); @@ -91,7 +93,8 @@ $write = $user->admin || in_array($user->acceso, ['w']);
- @@ -127,7 +130,8 @@ $write = $user->admin || in_array($user->acceso, ['w']);
-