Alpha v0.7.2

This commit is contained in:
Flatlogic Bot 2026-02-23 02:56:14 +00:00
parent 8e63d8ec36
commit 6e4209f588
4 changed files with 94 additions and 1 deletions

View File

@ -173,6 +173,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
$fa_icon = $_POST['fa_icon'];
$color = $_POST['color'];
$image_url = null;
$alliance_ids = isset($_POST['alliances']) ? $_POST['alliances'] : [];
if ($id > 0) {
$stmt_img = $db->prepare("SELECT image_url FROM factions WHERE id = ?");
$stmt_img->execute([$id]);
@ -192,7 +194,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
} else {
$stmt = $db->prepare("INSERT INTO factions (name, slug, image_url, fa_icon, color) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name, $slug, $image_url, $fa_icon, $color]);
$id = $db->lastInsertId();
}
// Handle Alliances (Reciprocal)
$db->prepare("DELETE FROM faction_alliances WHERE faction_id_1 = ? OR faction_id_2 = ?")->execute([$id, $id]);
foreach ($alliance_ids as $ally_id) {
$f1 = min((int)$id, (int)$ally_id);
$f2 = max((int)$id, (int)$ally_id);
if ($f1 === $f2) continue;
$db->prepare("INSERT IGNORE INTO faction_alliances (faction_id_1, faction_id_2) VALUES (?, ?)")->execute([$f1, $f2]);
}
header("Location: admin.php?tab=factions&success=1");
exit;
}
@ -325,6 +338,7 @@ if ($tab === 'users') {
$stmt->execute([$obj['id']]);
$obj['modifier_ids'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
}
unset($obj);
$modifiers_list = $db->query("SELECT * FROM modifiers ORDER BY type, name ASC")->fetchAll();
} elseif ($tab === 'statuses') {
$statuses_list = $db->query("SELECT * FROM celestial_object_statuses ORDER BY name ASC")->fetchAll();
@ -334,6 +348,12 @@ if ($tab === 'users') {
$modifiers_list = $db->query("SELECT * FROM modifiers ORDER BY type, name ASC")->fetchAll();
} elseif ($tab === 'factions') {
$factions_list = $db->query("SELECT * FROM factions ORDER BY name ASC")->fetchAll();
foreach ($factions_list as &$f) {
$stmt = $db->prepare("SELECT faction_id_1 as ally_id FROM faction_alliances WHERE faction_id_2 = ? UNION SELECT faction_id_2 as ally_id FROM faction_alliances WHERE faction_id_1 = ?");
$stmt->execute([$f['id'], $f['id']]);
$f['alliance_ids'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
}
unset($f);
} elseif ($tab === 'resources') {
$resources_list = $db->query("SELECT * FROM game_resources ORDER BY name ASC")->fetchAll();
} elseif ($tab === 'lootboxes') {
@ -348,6 +368,7 @@ if ($tab === 'users') {
$stmt_i->execute([$lb['id']]);
$lb['items'] = $stmt_i->fetchAll();
}
unset($lb);
}
?>
@ -738,13 +759,28 @@ if ($tab === 'users') {
<input type="file" name="image" accept="image/png">
</div>
</div>
<div class="form-group">
<label style="font-size: 12px; color: #8c92a3;">Alliances (Réciprocité automatique)</label>
<div style="background: #0f172a; border: 1px solid #334155; padding: 10px; max-height: 150px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 10px; margin-top: 5px;">
<?php foreach ($factions_list as $potential_ally): ?>
<label class="alliance-label" style="font-size: 11px; display: flex; align-items: center; gap: 5px; cursor: pointer;" data-id="<?php echo $potential_ally['id']; ?>">
<input type="checkbox" name="alliances[]" value="<?php echo $potential_ally['id']; ?>" class="alliance-checkbox" data-id="<?php echo $potential_ally['id']; ?>">
<span style="padding: 2px 8px; border-radius: 4px; background: #334155; color: #fff;">
<?php echo htmlspecialchars($potential_ally['name']); ?>
</span>
</label>
<?php endforeach; ?>
</div>
</div>
<button type="submit" class="btn btn-add">ENREGISTRER LA FACTION</button>
<button type="button" class="btn" style="background: #4c566a; color: #fff;" onclick="resetFactionForm()">ANNULER</button>
</form>
</div>
<table>
<thead><tr><th>Couleur</th><th>Visuel</th><th>Nom</th><th>Slug</th><th>Actions</th></tr></thead>
<thead><tr><th>Couleur</th><th>Visuel</th><th>Nom</th><th>Slug</th><th>Alliances</th><th>Actions</th></tr></thead>
<tbody>
<?php foreach ($factions_list as $f): ?>
<tr>
@ -760,6 +796,22 @@ if ($tab === 'users') {
</td>
<td><strong><?php echo htmlspecialchars($f['name']); ?></strong></td>
<td><code><?php echo htmlspecialchars($f['slug']); ?></code></td>
<td>
<small>
<?php
$allies = [];
foreach ($f['alliance_ids'] as $aid) {
foreach ($factions_list as $fl) {
if ($fl['id'] == $aid) {
$allies[] = '<span style="color: #a3be8c;">' . htmlspecialchars($fl['name']) . '</span>';
break;
}
}
}
echo !empty($allies) ? implode(', ', $allies) : '<em>Aucune</em>';
?>
</small>
</td>
<td>
<button class="btn btn-edit" onclick='editFaction(<?php echo json_encode($f, JSON_HEX_APOS); ?>)'>Editer</button>
<?php if ($f['name'] !== 'Aucune'): ?>
@ -1035,6 +1087,21 @@ if ($tab === 'users') {
document.getElementById('fac_color_picker').value = color.startsWith('#') ? color : '#808080';
}
document.getElementById('fac_fa_icon').value = data.fa_icon || '';
// Handle Alliances
document.querySelectorAll('.alliance-checkbox').forEach(cb => cb.checked = false);
document.querySelectorAll('.alliance-label').forEach(lbl => lbl.style.display = 'flex');
// Hide current faction from alliance list
const currentLabel = document.querySelector(`.alliance-label[data-id="${data.id}"]`);
if (currentLabel) currentLabel.style.display = 'none';
if (data.alliance_ids) {
data.alliance_ids.forEach(aid => {
const cb = document.querySelector(`.alliance-checkbox[value="${aid}"]`);
if (cb) cb.checked = true;
});
}
window.scrollTo(0,0);
}
function resetFactionForm() {
@ -1042,6 +1109,8 @@ if ($tab === 'users') {
document.getElementById('fac_id').value = 0;
document.getElementById('fac_color').value = '#808080';
document.getElementById('fac_color_picker').value = '#808080';
document.querySelectorAll('.alliance-checkbox').forEach(cb => cb.checked = false);
document.querySelectorAll('.alliance-label').forEach(lbl => lbl.style.display = 'flex');
}
function editResource(data) {

View File

@ -0,0 +1,20 @@
<?php
require_once __DIR__ . '/config.php';
$db = db();
try {
// Create faction_alliances table
$db->exec("CREATE TABLE IF NOT EXISTS faction_alliances (
id INT AUTO_INCREMENT PRIMARY KEY,
faction_id_1 INT NOT NULL,
faction_id_2 INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY unique_alliance (faction_id_1, faction_id_2),
FOREIGN KEY (faction_id_1) REFERENCES factions(id) ON DELETE CASCADE,
FOREIGN KEY (faction_id_2) REFERENCES factions(id) ON DELETE CASCADE
)");
echo "Table 'faction_alliances' created or already exists.\n";
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage());
}

View File

@ -219,6 +219,7 @@ if ($view === 'sector') {
}
// Fetch Cities
unset($slot_data);
$stmt = $db->prepare("SELECT * FROM cities WHERE planet_id IN ($placeholders)");
$stmt->execute($planet_ids);
$all_cities = $stmt->fetchAll(PDO::FETCH_ASSOC);
@ -243,6 +244,7 @@ if ($view === 'sector') {
}
}
}
unset($slot_data);
}
$stmt = $db->prepare("SELECT name, status FROM sectors WHERE id = ?");
$stmt->execute([$sector_id]);

View File

@ -69,6 +69,7 @@ if ($view === 'sector') {
}
// Fetch Cities
unset($slot_data);
$stmt = $db->prepare("SELECT c.*, st.name as type_name
FROM cities c
LEFT JOIN settlement_types st ON c.settlement_type_id = st.id
@ -97,6 +98,7 @@ if ($view === 'sector') {
}
}
}
unset($slot_data);
$stmt = $db->prepare("SELECT name FROM sectors WHERE id = ?");
$stmt->execute([$sector_id]);