[3733] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * CalDAV Server - handle REPORT method |
---|
| 4 | * |
---|
| 5 | * @package davical |
---|
| 6 | * @subpackage caldav |
---|
| 7 | * @author Andrew McMillan <andrew@morphoss.com> |
---|
| 8 | * @copyright Catalyst .Net Ltd, Morphoss Ltd |
---|
| 9 | * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 |
---|
| 10 | */ |
---|
| 11 | dbg_error_log("REPORT", "method handler"); |
---|
| 12 | |
---|
| 13 | require_once("XMLDocument.php"); |
---|
| 14 | require_once('DAVResource.php'); |
---|
| 15 | include_once("drivers_ldap.php"); |
---|
| 16 | require_once('RRule-v2.php'); |
---|
| 17 | |
---|
| 18 | if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || (isset($c->dbg['report']) && $c->dbg['report'])) ) { |
---|
| 19 | $fh = fopen('/tmp/REPORT.txt','w'); |
---|
| 20 | if ( $fh ) { |
---|
| 21 | fwrite($fh,$request->raw_post); |
---|
| 22 | fclose($fh); |
---|
| 23 | } |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | if ( !isset($request->xml_tags) ) { |
---|
| 27 | $request->DoResponse( 406, translate("REPORT body contains no XML data!") ); |
---|
| 28 | } |
---|
| 29 | $position = 0; |
---|
| 30 | $xmltree = BuildXMLTree( $request->xml_tags, $position); |
---|
| 31 | if ( !is_object($xmltree) ) { |
---|
| 32 | $request->DoResponse( 406, translate("REPORT body is not valid XML data!") ); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | $target = new DAVResource($request->path); |
---|
| 36 | $target->NeedPrivilege( array('DAV::read', 'urn:ietf:params:xml:ns:caldav:read-free-busy'), true ); // They may have either |
---|
| 37 | |
---|
| 38 | if ( $xmltree->GetTag() != 'DAV::principal-property-search' |
---|
| 39 | && $xmltree->GetTag() != 'DAV::principal-property-search-set' ) { |
---|
| 40 | $target->NeedPrivilege( array('DAV::read', 'urn:ietf:params:xml:ns:caldav:read-free-busy'), true ); // They may have either |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | require_once("iCalendar.php"); |
---|
| 44 | |
---|
| 45 | $reportnum = -1; |
---|
| 46 | $report = array(); |
---|
| 47 | $denied = array(); |
---|
| 48 | $unsupported = array(); |
---|
| 49 | if ( isset($prop_filter) ) unset($prop_filter); |
---|
| 50 | |
---|
| 51 | if ( $xmltree->GetTag() == 'urn:ietf:params:xml:ns:caldav:free-busy-query' ) { |
---|
| 52 | include("caldav-REPORT-freebusy.php"); |
---|
| 53 | exit; // Not that the above include should return anyway |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | $reply = new XMLDocument( array( "DAV:" => "" ) ); |
---|
| 57 | switch( $xmltree->GetTag() ) { |
---|
| 58 | case 'DAV::principal-property-search': |
---|
| 59 | include("caldav-REPORT-principal.php"); |
---|
| 60 | exit; // Not that it should return anyway. |
---|
| 61 | case 'DAV::principal-search-property-set': |
---|
| 62 | include("caldav-REPORT-pps-set.php"); |
---|
| 63 | exit; // Not that it should return anyway. |
---|
| 64 | case 'DAV::sync-collection': |
---|
| 65 | include("caldav-REPORT-sync-collection.php"); |
---|
| 66 | exit; // Not that it should return anyway. |
---|
| 67 | case 'DAV::expand-property': |
---|
| 68 | include("caldav-REPORT-expand-property.php"); |
---|
| 69 | exit; // Not that it should return anyway. |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * Return XML for a single calendar (or todo) entry from the DB |
---|
| 75 | * |
---|
| 76 | * @param array $properties The properties for this calendar |
---|
| 77 | * @param string $item The calendar data for this calendar |
---|
| 78 | * |
---|
| 79 | * @return string An XML document which is the response for the calendar |
---|
| 80 | ******************************** Função Customizada para o Expresso ******************** |
---|
| 81 | // |
---|
| 82 | //function calendar_to_xml( $properties, $item ) { |
---|
| 83 | // global $session, $c, $request, $reply; |
---|
| 84 | // |
---|
| 85 | // dbg_error_log("REPORT","Building XML Response for item '%s'", $item->dav_name ); |
---|
| 86 | // |
---|
| 87 | // $denied = array(); |
---|
| 88 | // $caldav_data = $item->caldav_data; |
---|
| 89 | // $displayname = $item->summary; |
---|
| 90 | // if ( isset($properties['calendar-data']) || isset($properties['displayname']) ) { |
---|
| 91 | // if ( !$request->AllowedTo('all') && $session->user_no != $item->user_no ){ |
---|
| 92 | // // the user is not admin / owner of this calendarlooking at his calendar and can not admin the other cal |
---|
| 93 | // /** @todo We should examine the ORGANIZER and ATTENDEE fields in the event. If this person is there then they should see this */ |
---|
| 94 | // if ( $item->class == 'CONFIDENTIAL' || !$request->AllowedTo('read') ) { |
---|
| 95 | // $ical = new iCalComponent( $caldav_data ); |
---|
| 96 | // $resources = $ical->GetComponents('VTIMEZONE',false); |
---|
| 97 | // $first = $resources[0]; |
---|
| 98 | // |
---|
| 99 | // // if the event is confidential we fake one that just says "Busy" |
---|
| 100 | // $confidential = new iCalComponent(); |
---|
| 101 | // $confidential->SetType($first->GetType()); |
---|
| 102 | // $confidential->AddProperty( 'SUMMARY', translate('Busy') ); |
---|
| 103 | // $confidential->AddProperty( 'CLASS', 'CONFIDENTIAL' ); |
---|
| 104 | // $confidential->SetProperties( $first->GetProperties('DTSTART'), 'DTSTART' ); |
---|
| 105 | // $confidential->SetProperties( $first->GetProperties('RRULE'), 'RRULE' ); |
---|
| 106 | // $confidential->SetProperties( $first->GetProperties('DURATION'), 'DURATION' ); |
---|
| 107 | // $confidential->SetProperties( $first->GetProperties('DTEND'), 'DTEND' ); |
---|
| 108 | // $confidential->SetProperties( $first->GetProperties('UID'), 'UID' ); |
---|
| 109 | // $ical->SetComponents(array($confidential),$confidential->GetType()); |
---|
| 110 | // |
---|
| 111 | // $caldav_data = $ical->Render(); |
---|
| 112 | // $displayname = translate('Busy'); |
---|
| 113 | // } |
---|
| 114 | // } |
---|
| 115 | // } |
---|
| 116 | // |
---|
| 117 | // $url = ConstructURL($item->dav_name); |
---|
| 118 | // |
---|
| 119 | // $prop = new XMLElement("prop"); |
---|
| 120 | // foreach( $properties AS $k => $v ) { |
---|
| 121 | // switch( $k ) { |
---|
| 122 | // case 'getcontentlength': |
---|
| 123 | // $contentlength = strlen($caldav_data); |
---|
| 124 | // $prop->NewElement($k, $contentlength ); |
---|
| 125 | // break; |
---|
| 126 | // case 'calendar-data': |
---|
| 127 | // $reply->CalDAVElement($prop, $k, $caldav_data ); |
---|
| 128 | // break; |
---|
| 129 | // case 'getcontenttype': |
---|
| 130 | // $prop->NewElement($k, "text/calendar" ); |
---|
| 131 | // break; |
---|
| 132 | // case 'current-user-principal': |
---|
| 133 | // $prop->NewElement("current-user-principal", $request->current_user_principal_xml); |
---|
| 134 | // break; |
---|
| 135 | // case 'displayname': |
---|
| 136 | // $prop->NewElement($k, $displayname ); |
---|
| 137 | // break; |
---|
| 138 | // case 'resourcetype': |
---|
| 139 | // $prop->NewElement($k); // Just an empty resourcetype for a non-collection. |
---|
| 140 | // break; |
---|
| 141 | // case 'getetag': |
---|
| 142 | // $prop->NewElement($k, '"'.$item->dav_etag.'"' ); |
---|
| 143 | // break; |
---|
| 144 | // case '"current-user-privilege-set"': |
---|
| 145 | // $prop->NewElement($k, privileges($request->permissions) ); |
---|
| 146 | // break; |
---|
| 147 | // case 'SOME-DENIED-PROPERTY': /** indicating the style for future expansion */ |
---|
| 148 | // $denied[] = $v; |
---|
| 149 | // break; |
---|
| 150 | // default: |
---|
| 151 | // dbg_error_log( 'REPORT', "Request for unsupported property '%s' of calendar item.", $v ); |
---|
| 152 | // $unsupported[] = $v; |
---|
| 153 | // } |
---|
| 154 | // } |
---|
| 155 | // $status = new XMLElement("status", "HTTP/1.1 200 OK" ); |
---|
| 156 | // |
---|
| 157 | // $propstat = new XMLElement( "propstat", array( $prop, $status) ); |
---|
| 158 | // $href = new XMLElement("href", $url ); |
---|
| 159 | // $elements = array($href,$propstat); |
---|
| 160 | // |
---|
| 161 | // if ( count($denied) > 0 ) { |
---|
| 162 | // $status = new XMLElement("status", "HTTP/1.1 403 Forbidden" ); |
---|
| 163 | // $noprop = new XMLElement("prop"); |
---|
| 164 | // foreach( $denied AS $k => $v ) { |
---|
| 165 | // $noprop->NewElement( strtolower($v) ); |
---|
| 166 | // } |
---|
| 167 | // $elements[] = new XMLElement( "propstat", array( $noprop, $status) ); |
---|
| 168 | // } |
---|
| 169 | // |
---|
| 170 | // $response = new XMLElement( "response", $elements ); |
---|
| 171 | // |
---|
| 172 | // return $response; |
---|
| 173 | //} |
---|
| 174 | // |
---|
| 175 | //*/ |
---|
| 176 | /************* Função nova Customizada ************* |
---|
| 177 | */ |
---|
| 178 | function contacts_to_xml( $properties, $item) |
---|
| 179 | { |
---|
| 180 | global $session, $c, $request, $reply; |
---|
| 181 | $path = preg_replace("/^\//","",$request->path); |
---|
| 182 | //$filtro = "uid=".$path; |
---|
| 183 | //$atributos = array("uidNumber"); |
---|
| 184 | //$uidnumber = ldapDrivers::requestAtributo($filtro, $atributos); |
---|
| 185 | //if ($uidnumber == false) { |
---|
| 186 | // dbg_error_log( "REPORT", "Responding with report error: usuario não encontrado no diretorio"); |
---|
| 187 | // $request->DoResponse( 501, 'Database error'); |
---|
| 188 | //} |
---|
| 189 | // $nome = $uidnumber['uidNumber']; |
---|
| 190 | // $nome = $target->GetProperty('user_no'); |
---|
| 191 | $nome = $item->id_owner; |
---|
| 192 | $mails = array(); |
---|
| 193 | $phones = array(); |
---|
| 194 | unset($VCARD); |
---|
| 195 | $VCARD = "UID:$item->id_contact@$nome\n\n"; |
---|
| 196 | |
---|
| 197 | /*************************** |
---|
| 198 | ********* DADOS DEFAULT **** |
---|
| 199 | ****************************/ |
---|
| 200 | $VCARD .= "N:$item->family_names;$item->given_names\n\n"; |
---|
| 201 | $VCARD .= "FN:$item->names_ordered\n\n"; |
---|
| 202 | if ( isset($item->alias)) $VCARD .= "NICKNAME:$item->alias\n\n"; |
---|
| 203 | if ( isset($item->photo)) $VCARD .= "PHOTO:ENCODING=b;TYPE=JPEG:$item->photo\n\n"; |
---|
| 204 | if ( isset($item->birthdate)) $VCARD .= "BDAY:$item->birthdate\n\n"; |
---|
| 205 | if ( isset($item->notes)) $VCARD .= "NOTE:$item->notes\n\n"; |
---|
| 206 | /************************** |
---|
| 207 | ********** EMAIL & TEL **** |
---|
| 208 | ***************************/ |
---|
| 209 | $qry = new AwlQuery("SELECT * FROM phpgw_cc_contact_conns inner join phpgw_cc_connections using(id_connection) WHERE phpgw_cc_contact_conns.id_contact= :id", array(':id' => $item->id_contact)); |
---|
| 210 | if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows() > 0 ){ |
---|
| 211 | while( $email_tel = $qry->Fetch() ) { |
---|
| 212 | if ( $email_tel->id_typeof_contact_connection == 1) |
---|
| 213 | { |
---|
| 214 | if ( $email_tel->connection_name == 'Principal' ) |
---|
| 215 | $type=WORK; |
---|
| 216 | else |
---|
| 217 | $type=HOME; |
---|
| 218 | $VCARD .= "EMAIL;TYPE=$type:$email_tel->connection_value\n\n"; |
---|
| 219 | } |
---|
| 220 | else if ( $email_tel->id_typeof_contact_connection == 2) |
---|
| 221 | { |
---|
| 222 | if ( $email_tel->connection_name == 'Trabalho' ) |
---|
| 223 | $type=WORK; |
---|
| 224 | else if ( $email_tel->connection_name == 'Casa' ) |
---|
| 225 | $type=HOME; |
---|
| 226 | else if ( $email_tel->connection_name == 'Celular' ) |
---|
| 227 | $type=CELL; |
---|
| 228 | else if ( $email_tel->connection_name == 'Fax' ) |
---|
| 229 | $type=FAX; |
---|
| 230 | |
---|
| 231 | $VCARD .= "TEL;TYPE=$type:$email_tel->connection_value\n\n"; |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | /************************** |
---|
| 236 | ************ ADDR ******** |
---|
| 237 | **************************/ |
---|
| 238 | $qry = new AwlQuery("SELECT * FROM phpgw_cc_contact_addrs inner join phpgw_cc_addresses using(id_address) WHERE phpgw_cc_contact_addrs.id_contact= :id", array(':id' => $item->id_contact)); |
---|
| 239 | if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows() > 0 ){ |
---|
| 240 | while( $addr = $qry->Fetch() ) { |
---|
| 241 | if ( $addr->id_typeof_contact_address == 1) |
---|
| 242 | { |
---|
| 243 | $type=HOME; |
---|
| 244 | $VCARD .= "ADR;TYPE=$type:;;$addr->address1;$addr->city;$addr->state;$addr->postal_code;$addr->id_contry\n\n"; |
---|
| 245 | } |
---|
| 246 | else if ( $addr->id_typeof_contact_address == 2) |
---|
| 247 | { |
---|
| 248 | $type=WORK; |
---|
| 249 | $VCARD .= "ADR;TYPE=$type:;;$addr->address1;$addr->city;$addr->state;$addr->postal_code;$addr->id_contry\n\n"; |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | /********** PUBLIC KEY ******** |
---|
| 256 | *****************************/ |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | dbg_error_log("REPORT","Building XML Response for item '%s' usuario '%s'", $item->id_contact,$nome ); |
---|
| 262 | $response = "BEGIN:VCARD\n\nVERSION:3.0\n\nPRODID:-//Inverse inc.//SOGo Connector 1.0//EN\n\n"; |
---|
| 263 | $response .= "$VCARD"; |
---|
| 264 | $response .= "END:VCARD\n\n"; |
---|
| 265 | $caldav_data = $response; |
---|
| 266 | |
---|
| 267 | $dav_nam = "{$item->id_contact}@{$item->id_owner}"; |
---|
| 268 | $dav_etag_nam = md5($item->id_contact.$item->id_owner.$item->last_update); |
---|
| 269 | //$dav_name = "{$item->id_contact}@{$item->id_owner}"; |
---|
| 270 | $dav_name = sprintf('/%s/%s@%s.vcf',$path,$item->id_contact,$item->id_owner); |
---|
| 271 | $url = ConstructURL($dav_name); |
---|
| 272 | |
---|
| 273 | $prop = new XMLElement("prop"); |
---|
| 274 | foreach( $properties AS $k => $v ) { |
---|
| 275 | switch( $k ) { |
---|
| 276 | case 'getcontentlength': |
---|
| 277 | $contentlength = strlen($caldav_data); |
---|
| 278 | $prop->NewElement($k, $contentlength ); |
---|
| 279 | break; |
---|
| 280 | case 'address-data': |
---|
| 281 | $reply->CardDAVElement($prop, $k, $caldav_data ); |
---|
| 282 | break; |
---|
| 283 | case 'getcontenttype': |
---|
| 284 | $prop->NewElement($k, "text/x-vcard" ); |
---|
| 285 | break; |
---|
| 286 | case 'current-user-principal': |
---|
| 287 | $prop->NewElement("current-user-principal", $request->current_user_principal_xml); |
---|
| 288 | break; |
---|
| 289 | case 'displayname': |
---|
| 290 | $prop->NewElement($k, $displayname ); |
---|
| 291 | break; |
---|
| 292 | case 'resourcetype': |
---|
| 293 | $prop->NewElement($k); // Just an empty resourcetype for a non-collection. |
---|
| 294 | break; |
---|
| 295 | case 'getetag': |
---|
| 296 | $prop->NewElement($k, '"'.$dav_etag_nam.'"' ); |
---|
| 297 | break; |
---|
| 298 | case '"current-user-privilege-set"': |
---|
| 299 | $prop->NewElement($k, privileges($request->permissions) ); |
---|
| 300 | break; |
---|
| 301 | case 'SOME-DENIED-PROPERTY': /** indicating the style for future expansion */ |
---|
| 302 | $denied[] = $v; |
---|
| 303 | break; |
---|
| 304 | default: |
---|
| 305 | dbg_error_log( 'REPORT', "Request for unsupported property '%s' of calendar item.", $v ); |
---|
| 306 | $unsupported[] = $v; |
---|
| 307 | } |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | $status = new XMLElement("status", "HTTP/1.1 200 OK" ); |
---|
| 311 | $propstat = new XMLElement( "propstat", array( $prop, $status) ); |
---|
| 312 | $href = new XMLElement("href", $url ); |
---|
| 313 | $elements = array($href,$propstat); |
---|
| 314 | if ( count($denied) > 0 ) { |
---|
| 315 | $status = new XMLElement("status", "HTTP/1.1 403 Forbidden" ); |
---|
| 316 | $noprop = new XMLElement("prop"); |
---|
| 317 | foreach( $denied AS $k => $v ) { |
---|
| 318 | $noprop->NewElement( strtolower($v) ); |
---|
| 319 | } |
---|
| 320 | $elements[] = new XMLElement( "propstat", array( $noprop, $status) ); |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | |
---|
| 324 | $response = new XMLElement( "response", $elements ); |
---|
| 325 | return $response; |
---|
| 326 | |
---|
| 327 | } |
---|
| 328 | function calendar_to_xml( $properties, $item ) { |
---|
| 329 | global $c, $request, $reply; |
---|
| 330 | $path = preg_replace("/^\//","",$request->path); |
---|
| 331 | //$filtro = "uid=".$path; |
---|
| 332 | //$atributos = array("uidNumber"); |
---|
| 333 | //$uidnumber = ldapDrivers::requestAtributo($filtro, $atributos); |
---|
| 334 | //if ($uidnumber == false) { |
---|
| 335 | // dbg_error_log( "REPORT", "Responding with report error: usuario não encontrado no diretorio"); |
---|
| 336 | // $request->DoResponse( 501, 'Database error'); |
---|
| 337 | //} |
---|
| 338 | //$nome = $uidnumber['uidNumber']; |
---|
| 339 | $nome = $item->owner; |
---|
| 340 | dbg_error_log("REPORT","Building XML Response for item '%s' usuario '%s'", $item->cal_id,$nome ); |
---|
| 341 | $mdate = $item->mdatetime; |
---|
| 342 | $calid = $item->cal_id; |
---|
| 343 | $modify_data = dataSegundosParaT($mdate,1); |
---|
| 344 | $date = $item->datetime; |
---|
| 345 | $create_data = dataSegundosParaT($date,1); |
---|
| 346 | $start_data = dataSegundosParaT($date); |
---|
| 347 | $edate = $item->edatetime; |
---|
| 348 | $end_data = dataSegundosParaT($edate); |
---|
| 349 | $titulo = utf8_encode($item->title); |
---|
| 350 | $local = utf8_encode($item->location); |
---|
| 351 | if($local != "" ) |
---|
| 352 | $local = "\n\nLOCATION:$local"; |
---|
| 353 | else |
---|
| 354 | $local = ""; |
---|
| 355 | $descricao = utf8_encode($item->description); |
---|
| 356 | if($descricao != "") |
---|
| 357 | $descricao = "\n\nDESCRIPTION:".preg_replace('/\r\n/', '\\n', $descricao); |
---|
| 358 | else |
---|
| 359 | $descricao = ""; |
---|
| 360 | $moz=""; |
---|
| 361 | |
---|
| 362 | /******************* |
---|
| 363 | **** Sequencia **** |
---|
| 364 | ******************/ |
---|
| 365 | |
---|
| 366 | $sequec = "\n\nSEQUENCE:0"; |
---|
| 367 | |
---|
| 368 | /********* |
---|
| 369 | *ALARMES* |
---|
| 370 | *********/ |
---|
| 371 | $alarme_id = $item->cal_id; |
---|
| 372 | $alarme = new AwlQuery( "SELECT * FROM phpgw_async WHERE id = :alarme_id", array(':alarme_id' => 'cal:'.$alarme_id.':0')); |
---|
| 373 | if ( $alarme->Exec("REPORT",__LINE__,__FILE__) && $alarme->rows() > 0 ){ |
---|
| 374 | $nao_alarme = new AwlQuery( "SELECT * FROM phpgw_cal_extra WHERE cal_id = :alarme_id AND (cal_extra_name = 'X-MOZ-LASTACK' OR cal_extra_name = :X-MOZ-LASTACK-PART)",array( ':alarme_id' => $alarme_id, ':X-MOZ-LASTACK-PART' => 'X-MOZ-LASTACK-PART-'.$nome)); |
---|
| 375 | if ( $nao_alarme->Exec("REPORT",__LINE__,__FILE__) && $nao_alarme->rows() == 1 ){ |
---|
| 376 | $alarmeqryno = $nao_alarme->Fetch(); |
---|
| 377 | $moz = "\n\nX-MOZ-LASTACK:$alarmeqryno->cal_extra_value"; |
---|
| 378 | $moz .= "\n\nX-MOZ-GENERATION:1"; |
---|
| 379 | $modify_data = "$alarmeqryno->cal_extra_value"; |
---|
| 380 | $adiamento = new AwlQuery( "SELECT * FROM phpgw_cal_extra WHERE cal_id = :alarme_id AND cal_extra_name LIKE 'X-MOZ-SNOOZE%'", array( ':alarme_id' => $alarme_id)); |
---|
| 381 | if ( $adiamento->Exec("REPORT",__LINE__,__FILE__) && $adiamento->rows() > 0 ){ |
---|
| 382 | $admno = $adiamento->Fetch(); |
---|
| 383 | $moz .= "\n\n$admno->cal_extra_name:$admno->cal_extra_value"; |
---|
| 384 | } |
---|
| 385 | dbg_error_log("REPORT","CANCELAR ALARME '%s' ", $moz); |
---|
| 386 | |
---|
| 387 | //$deleta = new AwlQuery( "DELETE FROM phpgw_cal_extra WHERE cal_id = '$alarme_id'"); |
---|
| 388 | //$deleta->Exec("calquery",__LINE__,__FILE__); |
---|
| 389 | |
---|
| 390 | } |
---|
| 391 | else{ |
---|
| 392 | $moz=""; |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | $alarmeqry = $alarme->Fetch(); |
---|
| 396 | $tempo = split(";", $alarmeqry->data, 4); |
---|
| 397 | $tempoalarme = $alarmeqry->next;// + $mais; |
---|
| 398 | $agoranow = date_create(); |
---|
| 399 | $agora = $agoranow->format("U"); |
---|
| 400 | $segundos = split(":", $tempo[3], 2); |
---|
| 401 | if ( $tempoalarme >= $agora | $item->cal_type == 'M'){ |
---|
| 402 | if ( $segundos[1] <= 3600 ){ |
---|
| 403 | $minutos = $segundos[1]/60; |
---|
| 404 | $VALARME = "\n\nBEGIN:VALARM\n\nTRIGGER;VALUE=DURATION:-PT${minutos}M\n\nDESCRIPTION:Descrição padrão Mozilla\n\nACTION:DISPLAY\n\nEND:VALARM"; |
---|
| 405 | } |
---|
| 406 | else if ( $segundos[1] < 86400 ){ |
---|
| 407 | $hora = $segundos[1]/60/60; |
---|
| 408 | $VALARME = "\n\nBEGIN:VALARM\n\nTRIGGER;VALUE=DURATION:-PT${hora}H\n\nDESCRIPTION:Descrição padrão Mozilla\n\nACTION:DISPLAY\n\nEND:VALARM"; |
---|
| 409 | } |
---|
| 410 | else if ( $segundos[1] == 604800 ){ |
---|
| 411 | $VALARME = "\n\nBEGIN:VALARM\n\nTRIGGER;VALUE=DURATION:-P1W\n\nDESCRIPTION:Descrição padrão Mozilla\n\nACTION:DISPLAY\n\nEND:VALARM"; |
---|
| 412 | } |
---|
| 413 | else{ |
---|
| 414 | $dia = $segundos[1]/60/60/24; |
---|
| 415 | $VALARME = "\n\nBEGIN:VALARM\n\nTRIGGER;VALUE=DURATION:-P${dia}D\n\nDESCRIPTION:Descrição padrão Mozilla\n\nACTION:DISPLAY\n\nEND:VALARM"; |
---|
| 416 | } |
---|
| 417 | } |
---|
| 418 | else{ |
---|
| 419 | $VALARME =""; |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | else{ |
---|
| 423 | $VALARME =""; |
---|
| 424 | } |
---|
| 425 | //dbg_error_log("GET", "HORA LOCAL = '%s'",$VALARME); |
---|
| 426 | |
---|
| 427 | /***************************************** |
---|
| 428 | **** Ajuste para TZ funcionar ************ |
---|
| 429 | *****************************************/ |
---|
| 430 | |
---|
| 431 | //$HorarioTimeZone = new DateTimeZone(date_default_timezone_get()); |
---|
| 432 | ///$create_data = dataSegundosParaT($item->datetime); |
---|
| 433 | //$retorna = date("Ymd\THis",$create_data); |
---|
| 434 | |
---|
| 435 | |
---|
| 436 | |
---|
| 437 | |
---|
| 438 | |
---|
| 439 | |
---|
| 440 | |
---|
| 441 | |
---|
| 442 | /******************* |
---|
| 443 | *NOME DA CATEGORIA* |
---|
| 444 | *******************/ |
---|
| 445 | $categories=""; |
---|
| 446 | //if (strlen($item->category)>2){ |
---|
| 447 | if ($item->category != "" ){ |
---|
| 448 | $x= "select cat_name from phpgw_categories WHERE cat_id = :category"; |
---|
| 449 | $phpgw_query = new AwlQuery ($x, array(':category' => $item->category)); |
---|
| 450 | if ( $phpgw_query->Exec() && $phpgw_query->rows() > 0 ) { |
---|
| 451 | while( $id_cale = $phpgw_query->Fetch() ) { |
---|
| 452 | $categories = "\n\nCATEGORIES:".utf8_encode($id_cale->cat_name); |
---|
| 453 | //$categories = $id_cale->cat_name; |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | } |
---|
| 457 | $displayname = $item->title; |
---|
| 458 | |
---|
| 459 | /********** |
---|
| 460 | *CONVITES* |
---|
| 461 | **********/ |
---|
| 462 | |
---|
| 463 | $cn = array(); |
---|
| 464 | $mail = array(); |
---|
| 465 | $estado = array(); |
---|
| 466 | $members = ""; |
---|
| 467 | unset($cn); |
---|
| 468 | unset($mail); |
---|
| 469 | unset($estado); |
---|
| 470 | unset($envia_convite); |
---|
| 471 | unset($mails); |
---|
| 472 | $part2= "SELECT cal_login,cal_status FROM phpgw_cal_user WHERE cal_id = :cal_id AND cal_type = 'u'"; |
---|
| 473 | $querypart = new AwlQuery( $part2 , array(':cal_id' => $item->cal_id)); |
---|
| 474 | $i=0; |
---|
| 475 | if ( $querypart->Exec("REPORT",__LINE__,__FILE__) && $querypart->rows() > 0 ) { |
---|
| 476 | while( $id_cale = $querypart->Fetch() ) { |
---|
| 477 | if ($item->owner != $id_cale->cal_login){ |
---|
| 478 | $filtro = "uidNumber=$id_cale->cal_login" ; |
---|
| 479 | if (strlen($filtro) > 12){ |
---|
| 480 | $atributos=array("cn","mail"); |
---|
| 481 | $usuario= ldapDrivers::requestAtributo($filtro,$atributos); |
---|
| 482 | if (isset($usuario)) |
---|
| 483 | { |
---|
| 484 | $cn[$i] = $usuario['cn']; |
---|
| 485 | $mail[$i] = $usuario['mail']; |
---|
| 486 | switch ($id_cale->cal_status){ |
---|
| 487 | case 'A': |
---|
| 488 | $estado[$i] = "ACCEPTED"; |
---|
| 489 | break; |
---|
| 490 | case 'T': |
---|
| 491 | $estado[$i] = "TENTATIVE"; |
---|
| 492 | break; |
---|
| 493 | case 'U': |
---|
| 494 | $estado[$i] = "NEEDS-ACTION"; |
---|
| 495 | break; |
---|
| 496 | case 'R': |
---|
| 497 | $estado[$i] = "DECLINED"; |
---|
| 498 | break; |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | } |
---|
| 502 | } |
---|
| 503 | $i++; |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | if ( isset($item->ex_participants)) |
---|
| 508 | { |
---|
| 509 | $mails = split("[?,]",$item->ex_participants); |
---|
| 510 | } |
---|
| 511 | for ($i = 0; $i <= count($cn); $i++) { |
---|
| 512 | if (strlen($mail[$i])>5){ |
---|
| 513 | $members = $members."\nATTENDEE;RSVP=TRUE;CN=$cn[$i];PARTSTAT=$estado[$i];ROLE=REQ-PARTICIPANT:MAILTO:$mail[$i]\r"; |
---|
| 514 | } |
---|
| 515 | dbg_error_log("REPORT", "participantes interno funcao report $members"); |
---|
| 516 | } |
---|
| 517 | for ($i = 0 ; $i <= count($mails); $i++) { |
---|
| 518 | if ( $mails[$i] != '' ){ |
---|
| 519 | dbg_error_log("REPORT", "participante externo = '%s'",$mails[$i]); |
---|
| 520 | $members = $members."\nATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:MAILTO:$mails[$i]\r"; |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | $HorarioTimeZone = new DateTimeZone(date_default_timezone_get()); |
---|
| 525 | $HorarioTime = new DateTime("now", $HorarioTimeZone); |
---|
| 526 | $convite = new AwlQuery( "SELECT cal_extra_value FROM phpgw_cal_extra WHERE cal_id = :cal_id", array(':cal_id' => $item->cal_id)); |
---|
| 527 | if ( $convite->Exec("REPORT",__LINE__,__FILE__) && $convite->rows() > 0 ) { |
---|
| 528 | $xmozconvite = $convite->Fetch(); |
---|
| 529 | dbg_error_log("REPORT", "estatus de ivio de convite = '%s'",$xmozconvite->cal_extra_value); |
---|
| 530 | if ($xmozconvite->cal_extra_value == "true"){ |
---|
| 531 | $envia_convite = "X-MOZ-SEND-INVITATIONS:TRUE"; |
---|
| 532 | $convite = new AwlQuery( "DELETE FROM phpgw_cal_extra WHERE cal_id = :cal_id", array(':cal_id' => $item->cal_id)); |
---|
| 533 | $convite->Exec("REPORT",__LINE__,__FILE__); |
---|
| 534 | }else{ |
---|
| 535 | $envia_convite = "X-MOZ-SEND-INVITATIONS:FALSE"; |
---|
| 536 | } |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | |
---|
| 540 | /********* |
---|
| 541 | *PUBLICO* |
---|
| 542 | *********/ |
---|
| 543 | |
---|
| 544 | if ( $item->is_public == 0 ){ |
---|
| 545 | $classe = "PRIVATE"; |
---|
| 546 | $transp = "\n\nTRANSP:TRANSPARENT"; |
---|
| 547 | } |
---|
| 548 | else{ |
---|
| 549 | $classe = "PUBLIC"; |
---|
| 550 | $transp = "\n\nTRANSP:OPAQUE"; |
---|
| 551 | |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | /******************* |
---|
| 555 | *EVENTOS REPETIDOS* |
---|
| 556 | *******************/ |
---|
| 557 | unset($Rrule); |
---|
| 558 | if ( $item->cal_type == 'M' ){ |
---|
| 559 | /**Busca exceções de eventos repetidos, quando são criados novos eventos a partir de uma repetição |
---|
| 560 | * Para ter funcionamento igual ao expresso, escondo o evento repetido. |
---|
| 561 | * Essa função apenas adiciona o horário dessa função ao campo EXDATE. |
---|
| 562 | */ |
---|
| 563 | if ( $item->recur_exception != ''){ |
---|
| 564 | $listadeexcecao = array(); |
---|
| 565 | $listadeexcecao = explode("," , $item->recur_exception); |
---|
| 566 | foreach ($listadeexcecao AS $dataexcecao){ |
---|
| 567 | $execao = dataSegundosParaT($dataexcecao,1); |
---|
| 568 | $exe = "$exe,$execao"; |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | $exe = trim($exe, " ,"); |
---|
| 572 | $x= "select datetime from phpgw_cal where reference = :cal_id"; |
---|
| 573 | $phpgw_query = new AwlQuery ($x, array(':cal_id' => $item->cal_id)); |
---|
| 574 | if ( $phpgw_query->Exec() && $phpgw_query->rows() > 0 ) { |
---|
| 575 | while( $id_cale = $phpgw_query->Fetch() ) { |
---|
| 576 | date_default_timezone_set('UTC'); |
---|
| 577 | $data_antiga = date("Ymd\THis",$item->datetime); |
---|
| 578 | $data_nova = date("Ymd\THis",$id_cale->datetime); |
---|
| 579 | date_default_timezone_set('America/Sao_Paulo'); |
---|
| 580 | $data_n = new DateTime($data_nova); |
---|
| 581 | $data_a = new DateTime($data_antiga); |
---|
| 582 | if ( $data_n->getOffset() > $data_a->getOffset() ) |
---|
| 583 | { |
---|
| 584 | $dias = $data_n->format('z') - $data_a->format('z'); |
---|
| 585 | $dias = $item->datetime + ($dias*86400) - 3600; |
---|
| 586 | $data2 = dataSegundosParaT($dias,1); |
---|
| 587 | $exe = $exe . ",". $data2; |
---|
| 588 | |
---|
| 589 | } |
---|
| 590 | elseif ( $data_n->getOffset() < $data_a->getOffset() ) |
---|
| 591 | { |
---|
| 592 | $dias = $data_n->format('z') - $data_a->format('z'); |
---|
| 593 | $dias = $item->datetime + ($dias*86400) + 3600; |
---|
| 594 | $data2 = dataSegundosParaT($dias,1); |
---|
| 595 | $exe = $exe . ",". $data2; |
---|
| 596 | |
---|
| 597 | } |
---|
| 598 | else |
---|
| 599 | { |
---|
| 600 | $propstat = new XMLElement( "propstat", array( $prop, $status) ); |
---|
| 601 | $dias = $data_n->format('z') - $data_a->format('z'); |
---|
| 602 | $dias = $item->datetime + ($dias*86400); |
---|
| 603 | $data2 = dataSegundosParaT($dias,1); |
---|
| 604 | $exe = $exe . ",". $data2; |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | } |
---|
| 608 | } |
---|
| 609 | $exe = trim($exe, " ,"); |
---|
| 610 | $exe = "\n\nEXDATE:$exe"; |
---|
| 611 | |
---|
| 612 | if ( $item->recur_enddate != 0){ |
---|
| 613 | |
---|
| 614 | $until = dataSegundosParaT($item->recur_enddate,1); |
---|
| 615 | if (substr("$until", 9,2) == "03" ) { |
---|
| 616 | $until = dataSegundosParaT($item->recur_enddate + 86400,1); |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | $intervalo = $item->recur_interval; |
---|
| 621 | switch($item->recur_type){ |
---|
| 622 | case 1: |
---|
| 623 | $frequencia = "DAILY"; |
---|
| 624 | $Rrule = "FREQ=$frequencia"; |
---|
| 625 | if ($until != ""){ |
---|
| 626 | $Rrule .= ";UNTIL=$until"; |
---|
| 627 | } |
---|
| 628 | if ($intervalo != ""){ |
---|
| 629 | $Rrule .= ";INTERVAL=$intervalo"; |
---|
| 630 | } |
---|
| 631 | break; |
---|
| 632 | case 2: |
---|
| 633 | $frequencia = "WEEKLY"; |
---|
| 634 | $dia_sem = converte_semana($item->recur_data); |
---|
| 635 | $Rrule = "FREQ=$frequencia"; |
---|
| 636 | if ($until != ""){ |
---|
| 637 | $Rrule .= ";UNTIL=$until"; |
---|
| 638 | } |
---|
| 639 | if ($intervalo !=""){ |
---|
| 640 | $Rrule .= ";INTERVAL=$intervalo"; |
---|
| 641 | } |
---|
| 642 | if($item->recur_data != ""){ |
---|
| 643 | $Rrule .= ";$dia_sem"; |
---|
| 644 | } |
---|
| 645 | break; |
---|
| 646 | case 3: |
---|
| 647 | $frequencia = "MONTHLY"; |
---|
| 648 | $Rrule = "FREQ=$frequencia"; |
---|
| 649 | if ($until != ""){ |
---|
| 650 | $Rrule .= ";UNTIL=$until"; |
---|
| 651 | } |
---|
| 652 | if ($intervalo !=""){ |
---|
| 653 | $Rrule .= ";INTERVAL=$intervalo"; |
---|
| 654 | } |
---|
| 655 | break; |
---|
| 656 | case 4: |
---|
| 657 | $frequencia = "MONTHLY"; |
---|
| 658 | $Rrule = "FREQ=$frequencia"; |
---|
| 659 | if ($until != ""){ |
---|
| 660 | $Rrule .= ";UNTIL=$until"; |
---|
| 661 | } |
---|
| 662 | if ($intervalo !=""){ |
---|
| 663 | $Rrule .= ";INTERVAL=$intervalo"; |
---|
| 664 | } |
---|
| 665 | break; |
---|
| 666 | case 5: |
---|
| 667 | $frequencia = "YEARLY"; |
---|
| 668 | $Rrule = "FREQ=$frequencia"; |
---|
| 669 | if ($until != ""){ |
---|
| 670 | $Rrule .= ";UNTIL=$until"; |
---|
| 671 | } |
---|
| 672 | if ($intervalo !=""){ |
---|
| 673 | $Rrule .= ";INTERVAL=$intervalo"; |
---|
| 674 | } |
---|
| 675 | break; |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | } |
---|
| 679 | if(isset($Rrule)) |
---|
| 680 | $Rrule = "\n\nRRULE:$Rrule"; |
---|
| 681 | else |
---|
| 682 | $Rrule = ""; |
---|
| 683 | $response = "BEGIN:VCALENDAR\n\nPRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n\nVERSION:2.0"; |
---|
| 684 | $response .= "\n\nBEGIN:VTIMEZONE |
---|
| 685 | TZID:America/Sao_Paulo |
---|
| 686 | X-LIC-LOCATION:America/Sao_Paulo |
---|
| 687 | BEGIN:DAYLIGHT |
---|
| 688 | TZOFFSETFROM:-0300 |
---|
| 689 | TZOFFSETTO:-0200 |
---|
| 690 | TZNAME:BRST |
---|
| 691 | DTSTART:19701018T000000 |
---|
| 692 | RRULE:FREQ=YEARLY;BYDAY=3SU;BYMONTH=10 |
---|
| 693 | END:DAYLIGHT |
---|
| 694 | BEGIN:STANDARD |
---|
| 695 | TZOFFSETFROM:-0300 |
---|
| 696 | TZOFFSETTO:-0300 |
---|
| 697 | TZNAME:BRT |
---|
| 698 | DTSTART:19700215T000000 |
---|
| 699 | RRULE:FREQ=YEARLY;BYDAY=3SU;BYMONTH=2 |
---|
| 700 | END:STANDARD |
---|
| 701 | END:VTIMEZONE"; |
---|
| 702 | $response .= "\n\nBEGIN:VEVENT\n\nCREATED:$create_data\n\nLAST-MODIFIED:$modify_data\n\nDTSTAMP:$modify_data\n\nUID:$item->cal_id@$item->owner\n\n${members}\n\nSUMMARY:$titulo\n\n$recurrence_id\n\nDTSTART;TZID=America/Sao_Paulo:$start_data\n\nDTEND;TZID=America/Sao_Paulo:${end_data}${local}${categories}\r\nPRIORITY:$item->priority${descricao}${Rrule}${exe}${moz}$VALARME\n\n$envia_convite\n\nEND:VEVENT\n\n"; |
---|
| 703 | $response .= "END:VCALENDAR\n\n\n"; |
---|
| 704 | $caldav_data = $response; |
---|
| 705 | |
---|
| 706 | |
---|
| 707 | $dav_nam = "{$item->cal_id}{$item->owner}"; |
---|
| 708 | $dav_etag_nam= md5($item->cal_id.$item->owner.$item->last_update); |
---|
| 709 | //$dav_name = "{$item->cal_id}@{$item->owner}@{$item->last_update}"; |
---|
| 710 | $dav_name = sprintf('/%s/%s@%s.ics',$path,$item->cal_id,$item->owner); |
---|
| 711 | $url = ConstructURL($dav_name); |
---|
| 712 | $prop = new XMLElement("prop"); |
---|
| 713 | foreach( $properties AS $k => $v ) { |
---|
| 714 | switch( $k ) { |
---|
| 715 | case 'getcontentlength': |
---|
| 716 | $contentlength = strlen($caldav_data); |
---|
| 717 | $prop->NewElement($k, $contentlength ); |
---|
| 718 | break; |
---|
| 719 | case 'calendar-data': |
---|
| 720 | $reply->CalDAVElement($prop, $k, $caldav_data ); |
---|
| 721 | break; |
---|
| 722 | case 'getcontenttype': |
---|
| 723 | $prop->NewElement($k, "text/calendar" ); |
---|
| 724 | break; |
---|
| 725 | case 'current-user-principal': |
---|
| 726 | $prop->NewElement("current-user-principal", $request->current_user_principal_xml); |
---|
| 727 | break; |
---|
| 728 | case 'displayname': |
---|
| 729 | $prop->NewElement($k, $displayname ); |
---|
| 730 | break; |
---|
| 731 | case 'resourcetype': |
---|
| 732 | $prop->NewElement($k); // Just an empty resourcetype for a non-collection. |
---|
| 733 | break; |
---|
| 734 | case 'getetag': |
---|
| 735 | $prop->NewElement($k, '"'.$dav_etag_nam.'"' ); |
---|
| 736 | break; |
---|
| 737 | case '"current-user-privilege-set"': |
---|
| 738 | $prop->NewElement($k, privileges($request->permissions) ); |
---|
| 739 | break; |
---|
| 740 | case 'SOME-DENIED-PROPERTY': /** indicating the style for future expansion */ |
---|
| 741 | $denied[] = $v; |
---|
| 742 | break; |
---|
| 743 | default: |
---|
| 744 | dbg_error_log( 'REPORT', "Request for unsupported property '%s' of calendar item.", $v ); |
---|
| 745 | $unsupported[] = $v; |
---|
| 746 | } |
---|
| 747 | } |
---|
| 748 | |
---|
| 749 | $status = new XMLElement("status", "HTTP/1.1 200 OK" ); |
---|
| 750 | $propstat = new XMLElement( "propstat", array( $prop, $status) ); |
---|
| 751 | $href = new XMLElement("href", $url ); |
---|
| 752 | $elements = array($href,$propstat); |
---|
| 753 | |
---|
| 754 | if ( count($denied) > 0 ) { |
---|
| 755 | $status = new XMLElement("status", "HTTP/1.1 403 Forbidden" ); |
---|
| 756 | $noprop = new XMLElement("prop"); |
---|
| 757 | foreach( $denied AS $k => $v ) { |
---|
| 758 | $noprop->NewElement( strtolower($v) ); |
---|
| 759 | } |
---|
| 760 | $elements[] = new XMLElement( "propstat", array( $noprop, $status) ); |
---|
| 761 | } |
---|
| 762 | |
---|
| 763 | $response = new XMLElement( "response", $elements ); |
---|
| 764 | |
---|
| 765 | return $response; |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | |
---|
| 769 | /** |
---|
| 770 | * Return XML for a single component from the DB |
---|
| 771 | * |
---|
| 772 | * @param array $properties The properties for this component |
---|
| 773 | * @param string $item The DB row data for this component |
---|
| 774 | * |
---|
| 775 | * @return string An XML document which is the response for the component |
---|
| 776 | */ |
---|
| 777 | |
---|
| 778 | function component_to_xml( $properties, $item ) { |
---|
| 779 | global $session, $c, $request, $reply; |
---|
| 780 | |
---|
| 781 | dbg_error_log("REPORT","Building XML Response for item '%s'", $item->dav_name ); |
---|
| 782 | |
---|
| 783 | $denied = array(); |
---|
| 784 | $unsupported = array(); |
---|
| 785 | $caldav_data = $item->caldav_data; |
---|
| 786 | $displayname = preg_replace( '{^.*/}', '', $item->dav_name ); |
---|
| 787 | $type = 'unknown'; |
---|
| 788 | $contenttype = 'text/plain'; |
---|
| 789 | switch( $item->caldav_type ) { |
---|
| 790 | case 'VJOURNAL': |
---|
| 791 | case 'VEVENT': |
---|
| 792 | case 'VTODO': |
---|
| 793 | $displayname = $item->summary; |
---|
| 794 | $type = 'calendar'; |
---|
| 795 | $contenttype = 'text/calendar'; |
---|
| 796 | break; |
---|
| 797 | |
---|
| 798 | case 'VCARD': |
---|
| 799 | $displayname = $item->fn; |
---|
| 800 | $type = 'vcard'; |
---|
| 801 | $contenttype = 'text/x-vcard'; |
---|
| 802 | break; |
---|
| 803 | } |
---|
| 804 | if ( isset($properties['calendar-data']) || isset($properties['displayname']) ) { |
---|
| 805 | if ( !$request->AllowedTo('all') && $session->user_no != $item->user_no ){ |
---|
| 806 | // the user is not admin / owner of this calendarlooking at his calendar and can not admin the other cal |
---|
| 807 | /** @todo We should examine the ORGANIZER and ATTENDEE fields in the event. If this person is there then they should see this */ |
---|
| 808 | if ( $type == 'calendar' && $item->class == 'CONFIDENTIAL' || !$request->AllowedTo('read') ) { |
---|
| 809 | $ical = new iCalComponent( $caldav_data ); |
---|
| 810 | $resources = $ical->GetComponents('VTIMEZONE',false); |
---|
| 811 | $first = $resources[0]; |
---|
| 812 | |
---|
| 813 | // if the event is confidential we fake one that just says "Busy" |
---|
| 814 | $confidential = new iCalComponent(); |
---|
| 815 | $confidential->SetType($first->GetType()); |
---|
| 816 | $confidential->AddProperty( 'SUMMARY', translate('Busy') ); |
---|
| 817 | $confidential->AddProperty( 'CLASS', 'CONFIDENTIAL' ); |
---|
| 818 | $confidential->SetProperties( $first->GetProperties('DTSTART'), 'DTSTART' ); |
---|
| 819 | $confidential->SetProperties( $first->GetProperties('RRULE'), 'RRULE' ); |
---|
| 820 | $confidential->SetProperties( $first->GetProperties('DURATION'), 'DURATION' ); |
---|
| 821 | $confidential->SetProperties( $first->GetProperties('DTEND'), 'DTEND' ); |
---|
| 822 | $confidential->SetProperties( $first->GetProperties('UID'), 'UID' ); |
---|
| 823 | $ical->SetComponents(array($confidential),$confidential->GetType()); |
---|
| 824 | |
---|
| 825 | $caldav_data = $ical->Render(); |
---|
| 826 | $displayname = translate('Busy'); |
---|
| 827 | } |
---|
| 828 | } |
---|
| 829 | } |
---|
| 830 | |
---|
| 831 | $url = ConstructURL($item->dav_name); |
---|
| 832 | |
---|
| 833 | $prop = new XMLElement("prop"); |
---|
| 834 | foreach( $properties AS $k => $v ) { |
---|
| 835 | switch( $k ) { |
---|
| 836 | case 'getcontentlength': |
---|
| 837 | $contentlength = strlen($caldav_data); |
---|
| 838 | $prop->NewElement($k, $contentlength ); |
---|
| 839 | break; |
---|
| 840 | case 'calendar-data': |
---|
| 841 | if ( $type == 'calendar' ) $reply->CalDAVElement($prop, $k, $caldav_data ); |
---|
| 842 | else $unsupported[] = $k; |
---|
| 843 | break; |
---|
| 844 | case 'address-data': |
---|
| 845 | if ( $type == 'vcard' ) $reply->CardDAVElement($prop, $k, $caldav_data ); |
---|
| 846 | else $unsupported[] = $k; |
---|
| 847 | break; |
---|
| 848 | case 'getcontenttype': |
---|
| 849 | $prop->NewElement($k, $contenttype ); |
---|
| 850 | break; |
---|
| 851 | case 'current-user-principal': |
---|
| 852 | $prop->NewElement("current-user-principal", $request->current_user_principal_xml); |
---|
| 853 | break; |
---|
| 854 | case 'displayname': |
---|
| 855 | $prop->NewElement($k, $displayname ); |
---|
| 856 | break; |
---|
| 857 | case 'resourcetype': |
---|
| 858 | $prop->NewElement($k); // Just an empty resourcetype for a non-collection. |
---|
| 859 | break; |
---|
| 860 | case 'getetag': |
---|
| 861 | $prop->NewElement($k, '"'.$item->dav_etag.'"' ); |
---|
| 862 | break; |
---|
| 863 | case '"current-user-privilege-set"': |
---|
| 864 | $prop->NewElement($k, privileges($request->permissions) ); |
---|
| 865 | break; |
---|
| 866 | case 'SOME-DENIED-PROPERTY': /** indicating the style for future expansion */ |
---|
| 867 | $denied[] = $k; |
---|
| 868 | break; |
---|
| 869 | default: |
---|
| 870 | dbg_error_log( 'REPORT', "Request for unsupported property '%s' of calendar item.", $v ); |
---|
| 871 | $unsupported[] = $k; |
---|
| 872 | } |
---|
| 873 | } |
---|
| 874 | $status = new XMLElement("status", "HTTP/1.1 200 OK" ); |
---|
| 875 | |
---|
| 876 | $propstat = new XMLElement( "propstat", array( $prop, $status) ); |
---|
| 877 | $href = new XMLElement("href", $url ); |
---|
| 878 | $elements = array($href,$propstat); |
---|
| 879 | |
---|
| 880 | if ( count($denied) > 0 ) { |
---|
| 881 | $status = new XMLElement("status", "HTTP/1.1 403 Forbidden" ); |
---|
| 882 | $noprop = new XMLElement("prop"); |
---|
| 883 | foreach( $denied AS $k => $v ) { |
---|
| 884 | $noprop->NewElement( strtolower($v) ); |
---|
| 885 | } |
---|
| 886 | $elements[] = new XMLElement( "propstat", array( $noprop, $status) ); |
---|
| 887 | } |
---|
| 888 | |
---|
| 889 | if ( count($unsupported) > 0 ) { |
---|
| 890 | $status = new XMLElement("status", "HTTP/1.1 404 Not Found" ); |
---|
| 891 | $noprop = new XMLElement("prop"); |
---|
| 892 | foreach( $unsupported AS $k => $v ) { |
---|
| 893 | $noprop->NewElement( strtolower($v) ); |
---|
| 894 | } |
---|
| 895 | $elements[] = new XMLElement( "propstat", array( $noprop, $status) ); |
---|
| 896 | } |
---|
| 897 | |
---|
| 898 | $response = new XMLElement( "response", $elements ); |
---|
| 899 | |
---|
| 900 | return $response; |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | if ( $xmltree->GetTag() == "urn:ietf:params:xml:ns:caldav:calendar-query" ) { |
---|
| 904 | $calquery = $xmltree->GetPath("/urn:ietf:params:xml:ns:caldav:calendar-query/*"); |
---|
| 905 | include("caldav-REPORT-calquery.php"); |
---|
| 906 | } |
---|
| 907 | elseif ( $xmltree->GetTag() == "urn:ietf:params:xml:ns:caldav:calendar-multiget" ) { |
---|
| 908 | $mode = 'caldav'; |
---|
| 909 | $qry_content = $xmltree->GetContent('urn:ietf:params:xml:ns:caldav:calendar-multiget'); |
---|
| 910 | include("caldav-REPORT-multiget.php"); |
---|
| 911 | } |
---|
| 912 | elseif ( $xmltree->GetTag() == "urn:ietf:params:xml:ns:carddav:addressbook-multiget" ) { |
---|
| 913 | $mode = 'carddav'; |
---|
| 914 | $qry_content = $xmltree->GetContent('urn:ietf:params:xml:ns:carddav:addressbook-multiget'); |
---|
| 915 | include("caldav-REPORT-multiget.php"); |
---|
| 916 | } |
---|
| 917 | elseif ( $xmltree->GetTag() == "urn:ietf:params:xml:ns:carddav:addressbook-query" ) { |
---|
| 918 | $cardquery = $xmltree->GetPath("/urn:ietf:params:xml:ns:carddav:addressbook-query/*"); |
---|
| 919 | include("caldav-REPORT-cardquery.php"); |
---|
| 920 | } |
---|
| 921 | else { |
---|
| 922 | $request->PreconditionFailed( 403, 'DAV::supported-report', sprintf( '"%s" is not a supported report type') ); |
---|
| 923 | } |
---|
| 924 | |
---|
| 925 | function converte_semana($sema){ |
---|
| 926 | $retorna = "BYDAY="; |
---|
| 927 | $param = 1; |
---|
| 928 | while( $param <= 64 ){ |
---|
| 929 | $numero = $sema & $param; |
---|
| 930 | if ( $numero != 0 ){ |
---|
| 931 | switch ($numero){ |
---|
| 932 | case 1: |
---|
| 933 | $retorna .= "SU,"; |
---|
| 934 | break; |
---|
| 935 | case 2: |
---|
| 936 | $retorna .= "MO,"; |
---|
| 937 | break; |
---|
| 938 | case 4: |
---|
| 939 | $retorna .= "TU,"; |
---|
| 940 | break; |
---|
| 941 | case 8: |
---|
| 942 | $retorna .= "WE,"; |
---|
| 943 | break; |
---|
| 944 | case 16: |
---|
| 945 | $retorna .= "TH,"; |
---|
| 946 | break; |
---|
| 947 | case 32: |
---|
| 948 | $retorna .= "FR,"; |
---|
| 949 | break; |
---|
| 950 | case 64: |
---|
| 951 | $retorna .= "SA"; |
---|
| 952 | break; |
---|
| 953 | default: |
---|
| 954 | continue; |
---|
| 955 | } |
---|
| 956 | } |
---|
| 957 | $param = $param * 2; |
---|
| 958 | } |
---|
| 959 | $nova = substr($retorna, 0, -1); |
---|
| 960 | return $nova; |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | function dataTzParaSegundos($datatz){ |
---|
| 964 | $HorarioTimeZone = new DateTimeZone(date_default_timezone_get()); |
---|
| 965 | $HorarioTime = new DateTime("now", $HorarioTimeZone); |
---|
| 966 | return mktime( substr("$datatz", 9,2),//hora |
---|
| 967 | substr("$datatz", 11,2),//min |
---|
| 968 | substr("$datatz", 13,2),//segundos |
---|
| 969 | substr("$datatz", 4,2),//mes |
---|
| 970 | substr("$datatz", 6,2),//dia |
---|
| 971 | substr("$datatz", 0,4)) + $HorarioTimeZone->getoffset($HorarioTime);//ano |
---|
| 972 | } |
---|
| 973 | |
---|
| 974 | function dataSegundosParaT($dataseg, $opcao = 0){ |
---|
| 975 | if ($opcao!=1){ |
---|
| 976 | $teste = getdate($dataseg); |
---|
| 977 | return date("Ymd\THis",$teste[0]); |
---|
| 978 | } |
---|
| 979 | date_default_timezone_set('UTC'); |
---|
| 980 | $data_nova = date("Ymd\THis",$dataseg); |
---|
| 981 | date_default_timezone_set('America/Sao_Paulo'); |
---|
| 982 | $HorarioTimeZone = new DateTimeZone(date_default_timezone_get()); |
---|
| 983 | $HorarioTime = new DateTime($data_nova, $HorarioTimeZone); |
---|
| 984 | //$teste = getdate($dataseg - $HorarioTimeZone->getoffset($HorarioTime)); |
---|
| 985 | //date_default_timezone_set('UTC'); |
---|
| 986 | //$retorna = date("Ymd\THis\Z",$dataseg); |
---|
| 987 | $teste = getdate($dataseg - $HorarioTimeZone->getoffset($HorarioTime)); |
---|
| 988 | return date("Ymd\THis\Z",$teste[0]); |
---|
| 989 | } |
---|
| 990 | |
---|