Autosave: 20260223-020340

This commit is contained in:
Flatlogic Bot 2026-02-23 02:03:41 +00:00
parent 4698c65f42
commit 83107ef847
3 changed files with 44 additions and 13 deletions

View File

@ -211,6 +211,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
$slug = $_POST['slug'];
$icon = $_POST['icon'];
$description = $_POST['description'];
$show_in_header = isset($_POST["show_in_header"]) ? 1 : 0;
$image_url = null;
if ($id > 0) {
@ -232,11 +233,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
}
if ($id > 0) {
$stmt = $db->prepare("UPDATE game_resources SET name = ?, slug = ?, icon = ?, description = ?, image_url = ? WHERE id = ?");
$stmt->execute([$name, $slug, $icon, $description, $image_url, $id]);
$stmt = $db->prepare("UPDATE game_resources SET name = ?, slug = ?, icon = ?, description = ?, image_url = ?, show_in_header = ? WHERE id = ?");
$stmt->execute([$name, $slug, $icon, $description, $image_url, $show_in_header, $id]);
} else {
$stmt = $db->prepare("INSERT INTO game_resources (name, slug, icon, description, image_url) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name, $slug, $icon, $description, $image_url]);
$stmt = $db->prepare("INSERT INTO game_resources (name, slug, icon, description, image_url, show_in_header) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $slug, $icon, $description, $image_url, $show_in_header]);
}
header("Location: admin.php?tab=resources&success=1");
@ -791,13 +792,19 @@ if ($tab === 'users') {
<label>Description</label>
<textarea name="description" id="res_desc" rows="2"></textarea>
</div>
<div class="form-group">
<label class="switch-label" style="display: flex; align-items: center; gap: 10px; cursor: pointer;">
<input type="checkbox" name="show_in_header" id="res_show" value="1" style="width: 20px; height: 20px;">
<span>Afficher dans la barre du header des joueurs</span>
</label>
</div>
<button type="submit" class="btn btn-add">ENREGISTRER LA RESSOURCE</button>
<button type="button" class="btn" style="background: #4c566a; color: #fff;" onclick="resetResourceForm()">ANNULER</button>
</form>
</div>
<table>
<thead><tr><th>Visuel</th><th>Nom</th><th>Slug</th><th>Actions</th></tr></thead>
<thead><tr><th>Visuel</th><th>Nom</th><th>Slug</th><th>Header?</th><th>Actions</th></tr></thead>
<tbody>
<?php foreach ($resources_list as $r): ?>
<tr>
@ -812,6 +819,13 @@ if ($tab === 'users') {
</td>
<td><strong><?php echo htmlspecialchars($r['name']); ?></strong></td>
<td><code><?php echo htmlspecialchars($r['slug']); ?></code></td>
<td style="text-align: center;">
<?php if ($r['show_in_header']): ?>
<i class="fa-solid fa-check-circle" style="color: #a3be8c;"></i>
<?php else: ?>
<i class="fa-solid fa-times-circle" style="color: #bf616a;"></i>
<?php endif; ?>
</td>
<td>
<button class="btn btn-edit" onclick='editResource(<?php echo json_encode($r, JSON_HEX_APOS); ?>)'>Editer</button>
<a href="?tab=resources&delete_resource=<?php echo $r['id']; ?>" class="btn btn-del" onclick="return confirm('Supprimer cette ressource ?')">Suppr</a>
@ -1010,6 +1024,7 @@ if ($tab === 'users') {
document.getElementById('res_slug').value = data.slug;
document.getElementById('res_icon').value = data.icon || '';
document.getElementById('res_desc').value = data.description || '';
document.getElementById('res_show').checked = (data.show_in_header == 1);
window.scrollTo(0,0);
}
function resetResourceForm() { document.getElementById('resourceForm').reset(); document.getElementById('res_id').value = 0; }

View File

@ -0,0 +1,17 @@
<?php
require_once __DIR__ . '/config.php';
try {
$db = db();
// Check if column already exists
$columns = $db->query("SHOW COLUMNS FROM game_resources LIKE 'show_in_header'")->fetchAll();
if (empty($columns)) {
$db->exec("ALTER TABLE game_resources ADD COLUMN show_in_header TINYINT(1) DEFAULT 0");
echo "Column 'show_in_header' added successfully to 'game_resources'.\n";
} else {
echo "Column 'show_in_header' already exists.\n";
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage() . "\n";
}

View File

@ -36,13 +36,8 @@ $factions_map = []; foreach($factions_db as $f) $factions_map[$f['id']] = $f;
$grid_size = 36;
// Mock Resources
$resources = [
'Metal' => ['val' => '136 053', 'max' => '1 210 000', 'prod' => '+1 980', 'icon' => 'fa-cube'],
'Crystal' => ['val' => '127 322', 'max' => '1 010 000', 'prod' => '+1 703', 'icon' => 'fa-gem'],
'Deuterium' => ['val' => '32 277', 'max' => '50 000', 'prod' => '+28', 'icon' => 'fa-flask'],
'Energy' => ['val' => '2 100', 'max' => '2 100', 'prod' => '', 'icon' => 'fa-bolt'],
'Dark Matter' => ['val' => '4 930', 'max' => '', 'prod' => '', 'icon' => 'fa-atom']
];
$header_resources = $db->query("SELECT * FROM game_resources WHERE show_in_header = 1 ORDER BY name ASC")->fetchAll(PDO::FETCH_ASSOC);
$resources = []; foreach($header_resources as $hr) { $resources[$hr["name"]] = ["val" => "0", "prod" => "", "icon" => $hr["icon"] ?: "fa-gem", "image" => $hr["image_url"]]; }
if ($view === 'sector') {
$stmt = $db->prepare("SELECT * FROM planets WHERE galaxy_id = ? AND sector_id = ? AND slot BETWEEN 1 AND ?");
@ -437,7 +432,11 @@ function getStatusColor($status, $statuses_map) {
<div class="resource-name"><?php echo $name; ?></div>
<div class="resource-value"><?php echo $res['val']; ?></div>
<div class="resource-prod"><?php echo $res['prod']; ?></div>
<i class="fa-solid <?php echo $res['icon']; ?>"></i>
<?php if (!empty($res["image"])): ?>
<img src="<?php echo htmlspecialchars($res["image"]); ?>?v=<?php echo time(); ?>" style="position: absolute; right: -15px; top: 5px; max-width: 25px; max-height: 25px; opacity: 0.6;">
<?php else: ?>
<i class="fa-solid <?php echo htmlspecialchars($res["icon"]); ?>"></i>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>