Changeset 5682


Ignore:
Timestamp:
03/08/12 19:17:09 (12 years ago)
Author:
acoutinho
Message:

Ticket #2434 - Correcao na importacao de eventos para participantes convidados

Location:
trunk/prototype
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/calendar/interceptors/DBMapping.php

    r5653 r5682  
    135135                }if(isset($params['endTime'])){ 
    136136                         
    137                         if (!is_numeric($params['endTime'])) 
     137                        if (!is_numeric($params['endTime'])){ 
    138138                                $params['endTime'] =   strtotime( $params['endTime'] . ' ' .$event['timezone']).'000'; 
    139139                                 
    140                         if($event['allDay']) 
    141                                 $params['endTime'] =  $params['endTime']  + 86400000; 
    142                          
     140                                if($event['allDay']) 
     141                                        $params['endTime'] =  $params['endTime']  + 86400000; 
     142                        } 
    143143                        $params['rangeEnd'] = $params['endTime'] ;        
    144144                                 
     
    243243 
    244244                                if(!isset($currentTimezone) || $currentTimezone  != $original['criteria']['timezones'][$v['calendar']]){ 
    245                                         $currentTimezone = $original['criteria']['timezones'][$v['calendar']]; 
     245                                        $currentTimezone = isset($original['criteria']['timezones'][$v['calendar']]) ?  $original['criteria']['timezones'][$v['calendar']] : $v['timezone']; 
    246246                                        $Time->setTimezone(new DateTimeZone($currentTimezone)); 
    247247                                } 
  • trunk/prototype/services/iCal.php

    r5615 r5682  
    201201                                $interation = self::_makeVEVENT( array() , $component , $params); 
    202202                              
     203                                                                                                 if( strpos($params['prodid'], 'kigkonsult.se') !== false ) //envia notificação para fora 
     204                                 { 
     205                                                                        
     206                                          /* Data de Inicio*/ 
     207                                           $startTime = $component->getProperty( 'dtstart', false , true ); 
     208 
     209                                            /* Tiem zone do evento*/     
     210                                            if(isset($startTime['params']['TZID'])) 
     211                                                $sc['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']);  
     212                                            else 
     213                                                $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo';  
     214 
     215                                                $objTimezone =  new DateTimeZone($sc['timezone']);   
     216 
     217                                                if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) 
     218                                                { 
     219                                                    $sc['allDay'] = 1; 
     220                                                    $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$sc['timezone']) . '000'; 
     221                                                } 
     222                                                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 */ 
     223                                                    $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000';       
     224                                                else 
     225                                                { 
     226                                                    $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
     227                                                    if( strpos($params['prodid'], 'Outlook') !== false ) 
     228                                                    { 
     229                                                        //Se o ics veio em utc não aplicar horario de verão 
     230                                                        $sTime = new DateTime( '@'.(int)($sc['startTime'] / 1000) , new DateTimeZone('UTC') );  
     231                                                        $sTime->setTimezone($objTimezone); 
     232                                                        if($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     233                                                        $sc['startTime'] = $sc['startTime'] - 3600000; 
     234                                                    } 
     235                                                } 
     236 
     237 
     238                                            /* Data de Termino*/ 
     239                                                $endTime = $component->getProperty( 'dtend', false , true );  
     240 
     241                                                if($endTime['params']['VALUE'] === 'DATE') 
     242                                                    $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$sc['timezone']) . '000'; 
     243                                                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 */ 
     244                                                    $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000'; 
     245                                                else 
     246                                                { 
     247                                                    $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
     248                                                    if( strpos($params['prodid'], 'Outlook') !== false ) 
     249                                                    { 
     250                                                    //Se o ics veio em utc não aplicar horario de verão 
     251                                                        $eTime = new DateTime( '@'.(int)($sc['endTime'] / 1000)  ,new DateTimeZone('UTC'));  
     252                                                        $eTime->setTimezone($objTimezone); 
     253                                                        if($eTime->format('I'))  
     254                                                            $sc['endTime'] = $sc['endTime'] - 3600000; 
     255                                                    } 
     256                                                }  
     257 
     258                                      
     259                                        if($uid = $component->getProperty( 'uid' , false , false )); 
     260                                             $sc['uid'] = $uid; 
     261                                              
     262                                              
     263                                        $sc['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'UTF-8' , 'UTF-8,ISO-8859-1'); 
     264 
     265                                        /* Definindo Description */ 
     266                                            if($desc = $component->getProperty( 'description' , false , false )) 
     267                                                $sc['description'] = mb_convert_encoding (str_ireplace (array('\n','\t'), array("\n","\t"), $desc) ,'UTF-8' , 'UTF-8,ISO-8859-1'); 
     268 
     269                                        /* Definindo location */ 
     270                                            if($location = $component->getProperty( 'location' , false , false )) 
     271                                            $sc['location'] = mb_convert_encoding ( $location , 'UTF-8' , 'UTF-8,ISO-8859-1') ; 
     272                                             
     273                                               
     274                                             
     275                                        if($property = $component->getProperty('organizer',FALSE , TRUE)) 
     276                                        { 
     277                                            $participant = array(); 
     278                                            $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
     279 
     280                                            $participantID = mt_rand().'2(Formatter)'; 
     281 
     282                                            $participant['schedulable'] = $eventID; 
     283                                            $participant['isOrganizer'] = '1'; 
     284                                      
     285                                            $user = null;     
     286                    
     287                                            $participant['isExternal']  = 1; 
     288                                            /* Gera um randon id para o contexto formater */ 
     289                                                $userID = mt_rand().'4(Formatter)'; 
     290 
     291                                            $user['mail'] = $mailUser; 
     292                                            $organizerMail = $mailUser; 
     293                                             
     294                                            $user['name'] =  ( isset($property['params']['CN']) ) ? $property['params']['CN'] : '';         
     295                                            $user['isExternal'] = '1'; 
     296                                            $participant['user'] = $user; 
     297 
     298                                            $sc['participants'][] = $participant; 
     299 
     300                                        } 
     301                                         
     302                                        $participant['schedulable'] = $eventID; 
     303                                        $participant['status'] = $params['status'] ? $params['status'] : STATUS_ACCEPTED; 
     304                                        $participant['isOrganizer'] = '0'; 
     305                                        $participant['isExternal']  = 0; 
     306                                        $participant['user'] =  array('mail' => Config::me('mail') , 'name' => Config::me('cn')); 
     307                                        $sc['participants'][] = $participant; 
     308                                        $sc['type'] = VEVENT; 
     309                          
     310             
     311                                            $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($sc) , array('method' => 'REPLY'));   
     312                                            $ical['type'] =  'application/ics'; 
     313                                            $ical['name'] = 'outlook.ics'; 
     314                                             
     315                                            $ical2['source'] = $ical['source']; 
     316                                            $ical2['type'] =  'text/calendar; method=REPLY'; 
     317                                            $ical2['name'] = 'thunderbird.ics'; 
     318                                       
     319                                            $timezone = new DateTimeZone('UTC'); 
     320                                            $sTime = new DateTime( '@'.(int)($sc['startTime'] / 1000) , $timezone ); 
     321                                            $eTime =  new DateTime( '@'.(int)($sc['endTime'] / 1000) , $timezone );  
     322 
     323                                            if(isset($sc['timezone'])) 
     324                                            { 
     325                                                $sTime->setTimezone(new DateTimeZone($sc['timezone'])); 
     326                                                $eTime->setTimezone(new DateTimeZone($sc['timezone'])); 
     327                                            } 
     328 
     329                                            $data = array('startDate' =>  date_format( $sTime , 'd/m/Y') , 
     330                                                            'startTime' =>  ($sc['allDay']) ? '' : date_format( $sTime , 'H:i') , 
     331                                                            'endDate' =>  date_format( $eTime , 'd/m/Y') , 
     332                                                            'endTime' =>  ($sc['allDay']) ? '' :  date_format( $eTime , 'H:i') , 
     333                                                            'eventTitle' =>  $sc['summary'], 
     334                                                            'eventLocation' =>  $sc['location'], 
     335                                                            'timezone' =>  ($sc['timezone']) ? $sc['timezone'] : 'UTC' , 
     336                                                            'participant' =>  (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']) ); 
     337 
     338                                            $subject['notificationType'] = 'Convite Aceito'; 
     339                                            $subject['eventTitle'] = mb_convert_encoding($sc['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); 
     340                                            $subject['startDate'] = date_format( $sTime , 'd/m/Y'); 
     341                                            $subject['startTime'] = ($sc['allDay']) ? '' : date_format( $sTime , 'H:i'); 
     342                                            $subject['endDate'] = date_format( $eTime , 'd/m/Y'); 
     343                                            $subject['endTime'] = ($sc['allDay']) ? '' : date_format( $eTime , 'H:i'); 
     344                                            $subject['participant'] = Config::me('uid'); 
     345 
     346                                        switch($param['status']) 
     347                                        { 
     348                                                case STATUS_ACCEPTED: 
     349                                                    $tpl =   'notify_accept_body'; 
     350                                                    $subject['notificationType'] = 'Convite Aceito'; 
     351                                                break; 
     352                                                case STATUS_TENATIVE: 
     353                                                    $tpl =   'notify_attempt_body'; 
     354                                                    $subject['notificationType'] = 'Convite  aceito provisoriamente'; 
     355                                                break; 
     356                                                case STATUS_CANCELLED: 
     357                                                    $tpl =   'notify_reject_body'; 
     358                                                    $subject['notificationType'] = 'Convite rejeitado'; 
     359                                                break; 
     360 
     361                                        } 
     362                                        require_once ROOTPATH.'/api/parseTPL.php'; 
     363                                         
     364                                        $mail = array(); 
     365                                        $mail['attachments'][] = $ical; 
     366                                        $mail['attachments'][] = $ical2; 
     367                                 
     368                                        $mail['isHtml'] = true;                          
     369                                        $mail['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/'.$tpl.'.tpl'); 
     370                                        $mail['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');; 
     371                                        $mail['from'] = Config::me('mail');    
     372                                        $mail['to'] = $organizerMail; 
     373  
     374                                         
     375                                        Controller::create( array( 'service' => 'SMTP' ), $mail );     
     376                                 } 
     377                                                          
    203378                             break;   
    204379                            
     
    747922        static private function _getSchedulable( $uid ) 
    748923        { 
    749            $schedulable =  Controller::find( array( 'concept' => 'schedulable' ) , false , array ( 'filter' => array( '=' , 'uid' , $uid ), 'criteria' => array('deepness' => 2) ));                
     924           $schedulable =  Controller::find( array( 'concept' => 'schedulable' ) , false , array ( 'filter' => array( '=' , 'uid' , $uid ), 'deepness' => 2 ));             
    750925                   return (isset($schedulable[0])) ? $schedulable[0] : false; 
    751926        } 
Note: See TracChangeset for help on using the changeset viewer.