- Justificar
- {{store.current.justificada.nombre.toUpperCase()}} del día {{store.current.justificada.registro_fecha_ideal}} a
- las {{store.current.justificada.horario_hora?.slice(0,5)}}
- para el profesor {{store.current.justificada.profesor_nombre}}
+ Justificar
+ {{store.current.justificada.nombre}} del día {{store.current.justificada.registro_fecha_ideal}} a
+ las {{store.current.justificada.horario_hora?.slice(0,5)}}
+ para el profesor {{store.current.justificada.profesor_nombre}}
diff --git a/class/c_login.php b/class/c_login.php
index f3e365e..bfb6e3a 100644
--- a/class/c_login.php
+++ b/class/c_login.php
@@ -18,8 +18,38 @@ require_once($ruta ?? '') . "vendor/autoload.php";
class Login
{
- public ?string $acceso;
- public function __construct(public array $user, public array $facultad, public array $rol, public bool $admin, public ?int $periodo_id, public bool $supervisor, public bool $jefe_carrera, public bool $profesor)
+ private function es_usuario(): bool
+ {
+ global $db;
+ return $db->where('usuario_clave', $this->user['clave'])->has("usuario");
+ }
+ public function __get($property)
+ {
+ global $db;
+ return match ($property) {
+ 'acceso' => $this->access(),
+ 'profesor' => $db->where('profesor_clave', preg_replace('/\D/', '', $this->user['clave']))->getOne("profesor")['profesor_id'] ?? null,
+ 'jefe_de_carrera' => $db->where('usuario_id', $this->user["id"])->has('usuario_carrera'),
+ 'periodo_id' => $db->where('usuario_id', $this->user["id"])->getOne('usuario')["periodo_id"],
+ 'admin' => $this->es_usuario() and $db->where('usuario_id', $this->user["id"])->getOne('usuario')["usuario_admin"],
+ 'facultad' => $this->es_usuario()
+ ? $db
+ ->where('usuario_id', $this->user["id"])
+ ->join('facultad', 'facultad.facultad_id = usuario.facultad_id', 'LEFT')
+ ->getOne('usuario', 'facultad.facultad_nombre as facultad, facultad.facultad_id')
+ : array ('facultad' => null, 'facultad_id' => null),
+ 'rol' => $this->es_usuario()
+ ? $db
+ ->join('rol', 'rol.rol_id = usuario.rol_id')
+ ->where('usuario_id', $this->user["id"])
+ ->getOne('usuario', 'rol.rol_titulo as rol, rol.rol_id')
+ : $db
+ ->where('rol_titulo', 'docente', 'ILIKE')
+ ->getOne('rol', 'rol.rol_titulo as rol, rol.rol_id'),
+ default => throw new Exception("Propiedad no definida"),
+ };
+ }
+ public function __construct(public array $user)
{
}
public function print_to_log(string $desc, array $old = null, array $new = null): void
@@ -31,40 +61,17 @@ class Login
$desc .= " |#| NEW:" . json_encode($new);
$log->appendLog($this->user["id"], $this->user["nombre"], $desc);
}
- public function access(string $pagina = null): void
+ public function access(string $pagina = null): string|null
{
global $db;
- $user = $db
- ->join('rol', 'rol.rol_id = usuario.rol_id')
- ->join('facultad', 'facultad.facultad_id = usuario.facultad_id', 'LEFT')
- ->where('usuario_id', $this->user["id"])
- ->getOne('usuario');
-
- $this->admin = $user["usuario_admin"];
-
- $this->rol = array(
- 'id' => $user["rol_id"],
- 'rol' => $user["rol_titulo"]
- );
-
- $this->facultad = array(
- 'facultad_id' => $user["facultad_id"],
- 'facultad' => $user["facultad_nombre"],
- );
-
- if ($this->admin) {
- $this->acceso = "w";
- return;
- }
-
- # print_r( $access );
+ if ($this->admin)
+ return "w";
$acceso = $db
->where('id', $this->user["id"])
->where('pagina_ruta', $pagina ?? substr(basename($_SERVER['PHP_SELF']), 0, -4))
->getOne('permiso_view');
- $this->acceso = isset($acceso["tipo"]) ? $acceso["tipo"] : null;
-
+ return isset($acceso["tipo"]) ? $acceso["tipo"] : null;
}
private static function validaUsuario($user, $pass): bool
{
@@ -84,82 +91,32 @@ class Login
}
public static function validUser(string $user, string $pass): Login|array
{
- if (Login::validaUsuario($user, $pass) === false) {
- return [
- 'error' => true,
- 'msg' => 'Error al autenticar usuario'
- ];
- }
global $db;
+ if (!Login::validaUsuario($user, $pass))
+ return ['error' => true, 'msg' => 'Error al autenticar usuario'];
+
if ($db->has("FS_VALIDACLAVEULSA('$user')")) {
- #die (Login::validaUsuario($user, $pass));
- $fs_validaclaveulsa = $db->querySingle(
- 'SELECT * FROM FS_VALIDACLAVEULSA(?)',
- [$user]
- );
+ $fs = $db->querySingle('SELECT * FROM FS_VALIDACLAVEULSA(?)', [$user]);
+ return new Login(user: ['id' => $fs["id"], 'nombre' => $fs["nombre"], 'clave' => $fs["clave"]]);
+ }
- $user = array(
- 'id' => $fs_validaclaveulsa["id"],
- 'nombre' => $fs_validaclaveulsa["nombre"],
- 'clave' => $db->where('usuario_id', $fs_validaclaveulsa["id"])->getOne("usuario")["usuario_clave"]
- );
- $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');
+ $profesorClave = preg_replace('/\D/', '', $user);
+ if ($db->where('profesor_clave', $profesorClave)->has("profesor")) {
+ $profesor = $db->where('profesor_clave', $profesorClave)->getOne("profesor");
+ return new Login(user: ['id' => $profesor["profesor_id"], 'nombre' => $profesor["profesor_nombre"], 'clave' => $profesor["profesor_clave"]]);
+ }
- $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), 'ilike')->has("profesor")) {
- $profesor = $db->where('profesor_clave', preg_replace('/^do0*/', '', $user), 'ilike')->getOne("profesor");
- $user = array(
- 'id' => $profesor["profesor_clave"],
- 'nombre' => $profesor["profesor_nombre"],
- );
- $facultad = array(
- 'facultad_id' => null,
- 'facultad' => null,
- );
- $rol = array(
- 'id' => null,
- 'rol' => 'Docente'
- );
-
- // 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: false, periodo_id: null, supervisor: false, jefe_carrera: false, profesor: true);
- } else
- return [
- 'error' => true,
- 'msg' => 'Usuario no encontrado'
- ];
+ return ['error' => true, 'msg' => 'Usuario no encontrado'];
}
+
+
public static function log_out(): void
{
session_start();
session_destroy();
}
- private static function is_logged(): bool
- {
- return isset($_SESSION["user"]);
- }
-
- // get the user from the session (if not )
-
public static function get_user(): Login
{
if (Login::is_logged()) {
@@ -169,4 +126,8 @@ class Login
header("Location: /");
exit();
}
+ private static function is_logged(): bool
+ {
+ return isset($_SESSION["user"]);
+ }
}
\ No newline at end of file
diff --git a/js/auditoría.js b/js/auditoría.js
index 2399f56..f00bfc8 100644
--- a/js/auditoría.js
+++ b/js/auditoría.js
@@ -171,10 +171,15 @@ const store = reactive({
if (fecha_fin)
params['fecha_fin'] = fecha_fin;
const paramsUrl = new URLSearchParams(params).toString();
- const res = await fetch(`action/action_auditoria.php?${paramsUrl}`, {
- method: 'GET',
- });
- this.data = await res.json();
+ try {
+ const res = await fetch(`action/action_auditoria.php?${paramsUrl}`, {
+ method: 'GET',
+ });
+ this.data = await res.json();
+ }
+ catch (error) {
+ alert('Error al cargar los datos');
+ }
this.loading = false;
store.current.page = 1;
},
diff --git a/reposiciones_crear.php b/reposiciones_crear.php
index 36c214e..27b9f05 100644
--- a/reposiciones_crear.php
+++ b/reposiciones_crear.php
@@ -1,16 +1,27 @@
profesor);
-print_r($user->acceso);//null sin permisos, w o r
-//profesor, admin, rol, facultad
-if (!$user->profesor && !$user->admin){
+if (!isset($_SESSION['user'])){
die(header('Location: index.php'));
}
+//$user = unserialize($_SESSION['user']);
+$user = Login::get_user();
+print_r($user);
+print_r($user->user["id"]);
+echo "****|";
+$user->access();
+print_r($user->acceso);//null sin permisos, w o r
+echo "|****|";
+print_r($user->profesor);
+echo "|****|";
+print_r($user->facultad["facultad_id"]);
+//profesor, admin, rol, facultad
+/*if ($user->acceso === null || !$user->admin){
+ die(header('Location: index.php'));
+ exit();
+}*/
+
//if (!$user->admin && in_array($user->acceso, ['n']))
//die(header('Location: main.php?error=1'));
@@ -21,10 +32,10 @@ $write = true; //
$en_fecha = $db->querySingle("SELECT ESTA_EN_PERIODO(NOW()::DATE, :periodo_id)", [':periodo_id' => $user->periodo_id])['esta_en_periodo'];
-$prof_rs = $db->query('SELECT * FROM profesor A WHERE EXISTS (
- SELECT * FROM horario_view hv join HORARIO_PROFESOR ON hv.HORARIO_ID = HORARIO_PROFESOR.horario_id WHERE HORARIO_PROFESOR.profesor_id = A.profesor_id AND hv.periodo_id = :periodo_id
-) ORDER BY profesor_nombre', [':periodo_id' => $user->periodo_id]);
+if($user->jefe_carrera){
+ $prof_rs = $db->query('SELECT DISTINCT * FROM fs_profesores(null, null, :fac) ORDER BY PROFESOR_NOMBRE', [':fac' => $user->facultad["facultad_id"]]);
+}
//Periodo
$periodo_rs = $db->querySingle('SELECT periodo_fecha_inicio, periodo_fecha_fin FROM periodo WHERE periodo_id = :periodo_id', [':periodo_id' => $user->periodo_id]);
@@ -42,12 +53,12 @@ else{
$fecha_man = date("d/m/Y", strtotime("+".$dias." day"));
}
-
+/*
// Materias
-$id_prof = $user->user["id"];
+$id_prof = $user->profesor;
//$facultad_id = 28;
$materias_rs = $db->query('SELECT * FROM fs_materiasprofesor(:id)', [':id' => $id_prof]);
-
+*/
if(isset($_POST["fecha_inicial"]))
$fecha_ini = $_POST["fecha_inicial"];
else
@@ -65,36 +76,28 @@ $fecha_fin_db= date("Y-m-d", strtotime($fecha_fin));
- Reposiciones crear | = $user->facultad['facultad'] ?? 'General' ?>
-
-
-
-
-
+
+
+ Reposiciones crear |
+ = $user->facultad['facultad'] ?? "Administrador"; ?>
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -105,11 +108,11 @@ $fecha_fin_db= date("Y-m-d", strtotime($fecha_fin));
?>
-
+ 0) {?>