Files
ferramentas/list.php
T

94 lines
3.4 KiB
PHP

<!DOCTYPE html>
<html>
<head>
<title>Documentos Processados</title>
<meta charset="utf-8">
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.file-list {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #fff;
}
.file-item {
padding: 15px;
border-bottom: 1px solid #eee;
display: flex;
justify-content: space-between;
align-items: center;
}
.file-info { flex: 1; }
.file-actions { margin-left: 15px; }
</style>
</head>
<body>
<div class="file-list">
<?php
if (!isset($_GET['client_id'])) {
echo "<p>Selecione um cliente para ver seus documentos:</p>";
$sql = "SELECT id, name as nome FROM clients ORDER BY name";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<div class='file-item'>";
echo "<div class='file-info'>";
echo "<strong>" . $row['nome'] . "</strong>";
echo "</div>";
echo "<div class='file-actions'>";
echo "<a href='index.php?page=doc_list&client_id=" . $row['id'] . "'>Ver documentos</a>";
echo "</div>";
echo "</div>";
}
} else {
$client_id = $_GET['client_id'];
// Buscar informações do cliente
$sql = "SELECT name as nome FROM clients WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $client_id);
$stmt->execute();
$result = $stmt->get_result();
$cliente = $result->fetch_assoc();
echo "<h2>Documentos de " . $cliente['nome'] . "</h2>";
// Buscar documentos do cliente
$sql = "SELECT * FROM documentos WHERE client_id = ? ORDER BY data_upload DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $client_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while ($doc = $result->fetch_assoc()) {
echo "<div class='file-item'>";
echo "<div class='file-info'>";
echo "<strong>Tipo: " . ucfirst($doc['tipo']) . "</strong><br>";
echo "Data: " . date("d/m/Y H:i", strtotime($doc['data_upload']));
echo "</div>";
echo "<div class='file-actions'>";
echo "<a href='" . $doc['arquivo'] . "' target='_blank'>Visualizar</a> | ";
echo "<a href='#' onclick='deleteDocument(" . $doc['id'] . ")'>Excluir</a>";
echo "</div>";
echo "</div>";
}
} else {
echo "<p>Nenhum documento processado para este cliente.</p>";
}
echo "<p><a href='index.php?page=doc_upload&client_id=" . $client_id . "'>Upload novo documento</a></p>";
}
?>
</div>
<script>
function deleteDocument(id) {
if (confirm('Deseja realmente excluir este documento?')) {
window.location.href = 'index.php?page=delete_document&id=' + id;
}
}
</script>
</body>
</html>