Stable
This commit is contained in:
@@ -1,73 +1,73 @@
|
||||
<?php
|
||||
/*
|
||||
* Objeto para leer y escribir datos de log de intentos de asistencia realizadas por el usuario
|
||||
*/
|
||||
|
||||
namespace classes;
|
||||
|
||||
define("MAX_LINES", 200);
|
||||
class LogAsistencias
|
||||
{
|
||||
//put your code here
|
||||
private $file, $month, $year;
|
||||
private $dir;
|
||||
|
||||
function __construct($ruta = null)
|
||||
{
|
||||
// die ruta
|
||||
$this->month = date("m");
|
||||
$this->year = date("Y");
|
||||
$this->dir = ($ruta ?? '') . "log/";
|
||||
$this->updateFilename();
|
||||
}
|
||||
|
||||
function setMes(string $mes)
|
||||
{
|
||||
$this->month = $mes;
|
||||
$this->updateFilename();
|
||||
}
|
||||
function setAno(string $ano)
|
||||
{
|
||||
$this->year = $ano;
|
||||
$this->updateFilename();
|
||||
}
|
||||
|
||||
private function updateFilename()
|
||||
{
|
||||
$this->file = "asistencias_" . $this->year . "_" . $this->month . ".log";
|
||||
}
|
||||
private function cleanLog($text)
|
||||
{ //remueve || de los textos
|
||||
return trim(str_ireplace("||", "", $text));
|
||||
}
|
||||
|
||||
function appendLog($claveULSA, $nombre, $desc)
|
||||
{
|
||||
$filename = $this->dir . $this->file;
|
||||
if (!file_exists($this->dir)) {
|
||||
mkdir($this->dir, 0755, true);
|
||||
}
|
||||
if (file_exists($this->dir)) {
|
||||
$data = date('Y-m-d H:i:s') . "||" . $this->cleanLog($claveULSA) . "||" . $this->cleanLog($desc) . "||" . $this->cleanLog($nombre) . "\n";
|
||||
/*echo*/
|
||||
file_put_contents($filename, $data, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
function getLog($mes = "", $ano = "")
|
||||
{
|
||||
if ($mes != "") $this->setMes($mes);
|
||||
if ($ano != "") $this->setAno($ano);
|
||||
$filename = $this->dir . $this->file;
|
||||
if (file_exists($filename)) {
|
||||
//return array_slice(file ($filename , FILE_SKIP_EMPTY_LINES) , -10);
|
||||
$lines = file($filename, FILE_SKIP_EMPTY_LINES);
|
||||
//echo "antes: ".count($lines);
|
||||
if (count($lines) > MAX_LINES) {
|
||||
$lines = array_slice($lines, MAX_LINES * (-1));
|
||||
}
|
||||
//echo "despues: ".count($lines);
|
||||
return $lines;
|
||||
} else
|
||||
return array();
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/*
|
||||
* Objeto para leer y escribir datos de log de intentos de asistencia realizadas por el usuario
|
||||
*/
|
||||
|
||||
namespace classes;
|
||||
|
||||
define("MAX_LINES", 200);
|
||||
class LogAsistencias
|
||||
{
|
||||
//put your code here
|
||||
private $file, $month, $year;
|
||||
private $dir;
|
||||
|
||||
function __construct($ruta = null)
|
||||
{
|
||||
// die ruta
|
||||
$this->month = date("m");
|
||||
$this->year = date("Y");
|
||||
$this->dir = ($ruta ?? '') . "log/";
|
||||
$this->updateFilename();
|
||||
}
|
||||
|
||||
function setMes(string $mes)
|
||||
{
|
||||
$this->month = $mes;
|
||||
$this->updateFilename();
|
||||
}
|
||||
function setAno(string $ano)
|
||||
{
|
||||
$this->year = $ano;
|
||||
$this->updateFilename();
|
||||
}
|
||||
|
||||
private function updateFilename()
|
||||
{
|
||||
$this->file = "asistencias_" . $this->year . "_" . $this->month . ".log";
|
||||
}
|
||||
private function cleanLog($text)
|
||||
{ //remueve || de los textos
|
||||
return trim(str_ireplace("||", "", $text));
|
||||
}
|
||||
|
||||
function appendLog($claveULSA, $nombre, $desc)
|
||||
{
|
||||
$filename = $this->dir . $this->file;
|
||||
if (!file_exists($this->dir)) {
|
||||
mkdir($this->dir, 0755, true);
|
||||
}
|
||||
if (file_exists($this->dir)) {
|
||||
$data = date('Y-m-d H:i:s') . "||" . $this->cleanLog($claveULSA) . "||" . $this->cleanLog($desc) . "||" . $this->cleanLog($nombre) . "\n";
|
||||
/*echo*/
|
||||
file_put_contents($filename, $data, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
function getLog($mes = "", $ano = "")
|
||||
{
|
||||
if ($mes != "") $this->setMes($mes);
|
||||
if ($ano != "") $this->setAno($ano);
|
||||
$filename = $this->dir . $this->file;
|
||||
if (file_exists($filename)) {
|
||||
//return array_slice(file ($filename , FILE_SKIP_EMPTY_LINES) , -10);
|
||||
$lines = file($filename, FILE_SKIP_EMPTY_LINES);
|
||||
//echo "antes: ".count($lines);
|
||||
if (count($lines) > MAX_LINES) {
|
||||
$lines = array_slice($lines, MAX_LINES * (-1));
|
||||
}
|
||||
//echo "despues: ".count($lines);
|
||||
return $lines;
|
||||
} else
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +1,143 @@
|
||||
<?php
|
||||
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);
|
||||
|
||||
require_once($ruta ?? '') . "include/bd_pdo.php";
|
||||
require_once($ruta ?? '') . "class/c_logasistencia.php";
|
||||
require_once($ruta ?? '') . "include/nusoap/nusoap.php";
|
||||
|
||||
session_start();
|
||||
class Login
|
||||
{
|
||||
public string $acceso;
|
||||
public function __construct(public array $user, public array $facultad, public array $rol, public bool $admin, public ?int $periodo, public bool $supervisor, public bool $jefe_carrera, public bool $profesor)
|
||||
{
|
||||
}
|
||||
public function print_to_log(string $desc, array $old = null, array $new = null): void
|
||||
{
|
||||
$log = new classes\LogAsistencias($_ENV["RUTA_RAIZ"]);
|
||||
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): void
|
||||
{
|
||||
if ($this->admin) {
|
||||
$this->acceso = "w";
|
||||
return;
|
||||
}
|
||||
|
||||
# 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';
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
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, ['ad017045']) and $pass == "admin")
|
||||
return true;
|
||||
$client = new nusoap_client('http://200.13.89.2/validacion.php?wsdl', 'wsdl');
|
||||
$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
|
||||
{
|
||||
if (!Login::validaUsuario($user, $pass)) {
|
||||
return [
|
||||
'error' => true,
|
||||
'msg' => 'Error al autenticar usuario'
|
||||
];
|
||||
}
|
||||
global $db;
|
||||
|
||||
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();
|
||||
}
|
||||
<?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($ruta ?? '') . "include/bd_pdo.php";
|
||||
require_once($ruta ?? '') . "class/c_logasistencia.php";
|
||||
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, public bool $supervisor, public bool $jefe_carrera, public bool $profesor)
|
||||
{
|
||||
}
|
||||
public function print_to_log(string $desc, array $old = null, array $new = null): void
|
||||
{
|
||||
$log = new classes\LogAsistencias($_ENV["RUTA_RAIZ"]);
|
||||
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): void
|
||||
{
|
||||
|
||||
global $db;
|
||||
|
||||
if ($this->admin) {
|
||||
$this->acceso = "w";
|
||||
return;
|
||||
}
|
||||
|
||||
# print_r( $access );
|
||||
$this->acceso = $db->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"]}), 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 ($user == 'ad017045' and $pass == "admin")
|
||||
return true;
|
||||
|
||||
$client = new nusoap_client('http://200.13.89.2/validacion.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
|
||||
{
|
||||
if (Login::validaUsuario($user, $pass) === false) {
|
||||
return [
|
||||
'error' => true,
|
||||
'msg' => 'Error al autenticar usuario'
|
||||
];
|
||||
}
|
||||
global $db;
|
||||
|
||||
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"],
|
||||
'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');
|
||||
|
||||
$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: null, supervisor: false, jefe_carrera: false, profesor: true);
|
||||
} else
|
||||
return [
|
||||
'error' => true,
|
||||
'msg' => 'Usuario no encontrado'
|
||||
];
|
||||
}
|
||||
public static function log_out(): void
|
||||
{
|
||||
session_start();
|
||||
session_destroy();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
class Menu {
|
||||
private array $menu = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->conn = new Connection();
|
||||
}
|
||||
|
||||
public function getMenu() {
|
||||
$sql = "SELECT * FROM menu";
|
||||
$result = $this->conn->getConnection()->query($sql);
|
||||
$this->menu = $result->fetchAll();
|
||||
return $this->menu;
|
||||
}
|
||||
<?php
|
||||
class Menu {
|
||||
private array $menu = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->conn = new Connection();
|
||||
}
|
||||
|
||||
public function getMenu() {
|
||||
$sql = "SELECT * FROM menu";
|
||||
$result = $this->conn->getConnection()->query($sql);
|
||||
$this->menu = $result->fetchAll();
|
||||
return $this->menu;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +1,57 @@
|
||||
<?php
|
||||
define("DB_HOST",($_SERVER["SERVER_NAME"] == "localhost") ? "200.13.89.27" : "localhost");
|
||||
define('DB_USER', 'checa_usr');
|
||||
define('DB_PASS', 'Cr0n0m3tr4d0&$');
|
||||
define('DB_NAME', 'checador');
|
||||
|
||||
class Connection {
|
||||
private $conn;
|
||||
public function __construct() {
|
||||
$this->conn = new PDO(
|
||||
"pgsql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER, DB_PASS,
|
||||
array(PDO::ATTR_PERSISTENT => true)
|
||||
);
|
||||
}
|
||||
public function getConnection() {
|
||||
return $this->conn;
|
||||
}
|
||||
|
||||
public function query() {}
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
"pgsql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS,
|
||||
array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_PERSISTENT => true
|
||||
)
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
print "Error!: " . $e->getMessage() . "<br/>";
|
||||
die();
|
||||
}
|
||||
|
||||
function SQL(string $sql, array $params = [])
|
||||
{
|
||||
global $pdo;
|
||||
$stmt = $pdo->prepare($sql);
|
||||
foreach ($params as $key => $value) {
|
||||
// bind Parameter
|
||||
$stmt->bindParam($key, $value);
|
||||
}
|
||||
$stmt->execute($params);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function filter_by(array $array, array $fields): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($array as $key => $value) {
|
||||
$result[$key] = [];
|
||||
foreach ($fields as $field) {
|
||||
$result[$key][$field] = $value[$field];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
<?php
|
||||
define("DB_HOST",($_SERVER["SERVER_NAME"] == "localhost") ? "200.13.89.27" : "localhost");
|
||||
define('DB_USER', 'checa_usr');
|
||||
define('DB_PASS', 'Cr0n0m3tr4d0&$');
|
||||
define('DB_NAME', 'checador');
|
||||
|
||||
class Connection {
|
||||
private $conn;
|
||||
public function __construct() {
|
||||
$this->conn = new PDO(
|
||||
"pgsql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER, DB_PASS,
|
||||
array(PDO::ATTR_PERSISTENT => true)
|
||||
);
|
||||
}
|
||||
public function getConnection() {
|
||||
return $this->conn;
|
||||
}
|
||||
|
||||
public function query() {}
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
"pgsql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS,
|
||||
array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_PERSISTENT => true
|
||||
)
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
print "Error!: " . $e->getMessage() . "<br/>";
|
||||
die();
|
||||
}
|
||||
|
||||
function SQL(string $sql, array $params = [])
|
||||
{
|
||||
global $pdo;
|
||||
$stmt = $pdo->prepare($sql);
|
||||
foreach ($params as $key => $value) {
|
||||
// bind Parameter
|
||||
$stmt->bindParam($key, $value);
|
||||
}
|
||||
$stmt->execute($params);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function filter_by(array $array, array $fields): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($array as $key => $value) {
|
||||
$result[$key] = [];
|
||||
foreach ($fields as $field) {
|
||||
$result[$key][$field] = $value[$field];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
Reference in New Issue
Block a user