Mister Spy Say ="Hello Kids ... :D"
___ ____ _ _____
| \/ (_) | | / ___|
| . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _
| |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | |
| | | | \__ \ || __/ | /\__/ / |_) | |_| |
\_| |_/_|___/\__\___|_| \____/| .__/ \__, |
| | __/ |
|_| |___/
Bot Mister Spy V3
Mister Spy
Mister Spy
<?php
require_once('class.db.php');
require_once('class.dbaccess.php');
require_once('class.socio.php');
require_once('class.filter.php');
require_once('class.page.php');
require_once('class.misc.php');
class Socios extends DBAccess implements IFilterable
{
public function ParseFilter(array $filter)
{
$sql = '';
if ($filter['Apellido'] != "")
{
$sql.= " AND (u.Apellido RLIKE '" . DB::StringUnquoted($filter['Apellido']) . "'";
$sql.= " OR u.Apellido IS NULL)";
}
if ($filter['Socio'] != "")
{
$Socio = preg_replace("/[^a-zA-Z]+/", " ", $filter['Socio']);
$arrSocio = explode(' ', $Socio);
$sql.= " AND (0";
foreach ($arrSocio as $str)
{
$sql.= " OR Nombre LIKE '%" . DB::StringUnquoted($str) . "%'";
$sql.= " OR Apellido LIKE '%" . DB::StringUnquoted($str) . "%'";
}
$sql.= " )";
}
if ($filter['Nombre'] != "")
{
$sql.= " AND (u.Nombre RLIKE '" . DB::StringUnquoted($filter['Nombre']) . "'";
$sql.= " OR u.Nombre IS NULL)";
}
if ($filter['Email'] != "")
{
$sql.= " AND (u.Email RLIKE '" . DB::StringUnquoted($filter['Email']) . "'";
$sql.= " OR u.Email IS NULL)";
}
if ($filter['IdPais'] != "")
{
$sql.= " AND u.IdPais = " . DB::Number($filter['IdPais']);
}
if ($filter['IdProvincia'] != "")
{
$sql.= " AND u.IdProvincia = " . DB::Number($filter['IdProvincia']);
}
return $sql;
}
public function GetPagesCount(Page $oPage, $filter = false)
{
$CountRows = $this->GetCountRows($filter);
$Count = $CountRows / DB::Number($oPage->Size);
$Count = ceil($Count);
return $Count;
}
public function GetAll(array $filter = NULL, Page $oPage = NULL)
{
if (!$oRes = $this->GetAllContent($filter, $oPage))
return false;
$arr = array();
while ($oRow = $oRes->GetRow())
{
$oSocio = new Socio();
$oSocio->ParseFromArray($oRow);
array_push($arr, $oSocio);
$oRes->MoveNext();
}
return $arr;
}
public function GetAllContent(array $filter = NULL, Page $oPage = NULL)
{
$sql = " SELECT u.*";
$sql.= " FROM tblSocios u";
$sql.= " WHERE 1";
if ($filter)
$sql.= " " . $this->ParseFilter($filter);
$sql.= " ORDER BY u.Apellido, u.Nombre";
if ($oPage != NULL)
$sql.= " " . Pageable::ParsePage($oPage);
if ( !($oRes = $this->GetQuery($sql)) )
return false;
return $oRes;
}
public function GetById($IdSocio)
{
$sql = "SELECT u.*";
$sql.= " FROM tblSocios u";
$sql.= " WHERE u.IdSocio = " . DB::Number($IdSocio);
if ( !($oRes = $this->GetQuery($sql)) )
return false;
if ( !($oRow = $oRes->GetRow()) )
return false;
$oSocio = new Socio();
$oSocio->ParseFromArray($oRow);
return $oSocio;
}
public function GetByNombre($Nombre, $Apellido)
{
$sql = "SELECT u.*";
$sql.= " FROM tblSocios u";
$sql.= " WHERE u.Nombre = " . DB::String($Nombre);
$sql.= " AND u.Apellido = " . DB::String($Apellido);
if ( !($oRes = $this->GetQuery($sql)) )
return false;
if ( !($oRow = $oRes->GetRow()) )
return false;
$oSocio = new Socio();
$oSocio->ParseFromArray($oRow);
return $oSocio;
}
public function GetCountRows(array $filter = NULL)
{
$sql = " SELECT u.*";
$sql.= " FROM tblSocios u";
$sql.= " WHERE 1";
if ($filter)
$sql.= " " . $this->ParseFilter($filter);
$sql.= " GROUP BY u.IdSocio";
$sql.= " ORDER BY u.Apellido, u.Nombre";
if (!($oRes = $this->GetQuery($sql)))
return false;
$CountRows = $oRes->NumRows();
return $CountRows;
}
private function GetArrayDB(Socio $oSocio)
{
$arr = array
(
'Nombre' => DB::String($oSocio->Nombre),
'Apellido' => DB::String($oSocio->Apellido),
'IdPais' => DB::Number($oSocio->IdPais),
'IdProvincia' => DB::Number($oSocio->IdProvincia),
'Localidad' => DB::String($oSocio->Localidad)
);
return $arr;
}
public function Create(Socio $oSocio)
{
/* inicia una transaccion */
if (!DBAccess::$db->Begin())
return false;
$arr = $this->GetArrayDB($oSocio);
if (!DBAccess::Insert('tblSocios', $arr))
{
DBAccess::$db->Rollback();
return false;
}
/* finaliza la transaccion */
DBAccess::$db->Commit();
$oSocio->IdSocio = DBAccess::GetLastInsertId();
return $oSocio;
}
public function Update(Socio $oSocio)
{
/* inicia una transaccion */
if (!DBAccess::$db->Begin())
return false;
$arr = $this->GetArrayDB($oSocio);
$where = " IdSocio = " . (int)$oSocio->IdSocio;
if (!DBAccess::UpdateEntidad('tblSocios', $arr, $where))
{
DBAccess::$db->Rollback();
return false;
}
/* finaliza la transaccion */
DBAccess::$db->Commit();
return $oSocio;
}
public function Delete($IdSocio)
{
if (!DBAccess::$db->Begin())
return false;
$where = " IdSocio = " . DB::Number($IdSocio);
if (!DBAccess::DeleteEntidad('tblSocios', $where))
{
DBAccess::$db->Rollback();
return false;
}
DBAccess::$db->Commit();
return true;
}
}
?>
Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat