versao 6
This commit is contained in:
parent
19d6fb9cc2
commit
da57997223
@ -298,3 +298,66 @@ body {
|
|||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macro Áreas Module Styles
|
||||||
|
* --------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: #eeeeee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Titles and Text */
|
||||||
|
.h1, .h2, .h3, .h4, .h5, .h6, h1, h2, h3, h4, h5, h6 {
|
||||||
|
color: #10403B;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Primary Buttons */
|
||||||
|
.btn-primary {
|
||||||
|
background-color: #005C53;
|
||||||
|
border-color: #005C53;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: #00443e;
|
||||||
|
border-color: #00443e;
|
||||||
|
}
|
||||||
|
.btn-primary .fas {
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Card Styles */
|
||||||
|
.card {
|
||||||
|
border: 1px solid #005C53;
|
||||||
|
}
|
||||||
|
.card-header {
|
||||||
|
background-color: #8AA6A3;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
.card-header .m-0.font-weight-bold {
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Table Styles */
|
||||||
|
.table thead th {
|
||||||
|
background-color: #8AA6A3;
|
||||||
|
color: #FFFFFF;
|
||||||
|
border-color: #8AA6A3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Badge Styles */
|
||||||
|
.badge-status-ativo {
|
||||||
|
background-color: #8AA6A3;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
.badge-status-arquivado {
|
||||||
|
background-color: #f0f0f0; /* gray-100 */
|
||||||
|
color: #333; /* gray-800 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Action Icons */
|
||||||
|
.table .btn .fas {
|
||||||
|
color: #4C5958;
|
||||||
|
}
|
||||||
170
macro_areas.php
170
macro_areas.php
@ -3,8 +3,54 @@ require_once 'includes/session.php';
|
|||||||
require_once 'db/config.php';
|
require_once 'db/config.php';
|
||||||
include_once 'includes/header.php';
|
include_once 'includes/header.php';
|
||||||
|
|
||||||
// Fetch macro areas from the database
|
// Helper function to generate a slug
|
||||||
|
function slugify($text) {
|
||||||
|
$text = preg_replace('~[\\pL\\d]+~u', '-', $text); // Added 'u' modifier for UTF-8
|
||||||
|
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||||
|
$text = preg_replace('~[^\\w]+~', '-', $text);
|
||||||
|
$text = trim($text, '-');
|
||||||
|
$text = preg_replace('~-~', '-', $text); // Simplified to just '-' as it's already trimmed
|
||||||
|
$text = strtolower($text);
|
||||||
|
return $text ?: 'n-a';
|
||||||
|
}
|
||||||
|
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
|
|
||||||
|
// Handle form submission (Create/Update)
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$id = $_POST['id'] ?? null;
|
||||||
|
$nome = $_POST['nome'] ?? '';
|
||||||
|
$descricao = $_POST['descricao'] ?? '';
|
||||||
|
$ativo = isset($_POST['ativo']) ? 1 : 0;
|
||||||
|
|
||||||
|
if ($nome) { // Basic validation
|
||||||
|
if ($id) {
|
||||||
|
// Update
|
||||||
|
$stmt = $pdo->prepare('UPDATE macro_areas SET nome = ?, descricao = ?, ativo = ? WHERE id = ?');
|
||||||
|
$stmt->execute([$nome, $descricao, $ativo, $id]);
|
||||||
|
} else {
|
||||||
|
// Create
|
||||||
|
$slug = slugify($nome);
|
||||||
|
$stmt = $pdo->prepare('INSERT INTO macro_areas (nome, descricao, slug, ativo, created_by) VALUES (?, ?, ?, ?, ?)');
|
||||||
|
$stmt->execute([$nome, $descricao, $slug, $ativo, $_SESSION['user_email'] ?? 'system']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Redirect to avoid form resubmission
|
||||||
|
header("Location: macro_areas.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle deletion
|
||||||
|
if (isset($_GET['delete'])) {
|
||||||
|
$id = $_GET['delete'];
|
||||||
|
$stmt = $pdo->prepare('DELETE FROM macro_areas WHERE id = ?');
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
header("Location: macro_areas.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Fetch macro areas from the database
|
||||||
$stmt = $pdo->query('SELECT * FROM macro_areas ORDER BY nome ASC');
|
$stmt = $pdo->query('SELECT * FROM macro_areas ORDER BY nome ASC');
|
||||||
$macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
@ -13,18 +59,22 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<!-- Page Heading -->
|
<!-- Page Heading -->
|
||||||
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
||||||
<h1 class="h3 mb-0 text-gray-800">Macro Áreas</h1>
|
<h1 class="h3 mb-0">Macro Áreas</h1>
|
||||||
<a href="#" class="btn btn-success btn-icon-split">
|
<div>
|
||||||
<span class="icon text-white-50">
|
<button class="btn btn-secondary btn-icon-split btn-sm">
|
||||||
<i class="fas fa-plus"></i>
|
<span class="icon text-white-50"><i class="fas fa-print"></i></span>
|
||||||
</span>
|
<span class="text">Imprimir Lista</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-primary btn-icon-split" data-toggle="modal" data-target="#macroAreaModal">
|
||||||
|
<span class="icon text-white-50"><i class="fas fa-plus"></i></span>
|
||||||
<span class="text">Nova Macro Área</span>
|
<span class="text">Nova Macro Área</span>
|
||||||
</a>
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="card shadow mb-4">
|
||||||
<div class="card-header py-3">
|
<div class="card-header py-3">
|
||||||
<h6 class="m-0 font-weight-bold text-primary">Registros</h6>
|
<h6 class="m-0 font-weight-bold">Registros</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
@ -34,32 +84,38 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<th>Nome</th>
|
<th>Nome</th>
|
||||||
<th>Descrição</th>
|
<th>Descrição</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Ações</th>
|
<th style="width: 100px;">Ações</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($macro_areas as $area): ?>
|
<?php foreach ($macro_areas as $area):
|
||||||
|
// Added check for 'ativo' to determine badge class
|
||||||
|
$badgeClass = $area['ativo'] ? 'badge-status-ativo' : 'badge-status-arquivado';
|
||||||
|
$statusText = $area['ativo'] ? 'Ativo' : 'Arquivado';
|
||||||
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo htmlspecialchars($area['nome']); ?></td>
|
<td><?php echo htmlspecialchars($area['nome']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($area['descricao']); ?></td>
|
<td><?php echo htmlspecialchars($area['descricao']); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<?php if ($area['ativo']): ?>
|
<span class="badge <?php echo $badgeClass; ?>"><?php echo $statusText; ?></span>
|
||||||
<span class="badge badge-success">Ativo</span>
|
|
||||||
<?php else: ?>
|
|
||||||
<span class="badge badge-secondary">Arquivado</span>
|
|
||||||
<?php endif; ?>
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="#" class="btn btn-info btn-circle btn-sm">
|
<button class="btn btn-info btn-circle btn-sm edit-btn"
|
||||||
|
data-id="<?php echo $area['id']; ?>"
|
||||||
|
data-nome="<?php echo htmlspecialchars($area['nome']); ?>"
|
||||||
|
data-descricao="<?php echo htmlspecialchars($area['descricao']); ?>"
|
||||||
|
data-ativo="<?php echo $area['ativo']; ?>">
|
||||||
<i class="fas fa-edit"></i>
|
<i class="fas fa-edit"></i>
|
||||||
</a>
|
</button>
|
||||||
<a href="#" class="btn btn-danger btn-circle btn-sm">
|
<a href="macro_areas.php?delete=<?php echo $area['id']; ?>" class="btn btn-danger btn-circle btn-sm" onclick="return confirm('Tem certeza que deseja excluir este item?');">
|
||||||
<i class="fas fa-trash"></i>
|
<i class="fas fa-trash"></i>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if (empty($macro_areas)): ?>
|
<?php if (empty($macro_areas)):
|
||||||
|
// Added colspan to match the number of columns
|
||||||
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4" class="text-center">Nenhuma macro área encontrada.</td>
|
<td colspan="4" class="text-center">Nenhuma macro área encontrada.</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -69,10 +125,76 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- /.container-fluid -->
|
|
||||||
|
|
||||||
<?php
|
<!-- Modal -->
|
||||||
include_once 'includes/footer.php';
|
<div class="modal fade" id="macroAreaModal" tabindex="-1" role="dialog" aria-labelledby="macroAreaModalLabel" aria-hidden="true">
|
||||||
?>
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="macroAreaModalLabel">Nova Macro Área</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<form id="macroAreaForm" method="POST" action="macro_areas.php">
|
||||||
|
<div class="modal-body">
|
||||||
|
<input type="hidden" name="id" id="macroAreaId">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="macroAreaNome">Nome</label>
|
||||||
|
<input type="text" class="form-control" id="macroAreaNome" name="nome" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="macroAreaDescricao">Descrição</label>
|
||||||
|
<textarea class="form-control" id="macroAreaDescricao" name="descricao" rows="3"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="macroAreaAtivo" name="ativo" value="1" checked>
|
||||||
|
<label class="form-check-label" for="macroAreaAtivo">Ativo</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Salvar</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include_once 'includes/footer.php'; ?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
// Handle modal for "Nova Macro Área"
|
||||||
|
$('#macroAreaModal').on('show.bs.modal', function (event) {
|
||||||
|
var button = $(event.relatedTarget); // Button that triggered the modal
|
||||||
|
var modal = $(this);
|
||||||
|
|
||||||
|
// If button is the "edit" button, it will have data attributes
|
||||||
|
var id = button.data('id');
|
||||||
|
if (id) {
|
||||||
|
// Editing an existing record
|
||||||
|
var nome = button.data('nome');
|
||||||
|
var descricao = button.data('descricao');
|
||||||
|
var ativo = button.data('ativo');
|
||||||
|
|
||||||
|
modal.find('.modal-title').text('Editar Macro Área');
|
||||||
|
modal.find('#macroAreaId').val(id);
|
||||||
|
modal.find('#macroAreaNome').val(nome);
|
||||||
|
modal.find('#macroAreaDescricao').val(descricao);
|
||||||
|
if (ativo == 1) {
|
||||||
|
modal.find('#macroAreaAtivo').prop('checked', true);
|
||||||
|
} else {
|
||||||
|
modal.find('#macroAreaAtivo').prop('checked', false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Creating a new record
|
||||||
|
modal.find('.modal-title').text('Nova Macro Área');
|
||||||
|
modal.find('#macroAreaForm')[0].reset();
|
||||||
|
modal.find('#macroAreaId').val('');
|
||||||
|
modal.find('#macroAreaAtivo').prop('checked', true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Loading…
x
Reference in New Issue
Block a user