GetElements('urn:ietf:params:xml:ns:caldav:expand'); if ( isset($expansion[0]) ) { $need_expansion = true; $expand_range_start = $expansion[0]->GetAttribute('start'); $expand_range_end = $expansion[0]->GetAttribute('end'); if ( isset($expand_range_start) ) $expand_range_start = new RepeatRuleDateTime($expand_range_start); if ( isset($expand_range_end) ) $expand_range_end = new RepeatRuleDateTime($expand_range_end); } } /** * Build the array of properties to include in the report output */ $proptype = $qry_content[0]->GetTag(); $properties = array(); switch( $proptype ) { case 'DAV::prop': $qry_props = $xmltree->GetPath('/*/'.$proptype.'/*'); foreach( $qry_content[0]->GetElements() AS $k => $v ) { $propertyname = preg_replace( '/^.*:/', '', $v->GetTag() ); $properties[$propertyname] = 1; if ( $v->GetTag() == 'urn:ietf:params:xml:ns:caldav:calendar-data' ) check_for_expansion($v); } break; case 'DAV::allprop': $properties['allprop'] = 1; if ( $qry_content[1]->GetTag() == 'DAV::include' ) { foreach( $qry_content[1]->GetElements() AS $k => $v ) { $include_properties[] = $v->GetTag(); /** $include_properties is referenced in DAVResource where allprop is expanded */ if ( $v->GetTag() == 'urn:ietf:params:xml:ns:caldav:calendar-data' ) check_for_expansion($v); } } break; default: $propertyname = preg_replace( '/^.*:/', '', $proptype ); $properties[$propertyname] = 1; } $collection = new DAVResource($request->path); $bound_from = $collection->bound_from(); /** * Build the href list for the IN ( href, href, href, ... ) clause. */ $mg_hrefs = $xmltree->GetPath('/*/DAV::href'); $href_in = ''; $params = array(); foreach( $mg_hrefs AS $k => $v ) { /** * We need this to work if they specified a relative *or* a full path, so we strip off * anything up to the matching request->path (which will include any http...) and then * put the $bound_from prefix back on. */ $href = $bound_from . preg_replace( "{^.*\E$request->path\Q}", '', rawurldecode($v->GetContent()) ); dbg_error_log("REPORT", "Reporting on href '%s'", $href ); $href_in .= ($href_in == '' ? '' : ', '); $href_in .= ':href'.$k; $params[':href'.$k] = $href; } //$where = " WHERE caldav_data.collection_id = " . $collection->resource_id(); //$where .= "AND caldav_data.dav_name IN ( $href_in ) "; $path = preg_replace("/\/|addressbook/","",$request->path); //$filtro = "uid=".$path; //$atributos = array("uidNumber"); //$uidnumber = ldapDrivers::requestAtributo($filtro, $atributos); //if ($uidnumber == false) { // dbg_error_log( "REPORT", "Responding with report error: usuario não encontrado no diretorio"); // continue; //} //$nome = $uidnumber['uidNumber']; $nome = $collection->GetProperty('user_no'); if ( $mode == 'caldav' ) { if ( $collection->Privileges() != privilege_to_bits('DAV::all') ) { $where .= "AND (calendar_item.class != 'PRIVATE' OR calendar_item.class IS NULL) "; } if ( isset($c->hide_TODO) && $c->hide_TODO && ! $collection->Privileges() == privilege_to_bits('all') ) { $where .= "AND caldav_data.caldav_type NOT IN ('VTODO') "; } /****************************** ***************** Melhorar as consultas */ $sqlp = "SELECT cal_id FROM phpgw_cal_user WHERE cal_type = 'u' AND cal_status = 'A' AND cal_login = :nome"; $qryp = new AwlQuery( $sqlp, array( ':nome' => $nome) ); if ( $qryp->Exec("REPORT-MULTIGET",__LINE__,__FILE__) && $qryp->rows() > 0 ) { while( $part = $qryp->Fetch() ) { $sql = "SELECT * FROM phpgw_cal WHERE cal_id = $part->cal_id AND cal_type = 'E'"; $qry = new AwlQuery( $sql); if ( $qry->Exec("REPORT-MULTIGET",__LINE__,__FILE__) && $qry->rows() > 0 ) { while( $calendar_object = $qry->Fetch() ) { if ( $bound_from != $collection->dav_name() ) { $calendar_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $calendar_object->dav_name); } if ( $need_expansion ) { $vResource = new vComponent($calendar_object->caldav_data); $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end); $calendar_object->caldav_data = $expanded->Render(); } $responses[] = calendar_to_xml( $properties, $calendar_object ); } } $sql = "SELECT * FROM phpgw_cal INNER JOIN phpgw_cal_repeats USING(cal_id) WHERE cal_id = $part->cal_id"; $qry = new AwlQuery( $sql); if ( $qry->Exec("PROPFIND",__LINE__,__FILE__) && $qry->rows() > 0 ) { while( $calendar_object = $qry->Fetch() ) { if ( $bound_from != $collection->dav_name() ) { $calendar_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $calendar_object->dav_name); } if ( $need_expansion ) { $vResource = new vComponent($calendar_object->caldav_data); $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end); $calendar_object->caldav_data = $expanded->Render(); } $responses[] = calendar_to_xml( $properties, $calendar_object ); } } } } //$sql = 'SELECT caldav_data.*,calendar_item.* FROM caldav_data // LEFT JOIN calendar_item USING(dav_id, user_no, dav_name, collection_id) // LEFT JOIN collection USING(collection_id)'; } else if ( $mode == 'carddav' ) { $sql = "SELECT * FROM phpgw_cc_contact WHERE id_owner= :nome"; $qry = new AwlQuery( $sql,array(':nome' => $nome)); if ( $qry->Exec("REPORT-MULTIGET",__LINE__,__FILE__) && $qry->rows() > 0 ) { while( $contacts_object = $qry->Fetch() ) { if ( $bound_from != $collection->dav_name() ) { $contacts_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $contacts_object->dav_name); } if ( $need_expansion ) { $vResource = new vComponent($contacts_object->caldav_data); $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end); $contacts_object->caldav_data = $expanded->Render(); } $responses[] = contacts_to_xml( $properties, $contacts_object); } } //$sql = 'SELECT caldav_data.*, addressbook_resource.* FROM caldav_data // LEFT JOIN addressbook_resource USING(dav_id) // LEFT JOIN collection USING(collection_id)'; } //if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $where .= " ORDER BY caldav_data.dav_id"; //$qry = new AwlQuery( $sql . $where, $params ); //if ( $qry->Exec('REPORT',__LINE__,__FILE__) && $qry->rows() > 0 ) { // while( $dav_object = $qry->Fetch() ) { // if ( $bound_from != $collection->dav_name() ) { // $dav_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $dav_object->dav_name); // } // if ( $need_expansion ) { // $vResource = new vComponent($dav_object->caldav_data); // $expanded = expand_event_instances($vResource, $expand_range_start, $expand_range_end); // $dav_object->caldav_data = $expanded->Render(); // } // $responses[] = component_to_xml( $properties, $dav_object ); // } //} $multistatus = new XMLElement( "multistatus", $responses, $reply->GetXmlNsArray() ); $request->XMLResponse( 207, $multistatus );