DAViCal
 All Classes Namespaces Functions Variables Pages
caldav-REPORT-multiget.php
1 <?php
6 $responses = array();
7 
12 $proptype = $qry_content[0]->GetNSTag();
13 $properties = array();
14 $need_expansion = false;
15 switch( $proptype ) {
16  case 'DAV::prop':
17  $qry_props = $xmltree->GetPath('/*/'.$proptype.'/*');
18  foreach( $qry_content[0]->GetElements() AS $k => $v ) {
19  $properties[$v->GetNSTag()] = 1;
20  if ( $v->GetNSTag() == 'urn:ietf:params:xml:ns:caldav:calendar-data' ) check_for_expansion($v);
21  }
22  break;
23 
24  case 'DAV::allprop':
25  $properties['DAV::allprop'] = 1;
26  if ( $qry_content[1]->GetNSTag() == 'DAV::include' ) {
27  foreach( $qry_content[1]->GetElements() AS $k => $v ) {
28  $include_properties[] = $v->GetNSTag();
29  if ( $v->GetNSTag() == 'urn:ietf:params:xml:ns:caldav:calendar-data' ) check_for_expansion($v);
30  }
31  }
32  break;
33 
34  default:
35  $properties[$proptype] = 1;
36 }
37 if ( empty($properties) ) $properties['DAV::allprop'] = 1;
38 
39 $collection = new DAVResource($request->path);
40 $bound_from = $collection->bound_from();
41 
45 $mg_hrefs = $xmltree->GetPath('/*/DAV::href');
46 $href_in = '';
47 $params = array();
48 foreach( $mg_hrefs AS $k => $v ) {
54  $rawurl = rawurldecode($v->GetContent());
55  $path_pos = strpos($rawurl,$request->path);
56  if ( $path_pos === false ) {
57  $href = $bound_from . $rawurl;
58  }
59  else {
60  $href = $bound_from . substr( $rawurl, $path_pos + strlen($request->path));
61  }
62  @dbg_error_log("REPORT", 'Reporting on href "%s"', $href );
63  $href_in .= ($href_in == '' ? '' : ', ');
64  $href_in .= ':href'.$k;
65  $params[':href'.$k] = $href;
66 }
67 
68 $where = " WHERE caldav_data.collection_id = " . $collection->resource_id();
69 $where .= " AND caldav_data.dav_name IN ( $href_in ) ";
70 
71 if ( $mode == 'caldav' ) {
72  if ( $collection->Privileges() != privilege_to_bits('DAV::all') ) {
73  $where .= " AND (calendar_item.class != 'PRIVATE' OR calendar_item.class IS NULL) ";
74  }
75 }
76 $sql = 'SELECT calendar_item.*, addressbook_resource.*, caldav_data.* FROM caldav_data
77  LEFT JOIN calendar_item USING(dav_id, user_no, dav_name, collection_id)
78  LEFT JOIN addressbook_resource USING(dav_id)
79  LEFT JOIN collection USING(collection_id)';
80 
87 if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $where .= " ORDER BY caldav_data.dav_id";
88 $qry = new AwlQuery( $sql . $where, $params );
89 if ( $qry->Exec('REPORT',__LINE__,__FILE__) && $qry->rows() > 0 ) {
90  while( $dav_object = $qry->Fetch() ) {
91  if ( $bound_from != $collection->dav_name() ) {
92  $dav_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $dav_object->dav_name);
93  }
94  if ( $need_expansion ) {
95  $vResource = new vComponent($dav_object->caldav_data);
96  $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end);
97  $dav_object->caldav_data = $expanded->Render();
98  }
99  $responses[] = component_to_xml( $properties, $dav_object );
100  }
101 }
102 
103 $multistatus = new XMLElement( "multistatus", $responses, $reply->GetXmlNsArray() );
104 
105 $request->XMLResponse( 207, $multistatus );