summaryrefslogtreecommitdiff
path: root/maquette_old/ical.php
blob: 7dc43e385b5f07124d0bc0e66703b36af33bf24b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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); 
	}
}

?>