add upload anexos pos ordem criada
This commit is contained in:
@@ -116,6 +116,7 @@ class OrderController
|
||||
|
||||
$conn = \App\Config\Database::getInstance()->getConnection();
|
||||
|
||||
$conn->beginTransaction();
|
||||
try {
|
||||
// Create Order
|
||||
$sql = "INSERT INTO orders (title, type, content, received_at) VALUES (:title, :type, :content, :received_at)";
|
||||
@@ -149,10 +150,13 @@ class OrderController
|
||||
'type' => $typeLabel
|
||||
], $count);
|
||||
|
||||
$conn->commit();
|
||||
|
||||
$_SESSION['flash_success'] = "Ordem criada com sucesso! $count domínios processados.";
|
||||
View::redirect('/admin/orders');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$conn->rollBack();
|
||||
$_SESSION['flash_error'] = "Erro ao processar ordem: " . $e->getMessage();
|
||||
View::redirect('/admin/orders/create');
|
||||
}
|
||||
@@ -216,4 +220,36 @@ class OrderController
|
||||
readfile($filePath);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function uploadAttachments($id)
|
||||
{
|
||||
$orderModel = new \App\Models\Order();
|
||||
$order = $orderModel->find($id);
|
||||
|
||||
if (!$order) {
|
||||
$_SESSION['flash_error'] = "Ordem não encontrada.";
|
||||
View::redirect('/admin/orders');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isset($_FILES['new_attachments']) && !empty($_FILES['new_attachments']['name'][0])) {
|
||||
$attachments = $_FILES['new_attachments'];
|
||||
$attachmentService = new AttachmentService();
|
||||
$savedCount = $attachmentService->storeFiles((int) $id, $attachments);
|
||||
|
||||
if ($savedCount > 0) {
|
||||
$_SESSION['flash_success'] = "{$savedCount} anexo(s) adicionado(s) com sucesso à ordem!";
|
||||
} else {
|
||||
$_SESSION['flash_error'] = "Nenhum arquivo válido foi recebido.";
|
||||
}
|
||||
} else {
|
||||
$_SESSION['flash_error'] = "Nenhum arquivo foi selecionado.";
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$_SESSION['flash_error'] = "Erro de upload: " . $e->getMessage();
|
||||
}
|
||||
|
||||
View::redirect('/admin/orders/view/' . $id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user