| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- /**
- * Vue d'édition d'un projet existant
- */
- include __DIR__ . '/../partials/header.php';
- // Variables attendues: $map (objet Map), $templates (array), $templateId, $radiusVal
- $mapObj = $map ?? null;
- $mapName = $mapObj ? $mapObj->getName() : '';
- $mapWidth = $mapObj ? $mapObj->getWidth() : 10;
- $mapHeight = $mapObj ? $mapObj->getHeight() : 10;
- $mapDescription = '';
- if (!empty($mapObj) && method_exists($mapObj, 'getDescription')) {
- $mapDescription = $mapObj->getDescription();
- }
- ?>
- <main class="main-content">
- <div class="container-fluid">
- <div class="row justify-content-center">
- <div class="col-lg-8 col-xl-6">
- <div class="d-flex align-items-center mb-4">
- <div>
- <h1 class="h3 mb-0">
- <i class="bi bi-pencil-square me-2"></i>Modifier le projet
- </h1>
- <p class="text-muted mb-0">Mettez à jour les paramètres de la carte</p>
- </div>
- </div>
- <div class="card">
- <div class="card-header">
- <h5 class="card-title mb-0">Configuration</h5>
- </div>
- <div class="card-body">
- <form id="editProjectForm" action="/projects/update" method="POST">
- <input type="hidden" name="id" value="<?php echo htmlspecialchars($mapId ?? ''); ?>">
- <div class="mb-3">
- <label for="mapName" class="form-label">Nom de la carte</label>
- <input type="text" class="form-control" id="mapName" name="name" required value="<?php echo htmlspecialchars($mapName); ?>">
- </div>
- <div class="mb-3">
- <label class="form-label">Taille (rayon hexagonal)</label>
- <select id="hexRadius" class="form-select">
- <?php for ($r = 1; $r <= 15; $r++):
- $count = 1 + 3 * $r * ($r + 1);
- $sel = ($radiusVal ?? 2) == $r ? ' selected' : '';
- ?>
- <option value="<?php echo $r; ?>"<?php echo $sel; ?>>Rayon <?php echo $r; ?> (<?php echo $count; ?> cases)</option>
- <?php endfor; ?>
- </select>
- <!-- Valeur cachée envoyée au serveur (le select est purement UX) -->
- <input type="hidden" id="radiusInput" name="radius" value="<?php echo htmlspecialchars($radiusVal ?? 2); ?>">
- <!-- Aperçu SVG (comme sur la page de création) -->
- <div id="hexPreviewContainer" class="mb-2 mt-3">
- <label class="form-label small">Aperçu</label>
- <div id="hexPreview" style="width:100%;height:140px;border:1px solid #e9ecef;background:#fafafa;display:flex;align-items:center;justify-content:center;"></div>
- </div>
- </div>
- <div class="mb-3">
- <label for="mapDescription" class="form-label">Description</label>
- <textarea id="mapDescription" name="description" class="form-control" rows="3"><?php echo htmlspecialchars($mapDescription ?? ''); ?></textarea>
- </div>
- <div class="mb-3">
- <label for="mapTemplate" class="form-label">Modèle</label>
- <select id="mapTemplate" class="form-select" name="template" required>
- <option value="" disabled>Choisissez un modèle</option>
- <?php
- if (!empty($templates) && is_array($templates)) {
- foreach ($templates as $tid => $tmeta) {
- if (!in_array($tid, ['neutral','rural','urban'])) continue;
- $sel = ($templateId ?? '') === $tid ? ' selected' : '';
- echo '<option value="' . htmlspecialchars($tmeta['id']) . '"' . $sel . '>' . htmlspecialchars($tmeta['name']) . '</option>';
- }
- }
- ?>
- </select>
- </div>
- <!-- Préparer et injecter les tileDefinitions côté serveur -->
- <?php
- $tilesExport = [];
- if (!empty($templates) && is_array($templates)) {
- foreach ($templates as $tid => $tmeta) {
- if (empty($tmeta['class'])) continue;
- $class = $tmeta['class'];
- try {
- if (method_exists($class, 'tileDefinitions')) {
- $defs = $class::tileDefinitions();
- $tilesExport[$tid] = $defs;
- }
- } catch (Throwable $e) {
- $tilesExport[$tid] = [];
- }
- }
- }
- ?>
- <script id="templateTilesData" type="application/json">
- <?= json_encode($tilesExport, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) ?>
- </script>
- <!-- Aperçu du modèle sélectionné (title/description + tiles) -->
- <div id="templatePreview" class="mb-4" style="display: none;">
- <div class="card bg-light">
- <div class="card-body text-center">
- <div id="templateImage" class="mb-2"></div>
- <h6 id="templateTitle"></h6>
- <p id="templateDescription" class="text-muted small mb-2"></p>
- <div id="templateTiles" class="d-flex gap-2 justify-content-center flex-wrap"></div>
- </div>
- </div>
- </div>
- <div class="d-flex gap-2 justify-content-end">
- <a href="/projects" class="btn btn-outline-secondary">Annuler</a>
- <button type="submit" class="btn btn-primary">Enregistrer</button>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- </main>
- <script src="/assets/js/pages/new-project.js"></script>
- <?php include __DIR__ . '/../partials/footer.php'; ?>
|