Index: /branches/2.4/prototype/services/iCal.php
===================================================================
--- /branches/2.4/prototype/services/iCal.php	(revision 6754)
+++ /branches/2.4/prototype/services/iCal.php	(revision 6826)
@@ -16,118 +16,215 @@
     static $suportedTimzones = array('Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara', 'Africa/Asmera', 'Africa/Bamako', 'Africa/Bangui', 'Africa/Banjul', 'Africa/Bissau', 'Africa/Blantyre', 'Africa/Brazzaville', 'Africa/Bujumbura', 'Africa/Cairo', 'Africa/Casablanca', 'Africa/Ceuta', 'Africa/Conakry', 'Africa/Dakar', 'Africa/Dar_es_Salaam', 'Africa/Djibouti', 'Africa/Douala', 'Africa/El_Aaiun', 'Africa/Freetown', 'Africa/Gaborone', 'Africa/Harare', 'Africa/Johannesburg', 'Africa/Kampala', 'Africa/Khartoum', 'Africa/Kigali', 'Africa/Kinshasa', 'Africa/Lagos', 'Africa/Libreville', 'Africa/Lome', 'Africa/Luanda', 'Africa/Lubumbashi', 'Africa/Lusaka', 'Africa/Malabo', 'Africa/Maputo', 'Africa/Maseru', 'Africa/Mbabane', 'Africa/Mogadishu', 'Africa/Monrovia', 'Africa/Nairobi', 'Africa/Ndjamena', 'Africa/Niamey', 'Africa/Nouakchott', 'Africa/Ouagadougou', 'Africa/Porto-Novo', 'Africa/Sao_Tome', 'Africa/Timbuktu', 'Africa/Tripoli', 'Africa/Tunis', 'Africa/Windhoek', 'America/Adak', 'America/Anchorage', 'America/Anguilla', 'America/Antigua', 'America/Araguaina', 'America/Argentina/Buenos_Aires', 'America/Argentina/Catamarca', 'America/Argentina/ComodRivadavia', 'America/Argentina/Cordoba', 'America/Argentina/Jujuy', 'America/Argentina/La_Rioja', 'America/Argentina/Mendoza', 'America/Argentina/Rio_Gallegos', 'America/Argentina/Salta', 'America/Argentina/San_Juan', 'America/Argentina/San_Luis', 'America/Argentina/Tucuman', 'America/Argentina/Ushuaia', 'America/Aruba', 'America/Asuncion', 'America/Atikokan', 'America/Atka', 'America/Bahia', 'America/Barbados', 'America/Belem', 'America/Belize', 'America/Blanc-Sablon', 'America/Boa_Vista', 'America/Bogota', 'America/Boise', 'America/Buenos_Aires', 'America/Cambridge_Bay', 'America/Campo_Grande', 'America/Cancun', 'America/Caracas', 'America/Catamarca', 'America/Cayenne', 'America/Cayman', 'America/Chicago', 'America/Chihuahua', 'America/Coral_Harbour', 'America/Cordoba', 'America/Costa_Rica', 'America/Cuiaba', 'America/Curacao', 'America/Danmarkshavn', 'America/Dawson_Creek', 'America/Dawson', 'America/Denver', 'America/Detroit', 'America/Dominica', 'America/Edmonton', 'America/Eirunepe', 'America/El_Salvador', 'America/Ensenada', 'America/Fort_Wayne', 'America/Fortaleza', 'America/Glace_Bay', 'America/Godthab', 'America/Goose_Bay', 'America/Grand_Turk', 'America/Grenada', 'America/Guadeloupe', 'America/Guatemala', 'America/Guayaquil', 'America/Guyana', 'America/Halifax', 'America/Havana', 'America/Hermosillo', 'America/Indiana/Indianapolis', 'America/Indiana/Knox', 'America/Indiana/Marengo', 'America/Indiana/Petersburg', 'America/Indiana/Tell_City', 'America/Indiana/Vevay', 'America/Indiana/Vincennes', 'America/Indiana/Winamac', 'America/Indianapolis', 'America/Inuvik', 'America/Iqaluit', 'America/Jamaica', 'America/Jujuy', 'America/Juneau', 'America/Kentucky/Louisville', 'America/Kentucky/Monticello', 'America/Knox_IN', 'America/La_Paz', 'America/Lima', 'America/Los_Angeles', 'America/Louisville', 'America/Maceio', 'America/Managua', 'America/Manaus', 'America/Marigot', 'America/Martinique', 'America/Matamoros', 'America/Mazatlan', 'America/Mendoza', 'America/Menominee', 'America/Merida', 'America/Mexico_City', 'America/Miquelon', 'America/Moncton', 'America/Monterrey', 'America/Montevideo', 'America/Montreal', 'America/Montserrat', 'America/Nassau', 'America/New_York', 'America/Nipigon', 'America/Nome', 'America/Noronha', 'America/North_Dakota/Center', 'America/North_Dakota/New_Salem', 'America/Ojinaga', 'America/Panama', 'America/Pangnirtung', 'America/Paramaribo', 'America/Phoenix', 'America/Port_of_Spain', 'America/Port-au-Prince', 'America/Porto_Acre', 'America/Porto_Velho', 'America/Puerto_Rico', 'America/Rainy_River', 'America/Rankin_Inlet', 'America/Recife', 'America/Regina', 'America/Resolute', 'America/Rio_Branco', 'America/Rosario', 'America/Santa_Isabel', 'America/Santarem', 'America/Santiago', 'America/Santo_Domingo', 'America/Sao_Paulo', 'America/Scoresbysund', 'America/Shiprock', 'America/St_Barthelemy', 'America/St_Johns', 'America/St_Kitts', 'America/St_Lucia', 'America/St_Thomas', 'America/St_Vincent', 'America/Swift_Current', 'America/Tegucigalpa', 'America/Thule', 'America/Thunder_Bay', 'America/Tijuana', 'America/Toronto', 'America/Tortola', 'America/Vancouver', 'America/Virgin', 'America/Whitehorse', 'America/Winnipeg', 'America/Yakutat', 'America/Yellowknife', 'Antarctica/Casey', 'Antarctica/Davis', 'Antarctica/DumontDUrville', 'Antarctica/Macquarie', 'Antarctica/Mawson', 'Antarctica/McMurdo', 'Antarctica/Palmer', 'Antarctica/Rothera', 'Antarctica/South_Pole', 'Antarctica/Syowa', 'Antarctica/Vostok', 'Arctic/Longyearbyen', 'Asia/Aden', 'Asia/Almaty', 'Asia/Amman', 'Asia/Anadyr', 'Asia/Aqtau', 'Asia/Aqtobe', 'Asia/Ashgabat', 'Asia/Ashkhabad', 'Asia/Baghdad', 'Asia/Bahrain', 'Asia/Baku', 'Asia/Bangkok', 'Asia/Beirut', 'Asia/Bishkek', 'Asia/Brunei', 'Asia/Calcutta', 'Asia/Choibalsan', 'Asia/Chongqing', 'Asia/Chungking', 'Asia/Colombo', 'Asia/Dacca', 'Asia/Damascus', 'Asia/Dhaka', 'Asia/Dili', 'Asia/Dubai', 'Asia/Dushanbe', 'Asia/Gaza', 'Asia/Harbin', 'Asia/Ho_Chi_Minh', 'Asia/Hong_Kong', 'Asia/Hovd', 'Asia/Irkutsk', 'Asia/Istanbul', 'Asia/Jakarta', 'Asia/Jayapura', 'Asia/Jerusalem', 'Asia/Kabul', 'Asia/Kamchatka', 'Asia/Karachi', 'Asia/Kashgar', 'Asia/Kathmandu', 'Asia/Katmandu', 'Asia/Kolkata', 'Asia/Krasnoyarsk', 'Asia/Kuala_Lumpur', 'Asia/Kuching', 'Asia/Kuwait', 'Asia/Macao', 'Asia/Macau', 'Asia/Magadan', 'Asia/Makassar', 'Asia/Manila', 'Asia/Muscat', 'Asia/Nicosia', 'Asia/Novokuznetsk', 'Asia/Novosibirsk', 'Asia/Omsk', 'Asia/Oral', 'Asia/Phnom_Penh', 'Asia/Pontianak', 'Asia/Pyongyang', 'Asia/Qatar', 'Asia/Qyzylorda', 'Asia/Rangoon', 'Asia/Riyadh', 'Asia/Saigon', 'Asia/Sakhalin', 'Asia/Samarkand', 'Asia/Seoul', 'Asia/Shanghai', 'Asia/Singapore', 'Asia/Taipei', 'Asia/Tashkent', 'Asia/Tbilisi', 'Asia/Tehran', 'Asia/Tel_Aviv', 'Asia/Thimbu', 'Asia/Thimphu', 'Asia/Tokyo', 'Asia/Ujung_Pandang', 'Asia/Ulaanbaatar', 'Asia/Ulan_Bator', 'Asia/Urumqi', 'Asia/Vientiane', 'Asia/Vladivostok', 'Asia/Yakutsk', 'Asia/Yekaterinburg', 'Asia/Yerevan', 'Atlantic/Azores', 'Atlantic/Bermuda', 'Atlantic/Canary', 'Atlantic/Cape_Verde', 'Atlantic/Faeroe', 'Atlantic/Faroe', 'Atlantic/Jan_Mayen', 'Atlantic/Madeira', 'Atlantic/Reykjavik', 'Atlantic/South_Georgia', 'Atlantic/St_Helena', 'Atlantic/Stanley', 'Australia/ACT', 'Australia/Adelaide', 'Australia/Brisbane', 'Australia/Broken_Hill', 'Australia/Canberra', 'Australia/Currie', 'Australia/Darwin', 'Australia/Eucla', 'Australia/Hobart', 'Australia/LHI', 'Australia/Lindeman', 'Australia/Lord_Howe', 'Australia/Melbourne', 'Australia/NSW', 'Australia/North', 'Australia/Perth', 'Australia/Queensland', 'Australia/South', 'Australia/Sydney', 'Australia/Tasmania', 'Australia/Victoria', 'Australia/West', 'Australia/Yancowinna', 'Europe/Amsterdam', 'Europe/Andorra', 'Europe/Athens', 'Europe/Belfast', 'Europe/Belgrade', 'Europe/Berlin', 'Europe/Bratislava', 'Europe/Brussels', 'Europe/Bucharest', 'Europe/Budapest', 'Europe/Chisinau', 'Europe/Copenhagen', 'Europe/Dublin', 'Europe/Gibraltar', 'Europe/Guernsey', 'Europe/Helsinki', 'Europe/Isle_of_Man', 'Europe/Istanbul', 'Europe/Jersey', 'Europe/Kaliningrad', 'Europe/Kiev', 'Europe/Lisbon', 'Europe/Ljubljana', 'Europe/London', 'Europe/Luxembourg', 'Europe/Madrid', 'Europe/Malta', 'Europe/Mariehamn', 'Europe/Minsk', 'Europe/Monaco', 'Europe/Moscow', 'Europe/Nicosia', 'Europe/Oslo', 'Europe/Paris', 'Europe/Podgorica', 'Europe/Prague', 'Europe/Riga', 'Europe/Rome', 'Europe/Samara', 'Europe/San_Marino', 'Europe/Sarajevo', 'Europe/Simferopol', 'Europe/Skopje', 'Europe/Sofia', 'Europe/Stockholm', 'Europe/Tallinn', 'Europe/Tirane', 'Europe/Tiraspol', 'Europe/Uzhgorod', 'Europe/Vaduz', 'Europe/Vatican', 'Europe/Vienna', 'Europe/Vilnius', 'Europe/Volgograd', 'Europe/Warsaw', 'Europe/Zagreb', 'Europe/Zaporozhye', 'Europe/Zurich', 'Indian/Antananarivo', 'Indian/Chagos', 'Indian/Christmas', 'Indian/Cocos', 'Indian/Comoro', 'Indian/Kerguelen', 'Indian/Mahe', 'Indian/Maldives', 'Indian/Mauritius', 'Indian/Mayotte', 'Indian/Reunion', 'Pacific/Apia', 'Pacific/Auckland', 'Pacific/Chatham', 'Pacific/Easter', 'Pacific/Efate', 'Pacific/Enderbury', 'Pacific/Fakaofo', 'Pacific/Fiji', 'Pacific/Funafuti', 'Pacific/Galapagos', 'Pacific/Gambier', 'Pacific/Guadalcanal', 'Pacific/Guam', 'Pacific/Honolulu', 'Pacific/Johnston', 'Pacific/Kiritimati', 'Pacific/Kosrae', 'Pacific/Kwajalein', 'Pacific/Majuro', 'Pacific/Marquesas', 'Pacific/Midway', 'Pacific/Nauru', 'Pacific/Niue', 'Pacific/Norfolk', 'Pacific/Noumea', 'Pacific/Pago_Pago', 'Pacific/Palau', 'Pacific/Pitcairn', 'Pacific/Ponape', 'Pacific/Port_Moresby', 'Pacific/Rarotonga', 'Pacific/Saipan', 'Pacific/Samoa', 'Pacific/Tahiti', 'Pacific/Tarawa', 'Pacific/Tongatapu', 'Pacific/Truk', 'Pacific/Wake', 'Pacific/Wallis', 'Pacific/Yap', 'UTC');
 
-    public function format($data, $params = false) {
-	$timezones = array_flip(self::$timezonesMap);
-
-	$ical = new icalCreator();
-
-	$ical->setProperty('method', isset($params['method']) ? $params['method'] : 'PUBLISH' );
-	$sytemTimezone = (date_default_timezone_get()) ? date_default_timezone_get() : 'America/Sao_Paulo';
-	$params['defaultTZI'] = self::nomalizeTZID((isset($params['defaultTZI']) && $params['defaultTZI'] != 'null') ? $params['defaultTZI'] : $sytemTimezone );
-
-	/*
-	 * Seta propiedades obrigatorias para alguns softwares (Outlook)
-	 */
-	$ical->setProperty('x-wr-calname', 'Calendar Expresso');
-	$ical->setProperty('X-WR-CALDESC', 'Calendar Expresso');
-	$ical->setProperty('X-WR-TIMEZONE', isset($timezones[$params['defaultTZI']]) ? $timezones[$params['defaultTZI']] : $params['defaultTZI']);
-
-	foreach ($data as $i => $v) {
-
-	    switch ($v['type']) {
-		case EVENT_ID:
-		    $vevent = $ical->newComponent('vevent');
-
-		    $vevent->setProperty('summary', $v['summary']);
-		    $vevent->setProperty('description', isset($v['description']) ? $v['description'] : '');
-		    $vevent->setProperty('location', $v['location']);
-		    $vevent->setProperty('tranp', (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ) ? 'TRANSPARENT' : 'OPAQUE' );
-
-		    $timezone = new DateTimeZone('UTC');
-		    $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']);
-		    $apTimezoneOBJ = new DateTimeZone($apTimezone);
-
-		    $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone);
-		    $sTime->setTimezone($apTimezoneOBJ);
-		    $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone);
-		    $eTime->setTimezone($apTimezoneOBJ);
-
-		    if (( isset($v['repeat']) ) && ( $v['repeat']['frequency'] != 'none' )) {
-			$repeat = array();
-
-			foreach ($v['repeat'] as $ir => $rv) {
-			    if ($rv) {
-				if ($ir == 'frequency' && $rv !== 'none')
-				    $repeat['FREQ'] = $rv;
-				else if ($ir == 'endTime') {
-				    $time = new DateTime('@' . (int) ($rv / 1000), $timezone);
-				    $time->setTimezone($apTimezoneOBJ);
-				    $repeat['until'] = $time->format(DATE_RFC822);
-				} else if ($ir == 'count')
-				    $repeat[$ir] = $rv;
-				else if ($ir == 'interval')
-				    $repeat[$ir] = $rv;
-				else if ($ir !== 'schedulable' && $ir !== 'id' && $ir !== 'startTime')
-				    $repeat[$ir] = explode(',', $rv);
+    public function format($data, $params = false)  
+    { 
+                $timezones = array_flip(self::$timezonesMap); 
+                $sytemTimezone = (date_default_timezone_get()) ? date_default_timezone_get() : 'America/Sao_Paulo'; 
+                $params['defaultTZI'] = self::nomalizeTZID((isset($params['defaultTZI']) && $params['defaultTZI'] != 'null') ? $params['defaultTZI'] : $sytemTimezone ); 
+                $params['X-WR-TIMEZONE'] = isset($timezones[$params['defaultTZI']]) ? $timezones[$params['defaultTZI']] : $params['defaultTZI']; 
+                 
+            return (isset($params['compatible']) && $params['compatible']) ? 
+                                        array('ical' => $this->createIcal($data, $params) , 'compatible' => $this->createCompatibleIcal($data, $params)) :  
+                                        $this->createIcal($data, $params); 
+ 
+    } 
+ 
+    protected function createIcal($data, $params = false ) 
+    { 
+        $ical = new icalCreator(); 
+                $ical->setProperty('method', isset($params['method']) ? $params['method'] : 'PUBLISH' ); 
+ 
+                /* 
+                 * Seta propiedades obrigatorias para alguns softwares (Outlook) 
+                 */ 
+                $ical->setProperty('x-wr-calname', 'Calendar Expresso'); 
+                $ical->setProperty('X-WR-CALDESC', 'Calendar Expresso'); 
+                $ical->setProperty('X-WR-TIMEZONE', $params['X-WR-TIMEZONE']); 
+ 
+                foreach ($data as $i => $v) { 
+ 
+                    switch ($v['type']) { 
+                        case EVENT_ID: 
+                            $vevent = $ical->newComponent('vevent'); 
+ 
+                            $vevent->setProperty('summary', $v['summary']); 
+                            $vevent->setProperty('description', isset($v['description']) ? $v['description'] : ''); 
+                            $vevent->setProperty('location', $v['location']); 
+                            $vevent->setProperty('tranp', (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ) ? 'TRANSPARENT' : 'OPAQUE' ); 
+ 
+                            $timezone = new DateTimeZone('UTC'); 
+                            $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 
+                            $apTimezoneOBJ = new DateTimeZone($apTimezone); 
+ 
+                            $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 
+                            $sTime->setTimezone($apTimezoneOBJ); 
+                            $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 
+                            $eTime->setTimezone($apTimezoneOBJ); 
+ 
+                            if (( isset($v['repeat']) ) && ( isset($v['repeat']['frequency']) && $v['repeat']['frequency'] && $v['repeat']['frequency'] != 'none' ))  
+                                    $vevent->setProperty('rrule', $this->formatIcalRepeat($v['repeat'])); 
+                             
+ 
+                            if (isset($v['allDay']) && $v['allDay'] == 1) { 
+                                $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 
+                                $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 
+                                $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 
+                            } else { 
+                                $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
+                                $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
+                                $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 
 			    }
-			}
-
-			if (isset($repeat['FREQ']))
-			    $vevent->setProperty('rrule', $repeat);
+			
+			if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
+                $participants = $v['participants']; 
+            else 
+                        $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 
+             
+                if (is_array($participants) && count($participants) > 0) 
+                        foreach ($participants as $ii => $vv) { 
+                         
+                                if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 
+                                { 
+                                        if ($vv['isExternal'] == 1) 
+                                                $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 
+                                        else 
+                                                $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 
+                                } 
+                         
+                                if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
+                                { 
+                                        $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'])))); 
+                                        if(is_array($alarms)) 
+                                                self::createAlarms($alarms, $vevent); 
+                                } 
+                         
+                        } 
+             
+            if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
+                        $this->createAttendee($v['participants'], $vevent); 
+
+            if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 
+                        $this->createAttachment($v['attachments'], $vevent); 
+
+            $vevent->setProperty('uid', $v['uid']);   
+             
+            break; 
+
+        default: 
+            break;
 		    }
 
-		    if (isset($v['allDay']) && $v['allDay'] == 1) {
-			$vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE"));
-			$vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE"));
-			$vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE');
-		    } else {
-			$vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone));
-			$vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone));
-			$vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE');
+	    }        
+		 
+		         
+                return $ical->createCalendar(); 
+    } 
+ 
+    protected function createCompatibleIcal($data, $params = false ) 
+    { 
+        $ical = new icalCreator(); 
+                $ical->setProperty('method', isset($params['method']) ? $params['method'] : 'PUBLISH' ); 
+ 
+                /* 
+                 * Seta propiedades obrigatorias para alguns softwares (Outlook) 
+                 */ 
+                $ical->setProperty('x-wr-calname', 'Calendar Expresso'); 
+                $ical->setProperty('X-WR-CALDESC', 'Calendar Expresso'); 
+                $ical->setProperty('X-WR-TIMEZONE', $params['X-WR-TIMEZONE']); 
+ 
+                foreach ($data as $i => $v) { 
+ 
+                    switch ($v['type']) { 
+                        case EVENT_ID: 
+                            $vevent = $ical->newComponent('vevent'); 
+ 
+                            $vevent->setProperty('summary', $v['summary']); 
+                            $vevent->setProperty('description', isset($v['description']) ? $v['description'] : ''); 
+                            $vevent->setProperty('location', $v['location']); 
+                            $vevent->setProperty('tranp', (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ) ? 'TRANSPARENT' : 'OPAQUE' ); 
+ 
+                            $timezone = new DateTimeZone('UTC'); 
+                            $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 
+                            $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 
+ 
+                            if (( isset($v['repeat']) ) && ( isset($v['repeat']['frequency']) && $v['repeat']['frequency'] && $v['repeat']['frequency'] != 'none' ))  
+                                    $vevent->setProperty('rrule', $this->formatIcalRepeat($v['repeat'])); 
+ 
+                            if (isset($v['allDay']) && $v['allDay'] == 1) { 
+                                $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 
+                                $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 
+                                $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 
+                            } else { 
+                                $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822)); 
+                                $vevent->setProperty('dtend', $eTime->format(DATE_RFC822)); 
+                                $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 
+                            } 
+                                             
+                            if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
+                                $participants = $v['participants']; 
+                            else 
+                                        $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 
+                             
+                                if (is_array($participants) && count($participants) > 0) 
+                                        foreach ($participants as $ii => $vv) { 
+                                         
+                                                if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 
+                                                { 
+                                                        if ($vv['isExternal'] == 1) 
+                                                                $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 
+                                                        else 
+                                                                $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 
+                                                } 
+                                         
+                                                if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
+                                                { 
+                                                        $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'])))); 
+                                                        if(is_array($alarms)) 
+                                                                self::createAlarms($alarms, $vevent); 
+                                                } 
+                                         
+                                        } 
+                             
+ 
+                            if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
+                                        $this->createAttendee($v['participants'], $vevent); 
+ 
+                            if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 
+                                        $this->createAttachment($v['attachments'], $vevent); 
+ 
+                            $vevent->setProperty('uid', $v['uid']);   
+                             
+                            break; 
+ 
+                        default: 
+                            break; 
 		    }
-		   		    
-		    if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0)
-		    	$participants = $v['participants'];
-		    else
-				$participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id'])));
-		    
-			if (is_array($participants) && count($participants) > 0)
-				foreach ($participants as $ii => $vv) {
-				
-					if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user']))
-					{
-						if ($vv['isExternal'] == 1)
-							$participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL'));
-						else
-							$participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user']));
-					}
-				
-					if ($participants[$ii]['user']['id'] == Config::me('uidNumber'))
-					{
-						$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']))));
-						if(is_array($alarms))
-							self::createAlarms($alarms, $vevent);
-					}
-				
-				}
-		    
-
-		    if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0)
-				$this->createAttendee($v['participants'], $vevent);
-
-		    if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0)
-				$this->createAttachment($v['attachments'], $vevent);
-
-		    $vevent->setProperty('uid', $v['uid']);  
-		    
-		    break;
-
-		default:
-		    break;
-	    }
-	}
+		}
 
 	
-	return $ical->createCalendar();
-    }
+		return $ical->createCalendar(); 
+    } 
+ 
+    protected function formatIcalRepeat($pRepeat) 
+    { 
+        $repeat = array(); 
+ 
+                foreach ($pRepeat as $ir => $rv) { 
+                    if ($rv) { 
+                        if ($ir == 'frequency' && $rv !== 'none') 
+                            $repeat['FREQ'] = $rv; 
+                        else if ($ir == 'endTime') { 
+                            $time = new DateTime('@' . (int) ($rv / 1000), $timezone); 
+                            $time->setTimezone($apTimezoneOBJ); 
+                            $repeat['until'] = $time->format(DATE_RFC822); 
+                        } else if ($ir == 'count') 
+                            $repeat[$ir] = $rv; 
+                        else if ($ir == 'interval') 
+                            $repeat[$ir] = $rv; 
+                        else if ($ir !== 'schedulable' && $ir !== 'id' && $ir !== 'startTime') 
+                            $repeat[$ir] = explode(',', $rv); 
+                    } 
+                } 
+                return $repeat; 
+    } 
     
     public function createAlarms($alarms, &$vevent)
Index: /branches/2.4/prototype/modules/calendar/interceptors/Notifications.php
===================================================================
--- /branches/2.4/prototype/modules/calendar/interceptors/Notifications.php	(revision 6754)
+++ /branches/2.4/prototype/modules/calendar/interceptors/Notifications.php	(revision 6826)
@@ -276,7 +276,5 @@
 	if ((Config::regGet('ical://' . $schedulable['id'] . '/' . $method) === false) || ($method == 'CANCEL')) { //Verifica se o ical ja não esta no reg
 	    $schedulable['URI']['concept'] = 'schedulable';
-	    $ical['source'] = Controller::format(array('service' => 'iCal'), array($schedulable), array('method' => $method));
-	    $ical['type'] = 'text/plain';
-	    $ical['name'] = 'outlook.ics';
+	    $ical = Controller::format(array('service' => 'iCal'), array($schedulable), array('method' => $method , 'compatible' => true ));
 	    if ($regSet)
 		Config::regSet('ical://' . $schedulable['id'] . '/' . $method, $ical);
@@ -429,9 +427,18 @@
      */
     private static function sendMail(&$data, &$ical, $to, &$subject, $template, $from = false) {
-	$ical2 = $ical;
+	
+
+	$ical1['type'] = 'text/plain'; 
+ 	$ical1['source'] = $ical['compatible']; 
+ 	$ical1['name'] = 'outlook.ics'; 
+ 	$ical2['source'] = $ical['ical']; 
 	$ical2['type'] = 'text/calendar';
 	$ical2['name'] = 'thunderbird.ics';
+
+	unset($ical);
 	$mail['attachments'][] = $ical2;
-	$mail['attachments'][] = $ical;
+	$mail['attachments'][] = $ical1; 
+ 	unset($ical1); 
+ 	unset($ical2); 
 	$mail['isHtml'] = true;
 	$mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $template . '.tpl');
