add cadastro
This commit is contained in:
BIN
lista/Leads XCMG Roleta.xlsx
Executable file
BIN
lista/Leads XCMG Roleta.xlsx
Executable file
Binary file not shown.
26
lista/ativar.php
Executable file
26
lista/ativar.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["id"])) {
|
||||
$id = intval($_POST["id"]);
|
||||
$sql = "UPDATE cadastros SET status = 1 WHERE id = $id";
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "success";
|
||||
} else {
|
||||
echo "error";
|
||||
}
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
|
||||
|
||||
|
||||
41
lista/atualiza.php
Executable file
41
lista/atualiza.php
Executable file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
$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);
|
||||
|
||||
$cadastros = array();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
while($row = $result->fetch_assoc()) {
|
||||
// Se houver dados_adicionais, tentar extrair e-mail para facilitar o frontend
|
||||
if (!empty($row['dados_adicionais'])) {
|
||||
// dados_adicionais are stored with single-quotes escaped as '' in salvar.php
|
||||
$json = str_replace("''", "'", $row['dados_adicionais']);
|
||||
$extras = json_decode($json, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($extras)) {
|
||||
$row['email'] = isset($extras['email']) ? $extras['email'] : '';
|
||||
} else {
|
||||
$row['email'] = '';
|
||||
}
|
||||
} else {
|
||||
$row['email'] = '';
|
||||
}
|
||||
|
||||
$cadastros[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($cadastros);
|
||||
|
||||
$conn->close();
|
||||
44
lista/converterTabelaEmPlanilha.py
Executable file
44
lista/converterTabelaEmPlanilha.py
Executable file
@@ -0,0 +1,44 @@
|
||||
from openpyxl import Workbook
|
||||
|
||||
import mysql.connector
|
||||
|
||||
|
||||
def export_cadastros_to_excel():
|
||||
# Configurações de conexão com o MySQL
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost", # altere para o host do seu banco de dados
|
||||
user="root", # altere para o usuário do seu banco
|
||||
password="", # altere para a senha do seu banco
|
||||
database="xcmg" # altere para o nome do seu banco de dados
|
||||
)
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Consulta da tabela cadastros
|
||||
cursor.execute("""
|
||||
SELECT id, nome, empresa, cargo, telefone, cliente_xcmg, usa_banco_xcmg, codigo, ativado, gerado, status
|
||||
FROM cadastros
|
||||
""")
|
||||
rows = cursor.fetchall()
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
# Cria um arquivo Excel
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "Cadastros"
|
||||
|
||||
# Cabeçalho da planilha
|
||||
headers = ['id', 'nome', 'empresa', 'cargo', 'telefone', 'cliente_xcmg', 'usa_banco_xcmg', 'codigo', 'ativado', 'gerado', 'status']
|
||||
ws.append(headers)
|
||||
|
||||
# Insere os dados na planilha
|
||||
for row in rows:
|
||||
ws.append(row)
|
||||
|
||||
# Salva a planilha em um arquivo Excel
|
||||
wb.save("cadastros.xlsx")
|
||||
|
||||
if __name__ == '__main__':
|
||||
export_cadastros_to_excel()
|
||||
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>
|
||||
4
lista/session_end.php
Executable file
4
lista/session_end.php
Executable file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("Location: /lista");
|
||||
Reference in New Issue
Block a user