137 lines
3.0 KiB
PHP
Executable File
137 lines
3.0 KiB
PHP
Executable File
<?php
|
|
|
|
class Color extends Main
|
|
{
|
|
private $colorId;
|
|
private $nombre;
|
|
|
|
public function setColorId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->colorId = $value;
|
|
}
|
|
|
|
public function setNombre($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, "Nombre");
|
|
$this->nombre = $value;
|
|
}
|
|
|
|
public function Info()
|
|
{
|
|
|
|
$sql = 'SELECT
|
|
*
|
|
FROM
|
|
color
|
|
WHERE
|
|
colorId = "'.$this->colorId.'"';
|
|
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$info = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
$row = $this->Util->EncodeRow($info);
|
|
|
|
return $row;
|
|
}
|
|
|
|
public function EnumerateAll()
|
|
{
|
|
|
|
$sql = 'SELECT
|
|
*
|
|
FROM
|
|
color
|
|
ORDER BY
|
|
nombre ASC';
|
|
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
return $result;
|
|
}
|
|
|
|
function Enumerate()
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT COUNT(*) FROM color");
|
|
$total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
$pages = $this->Util->HandleMultipages($this->page, $total ,WEB_ROOT."/colores");
|
|
|
|
$sqlAdd = "LIMIT ".$pages["start"].", ".$pages["items_per_page"];
|
|
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT * FROM color ORDER BY nombre ASC ".$sqlAdd);
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
$data["items"] = $result;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
}
|
|
|
|
function Save()
|
|
{
|
|
if($this->Util()->PrintErrors()){ return false; }
|
|
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("
|
|
INSERT INTO `color` (
|
|
`nombre`
|
|
)
|
|
VALUES (
|
|
'".utf8_decode($this->nombre)."'
|
|
)"
|
|
);
|
|
|
|
$colorId = $this->Util()->DBSelect($_SESSION["empresaId"])->InsertData();
|
|
|
|
$this->Util()->setError(20046, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
if($this->Util()->PrintErrors()){ return false; }
|
|
|
|
$sql = "
|
|
UPDATE `color` SET
|
|
`nombre` = '".utf8_decode($this->nombre)."'
|
|
WHERE colorId = '".$this->colorId."'
|
|
";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->UpdateData();
|
|
|
|
$this->Util()->setError(20047, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
}
|
|
|
|
function Delete()
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("
|
|
DELETE FROM color
|
|
WHERE colorId = '".$this->colorId."'"
|
|
);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
$this->Util()->setError(20048, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
}
|
|
|
|
function GetNameById()
|
|
{
|
|
$sql = 'SELECT nombre FROM color
|
|
WHERE colorId = "'.$this->colorId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$nombre = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $nombre;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|