<?php
include('config2.php');


$Task_id=trim($_GET['Task_id']);
$VIN=trim($_GET['VIN']);



$sqlcheck = "SELECT * FROM AllStockInClickUp WHERE vin = '$VIN';";
        $resultcheck = mysqli_query($conn, $sqlcheck); 
        if (mysqli_num_rows($resultcheck) > 0){

            $sql = "UPDATE AllStockInClickUp SET Task_Id ='$Task_id'
            WHERE VIN = '$VIN';";
            $result = mysqli_query($conn, $sql);
            if ($result == TRUE) 
            {
                // echo "Save Ok<br/>";
                $sqlcheck = "SELECT * FROM all_vehicle_information WHERE VIN = '$VIN';";
                $resultcheck = mysqli_query($conn, $sqlcheck); 
                if (mysqli_num_rows($resultcheck) > 0){
                    while ($row = mysqli_fetch_assoc($resultcheck)) {
                        echo $row['Model_Year'];
                        echo $row['Vehicle_location'];
                        $Model_Year=$row['Model_Year'];
                        $Vehicle_location=$row['Vehicle_location'];

                        /**
 * Requires libcurl
 */

$taskId =  $Task_id;
$fieldId = "e16bbb39-56ec-4760-9c53-313c923c1fce";
$query = array(
  "custom_task_ids" => "true",
  "team_id" => "36928142"
);

$curl = curl_init();

$payload = array(
  "value" => $Model_Year
);

curl_setopt_array($curl, [
  CURLOPT_HTTPHEADER => [
    "Authorization: pk_81649492_CHPKUC3PM80IBFT5D1Q7CAF9P0H8IBXG",
    "Content-Type: application/json"
  ],
  CURLOPT_POSTFIELDS => json_encode($payload),
  CURLOPT_URL => "https://api.clickup.com/api/v2/task/" . $taskId . "/field/" . $fieldId . "?" . http_build_query($query),
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
]);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$error = curl_error($curl);

curl_close($curl);

if ($error) {
  echo "cURL Error #:" . $error;
} else {
  echo $response;
}
 echo $row['Model_Year'];
                        echo $row['Vehicle_location'];

                        /**
 * Requires libcurl
 */

$taskId =  $Task_id;
$fieldId = "d31f2ea1-2311-4a55-81e6-f61d33566fe7";
$query = array(
  "custom_task_ids" => "true",
  "team_id" => "36928142"
);

$curl = curl_init();

$payload = array(
  "value" => $Vehicle_location
);

curl_setopt_array($curl, [
  CURLOPT_HTTPHEADER => [
    "Authorization: pk_81649492_CHPKUC3PM80IBFT5D1Q7CAF9P0H8IBXG",
    "Content-Type: application/json"
  ],
  CURLOPT_POSTFIELDS => json_encode($payload),
  CURLOPT_URL => "https://api.clickup.com/api/v2/task/" . $taskId . "/field/" . $fieldId . "?" . http_build_query($query),
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
]);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$error = curl_error($curl);

curl_close($curl);

if ($error) {
  echo "cURL Error #:" . $error;
} else {
  echo $response;
}
                    }

                }
            }else{
            
               } 
            
            
               

                
         }
    
    mysqli_close($conn);
?>