<?php
	include "koneksi.php";
	
	$id = "12345"; //Kode RS
	$pass = "password"; // Password RS Online
	//Get Timestamp
	$dt = new DateTime(null, new DateTimeZone("UTC"));
	$timestamp = $dt->getTimestamp();
	// update data tempat tidur
	
	$url = "http://sirs.kemkes.go.id/fo/index.php/Fasyankes";
	$method = "PUT";
	// Query Hasil Mapping, Pastikan Query berjalan dengan benar sebelum dimasukan dalam line dibawah ini
	$sth = mysqli_query($koneksi, "SELECT id_tt,ruang,jumlah_ruang,jumlah,terpakai, prepare,prepare_plan, covid FROM tt_rsonline"); 
	mysqli_query($koneksi, "UPDATE tt_rsonline SET PostDate=NOW()");
	$rows = array();
	while($r = mysqli_fetch_assoc($sth)) {
		$rows[] = $r;
	}
	$postdata = json_encode($rows);
	
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_HEADER, false);
	curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_HTTPHEADER, array(
		"X-rs-id: ".$id,
		"X-Timestamp: ".$timestamp,
		"X-pass: ".$pass,
		"Content-type: application/json"
		));
	$result = curl_exec($curl);
	curl_close($curl);
	echo $result;
?>