<?php

if (!isset($_SESSION)) {
    session_start();
}

$data = $_POST;



require_once('../lib/dbclass.php');

$regno = $data['customer_id'];


$data = findQuery("SELECT * FROM tbl_candidates WHERE Regno='$regno'");

$image                  = '../uploads/' . $data[0]['photo'];
$regno                  = $data[0]['Regno'] ?? '';
$name                   = $data[0]['name']  ?? '';
$payment_time_formatted = date('d-m-Y H:i:s', $payment->created_at);



$amount = '0'; // Default amount
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="../logo.png" type="image/x-icon" sizes="16x16">
    <title>Kerala NEET Model Exam</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            font-family: 'Poppins', sans-serif;
            background-color: #ffffff;
        }
        .main_container {
            text-align: center;
            max-width: 600px;
            padding: 20px;
        }
        .download-btn {
            display: inline-block;
            margin: 10px;
            padding: 12px;
            background-color: #242080;
            color: white;
            text-decoration: none;
            font-size: 14px;
            border-radius: 10px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .download-btn:hover {
            background-color: #16165b;
        }
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
</head>
<body>
    <div class="main_container">
        <img src="image.png" alt="Funny Animation" style="width: 100%; height: auto; max-width: 100px;">
        <h2>Registration Successful</h2>
        <p>Thank you for joining us! You're all set.</p>
        <p>Please download your receipt and keep it safe for future reference.</p>
        <p>Join our WhatsApp group, stay updated with the latest news and announcements.</p>
        <div>
            <button class="download-btn" onclick="generatePDF()">Download Receipt</button>
            <button class="download-btn" onclick="window.location.href='generate_poster.php?name=<?php echo urlencode($name); ?>&regno=<?php echo urlencode($regno); ?>&image=<?php echo urlencode($image); ?>'">Download Poster</button>
            <button class="download-btn" onclick="window.open('https://chat.whatsapp.com/Hye5DZp3087Evn6IntUbxV', '_blank')">Join WhatsApp Group</button>
        </div>
    </div>



    <script>
        function generatePDF() {
        
        const { jsPDF } = window.jspdf;
const doc = new jsPDF();

// Use the Arial font
doc.setFont('Arial');

// Set up the page size and margins
const margin = 15;
const pageWidth = doc.internal.pageSize.width;
const pageHeight = doc.internal.pageSize.height;
const contentWidth = pageWidth - 2 * margin;

// Title
doc.setFontSize(26);
doc.setTextColor(0, 102, 51);  // Dark Green for Title
doc.text('Confirmation Receipt', pageWidth / 2, margin + 15, null, null, 'center');

// Success Icon (green circle with custom image)
const successIconSize = 60;
const iconX = (pageWidth - successIconSize) / 2;
const iconY = margin + 30;
doc.setFillColor(76, 175, 80); // Green color
doc.circle(iconX + successIconSize / 2, iconY + successIconSize / 2, successIconSize / 2, 'F'); // Circle

// Add custom image (replace this with your image source)
const imgPath = 'checked.png';  // Local path or base64 image
const imageWidth = 40;  // Image width inside the circle
const imageHeight = 40;  // Image height inside the circle
const imageX = iconX + (successIconSize - imageWidth) / 2;  // Center the image horizontally
const imageY = iconY + (successIconSize - imageHeight) / 2;  // Center the image vertically

// Add the image (you can use a base64 image as well)
doc.addImage(imgPath, 'PNG', imageX, imageY, imageWidth, imageHeight);

// Payment Success Text
doc.setFontSize(22);
doc.setTextColor(0, 0, 0); // Black text for success message
doc.text('Registration Success!', pageWidth / 2, iconY + successIconSize + 10, null, null, 'center');

// Amount Paid
// Use ₹ symbol via image
doc.setFontSize(18);
doc.setTextColor(0, 0, 0); // Dark Green for the amount

// Add the ₹ symbol as an image
const rupeeSymbolPath = 'rupee-indian.png';  // Replace with your image file (path or base64)
const rupeeSymbolWidth = 4; // Width of the ₹ symbol image (slightly larger for better visibility)
const rupeeSymbolHeight = 4; // Height of the ₹ symbol image (same size as width for a square image)
const amountX = pageWidth / 2 - 12; // Position the amount slightly left to the ₹ symbol image
const amountY = iconY + successIconSize + 20; // Reduced vertical gap for the amount

// Add the rupee symbol image
//doc.addImage(rupeeSymbolPath, 'PNG', amountX, amountY, rupeeSymbolWidth, rupeeSymbolHeight);

// Add the amount text
//const amount = "<?php echo $amount; ?>"; // Dynamically insert the amount with ₹ symbol
//doc.text(amount + ' /-', amountX+12, amountY+4, null, null, 'center');

// Line separator
doc.setDrawColor(0, 0, 0); // Black line
doc.line(margin, iconY + successIconSize + 40, pageWidth - margin, iconY + successIconSize + 40);

// Payment Details Header
doc.setFontSize(18);
doc.setTextColor(0, 102, 51); // Dark Green for the details header
doc.text('Registration Details', pageWidth / 2, iconY + successIconSize + 50, null, null, 'center');

// Table for Payment Details
const details = [
 
  { label: 'Registration Number', value: '<?php echo $regno; ?>' }
];

const rowHeight = 12;
let yPosition = iconY + successIconSize + 60;
const labelWidth = contentWidth / 2;
const valueWidth = contentWidth / 2;

// Table header styling
doc.setFillColor(245, 245, 245); // Light gray for header background
doc.setTextColor(0, 0, 0);
doc.setFontSize(14);
doc.rect(margin, yPosition, contentWidth, rowHeight, 'F');
doc.text('Details', margin + 5, yPosition + 8); // Column label
doc.text('Information', margin + labelWidth + 5, yPosition + 8); // Column label

// Table rows
yPosition += rowHeight;
details.forEach(detail => {
  doc.setFontSize(12);
  doc.setTextColor(0, 0, 0);
  doc.text(detail.label, margin + 5, yPosition + 5);
  doc.text(detail.value, margin + labelWidth + 5, yPosition + 5);
  yPosition += rowHeight;
});

// Line separator below the table
doc.setDrawColor(0, 0, 0); // Black line
doc.line(margin, yPosition, pageWidth - margin, yPosition);

// Footer text
doc.setFontSize(10);
doc.setTextColor(150, 150, 150); // Light gray for footer
const footerText = "This is system-generated and does not require a signature.";
doc.text(footerText, pageWidth / 2, pageHeight - margin - 45, null, null, 'center');

// Save as PDF
doc.save('confirmation_receipt.pdf');

        
    }
    </script>
</body>
</html>
