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
| <!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Профиль этапа</title>
<link rel="stylesheet" href="styles.css">
<style>
.profile {
width: 70%;
margin: 50px auto;
padding: 20px;
background: rgba(255, 255, 255, 0.8);
border-radius: 10px;
text-align: left;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.profile h2 {
text-align: left;
color: #333;
font-size: 20px;
}
.profile p, .profile a {
margin: 10px 0;
font-size: 18px;
}
.add-pairs-btn, .assign-plus-btn, .random-assign-plus-btn, .move-pairs-btn, .save-top-pairs-btn {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 20px 0;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s;
}
.add-pairs-btn:hover, .assign-plus-btn:hover, .random-assign-plus-btn:hover, .move-pairs-btn:hover, .save-top-pairs-btn:hover {
background-color: #45a049;
}
.random-assign-plus-btn {
background-color: #ff9800;
}
.random-assign-plus-btn:hover {
background-color: #e08d38;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 12px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
input[type="number"] {
width: 50px;
text-align: center;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('.assign-plus-btn').click(function(e) {
e.preventDefault();
var form = $(this).closest('form');
var formData = form.serialize();
var dance = form.find('input[name="dance"]').val();
var category_id = form.find('input[name="category_id"]').val();
var stage = form.find('input[name="stage"]').val();
var competition_id = form.find('input[name="competition_id"]').val();
$.ajax({
type: 'POST',
url: 'save_scores.php',
data: formData,
success: function(response) {
window.location.href = 'save_scores_success.php?dance=' + dance + '&category_id=' + category_id + '&stage=' + stage + '&competition_id=' + competition_id;
},
error: function(xhr, status, error) {
alert('Ошибка при сохранении оценок: ' + error);
}
});
});
});
</script>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="index.php">Главная</a></li>
<li><a href="competitions.php">Соревнования</a></li>
<li><a href="judges.php">Судьи</a></li>
<li><a href="pairs.php">Пары</a></li>
<li><a href="rating.php">Рейтинг</a></li>
</ul>
</nav>
</header>
<main>
<section class="hero">
<h1 style="color: #333;">Профиль этапа</h1>
</section>
<section class="profile">
<?php
include 'db_connect.php';
if (isset($_GET['category_id']) && isset($_GET['stage']) && isset($_GET['competition_id'])) {
$category_id = intval($_GET['category_id']);
$stage = $_GET['stage'];
$competition_id = intval($_GET['competition_id']);
$sql = "SELECT name, dances FROM categories WHERE id = $category_id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo "<h2>Этап: {$stage} категории {$row['name']}</h2>";
echo "<a href='add_pairs.php?category_id=$category_id&stage=$stage' class='add-pairs-btn'>Добавить пары</a>";
$dances = explode(',', $row['dances']);
foreach ($dances as $dance) {
echo "<h3>Танец: " . getDanceName($dance) . "</h3>";
echo "<form method='post' action=''>";
echo "<input type='hidden' name='dance' value='$dance'>";
echo "<input type='hidden' name='category_id' value='$category_id'>";
echo "<input type='hidden' name='stage' value='$stage'>";
echo "<input type='hidden' name='competition_id' value='$competition_id'>";
echo "<table>";
echo "<tr>";
echo "<th>Пара</th>";
$judges_sql = "SELECT j.id FROM judges j JOIN categoryjudges cj ON j.id = cj.judge_id WHERE cj.category_id = $category_id ORDER BY j.id";
$judges_result = $conn->query($judges_sql);
if ($judges_result->num_rows > 0) {
$judge_count = 1;
while ($judge_row = $judges_result->fetch_assoc()) {
echo "<th>Судья $judge_count</th>";
$judge_count++;
}
}
echo "<th>Сумма</th>";
echo "</tr>";
$pairs_sql = "SELECT p.partner_name, p.partner_id, p.partness_name, p.partness_id, p.id as pair_id
FROM pairs p
JOIN categorypairs cp ON p.id = cp.pair_id
WHERE cp.category_id = $category_id AND cp.stage = '$stage'";
$pairs_result = $conn->query($pairs_sql);
if ($pairs_result->num_rows > 0) {
while ($pair_row = $pairs_result->fetch_assoc()) {
echo "<tr>";
echo "<td>{$pair_row['partner_name']} - {$pair_row['partness_name']}</td>";
$judges_result->data_seek(0);
$total_sum = 0;
while ($judge_row = $judges_result->fetch_assoc()) {
$score_sql = "SELECT score FROM judging WHERE judge_id = " . $judge_row['id'] . " AND pair_id = " . $pair_row['pair_id'] . " AND category_id = $category_id AND stage = '$stage' AND dance = '$dance'";
$score_result = $conn->query($score_sql);
if ($score_result->num_rows > 0) {
$score_row = $score_result->fetch_assoc();
echo "<td><input type='number' name='score_{$judge_row['id']}_{$pair_row['pair_id']}_{$dance}' value='" . $score_row['score'] . "'></td>";
$total_sum += $score_row['score'];
} else {
echo "<td><input type='number' name='score_{$judge_row['id']}_{$pair_row['pair_id']}_{$dance}' value='0'></td>";
}
}
echo "<td>" . $total_sum . "</td>";
echo "</tr>";
}
} else {
echo "<p>Нет пар</p>";
}
echo "</table>";
echo "<button type='submit' name='save_scores' class='assign-plus-btn'>Ввести очки вручную</button>";
echo "</form>";
echo "<a href='random_assign_scores.php?category_id=$category_id&stage=$stage&dance=$dance' class='random-assign-plus-btn'>Случайно расставить оценки</a>";
}
$dances_count = count($dances);
$judges_count_sql = "SELECT COUNT(*) as judge_count FROM judges j JOIN categoryjudges cj ON j.id = cj.judge_id WHERE cj.category_id = $category_id";
$judges_count_result = $conn->query($judges_count_sql);
$judges_count_row = $judges_count_result->fetch_assoc();
$judges_count = $judges_count_row['judge_count'];
$order_by = ($stage === 'Финал') ? 'ASC' : 'DESC';
$top_pairs_sql = "SELECT p.id as pair_id, p.partner_name, p.partner_id, p.partness_name, p.partness_id,
ROUND(SUM(j.score) / $dances_count, 1) as total_score
FROM pairs p
JOIN judging j ON p.id = j.pair_id
WHERE j.category_id = $category_id AND j.stage = '$stage'
GROUP BY p.id
ORDER BY total_score $order_by";
$top_pairs_result = $conn->query($top_pairs_sql);
if ($top_pairs_result->num_rows > 0) {
echo "<h3>Топ пар по сумме оценок</h3>";
echo "<table>";
echo "<tr>";
echo "<th>Пара</th>";
echo "<th>Сумма</th>";
echo "</tr>";
$place = 1;
while ($top_pair_row = $top_pairs_result->fetch_assoc()) {
echo "<tr>";
echo "<td>{$top_pair_row['partner_name']} - {$top_pair_row['partness_name']}</td>";
echo "<td>{$top_pair_row['total_score']}</td>";
echo "</tr>";
$place++;
}
echo "</table>";
} else {
echo "<p>Нет данных</p>";
}
echo "<a href='move_pairs_to_next_stage.php?category_id=$category_id&stage=$stage' class='move-pairs-btn'>Перенести лучшие пары в следующий этап</a>";
echo "<form method='post' action=''>";
echo "<input type='hidden' name='category_id' value='$category_id'>";
echo "<input type='hidden' name='stage' value='$stage'>";
echo "<input type='hidden' name='competition_id' value='$competition_id'>";
echo "<button type='submit' name='save_top_pairs' class='save-top-pairs-btn'>Записать данные в таблицу top_pairs</button>";
echo "</form>";
if (isset($_POST['save_top_pairs'])) {
$category_id = intval($_POST['category_id']);
$stage = $_POST['stage'];
$competition_id = intval($_POST['competition_id']);
$top_pairs_sql = "SELECT p.id as pair_id, p.partner_name, p.partner_id, p.partness_name, p.partness_id,
ROUND(SUM(j.score) / $dances_count, 1) as total_score
FROM pairs p
JOIN judging j ON p.id = j.pair_id
WHERE j.category_id = $category_id AND j.stage = '$stage'
GROUP BY p.id
ORDER BY total_score $order_by";
$top_pairs_result = $conn->query($top_pairs_sql);
if ($top_pairs_result->num_rows > 0) {
$values = [];
$place = 1;
while ($top_pair_row = $top_pairs_result->fetch_assoc()) {
$values[] = "($competition_id, $category_id, " . $top_pair_row['pair_id'] . ", " . $top_pair_row['total_score'] . ", $place, '$stage')";
$place++;
}
if (!empty($values)) {
$insert_sql = "INSERT INTO top_pairs (competition_id, category_id, pair_id, total_score, place, stage)
VALUES " . implode(", ", $values) . "
ON DUPLICATE KEY UPDATE total_score = VALUES(total_score), place = VALUES(place)";
$conn->query($insert_sql);
}
echo "<p>Данные успешно записаны в таблицу top_pairs.</p>";
} else {
echo "<p>Нет данных для записи.</p>";
}
}
} else {
echo "<p>Категория не найдена</p>";
}
$conn->close();
} else {
echo "<p>ID категории, этапа или соревнования не указан</p>";
}
function getDanceName($code) {
$dances = [
'W' => 'Waltz',
'T' => 'Tango',
'VW' => 'Viennese Waltz',
'SF' => 'Slow Foxtrot',
'Q' => 'Quickstep',
'C' => 'Cha-cha-cha',
'S' => 'Samba',
'R' => 'Rumba',
'PD' => 'Paso Doble',
'J' => 'Jive'
];
return $dances[$code];
}
?>
</section>
</main>
<footer>
<p>© 2023 DanceSport Association</p>
</footer>
</body>
</html> |