Files
PHP-LDAP/view/View.php
2025-03-26 20:48:39 +01:00

76 lines
2.1 KiB
PHP

<?php
$admin_account = "Administrateur";
function PrintListFirsts(string $title, array $liste): string
{
$result = '<div class="list-group-item"><h5>' . $title . '</h5>';
$result .= '<div class="list-group ">';
foreach ($liste as $element) {
$result .= '<div class="list-group-item">' . $element[0] . "</div>";
}
$result .= "</div></div>";
return $result;
}
function PrintLoginInfo($info)
{
global $admin_account;
$body = '<h2 class="text-center pt-3">Bienvenue ' . $info->fullName . " !</h2>";
if ($info->fullName == $admin_account) {
return $body .= PrintAdminInterface();
}
$body .= '<div class="list-group ">';
foreach ($info->ous as $ou) {
$body .= '<div class="list-group-item"><h3>' . $ou . "</h3>";
$body .= '<div class="list-group">';
$body .= PrintListFirsts("Utilisateurs", LdapGetUsersInOU($ou));
$body .= PrintListFirsts("Groupes", LdapGetGroupsInOU($ou));
$body .= "</div>";
$body .= "</div>";
}
$body .= "</div>";
return $body;
}
function translateSuccess(string $success) {
return $success == "success" ? "Succès" : "Échec";
}
function PrintAdminInterface(): string
{
$auth_attempts = GetLines();
$body = '<h5 class="text-center">Historique des connexions</h5>';
$body .= '<table id="attempts" class="table table-striped table-bordered">
<thead class="thead-light">
<tr>
<th scope="col">Utilisateur</th>
<th scope="col">Status</th>
<th scope="col">Date</th>
<th scope="col">Adresse IP</th>
</tr>
</thead>';
foreach ($auth_attempts as $attempt) {
$body .= '<tr>';
$body .= '<td>' . $attempt->username . '</td>';
$body .= '<td>' . translateSuccess($attempt->status) . '</td>';
$body .= '<td>' . $attempt->timestamp . '</td>';
$body .= '<td>' . $attempt->ip_address . '</td>';
$body .= '</tr>';
}
$body .= "</table>";
$body .= '
<script src="/js/datatables.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
let table = new DataTable("#attempts", {
language: {
url: "/lang/fr.json",
},
});
});
</script>
';
return $body;
}