<?php session_start();
require_once("./../../config/config.php");
//require_once("../config/commonsetting.php");
$actual_link = $_SERVER['HTTP_REFERER'];
$link = str_replace("installation/credentials.php","","$actual_link");
$myformId=SESS_MASTER;
$myIp= ipCheck() ;
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,'ipinfo.io/'.$myIp.'?token=00ec1f91664f39');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$result=json_decode($result);
$clientip = $result->ip;
$clientadd = $result->country;
$clientcity = $result->city;
$clientregion = $result->region;
$clientloc = $result->loc;
$clientorg = $result->org;
$clientpostal = $result->postal;
$clienttime = $result->timezone;
//echo $clienttime;
//var_dump($result);
//die;
$dateceated=date("Y-m-d G:i:s");
$createdby='0';
//echo $dateceated ;
//die;
$full_name		=   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'full_name']);
$emailid	=   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'emailid']);
$purchase_code =   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'purchase_code']);
$pass	=   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'new']);
$hash = password_hash($pass,PASSWORD_DEFAULT);
require_once('class.verify-purchase.php');
if($purchase_code){
   // $purchase_code = htmlspecialchars($_POST['purchase_code']);
   // $result_type = htmlspecialchars($_POST['result_type']);
    $o = EnvatoApi2::verifyPurchase( $purchase_code );
    if ( is_object($o) ) {
      $output  = '<div class="panel panel-default">';
      $output .= '<div class="panel-heading">Product Name</div>';
      $output .= '<div class="panel-body">';
      $output .= '<strong>'. $o->item->name .'</strong>';
      $output .= '</div></div>';
      $output .= '<div class="panel panel-success">';
      $output .= '<div class="panel-heading">Item ID</div>';
      $output .= '<div class="panel-body">';
      $output .= '<strong>'. $o->item->id .'</strong>';
      $output .= '</div></div>';
      $output .= '<div class="panel panel-default">';
      $output .= '<div class="panel-heading">Purchase Date</div>';
      $output .= '<div class="panel-body">';
      $output .= '<strong>'. date( "d F Y", strtotime( $o->sold_at ) ) .'</strong>';
      $output .= '</div></div>';
      $output .= '<div class="panel panel-success">';
      $output .= '<div class="panel-heading">Buyer Name</div>';
      $output .= '<div class="panel-body">';
      $output .= '<strong>'. $o->buyer .'</strong>';
      $output .= '</div></div>';
      $output .= '<div class="panel panel-default">';
      $output .= '<div class="panel-heading">License Type</div>';
      $output .= '<div class="panel-body">';
      $output .= '<strong>'. $o->license .'</strong>';
      $output .= '</div></div>';
      $output .= '<div class="panel panel-success">';
      $output .= '<div class="panel-heading">Supported Until</div>';
      $output .= '<div class="panel-body">';
      $output .= '<strong>'. date( "d F Y", strtotime( $o->supported_until ) ) .'</strong>';
      $output .= '</div></div>';

      $output_table = '<table class="table table-bordered">';
      $output_table .= '<thead><tr><th>Title</th> <th>Value</th></tr> </thead>';
      $output_table .= '<tbody>';
      $output_table .= '<tr><td>Product Name</td><td>'. $o->item->name .'</td></tr>';
      $output_table .= '<tr><td>Product ID</td><td>'. $o->item->id .'</td></tr>';
      $output_table .= '<tr><td>Purchase Date</td><td>'. date( "d F Y", strtotime( $o->sold_at ) ) .'</td></tr>';
      $output_table .= '<tr><td>Buyer Name</td><td>'. $o->buyer .'</td></tr>';
      $output_table .= '<tr><td>License Type</td><td>'. $o->license .'</td></tr>';
      $output_table .= '<tr><td>Supported Until</td><td>'. date( "d F Y", strtotime( $o->supported_until ) ) .'</td></tr>';
      $output_table .= '</tbody>';
      $output_table .= '</table>';

     $names=  $o->item->name ;
     $id = $o->item->id;
     $purchase_date = $o->sold_at;
      $buyer = $o->buyer;
      $license = $o->license;
      $supported = $o->supported_until;

     $olgaquery="INSERT INTO admin_license SET product_name='$names',product_id='$id',purchase_date='$purchase_date', buyer_name='$buyer', license_type='$license',supported_until='$supported', purchase_code='$purchase_code'";
		//echo  $olgaquery1;
		$stmt = $conn->prepare($olgaquery);
        if($stmt->execute()){

            $olgaquery="UPDATE admin_master SET createdIp='$myIp',datecreated='$dateceated',createdby='$createdby', full_name='$full_name', emailid='$emailid',userpass='$hash', purchase_code='$purchase_code'";
		//$olgaquery = $olgaquery."WHERE rowid = '1'";
		$stmt = $conn->prepare($olgaquery);
       // echo $olgaquery;
		if($stmt->execute()){
  $username = "noreply@ibuysoft.com";
  $dateceated=date("Y-m-d G:i:s");

  $_SESSION['forgot_pass']='success';
  echo "<script>window.location='./../completed.php';</script>";


         if( $retval == true ) {
            echo "Message sent successfully...";
         }else {
            echo "Message could not be sent...";
         }

        }
        }

    } else {
      $olgaquery="INSERT INTO admin_license SET purchase_date='$dateceated', buyer_name='$full_name', license_type='Custom License', purchase_code='$purchase_code'";
		//echo  $olgaquery1;
		$stmt = $conn->prepare($olgaquery);
        if($stmt->execute()){

            $olgaquery="UPDATE admin_master SET createdIp='$myIp',datecreated='$dateceated',createdby='$createdby', full_name='$full_name', emailid='$emailid',userpass='$hash', purchase_code='$purchase_code'";
		//$olgaquery = $olgaquery."WHERE rowid = '1'";
		$stmt = $conn->prepare($olgaquery);
       // echo $olgaquery;
		if($stmt->execute()){
  $username = "noreply@ibuysoft.com";
  $dateceated=date("Y-m-d G:i:s");
  $ab = "";
  $ab2 = "";
  $ab3 = "";

  $_SESSION['forgot_pass']='success';
  echo "<script>window.location='./../completed.php';</script>";


         if( $retval == true ) {
            echo "Message sent successfully...";
         }else {
            echo "Message could not be sent...";
         }

        }
    }
    }

  try{






   }

        // show error
        catch(PDOException $exception){
            die('ERROR: ' . $exception->getMessage());
        }
    }


?>
