Autosave: 20260409-023612
This commit is contained in:
parent
a528142c4f
commit
2944f9f509
146
scmining.php
146
scmining.php
@ -31,6 +31,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Add mineral to list
|
||||
if ($action === 'add_mineral') {
|
||||
$obj_id = (int)$_POST['obj_id'];
|
||||
$return_search = trim($_POST['return_search'] ?? '');
|
||||
$return_page = max(1, (int)($_POST['return_page'] ?? 1));
|
||||
|
||||
if ($obj_id > 0) {
|
||||
try {
|
||||
$stmt = $db->prepare("INSERT INTO tbl_scmining (cl_scmining_obj_id, cl_scmining_scan_value, cl_scmining_max_occurrence) VALUES (:obj_id, 0, 1)");
|
||||
@ -40,11 +43,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($e->getCode() == 23000) {
|
||||
auth_flash_set('error', 'Ce minéral est déjà dans la liste.');
|
||||
} else {
|
||||
auth_flash_set('error', 'Erreur lors de l\'ajout : ' . $e->getMessage());
|
||||
auth_flash_set('error', "Erreur lors de l'ajout : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
header('Location: scmining.php');
|
||||
header('Location: ' . scmining_search_url($return_search, $return_page));
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -85,33 +88,72 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
|
||||
// Search for adding items
|
||||
function sc_rarity_label(?string $rarity): string
|
||||
function sc_normalize_rarity(?string $rarity): string
|
||||
{
|
||||
return match ($rarity) {
|
||||
'L' => 'Legendary',
|
||||
'E' => 'Epic',
|
||||
'R' => 'Rare',
|
||||
'U' => 'Uncommon',
|
||||
'C' => 'Common',
|
||||
default => 'Non définie',
|
||||
};
|
||||
return strtoupper(trim((string) $rarity));
|
||||
}
|
||||
|
||||
function sc_rarity_class(?string $rarity): string
|
||||
{
|
||||
$rarity = sc_normalize_rarity($rarity);
|
||||
|
||||
return in_array($rarity, ['L', 'E', 'R', 'U', 'C'], true) ? 'rarity-' . $rarity : 'rarity-none';
|
||||
}
|
||||
|
||||
function sc_rarity_style(?string $rarity): string
|
||||
{
|
||||
return match (sc_normalize_rarity($rarity)) {
|
||||
'L' => 'color:#ff8000 !important;text-shadow:0 0 10px rgba(255,128,0,0.3);',
|
||||
'E' => 'color:#a335ee !important;text-shadow:0 0 10px rgba(163,53,238,0.3);',
|
||||
'R' => 'color:#0070dd !important;text-shadow:0 0 10px rgba(0,112,221,0.3);',
|
||||
'U' => 'color:#1eff00 !important;text-shadow:0 0 10px rgba(30,255,0,0.3);',
|
||||
'C' => 'color:#ffffff !important;',
|
||||
default => 'color:#8f96a3 !important;',
|
||||
};
|
||||
}
|
||||
|
||||
function scmining_search_url(string $search = '', int $page = 1): string
|
||||
{
|
||||
$params = [];
|
||||
|
||||
if ($search !== '') {
|
||||
$params['search'] = $search;
|
||||
}
|
||||
|
||||
if ($page > 1) {
|
||||
$params['search_page'] = $page;
|
||||
}
|
||||
|
||||
return 'scmining.php' . ($params ? '?' . http_build_query($params) : '');
|
||||
}
|
||||
|
||||
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
|
||||
$search_page = max(1, (int)($_GET['search_page'] ?? 1));
|
||||
$search_per_page = 10;
|
||||
$search_results = [];
|
||||
$search_total_results = 0;
|
||||
$search_total_pages = 0;
|
||||
|
||||
if ($search !== '') {
|
||||
$stmt_search = $db->prepare("SELECT * FROM tbl_scobjs WHERE cl_scobjs_name LIKE :search AND cl_scobjs_id NOT IN (SELECT cl_scmining_obj_id FROM tbl_scmining) ORDER BY cl_scobjs_name ASC LIMIT 10");
|
||||
$stmt_search->execute(['search' => "%$search%"]);
|
||||
$search_where = "FROM tbl_scobjs WHERE cl_scobjs_name LIKE :search AND cl_scobjs_id NOT IN (SELECT cl_scmining_obj_id FROM tbl_scmining)";
|
||||
|
||||
$stmt_search_count = $db->prepare("SELECT COUNT(*) " . $search_where);
|
||||
$stmt_search_count->execute(['search' => "%$search%"]);
|
||||
$search_total_results = (int)$stmt_search_count->fetchColumn();
|
||||
$search_total_pages = max(1, (int)ceil($search_total_results / $search_per_page));
|
||||
$search_page = min($search_page, $search_total_pages);
|
||||
$search_offset = ($search_page - 1) * $search_per_page;
|
||||
|
||||
$stmt_search = $db->prepare("SELECT * " . $search_where . " ORDER BY cl_scobjs_name ASC, cl_scobjs_id ASC LIMIT :limit OFFSET :offset");
|
||||
$stmt_search->bindValue(':search', "%$search%", PDO::PARAM_STR);
|
||||
$stmt_search->bindValue(':limit', $search_per_page, PDO::PARAM_INT);
|
||||
$stmt_search->bindValue(':offset', $search_offset, PDO::PARAM_INT);
|
||||
$stmt_search->execute();
|
||||
$search_results = $stmt_search->fetchAll();
|
||||
}
|
||||
|
||||
// Fetch current mining list
|
||||
$sql_list = "SELECT m.*, o.cl_scobjs_name, o.cl_scobjs_uuid, o.cl_scobjs_type, o.cl_scobjs_subtype
|
||||
$sql_list = "SELECT m.*, o.cl_scobjs_name, o.cl_scobjs_uuid, o.cl_scobjs_type, o.cl_scobjs_subtype, o.cl_scobjs_rarity
|
||||
FROM tbl_scmining m
|
||||
JOIN tbl_scobjs o ON m.cl_scmining_obj_id = o.cl_scobjs_id
|
||||
ORDER BY o.cl_scobjs_name ASC";
|
||||
@ -228,6 +270,12 @@ $current_session_user = $_SESSION['user'] ?? '';
|
||||
box-shadow: 0 0 15px var(--primary-glow);
|
||||
}
|
||||
|
||||
.btn-modern.active {
|
||||
background: var(--primary);
|
||||
color: var(--bg-dark);
|
||||
box-shadow: 0 0 15px var(--primary-glow);
|
||||
}
|
||||
|
||||
.btn-modern.danger { border-color: var(--danger); color: var(--danger); }
|
||||
.btn-modern.danger:hover { background: var(--danger); color: #fff; }
|
||||
|
||||
@ -314,22 +362,25 @@ $current_session_user = $_SESSION['user'] ?? '';
|
||||
.search-result-info { flex: 1; }
|
||||
.search-result-name { display: block; color: var(--primary); font-weight: bold; }
|
||||
.search-result-meta { display: block; font-size: 0.75rem; color: #888; }
|
||||
.search-result-rarity {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
margin-top: 0.4rem;
|
||||
font-size: 0.72rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
.search-results-summary {
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
color: #9a9a9a;
|
||||
}
|
||||
.search-result-rarity::before {
|
||||
content: '';
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
box-shadow: 0 0 8px currentColor;
|
||||
.pagination-controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
.pagination-controls .btn-modern {
|
||||
min-width: 42px;
|
||||
}
|
||||
.pagination-status {
|
||||
font-size: 0.8rem;
|
||||
color: #9a9a9a;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.rarity-L { color: var(--rarity-L) !important; text-shadow: 0 0 10px rgba(255, 128, 0, 0.3); }
|
||||
@ -409,27 +460,54 @@ $current_session_user = $_SESSION['user'] ?? '';
|
||||
<?php if (empty($search_results)): ?>
|
||||
<p style="text-align: center; color: #666;">Aucun objet non listé trouvé.</p>
|
||||
<?php else: ?>
|
||||
<?php $search_first_result = (($search_page - 1) * $search_per_page) + 1; ?>
|
||||
<?php $search_last_result = min($search_total_results, $search_first_result + count($search_results) - 1); ?>
|
||||
<div class="search-results-summary">
|
||||
Résultats <?php echo $search_first_result; ?> à <?php echo $search_last_result; ?> sur <?php echo $search_total_results; ?> — page <?php echo $search_page; ?>/<?php echo $search_total_pages; ?>
|
||||
</div>
|
||||
<?php foreach ($search_results as $res):
|
||||
if (is_array($res) && isset($res['cl_scobjs_uuid']) && isset($res['cl_scobjs_name']) && isset($res['cl_scobjs_type']) && isset($res['cl_scobjs_subtype']) && isset($res['cl_scobjs_id'])) {
|
||||
$rarity_code = $res['cl_scobjs_rarity'] ?? '';
|
||||
$rarity_class = sc_rarity_class($rarity_code);
|
||||
$rarity_label = sc_rarity_label($rarity_code);
|
||||
?>
|
||||
<div class="search-result-item">
|
||||
<img src="https://cstone.space/uifimages/<?php echo $res['cl_scobjs_uuid']; ?>.png" class="item-preview" alt="">
|
||||
<div class="search-result-info">
|
||||
<span class="search-result-name <?php echo htmlspecialchars($rarity_class); ?>"><?php echo htmlspecialchars($res['cl_scobjs_name']); ?></span>
|
||||
<span class="search-result-name <?php echo htmlspecialchars($rarity_class); ?>" style="<?php echo htmlspecialchars(sc_rarity_style($rarity_code)); ?>"><?php echo htmlspecialchars($res['cl_scobjs_name']); ?></span>
|
||||
<span class="search-result-meta"><?php echo htmlspecialchars($res['cl_scobjs_type']); ?> / <?php echo htmlspecialchars($res['cl_scobjs_subtype']); ?></span>
|
||||
<span class="search-result-rarity <?php echo htmlspecialchars($rarity_class); ?>">Rareté : <?php echo htmlspecialchars($rarity_label); ?></span>
|
||||
</div>
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token); ?>">
|
||||
<input type="hidden" name="action" value="add_mineral">
|
||||
<input type="hidden" name="obj_id" value="<?php echo $res['cl_scobjs_id']; ?>">
|
||||
<input type="hidden" name="return_search" value="<?php echo htmlspecialchars($search); ?>">
|
||||
<input type="hidden" name="return_page" value="<?php echo $search_page; ?>">
|
||||
<button type="submit" class="btn-modern btn-mini">+</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php } endforeach; ?>
|
||||
|
||||
<?php if ($search_total_pages > 1): ?>
|
||||
<?php
|
||||
$page_window_start = max(1, $search_page - 2);
|
||||
$page_window_end = min($search_total_pages, $search_page + 2);
|
||||
?>
|
||||
<div class="pagination-controls">
|
||||
<?php if ($search_page > 1): ?>
|
||||
<a href="<?php echo htmlspecialchars(scmining_search_url($search, $search_page - 1)); ?>" class="btn-modern btn-mini">«</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php for ($page_number = $page_window_start; $page_number <= $page_window_end; $page_number++): ?>
|
||||
<a href="<?php echo htmlspecialchars(scmining_search_url($search, $page_number)); ?>" class="btn-modern btn-mini<?php echo $page_number === $search_page ? ' active' : ''; ?>"><?php echo $page_number; ?></a>
|
||||
<?php endfor; ?>
|
||||
|
||||
<?php if ($search_page < $search_total_pages): ?>
|
||||
<a href="<?php echo htmlspecialchars(scmining_search_url($search, $search_page + 1)); ?>" class="btn-modern btn-mini">»</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<span class="pagination-status">Navigation des homonymes activée</span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@ -458,13 +536,15 @@ $current_session_user = $_SESSION['user'] ?? '';
|
||||
<?php else: ?>
|
||||
<?php foreach ($mining_list as $item):
|
||||
if (is_array($item) && isset($item['cl_scobjs_uuid']) && isset($item['cl_scobjs_name']) && isset($item['cl_scobjs_type']) && isset($item['cl_scobjs_subtype']) && isset($item['cl_scmining_id']) && isset($item['cl_scmining_scan_value']) && isset($item['cl_scmining_max_occurrence'])) {
|
||||
$rarity_code = $item['cl_scobjs_rarity'] ?? '';
|
||||
$rarity_class = sc_rarity_class($rarity_code);
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<img src="https://cstone.space/uifimages/<?php echo $item['cl_scobjs_uuid']; ?>.png" class="item-preview" alt="">
|
||||
</td>
|
||||
<td>
|
||||
<strong style="color: var(--primary);"><?php echo htmlspecialchars($item['cl_scobjs_name']); ?></strong><br>
|
||||
<strong class="<?php echo htmlspecialchars($rarity_class); ?>" style="<?php echo htmlspecialchars(sc_rarity_style($rarity_code)); ?>"><?php echo htmlspecialchars($item['cl_scobjs_name']); ?></strong><br>
|
||||
<span style="font-size: 0.75rem; color: #888;"><?php echo htmlspecialchars($item['cl_scobjs_type']); ?> / <?php echo htmlspecialchars($item['cl_scobjs_subtype']); ?></span>
|
||||
</td>
|
||||
<form method="post">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user