We need the DAVPrincipal module here in some situations.
[davical.git] / inc / caldav-REPORT-principal-match.php
blobe86d4918adc132f4546f84f8e61284e23525def3
1 <?php
4 $responses = array();
6 $request->NeedPrivilege(array('DAV::read','DAV::read-current-user-privilege-set','DAV::read-acl'));
8 /**
9 * Build the array of properties to include in the report output
11 $match = $xmltree->GetPath('/DAV::principal-match/DAV::self');
12 if ( count ( $match ) == 0 ) {
13 $match = $xmltree->GetPath('/DAV::principal-match/DAV::principal-property');
14 $match_self = false;
16 else {
17 $match_self = true;
19 if ( count ( $match ) == 0 ) {
20 $request->DoResponse( 400, 'Badly formed principal-match REPORT request.' );
23 $target = new DAVResource($request->path);
25 $where = '';
26 if ( $match_self ) {
27 // Technically we should restrict to finding the principal somewhere *below* the
28 // request path in the hierarchy, but we'll quietly ignore that because it's
29 // unlikely that anything would actually be wanting that behaviour.
30 $where .= 'username = :username';
31 $params = array(':username' => $session->username );
33 else {
34 $params = array(':dav_name'=>'/'.$request->principal->GetProperty('username').'/');
37 if ( $where != "" ) $where = "WHERE $where";
38 $sql = "SELECT * FROM dav_principal $where ORDER BY principal_id LIMIT 100";
39 $qry = new AwlQuery($sql, $params);
42 $get_props = $xmltree->GetPath('/DAV::principal-match/DAV::prop/*');
43 $properties = array();
44 foreach( $get_props AS $k1 => $v1 ) {
45 $properties[] = $v1->GetTag();
48 if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows() > 0 ) {
49 while( $row = $qry->Fetch() ) {
50 $principal = new DAVResource($row);
51 $responses[] = $principal->RenderAsXML( $properties, $reply );
55 $multistatus = new XMLElement( "multistatus", $responses, $reply->GetXmlNsArray() );
57 $request->XMLResponse( 207, $multistatus );