<?php
$title =
    'Emergency Rollback Center';

function rb_h($v)
{
    return htmlspecialchars(
        (string)$v,
        ENT_QUOTES,
        'UTF-8'
    );
}
?>

<div class="container-fluid py-4">

<div class="card border-0 shadow-lg rounded-4 mb-4">

<div class="card-body">

<h2 class="fw-bold mb-2">

<i class="fa fa-rotate-left text-danger"></i>

Emergency Rollback Center

</h2>

<div class="text-muted">

Restore the conference homepage from a saved snapshot. A safety backup is created automatically before restore.

</div>

</div>

</div>

<div class="alert alert-warning rounded-4">

<strong>Important:</strong>
Rollback replaces the current homepage sections with the selected snapshot sections.
The system will first create an automatic backup of the current homepage.

</div>

<div class="card border-0 shadow-sm rounded-4">

<div class="card-body">

<h4 class="fw-bold mb-4">

Available Snapshots

</h4>

<?php if (empty($snapshots)): ?>

<div class="alert alert-info">

No snapshots found. Create a snapshot first from the Publish Center or Marketplace.

</div>

<?php else: ?>

<div class="table-responsive">

<table class="table align-middle">

<thead>

<tr>

<th>ID</th>

<th>Name</th>

<th>Version</th>

<th>Created</th>

<th width="220">Action</th>

</tr>

</thead>

<tbody>

<?php foreach ($snapshots as $s): ?>

<tr>

<td>

<?= (int)$s['id'] ?>

</td>

<td>

<strong>

<?= rb_h($s['name'] ?? 'Untitled Snapshot') ?>

</strong>

</td>

<td>

<?= (int)($s['version_no'] ?? 1) ?>

</td>

<td>

<?= rb_h($s['created_at'] ?? '') ?>

</td>

<td>

<form
method="post"
action="/easychair/admin/conference-home/rollback/restore"
onsubmit="return confirm('Restore this snapshot? Current homepage sections will be backed up first, then replaced.');">

<input
type="hidden"
name="template_id"
value="<?= (int)$s['id'] ?>">

<button
class="btn btn-danger rounded-pill">

<i class="fa fa-rotate-left"></i>

Restore

</button>

</form>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

<?php endif; ?>

</div>

</div>

</div>
