erreur chatbot
This commit is contained in:
@ -967,46 +967,78 @@ $reponses_sauvegardees = json_decode($tentative['reponses_json'] ?? '{}', true)
|
|||||||
|
|
||||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||||
</script>
|
</script>
|
||||||
<!-- Chatbot IA Widget -->
|
<!-- Chatbot IA Widget -->
|
||||||
<div class="chat-bubble">
|
<div class="chat-bubble">
|
||||||
<button class="btn-chat" id="btn-open-chat">
|
<button class="btn-chat" id="btn-open-chat">
|
||||||
💬 Besoin d'aide ? <span class="help-badge"><span id="help-remaining">3</span>/3</span>
|
💬 Besoin d'aide ? <span class="help-badge"><span id="help-remaining">3</span>/3</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="modal-chat">
|
<div id="modal-chat">
|
||||||
<div class="chat-container">
|
<div class="chat-container">
|
||||||
<div class="chat-header">
|
<div class="chat-header">
|
||||||
<h3>🤖 Assistant Mathématiques</h3>
|
<h3>🤖 Assistant Mathématiques</h3>
|
||||||
<button class="btn-close-chat" id="btn-close-chat">×</button>
|
<button class="btn-close-chat" id="btn-close-chat">×</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="chat-messages" id="chat-messages">
|
<div class="chat-messages" id="chat-messages">
|
||||||
<div class="message message-assistant">
|
<div class="message message-assistant">
|
||||||
Bonjour ! 👋 Je suis là pour t'aider sur cette question.
|
Bonjour ! 👋 Je suis là pour t'aider sur cette question.
|
||||||
<br><br>
|
<br><br>
|
||||||
Pose-moi une question et je te guiderai étape par étape, sans te donner la réponse directement. Tu as droit à <strong>3 aides</strong> par question.
|
Pose-moi une question et je te guiderai étape par étape, sans te donner la réponse directement. Tu as droit à <strong>3 aides</strong> par question.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="chat-input-zone">
|
||||||
|
<textarea id="chat-input" placeholder="Pose ta question ici..." rows="3"></textarea>
|
||||||
|
<button id="btn-send">📤 Envoyer</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="chat-input-zone">
|
|
||||||
<textarea id="chat-input" placeholder="Pose ta question ici..." rows="3"></textarea>
|
|
||||||
<button id="btn-send">📤 Envoyer</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Chatbot IA Scripts -->
|
<!-- Chatbot IA Scripts -->
|
||||||
<script>
|
<script src="assets/js/chatbot.js"></script>
|
||||||
// Passer les données PHP à JavaScript
|
<script>
|
||||||
const tentativeId = <?= $id_tentative ?? 'null' ?>;
|
// Variables globales pour le chatbot
|
||||||
const currentQuestionId = <?= isset($questions) && isset($question_actuelle) ? $questions[$question_actuelle - 1]['id_question'] : 'null' ?>;
|
const tentativeId = <?= $id_tentative ?? 'null' ?>;
|
||||||
</script>
|
const questionsIds = <?= json_encode(array_column($questions ?? [], 'id_question')) ?>;
|
||||||
<script src="assets/js/chatbot.js"></script>
|
|
||||||
<script>
|
console.log('Init chatbot - tentativeId:', tentativeId);
|
||||||
// Initialiser le chatbot
|
console.log('Questions disponibles:', questionsIds);
|
||||||
if (tentativeId && currentQuestionId) {
|
|
||||||
window.chatbot = new ChatbotIA(tentativeId);
|
// Initialiser le chatbot
|
||||||
chatbot.currentQuestionId = currentQuestionId;
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
}
|
if (tentativeId && questionsIds.length > 0) {
|
||||||
</script>
|
try {
|
||||||
|
window.chatbot = new ChatbotIA(tentativeId);
|
||||||
|
|
||||||
|
// Fonction pour obtenir la question actuelle
|
||||||
|
window.chatbot.getCurrentQuestionId = function() {
|
||||||
|
// Chercher l'input radio/checkbox sélectionné ou le dernier input
|
||||||
|
const inputs = document.querySelectorAll('input[name^="reponse_"]');
|
||||||
|
if (inputs.length > 0) {
|
||||||
|
// Prendre la première question visible
|
||||||
|
for (let input of inputs) {
|
||||||
|
const match = input.name.match(/reponse_(\d+)/);
|
||||||
|
if (match) {
|
||||||
|
const qId = parseInt(match[1]);
|
||||||
|
console.log('Question actuelle détectée:', qId);
|
||||||
|
return qId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback : première question
|
||||||
|
console.log('Fallback: première question');
|
||||||
|
return questionsIds[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('✅ Chatbot initialisé avec succès');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Erreur initialisation chatbot:', error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('⚠️ Chatbot non initialisé:', {tentativeId, questionsCount: questionsIds.length});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user