| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- <?php
- if (core::ifGet("add") and access::ifAccesss("add-user")) {
- $id_form = '<input type="hidden" name="id" value="add">';
- $submit = "Ajouter un profil";
- $titre = "Ajouter un profil";
- $protect = 0;
- } else {
- if (core::ifGet("id") == FALSE or (core::ifGet("id") and session::getId() == core::getGet("id"))) {
- $user = user::getUser(session::getId());
- $submit = "Modifier votre profil";
- $titre = "Votre fiche de profil";
- $protect = 1;
- if (debug::isFile("debug")) {
- debug::log($user, "Données brutes user");
- }
- } else {
- if (access::ifAccesss("add-user")) {
- $user = user::getUser(core::getGet("id"));
- if (is_array($user)) {
- $submit = "Modifier ce profil";
- $titre = "Fiche de " . $user["prenom"] . " " . $user["nom"];
- if ($user["deleted"] == 1) {
- $titre .= " (Supprimée)";
- $protect = 2;
- } else {
- $protect = 0;
- }
- } else {
- get::page("unknow");
- exit();
- }
- } else {
- get::page("unknow");
- exit();
- }
- }
- $id_form = '<input type="hidden" name="id" value="' . $user["id"] . '">';
- }
- ?>
- <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light row">
- <div class="col-11">
- <h2 class="bd-title" id="content">
- <span><?= $titre ?></span>
- </h2>
- <?php if (isset($user["id"]) && session::getId() != $user["id"] && $protect != 2): ?>
- <div class="fix-container-button-nav">
- <a href="/submit.php?from=parametres-user-delete&id=<?= $user['id']; ?>" onclick="return confirm('Voulez-vous supprimer le compte de <?= $user["prenom"] . " " . $user["nom"]; ?> ?')">
- <button type="submit" class="btn btn-outline-danger btn-sm"><?= icon::getFont(["icon" => "bi-trash-fill"]); ?> Supprimer</button>
- </a>
- </div>
- <?php elseif ($protect == 2): ?>
- <div class="fix-container-button-nav">
- <a href="/submit.php?from=parametres-user-restore&id=<?= $user['id']; ?>" onclick="return confirm('Voulez-vous restaurer le compte de <?= $user["prenom"] . " " . $user["nom"]; ?> ?')">
- <button type="submit" class="btn btn-outline-danger btn-sm"><?= icon::getFont(["icon" => "bi bi-box2-fill"]); ?> Restaurer</button>
- </a>
- </div>
- <?php endif; ?>
- </div>
- </header>
- <?php
- if (core::getGet("id")) {
- echo core::filAriane(array(
- "current" => $titre,
- "arbo" => array(
- "Administration" => NULL,
- "Utilisateurs" => "/parametres-users.html",
- $titre => "#"
- )
- ));
- }
- ?>
- <?php if (isset($user["last_connect"])): ?>
- <?php callout::print([
- "type" => "info",
- "size" => "tiny",
- "style" => "margin:-5px 0;",
- "p" => "Dernière connexion le " . core::convertDate($user["last_connect"]),
- ]); ?>
- <?php endif; ?>
- <br />
- <?php if ($protect != 2): ?>
- <form id="form-user" method="post" action="/submit.php" oninput='password2.setCustomValidity(password2.value != password.value ? "Les mots de passe ne sont pas identiques" : "")' onsubmit="return(false);">
- <input type="hidden" name="from" value="user">
- <?php
- echo $id_form;
- endif;
- ?>
- <div class="form-group">
- <label>Type de compte</label>
- <?php
- $id_type = [
- 2 => "Contrôleur QRCode (émargement)",
- 3 => "Assistance sociale",
- 4 => "Modérateur du CMS",
- 5 => "Membre du Bureau du CSE",
- 6 => "Elu du CSE",
- 7 => "Comptable",
- 1 => "Administrateur"
- ];
- ?>
- <?php if ($protect == 0): ?>
- <?php
- html::printSelect('name="id_type" class="form-select"', $id_type, @$user["id_type"]);
- ?>
- <?php endif; ?>
- <?php if ($protect == 1 or $protect == 2): ?>
- <?php
- html::printSelect('class="form-control" disabled', $id_type, @$user["id_type"]);
- html::printInput('type="hidden" name="id_type"', $user["id_type"]);
- ?>
- <?php endif; ?>
- </div>
- <br />
- <?php
- if (access::ifAccesss("add-user") and core::ifGet("id") and (isset($user["deleted"]) and $user["deleted"] == 0)) { ?>
- <div class="form-group">
- <label>Rôles aditionnels</label>
- <?= html::printInput('type="text" name="tags" id="tags"', @$user["tags"]) ?>
- </div>
- <br />
- <?php
- } elseif (isset($user["tags"])) { ?>
- <div class="form-group">
- <label>Rôles aditionnels</label>
- <?= html::printInput('type="text" class="form-control" name="tags" readonly="readonly"', @$user["tags"]) ?>
- </div>
- <br />
- <?php
- } else {
- html::printInput('type="hidden" name="tags"');
- }
- ?>
- <div class="form-group">
- <label>Prénom</label>
- <?php
- $confPrenom = 'type="text" name="prenom" class="form-control" ';
- $confPrenom .= $protect == 2 ? 'readonly="readonly"' : 'required';
- html::printInput($confPrenom, @$user["prenom"]);
- ?>
- </div>
- <br />
- <div class="form-group">
- <label>nom</label>
- <?php
- $confNom = 'type="text" name="nom" class="form-control" ';
- $confNom .= $protect == 2 ? 'readonly="readonly"' : 'required';
- html::printInput($confNom, @$user["nom"]);
- ?>
- </div>
- <br />
- <div class="form-group">
- <label>Email</label>
- <?php
- $confEmail = 'type="text" name="email" class="form-control" ';
- $confEmail .= $protect == 2 ? 'readonly="readonly"' : 'required';
- html::printInput($confEmail, @$user["email"]);
- ?>
- </div>
- <br />
- <?php if ($protect != 2): ?>
- <div class="form-group">
- <label>Mot de passe</label>
- <?php
- $confPassword = 'type="password" class="form-control" minlength="8" maxlength="25" name="password" ';
- $confPassword .= core::ifGet("add") ? 'required"' : NULL;
- html::printInput($confPassword);
- ?>
- </div>
- <br />
- <div class="form-group">
- <label>Confirmation du mot de passe</label>
- <?php
- $confPassword2 = 'type="password" class="form-control" minlength="8" maxlength="25" name="password2" ';
- $confPassword2 .= core::ifGet("add") ? 'required"' : NULL;
- html::printInput($confPassword2);
- ?>
- </div>
- <br />
- <div class="form-group">
- <label>Google Authenticator</label>
- <?php
- $googleAuthenticator = [
- 0 => "Désactivé",
- 1 => "Activé",
- ];
- // Vérifier si le 2FA est en attente de validation
- $is2FAPending = isset($user["id"]) ? user::is2FAPending($user["id"]) : false;
- $is2FAActive = isset($user["googleAuthenticator"]) && $user["googleAuthenticator"] == 1;
- if ($is2FAPending) {
- // Afficher "En attente de validation" quand le 2FA est pending
- echo '<div class="alert alert-warning"><i class="bi bi-hourglass-split"></i> En attente de validation du code</div>';
- html::printInput('type="hidden" name="googleAuthenticator" value="0"');
- } else {
- $bgStyle = $is2FAActive ? 'background-color: #d4edda; color: #155724;' : 'background-color: #f8d7da; color: #721c24;';
- $iconClass = $is2FAActive ? 'bi-shield-check' : 'bi-shield-x';
- ?>
- <div class="input-group">
- <span class="input-group-text" style="<?= $bgStyle ?>">
- <i class="bi <?= $iconClass ?>"></i>
- </span>
- <?php html::printSelect('name="googleAuthenticator" class="form-select" style="' . $bgStyle . '"', $googleAuthenticator, @$user["googleAuthenticator"]); ?>
- </div>
- <?php
- }
- ?>
- </div>
- <br />
- <?php endif; ?>
- <?php if ($protect == 0): ?>
- <div class="form-group">
- <label>Etat du compte</label>
- <?php
- $actif = [
- 0 => "Compte désactivé",
- 1 => "Compte activé",
- ];
- html::printSelect('name="actif" class="form-select"', $actif, @$user["actif"]);
- ?>
- </div>
- <br />
- <?php endif; ?>
- <?php if ($protect == 1): ?>
- <?= html::printInput('type="hidden" name="actif"', $user["actif"]); ?>
- <?php endif; ?>
- <?php if ((isset($user["deleted"]) and $user["deleted"] == 0) or core::ifGet("add")) : ?>
- <input class="btn btn-primary btn-lg" style="width: 100%; margin-bottom:20px;" type="button" value="<?php echo $submit ?>" onclick="validateAndSubmit()">
- <?php endif; ?>
- </form>
- <?php
- // Modal pour activer le 2FA si en attente de validation (pending)
- if (isset($user["id"]) and user::is2FAPending($user["id"]) and $protect == 1): ?>
- <style>
- .qrcode-container img {
- max-width: 100%;
- height: auto;
- display: block;
- margin: 0 auto;
- }
- #modal2FA .modal-content {
- border-radius: 15px;
- }
- #modal2FA .modal-header {
- border-radius: 15px 15px 0 0;
- }
- </style>
- <!-- Modal 2FA -->
- <div class="modal fade" id="modal2FA" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="modal2FALabel" aria-hidden="true">
- <div class="modal-dialog modal-dialog-centered">
- <div class="modal-content">
- <div class="modal-header bg-warning text-dark">
- <h5 class="modal-title" id="modal2FALabel">
- <i class="bi bi-shield-lock"></i> Activation de la double authentification
- </h5>
- </div>
- <div class="modal-body text-center">
- <div class="qrcode-container" style="max-width: 250px; margin: 0 auto;">
- <?php
- $qrCodeUrl = googleAuthenticator::getGoogleUrl("CMS CSE Invent: " . ENVIRONNEMENT, user::getMyGoogleAuthenticator(session::getId()));
- myQrcode::printQRCode($qrCodeUrl);
- ?>
- </div>
- <p class="mt-3 mb-2">
- <small>1. Scannez ce QR code avec votre application Google Authenticator</small><br>
- <small>2. Entrez le code à 6 chiffres généré par l'application</small>
- </p>
- <form method="post" action="/submit.php" class="mt-3" id="form-validate-2fa">
- <input type="hidden" name="from" value="validate-2fa">
- <input type="hidden" name="id" value="<?= $user["id"] ?>">
- <div class="input-group mb-3" style="max-width: 280px; margin: 0 auto;">
- <input type="text" class="form-control text-center" name="totp_code" id="totp_code"
- maxlength="6" pattern="[0-9]{6}" required
- placeholder="000000" autocomplete="off"
- style="font-size: 1.5rem; letter-spacing: 0.5rem; font-weight: bold;">
- <button class="btn btn-success" type="submit">
- <i class="bi bi-check-lg"></i>
- </button>
- </div>
- </form>
- <div class="mt-2 mb-2">
- <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2" target="_blank" class="text-muted me-2">
- <?= icon::getFont(["type" => "bi bi-android2", "size" => "24px"]) ?>
- </a>
- <a href="https://apps.apple.com/fr/app/google-authenticator/id388497605" target="_blank" class="text-muted">
- <?= icon::getFont(["type" => "bi bi-apple", "size" => "24px"]) ?>
- </a>
- </div>
- </div>
- <div class="modal-footer justify-content-center border-0">
- <form method="post" action="/submit.php">
- <input type="hidden" name="from" value="cancel-2fa-pending">
- <input type="hidden" name="id" value="<?= $user["id"] ?>">
- <button class="btn btn-outline-secondary btn-sm" type="submit">
- <i class="bi bi-x-lg"></i> Annuler l'activation
- </button>
- </form>
- </div>
- </div>
- </div>
- </div>
- <script>
- $(document).ready(function() {
- // Ouvrir automatiquement la modal
- var modal2FA = new bootstrap.Modal(document.getElementById('modal2FA'));
- modal2FA.show();
- // Focus sur le champ de code
- $('#modal2FA').on('shown.bs.modal', function() {
- $('#totp_code').focus();
- });
- });
- </script>
- <?php endif; ?>
- <script>
- $(document).ready(function() {
- $('#tags').inputTags({
- autocomplete: {
- values: <?php echo tags::getJquery(1) ?>,
- only: true
- },
- max: 3
- });
- });
- </script>
- <?php
- get::javascript("user");
- ?>
|