V1.1.4
This commit is contained in:
parent
1fd504ade9
commit
20d4eb5497
215
index.php
215
index.php
@ -42,6 +42,7 @@ $scan_reference_rows = [];
|
||||
$scan_reference_max_occurrence = 0;
|
||||
$scan_reference_error = null;
|
||||
$ship_preset_rows = [];
|
||||
$ship_preset_manufacturers = [];
|
||||
$ship_preset_error = null;
|
||||
|
||||
try {
|
||||
@ -112,15 +113,26 @@ try {
|
||||
);
|
||||
|
||||
foreach ($stmt_ship_presets->fetchAll() as $row) {
|
||||
$ship_name = trim((string) ($row['cl_scpreset_name'] ?? '')) ?: 'Vaisseau inconnu';
|
||||
$manufacturer = trim((string) ($row['cl_scpreset_manufacturer'] ?? '')) ?: 'Manufacture inconnue';
|
||||
$manufacturer_key = function_exists('mb_strtolower')
|
||||
? mb_strtolower($manufacturer, 'UTF-8')
|
||||
: strtolower($manufacturer);
|
||||
|
||||
$ship_preset_manufacturers[$manufacturer_key] = $manufacturer;
|
||||
|
||||
$ship_preset_rows[] = [
|
||||
'id' => (string) ($row['cl_scpreset_id'] ?? ''),
|
||||
'name' => trim((string) ($row['cl_scpreset_name'] ?? '')),
|
||||
'manufacturer' => trim((string) ($row['cl_scpreset_manufacturer'] ?? '')),
|
||||
'name' => $ship_name,
|
||||
'manufacturer' => $manufacturer,
|
||||
'creator' => trim((string) ($row['cl_scpreset_creator'] ?? '')) ?: 'Inconnu',
|
||||
'description' => trim((string) ($row['cl_scpreset_description'] ?? '')) ?: 'Aucune description disponible pour ce preset.',
|
||||
'link' => trim((string) ($row['cl_scpreset_link'] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
natcasesort($ship_preset_manufacturers);
|
||||
$ship_preset_manufacturers = array_values($ship_preset_manufacturers);
|
||||
} catch (Throwable $e) {
|
||||
$ship_preset_error = 'Impossible de charger les presets de vaisseaux pour le moment.';
|
||||
}
|
||||
@ -374,7 +386,6 @@ try {
|
||||
padding: 22px 26px 26px;
|
||||
}
|
||||
|
||||
.ship-presets-intro,
|
||||
.ship-presets-empty,
|
||||
.ship-presets-error {
|
||||
margin: 0 0 18px;
|
||||
@ -384,10 +395,6 @@ try {
|
||||
text-align: left !important;
|
||||
}
|
||||
|
||||
.ship-presets-intro {
|
||||
background: rgba(162, 155, 120, 0.12);
|
||||
border: 1px solid rgba(162, 155, 120, 0.18);
|
||||
}
|
||||
|
||||
.ship-presets-empty {
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
@ -400,6 +407,64 @@ try {
|
||||
color: #ffbdbd;
|
||||
}
|
||||
|
||||
.ship-presets-filter-bar {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 16px;
|
||||
margin: 0 0 18px;
|
||||
padding: 14px 16px;
|
||||
border-radius: 14px;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border: 1px solid rgba(162, 155, 120, 0.18);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.ship-presets-filter-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 240px;
|
||||
flex: 1 1 240px;
|
||||
}
|
||||
|
||||
.ship-presets-filter-label {
|
||||
margin: 0;
|
||||
font-size: 0.8em;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
}
|
||||
|
||||
.ship-presets-filter-select {
|
||||
width: 100%;
|
||||
padding: 10px 14px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid rgba(162, 155, 120, 0.3);
|
||||
background: rgba(10, 14, 21, 0.95);
|
||||
color: #ffffff;
|
||||
font-size: 0.92em;
|
||||
}
|
||||
|
||||
.ship-presets-filter-select:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.ship-presets-filter-select:focus-visible {
|
||||
outline: 2px solid rgba(162, 155, 120, 0.45);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.ship-presets-filter-status {
|
||||
margin: 0 0 0 auto;
|
||||
font-size: 0.85em;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
flex: 1 1 220px;
|
||||
text-align: right;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.ship-presets-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
@ -482,6 +547,10 @@ try {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.ship-preset-card.is-hidden-by-ship-filter {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.modal-scan-reference,
|
||||
.modal-ship-presets {
|
||||
@ -503,6 +572,15 @@ try {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.ship-presets-filter-bar {
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.ship-presets-filter-status {
|
||||
margin-left: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.ship-presets-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
@ -601,10 +679,27 @@ try {
|
||||
<?php elseif ($ship_preset_rows === []): ?>
|
||||
<p class="ship-presets-empty">Aucun preset de vaisseau n'est enregistré pour le moment.</p>
|
||||
<?php else: ?>
|
||||
<p class="ship-presets-intro"></p>
|
||||
<div class="ship-presets-grid">
|
||||
<div class="ship-presets-filter-bar">
|
||||
<div class="ship-presets-filter-group">
|
||||
<label class="ship-presets-filter-label" for="shipPresetManufacturerFilter">Filtrer par manufacture</label>
|
||||
<select id="shipPresetManufacturerFilter" class="ship-presets-filter-select">
|
||||
<option value="">Toutes les manufactures</option>
|
||||
<?php foreach ($ship_preset_manufacturers as $ship_preset_manufacturer): ?>
|
||||
<option value="<?php echo htmlspecialchars($ship_preset_manufacturer, ENT_QUOTES, 'UTF-8'); ?>"><?php echo htmlspecialchars($ship_preset_manufacturer, ENT_QUOTES, 'UTF-8'); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="ship-presets-filter-group">
|
||||
<label class="ship-presets-filter-label" for="shipPresetShipFilter">Filtrer par vaisseau</label>
|
||||
<select id="shipPresetShipFilter" class="ship-presets-filter-select" disabled>
|
||||
<option value="">Choisis d'abord une manufacture</option>
|
||||
</select>
|
||||
</div>
|
||||
<p class="ship-presets-filter-status" id="shipPresetFilterStatus"></p>
|
||||
</div>
|
||||
<div class="ship-presets-grid" id="shipPresetsGrid">
|
||||
<?php foreach ($ship_preset_rows as $ship_preset_row): ?>
|
||||
<article class="ship-preset-card">
|
||||
<article class="ship-preset-card" data-manufacturer="<?php echo htmlspecialchars($ship_preset_row['manufacturer'], ENT_QUOTES, 'UTF-8'); ?>" data-ship-name="<?php echo htmlspecialchars($ship_preset_row['name'], ENT_QUOTES, 'UTF-8'); ?>">
|
||||
<div class="ship-preset-card-header">
|
||||
<p class="ship-preset-card-manufacturer"><?php echo htmlspecialchars($ship_preset_row['manufacturer'], ENT_QUOTES, 'UTF-8'); ?></p>
|
||||
<h4 class="ship-preset-card-name"><?php echo htmlspecialchars($ship_preset_row['name'], ENT_QUOTES, 'UTF-8'); ?></h4>
|
||||
@ -858,6 +953,106 @@ try {
|
||||
})();
|
||||
</script>
|
||||
|
||||
<script>
|
||||
(function initShipPresetFilter() {
|
||||
const manufacturerSelect = document.getElementById('shipPresetManufacturerFilter');
|
||||
const shipSelect = document.getElementById('shipPresetShipFilter');
|
||||
const status = document.getElementById('shipPresetFilterStatus');
|
||||
const grid = document.getElementById('shipPresetsGrid');
|
||||
|
||||
if (!manufacturerSelect || !shipSelect || !status || !grid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cards = Array.from(grid.querySelectorAll('.ship-preset-card'));
|
||||
const manufacturerToShips = new Map();
|
||||
|
||||
cards.forEach((card) => {
|
||||
const manufacturer = String(card.dataset.manufacturer || '').trim();
|
||||
const shipName = String(card.dataset.shipName || '').trim();
|
||||
|
||||
if (!manufacturerToShips.has(manufacturer)) {
|
||||
manufacturerToShips.set(manufacturer, new Set());
|
||||
}
|
||||
|
||||
if (shipName !== '') {
|
||||
manufacturerToShips.get(manufacturer).add(shipName);
|
||||
}
|
||||
});
|
||||
|
||||
function setShipOptions(manufacturer) {
|
||||
const previousValue = shipSelect.value;
|
||||
shipSelect.innerHTML = '';
|
||||
|
||||
if (manufacturer === '') {
|
||||
shipSelect.disabled = true;
|
||||
shipSelect.append(new Option("Choisis d'abord une manufacture", ''));
|
||||
shipSelect.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
shipSelect.disabled = false;
|
||||
shipSelect.append(new Option('Tous les vaisseaux de cette manufacture', ''));
|
||||
|
||||
const ships = Array.from(manufacturerToShips.get(manufacturer) || []);
|
||||
ships.sort((a, b) => a.localeCompare(b, 'fr', { sensitivity: 'base' }));
|
||||
|
||||
ships.forEach((shipName) => {
|
||||
shipSelect.append(new Option(shipName, shipName));
|
||||
});
|
||||
|
||||
shipSelect.value = ships.includes(previousValue) ? previousValue : '';
|
||||
}
|
||||
|
||||
function refreshStatus() {
|
||||
const visibleCards = cards.filter((card) => !card.classList.contains('is-hidden-by-ship-filter'));
|
||||
const visibleShips = new Set(
|
||||
visibleCards
|
||||
.map((card) => String(card.dataset.shipName || '').trim())
|
||||
.filter(Boolean)
|
||||
);
|
||||
const selectedManufacturer = manufacturerSelect.value;
|
||||
const selectedShip = shipSelect.value;
|
||||
|
||||
if (selectedManufacturer !== '' && selectedShip !== '') {
|
||||
status.textContent = visibleCards.length + ' preset(s) affiché(s) pour ' + selectedShip + ' chez ' + selectedManufacturer + '.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedManufacturer !== '') {
|
||||
status.textContent = visibleCards.length + ' preset(s) affiché(s) pour ' + visibleShips.size + ' vaisseau(x) chez ' + selectedManufacturer + '.';
|
||||
return;
|
||||
}
|
||||
|
||||
status.textContent = visibleCards.length + ' preset(s) affiché(s) sur ' + cards.length + ' pour ' + visibleShips.size + ' vaisseau(x).';
|
||||
}
|
||||
|
||||
function applyFilter() {
|
||||
const selectedManufacturer = manufacturerSelect.value;
|
||||
const selectedShip = shipSelect.value;
|
||||
|
||||
cards.forEach((card) => {
|
||||
const manufacturer = String(card.dataset.manufacturer || '').trim();
|
||||
const shipName = String(card.dataset.shipName || '').trim();
|
||||
const hideByManufacturer = selectedManufacturer !== '' && manufacturer !== selectedManufacturer;
|
||||
const hideByShip = selectedShip !== '' && shipName !== selectedShip;
|
||||
card.classList.toggle('is-hidden-by-ship-filter', hideByManufacturer || hideByShip);
|
||||
});
|
||||
|
||||
refreshStatus();
|
||||
}
|
||||
|
||||
manufacturerSelect.addEventListener('change', function () {
|
||||
setShipOptions(manufacturerSelect.value);
|
||||
applyFilter();
|
||||
});
|
||||
|
||||
shipSelect.addEventListener('change', applyFilter);
|
||||
setShipOptions(manufacturerSelect.value);
|
||||
applyFilter();
|
||||
})();
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// On ajoute dynamiquement l'origine à l'URL de l'iframe (recommandé par l'API YouTube)
|
||||
(function attachOrigin(){
|
||||
|
||||
284
scpreset.php
284
scpreset.php
@ -21,6 +21,38 @@ $current_session_user = $_SESSION['user'] ?? '';
|
||||
$current_session_role = $_SESSION['role'] ?? 'member';
|
||||
$role_label = ($current_session_role === 'admin') ? 'Administrateur' : 'Membre';
|
||||
|
||||
function normalize_catalog_label(string $value): string {
|
||||
$value = trim($value);
|
||||
return function_exists('mb_strtolower') ? mb_strtolower($value, 'UTF-8') : strtolower($value);
|
||||
}
|
||||
|
||||
function find_preset_ship_relation(PDO $db, int $manufactureId, int $shipId): ?array {
|
||||
if ($manufactureId <= 0 || $shipId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare(
|
||||
"SELECT
|
||||
m.cl_scmanufactures_id,
|
||||
m.cl_scmanufactures_name,
|
||||
v.cl_scvaisseaux_id,
|
||||
v.cl_scvaisseaux_name
|
||||
FROM tbl_scvaisseaux v
|
||||
INNER JOIN tbl_scmanufactures m
|
||||
ON m.cl_scmanufactures_id = v.cl_scvaisseaux_manufacture_id
|
||||
WHERE m.cl_scmanufactures_id = :manufacture_id
|
||||
AND v.cl_scvaisseaux_id = :ship_id
|
||||
LIMIT 1"
|
||||
);
|
||||
$stmt->execute([
|
||||
'manufacture_id' => $manufactureId,
|
||||
'ship_id' => $shipId,
|
||||
]);
|
||||
|
||||
$relation = $stmt->fetch();
|
||||
return $relation ?: null;
|
||||
}
|
||||
|
||||
// Handle POST actions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$submitted_csrf = $_POST['csrf_token'] ?? '';
|
||||
@ -34,28 +66,47 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
// Add preset
|
||||
if ($action === 'add_preset') {
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$manufacturer = trim($_POST['manufacturer'] ?? '');
|
||||
$manufacture_id = (int)($_POST['manufacture_id'] ?? 0);
|
||||
$ship_id = (int)($_POST['ship_id'] ?? 0);
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
$link = trim($_POST['link'] ?? '');
|
||||
$creator = $current_session_user ?: 'Inconnu';
|
||||
$relation = find_preset_ship_relation($db, $manufacture_id, $ship_id);
|
||||
|
||||
if ($name !== '' && $manufacturer !== '' && $link !== '') {
|
||||
if ($relation && $link !== '') {
|
||||
try {
|
||||
$stmt = $db->prepare("INSERT INTO tbl_scpreset (cl_scpreset_name, cl_scpreset_manufacturer, cl_scpreset_description, cl_scpreset_link, cl_scpreset_creator) VALUES (:name, :manufacturer, :description, :link, :creator)");
|
||||
$stmt = $db->prepare("INSERT INTO tbl_scpreset (
|
||||
cl_scpreset_manufacture_id,
|
||||
cl_scpreset_vaisseau_id,
|
||||
cl_scpreset_name,
|
||||
cl_scpreset_manufacturer,
|
||||
cl_scpreset_description,
|
||||
cl_scpreset_link,
|
||||
cl_scpreset_creator
|
||||
) VALUES (
|
||||
:manufacture_id,
|
||||
:ship_id,
|
||||
:name,
|
||||
:manufacturer,
|
||||
:description,
|
||||
:link,
|
||||
:creator
|
||||
)");
|
||||
$stmt->execute([
|
||||
'name' => $name,
|
||||
'manufacturer' => $manufacturer,
|
||||
'manufacture_id' => $relation['cl_scmanufactures_id'],
|
||||
'ship_id' => $relation['cl_scvaisseaux_id'],
|
||||
'name' => $relation['cl_scvaisseaux_name'],
|
||||
'manufacturer' => $relation['cl_scmanufactures_name'],
|
||||
'description' => $description,
|
||||
'link' => $link,
|
||||
'creator' => $creator
|
||||
'creator' => $creator,
|
||||
]);
|
||||
auth_flash_set('success', 'Preset ajouté avec succès.');
|
||||
} catch (PDOException $e) {
|
||||
auth_flash_set('error', 'Erreur lors de l\'ajout : ' . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
auth_flash_set('error', 'Veuillez remplir les champs obligatoires (Nom, Manufacture, Lien).');
|
||||
auth_flash_set('error', 'Veuillez sélectionner une manufacture, un vaisseau valide et renseigner le lien.');
|
||||
}
|
||||
header('Location: scpreset.php');
|
||||
exit;
|
||||
@ -64,27 +115,37 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Update preset
|
||||
if ($action === 'update_preset') {
|
||||
$preset_id = (int)($_POST['preset_id'] ?? 0);
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$manufacturer = trim($_POST['manufacturer'] ?? '');
|
||||
$manufacture_id = (int)($_POST['manufacture_id'] ?? 0);
|
||||
$ship_id = (int)($_POST['ship_id'] ?? 0);
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
$link = trim($_POST['link'] ?? '');
|
||||
$relation = find_preset_ship_relation($db, $manufacture_id, $ship_id);
|
||||
|
||||
if ($preset_id > 0 && $name !== '' && $manufacturer !== '' && $link !== '') {
|
||||
if ($preset_id > 0 && $relation && $link !== '') {
|
||||
try {
|
||||
$stmt = $db->prepare("UPDATE tbl_scpreset SET cl_scpreset_name = :name, cl_scpreset_manufacturer = :manufacturer, cl_scpreset_description = :description, cl_scpreset_link = :link WHERE cl_scpreset_id = :id");
|
||||
$stmt = $db->prepare("UPDATE tbl_scpreset SET
|
||||
cl_scpreset_manufacture_id = :manufacture_id,
|
||||
cl_scpreset_vaisseau_id = :ship_id,
|
||||
cl_scpreset_name = :name,
|
||||
cl_scpreset_manufacturer = :manufacturer,
|
||||
cl_scpreset_description = :description,
|
||||
cl_scpreset_link = :link
|
||||
WHERE cl_scpreset_id = :id");
|
||||
$stmt->execute([
|
||||
'name' => $name,
|
||||
'manufacturer' => $manufacturer,
|
||||
'manufacture_id' => $relation['cl_scmanufactures_id'],
|
||||
'ship_id' => $relation['cl_scvaisseaux_id'],
|
||||
'name' => $relation['cl_scvaisseaux_name'],
|
||||
'manufacturer' => $relation['cl_scmanufactures_name'],
|
||||
'description' => $description,
|
||||
'link' => $link,
|
||||
'id' => $preset_id
|
||||
'id' => $preset_id,
|
||||
]);
|
||||
auth_flash_set('success', 'Preset mis à jour.');
|
||||
} catch (PDOException $e) {
|
||||
auth_flash_set('error', 'Erreur lors de la mise à jour : ' . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
auth_flash_set('error', 'Données invalides.');
|
||||
auth_flash_set('error', 'Données invalides : sélectionne une manufacture, un vaisseau valide et un lien.');
|
||||
}
|
||||
header('Location: scpreset.php');
|
||||
exit;
|
||||
@ -105,9 +166,92 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all presets
|
||||
$stmt_list = $db->query("SELECT * FROM tbl_scpreset ORDER BY cl_scpreset_manufacturer ASC, cl_scpreset_name ASC");
|
||||
$stmt_mans = $db->query("SELECT * FROM tbl_scmanufactures ORDER BY cl_scmanufactures_name ASC");
|
||||
$manufactures = $stmt_mans->fetchAll();
|
||||
|
||||
$stmt_ships = $db->query("SELECT
|
||||
v.cl_scvaisseaux_id,
|
||||
v.cl_scvaisseaux_name,
|
||||
v.cl_scvaisseaux_manufacture_id,
|
||||
m.cl_scmanufactures_name
|
||||
FROM tbl_scvaisseaux v
|
||||
INNER JOIN tbl_scmanufactures m ON m.cl_scmanufactures_id = v.cl_scvaisseaux_manufacture_id
|
||||
ORDER BY m.cl_scmanufactures_name ASC, v.cl_scvaisseaux_name ASC");
|
||||
$ships = $stmt_ships->fetchAll();
|
||||
|
||||
$manufacture_lookup = [];
|
||||
$ships_by_manufacture = [];
|
||||
$ships_by_id = [];
|
||||
$ship_lookup = [];
|
||||
|
||||
foreach ($manufactures as $manufacture) {
|
||||
$manufacture_lookup[normalize_catalog_label($manufacture['cl_scmanufactures_name'])] = (int)$manufacture['cl_scmanufactures_id'];
|
||||
$ships_by_manufacture[(int)$manufacture['cl_scmanufactures_id']] = [];
|
||||
}
|
||||
|
||||
foreach ($ships as $ship) {
|
||||
$manufactureId = (int)$ship['cl_scvaisseaux_manufacture_id'];
|
||||
$shipId = (int)$ship['cl_scvaisseaux_id'];
|
||||
$shipName = $ship['cl_scvaisseaux_name'];
|
||||
$manufacturerName = $ship['cl_scmanufactures_name'];
|
||||
|
||||
$ships_by_manufacture[$manufactureId][] = [
|
||||
'id' => $shipId,
|
||||
'name' => $shipName,
|
||||
];
|
||||
$ships_by_id[$shipId] = [
|
||||
'id' => $shipId,
|
||||
'name' => $shipName,
|
||||
'manufacture_id' => $manufactureId,
|
||||
'manufacturer_name' => $manufacturerName,
|
||||
];
|
||||
$ship_lookup[$manufactureId . '|' . normalize_catalog_label($shipName)] = $shipId;
|
||||
}
|
||||
|
||||
$stmt_list = $db->query("SELECT
|
||||
p.*,
|
||||
m.cl_scmanufactures_name AS relation_manufacturer_name,
|
||||
v.cl_scvaisseaux_name AS relation_ship_name,
|
||||
v.cl_scvaisseaux_manufacture_id AS relation_ship_manufacture_id
|
||||
FROM tbl_scpreset p
|
||||
LEFT JOIN tbl_scmanufactures m ON m.cl_scmanufactures_id = p.cl_scpreset_manufacture_id
|
||||
LEFT JOIN tbl_scvaisseaux v ON v.cl_scvaisseaux_id = p.cl_scpreset_vaisseau_id
|
||||
ORDER BY COALESCE(m.cl_scmanufactures_name, p.cl_scpreset_manufacturer) ASC,
|
||||
COALESCE(v.cl_scvaisseaux_name, p.cl_scpreset_name) ASC");
|
||||
$presets = $stmt_list->fetchAll();
|
||||
|
||||
foreach ($presets as &$preset) {
|
||||
$resolvedManufactureId = (int)($preset['cl_scpreset_manufacture_id'] ?? 0);
|
||||
if ($resolvedManufactureId <= 0) {
|
||||
$manufacturerKey = normalize_catalog_label((string)($preset['cl_scpreset_manufacturer'] ?? ''));
|
||||
if ($manufacturerKey !== '' && isset($manufacture_lookup[$manufacturerKey])) {
|
||||
$resolvedManufactureId = $manufacture_lookup[$manufacturerKey];
|
||||
}
|
||||
}
|
||||
|
||||
$resolvedShipId = (int)($preset['cl_scpreset_vaisseau_id'] ?? 0);
|
||||
if ($resolvedShipId <= 0 && $resolvedManufactureId > 0) {
|
||||
$shipKey = $resolvedManufactureId . '|' . normalize_catalog_label((string)($preset['cl_scpreset_name'] ?? ''));
|
||||
if (isset($ship_lookup[$shipKey])) {
|
||||
$resolvedShipId = $ship_lookup[$shipKey];
|
||||
}
|
||||
}
|
||||
|
||||
$displayManufacturer = $preset['relation_manufacturer_name'] ?: $preset['cl_scpreset_manufacturer'];
|
||||
$displayName = $preset['relation_ship_name'] ?: $preset['cl_scpreset_name'];
|
||||
|
||||
if ($resolvedShipId > 0 && isset($ships_by_id[$resolvedShipId])) {
|
||||
$displayName = $ships_by_id[$resolvedShipId]['name'];
|
||||
$displayManufacturer = $ships_by_id[$resolvedShipId]['manufacturer_name'];
|
||||
$resolvedManufactureId = $ships_by_id[$resolvedShipId]['manufacture_id'];
|
||||
}
|
||||
|
||||
$preset['resolved_manufacture_id'] = $resolvedManufactureId;
|
||||
$preset['resolved_ship_id'] = $resolvedShipId;
|
||||
$preset['display_manufacturer'] = $displayManufacturer;
|
||||
$preset['display_name'] = $displayName;
|
||||
}
|
||||
unset($preset);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
@ -262,6 +406,13 @@ $presets = $stmt_list->fetchAll();
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
.form-control:focus { outline: none; border-color: var(--primary); background: rgba(0, 0, 0, 0.5); }
|
||||
.form-control:disabled { opacity: 0.55; cursor: not-allowed; }
|
||||
.form-help {
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.78rem;
|
||||
color: #8f8f8f;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.modern-table { width: 100%; border-collapse: separate; border-spacing: 0 8px; }
|
||||
.modern-table th { text-align: left; padding: 1rem; font-size: 0.8rem; text-transform: uppercase; color: var(--primary); opacity: 0.7; }
|
||||
@ -348,19 +499,34 @@ $presets = $stmt_list->fetchAll();
|
||||
<div class="side-panel">
|
||||
<section class="glass-card">
|
||||
<h2 id="formTitle">Nouveau Preset</h2>
|
||||
<?php if (empty($manufactures)): ?>
|
||||
<p style="color: var(--danger); font-size: 0.9rem;">Aucune manufacture n'est disponible. Ajoute d'abord une manufacture.</p>
|
||||
<a href="scmanufactures.php" class="btn-modern" style="width: 100%;">Gérer les manufactures</a>
|
||||
<?php elseif (empty($ships)): ?>
|
||||
<p style="color: var(--danger); font-size: 0.9rem;">Aucun vaisseau n'est disponible. Ajoute d'abord au moins un vaisseau lié à une manufacture.</p>
|
||||
<a href="scvaisseaux.php" class="btn-modern" style="width: 100%;">Gérer les vaisseaux</a>
|
||||
<?php else: ?>
|
||||
<form id="presetForm" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token); ?>">
|
||||
<input type="hidden" name="action" id="formAction" value="add_preset">
|
||||
<input type="hidden" name="preset_id" id="presetId" value="">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Nom du Vaisseau</label>
|
||||
<input type="text" name="name" id="presetName" class="form-control" required placeholder="ex: Prospector">
|
||||
<label>Manufacture</label>
|
||||
<select name="manufacture_id" id="presetManufactureId" class="form-control" required>
|
||||
<option value="">- Sélectionner une manufacture -</option>
|
||||
<?php foreach ($manufactures as $m): ?>
|
||||
<option value="<?php echo $m['cl_scmanufactures_id']; ?>"><?php echo htmlspecialchars($m['cl_scmanufactures_name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Manufacture</label>
|
||||
<input type="text" name="manufacturer" id="presetManufacturer" class="form-control" required placeholder="ex: MISC">
|
||||
<label>Vaisseau</label>
|
||||
<select name="ship_id" id="presetShipId" class="form-control" required disabled>
|
||||
<option value="">- Choisissez d'abord une manufacture -</option>
|
||||
</select>
|
||||
<div class="form-help">Le vaisseau affiché dépend de la manufacture choisie. Le nom et la manufacture du preset seront remplis automatiquement.</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@ -376,6 +542,7 @@ $presets = $stmt_list->fetchAll();
|
||||
<button type="submit" id="submitBtn" class="btn-modern" style="width: 100%;">Ajouter</button>
|
||||
<button type="button" id="cancelBtn" class="btn-modern" style="width: 100%; margin-top: 10px; display: none;" onclick="resetForm()">Annuler</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@ -400,8 +567,8 @@ $presets = $stmt_list->fetchAll();
|
||||
<?php foreach ($presets as $p): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<strong style="color: var(--primary); text-transform: uppercase;"><?php echo htmlspecialchars($p['cl_scpreset_name']); ?></strong><br>
|
||||
<span class="manufacturer-text"><?php echo htmlspecialchars($p['cl_scpreset_manufacturer']); ?></span>
|
||||
<strong style="color: var(--primary); text-transform: uppercase;"><?php echo htmlspecialchars($p['display_name']); ?></strong><br>
|
||||
<span class="manufacturer-text"><?php echo htmlspecialchars($p['display_manufacturer']); ?></span>
|
||||
<span class="creator-text">Par <?php echo htmlspecialchars($p['cl_scpreset_creator'] ?: 'Inconnu'); ?></span>
|
||||
</td>
|
||||
<td>
|
||||
@ -417,11 +584,13 @@ $presets = $stmt_list->fetchAll();
|
||||
<button type="button" class="btn-modern btn-mini"
|
||||
onclick='editPreset(<?php echo json_encode([
|
||||
"id" => $p["cl_scpreset_id"],
|
||||
"name" => $p["cl_scpreset_name"],
|
||||
"manufacturer" => $p["cl_scpreset_manufacturer"],
|
||||
"manufacture_id" => $p["resolved_manufacture_id"],
|
||||
"ship_id" => $p["resolved_ship_id"],
|
||||
"name" => $p["display_name"],
|
||||
"manufacturer" => $p["display_manufacturer"],
|
||||
"description" => $p["cl_scpreset_description"],
|
||||
"link" => $p["cl_scpreset_link"]
|
||||
]); ?>)'>
|
||||
], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); ?>)'>
|
||||
Edit
|
||||
</button>
|
||||
<form method="post" onsubmit="return confirm('Supprimer ce preset ?');">
|
||||
@ -444,26 +613,75 @@ $presets = $stmt_list->fetchAll();
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const shipsByManufacture = <?php echo json_encode($ships_by_manufacture, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); ?>;
|
||||
const presetForm = document.getElementById('presetForm');
|
||||
const manufactureSelect = document.getElementById('presetManufactureId');
|
||||
const shipSelect = document.getElementById('presetShipId');
|
||||
|
||||
function populateShipOptions(manufactureId, selectedShipId = '') {
|
||||
if (!shipSelect) {
|
||||
return;
|
||||
}
|
||||
|
||||
shipSelect.innerHTML = '';
|
||||
|
||||
if (!manufactureId || !shipsByManufacture[manufactureId] || shipsByManufacture[manufactureId].length === 0) {
|
||||
shipSelect.disabled = true;
|
||||
shipSelect.innerHTML = '<option value="">- Choisissez d\'abord une manufacture -</option>';
|
||||
return;
|
||||
}
|
||||
|
||||
shipSelect.disabled = false;
|
||||
shipSelect.innerHTML = '<option value="">- Sélectionner un vaisseau -</option>';
|
||||
|
||||
shipsByManufacture[manufactureId].forEach((ship) => {
|
||||
const option = document.createElement('option');
|
||||
option.value = String(ship.id);
|
||||
option.textContent = ship.name;
|
||||
if (selectedShipId && String(selectedShipId) === String(ship.id)) {
|
||||
option.selected = true;
|
||||
}
|
||||
shipSelect.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
if (manufactureSelect) {
|
||||
manufactureSelect.addEventListener('change', function () {
|
||||
populateShipOptions(this.value, '');
|
||||
});
|
||||
populateShipOptions(manufactureSelect.value, shipSelect ? shipSelect.value : '');
|
||||
}
|
||||
|
||||
function editPreset(data) {
|
||||
if (!presetForm || !manufactureSelect || !shipSelect) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('formAction').value = 'update_preset';
|
||||
document.getElementById('presetId').value = data.id;
|
||||
document.getElementById('presetName').value = data.name;
|
||||
document.getElementById('presetManufacturer').value = data.manufacturer;
|
||||
manufactureSelect.value = data.manufacture_id ? String(data.manufacture_id) : '';
|
||||
populateShipOptions(manufactureSelect.value, data.ship_id ? String(data.ship_id) : '');
|
||||
document.getElementById('presetDescription').value = data.description;
|
||||
document.getElementById('presetLink').value = data.link;
|
||||
|
||||
document.getElementById('submitBtn').innerText = 'Mettre à jour';
|
||||
document.getElementById('cancelBtn').style.display = 'block';
|
||||
document.getElementById('formTitle').innerText = 'Modifier le Preset';
|
||||
document.getElementById('formTitle').innerText = data.name && data.manufacturer
|
||||
? `Modifier le Preset · ${data.manufacturer} / ${data.name}`
|
||||
: 'Modifier le Preset';
|
||||
|
||||
// Scroll to form
|
||||
document.getElementById('presetForm').scrollIntoView({ behavior: 'smooth' });
|
||||
presetForm.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
if (!presetForm) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('formAction').value = 'add_preset';
|
||||
document.getElementById('presetId').value = '';
|
||||
document.getElementById('presetForm').reset();
|
||||
presetForm.reset();
|
||||
populateShipOptions('', '');
|
||||
|
||||
document.getElementById('submitBtn').innerText = 'Ajouter';
|
||||
document.getElementById('cancelBtn').style.display = 'none';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user