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

<?php 

require_once('class.dbaccess.php');
require_once('class.template.php');
require_once('class.filter.php');
require_once('class.page.php');

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

		return $sql;
	}
	
	
	public function GetAll(Page $oPage = NULL, $filter = NULL)
	{
		$sql = " SELECT * ";
		$sql.= " FROM tblTemplates ";
		$sql.= " WHERE 1";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Nombre ASC";
		$sql.= ($oPage) ? Pageable::ParsePage($oPage) : "";

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

	public function GetById($IdTemplate)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblTemplates";
		$sql.= " WHERE IdTemplate = " . DB::Number($IdTemplate);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oTemplate = new Template();
		$oTemplate->ParseFromArray($oRow);
		
		return $oTemplate;		
	}
	
	
	public function GetByNombre($Nombre)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblTemplates";
		$sql.= " WHERE Nombre LIKE " . DB::String($Nombre);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oTemplate = new Template();
		$oTemplate->ParseFromArray($oRow);
		
		return $oTemplate;		
	}
	
	
	public function GetCountRows(array $filter = NULL)
	{
		$sql = " SELECT * ";
		$sql.= " FROM tblTemplates ";
		$sql.= " WHERE 1";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Nombre";
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
		
		$CountRows = $oRes->NumRows();
		
		return $CountRows;
	}
	
	
	public function Create(Template $oTemplate)
	{
		$arr = array
		(
			'Nombre' 		=> DB::String($oTemplate->Nombre),
			'ImagenHeader' 	=> DB::String($oTemplate->ImagenHeader),
			'ImagenFooter' 	=> DB::String($oTemplate->ImagenFooter),
			'Css' 			=> DB::String($oTemplate->Css)
		);
		
		if (!$this->Insert('tblTemplates', $arr))
			return false;
			
		return $oTemplate;
	}
	
	
	public function Update(Template $oTemplate)
	{
		$where = " IdTEmplate = " . DB::Number($oTemplate->IdTemplate);
		
		$arr = array
		(
			'Nombre' 		=> DB::String($oTemplate->Nombre),
			'ImagenHeader' 	=> DB::String($oTemplate->ImagenHeader),
			'ImagenFooter' 	=> DB::String($oTemplate->ImagenFooter),
			'Css' 			=> DB::String($oTemplate->Css)
		);
		
		if (!DBAccess::UpdateEntidad('tblTemplates', $arr, $where))
			return false;
		
		return $oTemplate;
	}
	

	public function Delete($IdTemplate)
	{
		if (!DBAccess::$db->Begin())
			return false;
		
		$oTemplate = new Template();
		$oTemplate = $this->GetById($IdTemplate);
		
		if ($oTemplate->ImagenHeader != '')
			Up::DeleteFile(Template::PathImageHeader, $oTemplate->ImagenHeader);
			
		if ($oTemplate->ImagenFooter != '')
			Up::DeleteFile(Template::PathImageFooter, $oTemplate->ImagenFooter);
		
		if ($oTemplate->Css != '')
			Up::DeleteFile(Template::PathCss, $oTemplate->Css);
			
		$where = " IdTemplate = " . DB::Number($IdTemplate);
		if (!DBAccess::DeleteEntidad('tblTemplates', $where))
		{
				DBAccess::$db->Rollback();	
				return false;
		}

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

?>

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