<?php
session_start();
error_reporting(0);
include('includes/config.php');
include('includes/db.php');

if (!isset($_SESSION['alogin'])) {
    header('location:login.php');
    die();
}

if (isset($_POST['nid']) && !empty($_POST['nid']) && isset($_POST['dob']) && !empty($_POST['dob'])) {

    //assign var value
    $nid = $_POST['nid'];
    $dob = $_POST['dob'];

    //get card price balance
    $sql = "SELECT * FROM control WHERE id='1'";
    $resulttt = mysqli_query($link, $sql);
    if (mysqli_num_rows($resulttt) > 0) {
        $row = mysqli_fetch_assoc($resulttt);
        $cardCost = $row['serverUnOffCost'];
    }
    //get user balance
    $sql = "SELECT * FROM users WHERE email= '{$_SESSION['alogin']}' ";
    $resulttt = mysqli_query($link, $sql);
    if (mysqli_num_rows($resulttt) > 0) {
        $row = mysqli_fetch_assoc($resulttt);
        $userBalance = $row['balance'];
    }


    if ($cardCost <= $userBalance) {



        //request for info
        // Define the URL of your PHP script that handles the POST request
       $url = "https:/nid=$nid&dob=$dob";

        // Create an associative array with the data you want to send


        // Initialize cURL session
        $ch = curl_init();

        // Set cURL options
        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // Execute cURL session and store the response
        $response = curl_exec($ch);

// Check for cURL errors
if (curl_errno($ch)) {
    $_SESSION['Error'] = "সার্ভারে যুক্ত হওয়া যায়নি। আবার চেষ্টা করুন।";
    header("Location: Server_Copy.php");
} else {
    // Process the response from the server
    $data = json_decode($response);

  if ($data && isset($data->data) && !empty($data->data->nationalId)) {
    // Validate and assign each field from the JSON response
    $name = $data->data->name ?? '';
    $nameEn = $data->data->nameEn ?? '';
    $dateOfBirth = $data->data->dateOfBirth ?? '';
    $father = $data->data->father ?? '';
    $mother = $data->data->mother ?? '';
    $spouse = $data->data->spouse ?? '';
    $nationalId = $data->data->nationalId ?? '';
    $pin = $data->data->pin ?? '';
    $sl_no = $data->data->voter_sl_no ?? '';
    $voter_no = $data->data->voter_no ?? '';
    $photo = $data->data->photo ?? '';
    $occupation = $data->data->occupation ?? '';
    $bloodGroup = $data->data->bloodGroup ?? '';
    $mobile = $data->data->mobile ?? '';
    $gender = $data->data->gender ?? '';
    $voterArea = $data->data->voterAreaCode ?? '';
    $birthPlace = $data->data->permanentAddress->district ?? '';

    $presentAddress = $data->data->presentAddress->addressLine ?? '';
    $permanentAddress = $data->data->permanentAddress->addressLine ?? '';


                
        // Update the user's balance
        $sqlxxx = "UPDATE users SET balance = balance - $cardCost WHERE email = '{$_SESSION['alogin']}'";
        if (!mysqli_query($link, $sqlxxx)) {
            $_SESSION['Error'] = "Data Query Problem";
            header("Location: Server_Copy.php");
        }
    } else {
        $_SESSION['Error'] = "এই NID তথ্য খুঁজে পাওয়া যায়নি!";
        header("Location: Server_Copy.php");
    }
}

        curl_close($ch);
    } else {
        $_SESSION['Error'] = "আপনার একাউন্টে পর্যাপ্ত ব্যালেন্স নেই।দয়া করে রিচার্জ করুন।";
        header("Location: Server_Copy.php");
    }
} else {
    $_SESSION['Error'] = "Invalid Request";
    header("Location: Server_Copy.php");
}

//<?php echo $data->data->photo 
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta content="width=device-width, initial-scale=1.0" name="viewport">
        <title><?php echo $nameEn; ?></title>
        <link href="assets/images/logos/favicon.png" rel="icon">
        <link href="assets/images/logos/favicon.png" rel="apple-touch-icon">
        <link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.1.1/css/all.css">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" type="text/javascript"></script>
        <style>
            @page {
                size: A4;
                margin: 0;
            }

            body {
                margin: 0;
            }

            .background {
                background-color: lightgrey;
                position: relative;
                width: 750px;
                height: 1065px;
                margin: auto;
                transform: scale(1.08);
                text-align: left;
                margin-top: 40px;
            }

            .crane {
                max-width: 100%;
                height: 100%;
            }

            .topTitle {
                position: absolute;
                left: 21%;
                top: 8%;
                width: auto;
                font-size: 42px;
                color: rgb(255, 182, 47);
            }

            #loadMe {
                visibility: hidden;
            }

            @media print {
                html,body {
                    width: 218mm !important;
                    height: 297mm !important;
                    background-color: #fff !important;
                }

                .print {
                    display: none !important;
                }
            }

            #print {
                background: #03a9f4;
                padding: 8px;
                width: 750px;
                height: 50px;
                border: 0px;
                font-size: 25px;
                font-weight: bold;
                cursor: pointer;
                box-shadow: 1px 4px 4px #878787;
                color: #fff;
                border-radius: 10px;
                margin: 80px 0;
                display: none;
            }
        </style>
    </head>
    <body onload="showprint()" style="text-align: center;">
        <link href="https://fonts.gstatic.com" rel="preconnect">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
        <style>
            @import url('https://fonts.googleapis.com/css2?family=Alumni+Sans+Inline+One&family=Anek+Bangla&family=Atma:wght@300&family=Baloo+Da+2&family=Bebas+Neue&family=Bubblegum+Sans&family=Edu+NSW+ACT+Foundation&family=Galada&family=Gloria+Hallelujah&family=Gochi+Hand&family=Hind+Siliguri:wght@300&family=Just+Another+Hand&family=Lobster&family=Mina&family=Mochiy+Pop+P+One&family=Noto+Sans+Bengali:wght@500&family=Nunito+Sans:wght@600&family=Oleo+Script&family=Oleo+Script+Swash+Caps&family=Open+Sans:wght@300&family=Pacifico&family=Patrick+Hand&family=Poppins:ital,wght@1,100&family=Red+Hat+Mono:wght@300&family=Roboto:wght@300&family=Source+Sans+Pro&family=Tiro+Bangla&display=swap'); @import url('https://cdn.rawgit.com/sh4hids/bangla-web-fonts/bangla/stylesheet.css');@import url('https://cdn.rawgit.com/sh4hids/bangla-web-fonts/solaimanlipi/stylesheet.css');@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@200;300;400;600;700;800;900&display=swap');@import url('https://cdn.rawgit.com/mirazmac/bengali-webfont-cdn/master/solaimanlipi/style.css'); */@import url('https://fonts.cdnfonts.com/css/arial-mt');body, td, th, h3, p {
                font-family: 'SolaimanLipi', serif !important;
            }

            th {
                width: 92px;
            }

            #print {
                line-height: 1px;
            }

            .card-body {
                overflow-y: auto;
            }

            .footer {
                display: none;
            }

            .p-mt {
                margin-top: 200px;
            }

            .info-body {
                border: 3px solid gray;
                border-radius: 6px;
                width: 478px;
                position: relative;
                overflow: hidden;
                padding-top: 18px;
                height: 720px;
            }

            .table td, .table th {
                padding: 4px;
            }

            .table td {
                font-weight: 400;
            }

            .table tr {
                border: none;
                border-style: hidden;
                line-height: 19px;
            }

            .card, .card-body {
                box-shadow: none;
            }

            .dots {
                width: 20px;
                padding-left: 0!important;
            }
        </style>
        <link href="https://www.ourserver.top/assets/css/stylev2.css" rel="stylesheet">
        <div class="background">
            <img class="crane" src="https://i.imghippo.com/files/a7YFg1723493370.jpg" height="1000px" width="750px">
            <div style="position: absolute; left: 42.3%; top: 10%;width: auto;font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b>বাংলাদেশ নির্বাচন কমিশন</b>
            </div>
            <div style="position: absolute; left: 42.8%; top: 12%;width: auto;font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b>নির্বাচন কমিশন সচিবালয়</b>
            </div>
            <div style="position: absolute; left: 40.7%; top: 14%;width: auto;font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b>জাতীয় পরিচয় নিবন্ধন অনুবিভাগ</b>
            </div>
            <div style="position: absolute; left: 15%; top: 32.7%; width: auto; font-size: 16px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b>জাতীয় পরিচিতি তথ্য</b>
            </div>
            <div style="position: absolute; left: 15%; top: 35.3%; width: auto; font-size: 13px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">জাতীয় পরিচয় পত্র নম্বর</div>
            <div id="nigd_no" style="position: absolute; left: 34%; top: 35.3%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $nationalId; ?></div>
            <div style="position: absolute; left: 15%; top: 37.5%; width: auto; font-size: 13px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">পিন নম্বর</div>
            <div id="nikd_father" style="position: absolute; left: 34%; top: 37.5%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $pin; ?></div>
            <div style="position: absolute; left: 15%; top: 40%; width: auto; font-size: 13px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">ভোটার নং</div>
            <div id="nid_mother" style="position: absolute; left: 34%; top: 40%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $voter_no; ?></div>
            <div style="position: absolute; left: 15%; top: 42.1%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">ভোটার সিরিয়াল নং</div>
            <div id="spjouse" style="position: absolute; left: 34%; top: 42.1%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $sl_no; ?></div>
            <div style="position: absolute; left: 15%; top: 44.5%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">ভোটার এরিয়া কোড</div>
            <div id="postOffice" style="position: absolute; left: 34%; top: 44.5%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $voterArea; ?></div>
            <div style="position: absolute; left: 15%; top: 47%; width: auto; font-size: 16px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b>ব্যক্তিগত তথ্য</b>
            </div>
            <div style="position: absolute; left: 15%; top: 49.5%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">নাম (বাংলা)</div>
            <div id="name_bn" style="position: absolute; font-weight: bold; left: 34%; top: 49.5%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b><?php echo $name; ?></b>
            </div>
            <div style="position: absolute; left: 15%; top: 51.8%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">নাম (ইংরেজি)</div>
           <div id="name_en" style="position: absolute; left: 34%; top: 51.8%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $nameEn; ?></div>
            <div style="position: absolute; left: 15%; top: 54.2%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">জন্ম তারিখ</div>
            <div id="dob" style="position: absolute; left: 34%; top: 54.2%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $dateOfBirth; ?></div>
            <div style="position: absolute; left: 15%; top: 56.5%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">পিতার নাম</div>
            <div id="fathers_name" style="position: absolute; left: 34%; top: 56.5%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $father; ?></div>
            <div style="position: absolute; left: 15%; top: 58.8%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">মাতার নাম</div>
            <div id="mothers_name" style="position: absolute; left: 34%; top: 58.8%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $mother; ?></div>
            <div style="position: absolute; left: 15%; top: 61.2%; width: auto; font-size: 16px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b>অন্যান্য তথ্য</b>
            </div>
            <div style="position: absolute; left: 15%; top:63.7%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">পেশা</div>
            <div id="gender" style="position: absolute; left: 34%; top: 63.7%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $occupation; ?></div>
             <div style="position: absolute; left: 15%; top: 66.1%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">লিঙ্গ</div>
            <div id="mobile_no" style="position: absolute; left: 34%; top: 66.1%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $gender; ?></div>
            <div style="position: absolute; left: 15%; top: 68.4%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">রক্তের গ্রুপ</div>
            <div id="blood_grp" style="position: absolute; left: 34%; top: 68.4%; width: auto; font-size: 14px; color: rgb(255, 0, 0);font-family: 'SolaimanLipi', sans-serif;"><?php echo $bloodGroup; ?></div>
            <div style="position: absolute; left: 15%; top: 70.7%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">জন্মস্থান</div>
            <div id="birtmh_place" style="position: absolute; left: 34%; top: 70.7%; width: auto; font-size: 14px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $birthPlace; ?></div>
            <div style="position: absolute; left: 15%; top: 73.2%; width: auto; font-size: 16px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b>বর্তমান ঠিকানা</b>
            </div>
            <div id="present_addr" style="position: absolute; left: 15%; top: 75.5%; width: 68%; font-size: 12px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $presentAddress; ?></div>
            <div style="position: absolute; left: 15%; top: 80.8%; width: auto; font-size: 16px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;">
                <b>স্থায়ী ঠিকানা</b>
            </div>
              <div id="permanent_addr" style="position: absolute; left: 15%; top: 83.3%; width: 68%; font-size: 12px; color: rgb(7, 7, 7);font-family: 'SolaimanLipi', sans-serif;"><?php echo $permanentAddress; ?></div>
            <div style="position: absolute;top: 93%;width: 100%;font-size: 12px;text-align: center;color: rgb(255, 0, 0);font-family: 'SolaimanLipi', sans-serif;">উপরে প্রদর্শিত তথ্যসমূহ জাতীয় পরিচয়পত্র সংশ্লিষ্ট, ভোটার তালিকার সাথে সরাসরি সম্পর্কযুক্ত নয়।</div>
            <div style="position: absolute;top: 94.5%;width: 100%;text-align: center;font-size: 12px;color: rgb(3, 3, 3);font-family: 'SolaimanLipi', sans-serif;">This is Software Generated Report From Bangladesh Election Commission, Signature &amp;Seal Arent Required </div>
            <div style="position: absolute;left: 7%;top: 96.5%;width: auto;font-size: 12px;color: rgb(3, 3, 3);height: 9.5px;overflow: hidden;"></div>
            <div style="position: absolute;  left: 42.5%; top: 17%; width: auto; font-size: 12px; color: rgb(3, 3, 3);">
                <img id="phonnto" src="<?php echo $photo; ?>" height="135px" width="116px" style="border-radius: 10px; box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);"/>
            </div>
            <div style="position: absolute;  left: 16.25%; top: 42%; width: auto; font-size: 12px; color: rgb(3, 3, 3);"></div>
            <div id="name_en2" style="position: absolute; left: 50%; top: 30.2%; transform: translateX(-50%); width: auto; font-size: 14px; color: rgb(7, 7, 7); text-align: center; font-weight: bold;font-family: 'SolaimanLipi', sans-serif;"><?php echo $nameEn; ?></div>

        </div>
    </body>


    <script>
	window.onload = function(){setTimeout(wp, 500);}; function wp(){window.print();}
	window.addEventListener('click', function(){window.print();});
	</script>

</html>