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.paises.php

<?php 

require_once('class.dbaccess.php');
require_once('class.configuraciones.php');
require_once('class.pais.php');
require_once('class.filter.php');
require_once('class.page.php');

class Paises extends DBAccess implements IFilterable
{
	public function ParseFilter(array $filter)
	{
		$sql = ' WHERE 1';
		
		if ((isset($filter['Nombre'])) && ($filter['Nombre'] != ''))
			$sql.= " AND Nombre LIKE '%" . DB::StringUnquoted($filter['Nombre']) . "%'";
		
		if ((isset($filter['Socio'])) && ($filter['Socio'] == '1'))
			$sql.= " AND IdPais IN (SELECT IdPais FROM tblSocios)";
		
		return $sql;
	}


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


	public function GetAllBusqueda(array $filter = NULL, Page $oPage = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblPaises";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Nombre";
		$sql.= ($oPage) ? Pageable::ParsePage($oPage) : "";

		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		$arr = array();
		
		array_push($arr, new Pais());	
		
		while ($oRow = $oRes->GetRow())	
		{	
			$oPais = new Pais();
			$oPais->ParseFromArray($oRow);
			$oPais->Nombre = utf8_encode($oPais->Nombre);
			
			array_push($arr, $oPais);
			
			$oRes->MoveNext();
		}	
		
		return $arr;		
	}
	

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

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

	
	public function GetCountRows(array $filter = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblPaises";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Nombre";
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
		
		$CountRows = $oRes->NumRows();
		
		return $CountRows;
	}
	
		
	public function GetAllUsed()
	{
		$sql = "SELECT p.*";
		$sql.= " FROM tblPaises p";
		$sql.= " LEFT JOIN tblUsuarios u ON u.IdPais = p.IdPais";
		$sql.= " LEFT JOIN tblUsuariosNewsletter un ON un.IdPais = p.IdPais";
		$sql.= " WHERE";
		$sql.= " (";
		$sql.= " 	u.IdPais IS NOT NULL";
		$sql.= " 	OR un.IdPais IS NOT NULL";
		$sql.= " )";
		$sql.= " GROUP BY p.IdPais";
		$sql.= " ORDER BY p.Nombre ASC";

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


	public function GetForEnvioZona(EnvioZona $oEnvioZona)
	{
		/* obtenemos informacion de configuracion del sitio */
		$oConfiguraciones = new Configuraciones();
		$oConfiguracion = $oConfiguraciones->GetRow();

		switch ($oConfiguracion->TipoEnvio)
		{
			case 'A':
				$sql = "SELECT p.*";
				$sql.= " FROM tblPaises p";
				$sql.= " LEFT JOIN tblEnvioZonaDetalles ezd ON p.IdPais = ezd.IdPais";
				$sql.= " WHERE ezd.IdPais IS NULL";
				$sql.= " GROUP BY p.IdPais";
				$sql.= " ORDER BY p.Nombre";
				break;
				
			case 'B':
				$sql = "SELECT *,";
				$sql.= " (";
				$sql.= " 	SELECT COUNT(IdProvincia)";
				$sql.= " 	FROM tblProvincias";
				$sql.= " 	WHERE IdPais = p.IdPais";
				$sql.= " ) AS ProvinciasTotales,";
				$sql.= " (";
				$sql.= " 	SELECT COUNT(IdProvincia)";
				$sql.= " 	FROM tblEnvioZonaDetalles";
				$sql.= " 	WHERE IdPais = p.IdPais";
				$sql.= " ) AS ProvinciasUtilizadas";
				$sql.= " FROM tblPaises p";
				$sql.= " LEFT JOIN tblEnvioZonaDetalles ezd ON p.IdPais = ezd.IdPais";
				$sql.= " GROUP BY p.IdPais";
				$sql.= " HAVING ProvinciasUtilizadas < ProvinciasTotales";
				$sql.= " OR ezd.IdEnvioZona = " . DB::Number($oEnvioZona->IdEnvioZona);
				break;
			
			case 'C':
				$sql = "SELECT *,";
				$sql.= " (";
				$sql.= " 	SELECT COUNT(IdLocalidad)";
				$sql.= " 	FROM tblLocalidades";
				$sql.= " 	WHERE IdPais = p.IdPais";
				$sql.= " ) AS LocalidadesTotales,";
				$sql.= " (";
				$sql.= " 	SELECT COUNT(IdLocalidad)";
				$sql.= " 	FROM tblEnvioZonaDetalles";
				$sql.= " 	WHERE IdPais = p.IdPais";
				$sql.= " ) AS LocalidadesUtilizadas";
				$sql.= " FROM tblPaises p";
				$sql.= " LEFT JOIN tblEnvioZonaDetalles ezd ON p.IdPais = ezd.IdPais";
				$sql.= " GROUP BY p.IdPais";
				$sql.= " HAVING LocalidadesUtilizadas < LocalidadesTotales";
				$sql.= " OR ezd.IdEnvioZona = " . DB::Number($oEnvioZona->IdEnvioZona);
				break;
				
			default:
				break;
		}
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		$arr = array();
			
		while ($oRow = $oRes->GetRow())	
		{	
			$oPais = new Pais();
			$oPais->ParseFromArray($oRow);
			
			array_push($arr, $oPais);
			
			$oRes->MoveNext();
		}	
		
		return $arr;		
	}
	
	
	public function Create(Pais $oPais)
	{
		$arr = array
		(
			'Nombre' 		=> DB::String($oPais->Nombre),
			'Abreviatura' 	=> DB::String($oPais->Abreviatura)
		);
		
		if (!$this->Insert('tblPaises', $arr))
			return false;
			
		return $oPais;
	}
	
	
	public function Update(Pais $oPais)
	{
		$where = " IdPais = " . DB::Number($oPais->IdPais);
		
		$arr = array
		(
			'Nombre' 		=> DB::String($oPais->Nombre),
			'Abreviatura' 	=> DB::String($oPais->Abreviatura)
		);
		
		if (!DBAccess::UpdateEntidad('tblPaises', $arr, $where))
			return false;
		
		return $oPais;
	}
	

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

		DBAccess::$db->Commit();
		
		return true;	
	}		
}

?>

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