Changeset 4219 for contrib/z-push
- Timestamp:
- 05/05/11 09:37:13 (13 years ago)
- Location:
- contrib/z-push
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
contrib/z-push/backend/BackendCalendarExpresso.php
r4000 r4219 52 52 53 53 function GetMessageList($folderid, $cutoffdate) { 54 debugLog('CalendarExpresso::GetMessageList('.$this->_uidnumber.')'); 54 debugLog('CalendarExpresso::GetMessageList('.$this->_uidnumber.', '.$cutoffdate.')'); 55 if (TRACE_UID !== false and $cutoffdate !== 0 and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageList-> Filtra eventos com data maior que cutoffdate: '.date("d/m/Y G:i:s",$cutoffdate).', cutoffdate_timestamp: '.$cutoffdate); 55 56 if ($folderid != "calendar") return false; 56 57 58 $cal_ids = null; 57 59 $messages = array(); 58 60 try { 59 61 $result = pg_query($this->db,"BEGIN;"); 60 62 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 61 if ($cutoffdate == 0) $result = pg_query($this->db, "select c.cal_id, c.last_update, c.datetime, c.cal_type from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.reference = 0;");62 else $result = pg_query($this->db, "select c.cal_id, c.last_update, c.datetime, c.cal_type from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.reference = 0 and c.edatetime > " . $cutoffdate . ";");63 if ($cutoffdate == 0) $result = pg_query($this->db, "select c.cal_id, c.last_update, c.datetime, c.cal_type, c.title from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.reference = 0;"); 64 else $result = pg_query($this->db, "select c.cal_id, c.last_update, c.datetime, c.cal_type, c.title from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.reference = 0 and c.edatetime > " . $cutoffdate . ";"); 63 65 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 64 66 while ($row = pg_fetch_row($result)) { 67 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageList-> Lê item do BD (cal_id: '.$row[0].', title: '.$row[4].', last_update: '.date("d/m/Y G:i:s",substr($row[1], 0, strlen($row[1])-3)).', last_update_timestamp: '.$row[1].', datetime: '.date("d/m/Y G:i:s",$row[2]).', datetime_timestamp: '.$row[2].', cal_type: '.$row[3].')'); 65 68 $result_recur = pg_query($this->db,"select recur_enddate from phpgw_cal_repeats where cal_id = " . $row[0] . ";"); 66 69 if ($result_recur == FALSE) throw new Exception(pg_last_error($this->db)); 67 70 if ($row[3] == 'M') { 68 71 if ($recur_enddate = pg_fetch_result($result_recur, 0, 0)) { 69 if ($recur_enddate < $row[2]) continue; // Nao sincroniza este evento, porque a data final da recorrencia eh menor que a data inicial do evento. Eh o BD do Expresso que esta inconsistente. 72 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageList-> Evento '.$row[0].' é recorrente: recur_enddate : '.date("d/m/Y G:i:s",$recur_enddate).', recur_enddate_timestamp: '.$recur_enddate); 73 if ($recur_enddate < $row[2]) { 74 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageList-> ERRO: Esse evento não será adicionado na lista porque o campo phpgw_cal_repeats.recur_enddate é menor que o campo phpgw_cal.datetime. Corrija o valor de um dos campos'); 75 continue; // Nao sincroniza este evento, porque a data final da recorrencia eh menor que a data inicial do evento. Eh o BD do Expresso que esta inconsistente. 76 } 70 77 } 71 78 } … … 76 83 $message["flags"] = 1; // always 'read' 77 84 $messages[] = $message; 85 if ($cal_ids === null) $cal_ids = $row[0]; 86 else $cal_ids = $cal_ids . ',' . $row[0]; 87 } 88 // Eventos com reference invalidos 89 if ($cutoffdate == 0) $result_invalid_ref = pg_query($this->db, "select c.cal_id, c.last_update, c.datetime, c.cal_type, c.title, c.reference from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.reference <> 0 and c.reference not in(".$cal_ids.");"); 90 else $result_invalid_ref = pg_query($this->db, "select c.cal_id, c.last_update, c.datetime, c.cal_type, c.title, c.reference from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.reference <> 0 and c.reference not in(".$cal_ids.") and c.datetime > ". $cutoffdate .";"); 91 if ($result_invalid_ref == FALSE) throw new Exception(pg_last_error($this->db)); 92 while ($row_invalid_ref = pg_fetch_row($result_invalid_ref)) { 93 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageList-> ERRO: Evento com campo reference inválido (cal_id: '.$row_invalid_ref[0].', title: '.$row_invalid_ref[4].', reference: '.$row_invalid_ref[5].', last_update: '.date("d/m/Y G:i:s",substr($row_invalid_ref[1], 0, strlen($row[1])-3)).', last_update_timestamp: '.$row_invalid_ref[1].', datetime: '.date("d/m/Y G:i:s",$row_invalid_ref[2]).', datetime_timestamp: '.$row_invalid_ref[2].', cal_type: '.$row_invalid_ref[3].')'); 94 } 95 // Evento fora da faixa filtrada 96 if ($cutoffdate !== 0) { 97 $result_out_cutoffdate = pg_query($this->db, "select c.cal_id, c.datetime, c.cal_type, c.title, c.reference from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.datetime <= ". $cutoffdate .";"); 98 if ($result_out_cutoffdate == FALSE) throw new Exception(pg_last_error($this->db)); 99 while ($row_out_cutoffdate = pg_fetch_row($result_out_cutoffdate)) { 100 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageList-> INFORMACAO: Evento com campo datetime fora da faixa filtrada (cal_id: '.$row_out_cutoffdate[0].', title: '.$row_out_cutoffdate[3].', reference: '.$row_out_cutoffdate[4].', datetime: '.date("d/m/Y G:i:s",$row_out_cutoffdate[1]).', datetime_timestamp: '.$row_out_cutoffdate[1].', cal_type: '.$row_out_cutoffdate[2].')'); 101 } 78 102 } 79 103 $result = pg_query($this->db,"COMMIT;"); … … 83 107 debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine()); 84 108 } 109 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageList-> Fim normal da função'); 85 110 return $messages; 86 111 } … … 132 157 $message["id"] = $id; 133 158 $message["flags"] = 1; 159 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::StatMessage-> mod: '.$message["mod"].', id: '.$message["id"]); 134 160 return $message; 135 161 } … … 141 167 debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine()); 142 168 } 169 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::StatMessage: ERRO: Não encontrou valor para o campo last_update para esse evento.'); 143 170 return false; 144 171 } … … 159 186 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 160 187 if ($row = pg_fetch_row($result)) { 188 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageDAO-> Lê evento do DB para enviar para o celular (cal_id: '.$row[0].', title:'.$row[1].', location: '.$row[2].', mdatetime: '.$row[3].', datetime: '.$row[4].', edatetime: '.$row[5].', reference: '.$row[7].', isPublic: '.$row[8].')'); 161 189 if ($row[7] != 0) $has_parent_event = true; 162 190 else $has_parent_event = false; … … 237 265 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 238 266 if ($row = pg_fetch_row($result)){ 267 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageDAO-> Lê recorrência do evento (recur_type: '.$row[0].', recur_use_end: '.$row[1].', recur_enddate: '.$row[2].', recur_interval: '.$row[3].', recur_data: '.$row[4].', recur_exception: '.$row[5].')'); 239 268 $recur = new SyncRecurrence(); 240 269 // Converte os tipos do Expresso para os tipos do Protocolo ActiveSync … … 282 311 } 283 312 $message->recurrence = $recur; 313 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageDAO-> Fim do Bloco - Lê recorrência do evento.'); 284 314 } 285 315 … … 288 318 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 289 319 while ($row_recur_exception = pg_fetch_row($result)) { 320 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageDAO: Lê evento único da recorrência com id: '.$row_recur_exception[0]); 290 321 $recur_exception = $this->GetMessageDAO($row_recur_exception[0]); 291 322 if ($recur_exception instanceof SyncAppointment) { … … 293 324 array_push($message->exceptions, $recur_exception); 294 325 } 326 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageDAO-> Fim do Bloco - Lê evento único da recorrência com id: '.$row_recur_exception[0]); 295 327 } 296 328 … … 299 331 $array_timestamps_recur_deleted = explode(",",$row[5]); 300 332 foreach ($array_timestamps_recur_deleted as $timestamp_recur_deleted) { 333 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageDAO: Timestamps dos eventos únicos da recorrência do tipo deletados: '.$timestamp_recur_deleted); 301 334 $recur_deleted = new SyncAppointment(); 302 335 $recur_deleted->deleted = '1'; … … 307 340 } 308 341 //TODO: Tratar Participantes do Evento 342 309 343 } 310 344 $result = pg_query($this->db,"COMMIT;"); … … 315 349 return; 316 350 } 351 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageDAO-> Fim do Bloco - Lê evento do DB para enviar para o celular: '.$id); 317 352 return $message; 318 353 } … … 354 389 return false; 355 390 } 391 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog("CalendarExpresso::DeleteMessage-> Fim normal da Função."); 356 392 return true; 357 393 } … … 363 399 function ChangeMessageDAO($id, $message) { 364 400 debugLog('CalendarExpresso::ChangeMessageDAO('.$id.', ..)'); 401 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> O evento do celular será inserido/atualizado no BD com o ID: '.$id); 365 402 try { 366 403 $result = pg_query($this->db,"BEGIN;"); … … 380 417 $description_from_DB = $row[3]; 381 418 $found_cal_id = true; 419 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Achou o evento na tabela phpgw_cal, vai ATUALIZAR essa tabela'); 382 420 } 383 421 } … … 388 426 if(isset($row[0])) { 389 427 $found_cal_user = true; 428 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Achou o evento na tabela phpgw_cal_user, vai ATUALIZAR essa tabela'); 390 429 } 391 430 } … … 396 435 if(isset($row[0])) { 397 436 $found_cal_repeats = true; 437 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Achou o evento na tabela phpgw_cal_repeats, vai ATUALIZAR essa tabela'); 398 438 } 399 439 } … … 403 443 if(isset($message->uid)) { 404 444 $arrayCal["uid"] = $this->truncateString(utf8_decode($message->uid),255); 445 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> uid: '.$arrayCal["uid"]); 405 446 } 406 447 if(isset($message->subject)) { 407 448 $arrayCal["title"] = $this->truncateString(utf8_decode($message->subject),299); 449 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> title: '.$arrayCal["title"]); 408 450 } 409 451 if(isset($message->location)) { 410 452 $arrayCal["location"] = $this->truncateString(utf8_decode($message->location),255); 453 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> location: '.$arrayCal["location"]); 411 454 } 412 455 if(isset($message->dtstamp)) { 413 456 $arrayCal["mdatetime"] = $message->dtstamp; 457 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> mdatetime: '.$arrayCal["mdatetime"]); 414 458 } 415 459 if(isset($message->starttime)) { 416 460 $arrayCal["datetime"] = $message->starttime; 461 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> datetime: '.$arrayCal["datetime"]); 417 462 } 418 463 if(isset($message->endtime)) { 419 464 $arrayCal["edatetime"] = $message->endtime; 465 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> edatetime: '.$arrayCal["edatetime"]); 420 466 } 421 467 if(isset($message->sensitivity) and $message->sensitivity == 0) { 422 468 $arrayCal["is_public"] = 1; // 1 - Normal 423 469 } else $arrayCal["is_public"] = 0; // 0 - Privado 470 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> is_public: '.$arrayCal["is_public"]); 424 471 425 472 if(isset($message->rtf)) { … … 429 476 if ($result_loadrtf == true) $rtf_to_ascii->parse(); 430 477 $arrayCal["description"] = $rtf_to_ascii->out; 478 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> description: '.$arrayCal["description"]); 431 479 // } else { 432 480 // $arrayCal["description"] = ''; … … 444 492 } 445 493 } 494 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> category: '.$arrayCal["category"]); 446 495 } 447 496 $tz_CEL = $this->_getTZFromSyncBlob(base64_decode($message->timezone)); … … 462 511 $result = pg_insert($this->db, 'phpgw_cal', $arrayCal); 463 512 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 513 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento INSERIDO na tabela phpgw_cal com cal_id: '.$arrayCal["cal_id"]); 464 514 } else { 465 515 if (isset($cal_type_from_DB)) { … … 469 519 $result = pg_update($this->db, 'phpgw_cal', $arrayCal, array('cal_id' => $cal_id)); 470 520 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 521 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento ATUALIZADO na tabela phpgw_cal'); 471 522 } 472 523 … … 480 531 $result = pg_insert($this->db, 'phpgw_cal_user', $arrayCalUser); 481 532 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 533 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento INSERIDO na tabela phpgw_cal_user com cal_id: '.$arrayCalUser["cal_id"]); 482 534 } else { 483 535 $result = pg_update($this->db, 'phpgw_cal_user', $arrayCalUser, array('cal_id' => $cal_id, 'cal_login' => $this->_uidnumber)); 484 536 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 537 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento ATUALIZADO na tabela phpgw_cal_user'); 485 538 } 486 539 if (!$id) { … … 490 543 //TODO: Implementar para os tipos 3 e 6. O Expresso ainda nao suporta esses tipos :-( 491 544 if (isset($message->recurrence) and ($message->recurrence->type == 0 or $message->recurrence->type == 1 or $message->recurrence->type == 2 or $message->recurrence->type == 5)) { 545 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> O Evento é Recorrente.'); 492 546 switch ($message->recurrence->type) { 493 547 case 0: //repeticao diaria … … 508 562 break; 509 563 } 564 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Recorrência-> recur_type: '.$arrayRecur["recur_type"]); 510 565 if (isset($message->recurrence->interval)) { 511 566 $arrayRecur["recur_interval"] = $message->recurrence->interval; 567 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Recorrência-> recur_interval: '.$arrayRecur["recur_interval"]); 512 568 } 513 569 if ($message->recurrence->type == 1 or $message->recurrence->type == 3 or $message->recurrence->type == 6) { 514 570 if (isset($message->recurrence->dayofweek)) { 515 571 $arrayRecur["recur_data"] = $message->recurrence->dayofweek; 572 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Recorrência-> recur_data: '.$arrayRecur["recur_data"]); 516 573 /*$day = $message->recurrence->dayofweek; 517 574 $day_of_week_counter = 0; … … 558 615 $arrayRecur["recur_enddate"] = 1893283200; // Se nao tem data de termino seta para 30/12/2029 559 616 } 617 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Recorrência-> recur_enddate: '.$arrayRecur["recur_enddate"]); 560 618 561 619 // Trata excecoes da recorrencia … … 563 621 // Tem Excecoes de recorrencia do tipo Edicao 564 622 // Verifica se ja existe o registro do evento de excecao de recorrencia na tabela phpgw_cal 623 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento tem exceção de recorrência'); 565 624 $recur_exception_changed_ids = ""; 566 625 $recur_exception_deleted_starttimes = ""; … … 584 643 $except_description_from_DB = $row[2]; 585 644 $found_except_cal_id = true; 645 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Achou o evento na tabela phpgw_cal, vai ATUALIZAR a exceção da recorrência nessa tabela'); 586 646 } 587 647 } … … 593 653 if(isset($row[0])) { 594 654 $found_except_cal_user = true; 655 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Achou o evento na tabela phpgw_cal_user, vai ATUALIZAR a exceção da recorrência nessa tabela'); 595 656 } 596 657 } … … 600 661 if(isset($message->uid)) { 601 662 $arrayExceptCal["uid"] = $this->truncateString(utf8_decode($message->uid),255); 663 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> uid: '.$arrayExceptCal["uid"]); 602 664 } 603 665 if(isset($recur_exception->subject)) { … … 606 668 $arrayExceptCal["title"] = $this->truncateString(utf8_decode($message->subject),299); 607 669 } 670 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> title: '.$arrayExceptCal["title"]); 608 671 if(isset($recur_exception->location)) { 609 672 $arrayExceptCal["location"] = $this->truncateString(utf8_decode($recur_exception->location),255); … … 611 674 $arrayExceptCal["location"] = $this->truncateString(utf8_decode($message->location),255); 612 675 } 676 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> location: '.$arrayExceptCal["location"]); 613 677 if(isset($recur_exception->dtstamp)) { 614 678 $arrayExceptCal["mdatetime"] = $recur_exception->dtstamp; … … 616 680 $arrayExceptCal["mdatetime"] = $message->dtstamp; 617 681 } 682 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> mdatetime: '.$arrayExceptCal["mdatetime"]); 618 683 if(isset($recur_exception->starttime)) { 619 684 $arrayExceptCal["datetime"] = $recur_exception->starttime; … … 621 686 $arrayExceptCal["datetime"] = $message->starttime; 622 687 } 688 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> datetime: '.$arrayExceptCal["datetime"]); 623 689 if(isset($recur_exception->endtime)) { 624 690 $arrayExceptCal["edatetime"] = $recur_exception->endtime; … … 626 692 $arrayExceptCal["edatetime"] = $message->endtime; 627 693 } 694 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> edatetime: '.$arrayExceptCal["edatetime"]); 628 695 if(isset($recur_exception->sensitivity) and $recur_exception->sensitivity == 0) { 629 696 $arrayExceptCal["is_public"] = 1; // 1 - Normal … … 633 700 $arrayExceptCal["is_public"] = 1; // 1 - Normal 634 701 }else $arrayExceptCal["is_public"] = 0; // 0 - Privado 702 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> is_public: '.$arrayExceptCal["is_public"]); 635 703 if (isset($recur_exception->body)) { 636 704 $arrayExceptCal["description"] = utf8_decode($recur_exception->body); … … 670 738 } 671 739 } 740 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> category: '.$arrayExceptCal["category"]); 672 741 //TODO: Converter eventos que sao alldayevent para iniciar as 0:00hs e terminar as 23:59hs. Isso porque o Expresso nao suporta alldayevents 673 742 // if(isset($message->alldayevent)) { … … 683 752 $result = pg_insert($this->db, 'phpgw_cal', $arrayExceptCal); 684 753 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 754 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento de Exceção da Recorrência INSERIDO na tabela phpgw_cal com cal_id: '.$arrayExceptCal["cal_id"]); 685 755 } else { 686 756 $result = pg_update($this->db, 'phpgw_cal', $arrayExceptCal, array('cal_id' => $except_cal_id)); 687 757 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 758 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento de Exceção da Recorrência ATUALIZADO na tabela phpgw_cal'); 688 759 } 689 760 … … 697 768 $result = pg_insert($this->db, 'phpgw_cal_user', $arrayExceptCalUser); 698 769 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 770 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento de Exceção da Recorrência INSERIDO na tabela phpgw_cal_user com cal_id: '.$arrayExceptCalUser["cal_id"]); 699 771 } else { 700 772 $result = pg_update($this->db, 'phpgw_cal_user', $arrayExceptCalUser, array('cal_id' => $except_cal_id, 'cal_login' => $this->_uidnumber)); 701 773 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 774 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento de Exceção da Recorrência ATUALIZADO na tabela phpgw_cal_user'); 702 775 } 703 776 if ($recur_exception_changed_ids == "") { … … 717 790 //Tem Excecoes de recorrencia do tipo Exclusao 718 791 $arrayRecur["recur_exception"] = $recur_exception_deleted_starttimes; 792 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Evento tem exceção de recorrência do tipo exclusão com os seguintes starttimes: '.$recur_exception_deleted_starttimes); 719 793 } else { 720 794 $arrayRecur["recur_exception"] = ""; 795 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Não tem exceção de recorrência do tipo exclusão para esse evento'); 721 796 } 722 797 if ($recur_exception_changed_ids == "") { … … 726 801 $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . ";"); 727 802 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 803 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Não tem exceção de recorrência, então deleta possíveis eventos de exceção de recorrência criados anteriormente para esse evento.'); 728 804 } else { 729 805 //Deleta as excecoes da recorrencia, exceto as inseridas/atualizadas acima … … 732 808 $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . " and cal_id not in (" . $recur_exception_changed_ids . ");"); 733 809 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 810 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Deleta as exçeções da recorrência, exceto as inseridas/atualizadas pelo celular com os seguintes cal_id:'.$recur_exception_changed_ids); 734 811 } 735 812 } else { … … 740 817 $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . ";"); 741 818 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 742 819 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Não tem exceção de recorrência, então deleta possíveis eventos de exceção de recorrência criados anteriormente para esse evento..'); 743 820 } 744 821 if (!$found_cal_repeats){ … … 746 823 $result = pg_insert($this->db, 'phpgw_cal_repeats', $arrayRecur); 747 824 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 825 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Recorrência INSERIDA na tabela phpgw_cal_repeats com cal_id: '.$arrayRecur["cal_id"]); 748 826 } else { 749 827 $result = pg_update($this->db, 'phpgw_cal_repeats', $arrayRecur, array('cal_id' => $cal_id)); 750 828 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 829 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Recorrência ATUALIZADA na tabela phpgw_cal_repeats'); 751 830 } 752 831 } elseif ($found_cal_id) { … … 758 837 $result = pg_query($this->db, "delete from phpgw_cal_repeats where cal_id = " . $cal_id . ";"); 759 838 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 839 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Não tem recorrência, então deleta possíveis eventos de recorrência criados anteriormente para esse evento'); 760 840 } 761 841 $result = pg_query($this->db,"COMMIT;"); … … 767 847 return false; 768 848 } 849 if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Fim normal da Função'); 769 850 return $id; 770 851 } -
contrib/z-push/backend/imap.php
r3754 r4219 313 313 if ($search !== false) 314 314 $sequence = implode(",", $search); 315 } 315 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetMessageList-> A função @imap_search leu as seguintes SEQUÊNCIAS do servidor IMAP com base no filtro de data: '.$sequence); 316 } 317 316 318 $overviews = @imap_fetch_overview($this->_mbox, $sequence); 317 319 … … 322 324 $date = ""; 323 325 $vars = get_object_vars($overview); 326 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetMessageList-> A função @imap_fetch_overview leu mais detalhes da mensagem: '. print_r($overview,1)); 324 327 if (array_key_exists( "date", $vars)) { 325 328 // message is out of range for cutoffdate, ignore it 326 if(strtotime(preg_replace("/\(.*\)/", "", $overview->date)) < $cutoffdate) continue; // emerson-faria.nobre@serpro.gov.br - 07/feb/2011 329 if(strtotime(preg_replace("/\(.*\)/", "", $overview->date)) < $cutoffdate) { // emerson-faria.nobre@serpro.gov.br - 07/feb/2011 330 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetMessageList-> O overview->date: '.$overview->date.' (overview->date_timestamp: '.strtotime(preg_replace("/\(.*\)/", "", $overview->date)).') é menor que o $cutoffdate: '.date("d/m/Y G:i:s",$cutoffdate).' ($cutoffdate_timestamp: '.$cutoffdate.') ou a função "strtotime" gerou um ERRO porque não conseguiu retornar um valor para o overview->date_timestamp. A mensagem será descartada da sincronização.'); 331 continue; 332 } 327 333 //if(strtotime($overview->date) < $cutoffdate) continue; 328 334 $date = $overview->date; 335 } else if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetMessageList-> ERRO: O campo date não existe no overview da mensagem.'); 336 337 // cut of deleted messages 338 if (array_key_exists( "deleted", $vars) && $overview->deleted) { 339 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetMessageList-> A mensagem está com o flag deleted ativo e será descartada da sincronização'); 340 continue; 329 341 } 330 331 // cut of deleted messages332 if (array_key_exists( "deleted", $vars) && $overview->deleted)333 continue;334 342 335 343 if (array_key_exists( "uid", $vars)) { … … 342 350 if(array_key_exists( "seen", $vars) && $overview->seen) 343 351 $message["flags"] = 1; 344 345 352 array_push($messages, $message); 346 } 353 } else if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetMessageList-> ERRO: O campo uid não existe no overview da mensagem.'); 347 354 } 348 355 } … … 361 368 $list = array_reverse($list); 362 369 foreach ($list as $val) { 370 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetFolderList-> Pasta lida usando a função @imap_getmailboxes: '.print_r($val,1)); 363 371 $box = array(); 364 372 … … 379 387 $box["parent"] = "0"; 380 388 } 381 389 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetFolderList-> Parâmetros da pasta após decodificação: '.print_r($box,1)); 382 390 $folders[]=$box; 383 391 } … … 461 469 //advanced debugging 462 470 //debugLog("IMAP-GetFolder(id: '$id') -> " . print_r($folder, 1)); 471 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::GetFolder(id: '.$id.'): '.print_r($folder,1)); 463 472 464 473 return $folder; … … 481 490 $stat["parent"] = $folder->parentid; 482 491 $stat["mod"] = $folder->displayname; 483 492 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::StatFolder(id: '.$id.'): '.print_r($stat,1)); 484 493 return $stat; 485 494 } … … 535 544 if (isset($message->parts[$part]->body)) 536 545 print $message->parts[$part]->body; 537 546 538 547 // unset mimedecoder & mail 539 548 unset($mobj); … … 565 574 $vars = get_object_vars($overview[0]); 566 575 576 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL') and (! array_key_exists( "uid", $vars))) debugLog('IMAP::StatMessage-> ERRO: A mensagem será desconsiderada porque não tem o campo "uid"'); 567 577 // without uid it's not a valid message 568 578 if (! array_key_exists( "uid", $vars)) return false; … … 578 588 $entry["flags"] = 1; 579 589 590 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::StatMessage: '.print_r($entry,1)); 591 580 592 //advanced debugging 581 593 //debugLog("IMAP-StatMessage-parsed: ". print_r($entry,1)); … … 601 613 $mail = @imap_fetchheader($this->_mbox, $id, FT_PREFETCHTEXT | FT_UID) . @imap_body($this->_mbox, $id, FT_PEEK | FT_UID); 602 614 615 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog("IMAP-GetMessage: Mensagem lida do servidor IMAP através da função @imap_fetchheader: ". print_r($mail,1)); 616 603 617 $mobj = new Mail_mimeDecode($mail); 604 618 $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $mail, 'crlf' => "\n", 'charset' => 'utf-8')); 619 620 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog("IMAP-GetMessage: Mensagem mime decodificada: ". print_r($message,1)); 605 621 606 622 $output = new SyncMail(); … … 661 677 unset($mobj); 662 678 unset($mail); 679 if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog("IMAP-GetMessage: Mensagem formatada para envio ao celular: ". print_r($output,1)); 663 680 return $output; 664 681 } … … 808 825 $this->getBodyRecursive($message, "plain", $body); 809 826 810 if(!isset($body) || $body === "") {827 if(!isset($body) or $body === '') { 811 828 $this->getBodyRecursive($message, "html", $body); 812 829 // remove css-style tags … … 817 834 // Remove the HTML tags using the 'html2text' - emerson-faria.nobre@serpro.gov.br 818 835 // The 'html2text' (http://www.mbayer.de/html2text) must be installed in Z-Push server. 819 836 820 837 // Advanced debug 821 838 // debugLog("IMAP-getBody: subject: " . $message->headers["subject"]); 822 $body = utf8_encode($body); 839 $body = utf8_encode($body); 823 840 libxml_use_internal_errors(true); 824 841 try { -
contrib/z-push/config.php
r4000 r4219 11 11 * Consult LICENSE file for details 12 12 ************************************************/ 13 13 14 // Defines the default time zone 14 15 if (function_exists("date_default_timezone_set")){ … … 46 47 47 48 // The data providers that we are using (see configuration below) 48 49 //$BACKEND_PROVIDER = "BackendIMAP"; 49 50 //$BACKEND_PROVIDER = "BackendCalendarExpresso"; 50 51 //$BACKEND_PROVIDER = "BackendContactsExpresso"; … … 95 96 define('VCARDDIR_DIR', '/var/www/vcf'); 96 97 98 // ********************** 99 // TRACE settings 100 // When enabled it creates a file named trace-<USER-ID>.txt during sincronization 101 // ********************** 102 // A string with User_Login that you want to trace or a boolean FALSE if you don't want to trace. 103 define('TRACE_UID', '86928023953'); 104 // TRACE_TYPE can be 'ALL', 'IMAP', 'CALENDAR' or 'CONTACTS' 105 define('TRACE_TYPE', 'IMAP'); 106 97 107 // **************************************************** 98 108 // LDAP Authentication settings … … 101 111 // Must have read access to DN, UID and UIDNUMBER of all users 102 112 define("ANONYMOUS_BIND", false); 103 define("LDAP_BIND_USER", "cn=admin,ou=expressolivre,ou=corp,dc= empresa,dc=gov,dc=br");104 define("LDAP_BIND_PASSWORD", " senha_do_admin");113 define("LDAP_BIND_USER", "cn=admin,ou=expressolivre,ou=corp,dc=serpro,dc=gov,dc=br"); 114 define("LDAP_BIND_PASSWORD", "correio"); 105 115 106 116 define("LDAP_HOST", "ldap://10.200.112.132/"); // Address of your LDAP server … … 108 118 109 119 // Search base & filter 110 define("LDAP_SEARCH_BASE", "dc= empresa,dc=gov,dc=br"); // Base path to search the filter. Example: dc=company,dc=com120 define("LDAP_SEARCH_BASE", "dc=serpro,dc=gov,dc=br"); // Base path to search the filter. Example: dc=company,dc=com 111 121 define("LDAP_SEARCH_FILTER", "uid=SEARCHVALUE"); // The filter is the user login attribute. You can change only the "uid" by other attribute. The SEARCHVALUE string is replaced by the user login inside the backends. 112 122
Note: See TracChangeset
for help on using the changeset viewer.