Util()->ValidateString($value, $max_chars=50, $minChars = 1, "Motivo"); $this->motivoId = $value; } public function setNombre($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Nombre'); $this->nombre = $value; } public $page = 0; public function SetPage($page) { $this->page = $page; } function Info(){ $sql = "SELECT * FROM motivo WHERE motivoId = '".$this->motivoId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $row = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow(); return $row; } function EnumerateAll() { $sql = "SELECT * FROM motivo WHERE baja = '0' ORDER BY nombre ASC"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $motivos = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult(); return $motivos; } function Enumerate() { $db = $this->Util()->DBSelect($_SESSION["empresaId"]); $sql = "SELECT COUNT(*) FROM motivo WHERE baja = '0'"; $db->setQuery($sql); $total = $db->GetSingle(); $pages = $this->Util()->HandleMultipages($this->page, $total ,WEB_ROOT."/motivos", "p"); $sqlAdd = " LIMIT ".$pages["start"].", ".$pages["items_per_page"]; $sql = "SELECT * FROM motivo WHERE baja = '0' ORDER BY nombre ASC".$sqlAdd; $db->setQuery($sql); $motivos = $db->GetResult(); $data["items"] = $motivos; $data["pages"] = $pages; return $data; } function Save(){ if($this->Util()->PrintErrors()){ return false; } $sql = "INSERT INTO `motivo` ( nombre ) VALUES ( '".utf8_decode($this->nombre)."' )"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->ExecuteQuery(); $this->Util()->setError(30051, "complete"); $this->Util()->PrintErrors(); return true; } function Update(){ if($this->Util()->PrintErrors()){ return false; } $sql = "UPDATE `motivo` SET nombre = '".utf8_decode($this->nombre)."' WHERE motivoId = ".$this->motivoId; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->ExecuteQuery(); $this->Util()->setError(30052, "complete"); $this->Util()->PrintErrors(); return true; } function Delete(){ $sql = "DELETE FROM motivo WHERE motivoId = '".$this->motivoId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $this->Util()->setError(30053, "complete"); $this->Util()->PrintErrors(); return true; } function Baja(){ $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery(" UPDATE motivo SET baja = '1' WHERE motivoId = '".$this->motivoId."'" ); $this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData(); $this->Util()->setError(30053, "complete"); $this->Util()->PrintErrors(); return true; }//Baja function GetNameById(){ $sql = "SELECT nombre FROM motivo WHERE motivoId = '".$this->motivoId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $name = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $name; } }//Motivo ?>