Upload via GUI (1 Datei)

This commit is contained in:
2026-11-15 19:53:29 +00:00
parent 2d11ecf2d3
commit 77a7ee93e4
+86 -25
View File
@@ -3778,6 +3778,19 @@ class WIS_Admin {
echo '<div class="updated"><p>✅ Status geändert!</p></div>';
}
// Bestellung manuell erneut senden: zurück auf 'pending', damit das
// Spigot-Plugin sie beim nächsten Abruf/Login wieder abholt.
if (isset($_GET['action'], $_GET['id']) && $_GET['action'] === 'resend') {
check_admin_referer('wis_order_action', '_wpnonce');
WIS_DB::update_order_status(intval($_GET['id']), 'pending');
echo '<div class="updated"><p>✅ Bestellung #' . intval($_GET['id']) . ' wird erneut gesendet (Status: Warte). Der Status aktualisiert sich automatisch.</p></div>';
// Aktion aus der Adresszeile entfernen, damit ein Neuladen (F5)
// die Bestellung nicht versehentlich noch einmal sendet.
echo '<script>(function(){var u=new URL(window.location.href);'
. '["action","id","_wpnonce"].forEach(function(k){u.searchParams.delete(k);});'
. 'window.history.replaceState({},"",u.toString());})();</script>';
}
if (isset($_GET['view'])) {
$order = WIS_DB::get_order(intval($_GET['view']));
if (!$order) { echo '<div class="error"><p>Bestellung nicht gefunden.</p></div>'; return; }
@@ -3879,10 +3892,10 @@ class WIS_Admin {
<th>Inhalt</th>
<th style="width:90px;">Preis</th>
<th style="width:110px;">Status</th>
<th style="width:180px;">Aktionen</th>
<th style="width:270px;">Aktionen</th>
</tr>
</thead>
<tbody>
<tbody id="wis-orders-body">
<?php if (empty($orders)): ?>
<tr><td colspan="9" style="text-align:center;padding:40px;color:#999;">Keine Bestellungen gefunden.</td></tr>
<?php else: foreach ($orders as $order): ?>
@@ -3897,6 +3910,9 @@ class WIS_Admin {
<td style="color:<?php echo $status_colors[$order->status] ?? '#333'; ?>;font-weight:bold;"><?php echo $status_map[$order->status] ?? $order->status; ?></td>
<td>
<a href="<?php echo admin_url('admin.php?page=wis_orders&view=' . $order->id); ?>" class="button button-small">Details</a>
<?php if ($order->status !== 'pending'): ?>
<a href="<?php echo wp_nonce_url(admin_url('admin.php?page=wis_orders&action=resend&id=' . $order->id . ($search?"&s=$search":'') . ($f_status?"&status=$f_status":'') . ($f_server?"&server=$f_server":'')), 'wis_order_action', '_wpnonce'); ?>" class="button button-small" onclick="return confirm('Bestellung #<?php echo intval($order->id); ?> erneut an den Server senden? Der Spieler erhält sie beim nächsten Abruf noch einmal.');">Erneut senden</a>
<?php endif; ?>
<a href="<?php echo wp_nonce_url(admin_url('admin.php?page=wis_orders&action=delete&id=' . $order->id . ($search?"&s=$search":'') . ($f_status?"&status=$f_status":'') . ($f_server?"&server=$f_server":'')), 'wis_order_action', '_wpnonce'); ?>" class="button button-small" onclick="return confirm('Wirklich löschen?');" style="color:red;">Löschen</a>
</td>
</tr>
@@ -3904,6 +3920,31 @@ class WIS_Admin {
</tbody>
</table>
<script>
// Bestell-Liste alle 5 Sekunden im Hintergrund aktualisieren,
// damit Statuswechsel (z.B. Warte → Fertig) ohne Neuladen sichtbar werden.
(function () {
var body = document.getElementById('wis-orders-body');
if (!body || !window.fetch || !window.DOMParser) return;
function refresh() {
if (document.hidden) return;
var u = new URL(window.location.href);
// Niemals eine Aktion (resend/delete/complete) im Hintergrund wiederholen
['action', 'id', '_wpnonce'].forEach(function (k) { u.searchParams.delete(k); });
fetch(u.toString(), { credentials: 'same-origin' })
.then(function (r) { return r.ok ? r.text() : null; })
.then(function (html) {
if (!html) return;
var fresh = new DOMParser().parseFromString(html, 'text/html')
.getElementById('wis-orders-body');
if (fresh && fresh.innerHTML !== body.innerHTML) body.innerHTML = fresh.innerHTML;
})
.catch(function () {});
}
setInterval(refresh, 5000);
})();
</script>
<?php if ($total_pages > 1): ?>
<div style="margin-top:15px;display:flex;gap:6px;align-items:center;flex-wrap:wrap;">
<?php for ($p = 1; $p <= $total_pages; $p++):
@@ -6024,24 +6065,55 @@ class WIS_API {
return new WP_REST_Response(['orders' => []]);
}
$table = $wpdb->prefix . 'wis_orders';
// Gift-Orders werden genauso wie normale Orders für Spieler A gepollt.
// Spieler A muss zuerst ingame bestätigen (Geld abbuchen), erst dann
// bekommt Spieler B die Gift-Anfrage.
$results = $wpdb->get_results($wpdb->prepare(
"SELECT * FROM $table
WHERE player_name = %s AND status = 'pending'
ORDER BY created_at ASC LIMIT 5",
$server = sanitize_text_field($request->get_param('server') ?? '');
return new WP_REST_Response(['orders' => self::claim_next_order($player, $server)]);
}
/**
* Gibt die nächste offene Order eines Spielers heraus und markiert genau diese als 'claimed'.
*
* - Mit $server werden nur Orders dieses Servers herausgegeben, damit kein anderer
* Server (z.B. Lobby) fremde Orders abholt und verwirft.
* - Es wird nur EINE Order herausgegeben, weil das Spigot-Plugin pro Abruf nur eine verarbeitet.
* - Abo-Lieferungen, die abgeholt aber nie ausgeliefert wurden, werden wieder freigegeben.
*/
private static function claim_next_order($player, $server) {
global $wpdb;
$table = $wpdb->prefix . 'wis_orders';
$wpdb->query($wpdb->prepare(
"UPDATE $table SET status = 'pending'
WHERE player_name = %s AND status = 'claimed'
AND item_id = 'item_abo_delivery'
AND created_at < (NOW() - INTERVAL 5 MINUTE)
AND created_at > (NOW() - INTERVAL 48 HOUR)",
$player
));
if (!empty($results)) {
$ids = implode(',', array_map(fn($o) => intval($o->id), $results));
$wpdb->query("UPDATE $table SET status = 'claimed' WHERE id IN ($ids) AND status = 'pending'");
$where = "player_name = %s AND status = 'pending'";
$args = [$player];
if (!empty($server)) {
$where .= " AND LOWER(server) = %s";
$args[] = strtolower($server);
}
return new WP_REST_Response(['orders' => $results]);
$results = $wpdb->get_results($wpdb->prepare(
"SELECT * FROM $table WHERE $where ORDER BY created_at ASC LIMIT 1",
...$args
));
if (!empty($results)) {
$wpdb->query($wpdb->prepare(
"UPDATE $table SET status = 'claimed' WHERE id = %d AND status = 'pending'",
intval($results[0]->id)
));
}
return $results;
}
public static function get_pending_offline($request) {
@@ -6056,20 +6128,9 @@ class WIS_API {
return new WP_REST_Response(['orders' => []]);
}
$table = $wpdb->prefix . 'wis_orders';
$results = $wpdb->get_results($wpdb->prepare(
"SELECT * FROM $table
WHERE player_name = %s AND status = 'pending'
ORDER BY created_at ASC LIMIT 10",
$player
));
$server = sanitize_text_field($request->get_param('server') ?? '');
if (!empty($results)) {
$ids = implode(',', array_map(fn($o) => intval($o->id), $results));
$wpdb->query("UPDATE $table SET status = 'claimed' WHERE id IN ($ids) AND status = 'pending'");
}
return new WP_REST_Response(['orders' => $results]);
return new WP_REST_Response(['orders' => self::claim_next_order($player, $server)]);
}
public static function get_orders_history($request) {