Files
dirga 800072f3ce
Build and publish Docker image / build (push) Successful in 56s
perubahan date format agar lebih enak di lihat
2026-10-21 09:04:50 +07:00

211 lines
6.9 KiB
PHP

<?php
require __DIR__ . '/bootstrap.php';
require_admin();
$search = substr(trim($_GET['q'] ?? ''), 0, 100);
$stage = (string) ($_GET['stage'] ?? '');
// Siapkan filter untuk jumlah data dan daftar peserta.
$where = ' WHERE 1=1';
$params = [];
$types = '';
if ($search !== '') {
$where .= ' AND (p.nama LIKE ? OR p.email LIKE ? OR p.posisi LIKE ?)';
$params = array_fill(0, 3, '%' . $search . '%');
$types = 'sss';
}
if (array_key_exists($stage, STAGES)) {
$where .= ' AND p.kode = ?';
$params[] = (int) $stage;
$types .= 'i';
}
// Tampilkan 25 peserta per halaman.
$total = (int) one(
'SELECT COUNT(*) n FROM in_daper p' . $where,
$types,
$params
)['n'];
$pages = max(1, (int) ceil($total / 25));
$page = max(1, min($pages, (int) ($_GET['page'] ?? 1)));
$offset = ($page - 1) * 25;
$sql = "
SELECT
p.id,
p.nama,
p.email,
p.nowa,
p.posisi,
p.level,
p.kode,
p.cek,
p.ts,
COALESCE(j.score, 0) score
FROM in_daper p
LEFT JOIN (
SELECT
idap,
SUM(CASE WHEN cek = '10' THEN 10 ELSE 0 END) score
FROM in_jawab
GROUP BY idap
) j ON j.idap = p.id
";
$sql .= $where;
$sql .= ' ORDER BY p.ts DESC, p.id DESC LIMIT 25 OFFSET ' . $offset;
$list = rows($sql, $types, $params);
page_start('Daftar Peserta Psikotest', 'participants');
?>
<section class="card">
<div class="card-heading">
<div>
<h2>Semua peserta <span class="count"><?= $total ?></span></h2>
<p>Pantau progres tes dan hasil seleksi kandidat.</p>
</div>
<a class="button" href="participant-new.php">+ Tambah peserta</a>
</div>
<form class="filters" method="get">
<input
aria-label="Cari peserta"
name="q"
placeholder="Cari nama, email, atau posisi…"
value="<?= e($search) ?>"
>
<select name="stage" aria-label="Tahap seleksi">
<option value="">Semua tahap seleksi</option>
<?php foreach (STAGES as $stageCode => $stageLabel): ?>
<option
value="<?= $stageCode ?>"
<?= $stage === (string) $stageCode ? 'selected' : '' ?>
>
<?= e($stageLabel) ?>
</option>
<?php endforeach; ?>
</select>
<button class="button secondary">Terapkan</button>
</form>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Peserta</th>
<th>Date Add</th>
<th>No. Handphone</th>
<th>Posisi dilamar</th>
<th>Progres tes</th>
<th>Seleksi</th>
<th>Skor</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($list as $participant): ?>
<?php
$level = (int) $participant['level'];
$phone = trim((string) ($participant['nowa'] ?? ''));
if ($level >= 4) {
$progressLabel = 'Selesai';
} elseif ($level === 0) {
$progressLabel = 'Belum mulai';
} else {
$progressLabel = 'Fase ' . $level . ' / 4';
}
?>
<tr>
<td>
<div class="person">
<span class="avatar">
<?= e(substr($participant['nama'], 0, 1)) ?>
</span>
<div>
<strong><?= e($participant['nama']) ?></strong>
<small><?= e($participant['email']) ?></small>
</div>
</div>
</td>
<td><?= e(date('d M, Y', strtotime($participant['ts']))) ?></td>
<td><?= e($phone !== '' ? $participant['nowa'] : '—') ?></td>
<td><?= e($participant['posisi']) ?></td>
<td>
<span class="badge <?= $level >= 4 ? 'success' : '' ?>">
<?= e($progressLabel) ?>
</span>
</td>
<td>
<?= e(STAGES[(int) $participant['kode']] ?? 'Kode ' . $participant['kode']) ?>
</td>
<td>
<?php if ((int) $participant['cek'] === 1): ?>
<strong><?= (int) $participant['score'] ?></strong>
<small>
<?= (int) $participant['score'] >= threshold() ? 'Lulus skor' : 'Di bawah ambang' ?>
</small>
<?php else: ?>
<span class="muted">Belum dinilai</span>
<?php endif; ?>
</td>
<td>
<a
class="button secondary compact"
href="idap_jawab.php?id=<?= (int) $participant['id'] ?>"
>
Lihat hasil ↗
</a>
</td>
</tr>
<?php endforeach; ?>
<?php if (!$list): ?>
<tr>
<td colspan="8" class="empty">
Tidak ada peserta yang sesuai pencarian.
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="pagination">
<span><?= $total ?> peserta · Halaman <?= $page ?> dari <?= $pages ?></span>
<div>
<?php if ($page > 1): ?>
<?php
$previousUrl = '?' . http_build_query([
'q' => $search,
'stage' => $stage,
'page' => $page - 1,
]);
?>
<a class="button secondary compact" href="<?= e($previousUrl) ?>">
← Sebelumnya
</a>
<?php endif; ?>
<?php if ($page < $pages): ?>
<?php
$nextUrl = '?' . http_build_query([
'q' => $search,
'stage' => $stage,
'page' => $page + 1,
]);
?>
<a class="button secondary compact" href="<?= e($nextUrl) ?>">
Selanjutnya →
</a>
<?php endif; ?>
</div>
</div>
</section>
<?php page_end(); ?>