181 lines
11 KiB
PHP
181 lines
11 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
require_once __DIR__ . '/includes/app.php';
|
||
app_boot();
|
||
require_login();
|
||
|
||
$user = current_user();
|
||
$errors = [];
|
||
|
||
if (is_post()) {
|
||
verify_csrf();
|
||
|
||
$firstName = trim((string) ($_POST['first_name'] ?? ''));
|
||
$lastName = trim((string) ($_POST['last_name'] ?? ''));
|
||
$sport = trim((string) ($_POST['sport_name'] ?? ''));
|
||
$club = trim((string) ($_POST['club_name'] ?? ''));
|
||
$nationality = trim((string) ($_POST['nationality'] ?? ''));
|
||
$position = trim((string) ($_POST['position_name'] ?? ''));
|
||
$jerseyNumber = trim((string) ($_POST['jersey_number'] ?? ''));
|
||
$status = trim((string) ($_POST['status'] ?? 'actif'));
|
||
$joinedOn = trim((string) ($_POST['joined_on'] ?? ''));
|
||
$matches = (int) ($_POST['matches_played'] ?? 0);
|
||
$goals = (int) ($_POST['goals_scored'] ?? 0);
|
||
$assists = (int) ($_POST['assists_count'] ?? 0);
|
||
$awards = trim((string) ($_POST['awards'] ?? ''));
|
||
$careerNote = trim((string) ($_POST['career_note'] ?? ''));
|
||
|
||
if ($firstName === '' || $lastName === '') {
|
||
$errors[] = 'Le prénom et le nom du sportif sont obligatoires.';
|
||
}
|
||
if ($sport === '') {
|
||
$errors[] = 'Le type de sport est obligatoire.';
|
||
}
|
||
if ($club === '') {
|
||
$errors[] = 'Le club actuel est obligatoire.';
|
||
}
|
||
if (!in_array($status, ['actif', 'blesse', 'suspendu', 'retraite'], true)) {
|
||
$errors[] = 'Le statut est invalide.';
|
||
}
|
||
if ($jerseyNumber !== '' && !ctype_digit($jerseyNumber)) {
|
||
$errors[] = 'Le numéro de maillot doit être numérique.';
|
||
}
|
||
|
||
if (!$errors) {
|
||
$stmt = db()->prepare(
|
||
'INSERT INTO athletes (user_id, first_name, last_name, sport_name, club_name, nationality, position_name, jersey_number, status, joined_on, matches_played, goals_scored, assists_count, awards, career_note)
|
||
VALUES (:user_id, :first_name, :last_name, :sport_name, :club_name, :nationality, :position_name, :jersey_number, :status, :joined_on, :matches_played, :goals_scored, :assists_count, :awards, :career_note)'
|
||
);
|
||
$stmt->bindValue(':user_id', (int) $user['id'], PDO::PARAM_INT);
|
||
$stmt->bindValue(':first_name', $firstName);
|
||
$stmt->bindValue(':last_name', $lastName);
|
||
$stmt->bindValue(':sport_name', $sport);
|
||
$stmt->bindValue(':club_name', $club);
|
||
$stmt->bindValue(':nationality', $nationality !== '' ? $nationality : null);
|
||
$stmt->bindValue(':position_name', $position !== '' ? $position : null);
|
||
$stmt->bindValue(':jersey_number', $jerseyNumber !== '' ? (int) $jerseyNumber : null, $jerseyNumber !== '' ? PDO::PARAM_INT : PDO::PARAM_NULL);
|
||
$stmt->bindValue(':status', $status);
|
||
$stmt->bindValue(':joined_on', $joinedOn !== '' ? $joinedOn : null);
|
||
$stmt->bindValue(':matches_played', max(0, $matches), PDO::PARAM_INT);
|
||
$stmt->bindValue(':goals_scored', max(0, $goals), PDO::PARAM_INT);
|
||
$stmt->bindValue(':assists_count', max(0, $assists), PDO::PARAM_INT);
|
||
$stmt->bindValue(':awards', $awards !== '' ? $awards : null);
|
||
$stmt->bindValue(':career_note', $careerNote !== '' ? $careerNote : null);
|
||
$stmt->execute();
|
||
|
||
$id = (int) db()->lastInsertId();
|
||
set_flash('success', 'Sportif créé avec succès.');
|
||
redirect('athlete.php?id=' . $id);
|
||
}
|
||
}
|
||
|
||
render_header('Ajouter un sportif', ['description' => 'Créer une nouvelle fiche sportive dans le registre RJLRESAKA.']);
|
||
?>
|
||
<main class="container-xxl py-5">
|
||
<div class="row g-4 align-items-start">
|
||
<div class="col-lg-4">
|
||
<div class="panel-card p-4 sticky-form-card">
|
||
<p class="section-kicker mb-1">Nouveau profil</p>
|
||
<h1 class="h3 mb-3">Ajouter un sportif</h1>
|
||
<p class="text-secondary mb-0">Créez une fiche complète avec club actuel, indicateurs de performance et note de parcours.</p>
|
||
</div>
|
||
</div>
|
||
<div class="col-lg-8">
|
||
<div class="panel-card p-4 p-lg-5">
|
||
<?php if ($errors): ?>
|
||
<div class="alert alert-danger" role="alert">
|
||
<ul class="mb-0 ps-3">
|
||
<?php foreach ($errors as $error): ?>
|
||
<li><?= e($error) ?></li>
|
||
<?php endforeach; ?>
|
||
</ul>
|
||
</div>
|
||
<?php endif; ?>
|
||
<form method="post" class="vstack gap-4">
|
||
<input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>">
|
||
<section>
|
||
<h2 class="h5 mb-3">Identité</h2>
|
||
<div class="row g-3">
|
||
<div class="col-md-6">
|
||
<label class="form-label" for="first_name">Prénom</label>
|
||
<input class="form-control" id="first_name" name="first_name" value="<?= old('first_name') ?>" required>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<label class="form-label" for="last_name">Nom</label>
|
||
<input class="form-control" id="last_name" name="last_name" value="<?= old('last_name') ?>" required>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<label class="form-label" for="nationality">Nationalité</label>
|
||
<input class="form-control" id="nationality" name="nationality" value="<?= old('nationality') ?>">
|
||
</div>
|
||
<div class="col-md-6">
|
||
<label class="form-label" for="position_name">Poste / spécialité</label>
|
||
<input class="form-control" id="position_name" name="position_name" value="<?= old('position_name') ?>">
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section>
|
||
<h2 class="h5 mb-3">Affectation sportive</h2>
|
||
<div class="row g-3">
|
||
<div class="col-md-6">
|
||
<label class="form-label" for="sport_name">Sport</label>
|
||
<input class="form-control" id="sport_name" name="sport_name" value="<?= old('sport_name') ?>" placeholder="Football, Basketball..." required>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<label class="form-label" for="club_name">Club actuel</label>
|
||
<input class="form-control" id="club_name" name="club_name" value="<?= old('club_name') ?>" required>
|
||
</div>
|
||
<div class="col-md-4">
|
||
<label class="form-label" for="jersey_number">N° maillot</label>
|
||
<input class="form-control" id="jersey_number" name="jersey_number" value="<?= old('jersey_number') ?>" inputmode="numeric">
|
||
</div>
|
||
<div class="col-md-4">
|
||
<label class="form-label" for="status">Statut</label>
|
||
<select class="form-select" id="status" name="status">
|
||
<?php foreach (['actif' => 'Actif', 'blesse' => 'Blessé', 'suspendu' => 'Suspendu', 'retraite' => 'Retraité'] as $value => $label): ?>
|
||
<option value="<?= e($value) ?>" <?= (($_POST['status'] ?? 'actif') === $value) ? 'selected' : '' ?>><?= e($label) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div class="col-md-4">
|
||
<label class="form-label" for="joined_on">Date d’arrivée</label>
|
||
<input class="form-control" id="joined_on" type="date" name="joined_on" value="<?= old('joined_on') ?>">
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section>
|
||
<h2 class="h5 mb-3">Performance actuelle</h2>
|
||
<div class="row g-3">
|
||
<div class="col-md-4">
|
||
<label class="form-label" for="matches_played">Matchs joués</label>
|
||
<input class="form-control" id="matches_played" type="number" min="0" name="matches_played" value="<?= old('matches_played', '0') ?>">
|
||
</div>
|
||
<div class="col-md-4">
|
||
<label class="form-label" for="goals_scored">Buts / points</label>
|
||
<input class="form-control" id="goals_scored" type="number" min="0" name="goals_scored" value="<?= old('goals_scored', '0') ?>">
|
||
</div>
|
||
<div class="col-md-4">
|
||
<label class="form-label" for="assists_count">Passes décisives</label>
|
||
<input class="form-control" id="assists_count" type="number" min="0" name="assists_count" value="<?= old('assists_count', '0') ?>">
|
||
</div>
|
||
<div class="col-12">
|
||
<label class="form-label" for="awards">Distinctions</label>
|
||
<input class="form-control" id="awards" name="awards" value="<?= old('awards') ?>" placeholder="Capitaine, MVP, record personnel...">
|
||
</div>
|
||
<div class="col-12">
|
||
<label class="form-label" for="career_note">Note de parcours</label>
|
||
<textarea class="form-control" id="career_note" name="career_note" rows="5" placeholder="Résumé du parcours professionnel, transferts, progression..."><?= e($_POST['career_note'] ?? '') ?></textarea>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<div class="d-flex flex-wrap gap-2 justify-content-between align-items-center border-top pt-4">
|
||
<p class="text-secondary small mb-0">Les données sont enregistrées en base MySQL via PDO et requêtes préparées.</p>
|
||
<button class="btn btn-dark" type="submit">Enregistrer la fiche</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</main>
|
||
<?php render_footer(); ?>
|