<?php
    session_start();
    include '_connect.php';
    // include 'qrcode/qrlib.php';
    $ct_no = $_GET['ct_no'];
    $billerid = $_GET['billerid'];
    $ref1 = $_GET['ref1'];
    $ref2 = $_GET['ref2'];
    $price = $_GET['price'];
    $QRCODE = $billerid." ".$ref1." ".$ref2." ".$price."00";
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
	<head>
		<meta charset="utf-8">
		<title>ชำระด้วย QR CODE</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <script src='https://kit.fontawesome.com/a076d05399.js' crossorigin='anonymous'></script>
        <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
        <?php
            include 'css.php';
        ?>
        <style media="screen">
            body{
                /* font-family:"Angsana New"; */
                font-size:27px;
                background-image: url("img/xBG01.jpg");
                background-repeat: no-repeat;
                background-size: 210%;
            }
        </style>
	</head>
	<body>
		<?php
            $sql = "SELECT ps_name,ct_mobileno,product_name,ct_no FROM EHONGDB.dbo.hps_ctmain
            WHERE ct_no = '$ct_no'";
            $select=$dbh->prepare($sql);
            $select->execute();
            $fetchx=$select->fetch();
            $ps_name = $fetchx['ps_name'];
            $ct_mobileno = $fetchx['ct_mobileno'];
            $product_name = $fetchx['product_name'];
            // echo $sql;
            // echo $QRCODE;
        ?>
        <center>
            <br>
            <h1>ชำระเงินผ่าน QR CODE</h1> <br>

            <table border="0" id="table_5" style='width: 100%'>
                <thead>
                    <tr></tr>
                </thead>
                <tbody style='text-align:center;'></tbody>
            </table>

        </center>

        <input type="text" value="" id="userId" hidden>
        <img src="" id="pictureUrl" alt="" hidden>
        <input type="text" value="" id="displayName" hidden>
        <input type="text" value="" id="statusMessage" hidden>
        
        <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
        <script charset="utf-8" src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
        <script src="_liffid.js"></script>
        
        <?php 
            // include '_index_linejson_1.php' 
            echo '<script type="text/javascript">';
            echo "var ct_no = '$ct_no';"; // ส่งค่า $data จาก PHP ไปยังตัวแปร data ของ Javascript
            echo "var billerid = '$billerid';"; // ส่งค่า $data จาก PHP ไปยังตัวแปร data ของ Javascript
            echo "var ref1 = '$ref1';"; // ส่งค่า $data จาก PHP ไปยังตัวแปร data ของ Javascript
            echo "var ref2 = '$ref2';"; // ส่งค่า $data จาก PHP ไปยังตัวแปร data ของ Javascript
            echo "var price = '$price';"; // ส่งค่า $data จาก PHP ไปยังตัวแปร data ของ Javascript
            echo '</script>';
        ?>

        <script>
        // ส่งข้อมูล ผ่าน ajax
        $.ajax({
            url: '_index_lineqrcodejson.php?ct_no='+ct_no+'&billerid='+billerid+'&ref1='+ref1+'&ref2='+ref2+'&price='+price,
            type: 'GET',
            dataType: 'JSON',
            // แสดงข้อมูล
            success: function(response){
                var len = response.length;
                for(var i=0; i<len; i++){
                var ct_no = response[i].ct_no;
                var ps_name = response[i].ps_name;
                var product_name = response[i].product_name;
                var price = response[i].price;
                var price_2 = response[i].price_2;


                var ct_mobileno = response[i].ct_mobileno;
                var ref1 = response[i].ref1;
                var ref2 = response[i].ref2;
                var billerid = response[i].billerid;
                var QRCODE = response[i].QRCODE;

                var tr_str = 
                    "<tr>" +
                        "<td>" + 
                        "ชื่อ-นามสกุล : " + ps_name + "<br>" +
                        "สินค้า : " + product_name + "<br>" +
                        "ค่าชำระ : <lable style='color:red'>" + price_2 + "</lable><br>" + "<hr>" + 
                        "<img src='qrcode/qrpng.php?billerid=" + billerid + "&ref1=" + ref1 + "&ref2=" + ref2 + "&price=" + price + "' width='50%' ><br>" +
                        QRCODE +
                        "</td>" +
                    "</tr>";
                $("#table_5 tbody").append(tr_str);
                }
            } 
        });
        </script>
            
	</body>
</html>
