Files
2026-09-23 20:43:55 +03:00

80 lines
3.7 KiB
HTML

{% extends "affiliations/base.html" %}
{% set active_page = "codes" %}
{% block page %}
<h4>New code</h4>
<form method="POST" action="{{ url_for('ctfd-affiliations.admin_create_code') }}" class="form-row align-items-end">
<input type="hidden" name="nonce" value="{{ Session.nonce }}">
<div class="form-group col-md-4">
<label for="new-affiliation"><b>Affiliation</b></label>
<input id="new-affiliation" name="affiliation" class="form-control" maxlength="127" required>
</div>
<div class="form-group col-md-3">
<label for="new-code"><b>Code</b></label>
<input id="new-code" name="code" class="form-control" maxlength="128" placeholder="Random if empty">
</div>
<div class="form-group col-md-3">
<label for="new-max-uses"><b>Max uses</b></label>
<input id="new-max-uses" name="max_uses" type="number" min="0" class="form-control" placeholder="Unlimited">
</div>
<div class="form-group col-md-2">
<button type="submit" class="btn btn-primary w-100">Create</button>
</div>
</form>
<h4 class="mt-4">Codes</h4>
{% if codes %}
<table class="table table-striped border">
<thead>
<tr>
<th>Affiliation</th>
<th>Code</th>
<th class="text-center">Uses</th>
<th>Max uses</th>
<th class="text-center">Enabled</th>
<th></th>
</tr>
</thead>
<tbody>
{% for code in codes %}
<tr>
<td>
<form id="edit-{{ code.id }}" method="POST" action="{{ url_for('ctfd-affiliations.admin_update_code', code_id=code.id) }}">
<input type="hidden" name="nonce" value="{{ Session.nonce }}">
</form>
<input form="edit-{{ code.id }}" name="affiliation" class="form-control form-control-sm" value="{{ code.affiliation }}" maxlength="127" required>
</td>
<td>
<input form="edit-{{ code.id }}" name="code" class="form-control form-control-sm text-monospace" value="{{ code.code }}" maxlength="128" required>
</td>
<td class="text-center align-middle">
<a href="{{ url_for('ctfd-affiliations.admin_users', affiliation=code.affiliation) }}" title="Show users">{{ code.uses }}</a>
</td>
<td>
<input form="edit-{{ code.id }}" name="max_uses" type="number" min="0" class="form-control form-control-sm" value="{{ code.max_uses or '' }}" placeholder="∞">
</td>
<td class="text-center align-middle">
<input form="edit-{{ code.id }}" name="enabled" type="checkbox" value="y" {% if code.enabled %}checked{% endif %}>
{% if code.exhausted %}<br><small class="text-danger">limit reached</small>{% endif %}
</td>
<td class="text-right text-nowrap">
<button form="edit-{{ code.id }}" type="submit" class="btn btn-sm btn-outline-primary" title="Save">
<i class="fas fa-save"></i>
</button>
<form method="POST" action="{{ url_for('ctfd-affiliations.admin_delete_code', code_id=code.id) }}" class="d-inline"
onsubmit="return confirm('Delete code {{ code.code }}? Its users keep the affiliation but will be able to change it.');">
<input type="hidden" name="nonce" value="{{ Session.nonce }}">
<button type="submit" class="btn btn-sm btn-outline-danger" title="Delete">
<i class="fas fa-times"></i>
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="text-muted">No codes yet.</p>
{% endif %}
{% endblock %}