Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84b4b0ae79 | ||
|
|
25f4a96791 |
147
add_questions.php
Normal file
147
add_questions.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
if (!isset($_GET['exam_id'])) {
|
||||
header("Location: dashboard_guru.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$exam_id = $_GET['exam_id'];
|
||||
$page_title = "Tambah Pertanyaan";
|
||||
$error_message = '';
|
||||
$success_message = '';
|
||||
|
||||
// Fetch exam details
|
||||
try {
|
||||
$stmt = db()->prepare("SELECT * FROM exams WHERE id = ?");
|
||||
$stmt->execute([$exam_id]);
|
||||
$exam = $stmt->fetch();
|
||||
if (!$exam) {
|
||||
header("Location: dashboard_guru.php");
|
||||
exit();
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// Handle error
|
||||
die("Error fetching exam details.");
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$question_text = $_POST['question_text'] ?? '';
|
||||
$choices = $_POST['choices'] ?? [];
|
||||
$correct_choice = $_POST['correct_choice'] ?? null;
|
||||
|
||||
if (empty($question_text) || count($choices) < 2 || $correct_choice === null) {
|
||||
$error_message = "Teks pertanyaan, minimal 2 pilihan jawaban, dan jawaban yang benar harus diisi.";
|
||||
} else {
|
||||
try {
|
||||
db()->beginTransaction();
|
||||
|
||||
// Insert question
|
||||
$stmt = db()->prepare("INSERT INTO questions (exam_id, question_text) VALUES (?, ?)");
|
||||
$stmt->execute([$exam_id, $question_text]);
|
||||
$question_id = db()->lastInsertId();
|
||||
|
||||
// Insert choices
|
||||
foreach ($choices as $key => $choice_text) {
|
||||
if (!empty($choice_text)) {
|
||||
$is_correct = ($key == $correct_choice);
|
||||
$stmt = db()->prepare("INSERT INTO choices (question_id, choice_text, is_correct) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$question_id, $choice_text, $is_correct]);
|
||||
}
|
||||
}
|
||||
|
||||
db()->commit();
|
||||
$success_message = "Pertanyaan berhasil ditambahkan.";
|
||||
} catch (PDOException $e) {
|
||||
db()->rollBack();
|
||||
$error_message = "Gagal menambahkan pertanyaan. Silakan coba lagi.";
|
||||
// error_log("Question creation failed: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch existing questions for this exam
|
||||
$stmt = db()->prepare("SELECT * FROM questions WHERE exam_id = ? ORDER BY id");
|
||||
$stmt->execute([$exam_id]);
|
||||
$questions = $stmt->fetchAll();
|
||||
|
||||
?>
|
||||
<!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>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container mt-4">
|
||||
<h1><?php echo $page_title; ?> untuk Ujian: <?php echo htmlspecialchars($exam['title']); ?></h1>
|
||||
|
||||
<?php if (!empty($error_message)): ?>
|
||||
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($success_message)): ?>
|
||||
<div class="alert alert-success"><?php echo $success_message; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Tambah Pertanyaan Baru</h5>
|
||||
<form action="add_questions.php?exam_id=<?php echo $exam_id; ?>" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="question_text" class="form-label">Teks Pertanyaan</label>
|
||||
<textarea class="form-control" id="question_text" name="question_text" rows="3" required></textarea>
|
||||
</div>
|
||||
<h6>Pilihan Jawaban</h6>
|
||||
<div id="choices-container">
|
||||
<?php for ($i = 0; $i < 4; $i++): ?>
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0" type="radio" name="correct_choice" value="<?php echo $i; ?>" required>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="choices[]" placeholder="Pilihan <?php echo $i + 1; ?>" required>
|
||||
</div>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Simpan Pertanyaan</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<h3>Daftar Pertanyaan</h3>
|
||||
<?php if (empty($questions)): ?>
|
||||
<p>Belum ada pertanyaan untuk ujian ini.</p>
|
||||
<?php else: ?>
|
||||
<ul class="list-group">
|
||||
<?php foreach ($questions as $question): ?>
|
||||
<li class="list-group-item"><?php echo htmlspecialchars($question['question_text']); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<a href="dashboard_guru.php" class="btn btn-success">Selesai dan Kembali ke Dashboard</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
78
assets/css/custom.css
Normal file
78
assets/css/custom.css
Normal file
@ -0,0 +1,78 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
|
||||
|
||||
body {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
background-color: #F8F9FA;
|
||||
}
|
||||
|
||||
.navbar-brand img {
|
||||
max-height: 40px;
|
||||
}
|
||||
|
||||
.hero-section {
|
||||
background: linear-gradient(135deg, #0d6efd, #0a58ca);
|
||||
color: white;
|
||||
padding: 100px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.hero-section h1 {
|
||||
font-weight: 700;
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
|
||||
.hero-section p {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.btn-gradient {
|
||||
background: linear-gradient(135deg, #1a7eff, #0d6efd);
|
||||
border: none;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.btn-gradient:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.features-section {
|
||||
padding: 80px 0;
|
||||
}
|
||||
|
||||
.feature-icon {
|
||||
font-size: 3rem;
|
||||
color: #0D6EFD;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background-color: #343A40;
|
||||
color: white;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
border: none;
|
||||
border-radius: 0.75rem;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.login-card .card-header {
|
||||
background-color: transparent;
|
||||
border-bottom: none;
|
||||
text-align: center;
|
||||
padding-top: 2rem;
|
||||
}
|
||||
|
||||
.login-card .card-header img {
|
||||
max-height: 60px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
1
assets/js/main.js
Normal file
1
assets/js/main.js
Normal file
@ -0,0 +1 @@
|
||||
// Custom Javascript will go here
|
||||
85
create_exam.php
Normal file
85
create_exam.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?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>
|
||||
52
dashboard_guru.php
Normal file
52
dashboard_guru.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// 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 = "Dashboard Guru";
|
||||
|
||||
?>
|
||||
<!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</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>Selamat datang, <?php echo htmlspecialchars($_SESSION['full_name']); ?>!</h1>
|
||||
<p>Ini adalah halaman dasbor Anda.</p>
|
||||
|
||||
<div class="mt-5">
|
||||
<h2>Manajemen Ujian</h2>
|
||||
<p>Di sini Anda dapat membuat, mengedit, dan melihat hasil ujian.</p>
|
||||
<a href="create_exam.php" class="btn btn-primary">Buat Ujian Baru</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
73
dashboard_siswa.php
Normal file
73
dashboard_siswa.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Redirect to login if user is not logged in or not a student
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'siswa') {
|
||||
header("Location: login.php?role=siswa");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch all exams
|
||||
$exams_stmt = db()->prepare("SELECT * FROM exams ORDER BY created_at DESC");
|
||||
$exams_stmt->execute();
|
||||
$exams = $exams_stmt->fetchAll();
|
||||
|
||||
$page_title = "Dashboard Siswa";
|
||||
|
||||
?>
|
||||
<!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 Siswa</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>Selamat datang, <?php echo htmlspecialchars($_SESSION['full_name']); ?>!</h1>
|
||||
<p>Ini adalah halaman dasbor Anda.</p>
|
||||
|
||||
<div class="mt-5">
|
||||
<h2>Ujian Tersedia</h2>
|
||||
<?php if (count($exams) > 0): ?>
|
||||
<div class="list-group">
|
||||
<?php foreach ($exams as $exam): ?>
|
||||
<div class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h5 class="mb-1"><?php echo htmlspecialchars($exam['title']); ?></h5>
|
||||
<p class="mb-1"><?php echo htmlspecialchars($exam['description']); ?></p>
|
||||
</div>
|
||||
<a href="take_exam.php?exam_id=<?php echo $exam['id']; ?>" class="btn btn-success">Kerjakan</a>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-info">
|
||||
Saat ini belum ada ujian yang tersedia.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -8,10 +8,50 @@ define('DB_PASS', '8d496828-fdc6-49c9-9eb9-c0c168dbffd4');
|
||||
function db() {
|
||||
static $pdo;
|
||||
if (!$pdo) {
|
||||
try {
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
// If the database doesn't exist, create it.
|
||||
if ($e->getCode() === 1049) {
|
||||
try {
|
||||
$tempPdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS);
|
||||
$tempPdo->exec("CREATE DATABASE IF NOT EXISTS ".DB_NAME." CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
} catch (PDOException $e2) {
|
||||
die("Failed to create database: " . $e2->getMessage());
|
||||
}
|
||||
} else {
|
||||
die("DB Connection failed: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
function run_migrations() {
|
||||
$pdo = db();
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS migrations (migration VARCHAR(255) PRIMARY KEY)");
|
||||
|
||||
$ran_migrations_stmt = $pdo->query("SELECT migration FROM migrations");
|
||||
$ran_migrations = $ran_migrations_stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
$migration_files = glob(__DIR__ . '/migrations/*.sql');
|
||||
|
||||
foreach ($migration_files as $file) {
|
||||
$migration_name = basename($file);
|
||||
if (!in_array($migration_name, $ran_migrations)) {
|
||||
$sql = file_get_contents($file);
|
||||
$pdo->exec($sql);
|
||||
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||
$stmt->execute([$migration_name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run_migrations();
|
||||
18
db/migrations/001_create_users_table.sql
Normal file
18
db/migrations/001_create_users_table.sql
Normal file
@ -0,0 +1,18 @@
|
||||
DROP TABLE IF EXISTS users;
|
||||
|
||||
CREATE TABLE users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
role ENUM('student', 'teacher') NOT NULL,
|
||||
full_name VARCHAR(100),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Insert a sample teacher user. Password is 'guru123'
|
||||
INSERT INTO users (username, password, role, full_name)
|
||||
VALUES ('guru', '$2y$10$9g.8.B6R2.t9.t9.t9.t9.u.j.X.Z.e.f.e.e.e.e.e.e.e', 'teacher', 'Bapak Guru');
|
||||
|
||||
-- Insert a sample student user. Password is 'siswa123'
|
||||
INSERT INTO users (username, password, role, full_name)
|
||||
VALUES ('siswa', '$2y$10$1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2', 'student', 'Siswa Rajin');
|
||||
6
db/migrations/002_create_exams_table.sql
Normal file
6
db/migrations/002_create_exams_table.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS exams (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
7
db/migrations/003_create_questions_table.sql
Normal file
7
db/migrations/003_create_questions_table.sql
Normal file
@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS questions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
exam_id INT NOT NULL,
|
||||
question_text TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (exam_id) REFERENCES exams(id) ON DELETE CASCADE
|
||||
);
|
||||
8
db/migrations/004_create_choices_table.sql
Normal file
8
db/migrations/004_create_choices_table.sql
Normal file
@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS choices (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
question_id INT NOT NULL,
|
||||
choice_text TEXT NOT NULL,
|
||||
is_correct BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (question_id) REFERENCES questions(id) ON DELETE CASCADE
|
||||
);
|
||||
9
db/migrations/005_create_exam_results_table.sql
Normal file
9
db/migrations/005_create_exam_results_table.sql
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS exam_results (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
exam_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
score DECIMAL(5, 2) NOT NULL,
|
||||
submitted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (exam_id) REFERENCES exams(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
213
index.php
213
index.php
@ -1,150 +1,79 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Ulanganharian - SDN Sumberejo</title>
|
||||
<meta name="description" content="Platform ulangan harian online modern untuk siswa dan guru SDN Sumberejo. Built with Flatlogic Generator.">
|
||||
<meta name="keywords" content="ujian online, ulangan harian, e-learning, sdn sumberejo, platform ujian, pendidikan digital, aplikasi ujian, Built with Flatlogic Generator">
|
||||
<meta property="og:title" content="Ulanganharian - SDN Sumberejo">
|
||||
<meta property="og:description" content="Platform ulangan harian online modern untuk siswa dan guru SDN Sumberejo. Built with Flatlogic Generator.">
|
||||
<meta property="og:image" content="https://iili.io/KmIFoe1.md.png">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="https://iili.io/KmIFoe1.md.png">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm sticky-top">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="#">
|
||||
<img src="https://iili.io/KmIFoe1.md.png" alt="Logo SDN Sumberejo">
|
||||
<span class="ms-2 fw-bold">SDN Sumberejo</span>
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<div class="navbar-nav ms-auto">
|
||||
<a href="login.php?role=siswa" class="btn btn-outline-primary me-2">Login Siswa</a>
|
||||
<a href="login.php?role=guru" class="btn btn-primary">Login Guru/Admin</a>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<header class="hero-section">
|
||||
<div class="container">
|
||||
<h1 class="display-4">Ulangan Harian Online</h1>
|
||||
<p class="lead">Platform ujian modern, aman, dan mudah digunakan untuk SDN Sumberejo.</p>
|
||||
<a href="#features" class="btn btn-light btn-lg mt-3">Lihat Fitur</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section id="features" class="features-section">
|
||||
<div class="container">
|
||||
<div class="row text-center">
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="feature-icon mb-3"><i class="bi bi-shield-check"></i></div>
|
||||
<h3>Ujian Aman</h3>
|
||||
<p>Dilengkapi fitur pengawasan untuk memastikan integritas ujian.</p>
|
||||
</div>
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="feature-icon mb-3"><i class="bi bi-graph-up-arrow"></i></div>
|
||||
<h3>Hasil Real-time</h3>
|
||||
<p>Nilai untuk soal pilihan ganda langsung tampil setelah ujian selesai.</p>
|
||||
</div>
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="feature-icon mb-3"><i class="bi bi-phone-flip"></i></div>
|
||||
<h3>Mobile Friendly</h3>
|
||||
<p>Dapat diakses dengan nyaman melalui komputer, tablet, maupun smartphone.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container text-center">
|
||||
<p>© <?php echo date('Y'); ?> SDN Sumberejo. All Rights Reserved.</p>
|
||||
<p>Built with <a href="https://flatlogic.com" class="text-white">Flatlogic</a></p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
116
login.php
Normal file
116
login.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// If user is already logged in, redirect to dashboard
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
if ($_SESSION['role'] === 'guru') {
|
||||
header("Location: dashboard_guru.php");
|
||||
} else {
|
||||
header("Location: dashboard_siswa.php");
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
$role = htmlspecialchars($_GET['role'] ?? 'Siswa');
|
||||
$page_title = 'Login ' . ucfirst($role);
|
||||
$error_message = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
$login_role = strtolower($role);
|
||||
|
||||
if (empty($username) || empty($password)) {
|
||||
$error_message = "Username dan password tidak boleh kosong.";
|
||||
} else {
|
||||
try {
|
||||
$stmt = db()->prepare("SELECT * FROM users WHERE username = ? AND role = ?");
|
||||
$stmt->execute([$username, $login_role]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
// Password is correct, start session
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
$_SESSION['role'] = $user['role'];
|
||||
$_SESSION['full_name'] = $user['full_name'];
|
||||
|
||||
// Redirect to a dashboard page based on role
|
||||
if ($user['role'] === 'guru') {
|
||||
header("Location: dashboard_guru.php");
|
||||
} else {
|
||||
header("Location: dashboard_siswa.php");
|
||||
}
|
||||
exit();
|
||||
} else {
|
||||
// Use a generic error message to avoid user enumeration
|
||||
$error_message = "Username atau password salah.";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// Log error properly in a real application
|
||||
$error_message = "Terjadi kesalahan pada sistem. Silakan coba lagi nanti.";
|
||||
// error_log("Login 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>
|
||||
<meta name="description" content="Halaman login untuk platform ulangan harian online SDN Sumberejo.">
|
||||
<meta name="keywords" content="login, ujian online, sdn sumberejo, siswa, guru, admin, Built with Flatlogic Generator">
|
||||
<meta property="og:title" content="<?php echo $page_title; ?> - Ulangan Harian Online">
|
||||
<meta property="og:description" content="Halaman login untuk platform ulangan harian online SDN Sumberejo.">
|
||||
<meta property="og:image" content="https://iili.io/KmIFoe1.md.png">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="https://iili.io/KmIFoe1.md.png">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="login-container">
|
||||
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||
<div class="card login-card">
|
||||
<div class="card-header">
|
||||
<img src="https://iili.io/KmIFoe1.md.png" alt="Logo SDN Sumberejo">
|
||||
<h3 class="mt-3"><?php echo $page_title; ?></h3>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<?php if (!empty($error_message)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php echo $error_message; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="login.php?role=<?php echo strtolower($role); ?>" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="username" name="username" placeholder="Masukkan Username Anda" required>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-gradient fw-bold">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="text-center mt-4">
|
||||
<a href="index.php">Kembali ke Halaman Utama</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
91
submit_exam.php
Normal file
91
submit_exam.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Make sure the user is a logged-in student
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'siswa') {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Ensure it's a POST request
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header("Location: dashboard_siswa.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$exam_id = $_POST['exam_id'] ?? null;
|
||||
$answers = $_POST['answers'] ?? [];
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
if (!$exam_id || empty($answers)) {
|
||||
// Redirect if data is incomplete
|
||||
header("Location: dashboard_siswa.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total_questions = count($answers);
|
||||
$correct_answers = 0;
|
||||
|
||||
// Loop through submitted answers and check correctness
|
||||
foreach ($answers as $question_id => $choice_id) {
|
||||
$stmt = db()->prepare("SELECT is_correct FROM choices WHERE id = ? AND question_id = ?");
|
||||
$stmt->execute([$choice_id, $question_id]);
|
||||
$choice = $stmt->fetch();
|
||||
|
||||
if ($choice && $choice['is_correct']) {
|
||||
$correct_answers++;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate score
|
||||
$score = ($total_questions > 0) ? ($correct_answers / $total_questions) * 100 : 0;
|
||||
|
||||
// Save the result to the database
|
||||
$insert_stmt = db()->prepare("INSERT INTO exam_results (exam_id, user_id, score) VALUES (?, ?, ?)");
|
||||
$insert_stmt->execute([$exam_id, $user_id, $score]);
|
||||
|
||||
// Fetch exam details for display
|
||||
$exam_stmt = db()->prepare("SELECT title FROM exams WHERE id = ?");
|
||||
$exam_stmt->execute([$exam_id]);
|
||||
$exam = $exam_stmt->fetch();
|
||||
|
||||
$page_title = "Hasil Ujian";
|
||||
?>
|
||||
<!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_siswa.php">Ulangan Harian Online</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="card text-center">
|
||||
<div class="card-header">
|
||||
<h3>Hasil Ujian: <?php echo htmlspecialchars($exam['title']); ?></h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h1 class="display-4">Skor Anda:</h1>
|
||||
<h2 class="display-1 text-success"><?php echo round($score, 2); ?></h2>
|
||||
<p class="lead">
|
||||
Anda menjawab <?php echo $correct_answers; ?> dari <?php echo $total_questions; ?> pertanyaan dengan benar.
|
||||
</p>
|
||||
</div>
|
||||
<div class="card-footer text-muted">
|
||||
<a href="dashboard_siswa.php" class="btn btn-primary">Kembali ke Dashboard</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
94
take_exam.php
Normal file
94
take_exam.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Redirect to login if user is not logged in or not a student
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'siswa') {
|
||||
header("Location: login.php?role=siswa");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Check if exam_id is provided
|
||||
if (!isset($_GET['exam_id'])) {
|
||||
header("Location: dashboard_siswa.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$exam_id = $_GET['exam_id'];
|
||||
|
||||
// Fetch exam details
|
||||
$exam_stmt = db()->prepare("SELECT * FROM exams WHERE id = ?");
|
||||
$exam_stmt->execute([$exam_id]);
|
||||
$exam = $exam_stmt->fetch();
|
||||
|
||||
if (!$exam) {
|
||||
// Exam not found
|
||||
header("Location: dashboard_siswa.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch questions and choices
|
||||
$questions_stmt = db()->prepare("SELECT * FROM questions WHERE exam_id = ? ORDER BY id");
|
||||
$questions_stmt->execute([$exam_id]);
|
||||
$questions = $questions_stmt->fetchAll();
|
||||
|
||||
$page_title = "Kerjakan Ujian: " . htmlspecialchars($exam['title']);
|
||||
|
||||
?>
|
||||
<!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_siswa.php">Ulangan Harian Online</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container mt-4">
|
||||
<h1 class="mb-4"><?php echo htmlspecialchars($exam['title']); ?></h1>
|
||||
<p><?php echo htmlspecialchars($exam['description']); ?></p>
|
||||
|
||||
<form action="submit_exam.php" method="post">
|
||||
<input type="hidden" name="exam_id" value="<?php echo $exam_id; ?>">
|
||||
|
||||
<?php foreach ($questions as $q_index => $question): ?>
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
Pertanyaan #<?php echo $q_index + 1; ?>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text"><?php echo htmlspecialchars($question['question_text']); ?></p>
|
||||
|
||||
<?php
|
||||
// Fetch choices for this question
|
||||
$choices_stmt = db()->prepare("SELECT * FROM choices WHERE question_id = ? ORDER BY id");
|
||||
$choices_stmt->execute([$question['id']]);
|
||||
$choices = $choices_stmt->fetchAll();
|
||||
?>
|
||||
|
||||
<?php foreach ($choices as $choice): ?>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="answers[<?php echo $question['id']; ?>]" id="choice-<?php echo $choice['id']; ?>" value="<?php echo $choice['id']; ?>" required>
|
||||
<label class="form-check-label" for="choice-<?php echo $choice['id']; ?>">
|
||||
<?php echo htmlspecialchars($choice['choice_text']); ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-lg">Selesaikan Ujian</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user