Files
sae_r301_g12/codeigniter-develop/application/views/formulaire_ajout.php
T

113 lines
6.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
$est_modification = isset($jeu);
$action_url = $est_modification ? site_url('jeux/mettre_a_jour/' . $jeu['id']) : site_url('jeux/sauvegarder');
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title><?= $est_modification ? 'Modifier le jeu' : 'Ajouter un nouveau jeu' ?></title>
<style>
/* === LE CSS POUR UN BEAU FORMULAIRE PROPRE === */
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f4f7f6; color: #333; margin: 0; padding: 20px; }
.container { max-width: 700px; margin: 40px auto; background: #fff; padding: 40px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
.back-link { display: inline-block; background: #ecf0f1; padding: 8px 15px; border-radius: 5px; color: #2c3e50; text-decoration: none; margin-bottom: 25px; font-weight: bold; transition: background 0.3s; }
.back-link:hover { background: #bdc3c7; }
h2 { color: #2c3e50; border-bottom: 2px solid #ecf0f1; padding-bottom: 10px; margin-bottom: 30px; margin-top: 0; }
h3 { color: #34495e; font-size: 18px; margin-top: 30px; border-bottom: 1px solid #eee; padding-bottom: 5px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; color: #34495e; }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea { width: 100%; padding: 12px; border: 1px solid #bdc3c7; border-radius: 4px; font-size: 16px; box-sizing: border-box; outline: none; font-family: inherit; transition: border-color 0.3s; }
.form-group input:focus, .form-group textarea:focus { border-color: #3498db; box-shadow: 0 0 5px rgba(52, 152, 219, 0.3); }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 15px; margin-top: 15px; }
.checkbox-item { background: #f8f9fa; padding: 10px 15px; border-radius: 6px; border: 1px solid #e0e0e0; font-size: 14px; cursor: pointer; transition: background 0.2s; display: flex; align-items: center; gap: 8px; }
.checkbox-item:hover { background: #eef2f5; }
.checkbox-item input[type="checkbox"] { cursor: pointer; width: 16px; height: 16px; }
.btn-submit { display: block; background-color: #2ecc71; color: white; padding: 15px 25px; border: none; border-radius: 5px; font-size: 18px; font-weight: bold; cursor: pointer; transition: background 0.3s; width: 100%; margin-top: 40px; text-align: center; }
.btn-submit:hover { background-color: #27ae60; }
.info-text { color: #7f8c8d; font-size: 13px; font-style: italic; margin-top: 5px; display: block; }
</style>
</head>
<body>
<div class="container">
<a href="<?= site_url('jeux/lister') ?>" class="back-link">⬅ Retour à la liste des jeux</a>
<h2><?= $est_modification ? '✏️ Modifier le jeu' : '➕ Ajouter un nouveau jeu' ?></h2>
<form action="<?= $action_url ?>" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Nom du jeu :</label>
<input type="text" id="name" name="name" required value="<?= $est_modification ? html_escape($jeu['name']) : '' ?>" placeholder="Ex: Elden Ring">
</div>
<div class="form-group">
<label for="releaseYear">Année de sortie :</label>
<input type="number" id="releaseYear" name="releaseYear" required value="<?= $est_modification ? html_escape($jeu['releaseYear']) : '' ?>" placeholder="Ex: 2022">
</div>
<div class="form-group">
<label for="developer_name">Développeur :</label>
<input type="text" id="developer_name" name="developer_name" value="<?= $est_modification && !empty($jeu['developer_name']) ? html_escape($jeu['developer_name']) : '' ?>" placeholder="Ex: FromSoftware">
</div>
<div class="form-group">
<label for="price">Prix (en centimes) :</label>
<input type="number" id="price" name="price" value="<?= $est_modification ? html_escape($jeu['price']) : '' ?>" placeholder="Ex: 5999 (pour 59,99 €)">
</div>
<div class="form-group">
<label for="shortDescription">Description courte :</label>
<textarea id="shortDescription" name="shortDescription" rows="5" placeholder="Résumé du jeu..."><?= $est_modification ? html_escape($jeu['shortDescription']) : '' ?></textarea>
</div>
<?php if (!$est_modification): ?>
<div class="form-group">
<label for="poster">Image du jeu (Poster) :</label>
<input type="file" id="poster" name="poster" accept="image/jpeg, image/png">
<span class="info-text">L'image est facultative et ne peut être ajoutée qu'à la création du jeu.</span>
</div>
<?php endif; ?>
<h3>Catégories associées :</h3>
<div class="checkbox-group">
<?php foreach ($categories as $cat): ?>
<?php
$checked = ($est_modification && in_array($cat['id'], $jeu_categories)) ? 'checked' : '';
?>
<label class="checkbox-item">
<input type="checkbox" name="categories[]" value="<?= $cat['id'] ?>" <?= $checked ?>>
<?= html_escape($cat['description']) ?>
</label>
<?php endforeach; ?>
</div>
<h3>Genres associés :</h3>
<div class="checkbox-group">
<?php foreach ($genres as $gen): ?>
<?php
$checked = ($est_modification && in_array($gen['id'], $jeu_genres)) ? 'checked' : '';
?>
<label class="checkbox-item">
<input type="checkbox" name="genres[]" value="<?= $gen['id'] ?>" <?= $checked ?>>
<?= html_escape($gen['description']) ?>
</label>
<?php endforeach; ?>
</div>
<button type="submit" class="btn-submit"><?= $est_modification ? '💾 Mettre à jour le jeu' : '➕ Ajouter le jeu à la base' ?></button>
</form>
</div>
</body>
</html>