-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
166 lines (146 loc) · 5.66 KB
/
Copy pathtest.php
File metadata and controls
166 lines (146 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
if (!isset($_GET['id'])) {
echo "ID de flashcard manquant.";
exit;
}
$id = intval($_GET['id']);
try {
$db = new PDO('sqlite:flashcards.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT data FROM flashcards WHERE id = :id");
$stmt->execute([':id' => $id]);
$flashcard = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$flashcard) {
echo "Flashcard non trouvée.";
exit;
}
$flashcards = json_decode($flashcard['data'], true);
} catch (PDOException $e) {
echo "Erreur : " . $e->getMessage();
exit;
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test de Flashcards</title>
<link rel="stylesheet" href="style.css">
<style>
.correct { color: green; }
.incorrect { color: red; }
</style>
<link rel="stylesheet" href="style.css">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
</head>
<body>
<div class="container" id="flashcardsContainer">
<h1>Test de Flashcards</h1>
<h2>Vos Flashcards</h2>
<div class="flashcard" id="flashcard"></div>
<div class="input-group">
<input type="text" id="userInput" placeholder="Votre réponse">
<button onclick="checkAnswer()">Valider</button>
</div>
<div class="navigation">
<button onclick="prevCard()">⬅️ Précédent</button>
<button onclick="nextCard()">Suivant ➡️</button>
</div>
<div class="navigation">
<button onclick="shuffleCards()">🔀 Mélanger</button>
<button onclick="toggleDirection()">🔄 Changer le sens</button>
<button onclick="toggleRandomDirection()">🔀 Sens aléatoire</button>
</div>
<div class="progress-bar-container">
<div class="progress-bar" id="progressBar"></div>
</div>
</div>
<script>
const flashcards = <?php echo json_encode($flashcards); ?>;
let currentCardIndex = 0;
let showTermFirst = true;
let randomDirection = false;
function displayCard() {
const flashcardElement = document.getElementById('flashcard');
const card = flashcards[currentCardIndex];
flashcardElement.classList.remove('answer');
if (randomDirection) {
showTermFirst = Math.random() >= 0.5;
}
if (showTermFirst) {
flashcardElement.textContent = card.term;
} else {
flashcardElement.textContent = card.definition;
flashcardElement.classList.add('answer');
}
}
function prevCard() {
currentCardIndex = (currentCardIndex - 1 + flashcards.length) % flashcards.length;
updateProgressBar();
displayCard();
}
function nextCard() {
currentCardIndex = (currentCardIndex + 1) % flashcards.length;
updateProgressBar();
displayCard();
}
function shuffleCards() {
for (let i = flashcards.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[flashcards[i], flashcards[j]] = [flashcards[j], flashcards[i]];
}
currentCardIndex = 0;
updateProgressBar();
displayCard();
}
function toggleDirection() {
showTermFirst = !showTermFirst;
displayCard();
}
function toggleRandomDirection() {
randomDirection = !randomDirection;
if (randomDirection) {
document.querySelector("button[onclick='toggleRandomDirection()']").classList.add('active');
} else {
document.querySelector("button[onclick='toggleRandomDirection()']").classList.remove('active');
}
displayCard();
}
function updateProgressBar() {
const progress = ((currentCardIndex + 1) / flashcards.length) * 100;
document.getElementById('progressBar').style.width = `${progress}%`;
}
function checkAnswer() {
const userInput = document.getElementById('userInput').value.trim();
const flashcardElement = document.getElementById('flashcard');
const card = flashcards[currentCardIndex];
const correctAnswer = showTermFirst ? card.definition : card.term;
const result = compareAnswers(userInput, correctAnswer);
flashcardElement.innerHTML = result;
}
function compareAnswers(userInput, correctAnswer) {
userInput = userInput.toLowerCase();
correctAnswer = correctAnswer.toLowerCase();
let result = '';
for (let i = 0; i < correctAnswer.length; i++) {
let char = correctAnswer[i] === ' ' ? ' ' : correctAnswer[i];
if (i < userInput.length && userInput[i] === correctAnswer[i]) {
result += `<span class="correct">${char}</span>`;
} else {
result += `<span class="incorrect">${char}</span>`;
}
}
return result;
}
displayCard();
</script>
<footer class="footer">
Made with ❤️ by Trisout (Tristan)
</footer>
</body>
</html>