versao word 4

This commit is contained in:
Flatlogic Bot 2025-12-01 23:03:27 +00:00
parent 369b14c872
commit 716bb2a115

View File

@ -33,141 +33,104 @@ try {
die("Erro ao acessar o banco de dados: " . $e->getMessage()); die("Erro ao acessar o banco de dados: " . $e->getMessage());
} }
// 5. Gerar o nome do arquivo para download // --- Início da Geração MHTML ---
$boundary = "----=" . md5(uniqid(time()));
$filename = "instalacao_" . $installation['id'] . "_" . str_replace(' ', '_', $installation['client_name']) . ".doc"; $filename = "instalacao_" . $installation['id'] . "_" . str_replace(' ', '_', $installation['client_name']) . ".doc";
// 6. Enviar cabeçalhos para forçar o download // Cabeçalhos principais para MHTML
header("Content-Type: application/vnd.ms-word"); header("Content-Type: multipart/related; boundary=\"$boundary\"");
header("Content-Disposition: attachment; filename=\"" . $filename . "\""); header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// 7. Iniciar a geração do conteúdo HTML // Parte 1: Conteúdo HTML
?> $html_content = <<<HTML
<!DOCTYPE html> <!DOCTYPE html>
<html lang="pt-BR"> <html lang="pt-BR">
<head> <head>
<meta charset="UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Relatório de Instalação - <?php echo htmlspecialchars($installation['client_name']); ?></title> <title>Relatório de Instalação - {htmlspecialchars($installation['client_name'])}</title>
<style> <style>
body { body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
font-family: Arial, sans-serif; .container { width: 90%; margin: 0 auto; }
line-height: 1.6; h1 { color: #0056b3; border-bottom: 2px solid #f0f0f0; padding-bottom: 10px; }
color: #333; .details-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
} .details-table td { padding: 8px; border: 1px solid #ddd; }
.container { .details-table td:first-child { font-weight: bold; background-color: #f9f9f9; width: 25%; }
width: 90%; .images-section img { max-width: 400px; margin: 10px; border: 1px solid #ccc; padding: 5px; }
margin: 0 auto; .section-title { font-size: 1.5em; color: #0056b3; margin-top: 20px; margin-bottom: 10px; }
}
h1 {
color: #0056b3;
border-bottom: 2px solid #f0f0f0;
padding-bottom: 10px;
}
.details-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
.details-table td {
padding: 8px;
border: 1px solid #ddd;
}
.details-table td:first-child {
font-weight: bold;
background-color: #f9f9f9;
width: 25%;
}
.images-section img {
max-width: 400px;
margin: 10px;
border: 1px solid #ccc;
padding: 5px;
}
.section-title {
font-size: 1.5em;
color: #0056b3;
margin-top: 20px;
margin-bottom: 10px;
}
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>Relatório de Instalação</h1> <h1>Relatório de Instalação</h1>
<h2 class="section-title">Detalhes do Cliente e Instalação</h2> <h2 class="section-title">Detalhes do Cliente e Instalação</h2>
<table class="details-table"> <table class="details-table">
<tr> <tr><td>ID da Instalação</td><td>{htmlspecialchars($installation['id'])}</td></tr>
<td>ID da Instalação</td> <tr><td>Cliente</td><td>{htmlspecialchars($installation['client_name'])}</td></tr>
<td><?php echo htmlspecialchars($installation['id']); ?></td> <tr><td>Endereço</td><td>{htmlspecialchars($installation['address'])}</td></tr>
</tr> <tr><td>Técnico Responsável</td><td>{htmlspecialchars($installation['technician_name'])}</td></tr>
<tr> <tr><td>Data</td><td>{date("d/m/Y H:i", strtotime($installation['created_at']))}</td></tr>
<td>Cliente</td> <tr><td>Status</td><td>{ucfirst(htmlspecialchars($installation['status']))}</td></tr>
<td><?php echo htmlspecialchars($installation['client_name']); ?></td>
</tr>
<tr>
<td>Endereço</td>
<td><?php echo htmlspecialchars($installation['address']); ?></td>
</tr>
<tr>
<td>Técnico Responsável</td>
<td><?php echo htmlspecialchars($installation['technician_name']); ?></td>
</tr>
<tr>
<td>Data</td>
<td><?php echo date("d/m/Y H:i", strtotime($installation['created_at'])); ?></td>
</tr>
<tr>
<td>Status</td>
<td><?php echo ucfirst(htmlspecialchars($installation['status'])); ?></td>
</tr>
</table> </table>
<h2 class="section-title">Dados Elétricos</h2> <h2 class="section-title">Dados Elétricos</h2>
<table class="details-table"> <table class="details-table">
<tr> <tr><td>Tensão (V)</td><td>{htmlspecialchars($installation['voltage'] ?? 'N/A')}</td></tr>
<td>Tensão (V)</td> <tr><td>Fase-Neutro-Terra</td><td>{htmlspecialchars($installation['phase_neutral_ground'] ?? 'N/A')}</td></tr>
<td><?php echo htmlspecialchars($installation['voltage'] ?? 'N/A'); ?></td> <tr><td>Saída do Disjuntor</td><td>{htmlspecialchars($installation['breaker_output'] ?? 'N/A')}</td></tr>
</tr>
<tr>
<td>Fase-Neutro-Terra</td>
<td><?php echo htmlspecialchars($installation['phase_neutral_ground'] ?? 'N/A'); ?></td>
</tr>
<tr>
<td>Saída do Disjuntor</td>
<td><?php echo htmlspecialchars($installation['breaker_output'] ?? 'N/A'); ?></td>
</tr>
</table> </table>
<h2 class="section-title">Observações</h2> <h2 class="section-title">Observações</h2>
<p><?php echo nl2br(htmlspecialchars($installation['observations'] ?? 'Nenhuma observação.')); ?></p> <p>{nl2br(htmlspecialchars($installation['observations'] ?? 'Nenhuma observação.'))}</p>
HTML;
<?php if (!empty($images)): ?> // Preparar a seção de imagens
<h2 class="section-title">Imagens da Instalação</h2> $images_html = '';
<div class="images-section" style="page-break-before: always;"> $image_parts = '';
<?php foreach ($images as $image):
// Construir caminho absoluto de forma mais robusta if (!empty($images)) {
$images_html = '<h2 class="section-title">Imagens da Instalação</h2><div class="images-section" style="page-break-before: always;">';
foreach ($images as $i => $image) {
$image_full_path = realpath(__DIR__ . '/' . $image['image_path']); $image_full_path = realpath(__DIR__ . '/' . $image['image_path']);
if (file_exists($image_full_path)) { if (file_exists($image_full_path)) {
// Tentar obter o tipo MIME
$finfo = finfo_open(FILEINFO_MIME_TYPE); $finfo = finfo_open(FILEINFO_MIME_TYPE);
$image_mime = finfo_file($finfo, $image_full_path); $image_mime = finfo_file($finfo, $image_full_path);
finfo_close($finfo); finfo_close($finfo);
// Obter conteúdo e codificar
$image_data = base64_encode(file_get_contents($image_full_path)); $image_data = base64_encode(file_get_contents($image_full_path));
$cid = "image" . $i . "@" . md5($image['image_path']);
// Exibir imagem incorporada // Adiciona a tag <img> ao HTML
echo '<img src="data:' . $image_mime . ';base64,' . $image_data . '" alt="Imagem da Instalação"><br>'; $images_html .= '<img src="cid:' . $cid . '" alt="Imagem da Instalação ' . ($i+1) . '"><br>';
} else {
echo '<p style="color: red;">Imagem não encontrada no caminho: ' . htmlspecialchars($image['image_path']) . '</p>'; // Cria a parte MIME para a imagem
$image_parts .= "--$boundary\r\n";
$image_parts .= "Content-Type: $image_mime\r\n";
$image_parts .= "Content-Transfer-Encoding: base64\r\n";
$image_parts .= "Content-ID: <$cid>\r\n";
$image_parts .= "Content-Location: " . basename($image['image_path']) . "\r\n\r\n";
$image_parts .= chunk_split($image_data) . "\r\n";
} }
?><?php endforeach; ?> }
</div> $images_html .= '</div>';
<?php endif; ?> }
</div> // Finaliza o HTML
</body> $html_content .= $images_html;
</html> $html_content .= '</div></body></html>';
// Monta a saída final
echo "--$boundary\r\n";
echo "Content-Type: text/html; charset=\"UTF-8\"\r\n";
echo "Content-Transfer-Encoding: 7bit\r\n\r\n";
echo $html_content . "\r\n";
// Adiciona as partes das imagens
echo $image_parts;
// Fecha o boundary final
echo "--$boundary--\r\n";
?>