Estiliza pagina de upload externo - responsiva (novo47)
This commit is contained in:
1 parent
05cd7b9c79
commit
54012a6c98
6 files changed
+373
-1
No files matched your search
@@ -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>
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
|
class DocumentProcessor {
|
||||||
|
private $srcImage;
|
||||||
|
private $processedImage;
|
||||||
|
private $outputPath;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
if (!extension_loaded('opencv')) {
|
||||||
|
throw new Exception('OpenCV PHP extension is required');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processDocument($imagePath, $outputPath) {
|
||||||
|
$this->outputPath = $outputPath;
|
||||||
|
|
||||||
|
// Carrega a imagem
|
||||||
|
$this->srcImage = cv\imread($imagePath);
|
||||||
|
if ($this->srcImage === null) {
|
||||||
|
throw new Exception('Failed to load image');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pipeline de processamento
|
||||||
|
$this->detectDocument()
|
||||||
|
->correctPerspective()
|
||||||
|
->enhanceImage()
|
||||||
|
->saveResult();
|
||||||
|
|
||||||
|
return $this->outputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function detectDocument() {
|
||||||
|
// Converte para escala de cinza
|
||||||
|
$gray = cv\cvtColor($this->srcImage, cv\COLOR_BGR2GRAY);
|
||||||
|
|
||||||
|
// Aplica blur para reduzir ruído
|
||||||
|
$blur = new cv\Mat();
|
||||||
|
cv\GaussianBlur($gray, $blur, new cv\Size(5, 5), 0);
|
||||||
|
|
||||||
|
// Detecta bordas
|
||||||
|
$edges = new cv\Mat();
|
||||||
|
cv\Canny($blur, $edges, 75, 200);
|
||||||
|
|
||||||
|
// Encontra contornos
|
||||||
|
$contours = [];
|
||||||
|
$hierarchy = new cv\Mat();
|
||||||
|
cv\findContours($edges, $contours, $hierarchy, cv\RETR_LIST, cv\CHAIN_APPROX_SIMPLE);
|
||||||
|
|
||||||
|
// Ordena contornos por área
|
||||||
|
usort($contours, function($a, $b) {
|
||||||
|
return cv\contourArea($b) - cv\contourArea($a);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Procura o contorno mais próximo de um documento
|
||||||
|
foreach ($contours as $contour) {
|
||||||
|
$peri = cv\arcLength($contour, true);
|
||||||
|
$approx = cv\approxPolyDP($contour, 0.02 * $peri, true);
|
||||||
|
|
||||||
|
if (count($approx) == 4) {
|
||||||
|
$this->documentContour = $approx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function correctPerspective() {
|
||||||
|
if (!isset($this->documentContour)) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ordena os pontos para perspectiva
|
||||||
|
$points = $this->orderPoints($this->documentContour);
|
||||||
|
|
||||||
|
// Calcula dimensões do documento
|
||||||
|
$width = max(
|
||||||
|
sqrt(pow($points[1][0] - $points[0][0], 2) + pow($points[1][1] - $points[0][1], 2)),
|
||||||
|
sqrt(pow($points[3][0] - $points[2][0], 2) + pow($points[3][1] - $points[2][1], 2))
|
||||||
|
);
|
||||||
|
|
||||||
|
$height = max(
|
||||||
|
sqrt(pow($points[2][0] - $points[1][0], 2) + pow($points[2][1] - $points[1][1], 2)),
|
||||||
|
sqrt(pow($points[3][0] - $points[0][0], 2) + pow($points[3][1] - $points[0][1], 2))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Define pontos de destino
|
||||||
|
$dst = cv\Mat::zeros([4, 2], CV_32F);
|
||||||
|
$dst[0] = [0, 0];
|
||||||
|
$dst[1] = [$width - 1, 0];
|
||||||
|
$dst[2] = [$width - 1, $height - 1];
|
||||||
|
$dst[3] = [0, $height - 1];
|
||||||
|
|
||||||
|
// Aplica transformação de perspectiva
|
||||||
|
$matrix = cv\getPerspectiveTransform($points, $dst);
|
||||||
|
$this->processedImage = cv\warpPerspective($this->srcImage, $matrix, [$width, $height]);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function enhanceImage() {
|
||||||
|
if (!isset($this->processedImage)) {
|
||||||
|
$this->processedImage = $this->srcImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converte para LAB para melhor processamento
|
||||||
|
$lab = cv\cvtColor($this->processedImage, cv\COLOR_BGR2LAB);
|
||||||
|
$l_channel = cv\split($lab)[0];
|
||||||
|
|
||||||
|
// Aplica CLAHE para melhorar contraste
|
||||||
|
$clahe = cv\createCLAHE(3.0, [8, 8]);
|
||||||
|
$cl = $clahe->apply($l_channel);
|
||||||
|
|
||||||
|
// Reconstrói imagem
|
||||||
|
$limg = cv\merge([$cl, cv\split($lab)[1], cv\split($lab)[2]]);
|
||||||
|
$this->processedImage = cv\cvtColor($limg, cv\COLOR_LAB2BGR);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function saveResult() {
|
||||||
|
if (!isset($this->processedImage)) {
|
||||||
|
throw new Exception('No processed image to save');
|
||||||
|
}
|
||||||
|
|
||||||
|
cv\imwrite($this->outputPath, $this->processedImage);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function orderPoints($pts) {
|
||||||
|
// Ordena pontos para transformação de perspectiva
|
||||||
|
$rect = array_fill(0, 4, [0, 0]);
|
||||||
|
$s = array_map(function($p) { return $p[0] + $p[1]; }, $pts);
|
||||||
|
$d = array_map(function($p) { return $p[0] - $p[1]; }, $pts);
|
||||||
|
|
||||||
|
$rect[0] = $pts[array_search(min($s), $s)]; // top-left
|
||||||
|
$rect[2] = $pts[array_search(max($s), $s)]; // bottom-right
|
||||||
|
$rect[1] = $pts[array_search(min($d), $d)]; // top-right
|
||||||
|
$rect[3] = $pts[array_search(max($d), $d)]; // bottom-left
|
||||||
|
|
||||||
|
return $rect;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,6 +52,10 @@ include 'top_menu.php';
|
|||||||
include 'clientes/edit_note.php';
|
include 'clientes/edit_note.php';
|
||||||
} elseif ($page == 'delete_note' && isset($_POST['id'])) {
|
} elseif ($page == 'delete_note' && isset($_POST['id'])) {
|
||||||
include 'clientes/delete_note.php';
|
include 'clientes/delete_note.php';
|
||||||
|
} elseif ($page == 'process_document') {
|
||||||
|
include 'process_document.php';
|
||||||
|
} elseif ($page == 'document_history') {
|
||||||
|
include 'document_history.php';
|
||||||
} else {
|
} else {
|
||||||
echo "<h2>Bem-vindo ao Sistema de Ferramentas</h2>";
|
echo "<h2>Bem-vindo ao Sistema de Ferramentas</h2>";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if (!isset($_SESSION['user_id'])) {
|
|||||||
<li>
|
<li>
|
||||||
<a href="javascript:void(0);" onclick="toggleSubmenu('submenu1')">Autenticador de Provas Digitais</a>
|
<a href="javascript:void(0);" onclick="toggleSubmenu('submenu1')">Autenticador de Provas Digitais</a>
|
||||||
<ul id="submenu1" class="submenu">
|
<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=status">Ver Status</a></li>
|
||||||
<li><a href="index.php?page=list_files">Lista de Arquivos Processados</a></li>
|
<li><a href="index.php?page=list_files">Lista de Arquivos Processados</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -24,6 +24,13 @@ if (!isset($_SESSION['user_id'])) {
|
|||||||
<li><a href="index.php?page=list_clients">Listagem de Clientes</a></li>
|
<li><a href="index.php?page=list_clients">Listagem de Clientes</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="javascript:void(0);" onclick="toggleSubmenu('submenu3')">Processamento de Documentos</a>
|
||||||
|
<ul id="submenu3" class="submenu">
|
||||||
|
<li><a href="index.php?page=process_document">Processar Documento</a></li>
|
||||||
|
<li><a href="index.php?page=document_history">Histórico</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
<!-- Adicione mais ferramentas aqui -->
|
<!-- Adicione mais ferramentas aqui -->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
if (!isset($_SESSION['user_id'])) {
|
||||||
|
header("Location: login.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'document_processor.php';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['document'])) {
|
||||||
|
try {
|
||||||
|
$file = $_FILES['document'];
|
||||||
|
$uploadDir = 'uploads/documents/';
|
||||||
|
$processedDir = 'uploads/processed/';
|
||||||
|
|
||||||
|
// Cria diretórios se não existirem
|
||||||
|
if (!file_exists($uploadDir)) {
|
||||||
|
mkdir($uploadDir, 0777, true);
|
||||||
|
}
|
||||||
|
if (!file_exists($processedDir)) {
|
||||||
|
mkdir($processedDir, 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gera nomes únicos para os arquivos
|
||||||
|
$originalName = basename($file['name']);
|
||||||
|
$extension = pathinfo($originalName, PATHINFO_EXTENSION);
|
||||||
|
$timestamp = time();
|
||||||
|
$uploadFile = $uploadDir . $timestamp . '_' . $originalName;
|
||||||
|
$processedFile = $processedDir . $timestamp . '_processed.' . $extension;
|
||||||
|
|
||||||
|
if (move_uploaded_file($file['tmp_name'], $uploadFile)) {
|
||||||
|
$processor = new DocumentProcessor();
|
||||||
|
$result = $processor->processDocument($uploadFile, $processedFile);
|
||||||
|
|
||||||
|
// Salva o registro no banco de dados
|
||||||
|
$mysqli = new mysqli("10.15.0.42", "root", "34641747", "valida");
|
||||||
|
$stmt = $mysqli->prepare("INSERT INTO processed_documents (user_id, original_path, processed_path, created_at) VALUES (?, ?, ?, NOW())");
|
||||||
|
$stmt->bind_param("iss", $_SESSION['user_id'], $uploadFile, $processedFile);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$message = "Documento processado com sucesso!";
|
||||||
|
$success = true;
|
||||||
|
} else {
|
||||||
|
throw new Exception("Falha ao fazer upload do arquivo.");
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$message = "Erro: " . $e->getMessage();
|
||||||
|
$success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h2>Processamento de Documentos</h2>
|
||||||
|
|
||||||
|
<?php if (isset($message)): ?>
|
||||||
|
<div class="alert <?php echo $success ? 'alert-success' : 'alert-error'; ?>">
|
||||||
|
<?php echo htmlspecialchars($message); ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="POST" enctype="multipart/form-data" class="upload-form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="document">Selecione o documento:</label>
|
||||||
|
<input type="file" id="document" name="document" accept="image/*" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Processar Documento</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php if (isset($processedFile) && file_exists($processedFile)): ?>
|
||||||
|
<div class="result-preview">
|
||||||
|
<h3>Resultado:</h3>
|
||||||
|
<div class="image-comparison">
|
||||||
|
<div>
|
||||||
|
<h4>Original:</h4>
|
||||||
|
<img src="<?php echo htmlspecialchars($uploadFile); ?>" alt="Original">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4>Processado:</h4>
|
||||||
|
<img src="<?php echo htmlspecialchars($processedFile); ?>" alt="Processado">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
@@ -209,3 +209,50 @@ textarea {
|
|||||||
#search-button:hover {
|
#search-button:hover {
|
||||||
background-color: #0056b3;
|
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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user