summaryrefslogtreecommitdiff
path: root/maquette/ical.php
diff options
context:
space:
mode:
Diffstat (limited to 'maquette/ical.php')
-rw-r--r--maquette/ical.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/maquette/ical.php b/maquette/ical.php
new file mode 100644
index 0000000..7dc43e3
--- /dev/null
+++ b/maquette/ical.php
@@ -0,0 +1,60 @@
+<?php
+include ('connect.inc.php');
+function generationIcal ($identifiant)
+{
+ $result = mysql_query("SELECT DISTINCT R.idR,R.objetR,P.courrielP,C.dateHeure,C.duree,R.lieuR,R.ordreJourR,L.idL FROM Liste L,Reunion R,Appartenir A,Creneau C,Personne P WHERE ((A.idP = $identifiant AND A.idL = L.idL) OR R.idP_Orga = $identifiant) AND R.idL = L.idL AND C.idC = R.idC_Fixe AND P.idP = R.idP_Orga");
+ if (mysql_num_rows($result)>0)
+ {
+ $nameiCal = "iCal" . $identifiant . ".ics";
+ $textiCal = "BEGIN:VCALENDAR\r\n" . "VERSION:2.0\r\n";
+ for($i=0;$i<mysql_num_rows($result);$i++)
+ {
+ $row = mysql_fetch_array($result);
+ $textiCal .= "BEGIN:VEVENT\r\n" . "UID:$identifiant." . $row["idR"] . "\r\n";
+ $textiCal .= "SUMMARY:" . $row["objetR"] . " (" . $row["courrielP"] . ")" ."\r\n";
+ list($date,$time) = explode(" ",$row["dateHeure"]);
+ list($year,$month,$day) = explode("-",$date);
+ list($hour,$minute,$seconde) = explode(":",$time);
+ $textiCal .= "DTSTART:$year$month$day"."T"."$hour$minute$seconde"."\r\n";
+ $endDate = date("Ymd", mktime((int)$hour, (int)((int)$minute+(int)$row["duree"]), (int)$seconde,(int)$month, (int)$day, (int)$year));
+ $endTime = date("His", mktime((int)$hour, (int)((int)$minute+(int)$row["duree"]), (int)$seconde,(int)$month, (int)$day, (int)$year));
+ $textiCal .= "DTEND:$endDate"."T"."$endTime"."\r\n" ;
+ $textiCal .= "LOCATION:".$row["lieuR"]."\r\n";
+ $textiCal .= "DESCRIPTION:".$row["ordreJourR"]."\r\n";
+ $result_p = mysql_query("SELECT P.courrielP FROM Appartenir A,Personne P WHERE A.idP = P.idP AND A.idL = " . $row['idL']);
+ for($j=0;$j<mysql_num_rows($result_p);$j++)
+ {
+ $row_p = mysql_fetch_array($result_p);
+ $textiCal .= "ATTENDEE:mailto:" . $row_p['courrielP'] . "\r\n";
+ }
+ $textiCal .= "URL:http://awor.free.fr/\r\n";
+ $textiCal .= "END:VEVENT\r\n";
+ }
+ $textiCal .= "END:VCALENDAR\r\n";
+ if ($f=fopen("iCal/".$nameiCal,"wb")) if (fputs($f, $textiCal) == true) {fclose($f); return($nameiCal);}
+ fclose($f);
+ return ("erreur");
+ }
+ else
+ {
+ return ("none");
+ }
+}
+
+if (isset($_GET["id"])) //a remplacer par isset($_SESSION["id"])
+{
+ $res = generationIcal($id);
+ if ($res != "none" && res != "erreur")
+ {
+ header("Content-disposition: attachment; filename=$res");
+ header("Content-Type: application/force-download");
+ header("Content-Transfer-Encoding: text/ics\n"); // Surtout ne pas enlever le \n
+ header("Content-Length: ".filesize("iCal/".$res));
+ header("Pragma: no-cache");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
+ header("Expires: 0");
+ readfile("iCal/".$res);
+ }
+}
+
+?>