source: contrib/davical/inc/caldav-REPORT-multiget.php @ 3733

Revision 3733, 8.0 KB checked in by gabriel.malheiros, 13 years ago (diff)

Ticket #1541 - <Davical customizado para o Expresso.Utiliza Caldav e CardDav?>

Line 
1<?php
2/**
3* Handle the calendar-multiget REPORT request.
4*/
5include_once("drivers_ldap.php");
6$responses = array();
7
8$need_expansion = false;
9function check_for_expansion( $calendar_data_node ) {
10  global $need_expansion, $expand_range_start, $expand_range_end;
11
12  if ( !class_exists('DateTime') ) return; /** We don't support expansion on PHP5.1 */
13
14  $expansion = $calendar_data_node->GetElements('urn:ietf:params:xml:ns:caldav:expand');
15  if ( isset($expansion[0]) ) {
16    $need_expansion = true;
17    $expand_range_start = $expansion[0]->GetAttribute('start');
18    $expand_range_end = $expansion[0]->GetAttribute('end');
19    if ( isset($expand_range_start) ) $expand_range_start = new RepeatRuleDateTime($expand_range_start);
20    if ( isset($expand_range_end) )   $expand_range_end   = new RepeatRuleDateTime($expand_range_end);
21  }
22}
23
24
25/**
26 * Build the array of properties to include in the report output
27 */
28$proptype = $qry_content[0]->GetTag();
29$properties = array();
30switch( $proptype ) {
31  case 'DAV::prop':
32    $qry_props = $xmltree->GetPath('/*/'.$proptype.'/*');
33    foreach( $qry_content[0]->GetElements() AS $k => $v ) {
34      $propertyname = preg_replace( '/^.*:/', '', $v->GetTag() );
35      $properties[$propertyname] = 1;
36      if ( $v->GetTag() == 'urn:ietf:params:xml:ns:caldav:calendar-data' ) check_for_expansion($v);
37    }
38    break;
39
40  case 'DAV::allprop':
41    $properties['allprop'] = 1;
42    if ( $qry_content[1]->GetTag() == 'DAV::include' ) {
43      foreach( $qry_content[1]->GetElements() AS $k => $v ) {
44        $include_properties[] = $v->GetTag(); /** $include_properties is referenced in DAVResource where allprop is expanded */
45        if ( $v->GetTag() == 'urn:ietf:params:xml:ns:caldav:calendar-data' ) check_for_expansion($v);
46      }
47    }
48    break;
49
50 default:
51    $propertyname = preg_replace( '/^.*:/', '', $proptype );
52    $properties[$propertyname] = 1;
53}
54$collection = new DAVResource($request->path);
55$bound_from = $collection->bound_from();
56
57/**
58 * Build the href list for the IN ( href, href, href, ... ) clause.
59 */
60$mg_hrefs = $xmltree->GetPath('/*/DAV::href');
61$href_in = '';
62$params = array();
63foreach( $mg_hrefs AS $k => $v ) {
64  /**
65   * We need this to work if they specified a relative *or* a full path, so we strip off
66   * anything up to the matching request->path (which will include any http...) and then
67   * put the $bound_from prefix back on.
68   */
69  $href = $bound_from . preg_replace( "{^.*\E$request->path\Q}", '', rawurldecode($v->GetContent()) );
70  dbg_error_log("REPORT", "Reporting on href '%s'", $href );
71  $href_in .= ($href_in == '' ? '' : ', ');
72  $href_in .= ':href'.$k;
73  $params[':href'.$k] = $href;
74}
75
76//$where = " WHERE caldav_data.collection_id = " . $collection->resource_id();
77//$where .= "AND caldav_data.dav_name IN ( $href_in ) ";
78$path = preg_replace("/\/|addressbook/","",$request->path);
79//$filtro = "uid=".$path;
80//$atributos = array("uidNumber");
81//$uidnumber = ldapDrivers::requestAtributo($filtro, $atributos);
82//if ($uidnumber == false) {
83//                 dbg_error_log( "REPORT", "Responding with report error:  usuario não encontrado no diretorio");
84//                 continue;
85//}
86//$nome = $uidnumber['uidNumber'];
87$nome = $collection->GetProperty('user_no');
88if ( $mode == 'caldav' ) {
89  if ( $collection->Privileges() != privilege_to_bits('DAV::all') ) {
90    $where .= "AND (calendar_item.class != 'PRIVATE' OR calendar_item.class IS NULL) ";
91  }
92
93  if ( isset($c->hide_TODO) && $c->hide_TODO && ! $collection->Privileges() == privilege_to_bits('all') ) {
94    $where .= "AND caldav_data.caldav_type NOT IN ('VTODO') ";
95  }
96
97/******************************
98***************** Melhorar as consultas
99*/
100    $sqlp = "SELECT cal_id FROM phpgw_cal_user WHERE  cal_type = 'u' AND cal_status = 'A' AND cal_login = :nome";
101    $qryp = new AwlQuery( $sqlp, array( ':nome' => $nome) );
102    if ( $qryp->Exec("REPORT-MULTIGET",__LINE__,__FILE__) && $qryp->rows() > 0 ) {
103       while( $part = $qryp->Fetch() ) {
104           $sql = "SELECT * FROM phpgw_cal WHERE cal_id = $part->cal_id AND cal_type = 'E'";
105           $qry = new AwlQuery( $sql);
106           if ( $qry->Exec("REPORT-MULTIGET",__LINE__,__FILE__) && $qry->rows() > 0 ) {
107              while( $calendar_object = $qry->Fetch() ) {
108                if ( $bound_from != $collection->dav_name() ) {
109                      $calendar_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $calendar_object->dav_name);
110                    }
111                if ( $need_expansion ) {
112                   $vResource = new vComponent($calendar_object->caldav_data);
113                   $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end);
114                   $calendar_object->caldav_data = $expanded->Render();
115                     }
116                  $responses[] = calendar_to_xml( $properties, $calendar_object );   
117              }
118           }
119            $sql = "SELECT * FROM phpgw_cal INNER JOIN phpgw_cal_repeats USING(cal_id) WHERE cal_id = $part->cal_id";
120            $qry = new AwlQuery( $sql);
121            if ( $qry->Exec("PROPFIND",__LINE__,__FILE__) && $qry->rows() > 0 ) {
122                  while( $calendar_object = $qry->Fetch() ) {
123                    if ( $bound_from != $collection->dav_name() ) {
124                      $calendar_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $calendar_object->dav_name);
125                    }
126                    if ( $need_expansion ) {
127                       $vResource = new vComponent($calendar_object->caldav_data);
128                        $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end);
129                       $calendar_object->caldav_data = $expanded->Render();
130                     }
131                    $responses[] = calendar_to_xml( $properties, $calendar_object );
132               }
133           }
134      }
135   }
136
137
138
139   
140 
141  //$sql = 'SELECT caldav_data.*,calendar_item.* FROM caldav_data
142  //                LEFT JOIN calendar_item USING(dav_id, user_no, dav_name, collection_id)
143  //                LEFT JOIN collection USING(collection_id)';
144}
145else if ( $mode == 'carddav' ) {
146
147        $sql = "SELECT * FROM phpgw_cc_contact WHERE  id_owner= :nome";
148           $qry = new AwlQuery( $sql,array(':nome' => $nome));
149           if ( $qry->Exec("REPORT-MULTIGET",__LINE__,__FILE__) && $qry->rows() > 0 ) {
150              while( $contacts_object = $qry->Fetch() ) {
151                if ( $bound_from != $collection->dav_name() ) {
152                      $contacts_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $contacts_object->dav_name);
153                    }
154                if ( $need_expansion ) {
155                   $vResource = new vComponent($contacts_object->caldav_data);
156                   $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end);
157                   $contacts_object->caldav_data = $expanded->Render();
158                     }
159
160                  $responses[] = contacts_to_xml( $properties, $contacts_object);
161
162              }
163           }
164   
165
166  //$sql = 'SELECT caldav_data.*, addressbook_resource.* FROM caldav_data
167  //                LEFT JOIN addressbook_resource USING(dav_id)
168  //                LEFT JOIN collection USING(collection_id)';
169}
170
171//if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $where .= " ORDER BY caldav_data.dav_id";
172//$qry = new AwlQuery( $sql . $where, $params );
173//if ( $qry->Exec('REPORT',__LINE__,__FILE__) && $qry->rows() > 0 ) {
174//  while( $dav_object = $qry->Fetch() ) {
175//    if ( $bound_from != $collection->dav_name() ) {
176//      $dav_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $dav_object->dav_name);
177//    }
178//    if ( $need_expansion ) {
179//      $vResource = new vComponent($dav_object->caldav_data);
180//      $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end);
181//      $dav_object->caldav_data = $expanded->Render();
182//    }
183//    $responses[] = component_to_xml( $properties, $dav_object );
184//  }
185//}
186
187$multistatus = new XMLElement( "multistatus", $responses, $reply->GetXmlNsArray() );
188
189$request->XMLResponse( 207, $multistatus );
Note: See TracBrowser for help on using the repository browser.