<?php
// 1. REVEAL CRITICAL ERRORS IF ANY THING GOES WRONG
error_reporting(E_ALL);
ini_set('display_errors', 1);

session_start();

// 2. DIRECT ACCESS CONTROL CHECK (Plain text bypass key)
if (isset($_POST['admin_login'])) {
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    if ($username === 'admin' && $password === 'admin123') {
        $_SESSION['admin_logged'] = true;
    } else {
        $msg = "Invalid Admin Credentials!";
    }
}

if (isset($_GET['logout'])) {
    unset($_SESSION['admin_logged']);
    header("Location: admin.php");
    exit();
}

if (!isset($_SESSION['admin_logged'])):
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CBT Admin Entrance Portal</title>
    <style>
        body { font-family: Arial, sans-serif; background: #1e222b; color: white; text-align: center; margin: 0; padding: 20px; }
        .box { max-width: 360px; margin: 120px auto; background: #282c34; padding: 35px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.3); border-top: 5px solid #007bff; }
        input { width: 100%; padding: 12px; margin: 12px 0; border: 1px solid #444; background: #21252b; color: white; border-radius: 4px; box-sizing: border-box; }
        .btn { width: 100%; padding: 12px; background: #007bff; border: none; color: white; font-weight: bold; font-size: 16px; border-radius: 4px; cursor: pointer; }
        .btn:hover { background: #0056b3; }
        .error { color: #ff6b6b; font-size: 14px; margin-bottom: 15px; text-align: left; }
		
		
		 

    </style>
</head>
<body>
<div class="box">
    <h3>CBT Administrative Access</h3>
    <?php if(isset($msg)) { echo "<div class='error'>⚠️ $msg</div>"; } ?>
    <form method="POST" action="admin.php">
        <input type="text" name="username" placeholder="Username (admin)" required autocomplete="off">
        <input type="password" name="password" placeholder="Password (admin123)" required>
        <button type="submit" name="admin_login" class="btn">Dashboard Login</button>
    </form>
</div>
</body>
</html>
<?php 
exit(); 
endif; 
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CBT System Admin Panel</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; height: 100vh; background: #f0f2f5; overflow: hidden; }
        
        /* Left Menu Layout Styles */
        .sidebar { width: 260px; background: #007bff; color: white; display: flex; flex-direction: column; box-shadow: 2px 0 10px rgba(0,0,0,0.1); }
        .sidebar-header { background: #0056b3; padding: 20px; text-align: center; font-size: 20px; font-weight: bold; letter-spacing: 0.5px; }
        .menu-list { display: flex; flex-direction: column; padding: 15px 10px; gap: 8px; flex-grow: 1; }
        .menu-btn { display: block; padding: 12px 15px; background: #0069d9; color: white; text-decoration: none; border-radius: 6px; font-weight: bold; font-size: 14px; transition: background 0.2s, padding-left 0.2s; border-left: 4px solid transparent; }
        .menu-btn:hover { background: #0056b3; padding-left: 20px; border-left-color: #ffc107; }
        .menu-btn.logout-btn { background: #d9534f; margin-top: auto; text-align: center; border-left: none; }
        .menu-btn.logout-btn:hover { background: #b52b27; padding-left: 15px; }
        
        /* Right Main Content Display Area Workspace */
        .main-content { flex-grow: 1; display: flex; flex-direction: column; background: #f0f2f5; }
        .top-bar { background: #343a40; color: white; padding: 15px 30px; font-size: 18px; font-weight: bold; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
        .workspace-iframe { width: 100%; flex-grow: 1; border: none; background: #fff; }
    </style>
</head>
<body>

    <!-- LEFT BAR NAVIGATION COMPONENT -->
    <div class="sidebar">
        <div class="sidebar-header">Admin Menu</div>
        <div class="menu-list">
            <!-- target="workspace" forces the file to load dynamically in the right iframe container box -->
            <a href="add_student.php" target="workspace" class="menu-btn">👤 Add Student</a>
             <a href="edit_student.php" target="workspace" class="menu-btn">✏️ Edit Student Information</a>
             
             <!-- TAB HEADER NAVIGATION SYSTEM inside upload_csv.php -->
 
             <!-- TAB HEADER NAVIGATION SYSTEM inside upload_csv.php -->
              
             
             
            <a href="upload_question.php" target="workspace" class="menu-btn">📝 Upload Question</a>
            
              <a href="upload_csv.php" target="workspace" class="menu-btn">📊 Bulk Import via CSV File</a>
            
            
            
<a href="assign_class.php" target="workspace" class="menu-btn">🔗 Assign Question to Class</a>
            <!-- Inside your sidebar links wrapper section of admin.php -->
 

<!-- UPDATE THESE TWO LINES TO CONNECT TARGETS -->
<a href="delete_question.php" target="workspace" class="menu-btn">❌ Delete Question</a>
<!--<a href="#" onclick="alert('Feature placeholder')" class="menu-btn">🔗 Assign Question to Class</a>-->
<a href="score_sheets.php" target="workspace" class="menu-btn">🖨️ Score Sheets</a>
<!--<a href="#" onclick="alert('Feature placeholder')" class="menu-btn">📊 EED - Score Sheets</a> -->
 
<a href="authorise.php" target="workspace" class="menu-btn">🛡️ Authorise Student Retake</a>

<a href="set_duration.php" target="workspace" class="menu-btn">⏱️ Set Examination Duration</a>
            
            <a href="admin.php?logout=1" class="menu-btn logout-btn">🔒 Logout Control Center</a>
        </div>
    </div>

    <!-- RIGHT PANEL DYNAMIC WORKSPACE PANEL -->
    <div class="main-content">
        <div class="top-bar">CBT System Administration Console Terminal Dashboard</div>
        <!-- Default landing splash page template sets to open add_student.php natively -->
        <iframe name="workspace" src="add_student.php" class="workspace-iframe"></iframe>
    </div>

</body>
