Ignore:
Timestamp:
07/27/12 14:47:35 (12 years ago)
Author:
acoutinho
Message:

Ticket #2966 - Notificao e resposta de tasks / codec de normalizacao impressao de eventos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.4.2-expresso1/prototype/services/iCal.php

    r6528 r6891  
    122122                    break; 
    123123 
     124        case TASK_ID: 
     125 
     126            $todo = $ical->newComponent('todo'); 
     127 
     128            $todo->setProperty('summary', $v['summary']); 
     129            $todo->setProperty('description', isset($v['description']) ? $v['description'] : ''); 
     130            $todo->setProperty('priority', $v['priority']); 
     131            $todo->setProperty('percent-complete', $v['percentage']); 
     132            $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 
     133 
     134            $timezone = new DateTimeZone('UTC'); 
     135            $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 
     136            $apTimezoneOBJ = new DateTimeZone($apTimezone); 
     137 
     138            $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 
     139            $sTime->setTimezone($apTimezoneOBJ); 
     140            $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 
     141            $eTime->setTimezone($apTimezoneOBJ); 
     142 
     143            if (isset($v['allDay']) && $v['allDay'] == 1) { 
     144                $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 
     145                $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 
     146                //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 
     147            } else { 
     148                $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
     149                $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
     150                //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 
     151            } 
     152 
     153            if(isset($v['due']) && $v['due'] != ''){ 
     154                $dueTime = new DateTime('@' . (int) ($v['due'] / 1000), $timezone); 
     155                $dueTime->setTimezone($apTimezoneOBJ); 
     156 
     157                $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
     158            } 
     159             
     160            $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
     161                    
     162            if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
     163                $participants = $v['participants']; 
     164            else 
     165                $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 
     166             
     167            if (is_array($participants) && count($participants) > 0) 
     168                foreach ($participants as $ii => $vv) { 
     169                 
     170                    if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 
     171                    { 
     172                        if ($vv['isExternal'] == 1) 
     173                            $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 
     174                        else 
     175                            $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 
     176                    } 
     177                 
     178                    if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
     179                    { 
     180                        $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 
     181                        if(is_array($alarms)) 
     182                            self::createAlarms($alarms, $todo); 
     183                    } 
     184                 
     185                } 
     186             
     187 
     188            if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
     189                $this->createAttendee($v['participants'], $todo); 
     190 
     191            if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 
     192                $this->createAttachment($v['attachments'], $todo); 
     193 
     194            $todo->setProperty('uid', $v['uid']);   
     195             
     196            break; 
     197 
    124198                default: 
    125199                    break; 
     
    219293 
    220294    public function parse($data, $params = false) { 
    221         Config::regSet('noAlarm', TRUE); //Evita o envio de notificação 
     295        Config::regSet('noAlarm', TRUE); //Evita o envio de notificação 
    222296        $vcalendar = new icalCreator( ); 
    223297        $vcalendar->parse(trim($data)); 
     
    232306            $interation = array(); 
    233307            $uid = $component->getProperty('uid', false, false); //Resgata o uid do componente 
     308             
     309            ob_start(); 
     310            print_r(strtoupper($component->objName)); 
     311            $output = ob_get_clean(); 
     312            file_put_contents( "/tmp/acoutinho.log",  $output , FILE_APPEND); 
     313         
    234314 
    235315            switch (strtoupper($component->objName)) { 
     
    238318                    switch ($method) { 
    239319                        case 'PUBLISH': 
    240                             //Caso o evento não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 
     320                            //Caso o evento não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 
    241321                            if (!$schedulable = self::_getSchedulable($uid)) 
    242322                                $interation = self::_makeVEVENT($schedulable, $component, $params); 
     
    273353                                    } 
    274354 
    275                                     Config::regSet('noAlarm', FALSE); //reativa notificação 
     355                                    Config::regSet('noAlarm', FALSE); //reativa notificação 
    276356                                } else { 
    277357 
    278                                     if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     358                                    if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
    279359                                        $interation = self::_makeVEVENT($schedulable, $component, $params); 
    280360                                    else if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) { 
    281361                                        //Ler melhor rfc sobre isto 3.2.2.2 
    282                                         //Aparentemente é para retornar um ical com o evento atualizado para o attende 
     362                                        //Aparentemente é para retornar um ical com o evento atualizado para o attende 
    283363                                    } 
    284364 
     
    289369                                        }else 
    290370                                            $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 
    291                                         //Verifica a importação de eventos em que não participo 
     371                                        //Verifica a importação de eventos em que não participo 
    292372                                        if ($pID) { 
    293373                                            $interation['participant://' . $pID]['status'] = $params['status']; 
     
    298378                                $interation = self::_makeVEVENT(array(), $component, $params); 
    299379 
    300                                 if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 
     380                                if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 
    301381 
    302382                                    /* Data de Inicio */ 
     
    316396                                        $sc['allDay'] = 1; 
    317397                                        $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 
    318                                     } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz']))/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     398                                    } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz']))/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    319399                                        $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000'; 
    320400                                    else { 
    321401                                        $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
    322402                                        if (strpos($params['prodid'], 'Outlook') !== false) { 
    323                                             //Se o ics veio em utc não aplicar horario de verão 
     403                                            //Se o ics veio em utc não aplicar horario de verão 
    324404                                            $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC')); 
    325405                                            $sTime->setTimezone($objTimezone); 
    326                                             if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     406                                            if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
    327407                                                $sc['startTime'] = $sc['startTime'] - 3600000; 
    328408                                        } 
     
    335415                                    if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 
    336416                                        $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 
    337                                     else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     417                                    else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    338418                                        $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000'; 
    339419                                    else { 
    340420                                        $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
    341421                                        if (strpos($params['prodid'], 'Outlook') !== false) { 
    342                                             //Se o ics veio em utc não aplicar horario de verão 
     422                                            //Se o ics veio em utc não aplicar horario de verão 
    343423                                            $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC')); 
    344424                                            $eTime->setTimezone($objTimezone); 
     
    527607                            else // Importar evento 
    528608                                $interation = self::_makeVEVENT(array(), $component, $params); 
    529  
    530  
    531  
    532609                            break; 
    533610                    } 
     
    536613                    $return[] = $interation; 
    537614                    break; 
    538                 case 'VTIMEZONE': 
    539  
    540  
    541                     break; 
     615                /***********************************************************************TODO*******************************************************************************/ 
     616        case 'VTODO': 
     617        switch ($method) { 
     618            case 'PUBLISH': 
     619                //Caso a tarefa não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 
     620                if (!$schedulable = self::_getSchedulable($uid)) 
     621                    $interation = self::_makeVEVENT($schedulable, $component, $params); 
     622                else{ 
     623                    $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 
     624                    array('AND', 
     625                        array('=', 'calendar', $params['calendar']), 
     626                        array('=', 'schedulable', $schedulable['id']) 
     627                    ))); 
     628 
     629                    if(!$links &&  !isset($links[0])) 
     630                        Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id'])); 
     631                } 
     632                break; 
     633 
     634            case 'REQUEST': 
     635                $schedulable = self::_getSchedulable($uid); 
     636 
     637                if ($schedulable) { //Caso tarefa exista 
     638                    if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 
     639                         
     640                        $calendarToSchedulable = array(); 
     641                        $calendarToSchedulable['calendar'] = $params['calendar']; 
     642                        $calendarToSchedulable['schedulable'] = $schedulable['id']; 
     643                        $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 
     644         
     645                        if (isset($params['status'])) { 
     646                            if($params['owner'] != Config::me("uidNumber")){                         
     647                                $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) );                         
     648                                $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 
     649                            }else 
     650                                $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 
     651                                $interation['participant://' . $pID]['status'] = $params['status']; 
     652                        } 
     653                        Config::regSet('noAlarm', FALSE); //reativa notificação 
     654                    } else { 
     655 
     656                        if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     657                            $interation = self::_makeVEVENT($schedulable, $component, $params); 
     658                        else if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) { 
     659                        //Ler melhor rfc sobre isto 3.2.2.2 
     660                        //Aparentemente é para retornar um ical com o evento atualizado para o attende 
     661                        } 
     662 
     663                        if (isset($params['status'])) { 
     664                            if($params['owner'] != Config::me("uidNumber")){                         
     665                               $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) );                      
     666                                $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 
     667                            }else 
     668                                $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 
     669                            //Verifica a importação de eventos em que não participo 
     670                            if ($pID) { 
     671                                $interation['participant://' . $pID]['status'] = $params['status']; 
     672                            } 
     673                        } 
     674                    } 
     675                } else { // Importar tarefa 
     676                    $interation = self::_makeVEVENT(array(), $component, $params); 
     677 
     678                    if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 
     679 
     680                        /* Data de Inicio */ 
     681                        $startTime = $component->getProperty('dtstart', false, true); 
     682                        $tzid = isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 
     683 
     684                        /* Tiem zone do evento */    
     685                        if ($tzid) 
     686                            $sc['timezone'] = self::nomalizeTZID($tzid); 
     687                        else 
     688                            $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 
     689 
     690                        $objTimezone = new DateTimeZone($sc['timezone']); 
     691 
     692                        if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 
     693                            $sc['allDay'] = 1; 
     694                            $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 
     695                        } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz']))/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     696                            $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000'; 
     697                        else { 
     698                            $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
     699                            if (strpos($params['prodid'], 'Outlook') !== false) { 
     700                                //Se o ics veio em utc não aplicar horario de verão 
     701                                $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC')); 
     702                                $sTime->setTimezone($objTimezone); 
     703                                if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     704                                $sc['startTime'] = $sc['startTime'] - 3600000; 
     705                            } 
     706                        } 
     707 
     708                        /* Data de Termino */ 
     709                        $endTime = $component->getProperty('dtend', false, true); 
     710 
     711                        if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 
     712                            $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 
     713                        else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     714                            $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000'; 
     715                        else { 
     716                            $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
     717                            if (strpos($params['prodid'], 'Outlook') !== false) { 
     718                                //Se o ics veio em utc não aplicar horario de verão 
     719                                $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC')); 
     720                                $eTime->setTimezone($objTimezone); 
     721                                if ($eTime->format('I')) 
     722                                    $sc['endTime'] = $sc['endTime'] - 3600000; 
     723                            } 
     724                        } 
     725 
     726 
     727                        if ($uid = $component->getProperty('uid', false, false))                     
     728                            $sc['uid'] = $uid; 
     729 
     730                        $sc['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'UTF-8', 'UTF-8,ISO-8859-1'); 
     731 
     732                        /* Definindo Description */ 
     733                        if ($desc = $component->getProperty('description', false, false)) 
     734                            $sc['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'UTF-8', 'UTF-8,ISO-8859-1'); 
     735 
     736            if ($priority = $component->getProperty('priority', false, false)) 
     737                $sc['priority'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $priority), 'UTF-8', 'UTF-8,ISO-8859-1'); 
     738 
     739            if ($status = $component->getProperty('status', false, false)) 
     740                $sc['status'] = $this->decodeStatusTodo(mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $status), 'UTF-8', 'UTF-8,ISO-8859-1')); 
     741 
     742            if ($percentage = $component->getProperty('percent-complete', false, false)) 
     743                $sc['percentage'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $percentage), 'UTF-8', 'UTF-8,ISO-8859-1'); 
     744 
     745            $todo->setProperty('priority', $v['priority']); 
     746            $todo->setProperty('percent-complete', $v['percentage']); 
     747            $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 
     748 
     749                        /* Definindo location */ 
     750                        if ($location = $component->getProperty('location', false, false)) 
     751                            $sc['location'] = mb_convert_encoding($location, 'UTF-8', 'UTF-8,ISO-8859-1'); 
     752 
     753 
     754 
     755                        if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 
     756                            $participant = array(); 
     757                            $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
     758 
     759                            $participantID = mt_rand() . '2(Formatter)'; 
     760 
     761                            $participant['isOrganizer'] = '1'; 
     762 
     763                            $user = null; 
     764 
     765                            $participant['isExternal'] = 1; 
     766                            /* Gera um randon id para o contexto formater */ 
     767                            $userID = mt_rand() . '4(Formatter)'; 
     768 
     769                            $user['mail'] = $mailUser; 
     770                            $organizerMail = $mailUser; 
     771 
     772                            $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 
     773                            $user['isExternal'] = '1'; 
     774                            $participant['user'] = $user; 
     775 
     776                            $sc['participants'][] = $participant; 
     777                        } 
     778 
     779 
     780                        $participant['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 
     781                        $participant['isOrganizer'] = '0'; 
     782                        $participant['isExternal'] = 0; 
     783                        $participant['user'] = array('mail' => Config::me('mail'), 'name' => Config::me('cn')); 
     784                        $sc['participants'][] = $participant; 
     785                        $sc['type'] = TODO_ID; 
     786 
     787 
     788                        $ical['source'] = Controller::format(array('service' => 'iCal'), array($sc), array('method' => 'REPLY')); 
     789                        $ical['type'] = 'application/ics'; 
     790                        $ical['name'] = 'outlook.ics'; 
     791 
     792                        $ical2['source'] = $ical['source']; 
     793                        $ical2['type'] = 'text/calendar; method=REPLY'; 
     794                        $ical2['name'] = 'thunderbird.ics'; 
     795 
     796                        $timezone = new DateTimeZone('UTC'); 
     797                        $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), $timezone); 
     798                        $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), $timezone); 
     799 
     800                        if (isset($sc['timezone'])) { 
     801                            $sTime->setTimezone(new DateTimeZone($sc['timezone'])); 
     802                            $eTime->setTimezone(new DateTimeZone($sc['timezone'])); 
     803                        } 
     804 
     805                        $data = array('startDate' => date_format($sTime, 'd/m/Y'), 
     806                        'startTime' => (isset($sc['allDay']) && $sc['allDay'] ) ? '' : date_format($sTime, 'H:i'), 
     807                        'endDate' => date_format($eTime, 'd/m/Y'), 
     808                        'endTime' => isset($sc['allDay']) ? '' : date_format($eTime, 'H:i'), 
     809                        'eventTitle' => $sc['summary'], 
     810                        'eventLocation' => isset($sc['location']) ? $sc['location'] : '', 
     811                        'timezone' => ($sc['timezone']) ? $sc['timezone'] : 'UTC', 
     812                        'participant' => (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail'])); 
     813 
     814                        $subject['notificationType'] = 'Convite Aceito'; 
     815                        $subject['eventTitle'] = mb_convert_encoding($sc['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8'); 
     816                        $subject['startDate'] = date_format($sTime, 'd/m/Y'); 
     817                        $subject['startTime'] = ($sc['allDay']) ? '' : date_format($sTime, 'H:i'); 
     818                        $subject['endDate'] = date_format($eTime, 'd/m/Y'); 
     819                        $subject['endTime'] = ($sc['allDay']) ? '' : date_format($eTime, 'H:i'); 
     820                        $subject['participant'] = Config::me('uid'); 
     821 
     822                        $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 
     823 
     824                        switch ($params['status']) { 
     825                            case STATUS_ACCEPTED: 
     826                                $tpl = 'notify_accept_body'; 
     827                                $subject['notificationType'] = 'Convite Aceito'; 
     828                                break; 
     829                            case STATUS_TENTATIVE: 
     830                                $tpl = 'notify_attempt_body'; 
     831                                $subject['notificationType'] = 'Convite  aceito provisoriamente'; 
     832                                break; 
     833                            case STATUS_CANCELLED: 
     834                                $tpl = 'notify_reject_body'; 
     835                                $subject['notificationType'] = 'Convite rejeitado'; 
     836                                break; 
     837                        } 
     838 
     839                        require_once ROOTPATH . '/api/parseTPL.php'; 
     840 
     841                        $mail = array(); 
     842                        $mail['attachments'][] = $ical; 
     843                        $mail['attachments'][] = $ical2; 
     844 
     845                        $mail['isHtml'] = true; 
     846                        $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $tpl . '.tpl'); 
     847                        $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); 
     848 
     849                        $mail['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; 
     850                        $mail['to'] = $organizerMail; 
     851 
     852 
     853                        Controller::create(array('service' => 'SMTP'), $mail); 
     854                    } 
     855                } 
     856                break; 
     857 
     858            case 'REFRESH': 
     859                break; 
     860 
     861            case 'CANCEL': 
     862                if ($schedulable = self::_getSchedulable($uid)) 
     863                    $interation['schedulable://' . $schedulable['id']] = false; 
     864                break; 
     865 
     866            case 'ADD': 
     867                break; 
     868 
     869            case 'REPLY': 
     870                if ($schedulable = self::_getSchedulable($uid)) { 
     871                    while ($property = $component->getProperty('attendee', FALSE, TRUE)) 
     872                        if ($pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) 
     873                            $interation['participant://' . $pID] = array('id' => $pID, 'status' => constant('STATUS_' . strtoupper($property['params']['PARTSTAT']))); 
     874 
     875                    $interation['schedulable://' . $schedulable['id']]['sequence'] = $schedulable['sequence'] + 1; 
     876                } 
     877                break; 
     878 
     879            case 'COUNTER': 
     880                if ($params['acceptedSuggestion'] !== 'false') { 
     881 
     882                    $schedulable = self::_getSchedulable($uid); 
     883                    $params['calendar'] = self::_existInMyCalendars($schedulable['id'], $params['owner']); 
     884 
     885                    $interation = self::_makeCOUNTER($schedulable, $component, $params); 
     886                    Config::regSet('noAlarm', FALSE); 
     887                } else { 
     888                    $response = array(); 
     889                    $response['from'] = $params['from']; 
     890                    $response['type'] = 'suggestionResponse'; 
     891                    $response['status'] = 'DECLINECOUNTER'; 
     892                    $response['schedulable'] = self::_getSchedulable($uid); 
     893 
     894                    Controller::create(array('concept' => 'notification'), $response); 
     895                } 
     896                break; 
     897 
     898            case 'DECLINECOUNTER': 
     899                break; 
     900 
     901            default: 
     902 
     903                $schedulable = self::_getSchedulable($uid); 
     904 
     905                if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) { //Caso o evento exista 
     906                    $interation = self::_makeVEVENT($schedulable, $component, $params); 
     907 
     908                    if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 
     909                        $calendarToSchedulable = array(); 
     910                        $calendarToSchedulable['calendar'] = $params['calendar']; 
     911                        $calendarToSchedulable['schedulable'] = $schedulable['id']; 
     912                        $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 
     913                    } 
     914                } 
     915                else // Importar evento 
     916                $interation = self::_makeVEVENT(array(), $component, $params); 
     917 
     918                break; 
     919            } 
     920     
     921            $return[] = $interation; 
     922        break; 
     923        /***********************************************************************TODO*******************************************************************************/ 
     924        case 'VTIMEZONE': 
     925                break; 
    542926            } 
    543927        } 
     
    556940            $interation = array(); 
    557941            $uid = $component->getProperty('uid', false, false); //Resgata o uid do componente 
    558  
    559942            switch (strtoupper($component->objName)) { 
    560943                case 'VEVENT': 
     
    583966                                        } 
    584967                                    } else { 
    585                                         if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     968                                        if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
    586969                                            $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 
    587970                                        else 
     
    6491032                    $return[$uid] = $interation; 
    6501033                    break; 
     1034                case 'VTODO': 
     1035                    switch ($method) { 
     1036                        case 'PUBLISH': 
     1037                            $interation = ICAL_ACTION_IMPORT; 
     1038                            break; 
     1039 
     1040                        case 'REQUEST': 
     1041                            $schedulable = self::_getSchedulable($uid); 
     1042                            
     1043                            if ($schedulable) { //Caso o evento exista 
     1044                                $isOrganizer = false; 
     1045                                $isParticipant = false; 
     1046 
     1047                                foreach ($schedulable['participants'] as $value) 
     1048                                    if ($value['user']['id'] == $params['owner']) { 
     1049                                        $isParticipant = true; 
     1050                                        if ($value['isOrganizer']) 
     1051                                            $isOrganizer = true; 
     1052 
     1053                                        if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 
     1054                                             
     1055                                            ob_start(); 
     1056                                            print_r($schedulable['id']); 
     1057                                            print_r( $params['owner']); 
     1058                                            $output = ob_get_clean(); 
     1059                                            file_put_contents( "/tmp/acoutinho.log",  $output , FILE_APPEND); 
     1060                                             
     1061                                            $interation = ICAL_ACTION_IMPORT; 
     1062                                            break; 
     1063                                        } 
     1064                                    } else { 
     1065                                        if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     1066                                            $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 
     1067                                        else 
     1068                                            $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE; 
     1069                                    } 
     1070                                if (!$isParticipant){ 
     1071                                      $interation = self::_checkParticipantByPermissions($schedulable); 
     1072                                    } 
     1073                            }else 
     1074                                $interation = ICAL_ACTION_IMPORT; 
     1075                            break; 
     1076 
     1077                        case 'REFRESH': 
     1078                            break; 
     1079 
     1080                        case 'CANCEL': 
     1081                            $interation = ICAL_ACTION_DELETE; 
     1082                            break; 
     1083 
     1084                        case 'ADD': 
     1085                            break; 
     1086 
     1087                        case 'REPLY': 
     1088                            $interation = ICAL_ACTION_REPLY; 
     1089                            break; 
     1090 
     1091                        case 'COUNTER': 
     1092                            $interation = ICAL_ACTION_SUGGESTION; 
     1093                            break; 
     1094 
     1095                        case 'DECLINECOUNTER': 
     1096                            $interation = ICAL_ACTION_NONE; 
     1097                            break; 
     1098 
     1099                        default: 
     1100                            $schedulable = self::_getSchedulable($uid); 
     1101 
     1102                            if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) //Caso o evento exista 
     1103                                $interation = ICAL_ACTION_UPDATE; 
     1104                            else if ($schedulable) 
     1105                                $interation = ICAL_ACTION_NONE; 
     1106                            else // Importar evento 
     1107                                $interation = ICAL_ACTION_IMPORT; 
     1108 
     1109                            break; 
     1110                    } 
     1111 
     1112                    $return[$uid] = $interation; 
     1113                    break; 
    6511114                case 'VTIMEZONE': 
    652  
    653  
    654                     break; 
     1115                break; 
    6551116            } 
    6561117        } 
     
    6901151    } 
    6911152 
     1153    public function decodeStatusTodo( $action ) 
     1154    { 
     1155     $a = array( 
     1156        'NEED_ACTION' => STATUS_TODO_NEED_ACTION, 
     1157        'IN_PROGRESS' => STATUS_TODO_IN_PROGRESS  , 
     1158        'COMPLETED' =>  STATUS_TODO_COMPLETED , 
     1159        'CANCELLED'  => STATUS_TODO_CANCELLED 
     1160    ); 
     1161 
     1162    return isset($a[$id]) ? $a[$id] : 'STATUS_TODO_NEED_ACTION'; 
     1163     
     1164    } 
     1165 
     1166 
     1167    private function _getStatusTodo($id) { 
     1168        $a = array( 
     1169            STATUS_TODO_NEED_ACTION => 'NEED_ACTION', 
     1170            STATUS_TODO_IN_PROGRESS => 'IN_PROGRESS', 
     1171            STATUS_TODO_COMPLETED => 'COMPLETED', 
     1172            STATUS_TODO_CANCELLED => 'CANCELLED' 
     1173        ); 
     1174 
     1175    return isset($a[$id]) ? $a[$id] : 'NEED_ACTION'; 
     1176    } 
     1177 
    6921178    private static function _checkParticipantByPermissions($schedulable) { 
    6931179 
     
    7681254            $schedulable['allDay'] = 1; 
    7691255            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 
    770         } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1256        } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    7711257            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID'], '@' . self::date2timestamp($startTime['value'])) . '000'; 
    7721258            $schedulable['allDay'] = 0; 
     
    7741260            $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
    7751261            if (strpos($params['prodid'], 'Outlook') !== false) { 
    776                 //Se o ics veio em utc não aplicar horario de verão 
     1262                //Se o ics veio em utc não aplicar horario de verão 
    7771263                $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 
    7781264                $sTime->setTimezone($objTimezone); 
    779                 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     1265                if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
    7801266                    $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 
    7811267            } 
     
    7871273        if ($endTime['params']['VALUE'] === 'DATE') 
    7881274            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 
    789         else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1275        else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    7901276            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID'], '@' . self::date2timestamp($endTime['value'])) . '000'; 
    7911277        else { 
    7921278            $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
    7931279            if (strpos($params['prodid'], 'Outlook') !== false) { 
    794                 //Se o ics veio em utc não aplicar horario de verão 
     1280                //Se o ics veio em utc não aplicar horario de verão 
    7951281                $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 
    7961282                $eTime->setTimezone($objTimezone); 
     
    8261312            $schedulable['allDay'] = 1; 
    8271313            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 
    828         } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1314        } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    8291315            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 
    8301316            $schedulable['allDay'] = 0; 
     
    8321318            $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
    8331319            if (strpos($params['prodid'], 'Outlook') !== false) { 
    834                 //Se o ics veio em utc não aplicar horario de verão 
     1320                //Se o ics veio em utc não aplicar horario de verão 
    8351321                $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 
    8361322                $sTime->setTimezone($objTimezone); 
    837                 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     1323                if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
    8381324                    $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 
    8391325            } 
     
    8501336        if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 
    8511337            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 
    852         else if ($tzid && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1338        else if ($tzid && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    8531339            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 
    8541340        else { 
    8551341            $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
    8561342            if (strpos($params['prodid'], 'Outlook') !== false) { 
    857                 //Se o ics veio em utc não aplicar horario de verão 
     1343                //Se o ics veio em utc não aplicar horario de verão 
    8581344                $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 
    8591345                $eTime->setTimezone($objTimezone); 
     
    8801366            $schedulable['class'] = constant(strtoupper('CLASS_' . $class)); 
    8811367        else if (!isset($schedulable['class'])) 
    882             $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 
     1368            $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 
    8831369 
    8841370        /* Definindo RRULE */ 
     
    9061392        $participantsInEvent = array(); 
    9071393 
    908         //TODO: Participants com delegated não estao sendo levados em conta 
     1394        //TODO: Participants com delegated não estao sendo levados em conta 
    9091395        while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 
    9101396            $participant = array(); 
     
    9231409            $participant['isOrganizer'] = '0'; 
    9241410 
    925             /* Verifica se este usuario é um usuario interno do ldap */ 
     1411            /* Verifica se este usuario é um usuario interno do ldap */ 
    9261412            $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 
    9271413 
     
    9581444            $participant['acl'] = 'rowi'; 
    9591445 
    960             /* Verifica se este usuario é um usuario interno do ldap */ 
     1446            /* Verifica se este usuario é um usuario interno do ldap */ 
    9611447            $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 
    9621448 
     
    9801466            $interation['participant://' . $participantID] = $participant; 
    9811467            $schedulable['participants'][] = $participantID; 
    982         } else if (!is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 
     1468        } else if (!is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 
    9831469            $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 
    9841470 
     
    10941580 
    10951581    static private function _existInMyCalendars($id, $owner) { 
    1096         $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'user', $owner), array('=', 'isOwner', '1')))); 
     1582        $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'isOwner', '1'), array('=', 'user', $owner)))); 
    10971583        $calendars = array(); 
    10981584        foreach ($sig as $val) 
Note: See TracChangeset for help on using the changeset viewer.