Add $c->auto_refresh_duration option to set a auto refresh on any GET calendar.
[davical.git] / inc / caldav-GET.php
blobd9085d48f19189b3c898170d89535a43d1767993
1 <?php
2 /**
3 * CalDAV Server - handle GET method
5 * @package davical
6 * @subpackage caldav
7 * @author Andrew McMillan <andrew@mcmillan.net.nz>
8 * @copyright Catalyst .Net Ltd, Morphoss Ltd <http://www.morphoss.com/>
9 * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
11 dbg_error_log("get", "GET method handler");
13 require("caldav-GET-functions.php");
15 $dav_resource = new DAVResource($request->path);
16 $dav_resource->NeedPrivilege( array('urn:ietf:params:xml:ns:caldav:read-free-busy','DAV::read') );
17 if ( $dav_resource->IsExternal() ) {
18 update_external ( $dav_resource );
21 if ( ! $dav_resource->Exists() ) {
22 $request->DoResponse( 404, translate("Resource Not Found.") );
26 if ( $dav_resource->IsCollection() ) {
27 $response = export_iCalendar($dav_resource);
28 header( 'Etag: '.$dav_resource->unique_tag() );
29 $request->DoResponse( 200, ($request->method == 'HEAD' ? '' : $response), 'text/calendar; charset="utf-8"' );
33 // Just a single event then
35 $resource = $dav_resource->resource();
36 $ic = new iCalComponent( $resource->caldav_data );
38 $resource->caldav_data = preg_replace( '{(?<!\r)\n}', "\r\n", $resource->caldav_data);
40 /** Default deny... */
41 $allowed = false;
42 if ( $dav_resource->HavePrivilegeTo('all', false) || $session->user_no == $resource->user_no || $session->user_no == $resource->logged_user
43 || ( $c->allow_get_email_visibility && $ic->IsAttendee($session->email) ) ) {
44 /**
45 * These people get to see all of the event, and they should always
46 * get any alarms as well.
48 $allowed = true;
50 else if ( $resource->class != 'PRIVATE' ) {
51 $allowed = true; // but we may well obfuscate it below
52 if ( ! $dav_resource->HavePrivilegeTo('DAV::read') || ( $resource->class == 'CONFIDENTIAL' && ! $request->HavePrivilegeTo('DAV::write-content') ) ) {
53 $ical = new iCalComponent( $resource->caldav_data );
54 $comps = $ical->GetComponents('VTIMEZONE',false);
55 $confidential = obfuscated_event($comps[0]);
56 $ical->SetComponents( array($confidential), $resource->caldav_type );
57 $resource->caldav_data = $ical->Render();
60 // else $resource->class == 'PRIVATE' and this person may not see it.
62 if ( ! $allowed ) {
63 $request->DoResponse( 403, translate("Forbidden") );
66 header( 'Etag: "'.$resource->dav_etag.'"' );
67 header( 'Content-Length: '.strlen($resource->caldav_data) );
69 $contenttype = 'text/plain';
70 switch( $resource->caldav_type ) {
71 case 'VJOURNAL':
72 case 'VEVENT':
73 case 'VTODO':
74 $contenttype = 'text/calendar';
75 break;
77 case 'VCARD':
78 $contenttype = 'text/vcard';
79 break;
82 $request->DoResponse( 200, ($request->method == 'HEAD' ? '' : $resource->caldav_data), $contenttype.'; charset="utf-8"' );