DAViCal
Loading...
Searching...
No Matches
caldav-GET-functions.php
1<?php
11
12require_once("iCalendar.php");
13require_once("DAVResource.php");
14
15function obfuscated_event( $icalendar ) {
16 // The user is not admin / owner of this calendar looking at his calendar and can not admin the other cal,
17 // or maybe they don't have *read* access but they got here, so they must at least have free/busy access
18 // so we will present an obfuscated version of the event that just says "Busy" (translated :-)
19 $confidential = new iCalComponent();
20 $confidential->SetType($icalendar->GetType());
21 $confidential->AddProperty( 'SUMMARY', translate('Busy') );
22 $confidential->AddProperty( 'CLASS', 'CONFIDENTIAL' );
23 $confidential->SetProperties( $icalendar->GetProperties('DTSTART'), 'DTSTART' );
24 $confidential->SetProperties( $icalendar->GetProperties('RRULE'), 'RRULE' );
25 $confidential->SetProperties( $icalendar->GetProperties('EXDATE'), 'EXDATE' );
26 $confidential->SetProperties( $icalendar->GetProperties('RECURRENCE-ID'), 'RECURRENCE-ID' );
27 $confidential->SetProperties( $icalendar->GetProperties('SEQUENCE'), 'SEQUENCE' );
28 $confidential->SetProperties( $icalendar->GetProperties('DURATION'), 'DURATION' );
29 $confidential->SetProperties( $icalendar->GetProperties('DTEND'), 'DTEND' );
30 $confidential->SetProperties( $icalendar->GetProperties('UID'), 'UID' );
31 $confidential->SetProperties( $icalendar->GetProperties('CREATED'), 'CREATED' );
32
33 return $confidential;
34}
35
36function export_iCalendar( DAVResource $dav_resource ) {
37 global $session, $c, $request;
38 if ( ! $dav_resource->IsCalendar() && !(isset($c->get_includes_subcollections) && $c->get_includes_subcollections) ) {
40 header("Allow: PROPFIND,PROPPATCH,OPTIONS,MKCOL,REPORT,DELETE");
41 $request->DoResponse( 405, translate("GET requests on collections are only supported for calendars.") );
42 }
43
48 if ( isset($c->get_includes_subcollections) && $c->get_includes_subcollections ) {
49 $where = 'caldav_data.collection_id IN ';
50 $where .= '(SELECT bound_source_id FROM dav_binding WHERE dav_binding.dav_name ~ :path_match ';
51 $where .= 'UNION ';
52 $where .= 'SELECT collection_id FROM collection WHERE collection.dav_name ~ :path_match) ';
53 $params = array( ':path_match' => '^'.$dav_resource->dav_name() );
54 $distinct = 'DISTINCT ON (calendar_item.uid) ';
55 }
56 else {
57 $where = 'caldav_data.collection_id = :collection_id ';
58 $params = array( ':collection_id' => $dav_resource->resource_id() );
59 $distinct = '';
60 }
61 $sql = 'SELECT caldav_data, class, caldav_type, user_no, logged_user ';
62 $sql .= 'FROM (';
63 $sql .= 'SELECT '.$distinct.' caldav_data, class, caldav_type, calendar_item.user_no, logged_user, calendar_item.dav_name, calendar_item.dtstart, calendar_item.dtend ';
64 $sql .= 'FROM collection INNER JOIN caldav_data USING(collection_id) ';
65 $sql .= 'INNER JOIN calendar_item USING ( dav_id ) WHERE '.$where;
66 if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $sql .= ' ORDER BY calendar_item.uid, calendar_item.dav_id';
67 $sql .= ') AS s1';
68 if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $sql .= ' ORDER BY user_no, dtstart, dtend';
69
70 $qry = new AwlQuery( $sql, $params );
71 if ( !$qry->Exec("GET",__LINE__,__FILE__) ) {
72 $request->DoResponse( 500, translate("Database Error") );
73 }
74
79 $vcal = new iCalComponent();
80 $vcal->VCalendar();
81 $displayname = $dav_resource->GetProperty('displayname');
82 if ( isset($displayname) ) {
83 $vcal->AddProperty("X-WR-CALNAME", $displayname);
84 }
85 if ( !empty($c->auto_refresh_duration) ) {
86 $vcal->AddProperty("X-APPLE-AUTO-REFRESH-INTERVAL", $c->auto_refresh_duration);
87 $vcal->AddProperty("AUTO-REFRESH", $c->auto_refresh_duration);
88 $vcal->AddProperty("X-PUBLISHED-TTL", $c->auto_refresh_duration);
89 }
90
91 $need_zones = array();
92 $timezones = array();
93 while( $event = $qry->Fetch() ) {
94 $ical = new iCalComponent( $event->caldav_data );
95
97 $event_zones = $ical->GetComponents('VTIMEZONE',true);
98 foreach( $event_zones AS $k => $tz ) {
99 $tzid = $tz->GetPValue('TZID');
100 if ( !isset($tzid) ) continue ;
101 if ( $tzid != '' && !isset($timezones[$tzid]) ) {
102 $timezones[$tzid] = $tz;
103 }
104 }
105
107 $comps = $ical->GetComponents('VTIMEZONE',false);
108 foreach( $comps AS $k => $comp ) {
109 $tzid = $comp->GetPParamValue('DTSTART', 'TZID'); if ( isset($tzid) && !isset($need_zones[$tzid]) ) $need_zones[$tzid] = 1;
110 $tzid = $comp->GetPParamValue('DUE', 'TZID'); if ( isset($tzid) && !isset($need_zones[$tzid]) ) $need_zones[$tzid] = 1;
111 $tzid = $comp->GetPParamValue('DTEND', 'TZID'); if ( isset($tzid) && !isset($need_zones[$tzid]) ) $need_zones[$tzid] = 1;
112
113 if ( $dav_resource->HavePrivilegeTo('all',false) || $session->user_no == $event->user_no || $session->user_no == $event->logged_user
114 || ( isset($session->email) && $c->allow_get_email_visibility && $comp->IsAttendee($session->email) ) ) {
119 $vcal->AddComponent($comp);
120 continue;
121 }
123 if ( $event->class == 'PRIVATE' ) continue;
124
125 if ( ! $dav_resource->HavePrivilegeTo('DAV::read') || $event->class == 'CONFIDENTIAL' ) {
126 $vcal->AddComponent(obfuscated_event($comp));
127 }
128 elseif ( isset($c->hide_alarm) && $c->hide_alarm ) {
129 // Otherwise we hide the alarms (if configured to)
130 $comp->ClearComponents('VALARM');
131 $vcal->AddComponent($comp);
132 }
133 else {
134 $vcal->AddComponent($comp);
135 }
136 }
137 }
138
140 foreach( $need_zones AS $tzid => $v ) {
141 if ( isset($timezones[$tzid]) ) $vcal->AddComponent($timezones[$tzid]);
142 }
143
144 return $vcal->Render();
145}