Versão inicial em produção
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
$titulo_pagina = 'Páginas';
|
||||
$pagina_ativa = 'paginas_admin';
|
||||
|
||||
require_once __DIR__ . '/includes/config.php';
|
||||
require_once __DIR__ . '/includes/db.php';
|
||||
require_once __DIR__ . '/includes/auth.php';
|
||||
|
||||
ao_exigir_acesso_total();
|
||||
|
||||
$erro = null;
|
||||
$sucesso = null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['acao'] ?? '') === 'excluir') {
|
||||
$id = (int) ($_POST['id'] ?? 0);
|
||||
$pdo->prepare('DELETE FROM paginas WHERE id = ?')->execute([$id]);
|
||||
header('Location: paginas_admin.php?excluido=1');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['acao'] ?? '') === 'salvar') {
|
||||
$id = (int) ($_POST['id'] ?? 0);
|
||||
$chave = strtolower(trim($_POST['chave'] ?? ''));
|
||||
$nome = trim($_POST['nome'] ?? '');
|
||||
$arquivo = trim($_POST['arquivo'] ?? '');
|
||||
$ordem = (int) ($_POST['ordem'] ?? 0);
|
||||
$ativo = isset($_POST['ativo']) ? 1 : 0;
|
||||
|
||||
if ($chave === '' || $nome === '' || $arquivo === '') {
|
||||
$erro = 'Preencha chave, nome e arquivo.';
|
||||
} elseif (!preg_match('/^[a-z0-9_]+$/', $chave)) {
|
||||
$erro = 'A chave só pode ter letras minúsculas, números e sublinhado (ex: relatorios_mensais).';
|
||||
} elseif (array_key_exists($chave, AO_PAGINAS_ADMIN)) {
|
||||
$erro = 'Essa chave é reservada para as páginas de administração do próprio sistema.';
|
||||
} else {
|
||||
try {
|
||||
if ($id > 0) {
|
||||
$stmt = $pdo->prepare('UPDATE paginas SET chave=?, nome=?, arquivo=?, ordem=?, ativo=? WHERE id=?');
|
||||
$stmt->execute([$chave, $nome, $arquivo, $ordem, $ativo, $id]);
|
||||
} else {
|
||||
$stmt = $pdo->prepare('INSERT INTO paginas (chave, nome, arquivo, ordem, ativo) VALUES (?,?,?,?,?)');
|
||||
$stmt->execute([$chave, $nome, $arquivo, $ordem, $ativo]);
|
||||
}
|
||||
header('Location: paginas_admin.php?salvo=1');
|
||||
exit;
|
||||
} catch (PDOException $e) {
|
||||
$erro = ($e->getCode() === '23000') ? 'Já existe uma página com esta chave.' : ('Erro ao salvar: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$editando = null;
|
||||
if (isset($_GET['editar'])) {
|
||||
$stmt = $pdo->prepare('SELECT * FROM paginas WHERE id = ?');
|
||||
$stmt->execute([(int) $_GET['editar']]);
|
||||
$editando = $stmt->fetch() ?: null;
|
||||
}
|
||||
|
||||
if (isset($_GET['salvo'])) $sucesso = 'Página salva com sucesso.';
|
||||
if (isset($_GET['excluido'])) $sucesso = 'Página excluída.';
|
||||
|
||||
$paginas = $pdo->query('SELECT * FROM paginas ORDER BY ordem, nome')->fetchAll();
|
||||
|
||||
require __DIR__ . '/includes/header.php';
|
||||
?>
|
||||
|
||||
<h1 class="ao-page-title">Páginas do sistema</h1>
|
||||
<p style="color: var(--ao-text-muted); font-size: var(--ao-fs-sm); max-width: 640px; margin-top: -8px;">
|
||||
Esta é a lista de páginas de negócio que podem ser liberadas por perfil, em <a href="perfis.php">Perfis</a>.
|
||||
Ao cadastrar uma página nova aqui, crie também o arquivo <code>.php</code> correspondente no projeto,
|
||||
usando a mesma chave na variável <code>$pagina_ativa</code>.
|
||||
</p>
|
||||
|
||||
<?php if ($erro): ?>
|
||||
<div class="ao-badge ao-badge-baixa" style="display:block; margin-bottom: var(--ao-space-4); padding: 10px 14px; font-size: var(--ao-fs-sm);"><?= htmlspecialchars($erro) ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($sucesso): ?>
|
||||
<div class="ao-badge ao-badge-alta" style="display:block; margin-bottom: var(--ao-space-4); padding: 10px 14px; font-size: var(--ao-fs-sm);"><?= htmlspecialchars($sucesso) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="ao-card" style="max-width: 600px; margin-bottom: var(--ao-space-6);">
|
||||
<div class="ao-card-header"><strong><?= $editando ? 'Editar página' : 'Nova página' ?></strong></div>
|
||||
<form method="post" action="paginas_admin.php">
|
||||
<input type="hidden" name="acao" value="salvar">
|
||||
<input type="hidden" name="id" value="<?= (int) ($editando['id'] ?? 0) ?>">
|
||||
<div class="ao-row" style="gap: var(--ao-space-4); margin-bottom: var(--ao-space-4);">
|
||||
<div class="ao-field" style="flex: 1;">
|
||||
<label for="chave">Chave (interna)</label>
|
||||
<input type="text" id="chave" name="chave" placeholder="ex: relatorios" required value="<?= htmlspecialchars($editando['chave'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="ao-field" style="flex: 1;">
|
||||
<label for="nome">Nome no menu</label>
|
||||
<input type="text" id="nome" name="nome" placeholder="ex: Relatórios" required value="<?= htmlspecialchars($editando['nome'] ?? '') ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="ao-row" style="gap: var(--ao-space-4); margin-bottom: var(--ao-space-5); align-items: flex-end;">
|
||||
<div class="ao-field" style="flex: 1;">
|
||||
<label for="arquivo">Arquivo .php</label>
|
||||
<input type="text" id="arquivo" name="arquivo" placeholder="ex: relatorios.php" required value="<?= htmlspecialchars($editando['arquivo'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="ao-field" style="width: 100px;">
|
||||
<label for="ordem">Ordem</label>
|
||||
<input type="number" id="ordem" name="ordem" value="<?= (int) ($editando['ordem'] ?? 0) ?>">
|
||||
</div>
|
||||
<label style="display:flex; align-items:center; gap:6px; font-size: var(--ao-fs-sm); padding-bottom: 10px;">
|
||||
<input type="checkbox" name="ativo" <?= (!$editando || $editando['ativo']) ? 'checked' : '' ?>> Ativa
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" class="ao-btn ao-btn-primary"><?= $editando ? 'Salvar alterações' : 'Cadastrar página' ?></button>
|
||||
<?php if ($editando): ?>
|
||||
<a href="paginas_admin.php" class="ao-btn ao-btn-secondary">Cancelar</a>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="ao-card">
|
||||
<div class="ao-card-header"><strong>Páginas cadastradas</strong></div>
|
||||
<table class="ao-table">
|
||||
<thead>
|
||||
<tr><th>Ordem</th><th>Nome</th><th>Chave</th><th>Arquivo</th><th>Status</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($paginas as $p): ?>
|
||||
<tr>
|
||||
<td class="ao-numeric"><?= (int) $p['ordem'] ?></td>
|
||||
<td><?= htmlspecialchars($p['nome']) ?></td>
|
||||
<td class="ao-numeric"><?= htmlspecialchars($p['chave']) ?></td>
|
||||
<td class="ao-numeric"><?= htmlspecialchars($p['arquivo']) ?></td>
|
||||
<td><span class="ao-badge <?= $p['ativo'] ? 'ao-badge-alta' : 'ao-badge-neutro' ?>"><?= $p['ativo'] ? 'Ativa' : 'Inativa' ?></span></td>
|
||||
<td style="white-space: nowrap; text-align: right;">
|
||||
<a href="paginas_admin.php?editar=<?= $p['id'] ?>" class="ao-btn ao-btn-secondary" style="padding: 4px 10px; font-size: var(--ao-fs-xs);">Editar</a>
|
||||
<form method="post" action="paginas_admin.php" style="display:inline;" onsubmit="return confirm('Excluir esta página? Os perfis vinculados a ela perdem essa permissão.');">
|
||||
<input type="hidden" name="acao" value="excluir">
|
||||
<input type="hidden" name="id" value="<?= $p['id'] ?>">
|
||||
<button type="submit" class="ao-btn ao-btn-secondary" style="padding: 4px 10px; font-size: var(--ao-fs-xs);">Excluir</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php require __DIR__ . '/includes/footer.php'; ?>
|
||||
Reference in New Issue
Block a user