<?php 
    // ini_set("display_error",1);
    session_start();
    include "../modules/Class/autoload.php";
    date_default_timezone_set('Asia/Dushanbe');
    include '../phpqrcode/qrlib.php';
    $secret = "myandbdasecrettoday";
    $plate = $_REQUEST['plate'];
    $myhash = md5($secret.$plate);
    if($_REQUEST['sign']!=$myhash){
        header("Location:404.php");
        return;
    }
    $url = '217.11.177.108:9907/Fines/api/rbdaapi/index.php';
    $secret = 'shohinnewkey';
    $inputdate = date('ymdHis');
    $data = [
    "action"=>"logspravka",
    "inputdate"=>$inputdate,
    "fio"=>$_SESSION['username'],
    "date"=>date('d.m.Y'),
    "time"=>date('H:i:s'),
    "plate"=>filterdb($_REQUEST['plate']),
    "sign"=>md5('logspravka'.$inputdate.$secret)
    ];
    $jsondata = json_encode($data);
    $sendcurl = sendcurl($jsondata,$url);
    $arraydata = customjsondecode($sendcurl);
    // dd($arraydata);

    // Генерация QR-кода
    $tempDir = '../temp/';
    if (!file_exists($tempDir)){
        mkdir($tempDir);
    }

    $qrText = 'https://rbda.dc.tj/pages/checksignqr.php?plate='.$plate.'&ID='.$arraydata['id'].'&sign='.$myhash;
    $fileName = 'qrcode.png';
    $pngAbsoluteFilePath = $tempDir . $fileName;
    QRcode::png($qrText, $pngAbsoluteFilePath);


?>
<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>РБДА</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="РБДА" name="description" />
    <meta content="Themesdesign" name="author" />
    <!-- App favicon -->
    <link rel="shortcut icon" href="../assets/images/nerufavicon.png">
    <!-- Bootstrap Css -->
    <link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Icons Css -->
    <link href="../assets/css/icons.min.css" rel="stylesheet" type="text/css" />
    <!-- App Css-->
    <link href="../assets/css/app.min.css" rel="stylesheet" type="text/css" />
    <style>

        @media print {
            body * {
                visibility: hidden;
            }
            #printableDiv, #printableDiv * {
                visibility: visible;
            }
            #printableDiv {
                position: absolute;
                left: 0;
                top: 0;
            }
        }

        body {
            font-family: Arial, sans-serif;
        }
        .container {
            text-align: center;
            margin-top: 50px;
        }
        .header {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 10px;
        }

        .content {
            margin-top: 20px;
        }
        .qr-code {
            margin-top: 20px;
        }
    </style>
</head>

<body data-sidebar="dark">

    <!-- Begin page -->
    <div id="layout-wrapper">

        
        <?php include "header.php";?>
        <!-- ========== Left Sidebar Start ========== -->
        <?php include "menu.php"?>
        <!-- Left Sidebar End -->

        <!-- ============================================================== -->
        <!-- Start right Content here -->
        <!-- ============================================================== -->
        <div class="main-content">

            <div class="page-content">
                
                <div class="container-fluid">
                    <!-- end page title -->
                    <div class="card" id="printableDiv">
                        <div class="card-body">
                            <div class="p-lg-3">
                            <div class="container">
        <div class="header">
            <div style="clear: both;"></div>
                <div style="width: 95%;margin:0 auto;">
                    <img style="float: left;" src="../assets/images/neru.png" alt="NERU Logo" width="250" height="150">
                    <h4 style="font-weight: bold;text-align: center;float: right;width:60% ;">НИЗОМИ АВТОМАТИКУНОНИДАШУДАИ БАҚАЙДГИРИИ ВАЙРОНКУНИИ ҚОИДАҲОИ ҲАРАКАТ ДАР РОҲҲОИ ҶУМҲУРИИ ТОҶИКИСТОН</h4>
                </div>
                    <div style="clear: both;"></div>
        </div>
        <div class="content">
            <h2 style="font-weight: bold;">МАЪЛУМОТНОМА</h2>
            <p style="font-size: 20px;text-align: justify;">Рақами бақайдгирии <?=strtoupper($_REQUEST['plate'])?> ба санаи <?=date('d.m.Y')?> ва вақти <?=date('H:i:s')?> дар назди буҷети Ҷумҳурии Тоҷикистон маблағи пардохтнашудаи ҳуқуқвайронкунии маъмурӣ надорад.</p>
            <div style="clear: both;"></div>
            <div style="width: 80%;margin:0 auto;">
                <p style="font-size: 18px;float: left;">ш. Душанбе</p>
                <p style="font-size: 18px;float: right;"><?=date('d')?> <?php echo getMonthInRussian(date('Y-m-d')) ?> <?=date('Y')?> с.</p>
            </div>
            <div style="clear: both;"></div>
        </div>
        <div class="qr-code">
            <img width="350" height="350" src="<?=$pngAbsoluteFilePath?>" alt="QR Code">
        </div>
        <p style="font-weight: bold;text-align: center;">Пешниҳод кард: <?=$_SESSION['rank'].'-'.$_SESSION['fio'].' '.$_SESSION['name'] ?></p>
        <p style="font-weight: bold;font-size:30px;text-align: center;"><?=strtoupper($_REQUEST['plate'])?></p>
    </div>
                            </div>
                        <!--end card body-->
                    </div> <!-- end card-->


                </div> <!-- container-fluid -->
            </div>
            <!-- End Page-content -->
        </div>
        <!-- end main content-->

    </div>
    <!-- END layout-wrapper -->

    <!-- JAVASCRIPT -->
    <script src="../assets/libs/jquery/jquery.min.js"></script>
    <script src="../assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="../assets/libs/metismenu/metisMenu.min.js"></script>
    <script src="../assets/libs/simplebar/simplebar.min.js"></script>
    <script src="../assets/libs/node-waves/waves.min.js"></script>
    <script src="../assets/js/app.js"></script>
    <script>
        function printDiv(divId) {
            var printContents = document.getElementById(divId).innerHTML;
            var originalContents = document.body.innerHTML;

            document.body.innerHTML = printContents;
            window.print();
            document.body.innerHTML = originalContents;
        }

        // Запускаем печать при загрузке страницы
        window.onload = function() {
            printDiv('printableDiv');
        };
    </script>

</body>

</html>