<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
if (!isset($_SESSION['stud_name'])) {
    header("Location: /har_ghar_tiranga_quiz/index.php");
    exit;
}
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">-->
        <title>હર ઘર તિરંગા કિવઝ</title>
        <!--<link rel="stylesheet" href="style.css">-->
        <link rel="icon" type="image/x-icon" href="flaticon.ico">

        <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.8.0/html2pdf.bundle.min.js"></script>

        <script type="text/javascript" src="html2pdf.bundle.min.js"></script>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

    </head>
    <body style="background-color: aliceblue;">
        <div class="container text-center" style="padding: 10px;border: 0px;min-height: 0px">
            <div class="row">
                <div class="col-sm-3"></div>
                <div class="col-sm-6" style="background-color: white">
                    <img src="logo1.jpg" class="img-rounded" style="width: 100%;height: 160px;margin: 10px">
                </div>
                <div class="col-sm-3"></div>
            </div>
        </div>

        <div class="container" style="padding: 5px;border: 0px;min-height: 0px">
            <div class="row">
                <div class="col-sm-3">            
                    <!--<button type="button" class="btn btn-primary btnsave" id="btn-submit" tabindex="6">Go To Home</button>-->
                </div>
                <div class="col-sm-6" style="background-color: white">
                    <hr style="height: 4px;border-width:0;color:orange;background-color:orange;margin-top: 0px;margin-bottom: 0px">
                    <div style="padding: 10px">
                        <h1><b><span style="color: orange">હર ઘર</span> તિરંગા <span style="color: green">કિવઝ</span></b></h1>
                        <h5><b style="font-size: 18px"><?php echo $_SESSION['stud_name']; ?></b></h5>
                        <button class="btn btn-link" onclick="generatePDF()">Download Certificate</button>
                        <button class="btn btn-link" id="btn_view_summary">View Your Quiz Summary</button>
                    </div>
                    <hr style="height: 4px;border-width:0;color:orange;background-color:orange;margin-top: 0px;margin-bottom: 0px">
                </div>
                <div class="col-sm-3">
                </div>
            </div>
        </div>
        <div id="canvas_div_pdf">

            <div class="container" id="print_divtag">
                <img src="logo.png" alt="Nature" style="width:130px;">
                <h1 class="certificate" style="margin-top: -30;">CERTIFICATE</h1>
                <p class="section">This Certificate Declares that</p>
                <h2 class="name"> <?php echo $_SESSION['stud_name']; ?></h2>
                <h6 class="content"> <?php echo $_SESSION['school_name'] . ', ' . $_SESSION['select_taluka']; ?></h6>
                <h6 class="content2"> has completed</h6>
                <h3 class="title"> <b><span style="color: orange">હર ઘર</span> તિરંગા <span style="color: green">કિવઝ</span></b></h3>
                <!--        <div class="text-center" style="margin-left: 0px;">        
                            <img src="gujtext.png" alt="Nature" style="height: auto;width:auto;">
                        </div>-->

                <div class="text-center" style="margin-left: 0px;">
                    On <?php echo $_SESSION['quiz_date']; ?>            
                    <img src="logo_1.png" alt="Nature" style="width:100px;"> With Passing Score of <?php echo $_SESSION['percentage'] . '%'; ?>
                </div>
                <h6 class="userid text-center"> Certificate ID <?php echo $_SESSION['certificate_id']; ?></h6>

            </div>

        </div>
    </body>
    <script>

        // var element = document.getElementById('canvas_div_pdf');
        //html2pdf(element);
    </script>

    <script>
        function generatePDF() {
            //        // Choose the element that our invoice is rendered in.
            ////                document.getElementById('invoice').style.display ='block';
            //        const element = document.getElementById('canvas_div_pdf');
            //
            ////        html2pdf(element);
            //        html2pdf().from(element).save();
            ////        html2pdf().from(element).save();
            ////                html2pdf()
            ////                        .set({html2canvas: {scale: 4}})
            ////                        .from(element)
            ////                        .save();
            window.location.href = '/har_ghar_tiranga_quiz/certificate.php';
        }

    </script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            $(document.body).on('click', '#btn_view_summary', function (e) {
                window.location.href = '/har_ghar_tiranga_quiz/view_quiz_summary.php';
            });

            //        $(document.body).on('click', '#btn_view_summary', function (e) {
            //            window.location.href = '/har_ghar_tiranga_quiz/view_quiz_summary.php';
            //        });

            $(document.body).on('click', '.btnsave', function (e) {

                var send = {'go_to_index': "1"}
                $.ajax({
                    type: 'POST',
                    data: send,
                    url: './PHP_Code/student_entry.php',
                    success: function (data) {
                        debugger;
                        //                    console.log('success');
                        //                    console.log(JSON.stringify(data));
                        //                            alert('data ' + data);
                        window.location.href = '/har_ghar_tiranga_quiz/index.php';

                    }, error: function (xhr, err) {
                        alert('Error ' + err.message);
                    }
                });

            });
        });

    </script>
</html>