86 lines
3.2 KiB
PHP
86 lines
3.2 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Redirect to login if user is not logged in or not a teacher
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'guru') {
|
|
header("Location: login.php?role=guru");
|
|
exit();
|
|
}
|
|
|
|
$page_title = "Buat Ujian Baru";
|
|
$error_message = '';
|
|
$success_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$title = $_POST['title'] ?? '';
|
|
$description = $_POST['description'] ?? '';
|
|
|
|
if (empty($title)) {
|
|
$error_message = "Judul ujian tidak boleh kosong.";
|
|
} else {
|
|
try {
|
|
$stmt = db()->prepare("INSERT INTO exams (title, description) VALUES (?, ?)");
|
|
$stmt->execute([$title, $description]);
|
|
$exam_id = db()->lastInsertId();
|
|
header("Location: add_questions.php?exam_id=" . $exam_id);
|
|
exit();
|
|
} catch (PDOException $e) {
|
|
$error_message = "Gagal membuat ujian. Silakan coba lagi.";
|
|
// error_log("Exam creation failed: " . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo $page_title; ?> - Ulangan Harian Online</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="dashboard_guru.php">Dashboard Guru</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="logout.php">Logout</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-4">
|
|
<h1><?php echo $page_title; ?></h1>
|
|
|
|
<?php if (!empty($error_message)): ?>
|
|
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form action="create_exam.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label">Judul Ujian</label>
|
|
<input type="text" class="form-control" id="title" name="title" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="description" class="form-label">Deskripsi</label>
|
|
<textarea class="form-control" id="description" name="description" rows="3"></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Simpan dan Lanjutkan</button>
|
|
<a href="dashboard_guru.php" class="btn btn-secondary">Batal</a>
|
|
</form>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|