-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_cards.php
356 lines (301 loc) · 13.2 KB
/
show_cards.php
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?php
// Подключение к базе данных
require_once ('db.php');
global $link;
if ($link->connect_error) {
die("Connection failed: " . $link->connect_error);
}
$query = "SELECT Название FROM Подборки WHERE `код подборки` = ?";
$stmt = $link->prepare($query);
$stmt->bind_param('s', $_GET['id']);
$stmt->execute();
$result = $stmt->get_result();
$idName = $result->fetch_array(MYSQLI_ASSOC)['Название'];
if (isset($_COOKIE['user'])) {
$userId = $_COOKIE['user'];
}
$Id = $_GET['id'];
$time = date("Y-m-d H:i:s");
if (isset($_POST['finish'])) {
if (isset($_COOKIE['user'])) {
// Код для записи данных в таблицу "История"
$query = "INSERT INTO История (Пользователь, `Дата прохождения задания`, Подборка) VALUES (?, ?, ?)";
$stmt = $link->prepare($query);
$stmt->bind_param('sss', $userId, $time, $Id);
$stmt->execute();
}
// Перенаправление на страницу example.php с передачей данных в POST-запросе
header("Location: /collections/");
exit();
}
// Подключение к базе данных
$query = "SELECT * FROM `Карточка` WHERE Подборка = ?";
$stmt = $link->prepare($query);
$stmt->bind_param('s', $Id);
$stmt->execute();
$result = $stmt->get_result();
// Код для вывода карточек
if (isset($Id) && $Id != 0) {
// Создание массива всех карточек
$cardsArr = [];
while ($row = $result->fetch_assoc()) {
$card = [
'formula' => $row['Формула'],
'description' => $row['Описание'],
'explanation'=> $row['Пояснение']
];
$cardsArr[] = $card;
}
// Проверка на наличие карточек
if (count($cardsArr) > 0) {
// Определение текущей карточки
$currentCard = 0;
if (isset($_GET['card']) && $_GET['card'] >= 0 && $_GET['card'] < count($cardsArr)) {
$currentCard = $_GET['card'];
}
// Вывод текущей карточки
$card = $cardsArr[$currentCard];
} else {
header('Location: /collections/');
exit();
}
} else {
header('Location: /collections/');
exit();
}
?>
<!DOCTYPE html>
<html lang="en" class="h-100">
<head>
<title>Карточки</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Подключаем стили и скрипты библиотеки MathQuill -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mathquill/0.10.1/mathquill.css"
integrity="sha512-1i2kdU6oq3PAzrP6r/QkjDiuclLRhjFeT7L+d1X8C43ndhAR51ZgA+PSVwvH8Wmc7VhjzMG/n1Q5j5Fx9Pa5GA=="
crossorigin="anonymous"
/>
<style>
body{
overflow: hidden;
}
#card_cont {
min-height: 300px;
transition: transform 0.5s;
}
.front {
transform: rotateY(0deg);
}
.back {
transform: rotateY(180deg);
}
.flipped {
transform: rotateY(180deg);
}
</style>
</head>
<body class="bg-light d-flex flex-column h-100">
<?php include("inc/header.php"); ?>
<!--<div class="test_div">ТЕСТОВАЯ СТРОКА</div>-->
<div class="container">
<h2 class="text-center mb-xl-5" id="cardsName"></h2>
<div id="cards"></div>
</div>
<form action="#" method="post">
<input type="hidden" name="finish" value="1">
<!-- Модальное окно для кнопки "Закончить" -->
<div class="modal fade" id="finishModal" tabindex="-1" role="dialog" aria-labelledby="finishModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="finishModalLabel">Подтверждение завершения подборки</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Вы уверены, что хотите завершить прохождение карточек?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Отмена</button>
<button type="submit" class="btn btn-primary">закончить</button>
</div>
</div>
</div>
</div>
</form>
<!-- Подключение модального окна -->
<div class="modal fade" id="explanationModal" tabindex="-1" role="dialog" aria-labelledby="explanationModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="explanationModalLabel">Пояснение</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h2>Пояснение</h2>
<div id="explanationText"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
<?php include("inc/footer.php"); ?>
<!-- Подключение скриптов -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.js"></script>
<script>
let url = window.location.href;
let id = url.split('/').pop();
$.ajax({
url: '/collections/get_cards/' + id,
type: 'post',
dataType: 'json',
success: function(data) {
// Обработка полученных данных
let currentCardIndex = 0;
let cards = data;
let cardsName = cards[0].id;
let cardCount = cards.length;
let cardsNameContainer = $('#cardsName');
let cardContainer = $('#cards');
let explanationContainer = $('#explanationText');
let cardTemplate = '' +
'<div class="row mb-3">' +
'<div class="btn-group">' +
'<a href="/collections/keyboard/" class="btn btn-outline-primary">Тренажер</a>' +
'<button type="button" class="btn btn-outline-primary exp-btn" data-toggle="modal" data-target="#explanationModal">Пояснение</button>' +
'<a href="/add_to_favorites/" class="btn btn-outline-primary">Добавить в избранное</a>' +
'<button type="button" class="btn btn-outline-primary" data-toggle="modal" data-target="#finishModal">Закончить</button>' +
'</div>' +
'</div>' +
'<div class="row card_block">' +
'<div class="col-2">' +
'<a class="btn btn-outline-light text-dark w-100 h-100 prev-card"><h1 style="margin-top: 50%; font-size: 500%">←</h1></a>' +
'</div>' +
'<div class="col main_card_block">' +
'<div class="card border-primary align-items-center justify-content-center" id="card_cont">' +
'<div class="front">' +
'<h2>{formula}</h2>' +
'</div>' +
'<div class="back visually-hidden">' +
'<h3>{description}</h3>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-2">' +
'<a class="btn btn-outline-light text-dark w-100 h-100 next-card" id="btn-card"><h1 style="margin-top: 45%; font-size: 500%">→</h1></a>' +
'</div>' +
'</div>'
;
let explanationTemplate = '<p>{explanationText}</p>';
let cardsNameTemplate = '<p>'+cardsName+'</p>';
cardsNameContainer.html(cardsNameTemplate);
function showCard(index) {
let card = cards[index];
let formula = card.formula;
let description = card.description;
let nav = '<ul class="pagination justify-content-center mt-3">';
for (let i = 0; i < cardCount; i++) {
nav += '<li class="page-item' + (i === currentCardIndex? ' active' : '') + '"><a class="page-link" href="#" data-index="' + i + '">' + (i+1) + '</a></li>';
}
nav += '</ul>';
let html = cardTemplate.replace('{formula}', formula).replace('{description}', description).replace('{CardIndex}', index+1).replace('{CardCount}', cards.length);
cardContainer.html(html);
cardContainer.append(nav);
let card_class = document.querySelector('#card_cont');
let front = document.querySelector('.front');
let back = document.querySelector('.back');
cardContainer.on('click', '.card', function() {
card_class.classList.toggle('flipped');
front.classList.toggle('visually-hidden');
back.classList.toggle('visually-hidden');
});
// Отображение формулы в нужном виде
MathJax.Hub.Config({
showMathMenu: false,
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)'] ]
}
});
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
function showNextCard(){
currentCardIndex++;
if (currentCardIndex >= cardCount) {
currentCardIndex = 0;
}
showCard(currentCardIndex);
anime({
targets: ".main_card_block",
translateX: [
{ value: -1700, duration: 400, delay: 0 },
{ value: +1700, duration: 0, delay: 0 },
{ value: 0, duration: 400, delay: 0 },
],
});
}
function showPrevCard(){
currentCardIndex--;
if (currentCardIndex < 0) {
currentCardIndex = cardCount - 1;
}
showCard(currentCardIndex);
anime({
targets: ".main_card_block",
translateX: [
{ value: 1700, duration: 400, delay: 0 },
{ value: -1700, duration: 0, delay: 0 },
{ value: 0, duration: 400, delay: 0 },
],
});
}
function prepareExplanation(index){
let card = cards[index];
let explanation = card.explanation;
let html = explanationTemplate.replace('{explanationText}', explanation);
explanationContainer.html(html);
}
function showExplanation(){
prepareExplanation(currentCardIndex);
// Отображение формулы в нужном виде
MathJax.Hub.Config({
showMathMenu: false,
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)'] ]
}
});
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
showCard(currentCardIndex);
cardContainer.on('click', '.page-link', function(event) {
event.preventDefault();
let index = $(this).data('index');
currentCardIndex = index;
showCard(index);
});
cardContainer.on('click', '.prev-card', showPrevCard);
cardContainer.on('click', '.next-card', showNextCard);
cardContainer.on('click', '.exp-btn', showExplanation);
},
error: function(xhr, status, error) {
// Вывод ошибки в консоль
console.log('Error:', error);
}
});
</script>
<script>
</script>
</body>
<?php
$link->close();
?>
</html>