<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Define base URLs for navigation
// $is_root_page is set to true when called from root index.php
if (!isset($is_root_page)) {
    $is_root_page = false;
}

if ($is_root_page) {
    $base_url = "/Hessar_college/main/";
    $root_url = "/Hessar_college/";
} else {
    $base_url = "/Hessar_college/main/";
    $root_url = "/Hessar_college/";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HASSER ONLINE - College of Technology</title>
    <!-- Google Fonts -->
    <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=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome for icons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <!-- Animate.css for animations -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="/Hessar_college/assets/style.css">
</head>
<body>

<?php if(!isset($_SESSION['user_id'])): ?>
<div class="top-bar bg-blue text-dark py-2 d-none d-lg-block border-bottom">
    <div class="container-fluid px-4">
        <div class="d-flex justify-content-between align-items-center">
            <div class="small">
                <i class="fas fa-phone me-2"></i> +254790666507
                <i class="fas fa-envelope ms-3 me-2"></i> info@hessarcollege.edu
            </div>
            <div class="social-links">
                <a href="https://wa.me/254790666507" class="text-dark me-3 text-decoration-none" target="_blank"><i class="fab fa-whatsapp fa-lg"></i></a>
                <a href="#" class="text-dark me-3 text-decoration-none" target="_blank"><i class="fab fa-facebook fa-lg"></i></a>
                <a href="#" class="text-dark text-decoration-none" target="_blank"><i class="fab fa-instagram fa-lg"></i></a>
            </div>
        </div>
    </div>
</div>
<?php endif; ?>

<nav class="navbar navbar-expand-lg navbar-light bg-yellowish sticky-top border-bottom" style="z-index: 1050;">
    <div class="container-fluid px-4">
        <?php if(isset($_SESSION['user_id'])): ?>
            <button class="btn text-dark me-2" id="sidebarToggle">
                <i class="fas fa-bars"></i>
            </button>
        <?php endif; ?>
        <a class="navbar-brand d-flex align-items-center" href="<?php echo $root_url; ?>index.php">
            <img SRC="images/logo.png" alt="" class="me-2 rounded-circle shadow-sm" style="height: 50px;">
            <span class="fw-bold">HASSER ONLINE COLLEGE</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">
            <ul class="navbar-nav ms-auto align-items-center">
                <li class="nav-item">
                    <a class="nav-link" href="<?php echo $root_url; ?>index.php">Home</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="coursesDropdown" role="button" data-bs-toggle="dropdown">
                        Courses
                    </a>
                    <ul class="dropdown-menu shadow border-0">
                        <li><a class="dropdown-item" href="<?php echo $base_url; ?>courses.php?cat=web-design">Web Design</a></li>
                        <li><a class="dropdown-item" href="<?php echo $base_url; ?>courses.php?cat=computer-science">Computer Science</a></li>
                        <li><a class="dropdown-item" href="<?php echo $base_url; ?>courses.php?cat=it">Information Technology</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="<?php echo $base_url; ?>courses.php">All Courses</a></li>
                    </ul>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="servicesDropdown" role="button" data-bs-toggle="dropdown">
                        Services
                    </a>
                    <ul class="dropdown-menu shadow border-0">
                        <li><a class="dropdown-item" href="<?php echo $root_url; ?>index.php#services"><i class="fas fa-tools me-2"></i>Computer Repairing</a></li>
                        <li><a class="dropdown-item" href="<?php echo $root_url; ?>index.php#services"><i class="fas fa-network-wired me-2"></i>Network Installation</a></li>
                        <li><a class="dropdown-item" href="<?php echo $root_url; ?>index.php#services"><i class="fas fa-print me-2"></i>Stationaries & Printing</a></li>
                    </ul>
                </li>
                <?php if(!isset($_SESSION['user_id'])): ?>
                    <li class="nav-item">
                        <a class="nav-link" href="<?php echo $base_url; ?>about.php">About</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?php echo $base_url; ?>products.php">Our Products</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?php echo $base_url; ?>application.php">Application</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?php echo $base_url; ?>contacts.php">Contacts</a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link btn btn-outline-light px-3 ms-lg-2 dropdown-toggle" href="#" id="loginDropdown" role="button" data-bs-toggle="dropdown">
                            Login
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end shadow border-0">
                            <li><a class="dropdown-item" href="<?php echo $base_url; ?>login.php?role=student"><i class="fas fa-user-graduate me-2"></i>Student Login</a></li>
                            <li><a class="dropdown-item" href="<?php echo $base_url; ?>login.php?role=lecturer"><i class="fas fa-chalkboard-teacher me-2"></i>Lecturer Login</a></li>
                            <li><a class="dropdown-item" href="<?php echo $base_url; ?>login.php?role=admin"><i class="fas fa-user-shield me-2"></i>Admin Login</a></li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link btn btn-primary text-white px-3 ms-lg-2" href="<?php echo $base_url; ?>signup.php">Student Signup</a>
                    </li>
                <?php else: ?>
                    <li class="nav-item dropdown ms-lg-3">
                        <a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="fas fa-user-circle fa-lg me-2"></i>
                            <span><?php echo htmlspecialchars($_SESSION['username']); ?></span>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end shadow border-0">
                            <li><a class="dropdown-item" href="<?php echo $base_url; ?>profile.php"><i class="fas fa-user me-2"></i>Profile</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item text-danger" href="<?php echo $base_url; ?>logout.php"><i class="fas fa-sign-out-alt me-2"></i>Logout</a></li>
                        </ul>
                    </li>
                <?php endif; ?>
                <!-- Social Media for Mobile -->
                <li class="nav-item d-lg-none mt-3 text-center border-top pt-3">
                    <a href="https://wa.me/254701932255" class="text-white mx-3 text-decoration-none" target="_blank"><i class="fab fa-whatsapp fa-xl"></i></a>
                    <a href="#" class="text-white mx-3 text-decoration-none" target="_blank"><i class="fab fa-facebook fa-xl"></i></a>
                    <a href="#" class="text-white mx-3 text-decoration-none" target="_blank"><i class="fab fa-instagram fa-xl"></i></a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<?php if(isset($_SESSION['user_id'])): 
    $role = $_SESSION['role'];
?>
<div class="sidebar shadow" id="sidebar">
    <div class="sidebar-inner">
        <div class="sidebar-user p-3 border-bottom">
            <div class="d-flex align-items-center">
                <div class="rounded-circle bg-yellowish d-flex align-items-center justify-content-center me-3 shadow-sm" style="width:48px;height:48px;">
                    <i class="fas fa-user text-primary"></i>
                </div>
                <div class="overflow-hidden">
                    <div class="fw-semibold text-truncate"><?php echo htmlspecialchars($_SESSION['username']); ?></div>
                    <span class="badge bg-warning text-dark text-uppercase small"><?php echo $role; ?></span>
                </div>
            </div>
        </div>
        <div class="nav flex-column pt-2">
            <a href="<?php echo $base_url; ?>dashboard.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'dashboard.php' ? 'active' : ''; ?>" title="Dashboard" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-tachometer-alt"></i> Dashboard
            </a>
        
        <?php if($role == 'admin'): ?>
            <div class="px-3 py-2 text-uppercase small text-muted group-title">Admin Modules</div>
            <a href="<?php echo $base_url; ?>manage_users.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'manage_users.php' ? 'active' : ''; ?>" title="Manage Users" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-users-cog"></i> Manage Users
            </a>
            <a href="<?php echo $base_url; ?>manage_applications.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'manage_applications.php' ? 'active' : ''; ?>" title="Manage Applications" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-file-signature"></i> Manage Applications
            </a>
            <a href="<?php echo $base_url; ?>manage_courses.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'manage_courses.php' ? 'active' : ''; ?>" title="Manage Courses" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-book"></i> Manage Courses
            </a>
            <a href="<?php echo $base_url; ?>manage_appeals.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'manage_appeals.php' ? 'active' : ''; ?>" title="Manage Appeals" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-gavel"></i> Manage Appeals
            </a>
             <a href="<?php echo $base_url; ?>manage_payments.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'manage_payments.php' ? 'active' : ''; ?>" title="Payments & Arrears" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-money-check-alt"></i> Payments & Arrears
            </a>

            <div class="px-3 py-2 text-uppercase small text-muted group-title">PRODUCTS</div>

            <a href="<?php echo $base_url; ?>products.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'add_product.php' ? 'active' : ''; ?>" title="Add Product" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-box-open"></i> Products
            </a>
           
            <div class="px-3 py-2 text-uppercase small text-muted group-title">REPORTS</div>

            <a class="nav-link d-flex justify-content-between align-items-center <?php echo in_array(basename($_SERVER['PHP_SELF']), ['reports.php']) ? 'active' : ''; ?>" data-bs-toggle="collapse" href="#reportsMenu" role="button" aria-expanded="<?php echo basename($_SERVER['PHP_SELF']) == 'reports.php' ? 'true' : 'false'; ?>" aria-controls="reportsMenu" title="Reports" data-bs-toggle="tooltip" data-bs-placement="right">
                <span><i class="fas fa-chart-bar me-1"></i> Reports</span>
                <i class="fas fa-chevron-down small chevron"></i>
            </a>
            <div class="collapse submenu <?php echo basename($_SERVER['PHP_SELF']) == 'reports.php' ? 'show' : ''; ?>" id="reportsMenu">
                <a href="<?php echo $base_url; ?>reports.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'reports.php' ? 'active' : ''; ?>">
                    <i class="fas fa-file-alt"></i> System Reports
                </a>
            </div>
        <?php endif; ?>

        <?php if($role == 'lecturer'): ?>
            <div class="px-3 py-2 text-uppercase small text-muted group-title">Academic</div>
            <a href="<?php echo $base_url; ?>my_courses.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'my_courses.php' ? 'active' : ''; ?>" title="My Courses" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-book"></i> My Courses
            </a>
            <a href="<?php echo $base_url; ?>my_students.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'my_students.php' ? 'active' : ''; ?>" title="My Students" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-user-graduate"></i> My Students
            </a>
            <a href="<?php echo $base_url; ?>manage_appeals.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'manage_appeals.php' ? 'active' : ''; ?>" title="Manage Appeals" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-gavel"></i> Manage Appeals
            </a>
            <a href="<?php echo $base_url; ?>upload_notes.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'upload_notes.php' ? 'active' : ''; ?>" title="Upload Notes" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-upload"></i> Upload Notes
            </a>
            <a href="<?php echo $base_url; ?>manage_assignments.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'manage_assignments.php' ? 'active' : ''; ?>" title="Manage Assignments" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-tasks"></i> Manage Assignments
            </a>
            <a href="<?php echo $base_url; ?>manage_results.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'manage_results.php' ? 'active' : ''; ?>" title="Manage Results" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-poll"></i> Manage Results
            </a>
        <?php endif; ?>

        <?php if($role == 'student'): ?>
            <div class="px-3 py-2 text-uppercase small text-muted group-title">Student Menu</div>
            <a href="<?php echo $base_url; ?>courses.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'courses.php' ? 'active' : ''; ?>" title="Register Courses" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-graduation-cap"></i> Register Courses
            </a>
            <a href="<?php echo $base_url; ?>assignments.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'assignments.php' ? 'active' : ''; ?>" title="My Assignments" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-tasks"></i> My Assignments
            </a>
            <a href="<?php echo $base_url; ?>my_learning.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'my_learning.php' ? 'active' : ''; ?>" title="Learning Materials" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-book-open"></i> Learning Materials
            </a>
            <a href="<?php echo $base_url; ?>view_results.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'view_results.php' ? 'active' : ''; ?>" title="My Results" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-file-invoice"></i> My Results
            </a>
            <a href="<?php echo $base_url; ?>fee_status.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'fee_status.php' ? 'active' : ''; ?>" title="Fees & Arrears" data-bs-toggle="tooltip" data-bs-placement="right">
                <i class="fas fa-wallet"></i> Fees & Arrears
            </a>
        <?php endif; ?>
        </div>
    </div>
</div>
<div class="sidebar-overlay" id="sidebarOverlay"></div>
<div class="content-wrapper">
<?php endif; ?>
