DAViCal
 All Classes Namespaces Functions Variables Pages
caldav-REPORT-principal-match.php
1 <?php
2 
3 $request->NeedPrivilege(array('DAV::read','DAV::read-current-user-privilege-set','DAV::read-acl'));
4 
5 if ( $request->depth > 0 ) {
6  $request->DoResponse( 400, 'The principal-match REPORT is only defined for Depth "0".' );
7 }
8 
12 $match = $xmltree->GetPath('/DAV::principal-match/DAV::self');
13 if ( count ( $match ) == 0 ) {
14  $match = $xmltree->GetPath('/DAV::principal-match/DAV::principal-property');
15  $match_self = false;
16 }
17 else {
18  $match_self = true;
19 }
20 if ( count ( $match ) == 0 ) {
21  $request->DoResponse( 400, 'Badly formed principal-match REPORT request.' );
22 }
23 
24 $target = new DAVResource($request->path);
25 
26 $where = '';
27 if ( $match_self ) {
28  // Technically we should restrict to finding the principal somewhere *below* the
29  // request path in the hierarchy, but we'll quietly ignore that because it's
30  // unlikely that anything would actually be wanting that behaviour.
31  $where .= 'username = :username';
32  $params = array(':username' => $session->username );
33 }
34 else {
35  $where = 'dav_name = :dav_name';
36  $params = array(':dav_name'=>'/'.$request->principal->GetProperty('username').'/');
37 }
38 $sql = "SELECT * FROM dav_principal WHERE $where ORDER BY principal_id LIMIT 100";
39 
40 if ( $target->IsPrincipal() ) {
41  // The request path is more specific, so ALTERNATIVELY,
42  // we find this principal's resources (collections) instead
43  $sql = "SELECT * FROM collection WHERE user_no = :user_no";
44  $params = array(':user_no' => $target->user_no() );
45 }
46 
47 $qry = new AwlQuery($sql, $params);
48 
49 
53 $get_props = $xmltree->GetPath('/DAV::principal-match/DAV::prop/*');
54 $properties = array();
55 foreach( $get_props AS $k1 => $v1 ) {
56  $properties[] = $v1->GetNSTag();
57 }
58 
59 $responses = array();
60 if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows() > 0 ) {
61  while( $row = $qry->Fetch() ) {
62  $principal = new DAVResource($row);
63  $responses[] = $principal->RenderAsXML( $properties, $reply );
64  }
65 }
66 
67 $multistatus = new XMLElement( "multistatus", $responses, $reply->GetXmlNsArray() );
68 
69 $request->XMLResponse( 207, $multistatus );