<?php
include "bancodedados.php";
class Usuarios
{
private $conexao;
private $temreg;
public function __construct()
{
$this->conexao = Conexao::BancodeDados();
}
private function QuantUsuarios()
{
$quantreg = $this->conexao->prepare('select * from cadastros');
$quantreg->execute();
$temreg = $quantreg->rowCount();
return $temreg;
}
public function ListaUsuarios()
{
//verifica se está isset uma pagina
if(!isset ($_GET['pg']))
{
$pg = 0;
}
else
{
$pg = $_GET['pg'];
}
$temreg = $this->QuantUsuarios();
$registro = 10;
$inicio = $pg * $registro;
$quantpg = ceil($temreg/$registro);
$quantpg++;
//Lista os usuarios na tela
$buscar = $this->conexao->prepare("SELECT * FROM cadastros LIMIT $inicio,$registro");
$buscar->execute();
echo "<table border='1' cellpadding='8' align='center'>";
echo "<tr>";
echo "<th>Nome</th>";
echo "<th>Telefone</th>";
echo "<th>Email</th>";
if($_SESSION['logado'])
{
echo "<th>Editar</th>";
echo "<th>Deletar</th>";
}
echo "</tr>";
while($users = $buscar->fetch(PDO::FETCH_OBJ))
{
echo "<tr>";
echo "<td>".$users->nome."</td>";
echo "<td>".$users->telefone."</td>";
echo "<td>".$users->email."</td>";
if($_SESSION['logado'])
{
echo "<td><a href='/delete.php?deletar&id=$users->id'>Deletar</a></td>";
echo "<td><a href='?editar&id=$users->id'>Editar</a></td>";
}
echo "</tr>";
}
echo "</table>";
if($pg > 0)
{
echo "<a href=?lista&pg=".($pg-1).">Anterior</a>";
}
else
{
echo "Anterior";
}
for($i = 1; $i < $quantpg; $i++)
{
if($pg == ($i-1))
{
echo "<strong>$i</strong>";
}
elseif($i < 5)
{
echo $i;
}
}
if(($pg +2) < $quantpg)
{
echo "<a href=?lista&pg=".($pg+1).">Proxima</a>";
}
else
{
echo "Proxima";
}
}
}
?>