This commit is contained in:
KONE SOREL 2026-01-19 13:57:27 +00:00
parent bda6b3a2a3
commit d923250285

View File

@ -3,179 +3,182 @@
?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<div class="modal fade" id="pop_rec_faciale" role="dialog" data-backdrop="static" data-keyboard="false" >
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal fade animate__animated animate__zoomIn" id="pop_rec_faciale" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog modal-lg modal-dialog-centered shadow-lg">
<div class="modal-content border-0">
<div class="modal-header">
<div class="d-flex justify-content-between align-items-center w-100">
<h4 class="modal-title mb-0"><?= _("RECONNAISSANCE FACIALE") ?></h4>
<button id="btn_close_pop_rec_faciale" name="btn_close_pop_rec_faciale" type="button" class="btn-close" data-bs-dismiss="modal" onclick="javascript:fiche_beneficiaire();" aria-label="<?= _("Fermer") ?>"></button>
<div class="modal-header bg-primary text-white py-3">
<div class="d-flex align-items-center w-100">
<div class="bg-white bg-opacity-25 p-2 rounded-circle me-3">
<i class="fas fa-face-viewfinder fa-lg text-white"></i>
</div>
<h5 class="modal-title fw-bold mb-0"><?= _("Reconnaissance Faciale") ?></h5>
<button id="btn_close_pop_rec_faciale" type="button" class="btn-close btn-close-white ms-auto" data-bs-dismiss="modal" onclick="javascript:fiche_beneficiaire();" aria-label="Fermer"></button>
</div>
</div>
<div class="modal-body">
<!-- Boutons d'action - disposition responsive -->
<div class="row g-2 mb-3">
<div class="col-12 col-sm-6">
<button id="ebene_take_photo_face" name="ebene_take_photo_face" type="button" class="btn btn-primary w-100 py-2 btn_autre" onclick="javascript:takephoto();">
<i class="bi bi-camera me-2"></i><?= _("PRENDRE UNE PHOTO") ?>
<div class="modal-body p-4 bg-light">
<div class="row g-3 mb-4">
<div class="col-md-6">
<button id="ebene_take_photo_face" type="button" class="btn btn-primary w-100 py-3 fw-bold shadow-sm" onclick="takephoto();">
<i class="fas fa-camera me-2"></i><?= _("PRENDRE UNE PHOTO") ?>
</button>
</div>
<div class="col-md-6">
<?php if ($faceRegistered == "1") : ?>
<div class="col-12 col-sm-6">
<button disabled id="ebene_confirmer_photo_face" name="ebene_confirmer_photo_face" type="button" class="btn btn-primary w-100 py-2 btn_autre" onclick="javascript:ebene_confirmer_photo_face();">
<i class="bi bi-check-circle me-2"></i><?= _("CONFIRMER LA PHOTO") ?>
<button disabled id="ebene_confirmer_photo_face" type="button" class="btn btn-success w-100 py-3 fw-bold shadow-sm" onclick="ebene_confirmer_photo_face();">
<i class="fas fa-check-circle me-2"></i><?= _("CONFIRMER LA PHOTO") ?>
</button>
</div>
<?php endif; ?>
<?php if ($faceRegistered != "1") : ?>
<div class="col-12 col-sm-6">
<button disabled id="ebene_enregistrer_photo_face" name="ebene_enregistrer_photo_face" type="button" class="btn btn-primary w-100 py-2 btn_autre" onclick="javascript:ebene_enregistrer_photo_face();">
<i class="bi bi-save me-2"></i><?= _("ENREGISTRER LA PHOTO") ?>
<?php else : ?>
<button disabled id="ebene_enregistrer_photo_face" type="button" class="btn btn-info text-white w-100 py-3 fw-bold shadow-sm" onclick="ebene_enregistrer_photo_face();">
<i class="fas fa-save me-2"></i><?= _("ENREGISTRER LA PHOTO") ?>
</button>
</div>
<?php endif; ?>
</div>
<!-- Zone webcam et photo - disposition responsive -->
<div class="row g-3">
<div class="col-12 col-md-6">
<div class="text-center mb-2">
<legend class="h6"><?= _("Webcam") ?></legend>
</div>
<div class="ratio ratio-4x3 bg-dark rounded">
<video id="video_face" name="video_face" autoplay playsinline class="w-100 h-100 object-fit-cover"></video>
<div class="row g-4">
<div class="col-md-6">
<div class="text-center mb-2">
<span class="badge bg-dark px-3 py-2 rounded-pill small fw-bold text-uppercase"><?= _("Webcam en direct") ?></span>
</div>
<div class="ratio ratio-4x3 bg-dark rounded shadow-inner overflow-hidden border border-3 border-white">
<video id="video_face" autoplay playsinline class="w-100 h-100 object-fit-cover"></video>
<div class="position-absolute top-50 start-50 translate-middle border border-2 border-primary border-opacity-25 rounded-circle" style="width: 60%; height: 80%; pointer-events: none;"></div>
</div>
</div>
<div class="col-12 col-md-6">
<div class="col-md-6">
<div class="text-center mb-2">
<legend class="h6"><?= _("Photo") ?></legend>
<span class="badge bg-secondary px-3 py-2 rounded-pill small fw-bold text-uppercase"><?= _("Capture figée") ?></span>
</div>
<div class="ratio ratio-4x3 bg-white border border-3 border-white rounded shadow-inner overflow-hidden">
<img id="photo_face" src="" class="w-100 h-100 object-fit-cover" alt="<?= _("Photo capturée") ?>" />
</div>
</div>
<div class="ratio ratio-4x3 bg-light border rounded">
<img id="photo_face" name="photo_face" src="" class="w-100 h-100 object-fit-cover" alt="<?= _("Photo capturée") ?>" />
</div>
<form id="form_face" name="form_face" enctype="multipart/form-data" method="post" action="Fichebeneficiaire/ebeneenregistrerface">
<input class="sr-only" type="text" id="compare_face" name="compare_face" value="<?= $faceRegistered ?>">
<input class="sr-only" type="text" id="del_face" name="del_face" value="0">
<input class="image-tag" type="hidden" id="image_face" name="image_face">
<input type="hidden" id="compare_face" name="compare_face" value="<?= $faceRegistered ?>">
<input type="hidden" id="del_face" name="del_face" value="0">
<input type="hidden" id="image_face" name="image_face" class="image-tag">
<input type="hidden" id="photo_succes" name="photo_succes" value="0">
</form>
<div id="message_face" class="mt-4">
<div class="alert alert-warning mb-0 shadow-xs border-0 rounded-pill d-flex align-items-center px-4">
<i class="fas fa-lightbulb me-3 fa-lg text-primary"></i>
<marquee behavior="scroll" direction="left" scrollamount="3" class="small fw-bold m-0">
<?= _("Positionnez votre visage au centre du cadre. Assurez-vous d'être dans un endroit bien éclairé pour une meilleure précision.") ?>
</marquee>
</div>
</div>
<!-- Canvas caché -->
<canvas id="canvas" name="canvas" style="display: none;" width="350" height="260"></canvas>
<!-- Messages -->
<div id="message_face" name="message_face" class="mt-3">
<div class="alert alert-warning mb-0" role="alert">
<div class="d-flex align-items-center">
<i class="bi bi-info-circle me-2"></i>
<marquee behavior="scroll" direction="left" scrollamount="3" class="flex-grow-1"></marquee>
</div>
</div>
<input class="sr-only" type="text" id="photo_succes" name="photo_succes" value="0">
</div>
<!-- Zone d'attente -->
<div id="div_wait_face_ebene" class="mt-3"></div>
<canvas id="canvas" style="display: none;"></canvas>
</div>
<div class="modal-footer bg-light border-0 p-3">
<button id="close_poprec_faciane" type="button" class="btn btn-outline-secondary fw-bold px-4 rounded-pill" data-bs-dismiss="modal" onclick="fiche_beneficiaire();">
<i class="fas fa-times me-2"></i><?= _("Fermer") ?>
</button>
</div>
</div>
</div>
</div>
<style>
/* Miroir pour la vidéo (plus naturel pour l'utilisateur) */
#video_face { transform: scaleX(-1); }
.object-fit-cover { object-fit: cover; }
.shadow-inner { box-shadow: inset 0 2px 10px rgba(0,0,0,0.2); }
.shadow-xs { box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.modal-content { border-radius: 1.5rem; overflow: hidden; }
</style>
<script type="text/javascript">
var video = document.getElementById('video_face');
var canvas = document.getElementById('canvas');
var photo = document.getElementById('photo_face');
var image_face = document.getElementById('image_face');
var image_input = document.getElementById('image_face');
navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.mediaDevices.getUserMedia || navigator.moxGetUserMedia;
if (navigator.mediaDevices.getUserMedia)
{
navigator.mediaDevices.getUserMedia({
/**
* Initialisation de la caméra
*/
async function initCamera() {
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: {
facingMode: 'user',
width: { ideal: 1280 },
height: { ideal: 720 }
}
})
.then(function (stream) {
},
audio: false
});
video.srcObject = stream;
})
.catch(function (e) {
console.error("Erreur caméra:", e);
alert("Erreur d'accès à la caméra: " + e.message);
});
}
else
{
navigator.getMedia({
video: {
mandatory: {
maxWidth: 350,
maxHeight: 260
} catch (err) {
console.error("Erreur caméra:", err);
alert("Impossible d'accéder à la caméra. Vérifiez les autorisations.");
}
}
}, function(stream) {
video.src = stream;
}, function(e) {
console.error("Erreur caméra:", e);
alert("Erreur d'accès à la caméra: " + e.message);
});
}
/**
* Capture de la photo
*/
function takephoto() {
$('#message_face').html("");
// Effacer les anciens messages
$("#div_wait_face_ebene").html('');
// Ajustement de la taille du canvas pour mobile
// Configurer le canvas selon la source vidéo réelle
var context = canvas.getContext('2d');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
// Dessiner l'image
context.drawImage(video, 0, 0, canvas.width, canvas.height);
// Extraire en Base64
var data = canvas.toDataURL('image/jpeg', 0.8);
// Mettre à jour l'aperçu et le champ caché
photo.setAttribute('src', data);
$("#image_face").val(data);
image_input.value = data;
var faceRegistered = $("#faceRegistered").val();
// Activation des boutons
// Gestion des boutons
var faceRegistered = $("#compare_face").val();
$("#ebene_enregistrer_photo_face").prop('disabled', false);
if(faceRegistered == "1") {
if(faceRegistered === "1") {
$("#ebene_confirmer_photo_face").prop('disabled', false);
$("#ebene_supprimer_photo_face").prop('disabled', false);
$("#motif").prop('disabled', false);
}
}
// Gestion du redimensionnement pour mobile
$(window).on('resize', function() {
if($(window).width() < 768) {
$('.modal-dialog').addClass('modal-fullscreen-sm-down');
} else {
$('.modal-dialog').removeClass('modal-fullscreen-sm-down');
// Effet visuel de flash
photo.parentElement.classList.add('animate__animated', 'animate__flash');
setTimeout(() => {
photo.parentElement.classList.remove('animate__animated', 'animate__flash');
}, 500);
}
// Gestionnaires d'événements pour la modal Bootstrap 5
var myModalEl = document.getElementById('pop_rec_faciale');
// Allumer la caméra quand la modal s'affiche
myModalEl.addEventListener('shown.bs.modal', function () {
initCamera();
});
// Initialisation au chargement
$(document).ready(function() {
if($(window).width() < 768) {
$('.modal-dialog').addClass('modal-fullscreen-sm-down');
// Éteindre la caméra quand on ferme la modal (important !)
myModalEl.addEventListener('hidden.bs.modal', function () {
if (video.srcObject) {
const tracks = video.srcObject.getTracks();
tracks.forEach(track => track.stop());
video.srcObject = null;
}
});
</script>
</div>
<div class="modal-footer">
<button id="close_poprec_faciane" name="close_poprec_faciane" type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="javascript:fiche_beneficiaire();">
<i class="bi bi-x-circle me-2 btn_autre"></i><?= _("Fermer") ?>
</button>
</div>
</div>
</div>
</div>