Panel/Panel/modules/website/pages/staff_services.php

123 lines
7.2 KiB
PHP

<?php declare(strict_types=1); ?>
<section class="page-heading">
<div class="container">
<h1>Manage Game Services</h1>
<p>Update public catalog status, prices, slot limits, images, and location availability.</p>
</div>
</section>
<section class="section">
<div class="container">
<?php if ($message): ?><div class="alert info"><?= website_escape($message) ?></div><?php endif; ?>
<?php if ($error): ?><div class="alert warning"><?= website_escape($error) ?></div><?php endif; ?>
<?php if (empty($services)): ?>
<div class="empty-state">
<h2>No services found</h2>
<p>Run migrations and import or create billing services before editing catalog data.</p>
</div>
<?php else: ?>
<form method="post" class="website-form staff-services-form">
<?= website_csrf_field() ?>
<div class="staff-service-list">
<div class="staff-service-heading" aria-hidden="true">
<span>ID</span>
<span>Status</span>
<span>Service</span>
<span>Platform</span>
<span>Price</span>
<span>Slots</span>
<span>Image</span>
<span>Locations</span>
<span>Action</span>
</div>
<?php foreach ($services as $service): ?>
<?php
$sid = (int)$service['service_id'];
$enabled = (int)($service['enabled'] ?? 1) === 1;
$selectedIds = [];
foreach (preg_split('/\s+/', trim((string)($service['remote_server_id'] ?? ''))) ?: [] as $remoteServerId) {
$remoteServerId = trim((string)$remoteServerId);
if ($remoteServerId !== '') {
$selectedIds[$remoteServerId] = true;
}
}
$selected = $selectedIds;
$selectedCount = count($selected);
$serviceName = website_service_name($service);
$platformLabel = website_service_platform($service);
$minSlots = website_service_min_slots($service);
$maxSlots = website_service_max_slots($service);
$price = (float)($service['price_monthly'] ?? 0);
$imageValue = trim((string)($service['img_url'] ?? ''));
?>
<details class="staff-service-row">
<summary>
<span data-label="ID">#<?= website_escape((string)$sid) ?></span>
<span data-label="Status" class="status-badge <?= $enabled ? '' : 'status-badge-muted' ?>"><?= $enabled ? 'Enabled' : 'Disabled' ?></span>
<span data-label="Service" class="staff-service-name"><?= website_escape($serviceName) ?></span>
<span data-label="Platform"><?= website_escape($platformLabel) ?></span>
<span data-label="Price"><?= $price > 0 ? '$' . website_escape(number_format($price, 2)) : 'Contact' ?></span>
<span data-label="Slots"><?= website_escape((string)$minSlots) ?><?= $maxSlots > 0 ? '-' . website_escape((string)$maxSlots) : '+' ?></span>
<span data-label="Image"><?= $imageValue !== '' ? 'Set' : 'Default' ?></span>
<span data-label="Locations"><?= website_escape((string)$selectedCount) ?></span>
</summary>
<div class="staff-service-editor">
<label>
<span>Status</span>
<span><input type="checkbox" name="service[<?= $sid ?>][enabled]" value="1" <?= $enabled ? 'checked' : '' ?>> Enabled for public catalog</span>
</label>
<label>
<span>Display name</span>
<input name="service[<?= $sid ?>][service_name]" value="<?= website_escape((string)($service['service_name'] ?? '')) ?>">
</label>
<label class="staff-editor-wide">
<span>Description</span>
<textarea name="service[<?= $sid ?>][description]" rows="3"><?= website_escape((string)($service['description'] ?? '')) ?></textarea>
</label>
<label>
<span>Min slots</span>
<input type="number" name="service[<?= $sid ?>][slot_min_qty]" value="<?= website_escape((string)$minSlots) ?>">
</label>
<label>
<span>Max slots</span>
<input type="number" name="service[<?= $sid ?>][slot_max_qty]" value="<?= website_escape((string)$maxSlots) ?>">
</label>
<label>
<span>Monthly price</span>
<input type="number" step="0.01" name="service[<?= $sid ?>][price_monthly]" value="<?= website_escape((string)$price) ?>">
</label>
<label>
<span>Image URL</span>
<input name="service[<?= $sid ?>][img_url]" value="<?= website_escape($imageValue) ?>">
</label>
<fieldset class="staff-editor-wide">
<legend>Locations</legend>
<div class="checkbox-grid">
<?php foreach ($remoteServers as $rs): ?>
<?php $rid = (string)$rs['remote_server_id']; ?>
<label>
<input type="checkbox" name="service[<?= $sid ?>][locations][]" value="<?= website_escape($rid) ?>" <?= isset($selected[$rid]) ? 'checked' : '' ?>>
<span><?= website_escape((string)$rs['remote_server_name']) ?></span>
</label>
<?php endforeach; ?>
</div>
</fieldset>
</div>
</details>
<?php endforeach; ?>
</div>
<div class="card-actions">
<button class="button button-primary" type="submit">Save Services</button>
</div>
</form>
<?php endif; ?>
</div>
</section>