-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
380 lines (329 loc) · 17.8 KB
/
profile.php
File metadata and controls
380 lines (329 loc) · 17.8 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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
require_once 'assets/init_session.php';
require 'db.php';
// Si l'utilisateur n'est pas connecté, redirige vers l'accueil
if (!isset($_SESSION['user_id'])) {
header("Location: /");
exit;
}
// Récupération du profil à afficher
$profileUser = null;
$errorMsg = null;
// Détermine quel profil afficher
if (isset($_GET['username']) && !empty($_GET['username'])) {
// Si un pseudo est demandé dans l'URL
$targetUsername = $_GET['username'];
} else {
// Si rien n'est précisé, affiche le profil de l'utilisateur connecté
header("Location: profile.php?username=" . $_SESSION['username']);
exit;
}
// Cherche l'utilisateur dans la base de données
$stmt = $pdo->prepare("SELECT id, username, avatar, created_at, elo, grade, bio, wins, losses FROM users WHERE username = ?");
$stmt->execute([$targetUsername]);
$profileUser = $stmt->fetch();
if (!$profileUser) {
header("Location: 404.php");
exit;
}
$stmtTeam = $pdo->prepare("SELECT formation, team_name FROM teams WHERE user_id = ?");
$stmtTeam->execute([$profileUser['id']]);
$teamData = $stmtTeam->fetch();
// Si l'utilisateur a une formation sauvegardée, la prend. Sinon par défaut '4-4-2 Diamant'.
$savedFormation = $teamData['formation'] ?? '4-4-2 Diamant';
$teamName = $teamData['team_name'] ?? 'Victory Team';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Nettoie l'entrée (supprime les espaces inutiles au début/fin)
$newBio = trim($_POST['bio']);
// Vérification de la longueur (Sécurité côté serveur)
if (strlen($newBio) > 150) {
// Si c'est trop long, coupe ou renvoie une erreur
// Coupe pour simplifier
$newBio = substr($newBio, 0, 150);
}
$newTeamName = trim($_POST['team_name']);
if (strlen($newTeamName) > 12) $newTeamName = substr($newTeamName, 0, 12); // Limite à 12 carac
if (empty($newTeamName)) $newTeamName = "Victory Team"; // Fallback
// Mise à jour en BDD
try {
$stmt = $pdo->prepare("UPDATE users SET bio = ? WHERE id = ?");
$stmt->execute([$newBio, $_SESSION['user_id']]);
// Mise à jour du nom d'équipe
// Vérifie si l'équipe existe
$checkTeam = $pdo->prepare("SELECT id FROM teams WHERE user_id = ?");
$checkTeam->execute([$_SESSION['user_id']]);
if ($checkTeam->fetch()) {
$stmtTeam = $pdo->prepare("UPDATE teams SET team_name = ? WHERE user_id = ?");
$stmtTeam->execute([$newTeamName, $_SESSION['user_id']]);
} else {
// Création si inexistante (cas rare)
$stmtTeam = $pdo->prepare("INSERT INTO teams (user_id, team_name, formation) VALUES (?, ?, '4-4-2 Diamant')");
$stmtTeam->execute([$_SESSION['user_id'], $newTeamName]);
}
// Succès : on retourne au profil
header("Location: profile.php");
exit;
} catch (PDOException $e) {
// En cas d'erreur technique
die(__('prof_err_update') . " : " . $e->getMessage());
}
}
// Vérifie si propriétaire
$isOwner = isset($_SESSION['user_id']) && ($_SESSION['user_id'] == $profileUser['id']);
$targetUserId = $profileUser['id'];
// Classe CSS pour désactiver le curseur si on n'est pas proprio
$fieldClass = $isOwner ? 'editable-mode' : 'readonly-mode';
// --- STATUT AMI ---
$friendStatus = 'none'; // 'none', 'pending_sent', 'pending_received', 'accepted'
if (isset($_SESSION['user_id']) && !$isOwner) {
$stmtFriend = $pdo->prepare("SELECT sender_id, status FROM friends WHERE (sender_id = ? AND receiver_id = ?) OR (sender_id = ? AND receiver_id = ?)");
$stmtFriend->execute([$_SESSION['user_id'], $profileUser['id'], $profileUser['id'], $_SESSION['user_id']]);
$rel = $stmtFriend->fetch();
if ($rel) {
if ($rel['status'] === 'accepted') {
$friendStatus = 'accepted';
} else {
$friendStatus = ($rel['sender_id'] == $_SESSION['user_id']) ? 'pending_sent' : 'pending_received';
}
}
}
require 'assets/header.php';
require 'assets/footer.php';
# Titre de la page
$pageTitle = $profileUser ? __('prof_title_of') . " " . htmlspecialchars($profileUser['username']) : __('prof_not_found');
$header = new Header("SECTEUR V - " . $pageTitle);
$header->render();
?>
<main class="profile-viewer-main">
<?php if ($errorMsg): ?>
<div class="dashboard-container">
<h1 style="color: #e74c3c;"><?php echo __('prof_err_404'); ?></h1>
<p class="subtitle"><?php echo $errorMsg; ?></p>
<button class="cta-button" onclick="window.history.back()"><?php echo __('prof_back'); ?></button>
</div>
<?php else: ?>
<?php
// Data Prep
$displayUsername = htmlspecialchars($profileUser['username']);
$displayAvatar = $profileUser['avatar'] ? htmlspecialchars($profileUser['avatar']) : 'assets/img/default_user.webp';
$joinDate = date('d/m/Y', strtotime($profileUser['created_at'] ?? 'now'));
$elo = $profileUser['elo'];
$grade = $profileUser['grade'];
$bio = $profileUser['bio'];
$matchCount = $profileUser['wins'] + $profileUser['losses'];
$winRate = $matchCount > 0 ? round(($profileUser['wins'] / $matchCount) * 100, 0) : 0;
$gradeConfig = get_grade_config($grade);
// Bio check
$displayBio = empty($bio) ? __('prof_no_bio') : htmlspecialchars($bio);
$bioClass = empty($bio) ? "empty-bio" : "";
?>
<div class="osu-layout">
<div class="osu-profile-header">
<div class="header-avatar-section">
<img src="<?php echo $displayAvatar; ?>" alt="<?php echo $displayUsername; ?>" class="osu-avatar" style="border: 4px solid <?php echo $gradeConfig['color']; ?>; box-shadow: 0 0 10px <?php echo $gradeConfig['color']; ?>;">
</div>
<div class="header-info-section">
<div class="name-row">
<h1 class="osu-username" title="<?php echo htmlspecialchars($profileUser['username']); ?>">
<?php echo $profileUser['username']; ?>
</h1>
<?php echo display_grade_badge($grade); ?>
</div>
<div class="badges-row">
<div class="badge-pill tooltip" data-tooltip="<?php echo __('prof_verified'); ?>">
<i class="fas fa-check-circle"></i> <?php echo __('prof_verified_badge'); ?>
</div>
<div class="badge-pill">
<i class="fas fa-calendar-alt"></i> <?php echo $joinDate; ?>
</div>
</div>
<?php if (isset($_SESSION['user_id']) && !$isOwner): ?>
<div>
<?php if ($friendStatus === 'none'): ?>
<button onclick="handleFriendAction(<?php echo $profileUser['id']; ?>, 'send').then(() => location.reload());" class="ghost-btn" style="padding: 5px 10px; font-size: 0.8rem; color:#2ecc71; border-color:#e74c3c;"><i class="fas fa-user-plus"></i> <?php echo __('prof_add_friend'); ?></button>
<?php elseif ($friendStatus === 'pending_sent'): ?>
<button class="ghost-btn" style="padding: 5px 10px; font-size: 0.8rem; cursor: default;" disabled><i class="fas fa-clock"></i> <?php echo __('prof_pending_friend'); ?></button>
<?php elseif ($friendStatus === 'pending_received'): ?>
<button onclick="handleFriendAction(<?php echo $profileUser['id']; ?>, 'accept').then(() => location.reload());" class="ghost-btn" style="padding: 5px 10px; font-size: 0.8rem; color:#2ecc71; border-color:#e74c3c;"><i class="fas fa-user-check"></i> <?php echo __('prof_accept_friend'); ?></button>
<?php elseif ($friendStatus === 'accepted'): ?>
<button onclick="if(confirm('<?php echo addslashes(__('prof_confirm_remove')); ?>')) { handleFriendAction(<?php echo $profileUser['id']; ?>, 'remove').then(() => location.reload()); }" class="ghost-btn" style="padding: 5px 10px; font-size: 0.8rem; color:#e74c3c; border-color:#e74c3c;"><i class="fas fa-user-times"></i> <?php echo __('prof_remove_friend'); ?></button>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="bio-row">
<p class="osu-bio <?php echo $bioClass; ?>"><?php echo $displayBio; ?></p>
<?php if ($isOwner): ?>
<button class="mini-edit-btn" onclick="openEditModal()" title="<?php echo __('prof_edit_bio'); ?>">
<i class="fas fa-pencil-alt"></i>
</button>
<?php endif; ?>
</div>
</div>
<div class="header-stats-section">
<div class="stat-box">
<span class="stat-value"><?php echo $elo; ?></span>
<span class="stat-label"><?php echo __('prof_stat_edp'); ?></span>
</div>
<div class="stat-box">
<span class="stat-value"><?php echo $matchCount; ?></span> <span class="stat-label"><?php echo __('prof_stat_matches'); ?></span>
</div>
<div class="stat-box">
<span class="stat-value"><?php echo $winRate; ?>%</span> <span class="stat-label"><?php echo __('prof_stat_winrate'); ?></span>
</div>
</div>
</div>
<div class="osu-body-section">
<?php
$formationsMap = [
'4-4-2 Diamant' => '4-4-2-diamant',
'4-4-2 Boîte' => '4-4-2-boite',
'3-5-2 Liberté' => '3-5-2-liberte',
'4-3-3 Triangle' => '4-3-3-triangle',
'4-3-3 Delta' => '4-3-3-delta',
'4-5-1 Équilibré' => '4-5-1-equilibre',
'3-6-1 Hexa' => '3-6-1-hexa',
'5-4-1 Double Volante'=> '5-4-1-double-volante'
];
$currentClass = $formationsMap[$savedFormation] ?? '4-4-2-diamant';
?>
<p class="section-title"><?php echo __('prof_team_title'); ?></p>
<div class="team-header">
<div class="team-info-left">
<h2 class="team-name-title">
<?php echo htmlspecialchars($teamName); ?>
<?php if ($isOwner): ?>
<button class="mini-edit-btn" onclick="openEditModal()" title="<?php echo __('prof_change_team_name'); ?>">
<i class="fas fa-pencil-alt"></i>
</button>
<?php endif; ?>
</h2>
<div class="team-meta">
<div class="formation-selector-wrapper">
<span class="formation-tag" id="formationDisplay">
<i class="fas fa-chess-board"></i>
<span id="formationLabelText"><?php echo htmlspecialchars(__($savedFormation)); ?></span>
<?php if ($isOwner): ?>
<i class="fas fa-pencil-alt" style="margin-left: 8px; font-size: 0.8em; opacity: 0.7;"></i>
<?php endif; ?>
</span>
<?php if ($isOwner): ?>
<select id="formationSelect" onchange="changeFormation(this)" class="ghost-select" title="<?php echo __('prof_change_formation'); ?>">
<?php
foreach($formationsMap as $name => $cssClass) {
$isSelected = ($name === $savedFormation) ? 'selected' : '';
echo "<option value='$name' data-class='$cssClass' $isSelected>" . htmlspecialchars(__($name)) . "</option>";
}
?>
</select>
<?php endif; ?>
</div>
</div>
</div>
<div class="team-coach-right">
<div class="player-slot coach-slot tooltip <?php echo $isOwner ? '' : 'is-readonly'; ?>"
data-tooltip="<?php echo __('prof_no_coach'); ?>"
<?php echo $isOwner ? "onclick=\"openSelector('coach')\"" : ""; ?>
id="slot-display-coach">
<div class="empty-state"><i class="fas fa-user-tie"></i></div>
</div>
</div>
</div>
</div>
<div class="builder-container">
<div class="soccer-field <?php echo $fieldClass; ?> formation-<?php echo $currentClass; ?>" id="field-container">
<?php
function renderSlot($id, $label, $isOwner) {
$onclick = $isOwner ? "onclick=\"openSelector('$id')\"" : "";
$icon = $isOwner ? '<i class="fas fa-plus"></i>' : '';
$tooltipText = __('prof_empty_slot');
echo "<div class=\"player-slot tooltip\" data-tooltip=\"$tooltipText\" $onclick id=\"slot-display-$id\" data-slot=\"$id\">
<div class=\"empty-state\">$icon</div>
<span class=\"position-label\">$label</span>
</div>";
}
renderSlot('1', 'GK', $isOwner);
renderSlot('2', 'DF', $isOwner);
renderSlot('3', 'DF', $isOwner);
renderSlot('4', 'DF', $isOwner);
renderSlot('5', 'DF', $isOwner);
renderSlot('6', 'MF', $isOwner);
renderSlot('7', 'MF', $isOwner);
renderSlot('8', 'MF', $isOwner);
renderSlot('9', 'MF', $isOwner);
renderSlot('10', 'FW', $isOwner);
renderSlot('11', 'FW', $isOwner);
?>
</div>
</div>
</div>
</div> <?php endif; ?>
<div id="playerSelectorModal" onclick="if(event.target === this) closeSelector()">
<div class="modal-box-team">
<button class="close-btn" onclick="closeSelector()">×</button>
<h3 id="modalTitle"><?php echo __('prof_choose_player'); ?></h3>
<input type="text" id="playerSearchInput" placeholder="<?php echo __('prof_search_player'); ?>">
<div id="searchResults" class="results-grid">
</div>
</div>
</div>
</main>
<div id="editModal" class="modal-overlay" onclick="closeEditModal(event)">
<div class="modal-box">
<div class="modal-header">
<i class="fas fa-edit"></i> <?php echo __('prof_update_folder'); ?>
</div>
<form action="" method="POST">
<div class="modal-body">
<div class="form-group">
<label for="bio-input" class="form-label"><?php echo __('prof_bio_label'); ?></label>
<textarea
name="bio"
id="bio-input"
class="edit-textarea"
maxlength="150"
oninput="updateCharCount(this)"
placeholder="<?php echo __('prof_bio_placeholder'); ?>"><?php echo htmlspecialchars($profileUser['bio'] ?? ''); ?></textarea>
<div class="char-count-wrapper">
<span id="char-count">0</span>/150
</div>
</div>
<div class="form-group">
<label for="team-name-input" class="form-label"><?php echo __('prof_team_name_label'); ?></label>
<div class="input-wrapper">
<i class="fas fa-shield-alt"></i>
<input type="text"
name="team_name"
id="team-name-input"
value="<?php echo htmlspecialchars($teamName); ?>"
maxlength="12"
required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="other-button"><?php echo __('prof_save'); ?></button>
<button type="button" class="ghost-btn" onclick="closeEditModal(null)"><?php echo __('prof_cancel'); ?></button>
</div>
</form>
</div>
</div>
<?php
$footer = new Footer('profile-footer');
$footer->render();
?>
<script>
const CONFIG_TEAM = {
targetUserId: <?php echo $targetUserId; ?>,
isOwner: <?php echo $isOwner ? 'true' : 'false'; ?>,
currentFormation: "<?php echo htmlspecialchars($savedFormation); ?>"
};
// RPC Discord - Affiche que l'on est sur un profil
if (window.secteurV) {
window.secteurV.sendRPCData({
details: "<?php echo addslashes(__('rpc_profile_details')); ?>",
state: "<?php echo addslashes(__('rpc_profile_state')) . ' ' . addslashes($targetUsername); ?>"
});
}
</script>
</body>
</html>