Ocultar domingos

This commit is contained in:
2023-09-04 14:50:00 +00:00
parent c0ce381118
commit a761df59a7
6 changed files with 124 additions and 76 deletions

View File

@@ -17,6 +17,14 @@ $user = unserialize($_SESSION['user']);
// check method // check method
try { try {
if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null;
$params = [
':periodo_id' => $user->periodo_id,
':facultad_id' => $user->facultad['facultad_id'],
':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d'),
':fecha_fin' => $baseDate ? date('Y-m-d H:i:s', strtotime($baseDate . ' +24 hours')) : date('Y-m-d H:i:s'),
];
$data = $db->query( $data = $db->query(
"WITH horarios AS ( "WITH horarios AS (
SELECT *, SELECT *,
@@ -64,17 +72,14 @@ try {
LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id
LEFT JOIN ROL on ROL.rol_id = justificador.rol_id LEFT JOIN ROL on ROL.rol_id = justificador.rol_id
left join facultad on facultad.facultad_id = justificador.facultad_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)) WHERE (fechas.registro_fecha_ideal + HORARIO_HORA) BETWEEN
GREATEST(HORARIO_FECHA_INICIO, PERIODO_FECHA_INICIO, :fecha_inicio) AND LEAST(:fecha_fin, PERIODO_FECHA_FIN, HORARIO_FECHA_FIN)
ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre", ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
[ $params
':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,
]
); );
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
// $user->print_to_log(json_encode($params));
echo json_encode(array_merge($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} else { } else {
http_response_code(405); http_response_code(405);
echo json_encode(['error' => 'method not allowed']); echo json_encode(['error' => 'method not allowed']);

View File

@@ -31,20 +31,22 @@ try {
$data = array_map( $data = array_map(
fn($ruta) => array_merge( fn($ruta) => array_merge(
[ [
'horarios' => $db 'horarios' => array_merge(
->join('periodo', 'periodo.periodo_id = horario_view.periodo_id') $db
->join('bloque_horario', '(bloque_horario.hora_inicio, bloque_horario.hora_fin) OVERLAPS (horario_view.horario_hora, horario_view.horario_hora + horario_view.duracion)') ->join('periodo', 'periodo.periodo_id = horario_view.periodo_id')
->join('salon_view', 'salon_view.salon_id = horario_view.salon_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('horario_profesor', 'horario_profesor.horario_id = horario_view.horario_id') ->join('salon_view', 'salon_view.salon_id = horario_view.salon_id')
->join('profesor', 'profesor.profesor_id = horario_profesor.profesor_id') ->join('horario_profesor', 'horario_profesor.horario_id = horario_view.horario_id')
->join('registro', '(registro.profesor_id, registro.horario_id, registro.registro_fecha_ideal) = (profesor.profesor_id, horario_view.horario_id, CURRENT_DATE)', 'LEFT') ->join('profesor', 'profesor.profesor_id = horario_profesor.profesor_id')
->where('CURRENT_DATE BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin') ->join('registro', '(registro.profesor_id, registro.horario_id, registro.registro_fecha_ideal) = (profesor.profesor_id, horario_view.horario_id, CURRENT_DATE)', 'LEFT')
->where('horario_dia = EXTRACT(DOW FROM CURRENT_DATE)') ->where('CURRENT_DATE BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin')
->where('bloque_horario.id', $_GET['bloque_horario_id']) ->where('horario_dia = EXTRACT(DOW FROM CURRENT_DATE)')
->where('id_espacio_padre', $ruta['id_espacio_sgu']) ->where('bloque_horario.id', $_GET['bloque_horario_id'])
->get('horario_view', null, '*, horario_view.horario_id, profesor.profesor_id'), ->where('id_espacio_padre', $ruta['id_espacio_sgu'])
->get('horario_view', null, '*, horario_view.horario_id, profesor.profesor_id'),
),
], ],
$ruta $ruta,
), ),
$data $data
); );

View File

@@ -595,7 +595,8 @@
<div class="row mt-3"> <div class="row mt-3">
<div class="col-12"> <div class="col-12">
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="observaciones" v-model="store.current.observaciones"> <input class="form-check-input" type="checkbox" value="" id="observaciones"
v-model="store.current.observaciones">
<label class="form-check-label" for="observaciones"> <label class="form-check-label" for="observaciones">
¿Deseas añadir observaciones? ¿Deseas añadir observaciones?
</label> </label>

View File

@@ -18,38 +18,8 @@ require_once($ruta ?? '') . "vendor/autoload.php";
class Login class Login
{ {
private function es_usuario(): bool 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)
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 public function print_to_log(string $desc, array $old = null, array $new = null): void
@@ -61,17 +31,40 @@ class Login
$desc .= " |#| NEW:" . json_encode($new); $desc .= " |#| NEW:" . json_encode($new);
$log->appendLog($this->user["id"], $this->user["nombre"], $desc); $log->appendLog($this->user["id"], $this->user["nombre"], $desc);
} }
public function access(string $pagina = null): string|null public function access(string $pagina = null): void
{ {
global $db; global $db;
if ($this->admin) $user = $db
return "w"; ->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 );
$acceso = $db $acceso = $db
->where('id', $this->user["id"]) ->where('id', $this->user["id"])
->where('pagina_ruta', $pagina ?? substr(basename($_SERVER['PHP_SELF']), 0, -4)) ->where('pagina_ruta', $pagina ?? substr(basename($_SERVER['PHP_SELF']), 0, -4))
->getOne('permiso_view'); ->getOne('permiso_view');
return isset($acceso["tipo"]) ? $acceso["tipo"] : null; $this->acceso = isset($acceso["tipo"]) ? $acceso["tipo"] : null;
} }
private static function validaUsuario($user, $pass): bool private static function validaUsuario($user, $pass): bool
{ {
@@ -91,26 +84,69 @@ class Login
} }
public static function validUser(string $user, string $pass): Login|array 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; global $db;
if (!Login::validaUsuario($user, $pass))
return ['error' => true, 'msg' => 'Error al autenticar usuario'];
if ($db->has("FS_VALIDACLAVEULSA('$user')")) { if ($db->has("FS_VALIDACLAVEULSA('$user')")) {
$fs = $db->querySingle('SELECT * FROM FS_VALIDACLAVEULSA(?)', [$user]); #die (Login::validaUsuario($user, $pass));
return new Login(user: ['id' => $fs["id"], 'nombre' => $fs["nombre"], 'clave' => $fs["clave"]]); $fs_validaclaveulsa = $db->querySingle(
} 'SELECT * FROM FS_VALIDACLAVEULSA(?)',
[$user]
);
$profesorClave = preg_replace('/\D/', '', $user); $user = array(
if ($db->where('profesor_clave', $profesorClave)->has("profesor")) { 'id' => $fs_validaclaveulsa["id"],
$profesor = $db->where('profesor_clave', $profesorClave)->getOne("profesor"); 'nombre' => $fs_validaclaveulsa["nombre"],
return new Login(user: ['id' => $profesor["profesor_id"], 'nombre' => $profesor["profesor_nombre"], 'clave' => $profesor["profesor_clave"]]); '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');
return ['error' => true, 'msg' => 'Usuario no encontrado']; $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'
];
} }
public static function log_out(): void public static function log_out(): void
{ {
session_start(); session_start();

View File

@@ -51,6 +51,7 @@ const store = reactive({
maxDate: new Date(`${periodo_data.fecha_final}:00:00:00`), maxDate: new Date(`${periodo_data.fecha_final}:00:00:00`),
dateFormat: "yy-mm-dd", dateFormat: "yy-mm-dd",
showAnim: "slide", showAnim: "slide",
beforeShowDay: (date) => [(date.getDay() != 0), ""]
}); });
const fecha = $("#fecha"), inicio = $("#fecha_inicio"), fin = $("#fecha_fin"); const fecha = $("#fecha"), inicio = $("#fecha_inicio"), fin = $("#fecha_fin");
fecha.datepicker("setDate", new Date(`${periodo_data.fecha_final}:00:00:00`)); fecha.datepicker("setDate", new Date(`${periodo_data.fecha_final}:00:00:00`));
@@ -175,6 +176,7 @@ const store = reactive({
}); });
this.data = await res.json(); this.data = await res.json();
this.loading = false; this.loading = false;
store.current.page = 1;
}, },
invertir() { invertir() {
this.data = this.data.reverse(); this.data = this.data.reverse();

View File

@@ -124,6 +124,7 @@ const store = reactive({
maxDate: new Date(`${periodo_data.fecha_final}:00:00:00`), maxDate: new Date(`${periodo_data.fecha_final}:00:00:00`),
dateFormat: "yy-mm-dd", dateFormat: "yy-mm-dd",
showAnim: "slide", showAnim: "slide",
beforeShowDay: (date: Date) => [(date.getDay() != 0), ""]
}); });
const fecha = $("#fecha"), inicio = $("#fecha_inicio"), fin = $("#fecha_fin") const fecha = $("#fecha"), inicio = $("#fecha_inicio"), fin = $("#fecha_fin")
@@ -257,6 +258,7 @@ const store = reactive({
}) })
this.data = await res.json() this.data = await res.json()
this.loading = false this.loading = false
store.current.page = 1
}, },
invertir() { invertir() {
this.data = this.data.reverse() this.data = this.data.reverse()