summaryrefslogtreecommitdiff
path: root/appli_3_alpha_old/include/ical.inc.php
blob: 5df8e4c07f5224b7c4f73ec7e15310e3c99357d8 (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
61
62
63
64
65
66
67
68
<?php
/*
 * Fonction de g�n�ration d'iCal
 */
 
// Constantes d'erreur
define("ERR_ICAL_NO_DATA", -1);
define("ERR_ICAL_SQL_ERROR", -2);
 
 function generationIcal($idP, &$iCal_name, &$iCal_content, &$errmsg)
{
	require_once('connect.inc.php');
	$query = 'SELECT DISTINCT R.idR,R.objetR,P.courrielP,UNIX_TIMESTAMP(C.dateHeure),C.duree,R.lieuR,R.ordreJourR,L.idL'
		. ' FROM Liste L,Reunion R,Appartenir A,Creneau C,Personne P'
		. " WHERE ((A.idP = $idP AND A.idL = L.idL) OR R.idP_Orga = $idP)"
		. ' AND  R.idL = L.idL AND C.idC = R.idC_Fixe AND P.idP = R.idP_Orga';
	
	if ( ! $result = @mysql_query($query) )
	{
		// Cas d'erreur
		$errmsg =mysql_generate_errmsg();
		return ERR_ICAL_SQL_ERROR;
	}
	else
	{
		if (mysql_num_rows($result)<1)
		{
			return ERR_ICAL_NO_DATA;
		}
		else
		{
			$time = time();
			$iCal_name = "iCal_${idP}_${time}.ics";
			$iCal_content = "BEGIN:VCALENDAR\r\n" . "VERSION:2.0\r\n";
			while ( list($idR, $objetR, $courrielP, $dateDeb, $duree, $lieuR, $ordreJourR, $idL) = mysql_fetch_array($result) )
			{
				// TODO : Il est probablement judicieux d'ajouter � l'UID un timestamp unix !!!!!
				$iCal_content .= "BEGIN:VEVENT\r\n" . "UID:awor_${idP}.${idR}\r\n" . "SUMMARY:$objetR ($courrielP)\r\n";
				$iCal_content .= 'DTSTART:' . date('Ymd\THis', $dateDeb) . "\r\n";
				$iCal_content .= 'DTEND:' . date('Ymd\THis', $dateDeb+60*$duree) . "\r\n";
				$iCal_content .= "LOCATION:$lieuR\r\n";
				$iCal_content .= "DESCRIPTION:$ordreJourR\r\n";
				
				$query = 'SELECT P.courrielP FROM Appartenir A,Personne P' . " WHERE A.idP=P.idP AND A.idL='$idL'";
				if ( ! $result = mysql_query($query) )
				{
					// Cas d'erreur
					$errmsg =mysql_generate_errmsg();
					$ret=ERR_ICAL_SQL_ERROR;
					break;
				}
				else
				{
					while ( list($mail_autres) = mysql_fetch_array($result) )
					{
						$iCal_content .= "ATTENDEE:mailto:$mail_autres\r\n";
					}
				}
				// TODO : v�rifier la pertinance de la variable utilis�e
				$iCal_content .= 'URL:http://' . $_SERVER['HTTP_HOST'] . "\r\n";
				$iCal_content .= "END:VEVENT\r\n";
			}
			$iCal_content .= "END:VCALENDAR\r\n";
			return 0;
		}
	}
}
?>