dashboard.php
2.96 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
<?php
declare(strict_types=1);
require __DIR__ . '/../src/bootstrap.php';
Auth::requireLogin();
$erro = null;
$ok = null;
try {
$ldap = new Ldap();
$ldap->bindService();
$groupFilter = SettingsRepository::get('group_aluno_filter', 'cn=grpCI-Aluno-Info');
$logins = $ldap->groupMembers($groupFilter);
$alunos = [];
foreach ($logins as $cn) {
$entry = $ldap->findUserByCn($cn);
if ($entry === null) {
continue;
}
$accountControl = (int) ($entry['useraccountcontrol'][0] ?? 0);
$alunos[] = [
'cn' => $cn,
'nome' => $entry['displayname'][0] ?? $entry['cn'][0] ?? $cn,
'habilitado' => ($accountControl & 2) !== 2,
'descricao' => $entry['description'][0] ?? '',
];
}
} catch (Throwable $e) {
$erro = 'Não foi possível consultar o AD agora: ' . $e->getMessage();
$alunos = [];
}
if (($_GET['ok'] ?? '') === '1') {
$ok = 'Ação realizada com sucesso.';
} elseif (($_GET['erro'] ?? '') === '1') {
$erro = $_GET['msg'] ?? 'Ocorreu um erro ao processar a ação.';
}
View::header('Alunos');
?>
<div class="card">
<h1>Alunos do grupo</h1>
<?php if ($erro): ?>
<div class="alert error"><?= View::escape($erro) ?></div>
<?php endif; ?>
<?php if ($ok): ?>
<div class="alert success"><?= View::escape($ok) ?></div>
<?php endif; ?>
<table>
<tr>
<th>Aluno</th>
<th>Status</th>
<th>Última alteração por</th>
<th>Ações</th>
</tr>
<?php foreach ($alunos as $aluno): ?>
<tr>
<td data-label="Aluno"><?= View::escape($aluno['nome']) ?></td>
<td data-label="Status">
<?php if ($aluno['habilitado']): ?>
<span class="badge ok">Habilitado</span>
<?php else: ?>
<span class="badge off">Desabilitado</span>
<?php endif; ?>
</td>
<td data-label="Última alteração por"><?= View::escape($aluno['descricao']) ?></td>
<td data-label="Ações">
<form method="post" action="action_status" style="display:inline">
<input type="hidden" name="user" value="<?= View::escape($aluno['cn']) ?>">
<input type="hidden" name="enable" value="<?= $aluno['habilitado'] ? '0' : '1' ?>">
<button type="submit" class="<?= $aluno['habilitado'] ? 'danger' : '' ?>">
<?= $aluno['habilitado'] ? 'Desabilitar' : 'Habilitar' ?>
</button>
</form>
<a class="btn secondary" href="newpasswd?user=<?= urlencode($aluno['cn']) ?>">Nova senha</a>
</td>
</tr>
<?php endforeach; ?>
<?php if (!$alunos && !$erro): ?>
<tr><td colspan="4">Nenhum aluno encontrado no grupo.</td></tr>
<?php endif; ?>
</table>
</div>
<?php
View::footer();