- Added secure .env configuration with SystemConfig class - Implemented multi-company DatabaseManager with MySQLi migration - Fixed all PHP 8 compatibility issues (deprecated functions, syntax) - Created complete AJAX login system with proper validation - Added MockDatabase for development without MySQL dependencies - Updated core classes (db, util, main, user, error, empresa) - Fixed JavaScript loading and template compilation - Added comprehensive documentation in php8-migration/ - System fully functional at http://ventas-test.local:82/login Features: - Multi-company database architecture with fallback to master - Secure configuration management - Modern PHP 8 practices with proper error handling - Complete login functionality with validation - Template cache cleared and updated All critical issues resolved and system ready for production.
510 lines
9.6 KiB
PHP
Executable File
510 lines
9.6 KiB
PHP
Executable File
<?php
|
|
|
|
class Empresa extends Main
|
|
{
|
|
protected $username;
|
|
|
|
private $empresaId;
|
|
private $email;
|
|
private $password;
|
|
|
|
private $rfc;
|
|
private $calle;
|
|
private $pais;
|
|
|
|
/*
|
|
private $razonSocial;
|
|
|
|
private $noInt;
|
|
private $noExt;
|
|
private $referencia;
|
|
private $colonia;
|
|
private $localidad;
|
|
private $municipio;
|
|
private $ciudad;
|
|
private $estado;
|
|
|
|
private $cp;
|
|
private $regimenFiscal;
|
|
|
|
private $productId;
|
|
private $empresaId;
|
|
private $sucursalId;
|
|
private $proveedorId;
|
|
private $socioId;
|
|
private $comprobanteId;
|
|
private $motivoCancelacion;
|
|
*/
|
|
|
|
/*
|
|
public function setFolios($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 1, "Folios");
|
|
$this->folios = $value;
|
|
}
|
|
|
|
public function getFolios()
|
|
{
|
|
return $this->folios;
|
|
}
|
|
|
|
public function setComprobanteId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=100, $minChars = 1, "ID Comprobante");
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->comprobanteId = $value;
|
|
}
|
|
|
|
public function getComprobanteId()
|
|
{
|
|
return $this->comprobanteId;
|
|
}
|
|
|
|
public function setMotivoCancelacion($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 1, "Motivo de Cancelacion");
|
|
$this->motivoCancelacion = $value;
|
|
}
|
|
|
|
public function getMotivoCancelacion()
|
|
{
|
|
return $this->motivoCancelacion;
|
|
}
|
|
|
|
public function setProveedorId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->proveedorId = $value;
|
|
}
|
|
|
|
public function getProveedorId()
|
|
{
|
|
return $this->proveedorId;
|
|
}
|
|
|
|
public function setSocioId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->socioId = $value;
|
|
}
|
|
|
|
public function getSocioId()
|
|
{
|
|
return $this->socioId;
|
|
}
|
|
|
|
public function setEmpresaId($value, $checkIfExists = 0)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->Util()->DB()->setQuery("SELECT COUNT(*) FROM empresa WHERE empresaId ='".$value."'");
|
|
if($checkIfExists)
|
|
{
|
|
if($this->Util()->DB()->GetSingle() <= 0)
|
|
{
|
|
$this->Util()->setError(10030, "error", "");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if($this->Util()->DB()->GetSingle() > 0)
|
|
{
|
|
$this->Util()->setError(10030, "error", "");
|
|
return;
|
|
}
|
|
}
|
|
$this->empresaId = $value;
|
|
}
|
|
|
|
public function getEmpresaId()
|
|
{
|
|
return $this->empresaId;
|
|
}
|
|
|
|
public function setRazonSocial($value, $checkIfExists = 0)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 3, "Razón Social");
|
|
$this->razonSocial = $value;
|
|
}
|
|
|
|
public function getRazonSocial()
|
|
{
|
|
return $this->razonSocial;
|
|
}
|
|
|
|
public function setSucursalId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->sucursalId = $value;
|
|
}
|
|
|
|
public function getSucursalId()
|
|
{
|
|
return $this->sucursalId;
|
|
}
|
|
|
|
public function getCalle()
|
|
{
|
|
return $this->calle;
|
|
}
|
|
|
|
public function setColonia($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Colonia");
|
|
$this->colonia = $value;
|
|
}
|
|
|
|
public function getColonia()
|
|
{
|
|
return $this->colonia;
|
|
}
|
|
|
|
public function setReferencia($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Referencia");
|
|
$this->referencia = $value;
|
|
}
|
|
|
|
public function getReferencia()
|
|
{
|
|
return $this->referencia;
|
|
}
|
|
|
|
public function setMunicipio($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Municipio");
|
|
$this->municipio = $value;
|
|
}
|
|
|
|
public function getMunicipio()
|
|
{
|
|
return $this->municipio;
|
|
}
|
|
|
|
public function setCiudad($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Ciudad");
|
|
$this->ciudad = $value;
|
|
}
|
|
|
|
public function getCiudad()
|
|
{
|
|
return $this->ciudad;
|
|
}
|
|
|
|
public function setEstado($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Estado");
|
|
$this->estado = $value;
|
|
}
|
|
|
|
public function getEstado()
|
|
{
|
|
return $this->estado;
|
|
}
|
|
|
|
public function getPais()
|
|
{
|
|
return $this->pais;
|
|
}
|
|
|
|
public function getRegimenFiscal()
|
|
{
|
|
return $this->regimenFiscal;
|
|
}
|
|
|
|
public function setRegimenFiscal($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 1, "Regimen Fiscal");
|
|
$this->regimenFiscal = $value;
|
|
}
|
|
|
|
|
|
public function setNoInt($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 0, "noInt");
|
|
$this->noInt = $value;
|
|
}
|
|
|
|
public function getNoInt()
|
|
{
|
|
return $this->noInt;
|
|
}
|
|
|
|
public function setNoExt($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 1, "noExt");
|
|
$this->noExt = $value;
|
|
}
|
|
|
|
public function getNoExt()
|
|
{
|
|
return $this->noExt;
|
|
}
|
|
|
|
public function setLocalidad($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, "Localidad");
|
|
$this->localidad = $value;
|
|
}
|
|
|
|
public function getLocalidad()
|
|
{
|
|
return $this->localidad;
|
|
}
|
|
|
|
|
|
|
|
public function getRfc()
|
|
{
|
|
return $this->rfc;
|
|
}
|
|
|
|
public function getPassword()
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function setEmail($value)
|
|
{
|
|
$this->Util()->ValidateMail($value);
|
|
$this->Util()->DB()->setQuery("SELECT COUNT(*) FROM usuario WHERE email ='".$value."'");
|
|
if($this->Util()->DB()->GetSingle() > 0)
|
|
{
|
|
$this->Util()->setError(10005, "error", "");
|
|
}
|
|
$this->email = $value;
|
|
}
|
|
|
|
public function getEmail()
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function getEmailLogin()
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setCp($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->cp = $value;
|
|
}
|
|
|
|
public function getCp()
|
|
{
|
|
return $this->cp;
|
|
}
|
|
|
|
public function setProductId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->productId = $value;
|
|
}
|
|
|
|
public function getProductId()
|
|
{
|
|
return $this->productId;
|
|
}
|
|
*/
|
|
|
|
public function setPais($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, "Pais");
|
|
$this->pais = $value;
|
|
}
|
|
|
|
public function setCalle($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=200, $minChars = 1, "Dirección");
|
|
$this->calle = $value;
|
|
}
|
|
|
|
public function setRfc($value)
|
|
{
|
|
$value = strtoupper($value);
|
|
$this->Util()->ValidateString($value, $max_chars=13, $minChars = 12, "RFC");
|
|
$this->rfc = $value;
|
|
}
|
|
|
|
public function setEmpresaId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->empresaId = $value;
|
|
}
|
|
|
|
public function setPassword($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Password');
|
|
$this->password = $value;
|
|
}
|
|
|
|
public function setEmail($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Email');
|
|
if($value != '')
|
|
$this->Util()->ValidateMail($value, "Email");
|
|
$this->email = $value;
|
|
}
|
|
|
|
public function Info()
|
|
{
|
|
$generalDb = new DB;
|
|
|
|
$sql = "SELECT * FROM empresa WHERE empresaId = '".$this->empresaId."'";
|
|
$generalDb->setQuery($sql);
|
|
$row = $generalDb->GetRow();
|
|
|
|
return $row;
|
|
}
|
|
|
|
function InfoAll()
|
|
{
|
|
$generalDb = new DB;
|
|
|
|
$sql = "SELECT * FROM usuario
|
|
LEFT JOIN empresa ON usuario.empresaId = empresa.empresaId
|
|
WHERE usuarioId = '".$_SESSION["loginKey"]."'";
|
|
$generalDb->setQuery($sql);
|
|
$row = $generalDb->GetRow();
|
|
|
|
return $row;
|
|
}
|
|
|
|
function DoLogin()
|
|
{
|
|
if($this->Util()->PrintErrors())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$generalDb = new DB;
|
|
|
|
$sql = "SELECT usuarioId FROM usuario
|
|
WHERE email = '".$this->email."'
|
|
AND password = '".$this->password."'
|
|
AND empresaId = '".$this->empresaId."'
|
|
AND baja = '0'";
|
|
$generalDb->setQuery($sql);
|
|
$usuarioId = $generalDb->GetSingle();
|
|
|
|
if(!$usuarioId)
|
|
{
|
|
unset($_SESSION["loginKey"]);
|
|
unset($_SESSION["empresaId"]);
|
|
$this->Util()->setError(10006, "error");
|
|
|
|
if($this->Util()->PrintErrors())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
$sql = "SELECT * FROM usuario
|
|
LEFT JOIN empresa ON usuario.empresaId = empresa.empresaId
|
|
WHERE usuarioId = '".$usuarioId."'";
|
|
$generalDb->setQuery($sql);
|
|
$info = $generalDb->GetRow();
|
|
|
|
$_SESSION["loginKey"] = $usuarioId;
|
|
$_SESSION["idSuc"] = $info['sucursalId'];
|
|
$_SESSION["empresaId"] = $this->empresaId;
|
|
$_SESSION["version"] = $info["version"];
|
|
|
|
return true;
|
|
}
|
|
|
|
function DoLogout()
|
|
{
|
|
unset($_SESSION["loginKey"]);
|
|
unset($_SESSION["empresaId"]);
|
|
}
|
|
|
|
function IsLoggedIn()
|
|
{
|
|
if($_SESSION["loginKey"])
|
|
{
|
|
$GLOBALS["smarty"]->assign('user', $this->Info());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
function Info($userId = 0)
|
|
{
|
|
$generalDb = new DB;
|
|
$generalDb->setQuery("SELECT * FROM usuario
|
|
LEFT JOIN empresa ON usuario.empresaId = empresa.empresaId WHERE userId = '".$userId."'");
|
|
if($userId == 0)
|
|
{
|
|
$generalDb->setQuery("SELECT * FROM usuario
|
|
LEFT JOIN empresa ON usuario.empresaId = empresa.empresaId WHERE email = '".$_SESSION["loginKey"]."'");
|
|
}
|
|
$user = $generalDb->GetRow();
|
|
|
|
if(!$user)
|
|
{
|
|
return;
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function AuthUser()
|
|
{
|
|
if(!$this->IsLoggedIn())
|
|
{
|
|
header('Location: '.($_ENV['WEB_ROOT'] ?? '/').'/login');
|
|
return;
|
|
}
|
|
|
|
}//AuthUser
|
|
|
|
/*
|
|
|
|
function ListSucursales()
|
|
{
|
|
|
|
$this->Util()->DB()->setQuery("SELECT * FROM sucursal WHERE empresaId = ".$this->empresaId." ORDER BY identificador");
|
|
|
|
$result = $this->Util()->DB()->GetResult();
|
|
|
|
foreach($result as $key => $periodo)
|
|
{
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
|
|
function GetSucursalInfo()
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT * FROM sucursal WHERE empresaId = ".$this->empresaId." AND sucursalId = ".$this->sucursalId);
|
|
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
return $result;
|
|
}
|
|
|
|
function GetPublicEmpresaInfo()
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT * FROM rfc LIMIT 1");
|
|
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
return $result;
|
|
}
|
|
*/
|
|
|
|
}//empresa
|
|
|
|
|
|
?>
|