<?php

function SendVTODO ( $staff_member_id, $title, $description, $dueDateFmt )
{
	error_log ( "SendVTODO..." );

	return;

	$caldav_url ='https://cloud.ximeo.be/remote.php/dav/calendars/service/personal_shared_by_demo/';
	$username = 'service';
	$password = 'xIm#2025$se';

	$stamp			= new DateTime ('now', new DateTimeZone('UTC') );
	$due			= new DateTime ($dueDateFmt, new DateTimeZone('UTC') );
	$uid 			= uniqid().'@example.com';

	$vtodo = <<<EOT
	BEGIN:VCALENDAR
	VERSION:2.0
	PRODID:-//MonApp//Calendar//FR
	BEGIN:VTODO
	UID:$uid 
	DTSTAMP:{$stamp->format('Ymd\THis\Z')}
	DUE:{$due->format('Ymd\THis\Z')}
	SUMMARY:$title
	DESCRIPTION:$description
	STATUS:NEEDS-ACTION
	END:VTODO
	END:VCALENDAR
	EOT;

	$event_url = $caldav_url . urlencode($uid) . '.ics';

	$ch = curl_init($event_url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
	curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: text/calendar; charset=utf-8'] );
	curl_setopt($ch, CURLOPT_USERPWD, "$username:$password" );
	curl_setopt($ch, CURLOPT_POSTFIELDS, $vtodo );

	$response = curl_exec($ch);
	$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

	if ( curl_errno($ch))
	{
		echo 'Erreur cURL: ' . curl_error($ch);
	}
	else
	{
		echo "Réponse HTTP: $http_code\n";
	}

	curl_close($ch);
}

?>