correction chatbot
This commit is contained in:
36
api/chatbot_check_limit.php
Normal file
36
api/chatbot_check_limit.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../config/config.php';
|
||||||
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
if (!isLoggedIn() || !isEleve()) {
|
||||||
|
echo json_encode(['error' => 'Non autorisé']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id_tentative = filter_input(INPUT_POST, 'id_tentative', FILTER_VALIDATE_INT);
|
||||||
|
$id_question = filter_input(INPUT_POST, 'id_question', FILTER_VALIDATE_INT);
|
||||||
|
|
||||||
|
if (!$id_tentative || !$id_question) {
|
||||||
|
echo json_encode(['error' => 'Données manquantes']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Database::getInstance();
|
||||||
|
|
||||||
|
// Vérifier limite
|
||||||
|
$usage = $db->fetchOne(
|
||||||
|
"SELECT messages_count FROM chat_usage_limits
|
||||||
|
WHERE id_tentative = ? AND id_question = ?",
|
||||||
|
[$id_tentative, $id_question]
|
||||||
|
);
|
||||||
|
|
||||||
|
$messages_count = $usage['messages_count'] ?? 0;
|
||||||
|
$remaining = max(0, 3 - $messages_count);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'remaining' => $remaining,
|
||||||
|
'used' => $messages_count
|
||||||
|
]);
|
||||||
Reference in New Issue
Block a user