<?php header("Access-Control-Allow-Origin: *");
  header("Access-Control-Allow-Headers: *");  

  header('Content-Type: application/json');

  $json = file_get_contents('php://input');
  $obj = json_decode($json, true);

  include '../db/connectMe.php';   
  include '../function/function.php';  

  // (C) GENERATE JWT TOKEN
  require "../vendor/autoload.php";
  use Firebase\JWT\JWT;

  // (A) NO data
  if (isset($_GET["tk"])  ) {


  if( AuthorizeMe(@substr(getallheaders()["Authorization"], 7)) ){

    $jwt = substr(getallheaders()["Authorization"], 7);

    //Decoding data
    $decodeToken = (json_decode(base64_decode(str_replace('_', '/', str_replace('-','+',explode('.', $jwt)[1]))))->data);

    if(!isset($decodeToken)){

      exit(json_encode(array("error" => "unauthorised") ));

    }



    ///////////////////////////////////////repairs/////////////////////////////////////////
      $taken = mysql_prep($_GET["tk"]);
      $status  = 1; 

      $businessId = mysql_prep($decodeToken->BUSID);
      $newRepairs = find_all_repaired_products_for_taken($status, $businessId, $taken); 

      $i = 0;


      if(empty($newRepairs)){
        exit(json_encode([]));
      }

      foreach ($newRepairs as $pro[] ) {

        $item = $pro;
        $json = json_encode($item);

        $i++;

      }


      exit($json) ;






  }else{


    exit(json_encode(array("error" => "unauthorised") ));


  }

}else{

    exit(json_encode(array("error" => "invalid request") ));
}




