versao 7
This commit is contained in:
parent
da57997223
commit
d66f501122
@ -361,3 +361,97 @@ body {
|
|||||||
.table .btn .fas {
|
.table .btn .fas {
|
||||||
color: #4C5958;
|
color: #4C5958;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macro Áreas Modal Form Styles
|
||||||
|
* --------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#macroAreaModal .modal-content {
|
||||||
|
background-color: #eeeeee;
|
||||||
|
border: 1px solid #10403B;
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .modal-header,
|
||||||
|
#macroAreaModal .modal-body label {
|
||||||
|
color: #10403B;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .modal-header {
|
||||||
|
border-bottom: 1px solid #dcdcdc; /* Lighter separator */
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .modal-title {
|
||||||
|
color: #10403B;
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .form-control {
|
||||||
|
color: #4C5958;
|
||||||
|
border: 1px solid #b0b6b5;
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .form-control:focus {
|
||||||
|
border-color: #10403B;
|
||||||
|
box-shadow: 0 0 0 0.2rem rgba(16, 64, 59, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .form-control::placeholder {
|
||||||
|
color: #8AA6A3;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .modal-footer {
|
||||||
|
border-top: 1px solid #dcdcdc; /* Lighter separator */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Modal Buttons */
|
||||||
|
#macroAreaModal .modal-footer .btn-secondary {
|
||||||
|
background-color: #8AA6A3;
|
||||||
|
border-color: #8AA6A3;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .modal-footer .btn-secondary:hover {
|
||||||
|
background-color: #799592;
|
||||||
|
border-color: #799592;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .modal-footer .btn-primary {
|
||||||
|
background-color: #10403B;
|
||||||
|
border-color: #10403B;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
#macroAreaModal .modal-footer .btn-primary:hover {
|
||||||
|
background-color: #0a2926;
|
||||||
|
border-color: #0a2926;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Custom Switch for "Ativo" field */
|
||||||
|
.form-switch {
|
||||||
|
padding-left: 2.5em;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.form-switch .form-check-input {
|
||||||
|
width: 2em;
|
||||||
|
height: 1.25em;
|
||||||
|
margin-left: -2.5em;
|
||||||
|
background-color: #8AA6A3;
|
||||||
|
border-color: #8AA6A3;
|
||||||
|
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e");
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: left center;
|
||||||
|
border-radius: 2em;
|
||||||
|
transition: background-position .15s ease-in-out;
|
||||||
|
}
|
||||||
|
.form-switch .form-check-input:checked {
|
||||||
|
background-position: right center;
|
||||||
|
background-color: #10403B;
|
||||||
|
border-color: #10403B;
|
||||||
|
}
|
||||||
|
.form-switch .form-check-label {
|
||||||
|
padding-top: 2px;
|
||||||
|
}
|
||||||
|
|||||||
132
macro_areas.php
132
macro_areas.php
@ -3,46 +3,63 @@ 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';
|
||||||
|
|
||||||
// Helper function to generate a slug
|
// Helper function to generate a slug from a string
|
||||||
function slugify($text) {
|
function generateSlug($string) {
|
||||||
$text = preg_replace('~[\\pL\\d]+~u', '-', $text); // Added 'u' modifier for UTF-8
|
// Normalize to ASCII
|
||||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
|
||||||
$text = preg_replace('~[^\\w]+~', '-', $text);
|
// Convert to lowercase
|
||||||
$text = trim($text, '-');
|
$string = strtolower($string);
|
||||||
$text = preg_replace('~-~', '-', $text); // Simplified to just '-' as it's already trimmed
|
// Remove characters that are not letters, numbers, or hyphens
|
||||||
$text = strtolower($text);
|
$string = preg_replace('/[^a-z0-9_\-]+/', '-', $string);
|
||||||
return $text ?: 'n-a';
|
// Remove duplicate hyphens
|
||||||
|
$string = preg_replace('/-+/', '-', $string);
|
||||||
|
// Trim hyphens from the beginning and end
|
||||||
|
$string = trim($string, '-');
|
||||||
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
|
$error = null;
|
||||||
|
|
||||||
// Handle form submission (Create/Update)
|
// Handle form submission (Create/Update)
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$id = $_POST['id'] ?? null;
|
$id = $_POST['id'] ?? null;
|
||||||
$nome = $_POST['nome'] ?? '';
|
$nome = trim($_POST['nome'] ?? '');
|
||||||
$descricao = $_POST['descricao'] ?? '';
|
$descricao = trim($_POST['descricao'] ?? '');
|
||||||
$ativo = isset($_POST['ativo']) ? 1 : 0;
|
$ativo = isset($_POST['ativo']) ? 1 : 0;
|
||||||
|
$slug = generateSlug($nome);
|
||||||
|
|
||||||
if ($nome) { // Basic validation
|
// Basic validation
|
||||||
if ($id) {
|
if (empty($nome)) {
|
||||||
// Update
|
$error = "O campo Nome é obrigatório.";
|
||||||
$stmt = $pdo->prepare('UPDATE macro_areas SET nome = ?, descricao = ?, ativo = ? WHERE id = ?');
|
} else {
|
||||||
$stmt->execute([$nome, $descricao, $ativo, $id]);
|
// Check for duplicates
|
||||||
|
$stmt = $pdo->prepare('SELECT id FROM macro_areas WHERE (nome = ? OR slug = ?) AND id <> ?');
|
||||||
|
$stmt->execute([$nome, $slug, $id ?: 0]);
|
||||||
|
if ($stmt->fetch()) {
|
||||||
|
$error = "Já existe uma Macro Área com este nome.";
|
||||||
} else {
|
} else {
|
||||||
// Create
|
if ($id) {
|
||||||
$slug = slugify($nome);
|
// Update
|
||||||
$stmt = $pdo->prepare('INSERT INTO macro_areas (nome, descricao, slug, ativo, created_by) VALUES (?, ?, ?, ?, ?)');
|
$stmt = $pdo->prepare('UPDATE macro_areas SET nome = ?, slug = ?, descricao = ?, ativo = ? WHERE id = ?');
|
||||||
$stmt->execute([$nome, $descricao, $slug, $ativo, $_SESSION['user_email'] ?? 'system']);
|
$stmt->execute([$nome, $slug, $descricao, $ativo, $id]);
|
||||||
|
} else {
|
||||||
|
// Create
|
||||||
|
$stmt = $pdo->prepare('INSERT INTO macro_areas (nome, slug, descricao, ativo, user_id) VALUES (?, ?, ?, ?, ?)');
|
||||||
|
$stmt->execute([$nome, $slug, $descricao, $ativo, $_SESSION['user_id'] ?? 1]);
|
||||||
|
}
|
||||||
|
// Redirect to avoid form resubmission
|
||||||
|
header("Location: macro_areas.php");
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Redirect to avoid form resubmission
|
|
||||||
header("Location: macro_areas.php");
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle deletion
|
// Handle deletion
|
||||||
if (isset($_GET['delete'])) {
|
if (isset($_GET['delete'])) {
|
||||||
$id = $_GET['delete'];
|
$id = $_GET['delete'];
|
||||||
|
// It's a good practice to check for dependencies before deleting
|
||||||
$stmt = $pdo->prepare('DELETE FROM macro_areas WHERE id = ?');
|
$stmt = $pdo->prepare('DELETE FROM macro_areas WHERE id = ?');
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
header("Location: macro_areas.php");
|
header("Location: macro_areas.php");
|
||||||
@ -72,6 +89,15 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||||
|
<?php echo $error; ?>
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<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">Registros</h6>
|
<h6 class="m-0 font-weight-bold">Registros</h6>
|
||||||
@ -89,7 +115,6 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</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';
|
$badgeClass = $area['ativo'] ? 'badge-status-ativo' : 'badge-status-arquivado';
|
||||||
$statusText = $area['ativo'] ? 'Ativo' : 'Arquivado';
|
$statusText = $area['ativo'] ? 'Ativo' : 'Arquivado';
|
||||||
?>
|
?>
|
||||||
@ -104,7 +129,9 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
data-id="<?php echo $area['id']; ?>"
|
data-id="<?php echo $area['id']; ?>"
|
||||||
data-nome="<?php echo htmlspecialchars($area['nome']); ?>"
|
data-nome="<?php echo htmlspecialchars($area['nome']); ?>"
|
||||||
data-descricao="<?php echo htmlspecialchars($area['descricao']); ?>"
|
data-descricao="<?php echo htmlspecialchars($area['descricao']); ?>"
|
||||||
data-ativo="<?php echo $area['ativo']; ?>">
|
data-ativo="<?php echo $area['ativo']; ?>"
|
||||||
|
data-toggle="modal"
|
||||||
|
data-target="#macroAreaModal">
|
||||||
<i class="fas fa-edit"></i>
|
<i class="fas fa-edit"></i>
|
||||||
</button>
|
</button>
|
||||||
<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?');">
|
<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?');">
|
||||||
@ -113,9 +140,7 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</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>
|
||||||
@ -141,14 +166,14 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<input type="hidden" name="id" id="macroAreaId">
|
<input type="hidden" name="id" id="macroAreaId">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="macroAreaNome">Nome</label>
|
<label for="macroAreaNome">Nome *</label>
|
||||||
<input type="text" class="form-control" id="macroAreaNome" name="nome" required>
|
<input type="text" class="form-control" id="macroAreaNome" name="nome" placeholder="Ex: Moradia, Alimentação, Saúde" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="macroAreaDescricao">Descrição</label>
|
<label for="macroAreaDescricao">Descrição</label>
|
||||||
<textarea class="form-control" id="macroAreaDescricao" name="descricao" rows="3"></textarea>
|
<textarea class="form-control" id="macroAreaDescricao" name="descricao" rows="3" placeholder="Descrição opcional da macro área"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group form-check">
|
<div class="form-group form-check form-switch">
|
||||||
<input type="checkbox" class="form-check-input" id="macroAreaAtivo" name="ativo" value="1" checked>
|
<input type="checkbox" class="form-check-input" id="macroAreaAtivo" name="ativo" value="1" checked>
|
||||||
<label class="form-check-label" for="macroAreaAtivo">Ativo</label>
|
<label class="form-check-label" for="macroAreaAtivo">Ativo</label>
|
||||||
</div>
|
</div>
|
||||||
@ -166,15 +191,20 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
// Handle modal for "Nova Macro Área"
|
|
||||||
$('#macroAreaModal').on('show.bs.modal', function (event) {
|
$('#macroAreaModal').on('show.bs.modal', function (event) {
|
||||||
var button = $(event.relatedTarget); // Button that triggered the modal
|
var button = $(event.relatedTarget);
|
||||||
var modal = $(this);
|
var modal = $(this);
|
||||||
|
|
||||||
// If button is the "edit" button, it will have data attributes
|
|
||||||
var id = button.data('id');
|
var id = button.data('id');
|
||||||
|
|
||||||
|
// Reset form for new entry
|
||||||
|
modal.find('.modal-title').text('Nova Macro Área');
|
||||||
|
modal.find('#macroAreaForm')[0].reset();
|
||||||
|
modal.find('#macroAreaId').val('');
|
||||||
|
modal.find('#macroAreaAtivo').prop('checked', true); // Default to active
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
// Editing an existing record
|
// If editing, populate form
|
||||||
var nome = button.data('nome');
|
var nome = button.data('nome');
|
||||||
var descricao = button.data('descricao');
|
var descricao = button.data('descricao');
|
||||||
var ativo = button.data('ativo');
|
var ativo = button.data('ativo');
|
||||||
@ -183,18 +213,26 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
modal.find('#macroAreaId').val(id);
|
modal.find('#macroAreaId').val(id);
|
||||||
modal.find('#macroAreaNome').val(nome);
|
modal.find('#macroAreaNome').val(nome);
|
||||||
modal.find('#macroAreaDescricao').val(descricao);
|
modal.find('#macroAreaDescricao').val(descricao);
|
||||||
if (ativo == 1) {
|
modal.find('#macroAreaAtivo').prop('checked', 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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If there was a server-side error, show the modal again
|
||||||
|
<?php if ($error): ?>
|
||||||
|
$('#macroAreaModal').modal('show');
|
||||||
|
<?php endif; ?>
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Custom styles for action buttons to ensure they are circular */
|
||||||
|
.btn-circle {
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
padding: 6px 0;
|
||||||
|
border-radius: 15px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.42857;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user