<?php
$current_page = basename($_SERVER['PHP_SELF']);
$current_role = $_SESSION['role'] ?? '';
?>

<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
    <!-- Brand Logo -->
    <a href="<?php echo WEB_ROOT; ?>dashboard.php" class="brand-link">
        <span class="brand-text font-weight-light">Web Devil</span>
    </a>

    <!-- Sidebar -->
    <div class="sidebar">
        <!-- User panel -->
        <div class="user-panel mt-3 pb-3 mb-3 d-flex">
            <div class="info">
                <a href="#" class="d-block">
                    <?php echo htmlspecialchars($_SESSION['name'] ?? 'User'); ?>
                </a>
                <small class="text-light">
                    <?php echo htmlspecialchars($_SESSION['role'] ?? 'user'); ?>
                </small>
            </div>
        </div>

        <!-- Sidebar Menu -->
        <nav class="mt-2">
            <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu">

                <li class="nav-item">
                    <a href="<?php echo WEB_ROOT; ?>dashboard.php" class="nav-link <?php echo ($current_page == 'dashboard.php') ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-tachometer-alt"></i>
                        <p>Dashboard</p>
                    </a>
                </li>

                <?php if (in_array($current_role, ['admin', 'teacher'])): ?>

						<!-- Students -->
						<?php

								$student_pages = [

									'index.php',
									'enquiry.php',
									'import_students.php',
									'preview_student_import.php',
									'student_promotion.php',
									'generate_id_card.php'

								];

								$student_paths = [

									'student/',
									'student-import/',
									'student-promotion/',
									'student-idcard/'

								];

								$current_uri = $_SERVER['REQUEST_URI'];

								$in_students = false;

								foreach ($student_paths as $path) {

									if (strpos($current_uri, $path) !== false) {

										$in_students = true;
										break;
									}
								}
								?>
						<li class="nav-item has-treeview <?php echo $in_students ? 'menu-open' : ''; ?>">

							<a href="#" class="nav-link <?php echo $in_students ? 'active' : ''; ?>">
								<i class="nav-icon fas fa-user-graduate"></i>

								<p>
									Students
									<i class="right fas fa-angle-left"></i>
								</p>
							</a>

							<ul class="nav nav-treeview">

								<li class="nav-item">

									<a href="<?php echo WEB_ROOT; ?>student/index.php" class="nav-link">

										<i class="fas fa-user-graduate nav-icon"></i>

										<p>Manage Students</p>

									</a>

								</li>
								<li class="nav-item">

									<a href="<?php echo WEB_ROOT; ?>student/enquiry.php" class="nav-link">

										<i class="fas fa-user-graduate nav-icon"></i>

										<p>Enquiry</p>

									</a>

								</li>
								<li class="nav-item">

									<a href="<?php echo WEB_ROOT; ?>student-import/import_students.php"
									   class="nav-link">

										<i class="fas fa-file-excel nav-icon"></i>

										<p>Student Import</p>

									</a>

								</li>

								<li class="nav-item">

									<a href="<?php echo WEB_ROOT; ?>student-promotion/student_promotion.php"
									   class="nav-link">

										<i class="fas fa-level-up-alt nav-icon"></i>

										<p>Student Promotion</p>

									</a>

								</li>

								<li class="nav-item">

									<a href="<?php echo WEB_ROOT; ?>student-idcard/generate_id_card.php"
									   class="nav-link">

										<i class="fas fa-id-card nav-icon"></i>

										<p>Student ID Cards</p>

									</a>

								</li>

							</ul>

						</li>

					<?php endif; ?>


						<?php if (in_array($current_role, ['admin', 'teacher'])): ?>

							<!-- Attendance -->
							<?php

								$attendance_pages = [

									'index.php',
									'report.php',
									'attendance_report_print.php',
									'holidays.php',
									'weekly_offs.php'

								];

								$attendance_paths = [

									'/attendance/'

								];

								$current_uri = $_SERVER['REQUEST_URI'];

								$in_attendance = false;

								foreach ($attendance_paths as $path) {

									if (strpos($current_uri, $path) !== false) {

										$in_attendance = true;
										break;
									}
								}

								?>

								<?php if (in_array($current_role, ['admin', 'teacher'])): ?>

									<!-- Attendance -->

									<li class="nav-item has-treeview <?=
										$in_attendance ? 'menu-open' : '';
									?>">

										<a
											href="#"
											class="nav-link <?=
												$in_attendance ? 'active' : '';
											?>"
										>

											<i class="nav-icon fas fa-clipboard-check"></i>

											<p>

												Attendance

												<i class="right fas fa-angle-left"></i>

											</p>

										</a>

										<ul class="nav nav-treeview">

											<!-- MARK ATTENDANCE -->

											<li class="nav-item">

												<a
													href="<?php echo WEB_ROOT; ?>attendance/index.php"

													class="nav-link <?=
														($current_page === 'index.php' &&
														strpos($current_uri, '/attendance/') !== false)

															? 'active'
															: '';
													?>"
												>

													<i class="fas fa-user-check nav-icon"></i>

													<p>

														Mark Attendance

													</p>

												</a>

											</li>

											<!-- ATTENDANCE REPORT -->

											<li class="nav-item">

												<a
													href="<?php echo WEB_ROOT; ?>attendance/report.php"

													class="nav-link <?=
														($current_page === 'report.php')

															? 'active'
															: '';
													?>"
												>

													<i class="fas fa-chart-bar nav-icon"></i>

													<p>

														Attendance Report

													</p>

												</a>

											</li>

										   

											<!-- STAFF ATTENDANCE -->

											<li class="nav-item">

												<a
													href="<?php echo WEB_ROOT; ?>teacher/view_staff_attendance.php"

													class="nav-link"
												>

													<i class="fas fa-chalkboard-teacher nav-icon"></i>

													<p>

														Staff Attendance

													</p>

												</a>

											</li>

											<?php if ($current_role === 'admin'): ?>

												<!-- HOLIDAYS -->

												<li class="nav-item">

													<a
														href="<?php echo WEB_ROOT; ?>attendance/holidays.php"

														class="nav-link <?=
															($current_page === 'holidays.php')

																? 'active'
																: '';
														?>"
													>

														<i class="fas fa-calendar-alt nav-icon"></i>

														<p>

															Holidays

														</p>

													</a>

												</li>

												<!-- WEEKLY OFFS -->

												<li class="nav-item">

													<a
														href="<?php echo WEB_ROOT; ?>attendance/weekly_offs.php"

														class="nav-link <?=
															($current_page === 'weekly_offs.php')

																? 'active'
																: '';
														?>"
													>

														<i class="fas fa-bed nav-icon"></i>

														<p>

															Weekly Offs

														</p>

													</a>

												</li>

											<?php endif; ?>

										</ul>

									</li>

								<?php endif; ?>

						<?php endif; ?>
				<?php

						/*
						|--------------------------------------------------------------------------
						| ACADEMICS ACTIVE MENU
						|--------------------------------------------------------------------------
						*/

						$academics_pages = [

							'index.php',
							'subject.php',
							'assign_subject.php',
							'timetable.php'

						];

						$current_uri = $_SERVER['REQUEST_URI'];

						$in_academics =
							strpos($current_uri, '/academics/') !== false
							||
							strpos($current_uri, '/teacher/') !== false
							||
							strpos($current_uri, '/classes/') !== false;

						?>

						<!-- ACADEMICS SECTION -->

						<li class="nav-item has-treeview <?=
							$in_academics ? 'menu-open' : '';
						?>">

							<a
								href="#"
								class="nav-link <?=
									$in_academics ? 'active' : '';
								?>"
							>

								<i class="nav-icon fas fa-book"></i>

								<p>

									Academics

									<i class="right fas fa-angle-left"></i>

								</p>

							</a>

							<ul class="nav nav-treeview">

								<!-- MANAGE STAFF -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>teacher/index.php"

										class="nav-link <?=
											(
												$current_page === 'index.php'
												&&
												strpos($current_uri, '/teacher/') !== false
											)

												? 'active'
												: '';
										?>"
									>

										<i class="fas fa-chalkboard-teacher nav-icon"></i>

										<p>

											Manage Staff

										</p>

									</a>

								</li>

								<!-- SUBJECTS -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>academics/subject.php"

										class="nav-link <?=
											($current_page === 'subject.php')

												? 'active'
												: '';
										?>"
									>

										<i class="fas fa-list nav-icon"></i>

										<p>

											Subjects

										</p>

									</a>

								</li>

								<!-- ASSIGN SUBJECTS -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>academics/assign_subject.php"

										class="nav-link <?=
											($current_page === 'assign_subject.php')

												? 'active'
												: '';
										?>"
									>

										<i class="fas fa-chalkboard-teacher nav-icon"></i>

										<p>

											Assign Subjects

										</p>

									</a>

								</li>

								<!-- TIMETABLE -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>academics/timetable.php"

										class="nav-link <?=
											($current_page === 'timetable.php')

												? 'active'
												: '';
										?>"
									>

										<i class="fas fa-calendar-alt nav-icon"></i>

										<p>

											Timetable

										</p>

									</a>

								</li>

								<!-- CLASS LIST -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>classes/index.php"

										class="nav-link <?=
											(
												$current_page === 'index.php'
												&&
												strpos($current_uri, '/classes/') !== false
											)

												? 'active'
												: '';
										?>"
									>

										<i class="fas fa-school nav-icon"></i>

										<p>

											Class List

										</p>

									</a>

								</li>

							</ul>

						</li>

                <?php

							/*
							|--------------------------------------------------------------------------
							| FEES ACTIVE MENU
							|--------------------------------------------------------------------------
							*/

							$fees_pages = [

								'index.php',
								'add_fees.php',
								'view_fees.php',
								'total_fees.php'

							];

							$current_uri = $_SERVER['REQUEST_URI'];

							$in_fees =
								strpos($current_uri, '/fees/') !== false;

							?>

							<!-- FEES SECTION -->

							<li class="nav-item has-treeview <?=
								$in_fees ? 'menu-open' : '';
							?>">

								<a
									href="#"
									class="nav-link <?=
										$in_fees ? 'active' : '';
									?>"
								>

									<i class="nav-icon fas fa-money-bill-wave"></i>

									<p>

										Fees

										<i class="right fas fa-angle-left"></i>

									</p>

								</a>

								<ul class="nav nav-treeview">

									<!-- DASHBOARD -->

									<li class="nav-item">

										<a
											href="<?= WEB_ROOT ?>fees/index.php"

											class="nav-link <?=
												(
													$current_page === 'index.php'
													&&
													strpos($current_uri, '/fees/') !== false
												)

													? 'active'
													: '';
											?>"
										>

											<i class="fas fa-tachometer-alt nav-icon"></i>

											<p>

												Dashboard

											</p>

										</a>

									</li>

									<!-- ADD RECEIPT -->

									<li class="nav-item">

										<a
											href="<?= WEB_ROOT ?>fees/add_fees.php"

											class="nav-link <?=
												($current_page === 'add_fees.php')

													? 'active'
													: '';
											?>"
										>

											<i class="fas fa-plus-circle nav-icon"></i>

											<p>

												Add Receipt

											</p>

										</a>

									</li>

									<!-- VIEW RECEIPTS -->

									<li class="nav-item">

										<a
											href="<?= WEB_ROOT ?>fees/view_fees.php"

											class="nav-link <?=
												($current_page === 'view_fees.php')

													? 'active'
													: '';
											?>"
										>

											<i class="fas fa-receipt nav-icon"></i>

											<p>

												View Receipts

											</p>

										</a>

									</li>

									<!-- TOTAL FEES -->

									<li class="nav-item">

										<a
											href="<?= WEB_ROOT ?>fees/total_fees.php"

											class="nav-link <?=
												($current_page === 'total_fees.php')

													? 'active'
													: '';
											?>"
										>

											<i class="fas fa-coins nav-icon"></i>

											<p>

												Total Fees

											</p>

										</a>

									</li>

								</ul>

							</li>
							
<?php

/*
|--------------------------------------------------------------------------
| INCOME ACTIVE MENU
|--------------------------------------------------------------------------
*/

$income_pages = [

    'add.php',
    'view_income.php',
    'income_category.php'

];

$current_uri = $_SERVER['REQUEST_URI'];

$in_income =
    strpos($current_uri, '/income/') !== false;

?>

<!-- INCOME SECTION -->

<li class="nav-item has-treeview <?=
    $in_income ? 'menu-open' : '';
?>">

    <a
        href="#"
        class="nav-link <?=
            $in_income ? 'active' : '';
        ?>"
    >

        <i class="nav-icon fas fa-wallet"></i>

        <p>

            Income

            <i class="right fas fa-angle-left"></i>

        </p>

    </a>

    <ul class="nav nav-treeview">

        <!-- ADD INCOME -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>income/add.php"

                class="nav-link <?=
                    ($current_page === 'add.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-plus-circle nav-icon"></i>

                <p>

                    Add Income

                </p>

            </a>

        </li>

        <!-- VIEW INCOME -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>income/view_income.php"

                class="nav-link <?=
                    ($current_page === 'view_income.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-list-ul nav-icon"></i>

                <p>

                    View All Income

                </p>

            </a>

        </li>

        <!-- INCOME CATEGORY -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>income/income_category.php"

                class="nav-link <?=
                    ($current_page === 'income_category.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-tags nav-icon"></i>

                <p>

                    Manage Categories

                </p>

            </a>

        </li>

    </ul>

</li>



<?php

/*
|--------------------------------------------------------------------------
| EXPENSE ACTIVE MENU
|--------------------------------------------------------------------------
*/

$expense_pages = [

    'add_expense.php',
    'view_expense.php',
    'expense_category.php'

];

$in_expense =
    strpos($current_uri, '/expense/') !== false;

?>

<!-- EXPENSE SECTION -->

<li class="nav-item has-treeview <?=
    $in_expense ? 'menu-open' : '';
?>">

    <a
        href="#"
        class="nav-link <?=
            $in_expense ? 'active' : '';
        ?>"
    >

        <i class="nav-icon fas fa-minus-circle"></i>

        <p>

            Expenses

            <i class="right fas fa-angle-left"></i>

        </p>

    </a>

    <ul class="nav nav-treeview">

        <!-- ADD EXPENSE -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>expense/add_expense.php"

                class="nav-link <?=
                    ($current_page === 'add_expense.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-plus-circle nav-icon"></i>

                <p>

                    Add Expense

                </p>

            </a>

        </li>

        <!-- VIEW EXPENSE -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>expense/view_expense.php"

                class="nav-link <?=
                    ($current_page === 'view_expense.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-list-ul nav-icon"></i>

                <p>

                    View Expenses

                </p>

            </a>

        </li>

        <!-- EXPENSE CATEGORY -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>expense/expense_category.php"

                class="nav-link <?=
                    ($current_page === 'expense_category.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-tags nav-icon"></i>

                <p>

                    Manage Categories

                </p>

            </a>

        </li>

    </ul>

</li>



<?php

/*
|--------------------------------------------------------------------------
| SALARY ACTIVE MENU
|--------------------------------------------------------------------------
*/

$salary_pages = [

    
    'generate_salary.php'

];

$in_salary =
    strpos($current_uri, '/salary/') !== false;

?>

<!-- SALARY SECTION -->

<li class="nav-item has-treeview <?=
    $in_salary ? 'menu-open' : '';
?>">

    <a
        href="#"
        class="nav-link <?=
            $in_salary ? 'active' : '';
        ?>"
    >

        <i class="nav-icon fas fa-hand-holding-usd"></i>

        <p>

            Salary

            <i class="right fas fa-angle-left"></i>

        </p>

    </a>

    <ul class="nav nav-treeview">

        <!-- SALARY PAYOUT -->

        

        <!-- GENERATE SALARY -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>salary/generate_salary.php"

                class="nav-link <?=
                    ($current_page === 'generate_salary.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-file-invoice-dollar nav-icon"></i>

                <p>

                    Generate Salary

                </p>

            </a>

        </li>

    </ul>

</li>
				
				 
				 <!-- Examinations Section -->
				 <?php

						$exam_pages = [

							'exam_types.php',
							'exam_schedule.php',
							'view_schedules.php',
							'exam_admit_card.php'

						];

						$in_exams = in_array($current_page, $exam_pages);

						?>
				<li class="nav-item has-treeview <?php echo $in_exams ? 'menu-open' : ''; ?>">
						<a href="#" class="nav-link <?php echo $in_exams ? 'active' : ''; ?>">
							<i class="nav-icon fas fa-clipboard-list"></i>
								<p>Examinations<i class="right fas fa-angle-left"></i></p>
						</a>
					<ul class="nav nav-treeview">
						<li class="nav-item">
							<a href="<?php echo WEB_ROOT; ?>exams/exam_types.php" class="nav-link">
								<i class="fas fa-cogs nav-icon"></i>
									<p>Exam Setup (Types)</p>
							</a>
						</li>
						<li class="nav-item">
							<a href="<?php echo WEB_ROOT; ?>exams/exam_schedule.php" class="nav-link">
								<i class="fas fa-calendar-alt nav-icon"></i>
									<p>Exam Schedule</p>
							</a>
						</li>
						<li class="nav-item">
							<a href="<?php echo WEB_ROOT; ?>exams/view_schedules.php" class="nav-link">
								<i class="fas fa-list nav-icon"></i>
									<p>View Schedules</p>
							</a>
						</li>
						<li class="nav-item">
							<a href="<?php echo WEB_ROOT; ?>exams/exam_admit_card.php" class="nav-link">
								<i class="fas fa-id-card nav-icon"></i>
									<p>Admit Cards</p>
							</a>
						</li>
						
					</ul>
				</li>
				
				<?php

/*
|--------------------------------------------------------------------------
| INVENTORY ACTIVE MENU
|--------------------------------------------------------------------------
*/

$inventory_pages = [

    'Inventory.php',
    'issue.php'

];

$current_uri = $_SERVER['REQUEST_URI'];

$in_inventory =
    strpos($current_uri, '/inventory/') !== false;

?>

<!-- INVENTORY SECTION -->

<li class="nav-item has-treeview <?=
    $in_inventory ? 'menu-open' : '';
?>">

    <a
        href="#"
        class="nav-link <?=
            $in_inventory ? 'active' : '';
        ?>"
    >

        <i class="nav-icon fas fa-boxes"></i>

        <p>

            Inventory

            <i class="right fas fa-angle-left"></i>

        </p>

    </a>

    <ul class="nav nav-treeview">

        <!-- INVENTORY LIST -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>inventory/Inventory.php"

                class="nav-link <?=
                    ($current_page === 'Inventory.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-list-ul nav-icon"></i>

                <p>

                    Inventory List

                </p>

            </a>

        </li>

        <!-- ISSUE ITEM -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>inventory/issue.php"

                class="nav-link <?=
                    ($current_page === 'issue.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-share-square nav-icon"></i>

                <p>

                    Issue Item

                </p>

            </a>

        </li>

    </ul>

</li>
				
				
				<?php

					/*
					|--------------------------------------------------------------------------
					| LIBRARY ACTIVE MENU
					|--------------------------------------------------------------------------
					*/

					$library_pages = [

						'add_book.php',
						'edit_book.php',
						'list_books.php',

						'add_member.php',
						'edit_member.php',
						'list_members.php',

						'book_issue.php',
						'list_issued_books.php'

					];

					$in_library = in_array(
						$current_page,
						$library_pages
					);

					?>

					<!-- LIBRARY MANAGEMENT -->

					<?php if (in_array($current_role, ['admin', 'teacher'])): ?>

					<li class="nav-item has-treeview <?=
						$in_library ? 'menu-open' : '';
					?>">

						<a
							href="#"
							class="nav-link <?=
								$in_library ? 'active' : '';
							?>"
						>

							<i class="nav-icon fas fa-book-reader"></i>

							<p>

								Library

								<i class="right fas fa-angle-left"></i>

							</p>

						</a>

						<ul class="nav nav-treeview">

							<!-- ADD BOOK -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>books/add_book.php"

									class="nav-link <?=
										($current_page === 'add_book.php')

											? 'active'
											: '';
									?>"
								>

									<i class="fas fa-plus-circle nav-icon"></i>

									<p>

										Add Book

									</p>

								</a>

							</li>

							<!-- BOOK LIST -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>books/list_books.php"

									class="nav-link <?=
										(
											$current_page === 'list_books.php' ||
											$current_page === 'edit_book.php'
										)

											? 'active'
											: '';
									?>"
								>

									<i class="fas fa-book nav-icon"></i>

									<p>

										Book List

									</p>

								</a>

							</li>

							<!-- ADD MEMBER -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>books/add_member.php"

									class="nav-link <?=
										($current_page === 'add_member.php')

											? 'active'
											: '';
									?>"
								>

									<i class="fas fa-user-plus nav-icon"></i>

									<p>

										Add Member

									</p>

								</a>

							</li>

							<!-- MEMBER LIST -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>books/list_members.php"

									class="nav-link <?=
										(
											$current_page === 'list_members.php' ||
											$current_page === 'edit_member.php'
										)

											? 'active'
											: '';
									?>"
								>

									<i class="fas fa-users nav-icon"></i>

									<p>

										Member List

									</p>

								</a>

							</li>

							<!-- ISSUE BOOK -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>books/book_issue.php"

									class="nav-link <?=
										($current_page === 'book_issue.php')

											? 'active'
											: '';
									?>"
								>

									<i class="fas fa-share-square nav-icon"></i>

									<p>

										Issue Book

									</p>

								</a>

							</li>

							<!-- ISSUED BOOKS -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>books/list_issued_books.php"

									class="nav-link <?=
										($current_page === 'list_issued_books.php')

											? 'active'
											: '';
									?>"
								>

									<i class="fas fa-history nav-icon"></i>

									<p>

										Issued Books

									</p>

								</a>

							</li>

						</ul>

					</li>



                <?php

/*
|--------------------------------------------------------------------------
| TRANSPORT ACTIVE MENU
|--------------------------------------------------------------------------
*/

$transport_pages = [

    'vehicles.php',
    'drivers.php',
    'routes.php',
    'assign_transport.php',
    'edit_allocation.php'

];

$current_uri = $_SERVER['REQUEST_URI'];

$in_transport =
    strpos($current_uri, '/transport/') !== false;

?>

<!-- TRANSPORT MANAGEMENT -->

<li class="nav-item has-treeview <?=
    $in_transport ? 'menu-open' : '';
?>">

    <a
        href="#"
        class="nav-link <?=
            $in_transport ? 'active' : '';
        ?>"
    >

        <i class="nav-icon fas fa-bus"></i>

        <p>

            Transport

            <i class="right fas fa-angle-left"></i>

        </p>

    </a>

    <ul class="nav nav-treeview">

        <!-- VEHICLES -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>transport/vehicles.php"

                class="nav-link <?=
                    ($current_page === 'vehicles.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-truck nav-icon"></i>

                <p>

                    Vehicles

                </p>

            </a>

        </li>

        <!-- DRIVERS -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>transport/drivers.php"

                class="nav-link <?=
                    ($current_page === 'drivers.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-id-card nav-icon"></i>

                <p>

                    Drivers

                </p>

            </a>

        </li>

        <!-- ROUTES -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>transport/routes.php"

                class="nav-link <?=
                    ($current_page === 'routes.php')

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-route nav-icon"></i>

                <p>

                    Routes

                </p>

            </a>

        </li>

        <!-- TRANSPORT ALLOCATION -->

        <li class="nav-item">

            <a
                href="<?php echo WEB_ROOT; ?>transport/assign_transport.php"

                class="nav-link <?=
                    (
                        $current_page === 'assign_transport.php'
                        ||
                        $current_page === 'edit_allocation.php'
                    )

                        ? 'active'
                        : '';
                ?>"
            >

                <i class="fas fa-user-plus nav-icon"></i>

                <p>

                    Allocation

                </p>

            </a>

        </li>

    </ul>

</li>
				<?php endif; ?>
				<?php


/*
|--------------------------------------------------------------------------
| EXAM RESULT MODULE ACTIVE MENU
|--------------------------------------------------------------------------
*/

$exam_result_pages = [

    'marks-entry.php',
    'generate-result.php',
    'result-view.php',
    'student-marksheet.php',
    'final-marksheet.php',
    'result-publish.php',
    'result-reports.php',
    'final-result-generation.php',
    'merit-list.php',
    'grading-system.php',
    'result-settings.php',
    'result-dashboard.php'

];

$current_uri = $_SERVER['REQUEST_URI'];

$in_exam_results =
    strpos($current_uri, '/marksheet/') !== false;

?>

<!-- EXAM RESULTS -->

<li class="nav-item has-treeview <?=
    $in_exam_results ? 'menu-open' : '';
?>">

    <a
        href="#"
        class="nav-link <?=
            $in_exam_results ? 'active' : '';
        ?>"
    >

        <i class="nav-icon fas fa-file-signature"></i>

        <p>

            Exam Results

            <i class="right fas fa-angle-left"></i>

        </p>

    </a>

    <ul class="nav nav-treeview">

        <!-- DASHBOARD -->

        <li class="nav-item">

            <a
                href="<?= WEB_ROOT; ?>marksheet/result-dashboard.php"
                class="nav-link <?= ($current_page === 'result-dashboard.php') ? 'active' : ''; ?>"
            >

                <i class="fas fa-chart-pie nav-icon"></i>

                <p>

                    Dashboard

                </p>

            </a>

        </li>

        <!-- MARKS ENTRY -->

        <li class="nav-item">

            <a
                href="<?= WEB_ROOT; ?>marksheet/marks-entry.php"
                class="nav-link <?= ($current_page === 'marks-entry.php') ? 'active' : ''; ?>"
            >

                <i class="fas fa-edit nav-icon"></i>

                <p>

                    Marks Entry

                </p>

            </a>

        </li>

        <!-- GENERATE RESULTS -->

        <li class="nav-item">

            <a
                href="<?= WEB_ROOT; ?>marksheet/generate-result.php"
                class="nav-link <?= ($current_page === 'generate-result.php') ? 'active' : ''; ?>"
            >

                <i class="fas fa-calculator nav-icon"></i>

                <p>

                    Generate Results

                </p>

            </a>

        </li>

        <!-- FINAL RESULTS -->

        <li class="nav-item">

            <a
                href="<?= WEB_ROOT; ?>marksheet/final-result-generation.php"
                class="nav-link <?= ($current_page === 'final-result-generation.php') ? 'active' : ''; ?>"
            >

                <i class="fas fa-file-invoice nav-icon"></i>

                <p>

                    Final Results

                </p>

            </a>

        </li>
		<!-- PUBLISH RESULTS -->

<li class="nav-item">

    <a
        href="<?= WEB_ROOT; ?>marksheet/result-publish.php"
        class="nav-link <?= ($current_page === 'result-publish.php') ? 'active' : ''; ?>"
    >

        <i class="fas fa-upload nav-icon"></i>

        <p>

            Publish Results

        </p>

    </a>

</li>

        <!-- RESULT REPORTS -->

        <li class="nav-item">

            <a
                href="<?= WEB_ROOT; ?>marksheet/result-reports.php"
                class="nav-link <?= ($current_page === 'result-reports.php') ? 'active' : ''; ?>"
            >

                <i class="fas fa-chart-bar nav-icon"></i>

                <p>

                    Result Reports

                </p>

            </a>

        </li>
		<!-- PRINT MARKSHEET -->

<li class="nav-item">

    <a
        href="<?= WEB_ROOT; ?>marksheet/result-view.php"
        class="nav-link <?= ($current_page === 'result-view.php') ? 'active' : ''; ?>"
    >

        <i class="fas fa-print nav-icon"></i>

        <p>

            Print Marksheet

        </p>

    </a>

</li>

        <!-- MERIT LIST -->

        <li class="nav-item">

            <a
                href="<?= WEB_ROOT; ?>marksheet/merit-list.php"
                class="nav-link <?= ($current_page === 'merit-list.php') ? 'active' : ''; ?>"
            >

                <i class="fas fa-trophy nav-icon"></i>

                <p>

                    Merit List

                </p>

            </a>

        </li>

        <!-- RESULT SETTINGS -->

        <li class="nav-item">

            <a
                href="<?= WEB_ROOT; ?>marksheet/result-settings.php"
                class="nav-link <?= ($current_page === 'result-settings.php') ? 'active' : ''; ?>"
            >

                <i class="fas fa-cogs nav-icon"></i>

                <p>

                    Result Settings

                </p>

            </a>

        </li>

        <!-- GRADING SYSTEM -->

        <li class="nav-item">

            <a
                href="<?= WEB_ROOT; ?>marksheet/grading-system.php"
                class="nav-link <?= ($current_page === 'grading-system.php') ? 'active' : ''; ?>"
            >

                <i class="fas fa-layer-group nav-icon"></i>

                <p>

                    Grading System

                </p>

            </a>

        </li>

    </ul>

</li>
				<!-- Add this after Transport Management section, before Configuration -->

					<?php

					/*
					|--------------------------------------------------------------------------
					| TC GENERATION ACTIVE MENU
					|--------------------------------------------------------------------------
					*/

					$tc_pages = [

						'tc_generate.php',
						'tc_list.php',
						'tc_view.php',
						'tc_print.php'

					];

					$current_uri = $_SERVER['REQUEST_URI'];

					$in_tc =
						strpos($current_uri, '/generate/') !== false
						&&
						in_array($current_page, $tc_pages);

					?>

					<!-- TC GENERATION -->

					<li class="nav-item has-treeview <?=
						$in_tc ? 'menu-open' : '';
					?>">

						<a
							href="#"
							class="nav-link <?=
								$in_tc ? 'active' : '';
							?>"
						>

							<i class="nav-icon fas fa-file-alt"></i>

							<p>

								TC Generation

								<i class="right fas fa-angle-left"></i>

							</p>

						</a>

						<ul class="nav nav-treeview">

							<!-- GENERATE TC -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>generate/tc_generate.php"

									class="nav-link <?=
										($current_page === 'tc_generate.php')

											? 'active'
											: '';
									?>"
								>

									<i class="far fa-file-alt nav-icon"></i>

									<p>

										Generate TC

									</p>

								</a>

							</li>

							<!-- TC LIST -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>generate/tc_list.php"

									class="nav-link <?=
										(
											$current_page === 'tc_list.php' ||
											$current_page === 'tc_view.php' ||
											$current_page === 'tc_print.php'
										)

											? 'active'
											: '';
									?>"
								>

									<i class="fas fa-list nav-icon"></i>

									<p>

										TC List

									</p>

								</a>

							</li>

						</ul>

					</li>

					<?php

					/*
					|--------------------------------------------------------------------------
					| NOTIFICATIONS ACTIVE MENU
					|--------------------------------------------------------------------------
					*/

					$notification_pages = [

						'add_notice.php',
						'list.php',
						'edit_notice.php'

					];

					$current_uri = $_SERVER['REQUEST_URI'];

					$in_notifications =
						strpos($current_uri, '/notifications/') !== false;

					?>

					<!-- NOTIFICATIONS -->

					<li class="nav-item has-treeview <?=
						$in_notifications ? 'menu-open' : '';
					?>">

						<a
							href="#"
							class="nav-link <?=
								$in_notifications ? 'active' : '';
							?>"
						>

							<i class="nav-icon fas fa-bell"></i>

							<p>

								Notifications

								<span class="right badge badge-danger" id="notif-badge">

									<?php

									$stmt = $pdo->prepare("

										SELECT COUNT(*)

										FROM notifications

										WHERE school_id = ?
										AND is_active = 1

									");

									$stmt->execute([$_SESSION['school_id']]);

									echo $stmt->fetchColumn();

									?>

								</span>

							</p>

						</a>

						<ul class="nav nav-treeview">

							<!-- NEW NOTICE -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>notifications/add_notice.php"

									class="nav-link <?=
										($current_page === 'add_notice.php')

											? 'active'
											: '';
									?>"
								>

									<i class="far fa-plus nav-icon"></i>

									<p>

										New Notice

									</p>

								</a>

							</li>

							<!-- ALL NOTICES -->

							<li class="nav-item">

								<a
									href="<?php echo WEB_ROOT; ?>notifications/list.php"

									class="nav-link <?=
										(
											$current_page === 'list.php' ||
											$current_page === 'edit_notice.php'
										)

											? 'active'
											: '';
									?>"
								>

									<i class="fas fa-list nav-icon"></i>

									<p>

										All Notices

									</p>

								</a>

							</li>

						</ul>

					</li>
						<!-- =========================================================
						REPORTS
						========================================================= -->

						<li class="nav-item has-treeview <?=
							(
								strpos($_SERVER['REQUEST_URI'], '/reports/') !== false
							) ? 'menu-open' : '';
						?>">

							<a href="#" class="nav-link <?=
								(
									strpos($_SERVER['REQUEST_URI'], '/reports/') !== false
								) ? 'active' : '';
							?>">

								<i class="nav-icon fas fa-chart-bar"></i>

								<p>

									Reports

									<i class="right fas fa-angle-left"></i>

								</p>

							</a>

							<ul class="nav nav-treeview">

								<!-- REPORT DASHBOARD -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>reports/index.php"
										class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'index.php' ? 'active' : ''; ?>"
									>

										<i class="far fa-circle nav-icon"></i>

										<p>

											Reports Dashboard

										</p>

									</a>

								</li>

								<!-- CLASS REPORT -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>reports/class_reports.php"
										class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'class_reports.php' ? 'active' : ''; ?>"
									>

										<i class="far fa-circle nav-icon"></i>

										<p>

											Class Reports

										</p>

									</a>

								</li>

								<!-- CATEGORY REPORT -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>reports/category_report.php"
										class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'category_report.php' ? 'active' : ''; ?>"
									>

										<i class="far fa-circle nav-icon"></i>

										<p>

											Category Report

										</p>

									</a>

								</li>

								<!-- RELIGION REPORT -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>reports/religion_report.php"
										class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'religion_report.php' ? 'active' : ''; ?>"
									>

										<i class="far fa-circle nav-icon"></i>

										<p>

											Religion Report

										</p>

									</a>

								</li>

								<!-- DOCUMENT REPORT -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>reports/document_missing_report.php"
										class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'document_missing_report.php' ? 'active' : ''; ?>"
									>

										<i class="far fa-circle nav-icon"></i>

										<p>

											Missing Documents

										</p>

									</a>

								</li>

								<!-- TRANSPORT REPORT -->

								<li class="nav-item">

									<a
										href="<?php echo WEB_ROOT; ?>reports/transport_report.php"
										class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'transport_report.php' ? 'active' : ''; ?>"
									>

										<i class="far fa-circle nav-icon"></i>

										<p>

											Transport Report

										</p>

									</a>

								</li>

							</ul>

						</li>
				<?php

							/*
							|--------------------------------------------------------------------------
							| HOMEWORK ACTIVE MENU
							|--------------------------------------------------------------------------
							*/

							$homework_pages = [

								'index.php',
								'create.php',
								'reports.php',
								'view.php',
								'edit.php'

							];

							$current_uri = $_SERVER['REQUEST_URI'];

							$in_homework =
								strpos($current_uri, '/homework/') !== false;

							?>

							<!-- HOMEWORK -->

							<li class="nav-item has-treeview <?=
								$in_homework ? 'menu-open' : '';
							?>">

								<a
									href="#"
									class="nav-link <?=
										$in_homework ? 'active' : '';
									?>"
								>

									<i class="nav-icon fas fa-book"></i>

									<p>

										Homework

										<i class="right fas fa-angle-left"></i>

									</p>

								</a>

								<ul class="nav nav-treeview">

									<!-- HOMEWORK LIST -->

									<li class="nav-item">

										<a
											href="<?php echo WEB_ROOT; ?>homework/index.php"

											class="nav-link <?=
												(
													$current_page === 'index.php'
													&&
													strpos($current_uri, '/homework/') !== false
												)

													? 'active'
													: '';
											?>"
										>

											<i class="far fa-circle nav-icon"></i>

											<p>

												Homework List

											</p>

										</a>

									</li>

									<!-- ADD HOMEWORK -->

									<li class="nav-item">

										<a
											href="<?php echo WEB_ROOT; ?>homework/create.php"

											class="nav-link <?=
												($current_page === 'create.php')

													? 'active'
													: '';
											?>"
										>

											<i class="far fa-circle nav-icon"></i>

											<p>

												Add Homework

											</p>

										</a>

									</li>

									<!-- REPORTS -->

									<li class="nav-item">

										<a
											href="<?php echo WEB_ROOT; ?>homework/reports.php"

											class="nav-link <?=
												($current_page === 'reports.php')

													? 'active'
													: '';
											?>"
										>

											<i class="far fa-circle nav-icon"></i>

											<p>

												Homework Reports

											</p>

										</a>

									</li>

								</ul>

							</li>
				
				<!-- Configuration Section -->
<?php if (in_array($current_role, ['admin'])): ?>

    <li class="nav-header">CONFIGURATION</li>

    <!-- System Settings -->
    <li class="nav-item">

        <a href="<?php echo WEB_ROOT; ?>settings/index.php"
           class="nav-link <?php echo (strpos($current_page, 'settings') !== false) ? 'active' : ''; ?>">

            <i class="nav-icon fas fa-cogs"></i>

            <p>System Settings</p>

        </a>

    </li>

    <!-- User Management -->
    <li class="nav-item">

        <a href="<?php echo WEB_ROOT; ?>users/index.php"
           class="nav-link <?php echo (strpos($current_page, 'users') !== false) ? 'active' : ''; ?>">

            <i class="nav-icon fas fa-users-cog"></i>

            <p>User Management</p>

        </a>

    </li>

    <!-- School Backup -->
    <li class="nav-item">

        <a href="<?php echo WEB_ROOT; ?>backup/export_school_backup.php"
           class="nav-link">

            <i class="nav-icon fas fa-download"></i>

            <p>Download Backup</p>

        </a>

    </li>

<?php endif; ?>
            </ul>
        </nav>
    </div>
</aside>