From f2b20bc191ba5fc3de0077a3f71793d26c611ced Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 23 Dec 2009 23:30:07 +1300 Subject: [PATCH] Move caldav:calendar-timezone into the collection table. --- inc/DAVResource.php | 17 +++++++++++++++-- inc/caldav-PROPPATCH.php | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/inc/DAVResource.php b/inc/DAVResource.php index 53cf379e..197b0b88 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -277,8 +277,11 @@ class DAVResource $base_sql = 'SELECT collection.*, path_privs(:session_principal::int8, collection.dav_name,:scan_depth::int), '; $base_sql .= 'p.principal_id, p.type_id AS principal_type_id, '; - $base_sql .= 'p.displayname AS principal_displayname, p.default_privileges AS principal_default_privileges '; - $base_sql .= 'FROM collection LEFT JOIN principal p USING (user_no) WHERE '; + $base_sql .= 'p.displayname AS principal_displayname, p.default_privileges AS principal_default_privileges, '; + $base_sql .= 'time_zone.tz_spec '; + $base_sql .= 'FROM collection LEFT JOIN principal p USING (user_no) '; + $base_sql .= 'LEFT JOIN time_zone ON (collection.timezone=time_zone.tz_id) '; + $base_sql .= 'WHERE '; $sql = $base_sql .'collection.dav_name = :raw_path '; $params = array( ':raw_path' => $this->dav_name, ':session_principal' => $session->principal_id, ':scan_depth' => $c->permission_scan_depth ); if ( !preg_match( '#/$#', $this->dav_name ) ) { @@ -1021,6 +1024,16 @@ EOQRY; $denied[] = $reply->Tag($tag); break; + case 'urn:ietf:params:xml:ns:caldav:calendar-timezone': + if ( ! $this->_is_collection ) return false; + if ( !isset($this->collection->tz_spec) || $this->collection->tz_spec == '' ) return false; + + $cal = new iCalComponent(); + $cal->VCalendar(); + $cal->AddComponent( new iCalComponent($this->collection->tz_spec) ); + $reply->NSElement($prop, $tag, $cal->Render() ); + break; + case 'urn:ietf:params:xml:ns:caldav:calendar-data': if ( $this->_is_collection ) return false; if ( !isset($this->resource) ) $this->FetchResource(); diff --git a/inc/caldav-PROPPATCH.php b/inc/caldav-PROPPATCH.php index fe5896d5..999af1b4 100644 --- a/inc/caldav-PROPPATCH.php +++ b/inc/caldav-PROPPATCH.php @@ -10,6 +10,8 @@ */ dbg_error_log("PROPPATCH", "method handler"); +require_once('iCalendar.php'); + if ( ! $request->AllowedTo('write-properties') ) { $request->DoResponse( 403 ); } @@ -95,6 +97,17 @@ foreach( $setprops AS $k => $setting ) { } break; + case 'urn:ietf:params:xml:ns:caldav:calendar-timezone': + $tzcomponent = $setting->GetPath('urn:ietf:params:xml:ns:caldav:calendar-timezone'); + $tzstring = $tzcomponent[0]->GetContent(); + $calendar = new iCalendar( array( 'icalendar' => $tzstring) ); + $timezones = $calendar->component->GetComponents('VTIMEZONE'); + if ( $timezones === false || count($timezones) == 0 ) break; + $tz = $timezones[0]; // Backward compatibility + $tzid = $tz->GetPValue('TZID'); + $sql .= sprintf( 'UPDATE collection SET timezone = %s WHERE dav_name = %s;', qpg($tzid), qpg($request->path) ); + break; + /** * The following properties are read-only, so they will cause the request to fail */ @@ -159,6 +172,10 @@ foreach( $rmprops AS $k => $setting ) { } break; + case 'urn:ietf:params:xml:ns:caldav:calendar-timezone': + $sql .= sprintf( "UPDATE collection SET timezone = NULL WHERE dav_name = %s;", qpg($request->path) ); + break; + /** * The following properties are read-only, so they will cause the request to fail */