This commit is contained in:
Flatlogic Bot 2026-04-17 22:19:19 +00:00
parent 2936084d77
commit 40f86c7597

View File

@ -71,6 +71,17 @@ function scitemcustom_current_owner_auth_id(PDO $db): int
return (int) $stmt_owner->fetchColumn();
}
function scitemcustom_redirect(?int $itemcustom_id = null): void
{
$location = 'scitemcustom.php';
if ($itemcustom_id !== null && $itemcustom_id > 0) {
$location .= '#itemcustom-' . $itemcustom_id;
}
header('Location: ' . $location);
exit;
}
$flash = auth_flash_get();
$flash_type = $flash['type'] ?? '';
$flash_message = $flash['message'] ?? '';
@ -91,14 +102,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$submitted_csrf = $_POST['csrf_token'] ?? '';
if (!auth_validate_csrf($submitted_csrf)) {
auth_flash_set('error', 'Jeton CSRF invalide.');
header('Location: scitemcustom.php');
exit;
scitemcustom_redirect();
}
$action = $_POST['action'] ?? '';
if ($action === 'add_custom_item') {
$obj_id = (int) ($_POST['obj_id'] ?? 0);
$redirect_itemcustom_id = null;
if ($obj_id <= 0) {
auth_flash_set('error', 'Objet invalide.');
} else {
@ -116,6 +127,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'owner_auth_id' => $current_owner_auth_id,
'obj_id' => $obj_id,
]);
$redirect_itemcustom_id = (int) $db->lastInsertId();
auth_flash_set('success', 'Objet ajouté dans Item Custom.');
}
} catch (PDOException $e) {
@ -127,8 +139,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
header('Location: scitemcustom.php');
exit;
scitemcustom_redirect($redirect_itemcustom_id);
}
if ($action === 'delete_custom_item') {
@ -155,8 +166,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
header('Location: scitemcustom.php');
exit;
scitemcustom_redirect();
}
if ($action === 'add_custom_stat') {
@ -210,12 +220,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
header('Location: scitemcustom.php');
exit;
scitemcustom_redirect($itemcustom_id);
}
if ($action === 'update_custom_stat') {
$custom_stat_id = (int) ($_POST['custom_stat_id'] ?? 0);
$itemcustom_id = (int) ($_POST['itemcustom_id'] ?? 0);
$stat_id = (int) ($_POST['stat_id'] ?? 0);
$sign = scitemcustom_normalize_sign($_POST['sign'] ?? '+');
$value = scitemcustom_normalize_value($_POST['value'] ?? '');
@ -256,12 +266,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
header('Location: scitemcustom.php');
exit;
scitemcustom_redirect($itemcustom_id);
}
if ($action === 'delete_custom_stat') {
$custom_stat_id = (int) ($_POST['custom_stat_id'] ?? 0);
$itemcustom_id = (int) ($_POST['itemcustom_id'] ?? 0);
if ($custom_stat_id > 0) {
try {
$stmt_delete = $db->prepare(
@ -286,8 +296,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
header('Location: scitemcustom.php');
exit;
scitemcustom_redirect($itemcustom_id);
}
}
@ -672,6 +681,92 @@ $current_session_user = $_SESSION['user'] ?? '';
gap: 1rem;
align-items: center;
flex-wrap: wrap;
flex: 1;
min-width: 0;
}
.custom-item-summary {
display: flex;
justify-content: space-between;
gap: 1rem;
align-items: center;
flex-wrap: wrap;
}
.custom-item-summary-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 0.75rem;
flex-wrap: wrap;
margin-left: auto;
}
.custom-item-stats-count {
flex-shrink: 0;
}
.item-toggle-btn {
display: inline-flex;
align-items: center;
gap: 0.55rem;
padding: 0.6rem 0.9rem;
border-radius: 999px;
border: 1px solid rgba(162, 155, 120, 0.25);
background: rgba(162, 155, 120, 0.08);
color: #fff;
font-family: 'Electrolize', sans-serif;
cursor: pointer;
transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.item-toggle-btn:hover {
background: rgba(162, 155, 120, 0.14);
border-color: rgba(162, 155, 120, 0.45);
}
.item-toggle-btn:focus-visible {
outline: none;
box-shadow: 0 0 0 3px rgba(162, 155, 120, 0.18);
}
.item-toggle-label {
color: var(--primary);
font-size: 0.78rem;
text-transform: uppercase;
letter-spacing: 1px;
line-height: 1;
}
.item-toggle-icon {
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 0.95rem;
line-height: 1;
transition: transform 0.2s ease;
}
.item-toggle-btn[aria-expanded="true"] .item-toggle-icon {
transform: rotate(180deg);
}
.custom-item-card {
scroll-margin-top: 1.5rem;
}
.custom-item-card.is-open {
border-color: rgba(162, 155, 120, 0.35);
box-shadow: 0 0 0 1px rgba(162, 155, 120, 0.12);
}
.custom-item-body {
display: grid;
gap: 1.25rem;
}
.custom-item-body[hidden] {
display: none !important;
}
.inline-form {
@ -816,6 +911,20 @@ $current_session_user = $_SESSION['user'] ?? '';
.actions-row {
justify-content: stretch;
}
.custom-item-summary {
align-items: stretch;
}
.custom-item-summary-actions {
width: 100%;
justify-content: space-between;
}
.item-toggle-btn {
flex: 1;
justify-content: center;
}
}
</style>
</head>
@ -931,6 +1040,7 @@ $current_session_user = $_SESSION['user'] ?? '';
<?php foreach ($custom_items as $item): ?>
<?php $item_id = (int) $item['cl_scitemcustom_id']; ?>
<?php $item_stats = $custom_stats_by_item[$item_id] ?? []; ?>
<?php $item_stats_count = count($item_stats); ?>
<?php $item_search_text = trim(implode(' ', array_filter([
(string) ($item['cl_scobjs_name'] ?? ''),
(string) ($item['cl_scobjs_type'] ?? ''),
@ -938,136 +1048,156 @@ $current_session_user = $_SESSION['user'] ?? '';
(string) ($item['cl_scobjs_uuid'] ?? ''),
]))); ?>
<section class="custom-item-card" id="itemcustom-<?php echo $item_id; ?>" data-item-search="<?php echo htmlspecialchars($item_search_text, ENT_QUOTES, 'UTF-8'); ?>">
<div class="custom-item-header">
<div class="item-meta">
<img src="https://cstone.space/uifimages/<?php echo htmlspecialchars($item['cl_scobjs_uuid'], ENT_QUOTES, 'UTF-8'); ?>.png" class="item-preview" alt="">
<div>
<strong class="item-name"><?php echo htmlspecialchars($item['cl_scobjs_name'], ENT_QUOTES, 'UTF-8'); ?></strong>
<div class="item-submeta">
<?php echo htmlspecialchars($item['cl_scobjs_type'], ENT_QUOTES, 'UTF-8'); ?>
<?php if (!empty($item['cl_scobjs_subtype'])): ?> / <?php echo htmlspecialchars($item['cl_scobjs_subtype'], ENT_QUOTES, 'UTF-8'); ?><?php endif; ?><br>
UUID: <?php echo htmlspecialchars($item['cl_scobjs_uuid'], ENT_QUOTES, 'UTF-8'); ?>
<div class="custom-item-summary">
<div class="custom-item-header">
<div class="item-meta">
<img src="https://cstone.space/uifimages/<?php echo htmlspecialchars($item['cl_scobjs_uuid'], ENT_QUOTES, 'UTF-8'); ?>.png" class="item-preview" alt="">
<div>
<strong class="item-name"><?php echo htmlspecialchars($item['cl_scobjs_name'], ENT_QUOTES, 'UTF-8'); ?></strong>
<div class="item-submeta">
<?php echo htmlspecialchars($item['cl_scobjs_type'], ENT_QUOTES, 'UTF-8'); ?>
<?php if (!empty($item['cl_scobjs_subtype'])): ?> / <?php echo htmlspecialchars($item['cl_scobjs_subtype'], ENT_QUOTES, 'UTF-8'); ?><?php endif; ?><br>
UUID: <?php echo htmlspecialchars($item['cl_scobjs_uuid'], ENT_QUOTES, 'UTF-8'); ?>
</div>
</div>
</div>
<span class="badge custom-item-stats-count"><?php echo $item_stats_count; ?> stat<?php echo $item_stats_count > 1 ? 's' : ''; ?></span>
</div>
<form method="post" onsubmit="return confirm('Supprimer cet objet Item Custom et toutes ses stats ?');">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="delete_custom_item">
<input type="hidden" name="itemcustom_id" value="<?php echo $item_id; ?>">
<button type="submit" class="btn-modern danger">Supprimer l'objet</button>
</form>
</div>
<div>
<h3>Ajouter un bonus / malus</h3>
<?php if (empty($stats_catalog)): ?>
<div class="form-help">Aucune statistique disponible. Crée d'abord des entrées dans l'onglet <strong>Stats Item</strong>.</div>
<?php else: ?>
<form method="post" class="inline-form">
<div class="custom-item-summary-actions">
<button
type="button"
class="item-toggle-btn"
aria-expanded="false"
aria-controls="itemcustom-panel-<?php echo $item_id; ?>"
data-toggle-label-open="Replier"
data-toggle-label-closed="Déplier"
>
<span class="item-toggle-label">Déplier</span>
<span class="item-toggle-icon" aria-hidden="true"></span>
</button>
<form method="post" onsubmit="return confirm('Supprimer cet objet Item Custom et toutes ses stats ?');">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="add_custom_stat">
<input type="hidden" name="action" value="delete_custom_item">
<input type="hidden" name="itemcustom_id" value="<?php echo $item_id; ?>">
<div class="form-group" style="margin-bottom:0;">
<label>Statistique</label>
<select name="stat_id" class="form-control" required>
<?php foreach ($stats_catalog as $stat_option): ?>
<option value="<?php echo (int) $stat_option['cl_scstatsitem_id']; ?>">
<?php echo htmlspecialchars($stat_option['cl_scstatsitem_name'], ENT_QUOTES, 'UTF-8'); ?> (<?php echo htmlspecialchars($stat_option['cl_scstatsitem_unit'], ENT_QUOTES, 'UTF-8'); ?>)
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group" style="margin-bottom:0;">
<label>Signe</label>
<select name="sign" class="form-control">
<?php foreach ($allowed_signs as $sign_option): ?>
<option value="<?php echo htmlspecialchars($sign_option, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $sign_option === '+' ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($sign_labels[$sign_option], ENT_QUOTES, 'UTF-8'); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group" style="margin-bottom:0;">
<label>Valeur</label>
<input type="number" name="value" class="form-control" min="0" step="0.01" value="0" required>
</div>
<button type="submit" class="btn-modern">Ajouter la stat</button>
<button type="submit" class="btn-modern danger">Supprimer l'objet</button>
</form>
<?php endif; ?>
</div>
</div>
<div style="overflow-x:auto;">
<table class="modern-table">
<thead>
<tr>
<th>Statistique</th>
<th style="width:110px;">Signe</th>
<th style="width:140px;">Valeur</th>
<th style="width:120px;">Unité</th>
<th style="width:130px;">Aperçu</th>
<th style="text-align:right; width:220px;">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($item_stats)): ?>
<div class="custom-item-body" id="itemcustom-panel-<?php echo $item_id; ?>" hidden>
<div>
<h3>Ajouter un bonus / malus</h3>
<?php if (empty($stats_catalog)): ?>
<div class="form-help">Aucune statistique disponible. Crée d'abord des entrées dans l'onglet <strong>Stats Item</strong>.</div>
<?php else: ?>
<form method="post" class="inline-form">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="add_custom_stat">
<input type="hidden" name="itemcustom_id" value="<?php echo $item_id; ?>">
<div class="form-group" style="margin-bottom:0;">
<label>Statistique</label>
<select name="stat_id" class="form-control" required>
<?php foreach ($stats_catalog as $stat_option): ?>
<option value="<?php echo (int) $stat_option['cl_scstatsitem_id']; ?>">
<?php echo htmlspecialchars($stat_option['cl_scstatsitem_name'], ENT_QUOTES, 'UTF-8'); ?> (<?php echo htmlspecialchars($stat_option['cl_scstatsitem_unit'], ENT_QUOTES, 'UTF-8'); ?>)
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group" style="margin-bottom:0;">
<label>Signe</label>
<select name="sign" class="form-control">
<?php foreach ($allowed_signs as $sign_option): ?>
<option value="<?php echo htmlspecialchars($sign_option, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $sign_option === '+' ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($sign_labels[$sign_option], ENT_QUOTES, 'UTF-8'); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group" style="margin-bottom:0;">
<label>Valeur</label>
<input type="number" name="value" class="form-control" min="0" step="0.01" value="0" required>
</div>
<button type="submit" class="btn-modern">Ajouter la stat</button>
</form>
<?php endif; ?>
</div>
<div style="overflow-x:auto;">
<table class="modern-table">
<thead>
<tr>
<td colspan="6" class="empty-state">Aucune statistique configurée pour cet objet.</td>
<th>Statistique</th>
<th style="width:110px;">Signe</th>
<th style="width:140px;">Valeur</th>
<th style="width:120px;">Unité</th>
<th style="width:130px;">Aperçu</th>
<th style="text-align:right; width:220px;">Actions</th>
</tr>
<?php else: ?>
<?php foreach ($item_stats as $item_stat): ?>
</thead>
<tbody>
<?php if (empty($item_stats)): ?>
<tr>
<td>
<form method="post">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="update_custom_stat">
<input type="hidden" name="custom_stat_id" value="<?php echo (int) $item_stat['cl_scitemcustomstat_id']; ?>">
<select name="stat_id" class="form-control" required>
<?php foreach ($stats_catalog as $stat_option): ?>
<option value="<?php echo (int) $stat_option['cl_scstatsitem_id']; ?>" <?php echo (int) $stat_option['cl_scstatsitem_id'] === (int) $item_stat['cl_scitemcustomstat_stat_id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($stat_option['cl_scstatsitem_name'], ENT_QUOTES, 'UTF-8'); ?> (<?php echo htmlspecialchars($stat_option['cl_scstatsitem_unit'], ENT_QUOTES, 'UTF-8'); ?>)
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<select name="sign" class="form-control">
<?php foreach ($allowed_signs as $sign_option): ?>
<option value="<?php echo htmlspecialchars($sign_option, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $sign_option === $item_stat['cl_scitemcustomstat_sign'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($sign_labels[$sign_option], ENT_QUOTES, 'UTF-8'); ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<input type="number" name="value" class="form-control" min="0" step="0.01" value="<?php echo htmlspecialchars(scitemcustom_display_value($item_stat['cl_scitemcustomstat_value']), ENT_QUOTES, 'UTF-8'); ?>" required>
</td>
<td>
<span class="badge"><?php echo htmlspecialchars($item_stat['cl_scstatsitem_unit'], ENT_QUOTES, 'UTF-8'); ?></span>
</td>
<td>
<span class="preview-pill"><?php echo htmlspecialchars(scitemcustom_preview($item_stat['cl_scitemcustomstat_sign'], $item_stat['cl_scitemcustomstat_value'], $item_stat['cl_scstatsitem_unit']), ENT_QUOTES, 'UTF-8'); ?></span>
</td>
<td style="text-align:right;">
<div class="actions-row">
<button type="submit" class="btn-modern btn-mini">Save</button>
</form>
<form method="post" onsubmit="return confirm('Supprimer cette statistique ?');">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="delete_custom_stat">
<input type="hidden" name="custom_stat_id" value="<?php echo (int) $item_stat['cl_scitemcustomstat_id']; ?>">
<button type="submit" class="btn-modern btn-mini danger">X</button>
</form>
</div>
</td>
<td colspan="6" class="empty-state">Aucune statistique configurée pour cet objet.</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php else: ?>
<?php foreach ($item_stats as $item_stat): ?>
<tr>
<td>
<form method="post">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="update_custom_stat">
<input type="hidden" name="itemcustom_id" value="<?php echo $item_id; ?>">
<input type="hidden" name="custom_stat_id" value="<?php echo (int) $item_stat['cl_scitemcustomstat_id']; ?>">
<select name="stat_id" class="form-control" required>
<?php foreach ($stats_catalog as $stat_option): ?>
<option value="<?php echo (int) $stat_option['cl_scstatsitem_id']; ?>" <?php echo (int) $stat_option['cl_scstatsitem_id'] === (int) $item_stat['cl_scitemcustomstat_stat_id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($stat_option['cl_scstatsitem_name'], ENT_QUOTES, 'UTF-8'); ?> (<?php echo htmlspecialchars($stat_option['cl_scstatsitem_unit'], ENT_QUOTES, 'UTF-8'); ?>)
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<select name="sign" class="form-control">
<?php foreach ($allowed_signs as $sign_option): ?>
<option value="<?php echo htmlspecialchars($sign_option, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $sign_option === $item_stat['cl_scitemcustomstat_sign'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($sign_labels[$sign_option], ENT_QUOTES, 'UTF-8'); ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<input type="number" name="value" class="form-control" min="0" step="0.01" value="<?php echo htmlspecialchars(scitemcustom_display_value($item_stat['cl_scitemcustomstat_value']), ENT_QUOTES, 'UTF-8'); ?>" required>
</td>
<td>
<span class="badge"><?php echo htmlspecialchars($item_stat['cl_scstatsitem_unit'], ENT_QUOTES, 'UTF-8'); ?></span>
</td>
<td>
<span class="preview-pill"><?php echo htmlspecialchars(scitemcustom_preview($item_stat['cl_scitemcustomstat_sign'], $item_stat['cl_scitemcustomstat_value'], $item_stat['cl_scstatsitem_unit']), ENT_QUOTES, 'UTF-8'); ?></span>
</td>
<td style="text-align:right;">
<div class="actions-row">
<button type="submit" class="btn-modern btn-mini">Save</button>
</form>
<form method="post" onsubmit="return confirm('Supprimer cette statistique ?');">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="delete_custom_stat">
<input type="hidden" name="itemcustom_id" value="<?php echo $item_id; ?>">
<input type="hidden" name="custom_stat_id" value="<?php echo (int) $item_stat['cl_scitemcustomstat_id']; ?>">
<button type="submit" class="btn-modern btn-mini danger">X</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</section>
<?php endforeach; ?>
@ -1085,7 +1215,7 @@ $current_session_user = $_SESSION['user'] ?? '';
var emptyState = document.getElementById('item-custom-no-results');
var itemCards = Array.prototype.slice.call(document.querySelectorAll('#item-custom-list .custom-item-card'));
if (!filterInput || !resetButton || !visibleCount || !emptyState || itemCards.length === 0) {
if (itemCards.length === 0) {
return;
}
@ -1098,6 +1228,99 @@ $current_session_user = $_SESSION['user'] ?? '';
.trim();
}
function setCardState(card, isOpen) {
var body = card.querySelector('.custom-item-body');
var toggleButton = card.querySelector('.item-toggle-btn');
var toggleLabel = toggleButton ? toggleButton.querySelector('.item-toggle-label') : null;
if (!body || !toggleButton) {
return;
}
card.classList.toggle('is-open', isOpen);
body.hidden = !isOpen;
toggleButton.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
if (toggleLabel) {
toggleLabel.textContent = isOpen
? (toggleButton.getAttribute('data-toggle-label-open') || 'Replier')
: (toggleButton.getAttribute('data-toggle-label-closed') || 'Déplier');
}
}
function closeAllCards() {
itemCards.forEach(function (card) {
setCardState(card, false);
});
}
function getCurrentUrlWithoutHash() {
return window.location.pathname + window.location.search;
}
function openCard(card, options) {
var settings = options || {};
itemCards.forEach(function (otherCard) {
setCardState(otherCard, otherCard === card);
});
if (settings.syncHash !== false) {
window.history.replaceState(null, '', '#' + card.id);
}
if (settings.scrollIntoView) {
card.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
function closeCard(card, options) {
var settings = options || {};
setCardState(card, false);
if (settings.syncHash !== false && window.location.hash === '#' + card.id) {
window.history.replaceState(null, '', getCurrentUrlWithoutHash());
}
}
function syncFromHash() {
var hash = window.location.hash || '';
if (hash.indexOf('#itemcustom-') !== 0) {
closeAllCards();
return;
}
var targetCard = document.querySelector(hash + '.custom-item-card');
if (!targetCard) {
closeAllCards();
return;
}
openCard(targetCard, { syncHash: false });
}
itemCards.forEach(function (card) {
var toggleButton = card.querySelector('.item-toggle-btn');
if (!toggleButton) {
return;
}
setCardState(card, false);
toggleButton.addEventListener('click', function () {
var isOpen = toggleButton.getAttribute('aria-expanded') === 'true';
if (isOpen) {
closeCard(card);
} else {
openCard(card, { scrollIntoView: true });
}
});
});
syncFromHash();
window.addEventListener('hashchange', syncFromHash);
if (!filterInput || !resetButton || !visibleCount || !emptyState) {
return;
}
function applyFilter() {
var query = normalizeValue(filterInput.value);
var matches = 0;