erreur sencore pour le chat bot
This commit is contained in:
@ -67,28 +67,44 @@ class ChatbotIA {
|
||||
|
||||
// NOUVELLE MÉTHODE : Détecter la question visible
|
||||
detectCurrentQuestion() {
|
||||
// Méthode 1 : Chercher l'élément de question visible/actif
|
||||
const activeQuestion = document.querySelector('.question.active, .question-container.active, [data-question-active="true"]');
|
||||
if (activeQuestion && activeQuestion.dataset.questionId) {
|
||||
return parseInt(activeQuestion.dataset.questionId);
|
||||
// Trouver la question la plus visible dans le viewport
|
||||
const questionCards = document.querySelectorAll('.question-card[data-question-id]');
|
||||
|
||||
if (questionCards.length === 0) {
|
||||
console.error('❌ Aucune question-card trouvée');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Méthode 2 : Chercher dans les inputs visibles
|
||||
const visibleInputs = document.querySelectorAll('input[name^="reponse_"]:not([style*="display: none"])');
|
||||
if (visibleInputs.length > 0) {
|
||||
const match = visibleInputs[0].name.match(/reponse_(\d+)/);
|
||||
if (match) {
|
||||
return parseInt(match[1]);
|
||||
let closestQuestion = null;
|
||||
let minDistance = Infinity;
|
||||
const viewportCenter = window.innerHeight / 2;
|
||||
|
||||
questionCards.forEach(card => {
|
||||
const rect = card.getBoundingClientRect();
|
||||
|
||||
// La question est visible dans le viewport
|
||||
if (rect.top < window.innerHeight && rect.bottom > 0) {
|
||||
const cardCenter = rect.top + (rect.height / 2);
|
||||
const distance = Math.abs(cardCenter - viewportCenter);
|
||||
|
||||
if (distance < minDistance) {
|
||||
minDistance = distance;
|
||||
closestQuestion = card;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Méthode 3 : Index de question actuelle (si ton système utilise un index)
|
||||
if (typeof currentQuestionIndex !== 'undefined' && questionsIds[currentQuestionIndex]) {
|
||||
return questionsIds[currentQuestionIndex];
|
||||
if (closestQuestion) {
|
||||
const qId = parseInt(closestQuestion.dataset.questionId);
|
||||
console.log('✅ Question visible détectée:', qId);
|
||||
return qId;
|
||||
}
|
||||
|
||||
// Fallback : première question
|
||||
return questionsIds[0];
|
||||
const firstCard = questionCards[0];
|
||||
const qId = parseInt(firstCard.dataset.questionId);
|
||||
console.log('⚠️ Fallback première question:', qId);
|
||||
return qId;
|
||||
}
|
||||
|
||||
// NOUVELLE MÉTHODE : Charger l'aide restante via AJAX
|
||||
|
||||
@ -625,8 +625,7 @@ $reponses_sauvegardees = json_decode($tentative['reponses_json'] ?? '{}', true)
|
||||
<input type="hidden" name="id_evaluation" value="<?= $id_evaluation ?>">
|
||||
|
||||
<?php foreach ($questions as $index => $q): ?>
|
||||
<div class="question-card" data-question="<?= $index + 1 ?>" data-id="<?= $q['id_question'] ?>">
|
||||
<div class="question-header">
|
||||
<div class="question-card" data-question="<?= $index + 1 ?>" data-id="<?= $q['id_question'] ?>" data-question-id="<?= $q['id_question'] ?>"> <div class="question-header">
|
||||
<div class="question-number">Question <?= $index + 1 ?> / <?= count($questions) ?></div>
|
||||
<div class="question-meta">
|
||||
<span class="badge badge-points"><?= $q['points'] ?> pts</span>
|
||||
|
||||
Reference in New Issue
Block a user