<?php
session_start();

// Include access control functions
require_once '../includes/access_control.php';
require_once '../config/database.php';

// Check if user is logged in and is a teacher
require_teacher();

$user_role = $_SESSION['user_role'];
$user_id = $_SESSION['user_id'];
$user_name = $_SESSION['user_name'] ?? $_SESSION['username'] ?? 'শিক্ষক';

// Initialize messages
$success_message = '';
$error_message = '';

// Handle delete requests
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['delete_students'])) {
    $student_ids = $_POST['student_ids'] ?? [];
    
    if (!empty($student_ids) && is_array($student_ids)) {
        try {
            // Validate that teacher can delete these students (only from their assigned classes)
            $teacher_id = null;
            $stmt = $pdo->prepare("SELECT id FROM teachers WHERE user_id = ?");
            $stmt->execute([$user_id]);
            $teacher = $stmt->fetch();
            if ($teacher) {
                $teacher_id = $teacher['id'];
            }
            
            if ($teacher_id) {
                // Validate that teacher has access to all selected students
                $all_students_valid = true;
                foreach ($student_ids as $student_id) {
                    if (!teacher_has_student_access($teacher_id, $student_id)) {
                        $all_students_valid = false;
                        break;
                    }
                }

                if ($all_students_valid) {
                    // All students are valid, proceed with deletion
                    $pdo->beginTransaction();
                        
                        // Soft delete students (set status to 'inactive')
                        $placeholders = str_repeat('?,', count($student_ids) - 1) . '?';
                        $stmt = $pdo->prepare("UPDATE students SET status = 'inactive', updated_at = NOW() WHERE id IN ($placeholders)");
                        $stmt->execute($student_ids);
                        
                        $deleted_count = $stmt->rowCount();
                        $pdo->commit();
                        
                        $success_message = "$deleted_count জন ছাত্র-ছাত্রী সফলভাবে মুছে ফেলা হয়েছে";
                    } else {
                        $error_message = 'আপনি কেবল আপনার নির্ধারিত ক্লাসের ছাত্র-ছাত্রীদের মুছে ফেলতে পারবেন';
                    }
                } else {
                    $error_message = 'আপনার কোন ক্লাসে নির্ধারিত ছাত্র-ছাত্রী নেই';
                }
            } else {
                $error_message = 'অবৈধ শিক্ষক অ্যাকাউন্ট';
            }
        } catch (Exception $e) {
            if ($pdo->inTransaction()) {
                $pdo->rollBack();
            }
            $error_message = 'ছাত্র-ছাত্রীদের মুছে ফেলতে সমস্যা হয়েছে: ' . $e->getMessage();
        }
    } else {
        $error_message = 'অনুগ্রহ করে মুছে ফেলার জন্য অন্তত একজন ছাত্র-ছাত্রী নির্বাচন করুন';
    }
}

// Only teachers can access this page
if ($user_role !== 'teacher') {
    header('Location: ../index.php');
    exit();
}

// Get teacher ID
$teacher_id = null;
$stmt = $pdo->prepare("SELECT id FROM teachers WHERE user_id = ?");
$stmt->execute([$user_id]);
$teacher = $stmt->fetch();
if ($teacher) {
    $teacher_id = $teacher['id'];
} else {
    // Redirect if not a valid teacher
    header('Location: dashboard.php');
    exit();
}

// Get teacher's assigned classes
$assigned_classes = [];
$assigned_class_ids = [];
if ($teacher_id) {
    $assigned_class_ids = get_teacher_assigned_classes($teacher_id);

    // If no classes are assigned, auto-assign the teacher to all available classes (temporary fix)
    if (empty($assigned_class_ids)) {
        try {
            // Auto-assign teacher to all active classes as primary teacher
            $stmt = $pdo->query("SELECT id FROM classes WHERE status = 'active'");
            $all_classes = $stmt->fetchAll(PDO::FETCH_COLUMN);

            if (!empty($all_classes)) {
                foreach ($all_classes as $class_id) {
                    try {
                        $stmt = $pdo->prepare("
                            INSERT IGNORE INTO class_teachers (class_id, teacher_id, assignment_type, status, assigned_at)
                            VALUES (?, ?, 'primary', 'active', NOW())
                        ");
                        $stmt->execute([$class_id, $teacher_id]);
                    } catch (Exception $e) {
                        // Ignore duplicate key errors
                    }
                }
                $assigned_class_ids = $all_classes;
                $success_message = "আপনাকে সব ক্লাসে অটো-অ্যাসাইন করা হয়েছে। এখন আপনি সব ছাত্র-ছাত্রী দেখতে পারবেন।";

                // Re-fetch assigned classes with details after auto-assignment
                $placeholders = str_repeat('?,', count($assigned_class_ids) - 1) . '?';
                $stmt = $pdo->prepare("
                    SELECT DISTINCT c.id, c.name, c.section, 'assigned' as assignment_type
                    FROM classes c
                    WHERE c.id IN ($placeholders) AND c.status = 'active'
                    ORDER BY c.name, c.section
                ");
                $stmt->execute($assigned_class_ids);
                $assigned_classes = $stmt->fetchAll();
            }
        } catch (Exception $e) {
            // Ignore errors during auto-assignment
        }
    } else {
        // Get detailed class information for already assigned classes
        $placeholders = str_repeat('?,', count($assigned_class_ids) - 1) . '?';
        $stmt = $pdo->prepare("
            SELECT DISTINCT c.id, c.name, c.section, 'assigned' as assignment_type
            FROM classes c
            WHERE c.id IN ($placeholders) AND c.status = 'active'
            ORDER BY c.name, c.section
        ");
        $stmt->execute($assigned_class_ids);
        $assigned_classes = $stmt->fetchAll();
    }
}

// Get class IDs for filtering
$class_ids = array_column($assigned_classes, 'id');

// Pagination
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10;
$offset = ($page - 1) * $limit;

// Search and filter
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
$class_filter = isset($_GET['class_id']) ? (int)$_GET['class_id'] : 0;

// Only allow filtering by assigned classes
if ($class_filter > 0 && !in_array($class_filter, $class_ids)) {
    $class_filter = 0;
}

// Sorting
$sort_by = isset($_GET['sort_by']) ? $_GET['sort_by'] : 'roll_number';
$sort_order = isset($_GET['sort_order']) ? $_GET['sort_order'] : 'ASC';

// Validate sort parameters
$allowed_sort_fields = ['first_name', 'last_name', 'student_id', 'roll_number', 'created_at', 'class_name', 'session'];
$allowed_sort_orders = ['ASC', 'DESC'];

if (!in_array($sort_by, $allowed_sort_fields)) {
    $sort_by = 'roll_number';
}
if (!in_array($sort_order, $allowed_sort_orders)) {
    $sort_order = 'ASC';
}

// Build query for teacher's students only
$where_conditions = ["s.status = 'active'"];
$params = [];

// Filter by teacher's assigned classes
if (!empty($class_ids)) {
    $placeholders = str_repeat('?,', count($class_ids) - 1) . '?';
    $where_conditions[] = "s.class_id IN ($placeholders)";
    $params = array_merge($params, $class_ids);
} else {
    // If no classes assigned, show no students
    $where_conditions[] = "1=0"; // Always false condition
}

// Search condition
if (!empty($search)) {
    $where_conditions[] = "(s.first_name LIKE ? OR s.last_name LIKE ? OR s.student_id LIKE ? OR s.roll_number LIKE ? OR ses.session_name LIKE ?)";
    $params[] = "%$search%";
    $params[] = "%$search%";
    $params[] = "%$search%";
    $params[] = "%$search%";
    $params[] = "%$search%";
}

// Class filter
if ($class_filter > 0) {
    $where_conditions[] = "s.class_id = ?";
    $params[] = $class_filter;
}

$where_clause = implode(' AND ', $where_conditions);

// Get total count
$count_sql = "SELECT COUNT(*) FROM students s LEFT JOIN classes c ON s.class_id = c.id WHERE $where_clause";
$count_stmt = $pdo->prepare($count_sql);
$count_stmt->execute($params);
$total_records = $count_stmt->fetchColumn();
$total_pages = ceil($total_records / $limit);

$order_clause = "";
if ($sort_by && $sort_order) {
    // Map sort fields to correct column references
    $sort_field_map = [
        'class_name' => 'c.name',
        'session' => 'ses.session_name'
    ];

    $actual_sort_field = isset($sort_field_map[$sort_by]) ? $sort_field_map[$sort_by] : $sort_by;
    $order_clause = "ORDER BY $actual_sort_field $sort_order";
}

// Get students
$sql = "SELECT s.*, c.name as class_name, c.section as class_section, ses.session_name as session FROM students s LEFT JOIN classes c ON s.class_id = c.id LEFT JOIN academic_sessions ses ON s.session_id = ses.id WHERE $where_clause $order_clause LIMIT ? OFFSET ?";
$stmt = $pdo->prepare($sql);
$execute_params = array_merge($params, [$limit, $offset]);
$stmt->execute($execute_params);
$students = $stmt->fetchAll();

// Get classes for dropdown (only assigned classes)
if (!empty($class_ids)) {
    $placeholders = str_repeat('?,', count($class_ids) - 1) . '?';
    $classes_stmt = $pdo->prepare("SELECT id, name, section FROM classes WHERE id IN ($placeholders) AND status = 'active' ORDER BY name, section");
    $classes_stmt->execute($class_ids);
} else {
    // If no class IDs, just get an empty result
    $classes_stmt = $pdo->prepare("SELECT id, name, section FROM classes WHERE id IN (0) AND status = 'active' ORDER BY name, section");
    $classes_stmt->execute();
}
$classes = $classes_stmt->fetchAll();
?>

<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>আমার ছাত্র-ছাত্রী - স্কুল ম্যানেজমেন্ট সিস্টেম</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="../assets/css/jessoreboard-theme.css" rel="stylesheet">
    <style>
        .student-photo {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            object-fit: cover;
        }
        .no-photo {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #6c757d;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
        }
        .table-responsive {
            max-height: 600px;
            overflow-y: auto;
        }
        .sort-link {
            color: #006747;
            text-decoration: none;
        }
        .sort-link:hover {
            text-decoration: underline;
        }
        .sort-link.active {
            font-weight: bold;
        }
        .bulk-actions {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container-fluid">
            <a class="navbar-brand" href="<?php echo ($user_role == 'teacher') ? 'dashboard.php' : '../index.php'; ?>">
                <i class="fas fa-graduation-cap"></i> স্কুল ম্যানেজমেন্ট সিস্টেম
            </a>
            <div class="navbar-nav ms-auto">
                <a class="nav-link" href="bulk_upload_students.php">
                    <i class="fas fa-upload"></i> বাল্ক আপলোড
                </a>
                <a class="nav-link" href="<?php echo ($user_role == 'teacher') ? 'dashboard.php' : '../index.php'; ?>">
                    <i class="fas fa-arrow-left"></i> ড্যাশবোর্ডে ফিরুন
                </a>
            </div>
        </div>
    </nav>
    <div class="container-fluid mt-4">
        <div class="row">
            <div class="col-12">
                <h2><i class="fas fa-user-graduate"></i> আমার ছাত্র-ছাত্রী</h2>
                <p class="text-muted">আপনার নির্ধারিত ক্লাসের ছাত্র-ছাত্রীদের তালিকা</p>
            </div>
        </div>

        <!-- Messages -->
        <?php if ($success_message): ?>
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="fas fa-check-circle"></i> <?php echo $success_message; ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        <?php endif; ?>
        <?php if ($error_message): ?>
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <i class="fas fa-exclamation-triangle"></i> <?php echo $error_message; ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        <?php endif; ?>

        <!-- Search Form -->
        <div class="row mb-3">
            <div class="col-md-6">
                <form method="GET" class="d-flex">
                    <input type="text" class="form-control me-2" name="search" placeholder="নাম, আইডি বা রোল নম্বর দিয়ে অনুসন্ধান..." value="<?php echo htmlspecialchars($search); ?>">
                    <button class="btn btn-outline-success" type="submit">
                        <i class="fas fa-search"></i>
                    </button>
                </form>
            </div>
            <div class="col-md-6 text-end">
                <a href="bulk_upload_students.php" class="btn btn-success">
                    <i class="fas fa-upload"></i> বাল্ক আপলোড
                </a>
                <a href="add_student.php" class="btn btn-primary">
                    <i class="fas fa-plus"></i> নতুন ছাত্র-ছাত্রী
                </a>
                <a href="dashboard.php" class="btn btn-secondary">
                    <i class="fas fa-arrow-left"></i> ড্যাশবোর্ডে ফিরুন
                </a>
            </div>
        </div>

        <!-- Class Filter -->
        <div class="row mb-3">
            <div class="col-md-12">
                <form method="GET" class="d-flex align-items-center">
                    <input type="hidden" name="search" value="<?php echo htmlspecialchars($search); ?>">
                    <select name="class_id" class="form-select me-2" style="max-width: 300px;">
                        <option value="0">সব ক্লাস</option>
                        <?php foreach ($classes as $class): ?>
                            <option value="<?php echo $class['id']; ?>" <?php echo ($class_filter == $class['id']) ? 'selected' : ''; ?>>
                                <?php echo htmlspecialchars($class['name'] . ' - ' . $class['section']); ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                    <button class="btn btn-primary" type="submit">
                        <i class="fas fa-filter"></i> ফিল্টার
                    </button>
                    <?php if ($class_filter > 0 || !empty($search)): ?>
                        <a href="my_students.php" class="btn btn-outline-secondary ms-2">
                            <i class="fas fa-times"></i> ফিল্টার মুছুন
                        </a>
                    <?php endif; ?>
                </form>
            </div>
        </div>

        <!-- Bulk Actions -->
        <div class="row mb-3">
            <div class="col-12">
                <div class="bulk-actions">
                    <form method="POST" id="bulkDeleteForm">
                        <input type="hidden" name="delete_students" value="1">
                        <div class="d-flex align-items-center">
                            <div class="form-check me-3">
                                <input class="form-check-input" type="checkbox" id="selectAll">
                                <label class="form-check-label" for="selectAll">সবগুলো নির্বাচন করুন</label>
                            </div>
                            <button type="submit" class="btn btn-danger" id="deleteButton" disabled>
                                <i class="fas fa-trash-alt"></i> মুছে ফেলুন
                            </button>
                            <span class="ms-3 text-muted" id="selectedCount">0 জন ছাত্র-ছাত্রী নির্বাচন করা হয়েছে</span>
                        </div>
                    
                        <!-- Students Table -->
                        <div class="row mt-3">
                            <div class="col-12">
                                <div class="table-responsive">
                                    <table class="table table-striped table-hover">
                                        <thead class="table-dark">
                                            <tr>
                                                <th>
                                                    <input class="form-check-input" type="checkbox" id="selectAllHeader">
                                                </th>
                                                <th>ছবি</th>
                                                <th>
                                                    <a href="?<?php echo http_build_query(array_merge($_GET, ['sort_by' => 'first_name', 'sort_order' => ($sort_by == 'first_name' && $sort_order == 'ASC') ? 'DESC' : 'ASC'])); ?>" class="sort-link <?php echo $sort_by == 'first_name' ? 'active' : ''; ?>">
                                                        নাম <?php if ($sort_by == 'first_name'): ?><i class="fas fa-sort-<?php echo $sort_order == 'ASC' ? 'up' : 'down'; ?>"></i><?php endif; ?>
                                                    </a>
                                                </th>
                                                <th>আইডি</th>
                                                <th>রোল</th>
                                                <th>
                                                    <a href="?<?php echo http_build_query(array_merge($_GET, ['sort_by' => 'class_name', 'sort_order' => ($sort_by == 'class_name' && $sort_order == 'ASC') ? 'DESC' : 'ASC'])); ?>" class="sort-link <?php echo $sort_by == 'class_name' ? 'active' : ''; ?>">
                                                        ক্লাস <?php if ($sort_by == 'class_name'): ?><i class="fas fa-sort-<?php echo $sort_order == 'ASC' ? 'up' : 'down'; ?>"></i><?php endif; ?>
                                                    </a>
                                                </th>
                                                <th>সেশন</th>
                                                <th>ফোন</th>
                                                <th>কার্যক্রম</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php if (empty($students)): ?>
                                                <tr>
                                                    <td colspan="9" class="text-center">কোন ছাত্র-ছাত্রী পাওয়া যায়নি</td>
                                                </tr>
                                            <?php else: ?>
                                                <?php foreach ($students as $student): ?>
                                                    <tr>
                                                        <td>
                                                            <input class="form-check-input student-checkbox" type="checkbox" name="student_ids[]" value="<?php echo $student['id']; ?>">
                                                        </td>
                                                        <td>
                                                            <?php if (!empty($student['photo']) && file_exists('../' . $student['photo'])): ?>
                                                                <img src="../<?php echo $student['photo']; ?>" alt="Photo" class="student-photo">
                                                            <?php else: ?>
                                                                <div class="no-photo">
                                                                    <i class="fas fa-user"></i>
                                                                </div>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td><?php echo htmlspecialchars($student['first_name'] . ' ' . $student['last_name']); ?></td>
                                                        <td><?php echo htmlspecialchars($student['student_id']); ?></td>
                                                        <td><?php echo htmlspecialchars($student['roll_number']); ?></td>
                                                        <td><?php echo htmlspecialchars($student['class_name'] . ' - ' . $student['class_section']); ?></td>
                                                        <td><?php echo htmlspecialchars($student['session']); ?></td>
                                                        <td><?php echo htmlspecialchars($student['phone']); ?></td>
                                                        <td>
                                                            <div class="btn-group btn-group-sm" role="group">
                                                                <a href="view_student.php?id=<?php echo $student['id']; ?>" class="btn btn-outline-primary" title="দেখুন">
                                                                    <i class="fas fa-eye"></i>
                                                                </a>
                                                                <a href="edit_student.php?id=<?php echo $student['id']; ?>" class="btn btn-outline-warning" title="সম্পাদনা">
                                                                    <i class="fas fa-edit"></i>
                                                                </a>
                                                                <!-- Add Application Form Link -->
                                                                <a href="../admission_application.php?student_id=<?php echo $student['id']; ?>" class="btn btn-outline-success" title="আবেদন ফরম" target="_blank">
                                                                    <i class="fas fa-file-alt"></i>
                                                                </a>
                                                                <!-- Add Print Form Link -->
                                                                <a href="../admission_form_print.php?student_id=<?php echo $student['id']; ?>" class="btn btn-outline-info" title="প্রিন্ট ফরম" target="_blank">
                                                                    <i class="fas fa-print"></i>
                                                                </a>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                <?php endforeach; ?>
                                            <?php endif; ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- Pagination -->
        <?php if ($total_pages > 1): ?>
            <div class="row">
                <div class="col-12">
                    <nav aria-label="Page navigation">
                        <ul class="pagination justify-content-center">
                            <?php if ($page > 1): ?>
                                <li class="page-item">
                                    <a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => 1])); ?>" aria-label="First">
                                        <span aria-hidden="true">&laquo;&laquo;</span>
                                    </a>
                                </li>
                                <li class="page-item">
                                    <a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $page - 1])); ?>" aria-label="Previous">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>
                            <?php endif; ?>

                            <?php
                            $start_page = max(1, $page - 2);
                            $end_page = min($total_pages, $page + 2);

                            if ($start_page > 1): ?>
                                <li class="page-item">
                                    <a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => 1])); ?>">1</a>
                                </li>
                                <?php if ($start_page > 2): ?>
                                    <li class="page-item disabled">
                                        <span class="page-link">...</span>
                                    </li>
                                <?php endif; ?>
                            <?php endif; ?>

                            <?php for ($i = $start_page; $i <= $end_page; $i++): ?>
                                <li class="page-item <?php echo $i == $page ? 'active' : ''; ?>">
                                    <a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $i])); ?>"><?php echo $i; ?></a>
                                </li>
                            <?php endfor; ?>

                            <?php if ($end_page < $total_pages): ?>
                                <?php if ($end_page < $total_pages - 1): ?>
                                    <li class="page-item disabled">
                                        <span class="page-link">...</span>
                                    </li>
                                <?php endif; ?>
                                <li class="page-item">
                                    <a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $total_pages])); ?>"><?php echo $total_pages; ?></a>
                                </li>
                            <?php endif; ?>

                            <?php if ($page < $total_pages): ?>
                                <li class="page-item">
                                    <a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $page + 1])); ?>" aria-label="Next">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                                <li class="page-item">
                                    <a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $total_pages])); ?>" aria-label="Last">
                                        <span aria-hidden="true">&raquo;&raquo;</span>
                                    </a>
                                </li>
                            <?php endif; ?>
                        </ul>
                    </nav>
                </div>
            </div>
        <?php endif; ?>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Select all checkboxes functionality
        document.getElementById('selectAll').addEventListener('change', function() {
            const checkboxes = document.querySelectorAll('.student-checkbox');
            checkboxes.forEach(checkbox => {
                checkbox.checked = this.checked;
            });
            updateSelectedCount();
        });
        
        document.getElementById('selectAllHeader').addEventListener('change', function() {
            const checkboxes = document.querySelectorAll('.student-checkbox');
            checkboxes.forEach(checkbox => {
                checkbox.checked = this.checked;
            });
            updateSelectedCount();
        });
        
        // Update selected count when individual checkboxes are changed
        document.querySelectorAll('.student-checkbox').forEach(checkbox => {
            checkbox.addEventListener('change', updateSelectedCount);
        });
        
        // Update selected count display
        function updateSelectedCount() {
            const selectedCount = document.querySelectorAll('.student-checkbox:checked').length;
            document.getElementById('selectedCount').textContent = selectedCount + ' জন ছাত্র-ছাত্রী নির্বাচন করা হয়েছে';
            document.getElementById('deleteButton').disabled = selectedCount === 0;
        }
        
        // Confirm delete action
        document.getElementById('bulkDeleteForm').addEventListener('submit', function(e) {
            const selectedCount = document.querySelectorAll('.student-checkbox:checked').length;
            if (selectedCount === 0) {
                e.preventDefault();
                alert('অনুগ্রহ করে মুছে ফেলার জন্য অন্তত একজন ছাত্র-ছাত্রী নির্বাচন করুন');
                return false;
            }
            
            if (!confirm(selectedCount + ' জন ছাত্র-ছাত্রীকে মুছে ফেলতে চান? এই কাজটি পূর্বাবস্থায় ফেরানো যাবে না।')) {
                e.preventDefault();
                return false;
            }
        });
    </script>
</body>
</html>