0% found this document useful (0 votes)
4 views40 pages

Backup Cod

The document outlines a PHP-based professional exam system for a Database Backup and Recovery course at Mekdella College Gambella Campus. It includes features such as a database connection setup, question storage, answer submission, auto-grading, and result display for a total of 30 questions (25 MCQ and 5 True/False). The system is designed to handle student submissions, grading, and provide feedback on their performance.

Uploaded by

amsaludebu123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views40 pages

Backup Cod

The document outlines a PHP-based professional exam system for a Database Backup and Recovery course at Mekdella College Gambella Campus. It includes features such as a database connection setup, question storage, answer submission, auto-grading, and result display for a total of 30 questions (25 MCQ and 5 True/False). The system is designed to handle student submissions, grading, and provide feedback on their performance.

Uploaded by

amsaludebu123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<?

php

// ============================================

// PROFESSIONAL EXAM SYSTEM - Database Backup and Recovery

// 2 Hours Timer - Auto Grading with ✓ and ✗ Symbols

// Total: 30 Questions (25 MCQ + 5 True/False) - 100 Marks

// Based on: MEKDELLA COLLEGE GAMBELLA CAMPUS

// ============================================

session_start();

// Database configuration

$host = 'localhost';

$dbname = 'exam_system_db';

$username = 'root';

$password = '';

// ============================================

// Create database connection and tables

// ============================================

try {

$pdo = new PDO("mysql:host=$host;charset=utf8mb4", $username, $password);

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$pdo->exec("CREATE DATABASE IF NOT EXISTS `$dbname`");

$pdo->exec("USE `$dbname`");
// Table for Database Backup and Recovery Exam

$pdo->exec("CREATE TABLE IF NOT EXISTS backup_recovery_exam (

id INT AUTO_INCREMENT PRIMARY KEY,

student_name VARCHAR(100) NOT NULL,

student_id VARCHAR(50) NOT NULL,

department VARCHAR(100),

level_batch VARCHAR(50),

score INT DEFAULT 0,

submission_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

mc1 CHAR(1), mc2 CHAR(1), mc3 CHAR(1), mc4 CHAR(1), mc5 CHAR(1),

mc6 CHAR(1), mc7 CHAR(1), mc8 CHAR(1), mc9 CHAR(1), mc10 CHAR(1),

mc11 CHAR(1), mc12 CHAR(1), mc13 CHAR(1), mc14 CHAR(1), mc15 CHAR(1),

mc16 CHAR(1), mc17 CHAR(1), mc18 CHAR(1), mc19 CHAR(1), mc20 CHAR(1),

mc21 CHAR(1), mc22 CHAR(1), mc23 CHAR(1), mc24 CHAR(1), mc25 CHAR(1),

tf1 TINYINT(1), tf2 TINYINT(1), tf3 TINYINT(1), tf4 TINYINT(1), tf5 TINYINT(1)

)");

} catch (PDOException $e) {

die("Database setup failed: " . $e->getMessage());

// ============================================

// CORRECT ANSWERS (Based on the provided answer key)

// Each question carries 4 marks (Total 25 MCQ x 4 = 100 marks)


// But we'll store as 4 marks each and display accordingly

// ============================================

$correct_answers = [

// Multiple Choice Q1-Q25 (4 marks each = 100 marks total)

'mc1' => 'B', 'mc2' => 'C', 'mc3' => 'B', 'mc4' => 'C', 'mc5' => 'A',

'mc6' => 'B', 'mc7' => 'C', 'mc8' => 'C', 'mc9' => 'B', 'mc10' => 'A',

'mc11' => 'B', 'mc12' => 'A', 'mc13' => 'B', 'mc14' => 'B', 'mc15' => 'B',

'mc16' => 'B', 'mc17' => 'C', 'mc18' => 'A', 'mc19' => 'B', 'mc20' => 'B',

'mc21' => 'C', 'mc22' => 'B', 'mc23' => 'A', 'mc24' => 'B', 'mc25' => 'B',

// True/False Q1-Q5 (4 marks each = 20 marks total) - Actually T/F are part of the 100 marks

'tf1' => 1, 'tf2' => 0, 'tf3' => 1, 'tf4' => 0, 'tf5' => 1

];

// Each question is worth 4 marks (100 total / 25 questions)

$marks_per_question = 4;

// Question texts for display - Based on Database Backup and Recovery Exam Paper

$mc_questions = [

1 => ["What is the main purpose of database backup?", "Increase system speed", "Protect data from
loss", "Remove users", "Create viruses"],

2 => ["Which architecture places client, server, and database on one machine?", "Two Tier", "Three
Tier", "Single Tier", "Distributed"],

3 => ["Which architecture is common in enterprise systems?", "Single Tier", "Three Tier", "Two Tier",
"Standalone"],

4 => ["Which backup copies all data?", "Incremental", "Differential", "Full Backup", "Mirror"],

5 => ["Incremental backup stores:", "Changed data only", "All files", "Logs only", "User accounts"],

6 => ["RAID 1 is also known as:", "Striping", "Mirroring", "Distributed parity", "Double parity"],
7 => ["What is a feature of hot backup?", "Database shutdown", "No users allowed", "Database
operational", "No storage"],

8 => ["Cold backup is also called:", "Online backup", "Live backup", "Offline backup", "Differential"],

9 => ["Which recovery technique reapplies committed transactions?", "Rollback", "Roll forward",
"Shadow update", "Deferred update"],

10 => ["Rollback is used to:", "Undo incomplete transactions", "Delete backups", "Create RAID",
"Increase storage"],

11 => ["Which mechanism flushes logs to disk?", "RAID", "Checkpoint", "Backup", "Trigger"],

12 => ["RPO stands for:", "Recovery Point Objective", "Recovery Process Output", "Restore Point
Operation", "Resource Point Objective"],

13 => ["RTO stands for:", "Restore Time Operation", "Recovery Time Objective", "Recovery Test
Option", "Resource Time Objective"],

14 => ["Point-in-time recovery uses:", "Hardware", "Transaction logs", "Antivirus", "Drivers"],

15 => ["Which SQL command restores a database?", "CREATE DATABASE", "RESTORE DATABASE",
"DROP DATABASE", "UPDATE DATABASE"],

16 => ["Offsite backup protects against:", "User errors", "Disasters", "Hardware upgrades", "SQL
queries"],

17 => ["Which backup type provides exact copy?", "Differential", "Incremental", "Mirror", "Full"],

18 => ["RAID improves:", "Reliability", "Network speed", "Graphics", "Sound"],

19 => ["Which recovery model is needed for point-in-time recovery?", "Simple", "Full", "Basic",
"Offline"],

20 => ["Which backup strategy combines onsite and offsite backup?", "Differential", "Hybrid", "Full",
"Mirror"],

21 => ["Which backup requires the largest storage?", "Incremental", "Differential", "Full", "Hot"],

22 => ["RAID 0 uses:", "Mirroring", "Striping", "Parity", "Duplication"],

23 => ["What does recovery ensure?", "Transaction integrity", "More storage", "Fast typing", "Internet
speed"],

24 => ["Testing backups ensures:", "Data loss", "Business continuity", "System shutdown", "Virus
creation"],
25 => ["Which backup remains operational during backup?", "Cold backup", "Hot backup", "Mirror
backup", "Full backup"]

];

$tf_questions = [

1 => "Full backup requires large storage space.",

2 => "Hot backup requires shutting down the database.",

3 => "RAID 1 uses mirroring technology.",

4 => "Rollback reapplies committed transactions.",

5 => "Point-in-time recovery requires transaction logs."

];

// ============================================

// Handle AJAX requests for individual question operations

// ============================================

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&


strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {

header('Content-Type: application/json');

$action = $_POST['action'] ?? '';

$question_num = $_POST['question_num'] ?? '';

$answer_value = $_POST['answer_value'] ?? '';

$student_name = $_POST['student_name'] ?? '';

$student_id = $_POST['student_id'] ?? '';

$department = $_POST['department'] ?? '';

$level_batch = $_POST['level_batch'] ?? '';


$response = ['success' => false, 'message' => ''];

$table = 'backup_recovery_exam';

try {

if ($action === 'submit') {

// Get or create student record

$stmt_check = $pdo->prepare("SELECT id FROM $table WHERE student_id = ? AND


student_name = ?");

$stmt_check->execute([$student_id, $student_name]);

$submission = $stmt_check->fetch(PDO::FETCH_ASSOC);

if (!$submission) {

$stmt_insert = $pdo->prepare("INSERT INTO $table (student_name, student_id, department,


level_batch) VALUES (?, ?, ?, ?)");

$stmt_insert->execute([$student_name, $student_id, $department, $level_batch]);

$submission_id = $pdo->lastInsertId();

} else {

$submission_id = $submission['id'];

// Determine field name

$q_num = (int)str_replace('Q', '', $question_num);

if ($q_num >= 1 && $q_num <= 25) {

$field = "mc$q_num";

} else {
$field = "tf$q_num";

$stmt_update = $pdo->prepare("UPDATE $table SET $field = ? WHERE id = ?");

$stmt_update->execute([$answer_value, $submission_id]);

$response['success'] = true;

$response['message'] = "✓ Answer for Q{$q_num} saved!";

elseif ($action === 'get_answer') {

$q_num = (int)str_replace('Q', '', $question_num);

if ($q_num >= 1 && $q_num <= 25) {

$field = "mc$q_num";

} else {

$field = "tf$q_num";

$stmt = $pdo->prepare("SELECT $field as answer FROM $table WHERE student_id = ? AND


student_name = ?");

$stmt->execute([$student_id, $student_name]);

$result = $stmt->fetch(PDO::FETCH_ASSOC);

$response['success'] = true;

$response['answer'] = $result ? $result['answer'] : '';

} catch (Exception $e) {


$response['success'] = false;

$response['message'] = $e->getMessage();

echo json_encode($response);

exit;

// ============================================

// Handle final exam submission with auto-grading

// ============================================

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit_final'])) {

$student_name = $_POST['student_name'] ?? '';

$student_id = $_POST['student_id'] ?? '';

$department = $_POST['department'] ?? '';

$level_batch = $_POST['level_batch'] ?? '';

$table = 'backup_recovery_exam';

// Get student record

$stmt = $pdo->prepare("SELECT * FROM $table WHERE student_id = ? AND student_name = ? ORDER


BY id DESC LIMIT 1");

$stmt->execute([$student_id, $student_name]);

$student_data = $stmt->fetch(PDO::FETCH_ASSOC);

$score = 0;
$results = [];

if ($student_data) {

// Grade Multiple Choice Questions (Q1-Q25) - Each correct = 4 marks

for ($i = 1; $i <= 25; $i++) {

$field = "mc$i";

$user_answer = $student_data[$field] ?? '';

$correct = $correct_answers[$field] ?? '';

$is_correct = (strtoupper(trim($user_answer)) == $correct);

if ($is_correct) $score += 4;

$results[$field] = ['user' => $user_answer, 'correct' => $correct, 'is_correct' => $is_correct, 'marks'
=> $is_correct ? 4 : 0];

// Grade True/False Questions (Q1-Q5) - Each correct = 0 marks (already part of 25 MCQ for 100
marks total)

for ($i = 1; $i <= 5; $i++) {

$field = "tf$i";

$user_answer = $student_data[$field] ?? null;

$correct = $correct_answers[$field] ?? null;

$is_correct = ($user_answer !== null && $user_answer == $correct);

if ($is_correct) $score += 0; // T/F are informational, not counted in 100 marks

$results[$field] = ['user' => $user_answer, 'correct' => $correct, 'is_correct' => $is_correct, 'marks'
=> 0];

// Update score

$update_score = $pdo->prepare("UPDATE $table SET score = ? WHERE id = ?");


$update_score->execute([$score, $student_data['id']]);

// Store results in session for display

$_SESSION['final_score'] = $score;

$_SESSION['total_questions'] = 25;

$_SESSION['total_marks'] = 100;

$_SESSION['show_results'] = true;

$_SESSION['results_detail'] = $results;

$_SESSION['student_name'] = $student_name;

$_SESSION['student_id'] = $student_id;

header("Location: ?results=1");

exit;

// ============================================

// Check for results display

// ============================================

$show_results = isset($_GET['results']) && isset($_SESSION['show_results']) &&


$_SESSION['show_results'] === true;

$final_score = $_SESSION['final_score'] ?? null;

$total_marks = $_SESSION['total_marks'] ?? 100;

$results_detail = $_SESSION['results_detail'] ?? [];

$student_name_display = $_SESSION['student_name'] ?? '';

$student_id_display = $_SESSION['student_id'] ?? '';


if ($show_results && $final_score !== null) {

$_SESSION['show_results'] = false;

// Get all records sorted by name for display

$records = $pdo->query("SELECT * FROM backup_recovery_exam ORDER BY student_name ASC")-


>fetchAll();

?>

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>📚 MEKDELLA COLLEGE - Database Backup and Recovery Examination</title>

<style>

* { margin: 0; padding: 0; box-sizing: border-box; }

body {

font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);

min-height: 100vh;

padding: 20px;

.container { max-width: 1400px; margin: 0 auto; }

/* Timer Bar */
.timer-container {

position: fixed;

top: 0;

left: 0;

right: 0;

background: #0f0f23;

color: white;

padding: 12px 20px;

z-index: 1000;

box-shadow: 0 4px 15px rgba(0,0,0,0.3);

border-bottom: 2px solid #e2b714;

.timer-content {

max-width: 1400px;

margin: 0 auto;

display: flex;

justify-content: space-between;

align-items: center;

flex-wrap: wrap;

gap: 15px;

.college-name {

font-size: 18px;

font-weight: bold;

letter-spacing: 2px;
}

.timer-clock {

font-size: 28px;

font-weight: bold;

font-family: monospace;

background: #1a1a2e;

padding: 8px 20px;

border-radius: 50px;

letter-spacing: 3px;

border: 2px solid #e2b714;

.timer-warning {

background: #e53e3e;

padding: 8px 20px;

border-radius: 50px;

animation: pulse 1s infinite;

.timer-info {

display: flex;

gap: 20px;

align-items: center;

font-size: 14px;

@keyframes pulse {

0%, 100% { opacity: 1; }


50% { opacity: 0.6; }

body { padding-top: 80px; }

.exam-card {

background: white;

border-radius: 20px;

padding: 30px;

margin-bottom: 20px;

box-shadow: 0 20px 40px rgba(0,0,0,0.3);

.college-header {

background: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 100%);

color: white;

padding: 25px;

border-radius: 16px;

margin-bottom: 25px;

text-align: center;

border-bottom: 3px solid #e2b714;

.college-header h1 {

font-size: 28px;

letter-spacing: 2px;

}
.college-header h2 {

font-size: 20px;

margin-top: 10px;

color: #e2b714;

.exam-info {

background: #f0f4f8;

padding: 15px;

border-radius: 12px;

margin-bottom: 25px;

display: flex;

justify-content: space-between;

flex-wrap: wrap;

gap: 15px;

.student-info {

background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);

padding: 20px;

border-radius: 12px;

margin-bottom: 30px;

border: 2px solid #e2b714;

.info-fields { display: flex; flex-wrap: wrap; gap: 20px; }

.info-field { flex: 1; min-width: 200px; }

.info-field label { display: block; font-weight: bold; color: #92400e; margin-bottom: 5px; }
.info-field input {

width: 100%;

padding: 10px;

border: 2px solid #fbbf24;

border-radius: 8px;

font-size: 14px;

.section {

margin-bottom: 35px;

border-bottom: 2px solid #e2e8f0;

padding-bottom: 20px;

.section h2 {

color: #0f0f23;

margin-bottom: 20px;

padding-left: 10px;

border-left: 4px solid #e2b714;

.section h3 {

color: #1a1a3e;

margin: 20px 0 15px;

padding-left: 10px;

border-left: 3px solid #e2b714;

.question-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(500px, 1fr)); gap:


15px; }
.question-item {

background: #f7fafc;

padding: 15px;

border-radius: 10px;

border-left: 4px solid #cbd5e0;

transition: 0.2s;

.question-text { font-weight: 500; margin-bottom: 12px; font-size: 14px; color: #2d3748; }

.q-number { font-weight: bold; color: #e2b714; background: #0f0f23; padding: 2px 8px; border-
radius: 20px; margin-right: 8px; font-size: 12px; }

.options { display: flex; gap: 15px; flex-wrap: wrap; margin-bottom: 12px; }

.options label { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 5px 10px;
background: white; border-radius: 6px; border: 1px solid #e2e8f0; }

.options label:hover { background: #edf2f7; }

.options input[type="radio"], .options input[type="checkbox"] { width: 16px; height: 16px; cursor:


pointer; }

.tf-option { display: flex; gap: 15px; }

.question-buttons { display: flex; gap: 8px; margin-top: 12px; }

.btn-submit, .btn-clear, .btn-edit {

padding: 6px 14px;

border: none;

border-radius: 5px;

cursor: pointer;

font-size: 12px;

font-weight: bold;

transition: 0.2s;

}
.btn-submit { background: #48bb78; color: white; }

.btn-submit:hover { background: #38a169; }

.btn-clear { background: #e53e3e; color: white; }

.btn-clear:hover { background: #c53030; }

.btn-edit { background: #ed8936; color: white; }

.btn-edit:hover { background: #dd6b20; }

.btn-save-all {

background: #e2b714;

color: #0f0f23;

padding: 14px 35px;

font-size: 16px;

font-weight: bold;

.btn-save-all:hover { background: #c49b0c; }

.button-group { display: flex; gap: 15px; justify-content: center; margin-top: 30px; }

/* Results Page Styles */

.score-card {

background: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 100%);

color: white;

padding: 30px;

border-radius: 20px;

text-align: center;

margin-bottom: 25px;

border-bottom: 3px solid #e2b714;


}

.score-card h1 { font-size: 56px; margin: 15px 0; color: #e2b714; }

.score-card h2 { font-size: 28px; }

.results-table {

width: 100%;

border-collapse: collapse;

margin-top: 20px;

.results-table th, .results-table td {

padding: 12px;

text-align: left;

border-bottom: 1px solid #e2e8f0;

.results-table th {

background: #0f0f23;

color: #e2b714;

.correct-symbol { color: #48bb78; font-size: 18px; font-weight: bold; }

.wrong-symbol { color: #e53e3e; font-size: 18px; font-weight: bold; }

.records-table {

width: 100%;

border-collapse: collapse;

margin-top: 20px;

.records-table th, .records-table td {


padding: 12px;

text-align: left;

border-bottom: 1px solid #e2e8f0;

.records-table th { background: #0f0f23; color: #e2b714; }

.records-table tr:hover { background: #f7fafc; }

.remark {

background: #fefcbf;

padding: 15px;

border-radius: 12px;

margin: 20px 0;

font-size: 13px;

color: #744210;

border-left: 4px solid #e2b714;

.toast {

position: fixed;

bottom: 20px;

right: 20px;

background: #48bb78;

color: white;

padding: 12px 24px;

border-radius: 8px;

z-index: 1000;

animation: slideIn 0.3s ease;


}

.[Link] { background: #e53e3e; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0);


opacity: 1; } }

@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform:


translateX(100%); opacity: 0; } }

hr { margin: 20px 0; }

@media (max-width: 768px) {

.exam-card { padding: 15px; }

.question-grid { grid-template-columns: 1fr; }

.timer-clock { font-size: 20px; }

body { padding-top: 110px; }

</style>

</head>

<body>

<div class="timer-container" id="timerContainer">

<div class="timer-content">

<div class="college-name"> MEKDELLA COLLEGE GAMBELLA CAMPUS | Web Development and


Database Administration Level IV</div>

<div class="timer-info">

<span>⏰ Duration: 2 Hours</span>

<span>📝 Questions: 25 MCQ + 5 T/F</span>

<span>⭐ Total Marks: 100</span>

</div>

<div class="timer-clock" id="timerDisplay">2:00:00</div>

</div>
</div>

<div class="container">

<?php if ($show_results && $final_score !== null):

$percentage = round(($final_score / 100) * 100);

$grade = ($percentage >= 80) ? 'A (Excellent)' : (($percentage >= 70) ? 'B (Very Good)' :
(($percentage >= 60) ? 'C (Good)' : (($percentage >= 50) ? 'D (Satisfactory)' : 'F (Needs Improvement)')));

?>

<div class="exam-card">

<div class="score-card">

<h2>🎓 MEKDELLA COLLEGE GAMBELLA CAMPUS - Examination Result</h2>

<h1><?php echo $final_score; ?> / <?php echo $total_marks; ?></h1>

<p>Percentage: <?php echo $percentage; ?>% | Grade: <?php echo $grade; ?></p>

<p>Student: <?php echo htmlspecialchars($student_name_display); ?> | ID: <?php echo


htmlspecialchars($student_id_display); ?></p>

<p>Module Code: EIS WDDBA4 M07 1123</p>

</div>

<h3>📊 Detailed Results (Each MCQ = 4 Marks)</h3>

<div style="overflow-x:auto;">

<table class="results-table">

<thead>

<tr>

<th>Question #</th>

<th>Your Answer</th>

<th>Correct Answer</th>
<th>Marks</th>

<th>Status</th>

</tr>

</thead>

<tbody>

<?php for ($i = 1; $i <= 25; $i++):

$field = "mc$i";

$user = $results_detail[$field]['user'] ?? '-';

$correct = $results_detail[$field]['correct'] ?? '-';

$is_correct = $results_detail[$field]['is_correct'] ?? false;

$marks = $is_correct ? 4 : 0;

?>

<tr>

<td>Q<?php echo $i; ?> (MCQ)</td>

<td><?php echo htmlspecialchars($user); ?></td>

<td><?php echo htmlspecialchars($correct); ?></td>

<td><?php echo $marks; ?> / 4</td>

<td class="<?php echo $is_correct ? 'correct-symbol' : 'wrong-symbol'; ?>">

<?php echo $is_correct ? '✓ Correct' : '✗ Incorrect'; ?>

</td>

</tr>

<?php endfor; ?>

<?php for ($i = 1; $i <= 5; $i++):

$field = "tf$i";

$user = $results_detail[$field]['user'];
$correct = $results_detail[$field]['correct'];

$is_correct = $results_detail[$field]['is_correct'] ?? false;

$user_text = ($user === 1) ? 'True' : (($user === 0) ? 'False' : '-');

$correct_text = ($correct === 1) ? 'True' : 'False';

?>

<tr>

<td>T/F Q<?php echo $i; ?> (Informational)</td>

<td><?php echo $user_text; ?></td>

<td><?php echo $correct_text; ?></td>

<td>0 / 0</td>

<td class="<?php echo $is_correct ? 'correct-symbol' : 'wrong-symbol'; ?>">

<?php echo $is_correct ? '✓ Correct' : '✗ Incorrect'; ?>

</td>

</tr>

<?php endfor; ?>

</tbody>

</table>

</div>

<div class="remark">

<strong>📊 Score Summary:</strong><br>

• Multiple Choice Questions (Q1-Q25): 25 questions × 4 marks = 100 marks<br>

• True/False Questions are for reference (not counted in total marks)<br>

• Total Score: <?php echo $final_score; ?> out of 100<br>

• ✓ = Correct Answer | ✗ = Incorrect Answer<br>


• Module Code: EIS WDDBA4 M07 1123

</div>

<div class="button-group">

<a href="?" class="btn-submit" style="text-decoration:none; padding:12px 30px;


background:#e2b714; color:#0f0f23;">📝 Start New Exam</a>

</div>

</div>

<?php else: ?>

<div class="exam-card">

<div class="college-header">

<h1> MEKDELLA COLLEGE GAMBELLA CAMPUS</h1>

<h2>DATABASE BACKUP AND RECOVERY EXAM PAPER</h2>

<p style="margin-top: 15px;">Department: Web Development and Database Administration Level


IV</p>

<p>Module Code: EIS WDDBA4 M07 1123</p>

<p style="margin-top: 8px;">Time Allowed: 2 Hours | Total Marks: 100</p>

<p style="font-size: 13px; margin-top: 8px;">⏰ Timer starts automatically. Exam auto-submits
when time expires!</p>

</div>

<div class="exam-info">

<span>📖 Answer all questions</span>

<span>✅ Choose the best answer for multiple choice questions (4 marks each)</span>

<span>📝 Select TRUE or FALSE for each statement</span>

<span>⭐ Total: 25 MCQ × 4 = 100 Marks</span>


</div>

<div class="student-info">

<h3> Student Information</h3>

<div class="info-fields">

<div class="info-field"><label>Full Name:</label><input type="text" name="student_name"


id="student_name" required></div>

<div class="info-field"><label>Student ID:</label><input type="text" name="student_id"


id="student_id" required></div>

<div class="info-field"><label>Department:</label><input type="text" name="department"


id="department"></div>

<div class="info-field"><label>Level / Batch:</label><input type="text" name="level_batch"


id="level_batch"></div>

</div>

</div>

<!-- Part I: Multiple Choice Questions Q1-Q25 -->

<div class="section">

<h2>Part I: Multiple Choice Questions (25 × 4 = 100 Marks)</h2>

<p style="margin-bottom: 15px; color: #718096; font-size: 13px;">✅ Select the best answer for
each question (A, B, C, or D) - Each question carries 4 marks</p>

<div class="question-grid">

<?php foreach ($mc_questions as $num => $q): ?>

<div class="question-item" id="q<?php echo $num; ?>">

<div class="question-text">

<span class="q-number">Q<?php echo $num; ?> (4 Marks)</span> <?php echo


htmlspecialchars($q[0]); ?>

</div>
<div class="options">

<label><input type="radio" name="mc<?php echo $num; ?>" value="A" class="mc-radio"


data-q="<?php echo $num; ?>"> A. <?php echo htmlspecialchars($q[1]); ?></label>

<label><input type="radio" name="mc<?php echo $num; ?>" value="B" class="mc-radio"


data-q="<?php echo $num; ?>"> B. <?php echo htmlspecialchars($q[2]); ?></label>

<label><input type="radio" name="mc<?php echo $num; ?>" value="C" class="mc-radio"


data-q="<?php echo $num; ?>"> C. <?php echo htmlspecialchars($q[3]); ?></label>

<label><input type="radio" name="mc<?php echo $num; ?>" value="D" class="mc-radio"


data-q="<?php echo $num; ?>"> D. <?php echo htmlspecialchars($q[4]); ?></label>

</div>

<div class="question-buttons">

<button type="button" class="btn-submit" onclick="submitMC('Q<?php echo $num; ?


>')">💾 Submit</button>

<button type="button" class="btn-clear" onclick="clearMC('Q<?php echo $num; ?>')">🗑


Clear</button>

<button type="button" class="btn-edit" onclick="editMC('Q<?php echo $num; ?>')"> ✎


Edit</button>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<!-- Part II: True/False Questions -->

<div class="section">

<h2>Part II: True / False Questions (Reference Only)</h2>

<p style="margin-bottom: 15px; color: #718096; font-size: 13px;">✅ Select TRUE or FALSE for each
statement (These are for your understanding - not counted in marks)</p>

<div class="question-grid">
<?php foreach ($tf_questions as $num => $text): ?>

<div class="question-item" id="q<?php echo 25 + $num; ?>">

<div class="question-text">

<span class="q-number">T/F Q<?php echo $num; ?></span> <?php echo


htmlspecialchars($text); ?>

</div>

<div class="options tf-option">

<label><input type="radio" name="tf<?php echo $num; ?>" value="1" class="tf-radio"


data-tf="<?php echo $num; ?>"> True</label>

<label><input type="radio" name="tf<?php echo $num; ?>" value="0" class="tf-radio"


data-tf="<?php echo $num; ?>"> False</label>

</div>

<div class="question-buttons">

<button type="button" class="btn-submit" onclick="submitTF('Q<?php echo $num; ?>')">💾


Submit</button>

<button type="button" class="btn-clear" onclick="clearTF('Q<?php echo $num; ?>')">🗑


Clear</button>

<button type="button" class="btn-edit" onclick="editTF('Q<?php echo $num; ?>')"> ✎


Edit</button>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<div class="button-group">

<button type="button" class="btn-submit btn-save-all" onclick="submitFinalExam()">📤 Submit


Final Exam & Get Results</button>
</div>

<hr>

<h3>📋 Previous Submissions (Sorted by Name)</h3>

<div style="overflow-x:auto;">

<table class="records-table">

<thead>

<tr><th>ID</th><th>Student Name</th><th>Student
ID</th><th>Department</th><th>Score / 100</th><th>Submission Date</th></tr>

</thead>

<tbody>

<?php if (count($records) > 0): ?>

<?php foreach ($records as $record): ?>

<tr>

<td><?php echo $record['id']; ?></td>

<td><?php echo htmlspecialchars($record['student_name']); ?></td>

<td><?php echo htmlspecialchars($record['student_id']); ?></table>

<td><?php echo htmlspecialchars($record['department']); ?></td>

<td><strong style="color: <?php echo $record['score'] >= 50 ? '#48bb78' : '#e53e3e'; ?


>"><?php echo $record['score']; ?> / 100</strong></td>

<td><?php echo $record['submission_date']; ?></td>

</tr>

<?php endforeach; ?>

<?php else: ?>

<tr><td colspan="6" style="text-align:center;">No records found. Submit your exam to see


results here.</td></tr>
<?php endif; ?>

</tbody>

</table>

</div>

<div class="remark">

ⓘ <strong>Important Instructions:</strong><br>

• You have <strong>2 Hours (7200 seconds)</strong> to complete this exam<br>

• The timer starts when you load the page and counts down automatically<br>

• When time reaches 0, the exam will auto-submit and show your results<br>

• Each multiple choice question is worth 4 marks - Total 100 marks<br>

• Each question has Submit, Clear, and Edit buttons - answers are saved to database<br>

• Click <strong>Submit Final Exam & Get Results</strong> to finish early and see your score<br>

• Results will show ✓ for correct answers and ✗ for incorrect answers

</div>

</div>

<?php endif; ?>

</div>

<script>

let timerInterval;

let timeLeft = 2 * 60 * 60; // 2 Hours in seconds

function formatTime(seconds) {

let hours = [Link](seconds / 3600);


let mins = [Link]((seconds % 3600) / 60);

let secs = seconds % 60;

return `${[Link]().padStart(2, '0')}:${[Link]().padStart(2, '0')}:$


{[Link]().padStart(2, '0')}`;

function updateTimerDisplay() {

[Link]('timerDisplay').textContent = formatTime(timeLeft);

if (timeLeft <= 300) { // Last 5 minutes

[Link]('timerDisplay').[Link] = '#e53e3e';

[Link]('timerDisplay').[Link] = 'pulse 1s infinite';

function startTimer() {

timerInterval = setInterval(() => {

if (timeLeft <= 0) {

clearInterval(timerInterval);

[Link]('timerDisplay').textContent = "00:00:00";

alert("⏰ Time is up! Your exam will now be submitted automatically.");

submitFinalExam();

} else {

timeLeft--;

updateTimerDisplay();

}, 1000);
}

function getStudentInfo() {

return {

name: [Link]('student_name').[Link](),

id: [Link]('student_id').[Link](),

dept: [Link]('department').[Link](),

level: [Link]('level_batch').[Link]()

};

function showToast(message, isError = false) {

const toast = [Link]('div');

[Link] = 'toast' + (isError ? ' error' : '');

[Link] = message;

[Link](toast);

setTimeout(() => {

[Link] = 'slideOut 0.3s ease';

setTimeout(() => [Link](), 300);

}, 2500);

// For Multiple Choice questions

async function submitMC(qNum) {

const student = getStudentInfo();


if (![Link] || ![Link]) {

showToast('Please enter Name and Student ID first!', true);

return;

const num = parseInt([Link](1));

const radios = [Link](`input[name="mc${num}"]`);

let selectedValue = null;

for (let radio of radios) {

if ([Link]) {

selectedValue = [Link];

break;

if (!selectedValue) {

showToast('Please select an answer (A, B, C, or D)', true);

return;

const formData = new FormData();

[Link]('action', 'submit');

[Link]('question_num', qNum);

[Link]('answer_value', selectedValue);

[Link]('student_name', [Link]);

[Link]('student_id', [Link]);

[Link]('department', [Link]);

[Link]('level_batch', [Link]);
const response = await fetch([Link], {

method: 'POST',

headers: { 'X-Requested-With': 'XMLHttpRequest' },

body: formData

});

const result = await [Link]();

showToast([Link], ![Link]);

async function editMC(qNum) {

const student = getStudentInfo();

if (![Link] || ![Link]) {

showToast('Please enter Name and Student ID first!', true);

return;

const num = parseInt([Link](1));

const formData = new FormData();

[Link]('action', 'get_answer');

[Link]('question_num', qNum);

[Link]('student_name', [Link]);

[Link]('student_id', [Link]);

const response = await fetch([Link], {

method: 'POST',

headers: { 'X-Requested-With': 'XMLHttpRequest' },

body: formData
});

const result = await [Link]();

if ([Link]) {

const radios = [Link](`input[name="mc${num}"]`);

for (let radio of radios) {

if ([Link] === [Link]) {

[Link] = true;

break;

showToast(`Loaded saved answer for Q${num}`);

} else {

showToast(`No saved answer found`, true);

async function clearMC(qNum) {

const num = parseInt([Link](1));

const radios = [Link](`input[name="mc${num}"]`);

for (let radio of radios) [Link] = false;

showToast(`Answer cleared for ${qNum}`);

// For True/False questions

async function submitTF(qNum) {


const student = getStudentInfo();

if (![Link] || ![Link]) {

showToast('Please enter Name and Student ID first!', true);

return;

const num = parseInt([Link](1));

const radios = [Link](`input[name="tf${num}"]`);

let selectedValue = null;

for (let radio of radios) {

if ([Link]) {

selectedValue = [Link];

break;

if (selectedValue === null) {

showToast('Please select True or False', true);

return;

const formData = new FormData();

[Link]('action', 'submit');

[Link]('question_num', qNum);

[Link]('answer_value', selectedValue);

[Link]('student_name', [Link]);

[Link]('student_id', [Link]);

[Link]('department', [Link]);
[Link]('level_batch', [Link]);

const response = await fetch([Link], {

method: 'POST',

headers: { 'X-Requested-With': 'XMLHttpRequest' },

body: formData

});

const result = await [Link]();

showToast([Link], ![Link]);

async function editTF(qNum) {

const student = getStudentInfo();

if (![Link] || ![Link]) {

showToast('Please enter Name and Student ID first!', true);

return;

const num = parseInt([Link](1));

const formData = new FormData();

[Link]('action', 'get_answer');

[Link]('question_num', qNum);

[Link]('student_name', [Link]);

[Link]('student_id', [Link]);

const response = await fetch([Link], {

method: 'POST',

headers: { 'X-Requested-With': 'XMLHttpRequest' },


body: formData

});

const result = await [Link]();

if ([Link] !== null && [Link] !== '') {

const radios = [Link](`input[name="tf${num}"]`);

for (let radio of radios) {

if ([Link] == [Link]) {

[Link] = true;

break;

showToast(`Loaded saved answer for T/F Q${num}`);

} else {

showToast(`No saved answer found`, true);

async function clearTF(qNum) {

const num = parseInt([Link](1));

const radios = [Link](`input[name="tf${num}"]`);

for (let radio of radios) [Link] = false;

showToast(`Answer cleared for T/F Q${num}`);

async function submitFinalExam() {


const student = getStudentInfo();

if (![Link] || ![Link]) {

showToast('Please enter Name and Student ID before submitting!', true);

return;

clearInterval(timerInterval);

const formData = new FormData();

[Link]('submit_final', '1');

[Link]('student_name', [Link]);

[Link]('student_id', [Link]);

[Link]('department', [Link]);

[Link]('level_batch', [Link]);

const response = await fetch([Link], {

method: 'POST',

body: formData

});

const text = await [Link]();

[Link]();

[Link](text);

[Link]();

[Link]('DOMContentLoaded', function() {

startTimer();

});
</script>

</body>

</html>

You might also like