diff --git a/assets/css/custom.css b/assets/css/custom.css index 0cd1f11..2f5b65f 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -360,4 +360,98 @@ body { /* Action Icons */ .table .btn .fas { color: #4C5958; -} \ No newline at end of file +} + +/* + * 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; +} diff --git a/macro_areas.php b/macro_areas.php index 73d701f..6a5a3cb 100644 --- a/macro_areas.php +++ b/macro_areas.php @@ -3,46 +3,63 @@ require_once 'includes/session.php'; require_once 'db/config.php'; include_once 'includes/header.php'; -// 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'; +// Helper function to generate a slug from a string +function generateSlug($string) { + // Normalize to ASCII + $string = iconv('UTF-8', 'ASCII//TRANSLIT', $string); + // Convert to lowercase + $string = strtolower($string); + // Remove characters that are not letters, numbers, or hyphens + $string = preg_replace('/[^a-z0-9_\-]+/', '-', $string); + // Remove duplicate hyphens + $string = preg_replace('/-+/', '-', $string); + // Trim hyphens from the beginning and end + $string = trim($string, '-'); + return $string; } + $pdo = db(); +$error = null; // Handle form submission (Create/Update) if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = $_POST['id'] ?? null; - $nome = $_POST['nome'] ?? ''; - $descricao = $_POST['descricao'] ?? ''; + $nome = trim($_POST['nome'] ?? ''); + $descricao = trim($_POST['descricao'] ?? ''); $ativo = isset($_POST['ativo']) ? 1 : 0; + $slug = generateSlug($nome); - 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]); + // Basic validation + if (empty($nome)) { + $error = "O campo Nome é obrigatório."; + } else { + // 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 { - // 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']); + if ($id) { + // Update + $stmt = $pdo->prepare('UPDATE macro_areas SET nome = ?, slug = ?, descricao = ?, ativo = ? WHERE id = ?'); + $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 if (isset($_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->execute([$id]); header("Location: macro_areas.php"); @@ -72,6 +89,15 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC); + + + +
Registros
@@ -89,7 +115,6 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -100,11 +125,13 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC); - @@ -113,9 +140,7 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC); - + Nenhuma macro área encontrada. @@ -141,14 +166,14 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);