From facbb9931836bd650abdf1abc53c1d3721136d40 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sun, 10 Dec 2006 16:22:09 +1300 Subject: [PATCH] PROPFIND now working for individual resources. --- inc/caldav-PROPFIND.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/inc/caldav-PROPFIND.php b/inc/caldav-PROPFIND.php index f8017fa7..0712fc50 100644 --- a/inc/caldav-PROPFIND.php +++ b/inc/caldav-PROPFIND.php @@ -263,9 +263,8 @@ function get_collection_contents( $depth, $user_no, $collection ) { $sql = "SELECT dav_name, caldav_data, dav_etag, "; $sql .= "to_char(created at time zone 'GMT',?) AS created, "; - $sql .= "to_char(modified at time zone 'GMT',?) AS modified, "; + $sql .= "to_char(modified at time zone 'GMT',?) AS modified "; $sql .= "FROM caldav_data WHERE dav_name ~ ".qpg('^'.$collection->dav_name.'[^/]+$'); - $sql .= "dav_displayname, is_calendar FROM collection "; $qry = new PgQuery($sql, PgQuery::Plain(iCalendar::HttpDateFormat()), PgQuery::Plain(iCalendar::HttpDateFormat())); if( $qry->Exec("PROPFIND",__LINE__,__FILE__) && $qry->rows > 0 ) { while( $item = $qry->Fetch() ) { @@ -276,6 +275,7 @@ function get_collection_contents( $depth, $user_no, $collection ) { return $responses; } + /** * Get XML response for a single collection. If Depth is >0 then * subsidiary collections will also be got up to $depth @@ -327,6 +327,28 @@ function get_collection( $depth, $user_no, $collection_path ) { return $responses; } +/** +* Get XML response for a single item. Depth is irrelevant for this. +*/ +function get_item( $item_path ) { + $responses = array(); + + dbg_error_log("PROPFIND","Getting item: Path: %s", $item_path ); + + $sql = "SELECT dav_name, caldav_data, dav_etag, "; + $sql .= "to_char(created at time zone 'GMT',?) AS created, "; + $sql .= "to_char(modified at time zone 'GMT',?) AS modified "; + $sql .= "FROM caldav_data WHERE dav_name = ?;"; + $qry = new PgQuery($sql, PgQuery::Plain(iCalendar::HttpDateFormat()), PgQuery::Plain(iCalendar::HttpDateFormat()), $item_path); + if( $qry->Exec("PROPFIND",__LINE__,__FILE__) && $qry->rows > 0 ) { + while( $item = $qry->Fetch() ) { + $responses[] = item_to_xml( $item ); + } + } + return $responses; +} + + $request->UnsupportedRequest($unsupported); // Won't return if there was unsupported stuff. if ( $request->AllowedTo('read') ) { @@ -336,8 +358,13 @@ if ( $request->AllowedTo('read') ) { */ $url = $c->protocol_server_port_script . $request->path ; $url = preg_replace( '#/$#', '', $url); + if ( $request->IsCollection() ) { + $responses = get_collection( $request->depth, $request->user_no, $request->path ); + } + else { + $responses = get_item( $request->path ); + } - $responses = get_collection( $request->depth, (isset($request->user_no) ? $request->user_no : $session->user_no), $request->path ); $multistatus = new XMLElement( "multistatus", $responses, array('xmlns'=>'DAV:') ); }