<?php
require('fpdf/fpdf.php');
include 'db_config.php';

// Fetch all registered users
$sql = "SELECT * FROM users";
$result = $conn->query($sql);

class PDF extends FPDF
{
    function Header()
    {
        $this->SetFont('Arial', 'B', 10);
        $this->Cell(0, 10, '2024 Annual Conference Participants', 0, 1, 'C');
        $this->Ln(10);
    }

    function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('Arial', 'I', 8);
        $this->Cell(0, 10, 'Page ' . $this->PageNo(), 0, 0, 'C');
    }
}

$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(6, 10, 'ID', 1);
$pdf->Cell(32, 10, 'Full Name', 1);
$pdf->Cell(52, 10, 'Email', 1);
$pdf->Cell(30, 10, 'Phone', 1);
$pdf->Cell(28, 10, 'Payment Status', 1);
$pdf->Cell(20, 10, 'Hotel', 1);
$pdf->Cell(32, 10, 'Institution', 1);
$pdf->Cell(30, 10, 'Membership Type', 1);
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $pdf->Cell(6, 10, $row['id'], 1);
        $pdf->Cell(32, 10, $row['fullname'], 1);
        $pdf->Cell(52, 10, $row['email'], 1);
        $pdf->Cell(30, 10, $row['phone'], 1);
        $pdf->Cell(28, 10, $row['payment_status'], 1);
        $pdf->Cell(20, 10, $row['hotel'], 1);
        $pdf->Cell(32, 10, $row['institution'], 1);
        $pdf->Cell(30, 10, $row['membership_type'], 1);
        $pdf->Ln();
    }
} else {
    $pdf->Cell(0, 10, 'No registered users found.', 1, 1, 'C');
}

$pdf->Output('D', '2024 Annual Conference Participants.pdf');

$conn->close();
?>
