<?php

// $caldav_url ='https://cloud.abtconsult.fr/remote.php/dav/calendars/Test/personal/';
$caldav_url ='https://cloud.abtconsult.fr/remote.php/dav/calendars/service/personal_shared_by_Test/Personal';
$username = 'service';
$password = 'sErvIcE#2025$';

$summary = 'Réunion équipe';
$description 	= 'Discussion projet...';
$start			= new DateTime ('2025-06-10 10:00:00', new DateTimeZone('UTC') );
$end			= new DateTime ('2025-06-10 11:00:00', new DateTimeZone('UTC') );
$uid 			= uniqid().'@example.com';

$ical = <<<EOD
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//MonApp//Calendar//FR
BEGIN:VEVENT
UID:$uid 
DTSTAMP:{$start->format('Ymd\THis\Z')}
DTSTART:{$start->format('Ymd\THis\Z')}
DTEND:{$end->format('Ymd\THis\Z')}
SUMMARY:$summary
DESCRIPTION:$description
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
EOD;

$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, $ical );

$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);

?>