Index: /trunk/prototype/services/iCal.php
===================================================================
--- /trunk/prototype/services/iCal.php	(revision 5615)
+++ /trunk/prototype/services/iCal.php	(revision 5682)
@@ -201,4 +201,179 @@
                                 $interation = self::_makeVEVENT( array() , $component , $params);
                              
+								                                 if( strpos($params['prodid'], 'kigkonsult.se') !== false ) //envia notificação para fora
+                                 {
+                                                                       
+                                          /* Data de Inicio*/
+                                           $startTime = $component->getProperty( 'dtstart', false , true );
+
+                                            /* Tiem zone do evento*/    
+                                            if(isset($startTime['params']['TZID']))
+                                                $sc['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); 
+                                            else
+                                                $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 
+
+                                                $objTimezone =  new DateTimeZone($sc['timezone']);  
+
+                                                if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) )
+                                                {
+                                                    $sc['allDay'] = 1;
+                                                    $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$sc['timezone']) . '000';
+                                                }
+                                                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 */
+                                                    $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000';      
+                                                else
+                                                {
+                                                    $sc['startTime'] = self::date2timestamp($startTime['value']) . '000';
+                                                    if( strpos($params['prodid'], 'Outlook') !== false )
+                                                    {
+                                                        //Se o ics veio em utc não aplicar horario de verão
+                                                        $sTime = new DateTime( '@'.(int)($sc['startTime'] / 1000) , new DateTimeZone('UTC') ); 
+                                                        $sTime->setTimezone($objTimezone);
+                                                        if($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão
+                                                        $sc['startTime'] = $sc['startTime'] - 3600000;
+                                                    }
+                                                }
+
+
+                                            /* Data de Termino*/
+                                                $endTime = $component->getProperty( 'dtend', false , true ); 
+
+                                                if($endTime['params']['VALUE'] === 'DATE')
+                                                    $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$sc['timezone']) . '000';
+                                                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 */
+                                                    $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000';
+                                                else
+                                                {
+                                                    $sc['endTime'] = self::date2timestamp($endTime['value']) . '000';
+                                                    if( strpos($params['prodid'], 'Outlook') !== false )
+                                                    {
+                                                    //Se o ics veio em utc não aplicar horario de verão
+                                                        $eTime = new DateTime( '@'.(int)($sc['endTime'] / 1000)  ,new DateTimeZone('UTC')); 
+                                                        $eTime->setTimezone($objTimezone);
+                                                        if($eTime->format('I')) 
+                                                            $sc['endTime'] = $sc['endTime'] - 3600000;
+                                                    }
+                                                } 
+
+                                     
+                                        if($uid = $component->getProperty( 'uid' , false , false ));
+                                             $sc['uid'] = $uid;
+                                             
+                                             
+                                        $sc['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'UTF-8' , 'UTF-8,ISO-8859-1');
+
+                                        /* Definindo Description */
+                                            if($desc = $component->getProperty( 'description' , false , false ))
+                                                $sc['description'] = mb_convert_encoding (str_ireplace (array('\n','\t'), array("\n","\t"), $desc) ,'UTF-8' , 'UTF-8,ISO-8859-1');
+
+                                        /* Definindo location */
+                                            if($location = $component->getProperty( 'location' , false , false ))
+                                            $sc['location'] = mb_convert_encoding ( $location , 'UTF-8' , 'UTF-8,ISO-8859-1') ;
+                                            
+                                              
+                                            
+                                        if($property = $component->getProperty('organizer',FALSE , TRUE))
+                                        {
+                                            $participant = array();
+                                            $mailUser = trim(str_replace('MAILTO:', '', $property['value']));
+
+                                            $participantID = mt_rand().'2(Formatter)';
+
+                                            $participant['schedulable'] = $eventID;
+                                            $participant['isOrganizer'] = '1';
+                                     
+                                            $user = null;    
+                   
+                                            $participant['isExternal']  = 1;
+                                            /* Gera um randon id para o contexto formater */
+                                                $userID = mt_rand().'4(Formatter)';
+
+                                            $user['mail'] = $mailUser;
+                                            $organizerMail = $mailUser;
+                                            
+                                            $user['name'] =  ( isset($property['params']['CN']) ) ? $property['params']['CN'] : '';        
+                                            $user['isExternal'] = '1';
+                                            $participant['user'] = $user;
+
+                                            $sc['participants'][] = $participant;
+
+                                        }
+                                        
+                                        $participant['schedulable'] = $eventID;
+                                        $participant['status'] = $params['status'] ? $params['status'] : STATUS_ACCEPTED;
+                                        $participant['isOrganizer'] = '0';
+                                        $participant['isExternal']  = 0;
+                                        $participant['user'] =  array('mail' => Config::me('mail') , 'name' => Config::me('cn'));
+                                        $sc['participants'][] = $participant;
+                                        $sc['type'] = VEVENT;
+                         
+            
+                                            $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($sc) , array('method' => 'REPLY'));  
+                                            $ical['type'] =  'application/ics';
+                                            $ical['name'] = 'outlook.ics';
+                                            
+                                            $ical2['source'] = $ical['source'];
+                                            $ical2['type'] =  'text/calendar; method=REPLY';
+                                            $ical2['name'] = 'thunderbird.ics';
+                                      
+                                            $timezone = new DateTimeZone('UTC');
+                                            $sTime = new DateTime( '@'.(int)($sc['startTime'] / 1000) , $timezone );
+                                            $eTime =  new DateTime( '@'.(int)($sc['endTime'] / 1000) , $timezone ); 
+
+                                            if(isset($sc['timezone']))
+                                            {
+                                                $sTime->setTimezone(new DateTimeZone($sc['timezone']));
+                                                $eTime->setTimezone(new DateTimeZone($sc['timezone']));
+                                            }
+
+                                            $data = array('startDate' =>  date_format( $sTime , 'd/m/Y') ,
+                                                            'startTime' =>  ($sc['allDay']) ? '' : date_format( $sTime , 'H:i') ,
+                                                            'endDate' =>  date_format( $eTime , 'd/m/Y') ,
+                                                            'endTime' =>  ($sc['allDay']) ? '' :  date_format( $eTime , 'H:i') ,
+                                                            'eventTitle' =>  $sc['summary'],
+                                                            'eventLocation' =>  $sc['location'],
+                                                            'timezone' =>  ($sc['timezone']) ? $sc['timezone'] : 'UTC' ,
+                                                            'participant' =>  (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']) );
+
+                                            $subject['notificationType'] = 'Convite Aceito';
+                                            $subject['eventTitle'] = mb_convert_encoding($sc['summary'],'ISO-8859-1','ISO-8859-1,UTF-8');
+                                            $subject['startDate'] = date_format( $sTime , 'd/m/Y');
+                                            $subject['startTime'] = ($sc['allDay']) ? '' : date_format( $sTime , 'H:i');
+                                            $subject['endDate'] = date_format( $eTime , 'd/m/Y');
+                                            $subject['endTime'] = ($sc['allDay']) ? '' : date_format( $eTime , 'H:i');
+                                            $subject['participant'] = Config::me('uid');
+
+                                        switch($param['status'])
+                                        {
+                                                case STATUS_ACCEPTED:
+                                                    $tpl =   'notify_accept_body';
+                                                    $subject['notificationType'] = 'Convite Aceito';
+                                                break;
+                                                case STATUS_TENATIVE:
+                                                    $tpl =   'notify_attempt_body';
+                                                    $subject['notificationType'] = 'Convite  aceito provisoriamente';
+                                                break;
+                                                case STATUS_CANCELLED:
+                                                    $tpl =   'notify_reject_body';
+                                                    $subject['notificationType'] = 'Convite rejeitado';
+                                                break;
+
+                                        }
+                                        require_once ROOTPATH.'/api/parseTPL.php';
+                                        
+                                        $mail = array();
+                                        $mail['attachments'][] = $ical;
+                                        $mail['attachments'][] = $ical2;
+                                
+                                        $mail['isHtml'] = true;                         
+                                        $mail['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/'.$tpl.'.tpl');
+                                        $mail['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');;
+                                        $mail['from'] = Config::me('mail');   
+                                        $mail['to'] = $organizerMail;
+ 
+                                        
+                                        Controller::create( array( 'service' => 'SMTP' ), $mail );    
+                                 }
+							 
                              break;  
                            
@@ -747,5 +922,5 @@
         static private function _getSchedulable( $uid )
         {
-           $schedulable =  Controller::find( array( 'concept' => 'schedulable' ) , false , array ( 'filter' => array( '=' , 'uid' , $uid ), 'criteria' => array('deepness' => 2) ));		   
+           $schedulable =  Controller::find( array( 'concept' => 'schedulable' ) , false , array ( 'filter' => array( '=' , 'uid' , $uid ), 'deepness' => 2 ));		   
 		   return (isset($schedulable[0])) ? $schedulable[0] : false;
         }
Index: /trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5653)
+++ /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5682)
@@ -135,10 +135,10 @@
 		}if(isset($params['endTime'])){
 			
-			if (!is_numeric($params['endTime']))
+			if (!is_numeric($params['endTime'])){
 				$params['endTime'] =   strtotime( $params['endTime'] . ' ' .$event['timezone']).'000';
 				
-			if($event['allDay'])
-				$params['endTime'] =  $params['endTime']  + 86400000;
-			
+				if($event['allDay'])
+					$params['endTime'] =  $params['endTime']  + 86400000;
+			}
 			$params['rangeEnd'] = $params['endTime'] ;       
 				
@@ -243,5 +243,5 @@
 
 				if(!isset($currentTimezone) || $currentTimezone  != $original['criteria']['timezones'][$v['calendar']]){
-					$currentTimezone = $original['criteria']['timezones'][$v['calendar']];
+					$currentTimezone = isset($original['criteria']['timezones'][$v['calendar']]) ?  $original['criteria']['timezones'][$v['calendar']] : $v['timezone'];
 					$Time->setTimezone(new DateTimeZone($currentTimezone));
 				}
