-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
288 lines (267 loc) · 9.87 KB
/
admin.php
File metadata and controls
288 lines (267 loc) · 9.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
require_once dirname(__FILE__) . "/auth_admin.php";
require_once dirname(__FILE__) . "/funcoes_cliente.php";
if (!verificarSuperAdmin()) {
$returnUrl = urlencode($_SERVER["REQUEST_URI"]);
header("Location: admin_login.php?return=" . $returnUrl);
exit();
}
$mensagem = "";
$tipoMensagem = "";
// Lógica para atualizar senha do admin
if (isset($_POST["action"]) && $_POST["action"] === "atualizar_senha_admin") {
$novaSenha = $_POST["nova_senha"] ?? "";
$confirmarSenha = $_POST["confirmar_senha"] ?? "";
if (empty($novaSenha) || empty($confirmarSenha)) {
$mensagem = "Por favor, preencha todos os campos de senha.";
$tipoMensagem = "erro";
} elseif ($novaSenha !== $confirmarSenha) {
$mensagem = "As senhas não coincidem.";
$tipoMensagem = "erro";
} else {
if (atualizarSenhaSuperAdmin($novaSenha)) {
$mensagem = "Senha do Super Admin atualizada com sucesso!";
$tipoMensagem = "sucesso";
} else {
$mensagem = "Erro ao atualizar a senha do Super Admin.";
$tipoMensagem = "erro";
}
}
}
// Lógica para editar cliente
if (isset($_POST["action"]) && $_POST["action"] === "editar_cliente") {
$emailCliente = $_POST["email_cliente"] ?? "";
$limiteEventos = $_POST["limite_eventos"] ?? null;
$statusCliente = $_POST["status_cliente"] ?? "";
if (empty($emailCliente)) {
$mensagem = "E-mail do cliente não fornecido.";
$tipoMensagem = "erro";
} else {
$dadosAtualizacao = [];
if ($limiteEventos !== null) {
$dadosAtualizacao["limite_eventos_mensal"] = intval($limiteEventos);
}
if (!empty($statusCliente)) {
$dadosAtualizacao["status"] = $statusCliente;
}
if (!empty($dadosAtualizacao)) {
if (atualizarCliente($emailCliente, $dadosAtualizacao)) {
$mensagem = "Dados do cliente atualizados com sucesso!";
$tipoMensagem = "sucesso";
} else {
$mensagem = "Erro ao atualizar dados do cliente ou cliente não encontrado.";
$tipoMensagem = "erro";
}
} else {
$mensagem = "Nenhum dado para atualizar.";
$tipoMensagem = "aviso";
}
}
}
// Lógica para buscar cliente para edição
$clienteParaEditar = null;
if (isset($_GET["editar_email"]) && !empty($_GET["editar_email"])) {
$clienteParaEditar = obterClientePorEmail($_GET["editar_email"]);
if (!$clienteParaEditar) {
$mensagem = "Cliente não encontrado para edição.";
$tipoMensagem = "erro";
}
}
$todosClientes = obterTodosClientes();
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin - Sistema de Eventos</title>
<link rel="stylesheet" href="styles.css">
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f4f7f6;
margin: 0;
padding: 20px;
color: #333;
}
.container {
max-width: 900px;
margin: 20px auto;
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1, h2 {
color: #0056b3;
text-align: center;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.btn {
background-color: #007bff;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
width: 100%;
box-sizing: border-box;
}
.btn:hover {
background-color: #0056b3;
}
.alerta {
padding: 10px;
margin-bottom: 15px;
border-radius: 4px;
text-align: center;
}
.alerta.sucesso {
background-color: #d4edda;
color: #155724;
border-color: #c3e6cb;
}
.alerta.erro {
background-color: #f8d7da;
color: #721c24;
border-color: #f5c6cb;
}
.alerta.aviso {
background-color: #fff3cd;
color: #856404;
border-color: #ffeeba;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.logout-btn {
display: block;
width: 100%;
text-align: center;
margin-top: 20px;
padding: 10px;
background-color: #dc3545;
color: white;
border-radius: 4px;
text-decoration: none;
}
.logout-btn:hover {
background-color: #c82333;
}
</style>
</head>
<body>
<div class="container">
<h1>Painel de Administração</h1>
<?php if (!empty($mensagem)): ?>
<div class="alerta <?php echo $tipoMensagem; ?>">
<?php echo htmlspecialchars($mensagem); ?>
</div>
<?php endif; ?>
<h2>Atualizar Senha do Super Admin</h2>
<form action="admin.php" method="POST">
<input type="hidden" name="action" value="atualizar_senha_admin">
<div class="form-group">
<label for="nova_senha">Nova Senha:</label>
<input type="password" id="nova_senha" name="nova_senha" required>
</div>
<div class="form-group">
<label for="confirmar_senha">Confirmar Nova Senha:</label>
<input type="password" id="confirmar_senha" name="confirmar_senha" required>
</div>
<button type="submit" class="btn">Atualizar Senha</button>
</form>
<h2 style="margin-top: 40px;">Gerenciar Clientes</h2>
<?php if ($clienteParaEditar): ?>
<h3>Editar Cliente: <?php echo htmlspecialchars($clienteParaEditar["email"]); ?></h3>
<form action="admin.php" method="POST">
<input type="hidden" name="action" value="editar_cliente">
<input type="hidden" name="email_cliente" value="<?php echo htmlspecialchars($clienteParaEditar["email"]); ?>">
<div class="form-group">
<label for="limite_eventos">Limite de Eventos Mensal:</label>
<input type="number" id="limite_eventos" name="limite_eventos" value="<?php echo htmlspecialchars($clienteParaEditar["limite_eventos_mensal"] ?? ""); ?>" min="0">
</div>
<div class="form-group">
<label for="status_cliente">Status:</label>
<select id="status_cliente" name="status_cliente">
<option value="ativo" <?php echo ($clienteParaEditar["status"] ?? "") === "ativo" ? "selected" : ""; ?>>Ativo</option>
<option value="inativo" <?php echo ($clienteParaEditar["status"] ?? "") === "inativo" ? "selected" : ""; ?>>Inativo</option>
<option value="suspenso" <?php echo ($clienteParaEditar["status"] ?? "") === "suspenso" ? "selected" : ""; ?>>Suspenso</option>
</select>
</div>
<button type="submit" class="btn">Salvar Alterações</button>
<a href="admin.php" class="btn btn-secondary" style="margin-top: 10px;">Cancelar Edição</a>
</form>
<hr style="margin: 30px 0;">
<?php endif; ?>
<h3>Lista de Clientes</h3>
<table>
<thead>
<tr>
<th>E-mail</th>
<th>Limite Mensal</th>
<th>Criados Mês Atual</th>
<th>Status</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<?php if (!empty($todosClientes)): ?>
<?php foreach ($todosClientes as $clienteItem): ?>
<tr>
<td><?php echo htmlspecialchars($clienteItem["email"]); ?></td>
<td><?php echo htmlspecialchars($clienteItem["limite_eventos_mensal"] ?? "N/A"); ?></td>
<td><?php echo htmlspecialchars($clienteItem["eventos_criados_mes_atual"] ?? "N/A"); ?></td>
<td><?php echo htmlspecialchars($clienteItem["status"] ?? "N/A"); ?></td>
<td>
<a href="admin.php?editar_email=<?php echo urlencode($clienteItem["email"]); ?>" class="btn" style="width: auto; padding: 5px 10px;">Editar</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="5">Nenhum cliente cadastrado.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<a href="admin_logout.php" class="logout-btn">Sair do Admin</a>
</div>
</body>
</html>