Implementacao upload anexos de ordens
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderAttachment;
|
||||
use App\Services\AttachmentService;
|
||||
use App\Services\OrderProcessor;
|
||||
use App\Services\TelegramService;
|
||||
use App\Utils\View;
|
||||
@@ -88,26 +90,32 @@ class OrderController
|
||||
$sql = "INSERT INTO orders (title, type, content, received_at) VALUES (:title, :type, :content, :received_at)";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute([
|
||||
'title' => $title,
|
||||
'type' => $type,
|
||||
'content' => $content,
|
||||
'title' => $title,
|
||||
'type' => $type,
|
||||
'content' => $content,
|
||||
'received_at' => $received_at
|
||||
]);
|
||||
|
||||
$orderId = $conn->lastInsertId();
|
||||
|
||||
// Process CSV
|
||||
// Process CSV (unchanged)
|
||||
$processor = new OrderProcessor();
|
||||
$count = $processor->process($orderId, $type, $_FILES['csv_file']['tmp_name']);
|
||||
|
||||
// Store attachments (if any were sent)
|
||||
if (isset($_FILES['attachments']) && !empty($_FILES['attachments']['name'][0])) {
|
||||
$attachmentService = new AttachmentService();
|
||||
$attachmentService->storeFiles((int) $orderId, $_FILES['attachments']);
|
||||
}
|
||||
|
||||
// Send Telegram Notification
|
||||
$telegramService = new TelegramService();
|
||||
$typeLabel = ($type === 'block') ? 'Bloqueio' : (($type === 'unblock') ? 'Desbloqueio' : $type);
|
||||
|
||||
$telegramService->sendOrderNotification([
|
||||
'id' => $orderId,
|
||||
'id' => $orderId,
|
||||
'title' => $title,
|
||||
'type' => $typeLabel
|
||||
'type' => $typeLabel
|
||||
], $count);
|
||||
|
||||
$_SESSION['flash_success'] = "Ordem criada com sucesso! $count domínios processados.";
|
||||
@@ -134,11 +142,47 @@ class OrderController
|
||||
$stmt->execute(['id' => $id]);
|
||||
$items = $stmt->fetchAll();
|
||||
|
||||
// Get Attachments
|
||||
$attachmentModel = new OrderAttachment();
|
||||
$attachments = $attachmentModel->findByOrderId((int) $id);
|
||||
|
||||
View::render('layouts.admin', [
|
||||
'title' => 'Detalhes da Ordem #' . $id,
|
||||
'content' => __DIR__ . '/../../resources/views/admin/orders/view.php',
|
||||
'order' => $order,
|
||||
'items' => $items
|
||||
'title' => 'Detalhes da Ordem #' . $id,
|
||||
'content' => __DIR__ . '/../../resources/views/admin/orders/view.php',
|
||||
'order' => $order,
|
||||
'items' => $items,
|
||||
'attachments' => $attachments,
|
||||
]);
|
||||
}
|
||||
|
||||
public function downloadAttachment($id)
|
||||
{
|
||||
$attachmentModel = new OrderAttachment();
|
||||
$attachment = $attachmentModel->find($id);
|
||||
|
||||
if (!$attachment) {
|
||||
$_SESSION['flash_error'] = "Anexo não encontrado.";
|
||||
View::redirect('/admin/orders');
|
||||
return;
|
||||
}
|
||||
|
||||
$attachmentService = new AttachmentService();
|
||||
$filePath = $attachmentService->getFilePath((int) $attachment['order_id'], $attachment['stored_name']);
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
$_SESSION['flash_error'] = "Arquivo físico não encontrado no servidor.";
|
||||
View::redirect('/admin/orders/view/' . $attachment['order_id']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Serve o arquivo para download
|
||||
header('Content-Type: ' . ($attachment['mime_type'] ?? 'application/octet-stream'));
|
||||
header('Content-Disposition: attachment; filename="' . addslashes($attachment['original_name']) . '"');
|
||||
header('Content-Length: ' . filesize($filePath));
|
||||
header('Cache-Control: private, no-cache');
|
||||
header('Pragma: no-cache');
|
||||
|
||||
readfile($filePath);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user