Page 1 sur 1

Générer un fichier iCal à synchroniser avec Google Agenda

Posté : 17 mars 2021, 00:52
par Fatbulle
Bonjour,
Un de mes sites contient un planning. A chaque modification de ce planning, je génère un fichier iCal (.ics) en php. Je récupère ce fichier dans Google Agenda via une URL.
Ca marche lorsque je configure cette importation dans Google Agenda.
Mon problème :
Si je rajoute un évènement, celui-ci n'apparait pas dans Google Agenda. Pour qu'il apparaisse, il faut que je déconnecte mon nouvel agenda, puis que je le re-configure.
Voici le code de mon fichier ics avec 4 évènement ;

Code : Tout sélectionner

BEGIN:VCALENDAR VERSION:2.0 PRODID:-//CNotes.fr//CNOTESCAL v1.0//EN CALSCALE:GREGORIAN X-WR-CALNAME:Agenda de Jean Duval X-WR-TIMEZONE:Europe/Paris BEGIN:VEVENT DTSTART:20210317T070000Z DTEND:20210317T110000Z DTSTAMP:20210316T165426Z CREATED:20210305T123457Z LAST-MODIFIED:20210305T123457Z SUMMARY:CATOU 2 LOCATION:14 rue du cinéma 78400 - Chatou DESCRIPTION:brushing homme - END:VEVENT BEGIN:VEVENT DTSTART:20210318T070000Z DTEND:20210318T110000Z DTSTAMP:20210316T165426Z CREATED:20210305T123457Z LAST-MODIFIED:20210305T123457Z SUMMARY:CLIENT 2 LOCATION:14 rue du cinéma 78400 - Chatou DESCRIPTION:Taillage Haie - END:VEVENT BEGIN:VEVENT DTSTART:20210319T070000Z DTEND:20210319T110000Z DTSTAMP:20210316T165426Z CREATED:20210305T123457Z LAST-MODIFIED:20210305T123457Z SUMMARY:CLIENT 3 LOCATION:14 rue du cinéma 78400 - Chatou DESCRIPTION:Taillage Haie - END:VEVENT BEGIN:VEVENT DTSTART:20210320T130000Z DTEND:20210320T160000Z DTSTAMP:20210316T165426Z CREATED:20210305T123457Z LAST-MODIFIED:20210316T123457Z SUMMARY:CLIENT 4 LOCATION:14 rue du cinéma 78400 - Chatou DESCRIPTION:Taillage Haie - END:VEVENT END:VCALENDAR
Si quelqu'un voit une erreur, je suis preneur.
Merci à tous.

Re: Générer un fichier iCal à synchroniser avec Google Agenda

Posté : 17 mars 2021, 08:30
par @rthur
Si quelqu'un voit une erreur, je suis preneur.
Moi je dirai qu'il n'y a pas de rue du cinéma à Chatou 8-)
Plus sérieusement, tu met bien à jour les LAST-MODIFIED ?

Re: Générer un fichier iCal à synchroniser avec Google Agenda

Posté : 18 mars 2021, 11:26
par Fatbulle
Je vois que tu es hyper pointu sur le sujet !.. Effectivement, la rue du Cinéma n'existe pas à Chatou.
Sinon, la modification du LAST-MODIFIED ne change rien. 2 jours que j'y suis, je n'ai plus de cheveux, j'attaque les ongles.
pour info, voici mon code :

Code : Tout sélectionner

<?php session_start(); include('verifSession.php'); // chaine aléatoire function str_rand(int $length = 32){ // 64 = 32 $length = ($length < 4) ? 4 : $length; return bin2hex(random_bytes(($length-($length%2))/2)); } // fin chaine aléatoire $eol = "\r"; $d = '@cnotes.fr'; $dtStamp = date('Ymd') . 'T' . date('His') . 'Z'; $reqResa = $bdd->prepare("SELECT * from reservations WHERE employe=:employe;"); $reqResa->execute(array(':employe'=>$_SESSION['employeAdmin'])); $ics = "BEGIN:VCALENDAR" . $eol; $ics .= "VERSION:2.0" . $eol; $ics .= "PRODID:-//CNotes.fr//CNOTESCAL v1.0//EN" . $eol; $ics .= "CALSCALE:GREGORIAN" . $eol; while($rowResa = $reqResa -> fetch()){ $uid = str_rand() . $d; $idClient = $rowResa['client']; $typeInter = $rowResa['typeIntervention']; $adr = $rowResa['adrPresta'] . ' ' . $rowResa['cpPresta'] . ' - ' . $rowResa['villePresta']; $reqClient = $bdd->prepare("SELECT * from clients WHERE id_client=?;"); $reqClient->execute(array($idClient)); $rowClient = $reqClient -> fetch(); if($rowClient['particulier'] == -1){$nomClient = $rowClient['prenom'] . ' ' . $rowClient['nom'];} else {$nomClient = $rowClient['societe'];} $reqTypeInter = $bdd->prepare("SELECT * from type_intervention WHERE id_typeIntervention=?;"); $reqTypeInter->execute(array($typeInter)); $rowTypeInter = $reqTypeInter -> fetch(); $typeInter = $rowTypeInter['comment']; $dte = date('Ymd', strtotime($rowResa['dteReservation'])); $deb = date('His', strtotime($rowResa['heureDebut'])); $fin = date('His', strtotime($rowResa['heureFin'])); $date_debut = $dte; $date_fin = $dte; $objet = $nomClient; $lieu = $adr; $details = $typeInter . ' - ' . $rowResa['observations']; //Evenèment au format ICS $ics .= "BEGIN:VEVENT" . $eol; $ics .= "UID:" . $uid . $eol; $ics .= "DTSTART:". $date_debut."T".$deb."Z" . $eol; $ics .= "DTEND:".$date_fin."T".$fin."Z" . $eol; $ics .= "DTSTAMP:".$dtStamp . $eol; $ics .= "SUMMARY:".$objet."" . $eol; $ics .= "LOCATION:".$lieu."" . $eol; $ics .= "DESCRIPTION:".$details."" . $eol; $ics .= "END:VEVENT" . $eol; } //Création du fichier $ics .= "END:VCALENDAR" . $eol; $fichier = 'public/'.$_SESSION['repertoire'].'/'.$_SESSION['prenomNom'].'Ical.ics'; $f = fopen($fichier, 'w+'); fputs($f, $ics); ?><!doctype html> <html> <head> <meta charset="utf-8"> <title>Document sans titre</title> </head> <body> <p><?php echo('<a href="https://cnotes.pc-info-services.fr/' . $fichier . '" target="_blank">https://cnotes.pc-info-services.fr/' . $fichier . '</a>');?> </p> <p><?php echo($ics);?>&nbsp;</p> </body> </html>
Et voici le fichier ics obtenu :

Code : Tout sélectionner

BEGIN:VCALENDAR VERSION:2.0 PRODID:-//CNotes.fr//CNOTESCAL v1.0//EN CALSCALE:GREGORIAN BEGIN:VEVENT UID:[email protected] DTSTART:20210130T090000Z DTEND:20210130T110000Z DTSTAMP:20210318T095511Z SUMMARY:Menthe à l'eau LOCATION:45 impasse du Cudsac 54600 - Villers-lès-Nancy DESCRIPTION:Maintenance 2h - END:VEVENT BEGIN:VEVENT UID:[email protected] DTSTART:20210318T100000Z DTEND:20210318T120000Z DTSTAMP:20210318T095511Z SUMMARY:CATOU LOCATION:14 rue du cinéma 78400 - Chatou DESCRIPTION: - tralala END:VEVENT BEGIN:VEVENT UID:[email protected] DTSTART:20210319T110000Z DTEND:20210319T130000Z DTSTAMP:20210318T095511Z SUMMARY:Albert Baleine LOCATION:Av. de la mer 234 12909 - Genève DESCRIPTION: - Intervention 2 END:VEVENT END:VCALENDAR