Mister Spy Say ="Hello Kids ... :D"
___ ____ _ _____
| \/ (_) | | / ___|
| . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _
| |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | |
| | | | \__ \ || __/ | /\__/ / |_) | |_| |
\_| |_/_|___/\__\___|_| \____/| .__/ \__, |
| | __/ |
|_| |___/
Bot Mister Spy V3
Mister Spy
Mister Spy
<?php
require_once('class.dbaccess.php');
require_once('class.alerta.php');
class Alertas extends DBAccess
{
public function ParseFilter(array $filter)
{
$sql = '';
if (isset($filter['FechaDesde']) && $filter['FechaDesde'] != '') {
$sql.= " AND Fecha >= " . DB::Date($filter['FechaDesde']);
}
if (isset($filter['FechaHasta']) && $filter['FechaHasta'] != '') {
$sql.= " AND Fecha <= " . DB::Date($filter['FechaHasta']);
}
if (isset($filter['Titulo']) && $filter['Titulo'] != "" ) {
$sql.= " AND a.Titulo LIKE '%" . DB::StringUnquoted($filter['Titulo']) . "%'";
}
if (isset($filter['Alerta']) && $filter['Alerta'] != "") {
$sql.= " AND a.Alerta LIKE '%" . DB::StringUnquoted($filter['Alerta']) . "%'";
}
if (isset($filter['IdEvento']) && $filter['IdEvento'] != "") {
$sql.= " AND a.IdEvento = " . DB::Number($filter['IdEvento']);
}
if (isset($filter['Visible']) && $filter['Visible'] !== "") {
$sql.= " AND a.Visible = " . DB::Bool($filter['Visible']);
}
if (isset($filter['Evento']) && $filter['Evento'] != "" ) {
$sql.= " AND a.IdEvento IN (SELECT IdEvento FROM tblEventos where Denominacion LIKE '%" . DB::StringUnquoted($filter['Evento']) . "%')";
}
return $sql;
}
public function GetPagesCount(Page $oPage, $filter = false)
{
$sql = " SELECT COUNT(1) / " . DB::Number($oPage->Size) . " AS Count";
$sql.= " FROM tblAlertas ";
$sql.= " WHERE IdAlerta <> 1 ";
if ($filter)
$sql.= " " . $this->ParseFilter($filter);
if (!($oRes = $this->GetQuery($sql)) )
return false;
if ( !($oRow = $oRes->GetRow()) )
return false;
$Count = $oRow['Count'];
return ceil($Count);
}
public function GetAll(array $filter = NULL, Page $oPage = NULL)
{
$sql = " SELECT * ";
$sql.= " FROM tblAlertas a ";
$sql.= " WHERE IdAlerta <> 1 ";
if ($filter)
$sql.= " " . $this->ParseFilter($filter);
$sql.= " ORDER BY a.Fecha ";
if ($oPage != NULL)
$sql.= " " . Pageable::ParsePage($oPage);
if (!($oRes = $this->GetQuery($sql)))
return false;
$arr = array();
while ($oRow = $oRes->GetRow())
{
$oAlerta = new Alerta();
$oAlerta->ParseFromArray($oRow);
array_push($arr, $oAlerta);
$oRes->MoveNext();
}
return $arr;
}
public function GetGeneral()
{
$sql = " SELECT * ";
$sql.= " FROM tblAlertas a ";
$sql.= " WHERE IdAlerta <> 1";
$sql.= " AND Visible = 1";
$sql.= " AND (IdEvento IS NULL OR IdEvento = 0)";
$sql.= " AND (FechaDesde IS NULL OR FechaDesde <= " . DB::Date(date('d-m-Y')) . ")";
$sql.= " AND (FechaHasta IS NULL OR FechaHasta >= " . DB::Date(date('d-m-Y')) . ")";
$sql.= " ORDER BY a.Fecha ";
if (!($oRes = $this->GetQuery($sql)))
return false;
$arr = array();
while ($oRow = $oRes->GetRow())
{
$oAlerta = new Alerta();
$oAlerta->ParseFromArray($oRow);
array_push($arr, $oAlerta);
$oRes->MoveNext();
}
return $arr;
}
public function GetByIdEvento($IdEvento)
{
$sql = " SELECT * ";
$sql.= " FROM tblAlertas a ";
$sql.= " WHERE IdAlerta <> 1";
$sql.= " AND Visible = 1";
$sql.= " AND IdEvento = " . DB::Number($IdEvento);
$sql.= " AND (FechaDesde IS NULL OR FechaDesde <= " . DB::Date(date('d-m-Y')) . ")";
$sql.= " AND (FechaHasta IS NULL OR FechaHasta >= " . DB::Date(date('d-m-Y')) . ")";
$sql.= " ORDER BY a.Fecha ";
if (!($oRes = $this->GetQuery($sql)))
return false;
$arr = array();
while ($oRow = $oRes->GetRow())
{
$oAlerta = new Alerta();
$oAlerta->ParseFromArray($oRow);
array_push($arr, $oAlerta);
$oRes->MoveNext();
}
return $arr;
}
public function GetById($IdAlerta)
{
$sql = "SELECT a.*";
$sql.= " FROM tblAlertas a";
$sql.= " WHERE a.IdAlerta = " . DB::Number($IdAlerta);
if (!($oRes = $this->GetQuery($sql)))
return false;
if (!($oRow = $oRes->GetRow()))
return false;
$oAlerta = new Alerta();
$oAlerta->ParseFromArray($oRow);
return $oAlerta;
}
public function GetCountRows(array $filter = NULL)
{
$sql = "SELECT *";
$sql.= " FROM tblAlertas";
$sql.= " WHERE IdAlerta <> 1 ";
if ($filter)
$sql.= $this->ParseFilter($filter);
$sql.= " ORDER BY Nombre";
if (!($oRes = $this->GetQuery($sql)))
return false;
$CountRows = $oRes->NumRows();
return $CountRows;
}
public function Create(Alerta $oAlerta)
{
$arr = array
(
'Fecha' => DB::Date($oAlerta->Fecha),
'Titulo' => DB::String($oAlerta->Titulo),
'Alerta' => DB::String($oAlerta->Alerta),
'IdEvento' => DB::Number($oAlerta->IdEvento ? $oAlerta->IdEvento : null),
'Visible' => DB::Bool($oAlerta->Visible),
'FechaDesde' => DB::Date($oAlerta->FechaDesde),
'FechaHasta' => DB::Date($oAlerta->FechaHasta)
);
if (!$this->Insert('tblAlertas', $arr))
return false;
$oAlerta->IdAlerta = DBAccess::GetLastInsertId();
return $oAlerta;
}
public function Update(Alerta $oAlerta)
{
$where = " IdAlerta = " . DB::Number($oAlerta->IdAlerta);
$arr = array
(
'Fecha' => DB::Date($oAlerta->Fecha),
'Titulo' => DB::String($oAlerta->Titulo),
'Alerta' => DB::String($oAlerta->Alerta),
'IdEvento' => DB::Number($oAlerta->IdEvento ? $oAlerta->IdEvento : null),
'Visible' => DB::Bool($oAlerta->Visible),
'FechaDesde' => DB::Date($oAlerta->FechaDesde),
'FechaHasta' => DB::Date($oAlerta->FechaHasta)
);
if (!DBAccess::Update('tblAlertas', $arr, $where))
return false;
return $oAlerta;
}
public function Delete($IdAlerta)
{
if (!DBAccess::$db->Begin())
return false;
$where = " IdAlerta = " . DB::Number($IdAlerta);
if (!DBAccess::Delete('tblAlertas', $where))
{
DBAccess::$db->Rollback();
return false;
}
DBAccess::$db->Commit();
return true;
}
}
?>
Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat