<link rel="stylesheet" href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css">
<div style="width: 60%; margin: 0 auto; margin-top: 100px;">
    <h2>DNC Scrub</h2><br><br>
    <form action="" method="post">
        <div class="row">
            <div class="form-group col-md-6">
                <label for="Phone_number">Phone Number</label>
                <input type="text" class="form-control" id="phone_number" name="phone_number" required="" value="<?= ((isset($_GET['phone'])) ? $_GET['phone'] : '') ?>"
                    aria-describedby="Phone_numberHelp" placeholder="Enter Phone_number">
            </div>
            <div class="col-md-6 text-left" style="margin-top: 30px;">
                <button type="submit" class="btn btn-primary">Confirm Submit</button>
            </div>
        </div>
    </form>
    <?php
    if ($_POST) {
        //header('Content-Type: application/json; charset=utf-8');
        $phone = $_POST['phone_number'];
        if ($phone != '' && strlen($phone) == 10) {
            $curl = curl_init();
            curl_setopt_array($curl, array(
                CURLOPT_URL => 'https://www.dncscrub.com/app/main/rpc/scrub?phoneList=' . $phone . '&version=5&output=json',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'GET',
                CURLOPT_HTTPHEADER => array(
                    'loginId: 010E969C27A85E8FC3F5F107B1487433C66983BB61E0'
                ),
            ));

            $response = curl_exec($curl);

            curl_close($curl);
            $jsonRes = json_decode($response, true);
            //print_r($jsonRes);
            $status = $jsonRes[0]['ResultCode'];
            $DNC = ['D', 'P', 'O', 'X'];

            if (in_array($status, $DNC) || $jsonRes[0]['DoNotCallToday'] == "1") {

                echo '
                <div class="alert alert-danger" role="alert">You Number (' . $jsonRes[0]['Phone'] . ') is in DNC Scrub.
                    <table border="0">
                        <tr>
                            <td width=200>List</td>
                            <td>' . $jsonRes[0]['Reason'] . '</td> 
                        </tr>
                        <tr>
                            <td>Locale</td>
                            <td>' . $jsonRes[0]['Locale'] . '</td>
                        </tr>
                        <tr>
                            <td>Region</td>
                            <td>' . $jsonRes[0]['RegionAbbrev'] . '</td>
                        </tr>
                        <tr>
                            <td>Country</td>
                            <td>' . $jsonRes[0]['Country'] . '</td>
                        </tr>
                        <tr>
                            <td>CarrierInfo</td>
                            <td>' . $jsonRes[0]['CarrierInfo'] . '</td>
                        </tr>
                    </table>
                    <div style="display:none;">' . json_encode($jsonRes) . '</div>
                </div>';
            } else {
                echo '<div class="alert alert-success" role="alert">You Number (' . $jsonRes[0]['Phone'] . ') not in DNC Scrub </div>
                <div style="display:none;">' . json_encode($jsonRes) . '</div>';
            }
        } else {
            echo '<div class="alert alert-danger" role="alert">Invalid Number (' . $jsonRes[0]['Phone'] . ') </div>';
        }
    }
    ?>
</div>