From ea0e3ff9be65c90b83c7efdf0e24e05c45535ab3 Mon Sep 17 00:00:00 2001 From: nickpons666 Date: Wed, 7 Jan 2026 21:54:54 -0600 Subject: [PATCH] Fix usuarios module: resolve PHP 8 warnings and fatal errors - Fixed undefined array key warnings in usuarios-agregar.php - Fixed undefined variable warnings (, , ) - Fixed null array offset warnings in db.class.php GetSingle() - Added default parameter to ValidateMail() in util.class.php - Fixed PrintErrors() return value for proper error handling - Fixed integer constraint errors for codigoPostal and sucursalId - Added missing identificacion and comprobante fields to INSERT query - Fixed undefined variable in IsEmailTaked() --- classes/db.class.php | 6 ++-- classes/usuario.class.php | 56 ++++++++++++++++++++---------------- classes/util.class.php | 15 ++++++---- modules/usuarios-agregar.php | 29 ++++++++++++------- 4 files changed, 63 insertions(+), 43 deletions(-) diff --git a/classes/db.class.php b/classes/db.class.php index 59226c5..b597cd3 100755 --- a/classes/db.class.php +++ b/classes/db.class.php @@ -205,11 +205,9 @@ public function DatabaseConnect() } else { $row = mysqli_fetch_array($this->sqlResult); } - $rs = $row[0]; - if(!$rs) - $rs = 0; - + $rs = ($row && isset($row[0])) ? $row[0] : 0; + $this->CleanQuery(); return $rs; diff --git a/classes/usuario.class.php b/classes/usuario.class.php index dca3b4c..030842a 100755 --- a/classes/usuario.class.php +++ b/classes/usuario.class.php @@ -117,7 +117,7 @@ class Usuario extends Main public function setCodigoPostal($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Codigo Postal"); - $this->codigoPostal = $value; + $this->codigoPostal = empty($value) ? 0 : $value; } public function setTelefono($value) @@ -156,10 +156,10 @@ class Usuario extends Main $this->tipo = $value; } - public function setSucursalId($value) + public function setSucursalId($value) { $this->Util()->ValidateString($value, $max_chars=300, $minChars = 0, 'Sucursal'); - $this->sucursalId = $value; + $this->sucursalId = empty($value) ? 0 : $value; } public function setEmail($value) @@ -227,40 +227,45 @@ class Usuario extends Main public function Save() { - if($this->Util()->PrintErrors()){ - return false; + if($this->Util()->PrintErrors()){ + return false; } - + + $identificacion = isset($this->identificacion) ? $this->identificacion : ''; + $comprobante = isset($this->comprobante) ? $this->comprobante : ''; + $db = new DB(true); $db->setQuery(" - INSERT INTO usuario ( + INSERT INTO usuario ( empresaId, nombre, - apellidos, + apellidos, calle, - noInt, - noExt, - referencia, - colonia, - localidad, - municipio, + noInt, + noExt, + referencia, + colonia, + localidad, + municipio, estado, - pais, + pais, codigoPostal, telefono, celular, noImss, curp, rfc, - email, - password, + identificacion, + comprobante, + email, + password, `type`, - sucursalId - ) + sucursalId + ) VALUES ( '".$_SESSION["empresaId"]."', '".$this->nombre."', - '".$this->apellidos."', + '".$this->apellidos."', '".$this->calle."', '".$this->noInt."', '".$this->noExt."', @@ -276,11 +281,12 @@ class Usuario extends Main '".$this->noImss."', '".$this->curp."', '".$this->rfc."', + '".$identificacion."', + '".$comprobante."', '".$this->email."', '".$this->passwd."', '".$this->tipo."', - '".$this->sucursalId."')" - ); + '".$this->sucursalId."')"); $usuarioId = $db->InsertData(); $this->Util()->setError(20017, "complete"); @@ -494,10 +500,12 @@ class Usuario extends Main } function IsEmailTaked(){ - + + $sqlAdd = ''; + if($this->usuarioId) $sqlAdd = ' AND usuarioId <> "'.$this->usuarioId.'"'; - + $sql = 'SELECT usuarioId FROM usuario WHERE email = "'.$this->email.'" '.$sqlAdd.' diff --git a/classes/util.class.php b/classes/util.class.php index 61fc4c5..42a0faa 100755 --- a/classes/util.class.php +++ b/classes/util.class.php @@ -168,15 +168,15 @@ class Util extends SystemError return true; } }//ValidateFloat - - function ValidateMail($mail, $field) + + function ValidateMail($mail, $field = 'Email') { $mail = strtolower($mail); if (!preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',trim($mail))) { return $this->setError(10002, "error", "", $field); } - } + } function ValidateUrl($url) { @@ -477,12 +477,16 @@ class Util extends SystemError function PrintErrors() { + if(empty($this->error)){ + return false; + } + $errorStr = "
"; foreach($this->error as $key => $val) { $msg = $this->errorMessage($val); - $field = $this->errorField[$key]; - + $field = isset($this->errorField[$key]) ? $this->errorField[$key] : ''; + $errorStr .= "
"; if($field != "") { @@ -493,6 +497,7 @@ class Util extends SystemError } $errorStr .= "
"; echo $errorStr; + return true; } function errorMessage($code) diff --git a/modules/usuarios-agregar.php b/modules/usuarios-agregar.php index 5200eb4..075ddd3 100755 --- a/modules/usuarios-agregar.php +++ b/modules/usuarios-agregar.php @@ -7,10 +7,10 @@ exit; } - if($_POST['type'] == 'saveUsuario'){ - + if(isset($_POST['type']) && $_POST['type'] == 'saveUsuario'){ + $tipo = $_POST['tipo']; - $idSuc = $_POST['idSuc']; + $idSuc = isset($_POST['idSuc']) ? $_POST['idSuc'] : array(); $usuario->setTipo($tipo); $usuario->setNombre($_POST['nombre']); @@ -109,20 +109,29 @@ exit; } - + + $nomSuc = ''; + $info = array('type' => '', 'sucursalId' => ''); + $post = array('sucursalId' => ''); + if($Usr['type'] == 'gerente'){ $sucursal->setSucursalId($Usr['sucursalId']); $nomSuc = $sucursal->GetNameById(); $nomSuc = strtoupper(utf8_decode(urldecode($nomSuc))); } - + $sucursales = $sucursal->GetSucursalesByEmpresaId(); - foreach ($sucursales as $key => $sucursal ){ - $sucursales[$key]['nombre'] = utf8_decode(urldecode($sucursal['nombre'])); + $sucursalesFiltered = array(); + foreach ($sucursales as $item ){ + if($item){ + $item['nombre'] = utf8_decode(urldecode($item['nombre'])); + $sucursalesFiltered[] = $item; + } } - + + $smarty->assign('info', $info); + $smarty->assign('post', $post); $smarty->assign('nomSuc', $nomSuc); - $smarty->assign('usuarios', $usuarios); - $smarty->assign('sucursales', $sucursales); + $smarty->assign('sucursales', $sucursalesFiltered); ?> \ No newline at end of file