128 lines
4.8 KiB
PHP
128 lines
4.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
@ini_set('display_errors', '1');
|
|
@error_reporting(E_ALL);
|
|
@date_default_timezone_set('UTC');
|
|
|
|
require_once __DIR__ . '/includes/registration_db.php';
|
|
require_once __DIR__ . '/includes/flash.php';
|
|
ensure_registration_table();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('Location: /');
|
|
exit;
|
|
}
|
|
|
|
$name = trim($_POST['name'] ?? '');
|
|
$education = trim($_POST['education'] ?? '');
|
|
$major = trim($_POST['major'] ?? '');
|
|
|
|
$errors = [];
|
|
if ($name === '') { $errors[] = 'Nama wajib diisi.'; }
|
|
if ($education === '') { $errors[] = 'Pendidikan wajib dipilih.'; }
|
|
if ($major === '') { $errors[] = 'Jurusan wajib diisi.'; }
|
|
|
|
$photoPath = '';
|
|
if (!isset($_FILES['profile']) || $_FILES['profile']['error'] !== UPLOAD_ERR_OK) {
|
|
$errors[] = 'Foto profil wajib diunggah.';
|
|
} else {
|
|
$file = $_FILES['profile'];
|
|
if ($file['size'] > 3 * 1024 * 1024) {
|
|
$errors[] = 'Ukuran foto maksimal 3MB.';
|
|
} else {
|
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
|
$mime = $finfo->file($file['tmp_name']);
|
|
$allowed = ['image/jpeg' => 'jpg', 'image/png' => 'png', 'image/webp' => 'webp'];
|
|
if (!isset($allowed[$mime])) {
|
|
$errors[] = 'Format foto harus JPG, PNG, atau WEBP.';
|
|
} else {
|
|
$uploadDir = __DIR__ . '/assets/uploads';
|
|
if (!is_dir($uploadDir)) {
|
|
mkdir($uploadDir, 0775, true);
|
|
}
|
|
$filename = uniqid('profile_', true) . '.' . $allowed[$mime];
|
|
$destination = $uploadDir . '/' . $filename;
|
|
if (!move_uploaded_file($file['tmp_name'], $destination)) {
|
|
$errors[] = 'Gagal menyimpan foto.';
|
|
} else {
|
|
$photoPath = 'assets/uploads/' . $filename;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($errors) {
|
|
flash_set('danger', implode(' ', $errors));
|
|
header('Location: /#daftar');
|
|
exit;
|
|
}
|
|
|
|
$regCode = generate_reg_code();
|
|
insert_registration([
|
|
'reg_code' => $regCode,
|
|
'name' => $name,
|
|
'education' => $education,
|
|
'major' => $major,
|
|
'photo_path' => $photoPath,
|
|
]);
|
|
|
|
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
|
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
|
$now = date('Y-m-d H:i:s');
|
|
?>
|
|
<!doctype html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Pendaftaran Berhasil</title>
|
|
<?php if ($projectDescription): ?>
|
|
<meta name="description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
<?php endif; ?>
|
|
<?php if ($projectImageUrl): ?>
|
|
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
<?php endif; ?>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
|
|
</head>
|
|
<body class="app-body">
|
|
<div class="container py-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-7">
|
|
<div class="card shadow-sm border-0">
|
|
<div class="card-body">
|
|
<div class="alert alert-success border-0 mb-4">
|
|
Pendaftaran berhasil! Simpan nomor pendaftaran Anda.
|
|
</div>
|
|
<h1 class="h4 fw-semibold mb-3">Nomor Pendaftaran</h1>
|
|
<div class="p-3 border rounded-3 bg-light mb-4">
|
|
<span class="fw-semibold"><?= htmlspecialchars($regCode) ?></span>
|
|
</div>
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-5">
|
|
<img src="<?= htmlspecialchars($photoPath) ?>" class="img-fluid rounded-3 border" alt="Foto pendaftar">
|
|
</div>
|
|
<div class="col-md-7">
|
|
<p class="mb-1"><strong>Nama:</strong> <?= htmlspecialchars($name) ?></p>
|
|
<p class="mb-1"><strong>Pendidikan:</strong> <?= htmlspecialchars($education) ?></p>
|
|
<p class="mb-1"><strong>Jurusan:</strong> <?= htmlspecialchars($major) ?></p>
|
|
<p class="mb-0 text-muted small">Waktu daftar: <?= htmlspecialchars($now) ?> UTC</p>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex flex-wrap gap-2">
|
|
<a class="btn btn-dark" href="/">Kembali ke Form</a>
|
|
<a class="btn btn-outline-secondary" href="admin_login.php">Login Admin</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<p class="text-muted small mt-3">Jika Anda membutuhkan perubahan data, silakan hubungi admin internal.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|