Estiliza pagina de upload externo - responsiva (novo47)
This commit is contained in:
1 parent
05cd7b9c79
commit
337a51d298
11 files changed
+699
-13
No files matched your search
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// Configurações do banco de dados
|
||||
define('DB_HOST', '10.15.0.42');
|
||||
define('DB_USER', 'root');
|
||||
define('DB_PASS', '34641747');
|
||||
define('DB_NAME', 'valida');
|
||||
|
||||
// Criar conexão
|
||||
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
|
||||
// Verificar conexão
|
||||
if ($conn->connect_error) {
|
||||
die("Falha na conexão: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Configurar charset
|
||||
$conn->set_charset("utf8mb4");
|
||||
|
||||
// Configurar timezone
|
||||
date_default_timezone_set('America/Sao_Paulo');
|
||||
|
||||
// Função para limpar input
|
||||
function clean_input($data) {
|
||||
global $conn;
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
$data = htmlspecialchars($data);
|
||||
return $conn->real_escape_string($data);
|
||||
}
|
||||
|
||||
// Função para verificar se é uma requisição AJAX
|
||||
function is_ajax_request() {
|
||||
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
|
||||
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
|
||||
if (isset($_GET['id'])) {
|
||||
$doc_id = intval($_GET['id']);
|
||||
|
||||
// Buscar informações do documento
|
||||
$sql = "SELECT arquivo, client_id FROM documentos WHERE id = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("i", $doc_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($doc = $result->fetch_assoc()) {
|
||||
// Deletar arquivo físico
|
||||
if (file_exists($doc['arquivo'])) {
|
||||
unlink($doc['arquivo']);
|
||||
}
|
||||
|
||||
// Deletar registro do banco
|
||||
$sql = "DELETE FROM documentos WHERE id = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("i", $doc_id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
header("Location: index.php?page=doc_list&client_id=" . $doc['client_id'] . "&status=deleted");
|
||||
} else {
|
||||
die("Erro ao excluir documento: " . $stmt->error);
|
||||
}
|
||||
} else {
|
||||
die("Documento não encontrado");
|
||||
}
|
||||
} else {
|
||||
die("ID do documento não fornecido");
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE IF NOT EXISTS clientes (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
nome VARCHAR(100) NOT NULL,
|
||||
cpf VARCHAR(14) UNIQUE,
|
||||
email VARCHAR(100),
|
||||
telefone VARCHAR(20),
|
||||
data_cadastro DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS documentos (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
client_id INT NOT NULL,
|
||||
tipo VARCHAR(50) NOT NULL,
|
||||
arquivo VARCHAR(255) NOT NULL,
|
||||
data_upload DATETIME NOT NULL,
|
||||
FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE CASCADE,
|
||||
INDEX idx_client_id (client_id)
|
||||
) ENGINE=InnoDB;
|
||||
@@ -0,0 +1,100 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
import os
|
||||
from PIL import Image
|
||||
|
||||
def order_points(pts):
|
||||
rect = np.zeros((4, 2), dtype="float32")
|
||||
s = pts.sum(axis=1)
|
||||
rect[0] = pts[np.argmin(s)]
|
||||
rect[2] = pts[np.argmax(s)]
|
||||
diff = np.diff(pts, axis=1)
|
||||
rect[1] = pts[np.argmin(diff)]
|
||||
rect[3] = pts[np.argmax(diff)]
|
||||
return rect
|
||||
|
||||
def process_document(image_path, doc_type, output_dir):
|
||||
try:
|
||||
# Carrega e verifica a imagem
|
||||
image = cv2.imread(str(image_path))
|
||||
if image is None:
|
||||
raise Exception("Não foi possível carregar a imagem")
|
||||
|
||||
original = image.copy()
|
||||
|
||||
# Pré-processamento
|
||||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
|
||||
edges = cv2.Canny(blurred, 50, 150)
|
||||
|
||||
# Encontra contornos
|
||||
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
if not contours:
|
||||
raise Exception("Nenhum contorno encontrado")
|
||||
|
||||
# Ordena contornos por área
|
||||
contours = sorted(contours, key=cv2.contourArea, reverse=True)
|
||||
doc_corners = None
|
||||
|
||||
# Procura o documento
|
||||
for contour in contours:
|
||||
peri = cv2.arcLength(contour, True)
|
||||
approx = cv2.approxPolyDP(contour, 0.02 * peri, True)
|
||||
if len(approx) == 4:
|
||||
doc_corners = approx
|
||||
break
|
||||
|
||||
if doc_corners is None:
|
||||
raise Exception("Documento não encontrado")
|
||||
|
||||
# Processa cantos e aplica transformação
|
||||
doc_corners = doc_corners.reshape(4, 2)
|
||||
ordered_corners = order_points(doc_corners)
|
||||
|
||||
(tl, tr, br, bl) = ordered_corners
|
||||
widthA = np.linalg.norm(br - bl)
|
||||
widthB = np.linalg.norm(tr - tl)
|
||||
maxWidth = max(int(widthA), int(widthB))
|
||||
|
||||
heightA = np.linalg.norm(tr - br)
|
||||
heightB = np.linalg.norm(tl - bl)
|
||||
maxHeight = max(int(heightA), int(heightB))
|
||||
|
||||
dst = np.array([
|
||||
[0, 0],
|
||||
[maxWidth - 1, 0],
|
||||
[maxWidth - 1, maxHeight - 1],
|
||||
[0, maxHeight - 1]
|
||||
], dtype="float32")
|
||||
|
||||
# Aplica transformação perspectiva
|
||||
matrix = cv2.getPerspectiveTransform(ordered_corners, dst)
|
||||
warped = cv2.warpPerspective(original, matrix, (maxWidth, maxHeight))
|
||||
|
||||
# Salva resultado
|
||||
output_path = os.path.join(output_dir, f"{doc_type}_{Path(image_path).name}")
|
||||
cv2.imwrite(str(output_path), warped)
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Processamento concluído com sucesso",
|
||||
"width": maxWidth,
|
||||
"height": maxHeight
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"success": False,
|
||||
"message": str(e)
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 4:
|
||||
print(json.dumps({"success": False, "message": "Uso: python document_detector.py <input_path> <doc_type> <output_dir>"}))
|
||||
sys.exit(1)
|
||||
|
||||
result = process_document(Path(sys.argv[1]), sys.argv[2], Path(sys.argv[3]))
|
||||
print(json.dumps(result))
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Conectar ao banco de dados
|
||||
$mysqli = new mysqli("10.15.0.42", "root", "34641747", "valida");
|
||||
|
||||
if ($mysqli->connect_error) {
|
||||
die("Connection failed: " . $mysqli->connect_error);
|
||||
}
|
||||
|
||||
// Buscar histórico de documentos processados
|
||||
$query = "SELECT pd.*, u.username FROM processed_documents pd
|
||||
LEFT JOIN users u ON pd.user_id = u.id
|
||||
ORDER BY pd.created_at DESC";
|
||||
$result = $mysqli->query($query);
|
||||
?>
|
||||
|
||||
<div class="container">
|
||||
<h2>Histórico de Documentos Processados</h2>
|
||||
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data/Hora</th>
|
||||
<th>Usuário</th>
|
||||
<th>Documento Original</th>
|
||||
<th>Documento Processado</th>
|
||||
<th>Ações</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($row = $result->fetch_assoc()): ?>
|
||||
<tr>
|
||||
<td><?php echo date('d/m/Y H:i:s', strtotime($row['created_at'])); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['username']); ?></td>
|
||||
<td>
|
||||
<a href="<?php echo htmlspecialchars($row['original_path']); ?>" target="_blank">
|
||||
Ver Original
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?php echo htmlspecialchars($row['processed_path']); ?>" target="_blank">
|
||||
Ver Processado
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<button onclick="deleteDocument(<?php echo $row['id']; ?>)" class="delete-btn">
|
||||
Excluir
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endwhile; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function deleteDocument(id) {
|
||||
if (confirm('Tem certeza que deseja excluir este documento?')) {
|
||||
fetch('delete_document.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({id: id})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert('Documento excluído com sucesso!');
|
||||
location.reload();
|
||||
} else {
|
||||
alert('Erro ao excluir documento: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Erro ao excluir documento');
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
ob_start();
|
||||
session_start();
|
||||
//require_once 'config.php';
|
||||
|
||||
// Verificar se o usuário está logado
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
if (!isset($_SESSION['user_id']) && !in_array($_GET['page'], ['login', 'logout'])) {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
@@ -32,28 +33,61 @@ include 'top_menu.php';
|
||||
<?php
|
||||
if (isset($_GET['page'])) {
|
||||
$page = $_GET['page'];
|
||||
if ($page == 'upload') {
|
||||
switch($page) {
|
||||
case 'upload':
|
||||
include 'prova/upload_prova.php';
|
||||
} elseif ($page == 'status') {
|
||||
break;
|
||||
case 'status':
|
||||
include 'prova/status.php';
|
||||
} elseif ($page == 'list_files') {
|
||||
break;
|
||||
case 'list_files':
|
||||
include 'prova/list_files.php';
|
||||
} elseif ($page == 'register_client') {
|
||||
break;
|
||||
case 'register_client':
|
||||
include 'clientes/register_client.php';
|
||||
} elseif ($page == 'list_clients') {
|
||||
break;
|
||||
case 'list_clients':
|
||||
include 'clientes/list_clients.php';
|
||||
} elseif ($page == 'client_details' && isset($_GET['id'])) {
|
||||
break;
|
||||
case 'client_details':
|
||||
if (isset($_GET['id'])) {
|
||||
include 'clientes/client_details.php';
|
||||
} elseif ($page == 'edit_client' && isset($_GET['id'])) {
|
||||
}
|
||||
break;
|
||||
case 'edit_client':
|
||||
if (isset($_GET['id'])) {
|
||||
include 'clientes/edit_client.php';
|
||||
} elseif ($page == 'delete_client' && isset($_GET['id'])) {
|
||||
}
|
||||
break;
|
||||
case 'delete_client':
|
||||
if (isset($_GET['id'])) {
|
||||
include 'clientes/delete_client.php';
|
||||
} elseif ($page == 'edit_note' && isset($_POST['id'])) {
|
||||
}
|
||||
break;
|
||||
case 'edit_note':
|
||||
if (isset($_POST['id'])) {
|
||||
include 'clientes/edit_note.php';
|
||||
} elseif ($page == 'delete_note' && isset($_POST['id'])) {
|
||||
}
|
||||
break;
|
||||
case 'delete_note':
|
||||
if (isset($_POST['id'])) {
|
||||
include 'clientes/delete_note.php';
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
case 'doc_upload':
|
||||
include 'upload.php';
|
||||
break;
|
||||
case 'doc_list':
|
||||
include 'list.php';
|
||||
break;
|
||||
case 'delete_document':
|
||||
if (isset($_GET['id'])) {
|
||||
include 'delete_document.php';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
echo "<h2>Bem-vindo ao Sistema de Ferramentas</h2>";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
echo "<h2>Bem-vindo ao Sistema de Ferramentas</h2>";
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<!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>
|
||||
<?php
|
||||
require_once 'config.php'; // Adicionar esta linha no início
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Conexão falhou: " . $conn->connect_error);
|
||||
}
|
||||
?>
|
||||
<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>
|
||||
@@ -12,7 +12,7 @@ if (!isset($_SESSION['user_id'])) {
|
||||
<li>
|
||||
<a href="javascript:void(0);" onclick="toggleSubmenu('submenu1')">Autenticador de Provas Digitais</a>
|
||||
<ul id="submenu1" class="submenu">
|
||||
<li><a href="index.php?page=upload">Upload de Arquivos</a></li>
|
||||
<li><a href="/prova/upload_prova.php">Upload de Arquivos</a></li>
|
||||
<li><a href="index.php?page=status">Ver Status</a></li>
|
||||
<li><a href="index.php?page=list_files">Lista de Arquivos Processados</a></li>
|
||||
</ul>
|
||||
@@ -24,6 +24,13 @@ if (!isset($_SESSION['user_id'])) {
|
||||
<li><a href="index.php?page=list_clients">Listagem de Clientes</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:void(0);" onclick="toggleSubmenu('submenu3')">Processador de Documentos</a>
|
||||
<ul id="submenu3" class="submenu">
|
||||
<li><a href="index.php?page=doc_upload">Upload de Documentos</a></li>
|
||||
<li><a href="index.php?page=doc_list">Documentos Processados</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<!-- Adicione mais ferramentas aqui -->
|
||||
</ul>
|
||||
</div>
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
|
||||
$upload_dir = "uploads/";
|
||||
$processed_dir = "processed/";
|
||||
|
||||
// Debug mode
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Criar diretórios se não existirem
|
||||
if (!file_exists($upload_dir)) mkdir($upload_dir, 0777, true);
|
||||
if (!file_exists($processed_dir)) mkdir($processed_dir, 0777, true);
|
||||
|
||||
if ($_FILES["document"]["error"] == 0) {
|
||||
try {
|
||||
$temp = $_FILES["document"]["tmp_name"];
|
||||
$name = basename($_FILES["document"]["name"]);
|
||||
$doc_type = $_POST["doc_type"];
|
||||
$client_id = $_POST["client_id"];
|
||||
|
||||
// Criar diretório específico do cliente
|
||||
$client_dir = $processed_dir . $client_id . "/";
|
||||
if (!file_exists($client_dir)) mkdir($client_dir, 0777, true);
|
||||
|
||||
// Salvar arquivo original com timestamp
|
||||
$timestamp = time();
|
||||
$original_name = $timestamp . "_" . $name;
|
||||
$original_path = $upload_dir . $original_name;
|
||||
|
||||
if (!move_uploaded_file($temp, $original_path)) {
|
||||
throw new Exception("Erro ao fazer upload do arquivo");
|
||||
}
|
||||
|
||||
// Caminho absoluto para o script Python
|
||||
$python_script = realpath(__DIR__ . "/document_detector.py");
|
||||
$original_path = realpath($original_path);
|
||||
$client_dir = realpath($client_dir);
|
||||
|
||||
// Comando Python com paths absolutos
|
||||
$command = sprintf(
|
||||
'python3 "%s" "%s" "%s" "%s" 2>&1',
|
||||
$python_script,
|
||||
$original_path,
|
||||
$doc_type,
|
||||
$client_dir
|
||||
);
|
||||
|
||||
// Log do comando
|
||||
file_put_contents('python_debug.log', date('Y-m-d H:i:s') . "\nComando: " . $command . "\n", FILE_APPEND);
|
||||
|
||||
// Executar comando
|
||||
$output = [];
|
||||
$return_var = 0;
|
||||
exec($command, $output, $return_var);
|
||||
|
||||
// Log da saída
|
||||
file_put_contents('python_debug.log', "Saída: " . implode("\n", $output) . "\nCódigo: $return_var\n\n", FILE_APPEND);
|
||||
|
||||
// Verificar resultado
|
||||
$last_output = end($output);
|
||||
$result = json_decode($last_output, true);
|
||||
|
||||
if ($result && $result['success']) {
|
||||
// Nome do arquivo processado
|
||||
$processed_name = $doc_type . "_" . $original_name;
|
||||
$processed_file = $client_dir . "/" . $processed_name;
|
||||
|
||||
// Registrar no banco
|
||||
$sql = "INSERT INTO documentos (client_id, tipo, arquivo, data_upload) VALUES (?, ?, ?, NOW())";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("iss", $client_id, $doc_type, $processed_file);
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
throw new Exception("Erro ao registrar documento: " . $stmt->error);
|
||||
}
|
||||
|
||||
header("Location: index.php?page=doc_list&client_id=" . $client_id . "&status=success");
|
||||
exit();
|
||||
} else {
|
||||
throw new Exception("Erro no processamento: " . ($result['message'] ?? 'Erro desconhecido'));
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
file_put_contents('error.log', date('Y-m-d H:i:s') . " - " . $e->getMessage() . "\n", FILE_APPEND);
|
||||
die("Erro: " . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
die("Erro no upload: " . $_FILES["document"]["error"]);
|
||||
}
|
||||
?>
|
||||
@@ -209,3 +209,50 @@ textarea {
|
||||
#search-button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
/* Estilos para processamento de documentos */
|
||||
.upload-form {
|
||||
max-width: 600px;
|
||||
margin: 20px auto;
|
||||
padding: 20px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.result-preview {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.image-comparison {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.image-comparison img {
|
||||
max-width: 45%;
|
||||
height: auto;
|
||||
margin: 10px;
|
||||
border: 1px solid #ddd;
|
||||
box-shadow: 0 0 5px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
color: #155724;
|
||||
background-color: #d4edda;
|
||||
border-color: #c3e6cb;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
color: #721c24;
|
||||
background-color: #f8d7da;
|
||||
border-color: #f5c6cb;
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Upload de Documentos</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 20px; }
|
||||
.upload-form { max-width: 500px; margin: 0 auto; padding: 20px; background: #fff; }
|
||||
.button { padding: 10px 20px; background: #4CAF50; color: white; border: none; }
|
||||
.preview { max-width: 100%; margin: 20px 0; }
|
||||
.preview img { max-width: 100%; }
|
||||
#result { display: none; }
|
||||
.error { color: red; }
|
||||
select { width: 100%; padding: 8px; margin-bottom: 10px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="upload-form">
|
||||
<h2>Upload de Documentos</h2>
|
||||
<form action="process.php" method="post" enctype="multipart/form-data" id="uploadForm">
|
||||
<p>
|
||||
<label>Cliente:</label><br>
|
||||
<select name="client_id" required>
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
|
||||
// Debug de conexão
|
||||
if (!$conn) {
|
||||
die("Erro de conexão: " . mysqli_connect_error());
|
||||
}
|
||||
|
||||
// Debug da tabela
|
||||
$check_table = $conn->query("SHOW TABLES LIKE 'clients'");
|
||||
if ($check_table->num_rows == 0) {
|
||||
die("Tabela 'clients' não encontrada!");
|
||||
}
|
||||
|
||||
// Verificar estrutura da tabela
|
||||
$check_columns = $conn->query("DESCRIBE clients");
|
||||
if (!$check_columns) {
|
||||
die("Erro ao verificar estrutura da tabela: " . $conn->error);
|
||||
}
|
||||
|
||||
// Contar registros
|
||||
$count = $conn->query("SELECT COUNT(*) as total FROM clients");
|
||||
$total = $count->fetch_assoc()['total'];
|
||||
echo "<!-- Total de clientes: " . $total . " -->";
|
||||
|
||||
// Query com validação e debug
|
||||
$sql = "SELECT id, name FROM clients WHERE 1=1";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if (!$result) {
|
||||
die("Erro na query: " . $conn->error);
|
||||
}
|
||||
|
||||
// Exibir clientes com verificação
|
||||
echo "<option value=''>Selecione um cliente</option>";
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
echo "<option value='" . $row['id'] . "'>" .
|
||||
htmlspecialchars($row['name']) . "</option>";
|
||||
}
|
||||
} else {
|
||||
echo "<option value='' disabled>Nenhum cliente encontrado</option>";
|
||||
echo "<!-- Query executada: " . $sql . " -->";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label>Selecione o documento:</label><br>
|
||||
<input type="file" name="document" accept="image/*" required>
|
||||
</p>
|
||||
<p>
|
||||
<label>Tipo de documento:</label><br>
|
||||
<select name="doc_type" required>
|
||||
<option value="cpf">CPF</option>
|
||||
<option value="rg">RG</option>
|
||||
<option value="cnh">CNH</option>
|
||||
</select>
|
||||
</p>
|
||||
<input type="submit" value="Processar" class="button">
|
||||
</form>
|
||||
<div id="error" class="error">
|
||||
<?php
|
||||
if (isset($conn) && !$result) {
|
||||
echo "Erro ao buscar clientes: " . $conn->error;
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<p><a href="index.php?page=doc_list">Ver documentos processados</a></p>
|
||||
</div>
|
||||
|
||||
<div id="result">
|
||||
<h3>Resultado do Processamento:</h3>
|
||||
<div class="preview">
|
||||
<h4>Documento Original:</h4>
|
||||
<img id="originalImage" src="" alt="Original">
|
||||
</div>
|
||||
<div class="preview">
|
||||
<h4>Documento Processado:</h4>
|
||||
<img id="processedImage" src="" alt="Processado">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="error" class="error"></div>
|
||||
|
||||
<script>
|
||||
document.getElementById('uploadForm').onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = new FormData(e.target);
|
||||
|
||||
try {
|
||||
const response = await fetch('process.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
window.location.href = 'index.php?page=doc_list&status=success';
|
||||
} else {
|
||||
throw new Error('Erro ao processar documento');
|
||||
}
|
||||
} catch (error) {
|
||||
document.getElementById('error').textContent = error.message;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user