erreur chatbot
This commit is contained in:
@ -968,13 +968,13 @@ $reponses_sauvegardees = json_decode($tentative['reponses_json'] ?? '{}', true)
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
</script>
|
||||
<!-- Chatbot IA Widget -->
|
||||
<div class="chat-bubble">
|
||||
<div class="chat-bubble">
|
||||
<button class="btn-chat" id="btn-open-chat">
|
||||
💬 Besoin d'aide ? <span class="help-badge"><span id="help-remaining">3</span>/3</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modal-chat">
|
||||
<div id="modal-chat">
|
||||
<div class="chat-container">
|
||||
<div class="chat-header">
|
||||
<h3>🤖 Assistant Mathématiques</h3>
|
||||
@ -992,21 +992,53 @@ $reponses_sauvegardees = json_decode($tentative['reponses_json'] ?? '{}', true)
|
||||
<button id="btn-send">📤 Envoyer</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Chatbot IA Scripts -->
|
||||
<script>
|
||||
// Passer les données PHP à JavaScript
|
||||
const tentativeId = <?= $id_tentative ?? 'null' ?>;
|
||||
const currentQuestionId = <?= isset($questions) && isset($question_actuelle) ? $questions[$question_actuelle - 1]['id_question'] : 'null' ?>;
|
||||
</script>
|
||||
<script src="assets/js/chatbot.js"></script>
|
||||
<script>
|
||||
// Initialiser le chatbot
|
||||
if (tentativeId && currentQuestionId) {
|
||||
<!-- Chatbot IA Scripts -->
|
||||
<script src="assets/js/chatbot.js"></script>
|
||||
<script>
|
||||
// Variables globales pour le chatbot
|
||||
const tentativeId = <?= $id_tentative ?? 'null' ?>;
|
||||
const questionsIds = <?= json_encode(array_column($questions ?? [], 'id_question')) ?>;
|
||||
|
||||
console.log('Init chatbot - tentativeId:', tentativeId);
|
||||
console.log('Questions disponibles:', questionsIds);
|
||||
|
||||
// Initialiser le chatbot
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if (tentativeId && questionsIds.length > 0) {
|
||||
try {
|
||||
window.chatbot = new ChatbotIA(tentativeId);
|
||||
chatbot.currentQuestionId = currentQuestionId;
|
||||
}
|
||||
</script>
|
||||
|
||||
// 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>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user