Changeset 4219 for contrib


Ignore:
Timestamp:
05/05/11 09:37:13 (13 years ago)
Author:
emersonfaria
Message:

Ticket #1829 - Criado trace detalhado filtrado por usuario e backend

Location:
contrib/z-push
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • contrib/z-push/backend/BackendCalendarExpresso.php

    r4000 r4219  
    5252 
    5353        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); 
    5556                if ($folderid != "calendar") return false; 
    5657 
     58                $cal_ids = null; 
    5759                $messages = array(); 
    5860                try { 
    5961                        $result = pg_query($this->db,"BEGIN;"); 
    6062                        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 . ";"); 
    6365                        if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 
    6466                        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].')'); 
    6568                                $result_recur = pg_query($this->db,"select recur_enddate from phpgw_cal_repeats where cal_id = " . $row[0] . ";"); 
    6669                                if ($result_recur == FALSE) throw new Exception(pg_last_error($this->db)); 
    6770                                if ($row[3] == 'M') { 
    6871                                        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                                                } 
    7077                                        } 
    7178                                } 
     
    7683                                $message["flags"] = 1; // always 'read' 
    7784                                $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                                } 
    78102                        } 
    79103                        $result = pg_query($this->db,"COMMIT;"); 
     
    83107                        debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine()); 
    84108                } 
     109                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::GetMessageList-> Fim normal da função'); 
    85110                return $messages; 
    86111        } 
     
    132157                                $message["id"] = $id; 
    133158                                $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"]); 
    134160                                return $message; 
    135161                        } 
     
    141167                        debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine()); 
    142168                } 
     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.'); 
    143170                return false; 
    144171        } 
     
    159186                        if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 
    160187                        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].')'); 
    161189                                if ($row[7] != 0) $has_parent_event = true; 
    162190                                else $has_parent_event = false; 
     
    237265                                if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 
    238266                                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].')'); 
    239268                                        $recur = new SyncRecurrence(); 
    240269                                        // Converte os tipos do Expresso para os tipos do Protocolo ActiveSync 
     
    282311                                        } 
    283312                                        $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.'); 
    284314                                } 
    285315 
     
    288318                                if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 
    289319                                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]); 
    290321                                        $recur_exception = $this->GetMessageDAO($row_recur_exception[0]); 
    291322                                        if ($recur_exception instanceof SyncAppointment) { 
     
    293324                                                array_push($message->exceptions, $recur_exception); 
    294325                                        } 
     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]); 
    295327                                } 
    296328 
     
    299331                                        $array_timestamps_recur_deleted = explode(",",$row[5]); 
    300332                                        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); 
    301334                                                $recur_deleted = new SyncAppointment(); 
    302335                                                $recur_deleted->deleted = '1'; 
     
    307340                                } 
    308341                                //TODO: Tratar Participantes do Evento 
     342 
    309343                        } 
    310344                        $result = pg_query($this->db,"COMMIT;"); 
     
    315349                        return; 
    316350                } 
     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); 
    317352                return $message; 
    318353        } 
     
    354389                        return false; 
    355390                } 
     391                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog("CalendarExpresso::DeleteMessage-> Fim normal da Função."); 
    356392                return true; 
    357393        } 
     
    363399        function ChangeMessageDAO($id, $message) { 
    364400                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); 
    365402                try { 
    366403                        $result = pg_query($this->db,"BEGIN;"); 
     
    380417                                                $description_from_DB = $row[3]; 
    381418                                                $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'); 
    382420                                        } 
    383421                                } 
     
    388426                                        if(isset($row[0])) { 
    389427                                                $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'); 
    390429                                        } 
    391430                                } 
     
    396435                                        if(isset($row[0])) { 
    397436                                                $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'); 
    398438                                        } 
    399439                                } 
     
    403443                        if(isset($message->uid)) { 
    404444                                $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"]); 
    405446                        } 
    406447                        if(isset($message->subject)) { 
    407448                                $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"]); 
    408450                        } 
    409451                        if(isset($message->location)) { 
    410452                                $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"]); 
    411454                        } 
    412455                        if(isset($message->dtstamp)) { 
    413456                                $arrayCal["mdatetime"] = $message->dtstamp; 
     457                                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> mdatetime: '.$arrayCal["mdatetime"]); 
    414458                        } 
    415459                        if(isset($message->starttime)) { 
    416460                                $arrayCal["datetime"] = $message->starttime; 
     461                                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> datetime: '.$arrayCal["datetime"]); 
    417462                        } 
    418463                        if(isset($message->endtime)) { 
    419464                                $arrayCal["edatetime"] = $message->endtime; 
     465                                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> edatetime: '.$arrayCal["edatetime"]); 
    420466                        } 
    421467                        if(isset($message->sensitivity) and $message->sensitivity == 0) { 
    422468                                $arrayCal["is_public"] = 1; // 1 - Normal 
    423469                        } 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"]); 
    424471 
    425472                        if(isset($message->rtf)) { 
     
    429476                                if ($result_loadrtf == true) $rtf_to_ascii->parse(); 
    430477                                $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"]); 
    431479                                //                      } else { 
    432480                                //                              $arrayCal["description"] = ''; 
     
    444492                                        } 
    445493                                } 
     494                                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> category: '.$arrayCal["category"]); 
    446495                        } 
    447496                        $tz_CEL = $this->_getTZFromSyncBlob(base64_decode($message->timezone)); 
     
    462511                                $result = pg_insert($this->db, 'phpgw_cal', $arrayCal); 
    463512                                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"]); 
    464514                        } else { 
    465515                                if (isset($cal_type_from_DB)) { 
     
    469519                                $result = pg_update($this->db, 'phpgw_cal', $arrayCal, array('cal_id' => $cal_id)); 
    470520                                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'); 
    471522                        } 
    472523 
     
    480531                                $result = pg_insert($this->db, 'phpgw_cal_user', $arrayCalUser); 
    481532                                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"]); 
    482534                        } else { 
    483535                                $result = pg_update($this->db, 'phpgw_cal_user', $arrayCalUser, array('cal_id' => $cal_id, 'cal_login' => $this->_uidnumber)); 
    484536                                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'); 
    485538                        } 
    486539                        if (!$id) { 
     
    490543                        //TODO: Implementar para os tipos 3 e 6. O Expresso ainda nao suporta esses tipos :-( 
    491544                        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.'); 
    492546                                switch ($message->recurrence->type) { 
    493547                                        case 0: //repeticao diaria 
     
    508562                                                break; 
    509563                                } 
     564                                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Recorrência-> recur_type: '.$arrayRecur["recur_type"]); 
    510565                                if (isset($message->recurrence->interval)) { 
    511566                                        $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"]); 
    512568                                } 
    513569                                if ($message->recurrence->type == 1 or $message->recurrence->type == 3 or $message->recurrence->type == 6) { 
    514570                                        if (isset($message->recurrence->dayofweek)) { 
    515571                                                $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"]); 
    516573                                                /*$day = $message->recurrence->dayofweek; 
    517574                                                 $day_of_week_counter = 0; 
     
    558615                                        $arrayRecur["recur_enddate"] = 1893283200; // Se nao tem data de termino seta para 30/12/2029 
    559616                                } 
     617                                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Recorrência-> recur_enddate: '.$arrayRecur["recur_enddate"]); 
    560618 
    561619                                // Trata excecoes da recorrencia 
     
    563621                                        // Tem Excecoes de recorrencia do tipo Edicao 
    564622                                        // 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'); 
    565624                                        $recur_exception_changed_ids = ""; 
    566625                                        $recur_exception_deleted_starttimes = ""; 
     
    584643                                                                        $except_description_from_DB = $row[2]; 
    585644                                                                        $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'); 
    586646                                                                } 
    587647                                                        } 
     
    593653                                                                        if(isset($row[0])) { 
    594654                                                                                $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'); 
    595656                                                                        } 
    596657                                                                } 
     
    600661                                                        if(isset($message->uid)) { 
    601662                                                                $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"]); 
    602664                                                        } 
    603665                                                        if(isset($recur_exception->subject)) { 
     
    606668                                                                $arrayExceptCal["title"] = $this->truncateString(utf8_decode($message->subject),299); 
    607669                                                        } 
     670                                                        if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> title: '.$arrayExceptCal["title"]); 
    608671                                                        if(isset($recur_exception->location)) { 
    609672                                                                $arrayExceptCal["location"] = $this->truncateString(utf8_decode($recur_exception->location),255); 
     
    611674                                                                $arrayExceptCal["location"] = $this->truncateString(utf8_decode($message->location),255); 
    612675                                                        } 
     676                                                        if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> location: '.$arrayExceptCal["location"]); 
    613677                                                        if(isset($recur_exception->dtstamp)) { 
    614678                                                                $arrayExceptCal["mdatetime"] = $recur_exception->dtstamp; 
     
    616680                                                                $arrayExceptCal["mdatetime"] = $message->dtstamp; 
    617681                                                        } 
     682                                                        if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> mdatetime: '.$arrayExceptCal["mdatetime"]); 
    618683                                                        if(isset($recur_exception->starttime)) { 
    619684                                                                $arrayExceptCal["datetime"] = $recur_exception->starttime; 
     
    621686                                                                $arrayExceptCal["datetime"] = $message->starttime; 
    622687                                                        } 
     688                                                        if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> datetime: '.$arrayExceptCal["datetime"]); 
    623689                                                        if(isset($recur_exception->endtime)) { 
    624690                                                                $arrayExceptCal["edatetime"] = $recur_exception->endtime; 
     
    626692                                                                $arrayExceptCal["edatetime"] = $message->endtime; 
    627693                                                        } 
     694                                                        if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> edatetime: '.$arrayExceptCal["edatetime"]); 
    628695                                                        if(isset($recur_exception->sensitivity) and $recur_exception->sensitivity == 0) { 
    629696                                                                $arrayExceptCal["is_public"] = 1; // 1 - Normal 
     
    633700                                                                $arrayExceptCal["is_public"] = 1; // 1 - Normal 
    634701                                                        }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"]); 
    635703                                                        if (isset($recur_exception->body)) { 
    636704                                                                $arrayExceptCal["description"] = utf8_decode($recur_exception->body); 
     
    670738                                                                } 
    671739                                                        } 
     740                                                        if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Exceção De Recorrência-> category: '.$arrayExceptCal["category"]); 
    672741                                                        //TODO: Converter eventos que sao alldayevent para iniciar as 0:00hs e terminar as 23:59hs. Isso porque o Expresso nao suporta alldayevents 
    673742                                                        //               if(isset($message->alldayevent)) { 
     
    683752                                                                $result = pg_insert($this->db, 'phpgw_cal', $arrayExceptCal); 
    684753                                                                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"]); 
    685755                                                        } else { 
    686756                                                                $result = pg_update($this->db, 'phpgw_cal', $arrayExceptCal, array('cal_id' => $except_cal_id)); 
    687757                                                                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'); 
    688759                                                        } 
    689760 
     
    697768                                                                $result = pg_insert($this->db, 'phpgw_cal_user', $arrayExceptCalUser); 
    698769                                                                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"]); 
    699771                                                        } else { 
    700772                                                                $result = pg_update($this->db, 'phpgw_cal_user', $arrayExceptCalUser, array('cal_id' => $except_cal_id, 'cal_login' => $this->_uidnumber)); 
    701773                                                                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'); 
    702775                                                        } 
    703776                                                        if ($recur_exception_changed_ids == "") { 
     
    717790                                                //Tem Excecoes de recorrencia do tipo Exclusao 
    718791                                                $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); 
    719793                                        } else { 
    720794                                                $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'); 
    721796                                        } 
    722797                                        if ($recur_exception_changed_ids == "") { 
     
    726801                                                $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . ";"); 
    727802                                                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.'); 
    728804                                        } else { 
    729805                                                //Deleta as excecoes da recorrencia, exceto as inseridas/atualizadas acima 
     
    732808                                                $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . " and cal_id not in (" . $recur_exception_changed_ids . ");"); 
    733809                                                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); 
    734811                                        } 
    735812                                } else { 
     
    740817                                        $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . ";"); 
    741818                                        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..'); 
    743820                                } 
    744821                                if (!$found_cal_repeats){ 
     
    746823                                        $result = pg_insert($this->db, 'phpgw_cal_repeats', $arrayRecur); 
    747824                                        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"]); 
    748826                                } else { 
    749827                                        $result = pg_update($this->db, 'phpgw_cal_repeats', $arrayRecur, array('cal_id' => $cal_id)); 
    750828                                        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'); 
    751830                                } 
    752831                        } elseif ($found_cal_id) { 
     
    758837                                $result = pg_query($this->db, "delete from phpgw_cal_repeats where cal_id = " . $cal_id . ";"); 
    759838                                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'); 
    760840                        } 
    761841                        $result = pg_query($this->db,"COMMIT;"); 
     
    767847                        return false; 
    768848                } 
     849                if (TRACE_UID !== false and (TRACE_TYPE == 'CALENDAR' or TRACE_TYPE == 'ALL')) traceLog('CalendarExpresso::ChangeMessageDAO-> Fim normal da Função'); 
    769850                return $id; 
    770851        } 
  • contrib/z-push/backend/imap.php

    r3754 r4219  
    313313                        if ($search !== false) 
    314314                        $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 
    316318                $overviews = @imap_fetch_overview($this->_mbox, $sequence); 
    317319 
     
    322324                                $date = ""; 
    323325                                $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)); 
    324327                                if (array_key_exists( "date", $vars)) { 
    325328                                        // 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                                        } 
    327333                                        //if(strtotime($overview->date) < $cutoffdate) continue; 
    328334                                        $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; 
    329341                                } 
    330  
    331                                 // cut of deleted messages 
    332                                 if (array_key_exists( "deleted", $vars) && $overview->deleted) 
    333                                 continue; 
    334342 
    335343                                if (array_key_exists( "uid", $vars)) { 
     
    342350                                        if(array_key_exists( "seen", $vars) && $overview->seen) 
    343351                                        $message["flags"] = 1; 
    344  
    345352                                        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.'); 
    347354                        } 
    348355                } 
     
    361368                        $list = array_reverse($list); 
    362369                        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)); 
    363371                                $box = array(); 
    364372 
     
    379387                                        $box["parent"] = "0"; 
    380388                                } 
    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)); 
    382390                                $folders[]=$box; 
    383391                        } 
     
    461469                //advanced debugging 
    462470                //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)); 
    463472 
    464473                return $folder; 
     
    481490                $stat["parent"] = $folder->parentid; 
    482491                $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)); 
    484493                return $stat; 
    485494        } 
     
    535544                if (isset($message->parts[$part]->body)) 
    536545                print $message->parts[$part]->body; 
    537  
     546                 
    538547                // unset mimedecoder & mail 
    539548                unset($mobj); 
     
    565574                        $vars = get_object_vars($overview[0]); 
    566575 
     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"'); 
    567577                        // without uid it's not a valid message 
    568578                        if (! array_key_exists( "uid", $vars)) return false; 
     
    578588                        $entry["flags"] = 1; 
    579589 
     590                        if (TRACE_UID !== false and (TRACE_TYPE == 'IMAP' or TRACE_TYPE == 'ALL')) traceLog('IMAP::StatMessage: '.print_r($entry,1)); 
     591 
    580592                        //advanced debugging 
    581593                        //debugLog("IMAP-StatMessage-parsed: ". print_r($entry,1)); 
     
    601613                        $mail = @imap_fetchheader($this->_mbox, $id, FT_PREFETCHTEXT | FT_UID) . @imap_body($this->_mbox, $id, FT_PEEK | FT_UID); 
    602614 
     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 
    603617                        $mobj = new Mail_mimeDecode($mail); 
    604618                        $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)); 
    605621 
    606622                        $output = new SyncMail(); 
     
    661677                        unset($mobj); 
    662678                        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)); 
    663680                        return $output; 
    664681                } 
     
    808825                $this->getBodyRecursive($message, "plain", $body); 
    809826 
    810                 if(!isset($body) || $body === "") { 
     827                if(!isset($body) or $body === '') { 
    811828                        $this->getBodyRecursive($message, "html", $body); 
    812829                        // remove css-style tags 
     
    817834                        // Remove the HTML tags using the 'html2text' - emerson-faria.nobre@serpro.gov.br 
    818835                        // The 'html2text' (http://www.mbayer.de/html2text) must be installed in Z-Push server. 
    819                                  
     836 
    820837                        // Advanced debug 
    821838                        // debugLog("IMAP-getBody: subject: " . $message->headers["subject"]); 
    822                         $body = utf8_encode($body);      
     839                        $body = utf8_encode($body); 
    823840                        libxml_use_internal_errors(true); 
    824841                        try { 
  • contrib/z-push/config.php

    r4000 r4219  
    1111* Consult LICENSE file for details 
    1212************************************************/ 
     13 
    1314    // Defines the default time zone 
    1415    if (function_exists("date_default_timezone_set")){ 
     
    4647     
    4748    // The data providers that we are using (see configuration below) 
    48     //$BACKEND_PROVIDER = "BackendIMAP"; 
     49        //$BACKEND_PROVIDER = "BackendIMAP"; 
    4950    //$BACKEND_PROVIDER = "BackendCalendarExpresso"; 
    5051    //$BACKEND_PROVIDER = "BackendContactsExpresso"; 
     
    9596    define('VCARDDIR_DIR', '/var/www/vcf'); 
    9697 
     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     
    97107    // **************************************************** 
    98108    //  LDAP Authentication settings 
     
    101111    // Must have read access to DN, UID and UIDNUMBER of all users 
    102112        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"); 
    105115     
    106116        define("LDAP_HOST", "ldap://10.200.112.132/"); // Address of your LDAP server 
     
    108118 
    109119        // Search base & filter 
    110         define("LDAP_SEARCH_BASE", "dc=empresa,dc=gov,dc=br"); // Base path to search the filter. Example: dc=company,dc=com 
     120        define("LDAP_SEARCH_BASE", "dc=serpro,dc=gov,dc=br"); // Base path to search the filter. Example: dc=company,dc=com 
    111121        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. 
    112122 
Note: See TracChangeset for help on using the changeset viewer.