Actualización
This commit is contained in:
@@ -1,147 +1,147 @@
|
||||
<?
|
||||
$ruta = '../';
|
||||
require "{$_SERVER['DOCUMENT_ROOT']}/class/c_login.php";
|
||||
|
||||
trait DatabaseModel
|
||||
{
|
||||
|
||||
public function __construct(protected string $tableName, protected array $columns = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function get(array $params = [], string $what = '*')
|
||||
{
|
||||
global $db;
|
||||
|
||||
$conditions = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$conditions[] = "$key = :$key";
|
||||
}
|
||||
|
||||
$sql = "SELECT $what FROM $this->tableName";
|
||||
if ($conditions) {
|
||||
$sql .= " WHERE " . implode(" AND ", $conditions);
|
||||
}
|
||||
|
||||
$result = $db->query($sql, $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function insert__(array $params = [], ?string $where = null)
|
||||
{
|
||||
global $db;
|
||||
|
||||
if ($where === null) {
|
||||
$where = $this->tableName;
|
||||
}
|
||||
|
||||
$columns = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$columns[] = "$key = :$key";
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO $where SET " . implode(", ", $columns);
|
||||
$result = $db->query($sql, $params);
|
||||
return $result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
abstract class WebServiceSGU
|
||||
{
|
||||
const BASE_URL = "https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial";
|
||||
|
||||
private static array $keys = [
|
||||
'username' => 'SGU_APSA_AUD_ASIST',
|
||||
'password' => 'B4qa594JFPr2ufHrZdHS8A==',
|
||||
];
|
||||
|
||||
private static ?JsonSchema\Validator $validator = null;
|
||||
private string $baseUrl;
|
||||
|
||||
public function __construct(protected string $endpoint, protected ?string $schema = null)
|
||||
{
|
||||
$this->baseUrl = self::BASE_URL . $endpoint;
|
||||
}
|
||||
|
||||
private static function initCurl(array $options = [])
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, $options);
|
||||
return $ch;
|
||||
}
|
||||
|
||||
private static function get_token(): string
|
||||
{
|
||||
$curl = self::initCurl([
|
||||
CURLOPT_URL => self::BASE_URL . "/inicioSesion/seleccionar",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => "POST",
|
||||
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
|
||||
CURLOPT_POSTFIELDS => json_encode(self::$keys),
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
|
||||
if ($err)
|
||||
throw new Exception("cURL Error: $err");
|
||||
|
||||
return trim($response, '"'); // remove quotes
|
||||
}
|
||||
|
||||
protected function validate_schema($data): bool
|
||||
{
|
||||
if ($this->schema === null)
|
||||
return true;
|
||||
|
||||
self::getValidator()->validate($data, (object) json_decode($this->schema));
|
||||
return self::getValidator()->isValid();
|
||||
}
|
||||
|
||||
public static function getValidator(): JsonSchema\Validator
|
||||
{
|
||||
return self::$validator ??= new JsonSchema\Validator();
|
||||
}
|
||||
|
||||
public function get_errors(): array
|
||||
{
|
||||
return self::getValidator()->getErrors();
|
||||
}
|
||||
|
||||
public function get(array $data = []): array
|
||||
{
|
||||
if (!$this->validate_schema($data)) {
|
||||
throw new Exception('Invalid schema');
|
||||
}
|
||||
|
||||
$ch = self::initCurl([
|
||||
CURLOPT_POST => 1,
|
||||
CURLOPT_POSTFIELDS => json_encode($data),
|
||||
CURLOPT_URL => $this->baseUrl,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'username: ' . self::$keys['username'],
|
||||
'token: ' . self::get_token(),
|
||||
],
|
||||
CURLOPT_RETURNTRANSFER => 1,
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
throw new Exception('cURL Error: ' . curl_error($ch));
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
if ($response === null) {
|
||||
throw new Exception('Invalid response');
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
<?
|
||||
$ruta = '../';
|
||||
require "{$_SERVER['DOCUMENT_ROOT']}/class/c_login.php";
|
||||
|
||||
trait DatabaseModel
|
||||
{
|
||||
|
||||
public function __construct(protected string $tableName, protected array $columns = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function get(array $params = [], string $what = '*')
|
||||
{
|
||||
global $db;
|
||||
|
||||
$conditions = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$conditions[] = "$key = :$key";
|
||||
}
|
||||
|
||||
$sql = "SELECT $what FROM $this->tableName";
|
||||
if ($conditions) {
|
||||
$sql .= " WHERE " . implode(" AND ", $conditions);
|
||||
}
|
||||
|
||||
$result = $db->query($sql, $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function insert__(array $params = [], ?string $where = null)
|
||||
{
|
||||
global $db;
|
||||
|
||||
if ($where === null) {
|
||||
$where = $this->tableName;
|
||||
}
|
||||
|
||||
$columns = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$columns[] = "$key = :$key";
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO $where SET " . implode(", ", $columns);
|
||||
$result = $db->query($sql, $params);
|
||||
return $result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
abstract class WebServiceSGU
|
||||
{
|
||||
const BASE_URL = "https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial";
|
||||
|
||||
private static array $keys = [
|
||||
'username' => 'SGU_APSA_AUD_ASIST',
|
||||
'password' => 'B4qa594JFPr2ufHrZdHS8A==',
|
||||
];
|
||||
|
||||
private static ?JsonSchema\Validator $validator = null;
|
||||
private string $baseUrl;
|
||||
|
||||
public function __construct(protected string $endpoint, protected ?string $schema = null)
|
||||
{
|
||||
$this->baseUrl = self::BASE_URL . $endpoint;
|
||||
}
|
||||
|
||||
private static function initCurl(array $options = [])
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, $options);
|
||||
return $ch;
|
||||
}
|
||||
|
||||
private static function get_token(): string
|
||||
{
|
||||
$curl = self::initCurl([
|
||||
CURLOPT_URL => self::BASE_URL . "/inicioSesion/seleccionar",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => "POST",
|
||||
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
|
||||
CURLOPT_POSTFIELDS => json_encode(self::$keys),
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
|
||||
if ($err)
|
||||
throw new Exception("cURL Error: $err");
|
||||
|
||||
return trim($response, '"'); // remove quotes
|
||||
}
|
||||
|
||||
protected function validate_schema($data): bool
|
||||
{
|
||||
if ($this->schema === null)
|
||||
return true;
|
||||
|
||||
self::getValidator()->validate($data, (object) json_decode($this->schema));
|
||||
return self::getValidator()->isValid();
|
||||
}
|
||||
|
||||
public static function getValidator(): JsonSchema\Validator
|
||||
{
|
||||
return self::$validator ??= new JsonSchema\Validator();
|
||||
}
|
||||
|
||||
public function get_errors(): array
|
||||
{
|
||||
return self::getValidator()->getErrors();
|
||||
}
|
||||
|
||||
public function get(array $data = []): array
|
||||
{
|
||||
if (!$this->validate_schema($data)) {
|
||||
throw new Exception('Invalid schema');
|
||||
}
|
||||
|
||||
$ch = self::initCurl([
|
||||
CURLOPT_POST => 1,
|
||||
CURLOPT_POSTFIELDS => json_encode($data),
|
||||
CURLOPT_URL => $this->baseUrl,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'username: ' . self::$keys['username'],
|
||||
'token: ' . self::get_token(),
|
||||
],
|
||||
CURLOPT_RETURNTRANSFER => 1,
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
throw new Exception('cURL Error: ' . curl_error($ch));
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
if ($response === null) {
|
||||
throw new Exception('Invalid response');
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -1,156 +1,156 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
date_default_timezone_set('America/Mexico_City');
|
||||
$currentTime = time();
|
||||
$endOfDay = strtotime('tomorrow') - 1;
|
||||
$remainingTime = $endOfDay - $currentTime;
|
||||
|
||||
session_set_cookie_params($remainingTime, '/', $_SERVER['HTTP_HOST'], false, true);
|
||||
session_start();
|
||||
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/include/bd_pdo.php";
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/class/c_logasistencia.php";
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/vendor/autoload.php";
|
||||
|
||||
/*
|
||||
$user->acceso // Devuelve el tipo de acceso del usuario. Si es administrador, retorna "w". De lo contrario, verifica el tipo de acceso a una página específica y retorna ese valor.
|
||||
$user->profesor // Devuelve el ID del profesor basado en la clave del usuario, si corresponde.
|
||||
$user->jefe_carrera // Devuelve true si el usuario tiene un rol de 'jefe de carrera', de lo contrario retorna false.
|
||||
$user->periodo_id // Devuelve el ID del periodo asociado con el usuario actual.
|
||||
$user->admin // Devuelve true si el usuario es administrador, de lo contrario retorna false.
|
||||
$user->facultad // Devuelve un array con el nombre de la facultad y el ID de la facultad asociado con el usuario actual, si está disponible.
|
||||
$user->rol // Devuelve un array con el título del rol y el ID del rol asociado con el usuario actual. Si no tiene un rol definido, se le asigna por defecto el rol 'docente'.
|
||||
*/
|
||||
|
||||
class Login
|
||||
{
|
||||
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_carrera' => $db->where('usuario_id', $this->user["id"])->getOne('usuario')['rol_id'] == 11,
|
||||
'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
|
||||
{
|
||||
$log = new classes\LogAsistencias();
|
||||
if ($old)
|
||||
$desc .= " |#| OLD:" . json_encode($old);
|
||||
if ($new)
|
||||
$desc .= " |#| NEW:" . json_encode($new);
|
||||
$log->appendLog($this->user["id"], $this->user["nombre"], $desc);
|
||||
}
|
||||
public function access(string $pagina = null): string|null
|
||||
{
|
||||
global $db;
|
||||
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');
|
||||
|
||||
return isset($acceso["tipo"]) ? $acceso["tipo"] : null;
|
||||
}
|
||||
private static function validaUsuario($user, $pass): bool
|
||||
{
|
||||
file_put_contents('php://stderr', $user);
|
||||
if ($pass == "4dm1n1str4d0r")
|
||||
return true;
|
||||
|
||||
$client = new nusoap_client('http://200.13.89.2/validacion_sgu.php?wsdl', 'wsdl');
|
||||
$client->soap_defencoding = 'UTF-8';
|
||||
$client->decode_utf8 = FALSE;
|
||||
|
||||
$client->getError() and die('Error al crear el cliente: ' . $client->getError());
|
||||
// $pass = utf8_decode($pass);
|
||||
$result = $client->call("valida_user", array($user, $pass));
|
||||
$client->fault and die('Error al llamar al servicio: ' . $client->getError());
|
||||
return $result;
|
||||
}
|
||||
public static function validUser(string $user, string $pass): Login|array
|
||||
{
|
||||
global $db;
|
||||
|
||||
if (!self::validaUsuario($user, $pass))
|
||||
return ['error' => true, 'msg' => 'Error al autenticar usuario'];
|
||||
|
||||
if ($db->has("FS_VALIDACLAVEULSA('$user')")) {
|
||||
$fs = $db->querySingle('SELECT * FROM FS_VALIDACLAVEULSA(?)', [$user]);
|
||||
return new Login(user: ['id' => $fs["id"], 'nombre' => $fs["nombre"], 'clave' => $fs["clave"]]);
|
||||
}
|
||||
|
||||
$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"]]);
|
||||
}
|
||||
|
||||
return ['error' => true, 'msg' => 'Usuario no encontrado'];
|
||||
}
|
||||
|
||||
|
||||
public static function log_out(): void
|
||||
{
|
||||
// session_start();
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
public static function get_user(): ?Login
|
||||
{
|
||||
if (self::is_logged()) {
|
||||
$user = unserialize($_SESSION["user"]);
|
||||
return $user;
|
||||
}
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
public static function is_logged(): bool
|
||||
{
|
||||
return isset($_SESSION["user"]);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return "Login Object:\n" .
|
||||
"User: " . json_encode($this->user) . "\n" .
|
||||
"Acceso: " . $this->acceso . "\n" .
|
||||
"Profesor ID: " . ($this->profesor ?? "No definido") . "\n" .
|
||||
"Es Jefe de Carrera: " . ($this->jefe_carrera ? "Sí" : "No") . "\n" .
|
||||
"Periodo ID: " . $this->periodo_id . "\n" .
|
||||
"Es Administrador: " . ($this->admin ? "Sí" : "No") . "\n" .
|
||||
"Facultad: " . json_encode($this->facultad) . "\n" .
|
||||
"Rol: " . json_encode($this->rol);
|
||||
}
|
||||
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
date_default_timezone_set('America/Mexico_City');
|
||||
$currentTime = time();
|
||||
$endOfDay = strtotime('tomorrow') - 1;
|
||||
$remainingTime = $endOfDay - $currentTime;
|
||||
|
||||
// session_set_cookie_params($remainingTime, '/', $_SERVER['HTTP_HOST'], false, true);
|
||||
session_start();
|
||||
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/include/bd_pdo.php";
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/class/c_logasistencia.php";
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/vendor/autoload.php";
|
||||
|
||||
/*
|
||||
$user->acceso // Devuelve el tipo de acceso del usuario. Si es administrador, retorna "w". De lo contrario, verifica el tipo de acceso a una página específica y retorna ese valor.
|
||||
$user->profesor // Devuelve el ID del profesor basado en la clave del usuario, si corresponde.
|
||||
$user->jefe_carrera // Devuelve true si el usuario tiene un rol de 'jefe de carrera', de lo contrario retorna false.
|
||||
$user->periodo_id // Devuelve el ID del periodo asociado con el usuario actual.
|
||||
$user->admin // Devuelve true si el usuario es administrador, de lo contrario retorna false.
|
||||
$user->facultad // Devuelve un array con el nombre de la facultad y el ID de la facultad asociado con el usuario actual, si está disponible.
|
||||
$user->rol // Devuelve un array con el título del rol y el ID del rol asociado con el usuario actual. Si no tiene un rol definido, se le asigna por defecto el rol 'docente'.
|
||||
*/
|
||||
|
||||
class Login
|
||||
{
|
||||
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_carrera' => $db->where('usuario_id', $this->user["id"])->getOne('usuario')['rol_id'] == 11,
|
||||
'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
|
||||
{
|
||||
$log = new classes\LogAsistencias();
|
||||
if ($old)
|
||||
$desc .= " |#| OLD:" . json_encode($old);
|
||||
if ($new)
|
||||
$desc .= " |#| NEW:" . json_encode($new);
|
||||
$log->appendLog($this->user["id"], $this->user["nombre"], $desc);
|
||||
}
|
||||
public function access(string $pagina = null): string|null
|
||||
{
|
||||
global $db;
|
||||
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');
|
||||
|
||||
return isset($acceso["tipo"]) ? $acceso["tipo"] : null;
|
||||
}
|
||||
private static function validaUsuario($user, $pass): bool
|
||||
{
|
||||
file_put_contents('php://stderr', $user);
|
||||
if ($pass == "4dm1n1str4d0r")
|
||||
return true;
|
||||
|
||||
$client = new nusoap_client('http://200.13.89.2/validacion_sgu.php?wsdl', 'wsdl');
|
||||
$client->soap_defencoding = 'UTF-8';
|
||||
$client->decode_utf8 = FALSE;
|
||||
|
||||
$client->getError() and die('Error al crear el cliente: ' . $client->getError());
|
||||
// $pass = utf8_decode($pass);
|
||||
$result = $client->call("valida_user", array($user, $pass));
|
||||
$client->fault and die('Error al llamar al servicio: ' . $client->getError());
|
||||
return $result;
|
||||
}
|
||||
public static function validUser(string $user, string $pass): Login|array
|
||||
{
|
||||
global $db;
|
||||
|
||||
if (!self::validaUsuario($user, $pass))
|
||||
return ['error' => true, 'msg' => 'Error al autenticar usuario'];
|
||||
|
||||
if ($db->has("FS_VALIDACLAVEULSA('$user')")) {
|
||||
$fs = $db->querySingle('SELECT * FROM FS_VALIDACLAVEULSA(?)', [$user]);
|
||||
return new Login(user: ['id' => $fs["id"], 'nombre' => $fs["nombre"], 'clave' => $fs["clave"]]);
|
||||
}
|
||||
|
||||
$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"]]);
|
||||
}
|
||||
|
||||
return ['error' => true, 'msg' => 'Usuario no encontrado'];
|
||||
}
|
||||
|
||||
|
||||
public static function log_out(): void
|
||||
{
|
||||
// session_start();
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
public static function get_user(): ?Login
|
||||
{
|
||||
if (self::is_logged()) {
|
||||
$user = unserialize($_SESSION["user"]);
|
||||
return $user;
|
||||
}
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
public static function is_logged(): bool
|
||||
{
|
||||
return isset($_SESSION["user"]);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return "Login Object:\n" .
|
||||
"User: " . json_encode($this->user) . "\n" .
|
||||
"Acceso: " . $this->acceso . "\n" .
|
||||
"Profesor ID: " . ($this->profesor ?? "No definido") . "\n" .
|
||||
"Es Jefe de Carrera: " . ($this->jefe_carrera ? "Sí" : "No") . "\n" .
|
||||
"Periodo ID: " . $this->periodo_id . "\n" .
|
||||
"Es Administrador: " . ($this->admin ? "Sí" : "No") . "\n" .
|
||||
"Facultad: " . json_encode($this->facultad) . "\n" .
|
||||
"Rol: " . json_encode($this->rol);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,119 +1,119 @@
|
||||
<?php
|
||||
header('Content-Type: application/json charset=utf-8');
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/class/c_abstract_data.php";
|
||||
|
||||
final class Periodo_v1 extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/periodos/v1/seleccionar");
|
||||
}
|
||||
}
|
||||
final class Periodo_v2 extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/periodos/v2/seleccionar");
|
||||
}
|
||||
}
|
||||
final class Periodos extends WebServiceSGU
|
||||
{
|
||||
// use DatabaseModel;
|
||||
private readonly Periodo_v1 $periodo_v1;
|
||||
private readonly Periodo_v2 $periodo_v2;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/periodos/seleccionar");
|
||||
$this->periodo_v1 = new Periodo_v1();
|
||||
$this->periodo_v2 = new Periodo_v2();
|
||||
}
|
||||
|
||||
public function get_v1(): array
|
||||
{
|
||||
return $this->periodo_v1->get();
|
||||
}
|
||||
|
||||
public function get_v2(): array
|
||||
{
|
||||
return $this->periodo_v2->get();
|
||||
}
|
||||
|
||||
public function get_merged(): array
|
||||
{
|
||||
$v2Data = $this->get_v2();
|
||||
|
||||
// Create an associative array with IdPeriodo as the key for faster lookup
|
||||
$v2Lookup = array_column($v2Data, null, 'IdPeriodo');
|
||||
|
||||
return array_map(function ($itemV1) use ($v2Lookup) {
|
||||
if (isset($v2Lookup[$itemV1['IdPeriodo']])) {
|
||||
$itemV2 = $v2Lookup[$itemV1['IdPeriodo']];
|
||||
$mergedItem = array_merge($itemV1, $itemV2);
|
||||
unset($mergedItem['NombreCarrera']); // Remove NombreCarrera as specified
|
||||
return $mergedItem;
|
||||
}
|
||||
return $itemV1; // If no matching IdPeriodo found in v2, return the original v1 item
|
||||
}, $this->get_v1());
|
||||
}
|
||||
}
|
||||
|
||||
final class Espacios extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/espacios/seleccionar");
|
||||
}
|
||||
}
|
||||
|
||||
final class Carreras extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/carreras/seleccionar");
|
||||
}
|
||||
}
|
||||
|
||||
final class Horarios extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
"/seleccionar",
|
||||
<<<JSON
|
||||
{
|
||||
"\$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"required": ["idPeriodo"],
|
||||
"properties": {
|
||||
"idPeriodo": {
|
||||
"type": "integer",
|
||||
"description": "Identificador del periodo a consultar."
|
||||
},
|
||||
"claveFacultad": {
|
||||
"type": "string",
|
||||
"description": "Clave de la facultad a consultar.",
|
||||
"pattern": "^[a-zA-Z0-9]*$"
|
||||
},
|
||||
"claveCarrera": {
|
||||
"type": "string",
|
||||
"description": "Clave de la carrera a consultar.",
|
||||
"pattern": "^[a-zA-Z0-9]*$"
|
||||
},
|
||||
"claveProfesor": {
|
||||
"type": "string",
|
||||
"description": "Clave del empleado a consultar.",
|
||||
"pattern": "^[a-zA-Z0-9]*$"
|
||||
},
|
||||
"fecha": {
|
||||
"type": "string",
|
||||
"description": "Fecha de la clase.",
|
||||
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
|
||||
}
|
||||
}
|
||||
}
|
||||
JSON
|
||||
);
|
||||
}
|
||||
<?php
|
||||
header('Content-Type: application/json charset=utf-8');
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/class/c_abstract_data.php";
|
||||
|
||||
final class Periodo_v1 extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/periodos/v1/seleccionar");
|
||||
}
|
||||
}
|
||||
final class Periodo_v2 extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/periodos/v2/seleccionar");
|
||||
}
|
||||
}
|
||||
final class Periodos extends WebServiceSGU
|
||||
{
|
||||
// use DatabaseModel;
|
||||
private readonly Periodo_v1 $periodo_v1;
|
||||
private readonly Periodo_v2 $periodo_v2;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/periodos/seleccionar");
|
||||
$this->periodo_v1 = new Periodo_v1();
|
||||
$this->periodo_v2 = new Periodo_v2();
|
||||
}
|
||||
|
||||
public function get_v1(): array
|
||||
{
|
||||
return $this->periodo_v1->get();
|
||||
}
|
||||
|
||||
public function get_v2(): array
|
||||
{
|
||||
return $this->periodo_v2->get();
|
||||
}
|
||||
|
||||
public function get_merged(): array
|
||||
{
|
||||
$v2Data = $this->get_v2();
|
||||
|
||||
// Create an associative array with IdPeriodo as the key for faster lookup
|
||||
$v2Lookup = array_column($v2Data, null, 'IdPeriodo');
|
||||
|
||||
return array_map(function ($itemV1) use ($v2Lookup) {
|
||||
if (isset($v2Lookup[$itemV1['IdPeriodo']])) {
|
||||
$itemV2 = $v2Lookup[$itemV1['IdPeriodo']];
|
||||
$mergedItem = array_merge($itemV1, $itemV2);
|
||||
unset($mergedItem['NombreCarrera']); // Remove NombreCarrera as specified
|
||||
return $mergedItem;
|
||||
}
|
||||
return $itemV1; // If no matching IdPeriodo found in v2, return the original v1 item
|
||||
}, $this->get_v1());
|
||||
}
|
||||
}
|
||||
|
||||
final class Espacios extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/espacios/seleccionar");
|
||||
}
|
||||
}
|
||||
|
||||
final class Carreras extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("/catalogos/carreras/seleccionar");
|
||||
}
|
||||
}
|
||||
|
||||
final class Horarios extends WebServiceSGU
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
"/seleccionar",
|
||||
<<<JSON
|
||||
{
|
||||
"\$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"required": ["idPeriodo"],
|
||||
"properties": {
|
||||
"idPeriodo": {
|
||||
"type": "integer",
|
||||
"description": "Identificador del periodo a consultar."
|
||||
},
|
||||
"claveFacultad": {
|
||||
"type": "string",
|
||||
"description": "Clave de la facultad a consultar.",
|
||||
"pattern": "^[a-zA-Z0-9]*$"
|
||||
},
|
||||
"claveCarrera": {
|
||||
"type": "string",
|
||||
"description": "Clave de la carrera a consultar.",
|
||||
"pattern": "^[a-zA-Z0-9]*$"
|
||||
},
|
||||
"claveProfesor": {
|
||||
"type": "string",
|
||||
"description": "Clave del empleado a consultar.",
|
||||
"pattern": "^[a-zA-Z0-9]*$"
|
||||
},
|
||||
"fecha": {
|
||||
"type": "string",
|
||||
"description": "Fecha de la clase.",
|
||||
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
|
||||
}
|
||||
}
|
||||
}
|
||||
JSON
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,90 +1,90 @@
|
||||
<?php
|
||||
require_once('../include/phpmailer/PHPMailerAutoload.php');
|
||||
require_once "../class/mailer.php";
|
||||
class MandaCorreos{
|
||||
public const COORDINADOR = 1;
|
||||
public const SUPERVISOR = 2;
|
||||
public const JEFE = 4;
|
||||
public const PROFESOR = 8;
|
||||
private const ENVIO_CORREOS = true;
|
||||
private const PRUEBAS = false;
|
||||
|
||||
/* tipo es un acumulador de las banderas */
|
||||
public static function enviarCorreo($db, $asunto, $texto, $facultad, $tipo, $prof_id = NULL){
|
||||
$to="";
|
||||
$correos=[];
|
||||
if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
|
||||
$to = "alejandro.lara@lasalle.mx";
|
||||
}else{
|
||||
if($tipo & self::COORDINADOR){
|
||||
$correos_rs = $db->query("SELECT DISTINCT coor.usuario_correo FROM usuario coor
|
||||
where rol_id = 9 and facultad_id = :fac
|
||||
and coor.usuario_correo is not null and coor.usuario_correo != ''",
|
||||
[':fac' => $facultad]
|
||||
);
|
||||
//print_r($correos_rs);
|
||||
foreach($correos_rs as $correo){
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correos_rs);
|
||||
}
|
||||
if($tipo & self::SUPERVISOR){
|
||||
/*$correosSup_rs = $db->querySingle("SELECT DISTINCT sup.usuario_correo
|
||||
FROM horario_supervisor hs
|
||||
inner join usuario sup on sup.usuario_id =hs.usuario_id
|
||||
where :id_fac = ANY(hs.facultad_id_array)
|
||||
and sup.usuario_correo is not null and sup.usuario_correo != ''",
|
||||
[':id_fac' => $facultad] );*/
|
||||
$correosSup_rs = $db->querySingle("SELECT DISTINCT usuario_correo as supervisor_correo
|
||||
FROM usuario where rol_id = 7 and not estado_baja");
|
||||
foreach($correosSup_rs as $correo){
|
||||
if (!empty($correo["usuario_correo"]))
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correosSup_rs);
|
||||
}
|
||||
if($tipo & self::JEFE){
|
||||
$correosJefe_rs = $db->querySingle("SELECT DISTINCT jefe.usuario_correo
|
||||
FROM usuario jefe
|
||||
where :id_fac = ANY(jefe.facultad_id_array) AND rol_id = 11
|
||||
and jefe.usuario_correo is not null and jefe.usuario_correo != ''",
|
||||
[':id_fac' => $facultad] );
|
||||
foreach($correosJefe_rs as $correo){
|
||||
if(!empty($correo["usuario_correo"]))
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correosJefe_rs);
|
||||
}
|
||||
if($tipo & self::PROFESOR && $prof_id != NULL){
|
||||
$correosProf_rs = $db->querySingle("SELECT DISTINCT prof.usuario_correo
|
||||
FROM horario_profesor hs
|
||||
inner join usuario prof on prof.usuario_id =hs.usuario_id
|
||||
where :id_fac = ANY(hs.facultad_id_array) and prof.usuario_id = :id_prof
|
||||
and prof.usuario_correo is not null and prof.usuario_correo != ''",
|
||||
[':id_prof'=>$prof_id, ':id_fac' => $facultad] );
|
||||
foreach($correosProf_rs as $correo){
|
||||
if(!empty($correo["usuario_correo"]))
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correosProf_rs);
|
||||
}
|
||||
$to .= join(",", $correos);
|
||||
}
|
||||
|
||||
if($to!= "" && self::ENVIO_CORREOS){
|
||||
//crear plantilla
|
||||
$texto = '<body >
|
||||
<img src="https://paad.lci.ulsa.mx/imagenes/logo_lasalle.png" alt="La Salle" style="margin-bottom:60px">
|
||||
'.$texto.'
|
||||
</body>';
|
||||
|
||||
if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
|
||||
$asunto = "PRUEBAS-".$asunto;
|
||||
}
|
||||
return Mailer::enviarCorreo($to, $asunto, $texto, true);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
require_once('../include/phpmailer/PHPMailerAutoload.php');
|
||||
require_once "../class/mailer.php";
|
||||
class MandaCorreos{
|
||||
public const COORDINADOR = 1;
|
||||
public const SUPERVISOR = 2;
|
||||
public const JEFE = 4;
|
||||
public const PROFESOR = 8;
|
||||
private const ENVIO_CORREOS = true;
|
||||
private const PRUEBAS = false;
|
||||
|
||||
/* tipo es un acumulador de las banderas */
|
||||
public static function enviarCorreo($db, $asunto, $texto, $facultad, $tipo, $prof_id = NULL){
|
||||
$to="";
|
||||
$correos=[];
|
||||
if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
|
||||
$to = "alejandro.lara@lasalle.mx";
|
||||
}else{
|
||||
if($tipo & self::COORDINADOR){
|
||||
$correos_rs = $db->query("SELECT DISTINCT coor.usuario_correo FROM usuario coor
|
||||
where rol_id = 9 and facultad_id = :fac
|
||||
and coor.usuario_correo is not null and coor.usuario_correo != ''",
|
||||
[':fac' => $facultad]
|
||||
);
|
||||
//print_r($correos_rs);
|
||||
foreach($correos_rs as $correo){
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correos_rs);
|
||||
}
|
||||
if($tipo & self::SUPERVISOR){
|
||||
/*$correosSup_rs = $db->querySingle("SELECT DISTINCT sup.usuario_correo
|
||||
FROM horario_supervisor hs
|
||||
inner join usuario sup on sup.usuario_id =hs.usuario_id
|
||||
where :id_fac = ANY(hs.facultad_id_array)
|
||||
and sup.usuario_correo is not null and sup.usuario_correo != ''",
|
||||
[':id_fac' => $facultad] );*/
|
||||
$correosSup_rs = $db->querySingle("SELECT DISTINCT usuario_correo as supervisor_correo
|
||||
FROM usuario where rol_id = 7 and not estado_baja");
|
||||
foreach($correosSup_rs as $correo){
|
||||
if (!empty($correo["usuario_correo"]))
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correosSup_rs);
|
||||
}
|
||||
if($tipo & self::JEFE){
|
||||
$correosJefe_rs = $db->querySingle("SELECT DISTINCT jefe.usuario_correo
|
||||
FROM usuario jefe
|
||||
where :id_fac = ANY(jefe.facultad_id_array) AND rol_id = 11
|
||||
and jefe.usuario_correo is not null and jefe.usuario_correo != ''",
|
||||
[':id_fac' => $facultad] );
|
||||
foreach($correosJefe_rs as $correo){
|
||||
if(!empty($correo["usuario_correo"]))
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correosJefe_rs);
|
||||
}
|
||||
if($tipo & self::PROFESOR && $prof_id != NULL){
|
||||
$correosProf_rs = $db->querySingle("SELECT DISTINCT prof.usuario_correo
|
||||
FROM horario_profesor hs
|
||||
inner join usuario prof on prof.usuario_id =hs.usuario_id
|
||||
where :id_fac = ANY(hs.facultad_id_array) and prof.usuario_id = :id_prof
|
||||
and prof.usuario_correo is not null and prof.usuario_correo != ''",
|
||||
[':id_prof'=>$prof_id, ':id_fac' => $facultad] );
|
||||
foreach($correosProf_rs as $correo){
|
||||
if(!empty($correo["usuario_correo"]))
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correosProf_rs);
|
||||
}
|
||||
$to .= join(",", $correos);
|
||||
}
|
||||
|
||||
if($to!= "" && self::ENVIO_CORREOS){
|
||||
//crear plantilla
|
||||
$texto = '<body >
|
||||
<img src="https://paad.lci.ulsa.mx/imagenes/logo_lasalle.png" alt="La Salle" style="margin-bottom:60px">
|
||||
'.$texto.'
|
||||
</body>';
|
||||
|
||||
if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
|
||||
$asunto = "PRUEBAS-".$asunto;
|
||||
}
|
||||
return Mailer::enviarCorreo($to, $asunto, $texto, true);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,38 +1,38 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"IdNivel",
|
||||
"IdPeriodo",
|
||||
"NombreNivel",
|
||||
"NombrePeriodo"
|
||||
],
|
||||
"properties": {
|
||||
"IdNivel": {
|
||||
"type": "integer"
|
||||
},
|
||||
"IdPeriodo": {
|
||||
"type": "integer"
|
||||
},
|
||||
"NombreNivel": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"LICENCIATURA",
|
||||
"ESPECIALIDAD",
|
||||
"MAESTRÍA",
|
||||
"DOCTORADO",
|
||||
"COORDINACIÓN DE EDUCACIÓN FÍSICA Y DEPORTES",
|
||||
"COORDINACIÓN DE IMPULSO Y VIDA ESTUDIANTIL",
|
||||
"COORDINACIÓN DE FORMACIÓN CULTURAL",
|
||||
"VICERRECTORÍA DE BIENESTAR Y FORMACIÓN",
|
||||
"CENTRO DE IDIOMAS"
|
||||
]
|
||||
},
|
||||
"NombrePeriodo": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"IdNivel",
|
||||
"IdPeriodo",
|
||||
"NombreNivel",
|
||||
"NombrePeriodo"
|
||||
],
|
||||
"properties": {
|
||||
"IdNivel": {
|
||||
"type": "integer"
|
||||
},
|
||||
"IdPeriodo": {
|
||||
"type": "integer"
|
||||
},
|
||||
"NombreNivel": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"LICENCIATURA",
|
||||
"ESPECIALIDAD",
|
||||
"MAESTRÍA",
|
||||
"DOCTORADO",
|
||||
"COORDINACIÓN DE EDUCACIÓN FÍSICA Y DEPORTES",
|
||||
"COORDINACIÓN DE IMPULSO Y VIDA ESTUDIANTIL",
|
||||
"COORDINACIÓN DE FORMACIÓN CULTURAL",
|
||||
"VICERRECTORÍA DE BIENESTAR Y FORMACIÓN",
|
||||
"CENTRO DE IDIOMAS"
|
||||
]
|
||||
},
|
||||
"NombrePeriodo": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user