edit.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Vue d'édition d'un projet existant
  4. */
  5. include __DIR__ . '/../partials/header.php';
  6. // Variables attendues: $map (objet Map), $templates (array), $templateId, $radiusVal
  7. $mapObj = $map ?? null;
  8. $mapName = $mapObj ? $mapObj->getName() : '';
  9. $mapWidth = $mapObj ? $mapObj->getWidth() : 10;
  10. $mapHeight = $mapObj ? $mapObj->getHeight() : 10;
  11. $mapDescription = '';
  12. if (!empty($mapObj) && method_exists($mapObj, 'getDescription')) {
  13. $mapDescription = $mapObj->getDescription();
  14. }
  15. ?>
  16. <main class="main-content">
  17. <div class="container-fluid">
  18. <div class="row justify-content-center">
  19. <div class="col-lg-8 col-xl-6">
  20. <div class="d-flex align-items-center mb-4">
  21. <div>
  22. <h1 class="h3 mb-0">
  23. <i class="bi bi-pencil-square me-2"></i>Modifier le projet
  24. </h1>
  25. <p class="text-muted mb-0">Mettez à jour les paramètres de la carte</p>
  26. </div>
  27. </div>
  28. <div class="card">
  29. <div class="card-header">
  30. <h5 class="card-title mb-0">Configuration</h5>
  31. </div>
  32. <div class="card-body">
  33. <form id="editProjectForm" action="/projects/update" method="POST">
  34. <input type="hidden" name="id" value="<?php echo htmlspecialchars($mapId ?? ''); ?>">
  35. <div class="mb-3">
  36. <label for="mapName" class="form-label">Nom de la carte</label>
  37. <input type="text" class="form-control" id="mapName" name="name" required value="<?php echo htmlspecialchars($mapName); ?>">
  38. </div>
  39. <div class="mb-3">
  40. <label class="form-label">Taille (rayon hexagonal)</label>
  41. <select id="hexRadius" class="form-select">
  42. <?php for ($r = 1; $r <= 15; $r++):
  43. $count = 1 + 3 * $r * ($r + 1);
  44. $sel = ($radiusVal ?? 2) == $r ? ' selected' : '';
  45. ?>
  46. <option value="<?php echo $r; ?>"<?php echo $sel; ?>>Rayon <?php echo $r; ?> (<?php echo $count; ?> cases)</option>
  47. <?php endfor; ?>
  48. </select>
  49. <!-- Valeur cachée envoyée au serveur (le select est purement UX) -->
  50. <input type="hidden" id="radiusInput" name="radius" value="<?php echo htmlspecialchars($radiusVal ?? 2); ?>">
  51. <!-- Aperçu SVG (comme sur la page de création) -->
  52. <div id="hexPreviewContainer" class="mb-2 mt-3">
  53. <label class="form-label small">Aperçu</label>
  54. <div id="hexPreview" style="width:100%;height:140px;border:1px solid #e9ecef;background:#fafafa;display:flex;align-items:center;justify-content:center;"></div>
  55. </div>
  56. </div>
  57. <div class="mb-3">
  58. <label for="mapDescription" class="form-label">Description</label>
  59. <textarea id="mapDescription" name="description" class="form-control" rows="3"><?php echo htmlspecialchars($mapDescription ?? ''); ?></textarea>
  60. </div>
  61. <div class="mb-3">
  62. <label for="mapTemplate" class="form-label">Modèle</label>
  63. <select id="mapTemplate" class="form-select" name="template" required>
  64. <option value="" disabled>Choisissez un modèle</option>
  65. <?php
  66. if (!empty($templates) && is_array($templates)) {
  67. foreach ($templates as $tid => $tmeta) {
  68. if (!in_array($tid, ['neutral','rural','urban'])) continue;
  69. $sel = ($templateId ?? '') === $tid ? ' selected' : '';
  70. echo '<option value="' . htmlspecialchars($tmeta['id']) . '"' . $sel . '>' . htmlspecialchars($tmeta['name']) . '</option>';
  71. }
  72. }
  73. ?>
  74. </select>
  75. </div>
  76. <!-- Préparer et injecter les tileDefinitions côté serveur -->
  77. <?php
  78. $tilesExport = [];
  79. if (!empty($templates) && is_array($templates)) {
  80. foreach ($templates as $tid => $tmeta) {
  81. if (empty($tmeta['class'])) continue;
  82. $class = $tmeta['class'];
  83. try {
  84. if (method_exists($class, 'tileDefinitions')) {
  85. $defs = $class::tileDefinitions();
  86. $tilesExport[$tid] = $defs;
  87. }
  88. } catch (Throwable $e) {
  89. $tilesExport[$tid] = [];
  90. }
  91. }
  92. }
  93. ?>
  94. <script id="templateTilesData" type="application/json">
  95. <?= json_encode($tilesExport, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) ?>
  96. </script>
  97. <!-- Aperçu du modèle sélectionné (title/description + tiles) -->
  98. <div id="templatePreview" class="mb-4" style="display: none;">
  99. <div class="card bg-light">
  100. <div class="card-body text-center">
  101. <div id="templateImage" class="mb-2"></div>
  102. <h6 id="templateTitle"></h6>
  103. <p id="templateDescription" class="text-muted small mb-2"></p>
  104. <div id="templateTiles" class="d-flex gap-2 justify-content-center flex-wrap"></div>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="d-flex gap-2 justify-content-end">
  109. <a href="/projects" class="btn btn-outline-secondary">Annuler</a>
  110. <button type="submit" class="btn btn-primary">Enregistrer</button>
  111. </div>
  112. </form>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. </main>
  119. <script src="/assets/js/pages/new-project.js"></script>
  120. <?php include __DIR__ . '/../partials/footer.php'; ?>