-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayerbook.php
More file actions
238 lines (201 loc) · 11 KB
/
playerbook.php
File metadata and controls
238 lines (201 loc) · 11 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
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
<?php
require_once 'assets/init_session.php';
require 'db.php';
require 'assets/header.php';
require 'assets/footer.php';
// Logique de tri, recherche et filtres
// Paramètres par défaut
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = 50;
$offset = ($page - 1) * $limit;
// Tris autorisés
$allowed_sorts = ['id', 'name_en', 'name_jp', 'gender', 'total_stats'];
$sort = isset($_GET['sort']) && in_array($_GET['sort'], $allowed_sorts) ? $_GET['sort'] : 'id';
$order = isset($_GET['order']) && $_GET['order'] === 'DESC' ? 'DESC' : 'ASC';
// Recherche
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
// Récupération des Filtres
$filter_pos = isset($_GET['pos']) ? $_GET['pos'] : '';
$filter_elem = isset($_GET['elem']) ? $_GET['elem'] : '';
// Construction de la requête SQL
$sql = "SELECT * FROM players WHERE 1=1";
$params = [];
// Ajout Recherche
if ($search) {
$sql .= " AND (name_en LIKE ? OR name_jp LIKE ?)";
$params[] = "%$search%";
$params[] = "%$search%";
}
// Filtre Position
if ($filter_pos) {
$sql .= " AND position = ?";
$params[] = $filter_pos;
}
// Filtre Élément
if ($filter_elem) {
$sql .= " AND element = ?";
$params[] = $filter_elem;
}
// Tri et Pagination
$sql .= " ORDER BY $sort $order LIMIT $limit OFFSET $offset";
// Exécution requête principale
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$players = $stmt->fetchAll();
// Compte le total
$sqlCount = "SELECT COUNT(*) FROM players WHERE 1=1";
$paramsCount = [];
if ($search) {
$sqlCount .= " AND (name_en LIKE ? OR name_jp LIKE ?)";
$paramsCount[] = "%$search%";
$paramsCount[] = "%$search%";
}
if ($filter_pos) {
$sqlCount .= " AND position = ?";
$paramsCount[] = $filter_pos;
}
if ($filter_elem) {
$sqlCount .= " AND element = ?";
$paramsCount[] = $filter_elem;
}
$stmtCount = $pdo->prepare($sqlCount);
$stmtCount->execute($paramsCount);
$totalPlayers = $stmtCount->fetchColumn();
$totalPages = ceil($totalPlayers / $limit);
if ($totalPages < 1) $totalPages = 1;
// Fonction helper pour les liens
function getLink($newPage, $newSort = null, $currentSearch = '', $pPos = null, $pElem = null) {
global $page, $sort, $order, $filter_pos, $filter_elem;
$p = $newPage ?? $page;
$s = $newSort ?? $sort;
$currPos = $pPos !== null ? $pPos : $filter_pos;
$currElem = $pElem !== null ? $pElem : $filter_elem;
$o = $order;
// Logique d'inversion
if ($newSort && $newSort === $sort) {
$o = ($order === 'ASC') ? 'DESC' : 'ASC';
} elseif ($newSort) {
$o = 'DESC';
}
// Construction URL
$url = "?page=$p&sort=$s&order=$o";
if ($currentSearch) $url .= "&search=" . urlencode($currentSearch);
if ($currPos) $url .= "&pos=" . urlencode($currPos);
if ($currElem) $url .= "&elem=" . urlencode($currElem);
return $url;
}
function sortArrow($colName) {
global $sort, $order;
if ($sort === $colName) {
return $order === 'ASC' ? '▲' : '▼';
}
return '<span style="opacity:0.3">⇅</span>';
}
$header = new Header(__('pb_title'));
$header->render();
?>
<link rel="stylesheet" href="style-playerbook.css">
<main class="playerbook-container">
<div class="pb-header">
<h1 class="dashboard-h1"><?php echo __('pb_h1_1'); ?> <span style="color:var(--primary-purple)"><?php echo __('pb_h1_2'); ?></span></h1>
<p class="subtitle subtitle-playerbook"><?php echo __('pb_subtitle'); ?></p>
</div>
<div class="controls-wrapper">
<form method="GET" class="search-bar-container">
<input type="hidden" name="sort" value="<?php echo htmlspecialchars($sort); ?>">
<input type="hidden" name="order" value="<?php echo htmlspecialchars($order); ?>">
<?php if($filter_pos): ?><input type="hidden" name="pos" value="<?php echo htmlspecialchars($filter_pos); ?>"><?php endif; ?>
<?php if($filter_elem): ?><input type="hidden" name="elem" value="<?php echo htmlspecialchars($filter_elem); ?>"><?php endif; ?>
<input type="text" name="search" placeholder="<?php echo __('pb_search_placeholder'); ?>" value="<?php echo htmlspecialchars($search); ?>">
<button type="submit"><i class="fas fa-search"></i></button>
<?php if($search || $filter_pos || $filter_elem): ?>
<a href="playerbook.php" class="reset-btn" title="<?php echo __('pb_reset_title'); ?>">✖</a>
<?php endif; ?>
</form>
<div class="pagination">
<?php if ($page > 1): ?>
<a href="<?php echo getLink($page - 1); ?>" class="page-btn">←</a>
<?php endif; ?>
<!-- Pagination -->
<form method="GET" class="page-jump-form">
<input type="hidden" name="sort" value="<?php echo htmlspecialchars($sort); ?>">
<input type="hidden" name="order" value="<?php echo htmlspecialchars($order); ?>">
<input type="hidden" name="search" value="<?php echo htmlspecialchars($search); ?>">
<input type="hidden" name="pos" value="<?php echo htmlspecialchars($filter_pos); ?>">
<input type="hidden" name="elem" value="<?php echo htmlspecialchars($filter_elem); ?>">
<span class="page-info"><?php echo __('pb_page'); ?></span>
<input type="number" name="page" value="<?php echo $page; ?>" min="1" max="<?php echo $totalPages; ?>" class="page-input">
<span class="page-info">/ <?php echo $totalPages; ?></span>
</form>
<?php if ($page < $totalPages): ?>
<a href="<?php echo getLink($page + 1); ?>" class="page-btn">→</a>
<?php endif; ?>
</div>
</div>
<div class="table-responsive">
<table class="player-table">
<thead>
<tr>
<th class="col-img"><?php echo __('pb_th_preview'); ?></th>
<th><a href="<?php echo getLink(1, 'id'); ?>"><?php echo __('pb_th_id'); ?> <?php echo sortArrow('id'); ?></a></th>
<th><a href="<?php echo getLink(1, 'name_en'); ?>"><?php echo __('pb_th_name_en'); ?> <?php echo sortArrow('name_en'); ?></a></th>
<th><a href="<?php echo getLink(1, 'name_jp'); ?>"><?php echo __('pb_th_name_jp'); ?> <?php echo sortArrow('name_jp'); ?></a></th>
<th class="th-dropdown">
<span><?php echo __('pb_th_position'); ?> <i class="fas fa-filter" style="font-size:0.7rem; opacity:0.7;"></i></span>
<div class="dropdown-content">
<a href="<?php echo getLink(1, null, $search, ''); ?>" class="<?php echo !$filter_pos ? 'active' : ''; ?>"><?php echo __('pb_filter_all'); ?></a>
<a href="<?php echo getLink(1, null, $search, 'GK'); ?>" class="<?php echo $filter_pos === 'GK' ? 'active' : ''; ?>"><?php echo __('GK'); ?></a>
<a href="<?php echo getLink(1, null, $search, 'DF'); ?>" class="<?php echo $filter_pos === 'DF' ? 'active' : ''; ?>"><?php echo __('DF'); ?></a>
<a href="<?php echo getLink(1, null, $search, 'MF'); ?>" class="<?php echo $filter_pos === 'MF' ? 'active' : ''; ?>"><?php echo __('MF'); ?></a>
<a href="<?php echo getLink(1, null, $search, 'FW'); ?>" class="<?php echo $filter_pos === 'FW' ? 'active' : ''; ?>"><?php echo __('FW'); ?></a>
</div>
</th>
<th class="th-dropdown">
<span><?php echo __('pb_th_element'); ?> <i class="fas fa-filter" style="font-size:0.7rem; opacity:0.7;"></i></span>
<div class="dropdown-content">
<a href="<?php echo getLink(1, null, $search, null, ''); ?>" class="<?php echo !$filter_elem ? 'active' : ''; ?>"><?php echo __('pb_filter_all'); ?></a>
<a href="<?php echo getLink(1, null, $search, null, 'Wind'); ?>" class="<?php echo $filter_elem === 'Wind' ? 'active' : ''; ?>"><?php echo __('pb_elem_wind'); ?></a>
<a href="<?php echo getLink(1, null, $search, null, 'Mountain'); ?>" class="<?php echo $filter_elem === 'Mountain' ? 'active' : ''; ?>"><?php echo __('pb_elem_mountain'); ?></a>
<a href="<?php echo getLink(1, null, $search, null, 'Fire'); ?>" class="<?php echo $filter_elem === 'Fire' ? 'active' : ''; ?>"><?php echo __('pb_elem_fire'); ?></a>
<a href="<?php echo getLink(1, null, $search, null, 'Forest'); ?>" class="<?php echo $filter_elem === 'Forest' ? 'active' : ''; ?>"><?php echo __('pb_elem_wood'); ?></a>
</div>
</th>
<th><a href="<?php echo getLink(1, 'gender'); ?>"><?php echo __('pb_th_gender'); ?> <?php echo sortArrow('gender'); ?></a></th>
<th><a href="<?php echo getLink(1, 'total_stats'); ?>"><?php echo __('pb_th_stats'); ?> <?php echo sortArrow('total_stats'); ?></a></th>
</tr>
</thead>
<tbody>
<?php if (count($players) > 0): ?>
<?php foreach ($players as $p): ?>
<tr>
<td class="col-img">
<img src="<?php echo htmlspecialchars($p['image_webp']); ?>" alt="img" loading="lazy">
</td>
<td data-label="<?php echo __('pb_th_id'); ?>">#<?php echo $p['id']; ?></td>
<td data-label="<?php echo __('pb_th_name_en'); ?>" class="font-bold"><?php echo htmlspecialchars($p['name_en']); ?></td>
<td data-label="<?php echo __('pb_th_name_jp'); ?>" style="color:var(--text-secondary)"><?php echo htmlspecialchars($p['name_jp']); ?></td>
<td data-label="<?php echo __('pb_th_position'); ?>">
<span class="badge pos-<?php echo strtolower($p['position']); ?>"><?php echo __($p['position']); ?></span>
</td>
<td data-label="<?php echo __('pb_th_element'); ?>">
<span class="badge elem-<?php echo strtolower($p['element']); ?>"><?php echo __($p['element']); ?></span>
</td>
<td data-label="<?php echo __('pb_th_gender'); ?>"><?php echo __($p['gender']); ?></td>
<td data-label="<?php echo __('pb_th_stats'); ?>" class="stat-cell"><?php echo $p['total_stats']; ?></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="8" style="text-align:center; padding: 2rem;"><?php echo __('pb_no_results'); ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</main>
<?php
$footer = new Footer();
$footer->render();
?>
</body>
</html>