@extends($activeTemplate.'layouts.master')
@section('content')


<?php echo "this is user page" ?>

    <div class="container">
        @if(auth()->user()->kyckart_data)
            <div class="row justify-content-center mt-4">
                <div class="col-md-8">
                    <div class="card border border--base">
                        <div class="card-body">

                     @if(auth()->user()->kyckartv)
                            <div class="d-flex justify-content-end mb-3">
                                <span class="badge badge--success"> <i class="fas fa-check"></i> @lang('Approved')</span>
                            </div>
                            @endif
                            <ul class="list-group">
                                @foreach(auth()->user()->kyckart_data as $key=>$item)
                                 @if($item->type == 'file')
                                <li class="list-group-item d-flex flex-wrap justify-content-between">
                                    <span>@lang(keyToTitle($key))</span>
                                    {{$item->value}}
                                </li>
                            @else
                                <li class="list-group-item d-flex flex-wrap justify-content-between">
                                    <span>@lang(keyToTitle($key))</span>
                                    {{ $item->value }}
                                </li>
                                     <?php 
                                     $db_host        = 'localhost';
$db_user        = 'root';
$db_pass        = '';
$db_database    = 'aartham_banking1'; 
/* End config */
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_database);
/* check connection */
if (mysqli_connect_errno()) {printf("Connect failed: %s\n", mysqli_connect_error());}

                                    $number = $item->value;
                                    //Server url
                                  //  $url = "https://api.kyckart.com/api/panCard/search?panNumber=$number";
                                    $apiKey = 's7kg8g9ofujmomxd9qdusbpt40jyswqr'; // should match with Server key
                                    $headers = array(
                                         'Content-Type:application/json',
                                         'x-api-key: '.$apiKey
                                    );
                                    // Send request to Server
                                    $ch = curl_init($url);
                                    // To save response in a variable from server, set headers;
                                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                                    // Get response
                                    $response = curl_exec($ch);
                                    // Decode
                                    $result = json_decode($response);
                                    foreach($result as $row){
    //get the employee details
    $number = $result['number'];
    $name = $result['name'];
    $typeOfHolde = $result['typeOfHolde'];
    $isIndividual = $result['isIndividual'];
    $isValid = $result['isValid'];
    $panStatus = $result['panStatus'];

    
    //insert into mysql table
    $sql = "INSERT INTO pan_data(pan_number, name, type, indevisuality, validity, status)
    VALUES('$number', '$name', '$typeOfHolde', '$isIndividual', '$isValid', '$panStatus')";
    if(!mysqli_query($mysqli,$sql))
    {
        die('Error : ' . mysqli_error($mysqli));
    }
}
                                    ?>                                 
                                  <li class="list-group-item d-flex flex-wrap justify-content-between">
                                         <span>Name</span>                        
                                <?php echo  $result->response->name; ?>
                                </li>
                                 <li class="list-group-item d-flex flex-wrap justify-content-between">
                                         <span>Type of Holder</span>                       
                                 <?php echo  $result->response->typeOfHolder; ?>
                                </li>
                                 <li class="list-group-item d-flex flex-wrap justify-content-between">
                                        <span>Indivisual</span>                      
                                 <?php echo  $result->response->isIndividual; ?>
                                </li>
                                 <li class="list-group-item d-flex flex-wrap justify-content-between">
                                       <span>Valid</span>                           
                                 <?php echo  $result->response->isValid; ?>
                                </li>
                                 <li class="list-group-item d-flex flex-wrap justify-content-between">
                                         <span>Status</span>                         
                                 <?php echo  $result->response->panStatus; ?>
                                </li>
                                @endif
                                @endforeach
                              
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        @endif
    </div>
@endsection