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



$locations = [
    1  => 'SEED Campus, High Street Building, Old Bus stand, MG road Kasaragod',
    2  => 'Entrance Point, Noble Arcade Tower, Sub Registrar office Road, Caltex Junction Kannur.',
    3  => 'NeuroNet Edu Solution PV Complex, Old Bus Stand, Thalassery, Kannur District',
    4  => 'NeuroNet Edu Solution KTC Junction, Mahe',
    5  => 'NeuroNet Edu Solution Near Palloor Police Station, Palloor, Mahe',
    6  => 'DOPA hybrid campus New busstand Calicut.',
    7  => 'AIMs study Centre Balussery, Kozhikode Dist.',
    8  => 'Vadakara Steps Institute, Kozhikode Dist.',
    9  => 'Leads academy, Near Town church, Co-operative college building, Pulpally, Wayanad Dist.',
    10 => 'Amnus Tuition centre, Munderi Kalpetta. Wayanad Dist.',
    11 => 'DOPA offline campus Chankuvetti, Kurukathani - Kottakkal Road, Changuvetty, Kottakkal, Malappuram Dist.',
    12 => 'Mentor Tuition Centre, THOTTINTTAKKARA, Mampad, Malappuram Dist.',
    13 => 'THE AiMS ACADEMY, Nethaji Bypass Road, Edappal, Malappuram Dist.',
    14 => 'Entrance World, Konnakkal Arcade, Theyyala Road, Tanur, Malappuram Dist.',
    15 => 'DOPA offline campus K.W Road, Sakthan Thampuran Nagar, Veliyannur, Thrissur.',
    16 => 'Panangad Higher Secondary School, Sreenarayanapuram Kodungallur, Thrissur Dist.',
    17 => 'Synapse Institute of Science and Advanced Studies: Mele-Pattambi, Opp. Govt. Higher Secondary School, Perinthalmanna Rd, Pattambi, Palakkad Dist.',
    18 => 'Study point Palakkad KSRTC Busstand, MES Womens college, near BISMI HYPER MARKET, Mankavu, Palakkad',
    19 => 'Centum Coaching Centre, Cherpulassery. Palakkad Dist.',
    20 => 'Thiruvalla : SC seminary HsS school KSRTC busstand, Kottayam Dist',
    21 => 'Sharon and Nissi study centre, ChakolathuKavu Alappuzha Dist.',
    22 => 'Deepthi College, Thodupuzha, Idukki Dist.',
    23 => 'Providence college KSRTC busstand, Pathanamthitta Dist.',
    24 => 'Thiruvalla SC seminary HSS school, KSRTC busstand, Pathanamthitta Dist.',
    25 => 'ACE study centre Anchal, Kollam Dist.',
    26 => 'Inspire Near Railway Gate, SN College Junction, Kollam Dist.',
    27 => 'LIT School Tutions Academy, SS Kovil Road, Overbridge, Thampanoor, Trivandrum Dist.',
    28 => 'SNV Sanskrit Higher Secondary School, North Paravur, Kerala 683513, Ernakulam Dist.',
];



$registerno = $_POST['registerno'];
$mobileno   = $_POST['mobileno'];



$selected_location = $_POST['centre'];

// Check if the location is valid and print the corresponding name
if (isset($locations[$selected_location])) {
    $loc = $locations[$selected_location];
} else {
    echo 'Please select a valid location.';
}

$checking = findQuery("SELECT * FROM `tbl_candidates` where Regno='$registerno'");

if (!$checking) {
    $checking = findQuery("SELECT * FROM `tbl_candidates` where mobile='$mobileno'");
}





if (!$checking) {
    echo "<script src='../sweetalert.js'></script>";
    echo "<script>
        document.addEventListener('DOMContentLoaded', function() {
            swal({
                icon: 'error',
                title: 'No Records Found!',
                text: 'No Records Found,Please try again.',
                showConfirmButton: true,   // Hides the OK button
                timer: 3000                // Set timer in milliseconds (3000ms = 3 seconds)
            }).then(function() {
                window.location = 'login.php';  // Redirect after the timer expires
            });
        });
      </script>";

    exit;
}

$studid = $checking[0]['id'];
updateQuery("update tbl_candidates set examcentre='$loc' where id=$studid");

?>



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hall Ticket</title>
     <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap');

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f8f9fa;
    font-family: 'Poppins', sans-serif;
}

.ticket-container {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    width: 100%;
    border: 2px solid black;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    border: 2px solid black;
}

td {
    padding: 10px;
    border: 1px solid black;
}

.logo-container td {
    border: none !important;
    padding: 10px 80px 10px 80px;
}

.center-text {
    text-align: center;
    font-weight: bold;
}



.small-cell {
    padding: 4px;  
    height: 10px;  
    line-height: 1; 
    vertical-align: top;  
    border-bottom: none;  
    text-align: center;
}

.qrcode {
    width: 160px;
    height: 160px;
    margin: 20px auto; 
    display: flex;
    align-items: flex-end;
    justify-content: right;
    border: 1px solid black; 
    padding: 10px;
    margin-right: 100px;
}
.outer {
    display: flex;
    justify-content: space-between;
    align-items: center; 
    width: 100%;
}

.download-btn {
        display: block;
        margin: 20px auto;
        padding: 12px 24px;
        font-size: 16px;
        font-weight: bold;
        color: white;
        background-color: #030141;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        transition: 0.3s ease;
        text-align: center;
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.2);
    }

    .download-btn:hover {
        background-color: #083a6e;
    }

     </style>
</head>
<body>
    <div class="table-container">
        <form action="" method="post">
            <table>
  
                <tr class="logo-container">
                    <td style="text-align: left;">
                        <img src="NEET GALA Logo.png" alt="NEET GALA Logo" height="150px" width="auto" style="margin-top: 10px;">
                    </td>
                    <td style="text-align: center;">
                        <h2>DOPA NEET GALA INDIA <br> EXAMINATION 2025</h2>
                    </td>
                    <td style="text-align: right;">
                        <img src="DOPA by Bhatia.png" alt="DOPA by Bhatia Logo" width="200px">
                    </td>
                </tr>


                <tr>
                    <td colspan="3" style="text-align: center; padding: 10px;">
                        <p>This Admission ticket is issued for the application submitted to the <b>NEET GALA INDIA</b> <br> by <b>DOPA NEET COACHING</b>.</p>
                    </td>
                </tr>

             
                <tr>
                    <td colspan="2" style="text-align: center;"><b>PERSONAL DETAILS</b></td>
                    <td rowspan="7" class="photo-box"></td>
                </tr>
                <tr>
                    <td><b>Name of Candidate</b></td>
                    <td><?php echo $checking[0]['name'] ?></td>
                </tr>
                <tr>
                    <td><b>Mobile Number</b></td>
                    <td><?php echo $checking[0]['mobile'] ?></td>
                </tr>
                <tr>
                    <td><b>School</b></td>
                    <td><?php echo $checking[0]['school'] ?></td>
                </tr>
                <tr>
                    <td><b>District</b></td>
                    <td><?php echo $checking[0]['district'] ?></td>
                </tr>
                <tr>
                    <td><b>Place</b></td>
                    <td>Kerala</td>
                </tr>
                <tr>
                    <td><b>Country</b></td>
                    <td>INDIA</td>
                </tr>


                <tr>
                    <td colspan="3" style="text-align: center;">
                        <b>DETAILS OF EXAMINATION</b>
                    </td>
                </tr>
                <tr>
                    <td><b>Registration Number</b></td>
                    <td><?php echo $checking[0]['Regno'] ?></td>
                    <td style="text-align: center;">Signature of Candidate <br> <small>(Must be signed during examination)</small></td>
                </tr>

                <tr>
                    <td><b>Type of Examination</b></td>
                    <td><b>OBJECTIVE</b></td>
                    <td rowspan="2"></td>
                </tr>

                <tr>
                    <td><b>Examination Date</b></td>
                    <td><b>05 APRIL 2025, SATURDAY</b></td>
                </tr>

                <tr>
                    <td>Examination Time</td>
                    <td><b>2:00 PM - 5:00 PM</b> <br> Reporting Time <b>1:30 PM</b></td>
                    <td class="small-cell">Signature of Invigilator</td>
                </tr>
                
                <tr>
                    <td><br>Examination Center <br> <br></td>
                    <td><?php echo $loc?></td>
                </tr>
            </table>
        </form>
        <div class="outer">
            <div class="intruction">
                
            </div>
            <div class="qrcode" id="qrcode"></div>
        </div>
        <h3><b>Take your time, do your best, and shape your tomorrow..!</b></h3>
    </div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
<script>

    function generateQRCode(text) {

        document.getElementById("qrcode").innerHTML = "";
        
    
        new QRCode(document.getElementById("qrcode"), {
            text: text, 
            width: 160,
            height: 160
        });
    }

    document.addEventListener("DOMContentLoaded", function() {
        let registrationNumber = "<?php echo $checking[0]['Regno']; ?>"; 
        generateQRCode(registrationNumber);
    });
</script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>

<script>
   window.onload = function () {
        const { jsPDF } = window.jspdf;
        const doc = new jsPDF({
            orientation: 'portrait',
            unit: 'mm',
            format: 'a4'
        });

        const element = document.querySelector('.table-container');

        html2canvas(element, {
            scale: 2, 
            useCORS: true
        }).then(canvas => {
            const imgData = canvas.toDataURL('image/png');
            const imgWidth = 190; 
            const pageHeight = 297;
            const imgHeight = (canvas.height * imgWidth) / canvas.width;
            const marginX = 10;
            const marginY = 10;

            doc.addImage(imgData, 'PNG', marginX, marginY, imgWidth, imgHeight);
            doc.save('Hall_Ticket.pdf');
        });
    }

    
    
    
</script>



</html>
