35330-vm/macro_areas.php
Flatlogic Bot 6e8e69c52f versao 15
2025-10-29 16:51:49 +00:00

192 lines
7.4 KiB
PHP

<?php
require_once 'includes/session.php';
require_once 'db/config.php';
include_once 'includes/header.php';
$pdo = db();
$stmt = $pdo->query('SELECT * FROM macro_areas ORDER BY nome ASC');
$macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="container-fluid">
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0">Macro Áreas</h1>
<div>
<button id="printButton" class="btn btn-secondary btn-icon-split">
<span class="icon text-white-50"><i data-lucide="file-text" style="color: #FFFFFF;"></i></span>
<span class="text">Imprimir Lista</span>
</button>
<a href="macro_area_form.php" class="btn btn-primary btn-icon-split">
<span class="icon text-white-50"><i data-lucide="plus" style="color: #FFFFFF;"></i></span>
<span class="text">Nova Macro Área</span>
</a>
</div>
</div>
<?php if (isset($_SESSION['success_message'])): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?php echo $_SESSION['success_message']; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['success_message']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['error_message'])): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?php echo $_SESSION['error_message']; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['error_message']); ?>
<?php endif; ?>
<div class="card shadow mb-4">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold" style="color: #005C53;">
<i data-lucide="layers" class="me-2"></i>Lista de Macro Áreas
</h6>
<div class="input-group" style="width: 250px;">
<span class="input-group-text text-slate-400"><i data-lucide="search"></i></span>
<input type="text" class="form-control" id="searchInput" placeholder="Buscar...">
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-sm" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Nome</th>
<th>Descrição</th>
<th>Status</th>
<th style="width: 85px;">Ações</th>
</tr>
</thead>
<tbody id="tableBody">
<?php foreach ($macro_areas as $area):
$badgeClass = $area['ativo'] ? 'badge-status-ativo' : 'badge-status-arquivado';
$statusText = $area['ativo'] ? 'Ativo' : 'Arquivado';
?>
<tr>
<td><?php echo htmlspecialchars($area['nome']); ?></td>
<td><?php echo htmlspecialchars($area['descricao']); ?></td>
<td>
<span class="badge <?php echo $badgeClass; ?>"><?php echo $statusText; ?></span>
</td>
<td>
<div class="d-flex">
<a href="macro_area_form.php?id=<?php echo $area['id']; ?>" class="btn btn-sm">
<i data-lucide="edit" style="color: #4C5958; width: 18px; height: 18px;"></i>
</a>
<a href="delete_macro_area.php?id=<?php echo $area['id']; ?>" class="btn btn-sm">
<i data-lucide="trash-2" style="color: #4C5958; width: 18px; height: 18px;"></i>
</a>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($macro_areas)):
<tr>
<td colspan="4" class="text-center">Nenhuma macro área encontrada.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php include_once 'includes/footer.php'; ?>
<script>
document.addEventListener('DOMContentLoaded', function () {
// Search functionality
const searchInput = document.getElementById('searchInput');
const tableBody = document.getElementById('tableBody');
const tableRows = tableBody.getElementsByTagName('tr');
searchInput.addEventListener('keyup', function() {
const searchTerm = searchInput.value.toLowerCase();
for (let i = 0; i < tableRows.length; i++) {
const row = tableRows[i];
const cells = row.getElementsByTagName('td');
let match = false;
// Start search from the first cell, and not the last one (actions)
for (let j = 0; j < cells.length - 1; j++) {
if (cells[j]) {
if (cells[j].textContent.toLowerCase().indexOf(searchTerm) > -1) {
match = true;
break;
}
}
}
if (match) {
row.style.display = '';
} else {
row.style.display = 'none';
}
}
});
// Print functionality
const printButton = document.getElementById('printButton');
printButton.addEventListener('click', function() {
fetch('print_macro_areas.php')
.then(response => response.text())
.then(html => {
const printWindow = window.open('', '_blank');
printWindow.document.write(html);
printWindow.document.close();
printWindow.focus(); // Required for some browsers
// Use a small timeout to ensure content is loaded before printing
setTimeout(() => {
printWindow.print();
}, 250);
printWindow.addEventListener('afterprint', () => {
printWindow.close();
});
})
.catch(error => console.error('Error fetching print content:', error));
});
});
</script>
<style>
#printButton {
background-color: #005C53;
border-color: #005C53;
}
#printButton:hover {
background-color: #004c43;
border-color: #004c43;
}
.input-group-text {
background-color: #fff;
border-right: 0;
}
#searchInput {
border-left: 0;
}
.btn-sm i[data-lucide] {
width: 18px;
height: 18px;
}
/* Custom styles for status badges */
.badge-status-ativo {
background-color: #d1e7dd; /* Light green */
color: #0f5132; /* Dark green */
border: 1px solid #badbcc;
}
.badge-status-arquivado {
background-color: #f8d7da; /* Light red */
color: #842029; /* Dark red */
border: 1px solid #f5c2c7;
}
</style>