Files
cmsPRO/admin/templates/releases/main-view.php
Jacek Pyziak dd31c062ad feat(releases): powrót do zakładki Licencje po zapisie + wykrywanie wersji z dysku
- Redirecty save_license/delete_license/toggle_beta kierują teraz na #licenses
- Dodano akcję discover_versions: skanuje updates/*/ver_*.zip przez glob(),
  rejestruje nieznane wersje jako beta w pp_update_versions
- Przycisk "Wykryj wersje z dysku" w zakładce Wersje
- Tpl::__isset() dla poprawnej obsługi isset() na właściwościach szablonu
- Usunięto tymczasowy plik diagnostyczny _diag_licenses.php

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 01:46:32 +01:00

313 lines
13 KiB
PHP

<?php
global $gdb;
ob_start();
?>
<style>
.releases-tabs-nav { margin-bottom: 0; border-bottom: 1px solid #ddd; }
.releases-tabs-nav li { display: inline-block; margin-bottom: -1px; }
.releases-tabs-nav li a {
display: block; padding: 8px 16px; text-decoration: none; color: #555;
border: 1px solid transparent; border-radius: 3px 3px 0 0;
background: #f5f5f5; margin-right: 2px; cursor: pointer;
}
.releases-tabs-nav li.active a {
color: #333; background: #fff;
border-color: #ddd #ddd #fff;
}
.releases-tab-pane { display: none; padding: 18px 0 0; }
.releases-tab-pane.active { display: block; }
.license-form-wrap { display: none; margin-bottom: 20px; }
</style>
<ul class="releases-tabs-nav" id="releases-tabs-nav">
<li class="active"><a href="#" data-tab="tab-versions">Wersje</a></li>
<li><a href="#" data-tab="tab-licenses">Licencje</a></li>
</ul>
<!-- TAB: Wersje -->
<div class="releases-tab-pane active" id="tab-versions">
<div style="margin-bottom: 12px;">
<form method="post" action="/admin/releases/discover_versions/" style="display:inline"
onsubmit="return confirm('Wykryć wersje z dysku i zarejestrować jako stable?')">
<button type="submit" class="btn btn-info btn-sm">
<i class="fa fa-search"></i> Wykryj wersje z dysku
</button>
</form>
</div>
<table class="table table-bordered table-striped table-hover table-condensed">
<thead>
<tr>
<th>Wersja</th>
<th class="text-center" style="width:100px;">Kanał</th>
<th style="width:150px;">Data dodania</th>
<th style="width:150px;">Data promocji</th>
<th class="text-center" style="width:60px;">ZIP</th>
<th class="text-center" style="width:140px;">Akcje</th>
</tr>
</thead>
<tbody>
<?php if (empty($this->versions)): ?>
<tr><td colspan="6" class="text-center text-muted">Brak wersji w bazie.</td></tr>
<?php else: foreach ($this->versions as $v): ?>
<tr>
<td><strong><?= htmlspecialchars($v['version']) ?></strong></td>
<td class="text-center">
<?php if ($v['channel'] === 'stable'): ?>
<span class="label label-success">stable</span>
<?php else: ?>
<span class="label label-warning">beta</span>
<?php endif; ?>
</td>
<td><?= htmlspecialchars($v['created_at'] ?? '') ?></td>
<td><?= $v['promoted_at'] ? htmlspecialchars($v['promoted_at']) : '<span class="text-muted">—</span>' ?></td>
<td class="text-center">
<?php if ($v['zip_exists']): ?>
<span class="text-success"><i class="fa fa-check"></i></span>
<?php else: ?>
<span class="text-danger"><i class="fa fa-times"></i></span>
<?php endif; ?>
</td>
<td class="text-center">
<?php if ($v['channel'] === 'beta'): ?>
<form method="post" action="/admin/releases/promote/" style="display:inline">
<input type="hidden" name="version" value="<?= htmlspecialchars($v['version']) ?>">
<button type="submit" class="btn btn-success btn-xs"
onclick="return confirm('Promować <?= htmlspecialchars($v['version'], ENT_QUOTES) ?> do stable?')">
Promuj &rarr;stable
</button>
</form>
<?php else: ?>
<form method="post" action="/admin/releases/demote/" style="display:inline">
<input type="hidden" name="version" value="<?= htmlspecialchars($v['version']) ?>">
<button type="submit" class="btn btn-warning btn-xs"
onclick="return confirm('Cofnąć <?= htmlspecialchars($v['version'], ENT_QUOTES) ?> do beta?')">
Cofnij &rarr;beta
</button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
<!-- TAB: Licencje -->
<div class="releases-tab-pane" id="tab-licenses">
<div style="margin-bottom: 12px;">
<a href="#" class="btn btn-success btn-sm" id="btn-add-license">
<i class="fa fa-plus-circle"></i> Dodaj licencję
</a>
</div>
<!-- Formularz dodawania / edycji -->
<div class="license-form-wrap panel panel-default" id="license-form-wrap">
<div class="panel-heading">
<strong id="license-form-title">Nowa licencja</strong>
</div>
<div class="panel-body">
<form method="post" action="/admin/releases/save_license/" id="license-form">
<input type="hidden" name="id" id="lic-id" value="">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>Domena</label>
<input type="text" name="domain" id="lic-domain" class="form-control" placeholder="np. example.com" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Klucz licencji</label>
<input type="text" name="key" id="lic-key" class="form-control" placeholder="Klucz UUID / losowy ciąg (pusty = domyślny)">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label>Ważna do daty</label>
<input type="date" name="valid_to_date" id="lic-valid-date" class="form-control">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Ważna do wersji</label>
<input type="text" name="valid_to_version" id="lic-valid-ver" class="form-control" placeholder="np. 1.700">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Dostęp beta</label>
<select name="beta" id="lic-beta" class="form-control">
<option value="0">Nie</option>
<option value="1">Tak</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label>Notatka</label>
<input type="text" name="note" id="lic-note" class="form-control" placeholder="Opcjonalna notatka">
</div>
<button type="submit" class="btn btn-system btn-sm">
<i class="fa fa-save"></i> Zapisz licencję
</button>
<a href="#" class="btn btn-default btn-sm" id="btn-cancel-license">Anuluj</a>
</form>
</div>
</div>
<!-- Tabela licencji -->
<table class="table table-bordered table-striped table-hover table-condensed">
<thead>
<tr>
<th>Domena</th>
<th style="width:120px;">Klucz</th>
<th style="width:120px;">Do daty</th>
<th style="width:100px;">Do wersji</th>
<th class="text-center" style="width:70px;">Beta</th>
<th>Notatka</th>
<th class="text-center" style="width:60px;">Edytuj</th>
<th class="text-center" style="width:60px;">Usuń</th>
</tr>
</thead>
<tbody>
<?php if (empty($this->licenses)): ?>
<tr><td colspan="8" class="text-center text-muted">Brak licencji w bazie.</td></tr>
<?php else: foreach ($this->licenses as $lic): ?>
<tr>
<td><?= htmlspecialchars($lic['domain']) ?></td>
<td>
<code title="<?= htmlspecialchars($lic['key']) ?>">
<?= htmlspecialchars(substr($lic['key'], 0, 8)) ?>…
</code>
</td>
<td><?= $lic['valid_to_date'] ? htmlspecialchars($lic['valid_to_date']) : '<span class="text-muted">—</span>' ?></td>
<td><?= $lic['valid_to_version'] ? htmlspecialchars($lic['valid_to_version']) : '<span class="text-muted">—</span>' ?></td>
<td class="text-center">
<form method="post" action="/admin/releases/toggle_beta/" style="display:inline">
<input type="hidden" name="id" value="<?= (int)$lic['id'] ?>">
<button type="submit"
class="label <?= $lic['beta'] ? 'label-info' : 'label-default' ?>"
title="Kliknij, aby przełączyć"
style="cursor:pointer;border:none;background:none">
<?= $lic['beta'] ? 'tak' : 'nie' ?>
</button>
</form>
</td>
<td><?= htmlspecialchars($lic['note'] ?? '') ?></td>
<td class="text-center">
<a href="#"
class="btn btn-default btn-xs btn-edit-license"
data-id="<?= (int)$lic['id'] ?>"
data-domain="<?= htmlspecialchars($lic['domain'], ENT_QUOTES) ?>"
data-key="<?= htmlspecialchars($lic['key'], ENT_QUOTES) ?>"
data-valid-date="<?= htmlspecialchars($lic['valid_to_date'] ?? '', ENT_QUOTES) ?>"
data-valid-ver="<?= htmlspecialchars($lic['valid_to_version'] ?? '', ENT_QUOTES) ?>"
data-beta="<?= (int)$lic['beta'] ?>"
data-note="<?= htmlspecialchars($lic['note'] ?? '', ENT_QUOTES) ?>">
<i class="fa fa-pencil"></i>
</a>
</td>
<td class="text-center">
<form method="post" action="/admin/releases/delete_license/" style="display:inline"
onsubmit="return confirm('Usunąć licencję dla <?= htmlspecialchars($lic['domain'], ENT_QUOTES) ?>?')">
<input type="hidden" name="id" value="<?= (int)$lic['id'] ?>">
<button type="submit" class="btn btn-danger btn-xs">
<i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
<script>
(function () {
// Tab switching
document.querySelectorAll('#releases-tabs-nav a[data-tab]').forEach(function (link) {
link.addEventListener('click', function (e) {
e.preventDefault();
var targetId = this.getAttribute('data-tab');
document.querySelectorAll('#releases-tabs-nav li').forEach(function (li) {
li.classList.remove('active');
});
document.querySelectorAll('.releases-tab-pane').forEach(function (pane) {
pane.classList.remove('active');
});
this.parentElement.classList.add('active');
document.getElementById(targetId).classList.add('active');
});
});
// Show add-license form
document.getElementById('btn-add-license').addEventListener('click', function (e) {
e.preventDefault();
resetLicenseForm();
document.getElementById('license-form-title').textContent = 'Nowa licencja';
var wrap = document.getElementById('license-form-wrap');
if (wrap.style.display === 'none' || wrap.style.display === '') {
wrap.style.display = 'block';
$(wrap).slideDown(200);
}
});
// Cancel
document.getElementById('btn-cancel-license').addEventListener('click', function (e) {
e.preventDefault();
$(document.getElementById('license-form-wrap')).slideUp(200);
});
// Edit buttons
document.querySelectorAll('.btn-edit-license').forEach(function (btn) {
btn.addEventListener('click', function (e) {
e.preventDefault();
var d = this.dataset;
document.getElementById('lic-id').value = d.id;
document.getElementById('lic-domain').value = d.domain;
document.getElementById('lic-key').value = d.key;
document.getElementById('lic-valid-date').value = d.validDate;
document.getElementById('lic-valid-ver').value = d.validVer;
document.getElementById('lic-beta').value = d.beta;
document.getElementById('lic-note').value = d.note;
document.getElementById('license-form-title').textContent = 'Edytuj licencję: ' + d.domain;
var wrap = document.getElementById('license-form-wrap');
wrap.style.display = 'block';
$(wrap).slideDown(200);
wrap.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
function resetLicenseForm() {
document.getElementById('lic-id').value = '';
document.getElementById('lic-domain').value = '';
document.getElementById('lic-key').value = '';
document.getElementById('lic-valid-date').value = '';
document.getElementById('lic-valid-ver').value = '';
document.getElementById('lic-beta').value = '0';
document.getElementById('lic-note').value = '';
}
// If URL hash indicates licenses tab, switch to it on load
if (window.location.hash === '#licenses') {
document.querySelector('[data-tab="tab-licenses"]').click();
}
})();
</script>
<?php
$out = ob_get_clean();
$grid = new \gridEdit;
$grid->id = 'releases-view';
$grid->gdb_opt = $gdb;
$grid->include_plugins = true;
$grid->title = 'Releases &amp; Licencje';
$grid->default_buttons = false;
$grid->form = false;
$grid->external_code = $out;
echo $grid->draw();
?>