add cadastro
This commit is contained in:
140
lista/index.php
Executable file
140
lista/index.php
Executable file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
// exigir login para acessar a página
|
||||
// include '../proteger.php';
|
||||
|
||||
// Conectar ao banco de dados MySQL
|
||||
$servername = "localhost";
|
||||
$username = "root";
|
||||
$password = "";
|
||||
$dbname = "xcmg";
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
die("Conexão falhou: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Buscar cadastros não ativados
|
||||
$sql = "SELECT id, nome, empresa, cargo, telefone, dados_adicionais, codigo FROM cadastros WHERE status = 0";
|
||||
$result = $conn->query($sql);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Lista de Cadastros</title>
|
||||
<?php include '../header.php'; ?>
|
||||
<style>
|
||||
body {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #ccc;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="p-6 bg-gray-100" app="lista">
|
||||
<h2 class="text-xl font-bold mb-4">Lista de Cadastros</h2>
|
||||
<div id="cadastros">
|
||||
<?php while ($row = $result->fetch_assoc()) : ?>
|
||||
<div class="row-dados p-4 bg-white shadow rounded mb-2 flex justify-between items-center"
|
||||
id="cadastro-<?= $row['id'] ?>">
|
||||
<div class="col-codigo">
|
||||
<p><strong><?= $row['codigo'] ?></strong></p>
|
||||
</div>
|
||||
<div class="col-dados">
|
||||
<p><strong><?= $row['nome'] ?></strong></p>
|
||||
<p><?= $row['empresa'] ?></p>
|
||||
<?php
|
||||
// extrair email de dados_adicionais (se presente)
|
||||
$email = '';
|
||||
if (!empty($row['dados_adicionais'])) {
|
||||
// restaurar aspas simples duplicadas e decodificar JSON
|
||||
$json = str_replace("''", "'", $row['dados_adicionais']);
|
||||
$extras = json_decode($json, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($extras) && !empty($extras['email'])) {
|
||||
$email = htmlspecialchars($extras['email']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if ($email !== ''): ?>
|
||||
<p class="text-sm text-gray-200">Email: <span class="font-medium"><?= $email ?></span></p>
|
||||
<?php else: ?>
|
||||
<p class="text-sm text-gray-500">Email: <span class="italic">(não informado)</span></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<button class="bg-green-500 text-white px-4 py-2 rounded activate"
|
||||
data-id="<?= $row['id'] ?>">Ativar</button>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
</div>
|
||||
<script src="../js/jquery.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$(".activate").click(function () {
|
||||
console.log('ativar');
|
||||
let id = $(this).data("id");
|
||||
|
||||
$.post("ativar.php", {
|
||||
id: id
|
||||
}, function (response) {
|
||||
console.log(response);
|
||||
if (response == "success") {
|
||||
$("#cadastro-" + id).fadeOut();
|
||||
} else {
|
||||
alert("Erro ao ativar!");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
setInterval(function () {
|
||||
$.getJSON("atualiza.php?rand=" + Math.random(), function (data) {
|
||||
$("#cadastros").empty();
|
||||
$.each(data, function (key, val) {
|
||||
$("#cadastros").append(
|
||||
`<div class="row-dados p-4 bg-white shadow rounded mb-2 flex justify-between items-center" id="cadastro-${val.id}">
|
||||
<div class="col-codigo">
|
||||
<p><strong>${val.codigo}</strong></p>
|
||||
</div>
|
||||
<div class="col-dados">
|
||||
<p><strong>${val.nome}</strong></p>
|
||||
<p>${val.empresa}</p>
|
||||
${val.email ? `<p class="text-sm text-gray-200">Email: <span class="font-medium">${val.email}</span></p>` : `<p class="text-sm text-gray-500">Email: <span class="italic">(não informado)</span></p>`}
|
||||
</div>
|
||||
<button class="bg-green-500 text-white px-4 py-2 rounded activate" data-id="${val.id}">Ativar</button>
|
||||
</div>`
|
||||
);
|
||||
});$(".activate").click(function () {
|
||||
console.log('ativar');
|
||||
let id = $(this).data("id");
|
||||
|
||||
$.post("ativar.php", {
|
||||
id: id
|
||||
}, function (response) {
|
||||
console.log(response);
|
||||
if (response == "success") {
|
||||
$("#cadastro-" + id).fadeOut();
|
||||
} else {
|
||||
alert("Erro ao ativar!");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}, 10000);
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
background: #111 !important;
|
||||
}
|
||||
|
||||
.col-codigo {
|
||||
font-size: 32px;
|
||||
}
|
||||
</style>
|
||||
</body></html>
|
||||
Reference in New Issue
Block a user