<?php
    include('session.php');
    include('dbconn.php');
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <?php include 'plugincss.php' ?>

    <link rel="shortcut icon" href="assets/images/favicon.png" type="image/x-icon">

    <title><?php echo $sitetitle ;?></title>

    <style>
       table {
           width: 100%;
           border-collapse: collapse;
           margin-bottom: 20px;
       }
       th, td {
           border: 1px solid #ddd;
           padding: 8px;
           text-align: left;
       }
       th {
           background-color: #8f0000;
           font-weight: bold;
           text-align: center;
       }
       td {
           text-align: left; /* Left alignment for table cells */
       }
       td.cost {
           text-align: right; /* Right alignment for cost cells */
       }
       tr:nth-child(even) {
           background-color: #8f0000;
       }
    </style>

</head>

<body>
    <!-- ==========Preloader========== -->
    <div class="preloader">
        <div class="preloader-inner">
            <div class="preloader-icon">
                <span></span>
                <span></span>
            </div>
        </div>
    </div>
    <!-- ==========Preloader========== -->
    <!-- ==========Overlay========== -->
    <div class="overlay"></div>
    <a href="#0" class="scrollToTop">
        <i class="fas fa-angle-up"></i>
    </a>
    <!-- ==========Overlay========== -->

<!-- ==========Header-Section========== -->
<header class="header-section">
    <div class="container">
        <div class="header-wrapper">
            <div class="logo">
                <a href="index.php">
                    <img src="./assets/images/logo/nkn-logo-horizontal.png" alt="logo">
                </a>
            </div>
        </div>
    </div>
</header>
<!-- ==========Header-Section========== -->
        <br><br><br><br>
        <!-- ==========Blog-Section========== -->
        <section class="blog-section padding-top">
            <div class="container">
                <div class="row justify-content-center mb-30-none">
                    <div class="col-lg-12 mb-10 mb-lg-0">
                        <article>
                            <div class="post-item post-details">
                                <div class="post-thumb">
                                    <img src="/assets/images/poster.jpeg" alt="blog">
                                </div>
                                <div class="post-content">
                                    <div class="content">
                                        <div class="entry-content p-0">
                                            <div class="left">
                                                <span class="date">Registreation Closing Date : 01-04-2026 11:59 PM </span>
                                            </div>
                                        </div>
                                        <div class="post-header">
                                            <h4 class="m-title">
                                                NATIONAL LEVEL STEM & ICT QUIZ COMPETITION 2026
                                            </h4>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </article>
                    </div>
                </div>
            </div>
        </section>
        <!-- ==========Blog-Section========== -->


    <!-- ==========Event-Section========== -->
    <div class="event-facility">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <div class="checkout-widget checkout-contact">
                        <h5 class="title">Registration Information Verification Form<br>The information provided is required to generate the e-certificate.</h5>
                        <h6 style="color: yellow;">
                            <ol style="color: yellow;">
                                <li>Please enter Registered Email Address</li>
                                <li>Click the "Submit" button.</li>
                                <li>The registration details will be displayed.</li>
                                <li>If there are any errors in the displayed information, please update the details and click the "Verify" button.</li>
                                <li>If there are no errors, click the "Verify" button.</li>
                                <li>If no registration information is found, please contact Mr. Kalaiarasan at +016-4876512.</li>
                            </ol>
                        </h6>
                        <br>
                        <form class="checkout-contact-form" method="post">
                            <div class="form-group">
                                <input type="text" placeholder="Email Address" id ="email" name ="email" required>
                            </div>
                            <div class="form-group">
                                <center>
                                    <button type="button" id="btnSubmit" class="custom-button">
                                        Submit
                                    </button>
                                </center>
                            </div>
                        </form>
                        <br><br>
                        <form class="checkout-contact-form" id="verificationForm" method="" style="display: none;">
                            
                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- ==========Event-Section========== -->

    <!-- ==========Newslater-Section========== -->
    <footer class="footer-section">
        <div class="container">
            <div class="footer-top">
                <div class="logo">
                    
                </div>
                <ul class="social-icons">
                    
                </ul>
            </div>
            <div class="footer-bottom">
                <div class="footer-bottom-area">
                    <div class="left">
                        <p><?php echo $copyrights ;?></p>
                    </div>
                </div>
            </div>
        </div>
    </footer>
    <!-- ==========Newslater-Section========== -->
        <?php include 'pluginjs.php' ?>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <script>
    document.getElementById("btnSubmit").addEventListener("click", function(e) {
        e.preventDefault();
    
        let email = document.getElementById("email").value.trim();
        //let email = document.getElementById("email").value.replace(/\s+/g, '');
    
        fetch("get-registration.php", {
            method: "POST",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            body: "email=" + encodeURIComponent(email)
        })
        .then(response => response.text())
        .then(data => {
            document.getElementById("verificationForm").style.display = "block";
            document.getElementById("verificationForm").innerHTML = data;
        })
        .catch(error => console.error("Error:", error));
    });
    </script>
    
    <script>
        function verifyRow(id){
        
            let name = document.getElementById("name_" + id).value;
            let age = document.getElementById("age_" + id).value;
            let nricmykid = document.getElementById("nricmykid_" + id).value;
            let contact = document.getElementById("contact_" + id).value;
            let emailadd = document.getElementById("email_" + id).value;
            let school = document.getElementById("school_" + id).value;
            let category = document.getElementById("category_" + id).value;
            let platform = document.getElementById("platform_" + id).value;

            
            fetch("update-registration.php", {
                method: "POST",
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                body: "id=" + id +
                      "&name=" + encodeURIComponent(name) +
                      "&age=" + encodeURIComponent(age) +
                      "&nricmykid=" + encodeURIComponent(nricmykid) +
                      "&contact=" + encodeURIComponent(contact) +
                      "&emailadd=" + encodeURIComponent(emailadd) +
                      "&school=" + encodeURIComponent(school) +
                      "&category=" + encodeURIComponent(category) +
                      "&platform=" + encodeURIComponent(platform)
            })
            .then(res => {
                console.log("STATUS:", res.status); // 🔥 check status
                return res.text();
            })
            .then(data => {
                console.log("RESPONSE:", data); // 🔥 check response
            
                //alert(data); // 🔥 MUST SHOW
            
                if(data.trim() === "success"){
                    alert("Information updated!");
                    location.reload();
                } 
                else if(data.includes("no change")){
                    alert("No changes!");
                    location.reload();
                }
                else {
                    alert("Error: " + data);
                    location.reload();
                }
            })
            .catch(err => {
                console.error("FETCH ERROR:", err);
                alert("JS Error occurred!");
            });
        }
        </script>


</body>

</html>
