<?php 
require("../connect.php");
include './funcConvertToSecond.php';
date_default_timezone_set('Asia/Jakarta');

$seperateDate = explode("/", date("Y/m/d", time()));
$filename_db = "TKS".$_POST['addedby'].$_POST['blockid'].$_POST['tphid'].date("YmdHis",time()).".png";

$items = array();
$items[] = array(
    'field_1671' => $_POST['addedby'], // Created by
    'parent_item_id' => $_POST['blockid'],    // TPH ID
    'field_1658' => $_POST['blockid'],    // Blok ID
    'field_1665' => $_POST['tphcode'],    // TPH Code
    'field_1666' => $_POST['tphid'],    // TPH ID
    'field_1659' => $_POST['harvestdate'],    // Harvest Date
    'field_1677' => $_POST['inputdate'],    // Verification Date
    'field_1676' => timeToSeconds($_POST['inputtime']),    // Verification Time
    'field_1667' => $_POST['bjr'],    // Aktual BJR
    'field_1668' => $_POST['totaltree'],    // Pokok Blok
    'field_1669' => $_POST['jjgsample'],    // Janjang Sample
    'field_1670' => $_POST['pokoksample'],    // Pokok Sample
    'field_1680' => $_POST['potensibrod'],    // Potensi Brondolan
    'field_1679' => str_replace(',', '.', $_POST['potensiton']),    // Potensi Tonase
    'field_1678' => $_POST['akp'],    // Angka Rapat Panen
    'field_1952' => $_POST['inputmethodtph'],    // InputMethodTPH
    'field_1681' => $_POST['nodoc'],    // Document Number
    'field_1672' => $_POST['lattks'],    // Latitude Taksasi
    'field_1673' => $_POST['longtks'],    // Longitude Taksasi
    'field_1674' => "[map]".$_POST['lattks'].",".$_POST['longtks']."(".$_POST['nodoc'].")[/map]",    // Map Taksasi
    'field_1675' => $filename_db,   // Image Taksasi
    'field_1952' => $_POST['inputmethodtph']
);

$params = array(
    'key' => 'uq9gWhofzHpCbQZTaaCVyh6q6tiiwZfN9CfVbwGw', //API key
    'username' => 'admin', //username
    'password' => 'terimakasih', //password
    'action' => 'insert', //action
    'entity_id' => 83, //ID of the entity to which the record will be added
    'items' => $items, //array of records
);
						                                    
$ch = curl_init('https://agri.digibizdev.online/api/rest.php'); //API Url
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
$result = curl_exec($ch);
curl_close($ch);

if ($result) {
    $result = json_decode($result,true);
  
    if ($result['status'] == 'success') {
        echo json_encode(array("UPLOADTAKSASI"=>"SUCCESS"));
    }
  
}
?>