<?php
session_start();
if (!isset($_SESSION['MEM_ID'])) {
    header("location: index.php");
    exit;
}

include "connection.php";

$MEM_ID = $_SESSION['MEM_ID'];

// Fetch TRACKING_NO from NA_EVENT_REG table based on MEM_ID
$sql_tracking = "SELECT TRACKING_NO FROM NAA_EVENTS_REG WHERE MEM_ID = :mem_id";
$parse_tracking = ociparse($conn, $sql_tracking);
oci_bind_by_name($parse_tracking, ":mem_id", $MEM_ID);
oci_execute($parse_tracking);
$row_tracking = oci_fetch_assoc($parse_tracking);
$tracking_no = $row_tracking['TRACKING_NO'] ?? '';
oci_free_statement($parse_tracking);

if (isset($_POST['submit_payment'])) {
    $submitted_tracking_no = $_POST['tracking_no_payment'];
    // Redirect to your payment gateway with the tracking number
    $payment_gateway_url = "YOUR_PAYMENT_GATEWAY_URL?tracking_id=" . urlencode($submitted_tracking_no);
    header("Location: " . $payment_gateway_url);
    exit;
}

oci_close($conn);
?>

<html lang="en">
<head>
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-GQPGJ4YN30"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'G-GQPGJ4YN30');
    </script>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Payment</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
    <link rel="stylesheet" href="//malihu.github.io/custom-scrollbar/jquery.mCustomScrollbar.min.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
     <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <style>
        label {
            font-weight: bold;
        }
    </style>
    <script type="text/javascript">
        function printContent(el) {
            var divToPrint = document.getElementById(el);
            var newWin = window.open('', 'Print-Window');
            newWin.document.open();
            newWin.document.write('<html> <link rel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"crossorigin="anonymous">');
            newWin.document.write('<style> label{font-weight: bold;}  </style>');
            newWin.document.write('<body onload="window.print()"> ');
            newWin.document.write(divToPrint.innerHTML);
            newWin.document.write('</body></html>');
            newWin.document.close();
            setTimeout(function() {
                newWin.close();
            }, 1000);
        }
    </script>
    </head>
<body>
    <?php include 'dashboard.php'; ?>
    <style>
        .header img {
            float: left;
            width: 100px;
            height: 100px;
        }
        .header h1,
        h3,
        h4,
        h5,
        h6 {
            position: relative;
            top: 18px;
            left: 10px;
        }

            #personal::placeholder {
    color: white; /* Placeholder text color white */
    opacity: 1; /* Full visibility */
    font-weight: bold;
    text-align: center;
}
    </style>

    <div class="container" id="print_doc">
        <div class="card">
            <div class="card-body" style="margin:0; padding:0;">
                <div class="row">
                    <div class="col-md-2"></div>
                    <div class="col-md-10">
                        <div class="header">
                            <img src="assets/img/Holy_cross.png" style="border: 3px solid black;" class="mr-5 " alt="BD Logo">
                            <h3 style="color: #ddbe4d; font-style: oblique;">
                                75<sup style="font-size: 0.6em; vertical-align: super;">th</sup> Foundation Of Holy Cross Girls High School
                            </h3>
                            
                        </div>
                    </div>
                    <div class="col-md-2"></div>
                </div>
                <hr>
                <div class="form-body">

                     <div class="row m-3">
                                   <div class="col-md-12" >
                                   
                                    <div class="col-md-12">
                                        <input type="text" class="form-control" name="personal" id="personal" placeholder="Payment process Form" value="" disabled="" style="background-color: #ddbe4d; color: white;">
                                    </div>
                                   
                                </div>
                                 </div>

                    <form method="POST" enctype="multipart/form-data">
                        <div class="row m-3" style="padding-top: 20px;">
                            <div class="col-lg-3 col-md-3 col-sm-12">
                                
                            </div>
                             <div class="col-lg-6 col-md-6 col-sm-12">
                                <div class="row ">
                                    <div class="col-lg-4 col-md-4 col-sm-12">
                                        <label for="tracking_no_payment" class="text-center font-weight-bold" style="color: black">Tracking Number:</label>
                                    </div>
                                    <div class="col-lg-4 col-md-4 col-sm-12">
                                        <input type="text" class="form-control" id="tracking_no_payment" name="tracking_no_payment" value="<?php echo htmlspecialchars($tracking_no); ?>" readonly style="border: 2px solid #ddbe4d;background-color: #fff;color: black ">
                                        <small class="form-text text-muted"></small>
                                    </div>
                                </div>
                            </div>
                             <div class="col-lg-3 col-md-3 col-sm-12">
                                
                            </div>
                        </div>
                        <div class="row m-3">
                            <div class="col text-center">
                                <button type="submit" class="btn btn-success m-3" name='submit_payment' id='submit_payment'>
                                    Proceed to Payment
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
    <script src="//malihu.github.io/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</body>
</html>