DAViCal
DAVTicket.php
1 <?php
12 require_once('AwlQuery.php');
13 
14 
20 class DAVTicket
21 {
25  private $ticket_id;
26 
30  private $dav_name;
31 
35  private $target_collection_id;
36 
40  private $target_resource_id;
41 
45  private $expiry;
46 
50  private $dav_owner_id;
51 
55  private $privileges;
56 
60  private $grantor_collection_privileges;
61 
62  /* These fields were being added dynmically. Set to private mostly, I had to
63  * set these as public for tests to pass: expired
64  */
65  public $expired;
66  private $expires;
67 
72  function __construct( $ticket_id ) {
73  global $c;
74 
75  $this->dav_name = null;
76  $this->target_collection_id = null;
77  $this->target_resource_id = null;
78  $this->expiry = null;
79  $this->expired = true;
80  $this->dav_owner_id = null;
81  $this->ticket_id = $ticket_id;
82  $this->privileges = 0;
83  $this->grantor_collection_privileges = 0;
84 
85  $qry = new AwlQuery(
86  'SELECT access_ticket.*, collection.dav_name, (access_ticket.expires < current_timestamp) AS expired,
87  path_privs(access_ticket.dav_owner_id,collection.dav_name,:scan_depth) AS grantor_collection_privileges
88  FROM access_ticket JOIN collection ON (target_collection_id = collection_id)
89  WHERE ticket_id = :ticket_id::text',
90  array(':ticket_id' => $ticket_id, ':scan_depth' => $c->permission_scan_depth)
91  );
92  if ( $qry->Exec('DAVTicket',__LINE__,__FILE__) && $qry->rows() == 1 && $t = $qry->Fetch() ) {
93  if ( ! $t->expired ) {
94  foreach( $t AS $k => $v ) {
95  $this->{$k} = $v;
96  }
97  $this->expired = false;
98  $this->privileges = bindec($this->privileges);
99  $this->grantor_collection_privileges = bindec($this->grantor_collection_privileges);
100  dbg_error_log( 'DAVTicket', 'Found a current ticket for "%s"', implode(', ',bits_to_privilege($this->privileges())) );
101  }
102  else {
103  dbg_error_log( 'DAVTicket', 'Found an expired ticket: %s - %s', $ticket_id, $t->expires );
104  }
105  }
106  if ( isset($this->target_resource_id) ) {
107  $qry = new AwlQuery( 'SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id', array(':dav_id' => $this->target_resource_id ) );
108  if ( $qry->Exec('DAVTicket',__LINE__,__FILE__) && $qry->rows() == 1 && $r = $qry->Fetch() ) {
109  $this->dav_name = $r->dav_name;
110  }
111  }
112  }
113 
114 
115  function dav_name() {
116  return $this->dav_name;
117  }
118 
119 
120  function id() {
121  return $this->ticket_id;
122  }
123 
124 
125  function privileges() {
126  return ($this->privileges & $this->grantor_collection_privileges);
127  }
128 
129 
130  function MatchesPath( $test_path ) {
131  $length = strlen($this->dav_name);
132  return (substr($test_path, 0, $length) == $this->dav_name);
133  }
134 
135  function MatchesResource( $test_resource_id ) {
136  return ($test_resource_id == $this->target_collection_id || $test_resource_id == $this->target_resource_id);
137  }
138 }
__construct( $ticket_id)
Definition: DAVTicket.php:72