35330-vm/macro_areas.php
Flatlogic Bot e84e983545 versao 11
2025-10-29 16:16:48 +00:00

152 lines
5.7 KiB
PHP

<?php
require_once 'includes/session.php';
require_once 'db/config.php';
include_once 'includes/header.php';
$pdo = db();
// Handle deletion
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
// TODO: Add check to see if there are expenses associated before deleting
$stmt = $pdo->prepare('DELETE FROM macro_areas WHERE id = ?');
$stmt->execute([$id]);
header("Location: macro_areas.php");
exit;
}
$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 class="btn btn-secondary btn-icon-split btn-sm">
<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>
<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 text-primary">
<i data-lucide="layers" class="me-2" style="color: #005C53;"></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" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Nome</th>
<th>Descrição</th>
<th>Status</th>
<th style="width: 100px;">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>
<a href="macro_area_form.php?id=<?php echo $area['id']; ?>" class="btn btn-sm">
<i data-lucide="edit" style="color: #4C5958;"></i>
</a>
<a href="macro_areas.php?delete=<?php echo $area['id']; ?>" class="btn btn-sm" onclick="return confirm('Tem certeza que deseja excluir este item?');">
<i data-lucide="trash-2" style="color: #4C5958;"></i>
</a>
</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';
}
}
});
});
</script>
<style>
.input-group-text {
background-color: #fff;
border-right: 0;
}
#searchInput {
border-left: 0;
}
.btn-sm i[data-lucide] {
width: 16px;
height: 16px;
}
/* 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>