Your IP : 216.73.217.77


Current Path : /home/users/unlimited/www/nigeria.codeskitter.site/admin/
Upload File :
Current File : /home/users/unlimited/www/nigeria.codeskitter.site/admin/students.php

<?php
include '../includes/config.php';

if(!isset($_SESSION['user_id']) || $_SESSION['user_role'] != 'admin') {
    header("Location: login.php");
    exit();
}

// Get student progress
$student_progress_sql = "SELECT u.id, u.name, u.email, 
                        COUNT(e.id) as total_enrollments,
                        AVG(e.progress) as avg_progress,
                        MAX(e.enrolled_at) as last_enrollment
                        FROM users u 
                        LEFT JOIN enrollments e ON u.id = e.user_id 
                        WHERE u.role = 'student' 
                        GROUP BY u.id 
                        ORDER BY last_enrollment DESC";
$student_progress = $conn->query($student_progress_sql);

// Get detailed progress for a specific student
if(isset($_GET['student_id'])) {
    $student_id = $_GET['student_id'];
    $student_details_sql = "SELECT u.name, u.email, u.created_at as joined_date,
                           c.title as course_title, e.progress, e.enrolled_at
                           FROM enrollments e
                           JOIN users u ON e.user_id = u.id
                           JOIN courses c ON e.course_id = c.id
                           WHERE u.id = ?
                           ORDER BY e.enrolled_at DESC";
    $stmt = $conn->prepare($student_details_sql);
    $stmt->bind_param("i", $student_id);
    $stmt->execute();
    $student_details = $stmt->get_result();
    
    // Get student info
    $student_info_sql = "SELECT * FROM users WHERE id = ?";
    $stmt_info = $conn->prepare($student_info_sql);
    $stmt_info->bind_param("i", $student_id);
    $stmt_info->execute();
    $student_info = $stmt_info->get_result()->fetch_assoc();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Student Progress - Admin</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <?php include 'sidebar.php'; ?>
            
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
                <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                    <h1 class="h2">Student Progress</h1>
                </div>

                <?php if(isset($_GET['student_id'])): ?>
                <!-- Student Details View -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0">Student Details: <?php echo $student_info['name']; ?></h5>
                    </div>
                    <div class="card-body">
                        <div class="row mb-4">
                            <div class="col-md-6">
                                <p><strong>Email:</strong> <?php echo $student_info['email']; ?></p>
                                <p><strong>Joined:</strong> <?php echo date('M j, Y', strtotime($student_info['created_at'])); ?></p>
                            </div>
                        </div>
                        
                        <h6>Course Progress</h6>
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>Course</th>
                                        <th>Enrollment Date</th>
                                        <th>Progress</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php while($detail = $student_details->fetch_assoc()): ?>
                                    <tr>
                                        <td><?php echo $detail['course_title']; ?></td>
                                        <td><?php echo date('M j, Y', strtotime($detail['enrolled_at'])); ?></td>
                                        <td>
                                            <div class="progress" style="height: 20px;">
                                                <div class="progress-bar" role="progressbar" 
                                                     style="width: <?php echo $detail['progress']; ?>%;"
                                                     aria-valuenow="<?php echo $detail['progress']; ?>" 
                                                     aria-valuemin="0" aria-valuemax="100">
                                                    <?php echo $detail['progress']; ?>%
                                                </div>
                                            </div>
                                        </td>
                                        <td>
                                            <?php if($detail['progress'] == 100): ?>
                                            <span class="badge bg-success">Completed</span>
                                            <?php elseif($detail['progress'] > 0): ?>
                                            <span class="badge bg-warning">In Progress</span>
                                            <?php else: ?>
                                            <span class="badge bg-secondary">Not Started</span>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                    <?php endwhile; ?>
                                </tbody>
                            </table>
                        </div>
                        
                        <a href="students.php" class="btn btn-secondary mt-3">
                            <i class="bi bi-arrow-left"></i> Back to All Students
                        </a>
                    </div>
                </div>
                
                <?php else: ?>
                <!-- All Students View -->
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Student Name</th>
                                        <th>Email</th>
                                        <th>Enrollments</th>
                                        <th>Avg Progress</th>
                                        <th>Last Activity</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php while($student = $student_progress->fetch_assoc()): ?>
                                    <tr>
                                        <td><?php echo $student['id']; ?></td>
                                        <td><?php echo $student['name']; ?></td>
                                        <td><?php echo $student['email']; ?></td>
                                        <td><?php echo $student['total_enrollments']; ?></td>
                                        <td>
                                            <?php 
                                            $avg_progress = $student['avg_progress'] ? round($student['avg_progress']) : 0;
                                            echo $avg_progress; ?>%
                                        </td>
                                        <td>
                                            <?php if($student['last_enrollment']): ?>
                                            <?php echo date('M j, Y', strtotime($student['last_enrollment'])); ?>
                                            <?php else: ?>
                                            <span class="text-muted">No enrollments</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <a href="students.php?student_id=<?php echo $student['id']; ?>" class="btn btn-sm btn-outline-primary">
                                                <i class="bi bi-eye"></i> View Progress
                                            </a>
                                        </td>
                                    </tr>
                                    <?php endwhile; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <?php endif; ?>
            </main>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>