alterações 07-04-26
This commit is contained in:
Binary file not shown.
@@ -9,8 +9,12 @@ 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";
|
||||
// Verificar se deve mostrar os ativados
|
||||
$show_activated = isset($_GET['ativados']) && $_GET['ativados'] === 'true';
|
||||
$status_filter = $show_activated ? "status IN (0, 1)" : "status = 0";
|
||||
|
||||
// Buscar cadastros (filtrados pelo status)
|
||||
$sql = "SELECT id, nome, empresa, cargo, telefone, dados_adicionais, codigo, status FROM cadastros WHERE $status_filter ORDER BY id DESC";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
$cadastros = array();
|
||||
|
||||
BIN
lista/cadastros.xlsx
Normal file
BIN
lista/cadastros.xlsx
Normal file
Binary file not shown.
@@ -1,22 +1,21 @@
|
||||
import json
|
||||
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
|
||||
host="localhost", # Como o PHP chamará este script no servidor, usamos localhost
|
||||
user="root",
|
||||
password="",
|
||||
database="xcmg"
|
||||
)
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Consulta da tabela cadastros
|
||||
# Consulta da tabela cadastros (incluindo dados_adicionais)
|
||||
cursor.execute("""
|
||||
SELECT id, nome, empresa, cargo, telefone, cliente_xcmg, usa_banco_xcmg, codigo, ativado, gerado, status
|
||||
SELECT id, nome, empresa, cargo, telefone, codigo, ativado, gerado, status, dados_adicionais
|
||||
FROM cadastros
|
||||
""")
|
||||
rows = cursor.fetchall()
|
||||
@@ -27,17 +26,45 @@ def export_cadastros_to_excel():
|
||||
# Cria um arquivo Excel
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "Cadastros"
|
||||
ws.title = "Cadastros IUS"
|
||||
|
||||
# Cabeçalho da planilha
|
||||
headers = ['id', 'nome', 'empresa', 'cargo', 'telefone', 'cliente_xcmg', 'usa_banco_xcmg', 'codigo', 'ativado', 'gerado', 'status']
|
||||
# Cabeçalho da planilha (incluindo novos campos)
|
||||
headers = [
|
||||
'ID', 'Nome', 'Empresa', 'Cargo', 'E-mail',
|
||||
'Setor', 'Segmento', 'Funcionários',
|
||||
'Telefone', 'Código', 'Ativado', 'Data Cadastro', 'Status'
|
||||
]
|
||||
ws.append(headers)
|
||||
|
||||
# Insere os dados na planilha
|
||||
for row in rows:
|
||||
ws.append(row)
|
||||
(id_db, nome, empresa, cargo, telefone, codigo, ativado, gerado, status, dados_json_raw) = row
|
||||
|
||||
email = ""
|
||||
setor = ""
|
||||
segmento = ""
|
||||
funcionarios = ""
|
||||
|
||||
if dados_json_raw:
|
||||
try:
|
||||
# O banco armazena aspas simples duplicadas ('') como escape do MySQL
|
||||
json_clean = dados_json_raw.replace("''", "'")
|
||||
extras = json.loads(json_clean)
|
||||
email = extras.get('email', '')
|
||||
setor = extras.get('setor', '')
|
||||
segmento = extras.get('segmento', '')
|
||||
funcionarios = extras.get('funcionarios', '')
|
||||
except Exception as e:
|
||||
print(f"Erro ao processar JSON para ID {id_db}: {e}")
|
||||
|
||||
# Salva a planilha em um arquivo Excel
|
||||
# Monta a linha para o Excel
|
||||
ws.append([
|
||||
id_db, nome, empresa, cargo, email,
|
||||
setor, segmento, funcionarios,
|
||||
telefone, codigo, ativado, gerado, status
|
||||
])
|
||||
|
||||
# Salva a planilha
|
||||
wb.save("cadastros.xlsx")
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
28
lista/gerar_excel.php
Executable file
28
lista/gerar_excel.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// lista/gerar_excel.php
|
||||
|
||||
// Executa o script Python para gerar a planilha
|
||||
$output = shell_exec("python3 converterTabelaEmPlanilha.py 2>&1");
|
||||
|
||||
$arquivo = "cadastros.xlsx";
|
||||
|
||||
if (file_exists($arquivo)) {
|
||||
// Definir headers para o download do arquivo
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
header('Content-Disposition: attachment; filename="' . basename($arquivo) . '"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($arquivo));
|
||||
|
||||
// Ler e enviar o arquivo
|
||||
readfile($arquivo);
|
||||
|
||||
// Remover o arquivo temporário após o download (opcional)
|
||||
// unlink($arquivo);
|
||||
exit;
|
||||
} else {
|
||||
echo "Erro ao gerar o arquivo. Saída do log: <pre>$output</pre>";
|
||||
}
|
||||
?>
|
||||
164
lista/index.php
164
lista/index.php
@@ -39,94 +39,106 @@ $result = $conn->query($sql);
|
||||
</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 class="flex items-center justify-between mb-6 bg-white p-4 rounded shadow">
|
||||
<h2 class="text-xl font-bold !text-gray-800">Lista de Cadastros</h2>
|
||||
<div class="flex items-center space-x-6">
|
||||
<!-- Toggle Ativados -->
|
||||
<label class="inline-flex items-center cursor-pointer">
|
||||
<input type="checkbox" id="toggleAtvados" class="sr-only peer">
|
||||
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-green-300 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-green-600"></div>
|
||||
<span class="ms-3 text-sm font-medium text-gray-700">Mostrar Ativados</span>
|
||||
</label>
|
||||
|
||||
<!-- Download Button -->
|
||||
<a href="gerar_excel.php" class="bg-gray-800 hover:bg-gray-900 text-white px-4 py-2 rounded-lg text-sm font-medium transition flex items-center shadow-md">
|
||||
<svg class="w-4 h-4 me-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
|
||||
Download Excel
|
||||
</a>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
</div>
|
||||
|
||||
<div id="cadastros">
|
||||
<!-- Itens serão carregados via polling -->
|
||||
</div>
|
||||
|
||||
<script src="../js/jquery.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$(".activate").click(function () {
|
||||
console.log('ativar');
|
||||
let id = $(this).data("id");
|
||||
let showActivated = false;
|
||||
|
||||
$.post("ativar.php", {
|
||||
id: id
|
||||
}, function (response) {
|
||||
console.log(response);
|
||||
function refreshList() {
|
||||
$.getJSON("atualiza.php?rand=" + Math.random() + "&ativados=" + showActivated, function (data) {
|
||||
const container = $("#cadastros");
|
||||
container.empty();
|
||||
|
||||
if (data.length === 0) {
|
||||
container.append('<p class="text-center text-gray-400 py-10 italic">Nenhum cadastro encontrado.</p>');
|
||||
return;
|
||||
}
|
||||
|
||||
$.each(data, function (key, val) {
|
||||
const isActivated = val.status == 1;
|
||||
const rowClass = isActivated ? 'opacity-50 grayscale bg-gray-50' : 'bg-white';
|
||||
|
||||
container.append(`
|
||||
<div class="row-dados p-4 shadow rounded mb-2 flex justify-between items-center ${rowClass}" id="cadastro-${val.id}">
|
||||
<div class="col-codigo text-gray-800">
|
||||
<strong>${val.codigo}</strong>
|
||||
</div>
|
||||
<div class="col-dados flex-grow px-8">
|
||||
<p class="text-gray-900 font-bold text-lg">${val.nome}</p>
|
||||
<p class="text-gray-600">${val.empresa}</p>
|
||||
${val.email ?
|
||||
`<p class="text-sm text-gray-500">Email: <span class="font-medium">${val.email}</span></p>` :
|
||||
`<p class="text-sm text-gray-400 italic">Email: (não informado)</p>`
|
||||
}
|
||||
</div>
|
||||
<div class="col-acao">
|
||||
${!isActivated ?
|
||||
`<button class="bg-green-600 hover:bg-green-700 text-white px-6 py-2 rounded-lg font-bold shadow-sm activate" data-id="${val.id}">Ativar</button>` :
|
||||
`<span class="text-green-700 font-bold bg-green-100 px-3 py-1 rounded-full text-sm">✓ Ativado</span>`
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
|
||||
// Reatribui eventos
|
||||
bindEvents();
|
||||
});
|
||||
}
|
||||
|
||||
function bindEvents() {
|
||||
$(".activate").off('click').on('click', function () {
|
||||
let id = $(this).data("id");
|
||||
let btn = $(this);
|
||||
btn.prop('disabled', true).addClass('opacity-50');
|
||||
|
||||
$.post("ativar.php", { id: id }, function (response) {
|
||||
if (response == "success") {
|
||||
$("#cadastro-" + id).fadeOut();
|
||||
if (!showActivated) {
|
||||
$("#cadastro-" + id).fadeOut(300);
|
||||
} else {
|
||||
refreshList();
|
||||
}
|
||||
} else {
|
||||
alert("Erro ao ativar!");
|
||||
btn.prop('disabled', false).removeClass('opacity-50');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
// Inicializa Polling
|
||||
refreshList();
|
||||
setInterval(refreshList, 5000); // Polling a cada 5 segundos
|
||||
|
||||
// Toggle Ativados
|
||||
$("#toggleAtvados").on('change', function() {
|
||||
showActivated = $(this).is(':checked');
|
||||
refreshList();
|
||||
});
|
||||
});
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user