<?php
	include_once('../config.php');      
	include_once(ABS_PATH.'/custom_function/default.php'); 
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
                        
    
    if(isset($_REQUEST['goBck']))
    { 
        unset($_SESSION['Adharreference_id']);
        unset($_SESSION['adh']);
        header("Location: ../");
        die;
    }
    
     
    
    if(isset($_POST['submit'])) 
    {               
                $stmt=$conn->prepare("select  *  from  UI__PanVeri   where panId=:panId ");    
                $stmt->bindValue(':panId', $_POST['mobile'] , PDO::PARAM_STR); 
                $stmt->execute();    
                if($stmt->rowCount()>0)   
				{ 
				    $FResult = $stmt->fetch(PDO::FETCH_OBJ);    
                    $stmt=$conn->prepare("insert into  UI__PanVeri (panId,custId,Tdate,nm) values(:panId,:custId,:Tdate,:nm) ");    
                    $stmt->bindValue(':panId', $FResult->panId , PDO::PARAM_STR); 
                    $stmt->bindValue(':custId',   $_SESSION['userId'] , PDO::PARAM_STR);
                    $stmt->bindValue(':Tdate',   date("d-M-Y"), PDO::PARAM_STR);  
                    $stmt->bindValue(':nm',  $FResult->nm  , PDO::PARAM_STR);   
                    $stmt->execute();  
                    $_SESSION['Regis'] = "Pan Verification Completed!!";
                    $_SESSION['topSuc'] = 1;
				}
				else
                {  
                $number = $_POST['mobile'];
                $RechargeAccess_token = "c1IJbwdJ7NaChZ6a6UFECH0h0Cq6MiHteJ3G5x3G";    
                $data_string = '{"provider_id":"385","client_id":"'.mt_rand(343555,23255).'","number":"'.$number.'"}';     
                $ch = curl_init('https://mobileapi.in/api/v1/verify/pan');                                             
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
                'x-tera-tenant-region: IN', 
                'Content-Type: application/json', 
                $headers[] = "Authorization: Bearer ".$RechargeAccess_token,
                'Content-Length: ' . strlen($data_string))                                                                       
                );       																		 
                $response = curl_exec($ch);  
                $Result = json_decode($response);    
                if($Result->status_id==1)
                {
                    
                    $stmt=$conn->prepare("insert into  UI__PanVeri (panId,custId,Tdate,nm) values(:panId,:custId,:Tdate,:nm) ");    
					$stmt->bindValue(':panId', $number  , PDO::PARAM_STR); 
					$stmt->bindValue(':custId',   $_SESSION['userId'] , PDO::PARAM_STR);
					$stmt->bindValue(':Tdate',   date("d-M-Y"), PDO::PARAM_STR);  
					$stmt->bindValue(':nm',  $Result->name  , PDO::PARAM_STR);   
					$stmt->execute();        
                    $_SESSION['Regis'] = "Pan Verification Completed!!";
                    $_SESSION['topSuc'] = 1;
                }else
                    $_SESSION['Regis'] = "Enter Correct PAN No";  
                }
                    
                header("Location: panVeri.php");
                die; 
    }  
    
	
    $stmt=$conn->prepare("select * from   UI__PanVeri where custId=:cuurentId");    
    $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);     
    $stmt->execute(); 
    $aCt = $stmt->rowCount();    
    $Cname = $stmt->fetch(PDO::FETCH_OBJ);    
    

include_once("../view/dashboard/panVeri.php");
?>