'Etc/GMT+12', '(GMT-11.00) Midway Island / Samoa' => 'Pacific/Midway', '(GMT-10.00) Hawaii' => 'Pacific/Honolulu', '(GMT-09.00) Alaska' => 'America/Anchorage', '(GMT-08.00) Pacific Time (US & Canada) / Tijuana' => 'America/Los_Angeles', '(GMT-08.00) Tijuana / Baja California' => 'America/Tijuana', '(GMT-07.00) Arizona' => 'America/Phoenix', '(GMT-07.00) Chihuahua / La Paz / Mazatlan - Old' => 'America/Chihuahua', '(GMT-07.00) Mountain Time (US & Canada)' => 'America/Denver', '(GMT-06.00) Central America' => 'America/Guatemala', '(GMT-06.00) Central Time (US & Canada)' => 'America/Chicago', '(GMT-06.00) Guadalajara / Mexico City / Monterrey - Old' => 'America/Mexico_City', '(GMT-06.00) Saskatchewan' => 'America/Regina', '(GMT-05.00) Bogota / Lima / Quito' => 'America/Bogota', '(GMT-05.00) Eastern Time (US & Canada)' => 'America/New_York', '(GMT-05.00) Indiana (East)' => 'America/Indiana/Indianapolis', '(GMT-04.30) Caracas' => 'America/Caracas', '(GMT-04.00) Atlantic Time (Canada)' => 'America/Halifax', '(GMT-04.00) Georgetown' => 'America/Guyana', '(GMT-04.00) Caracas / La Paz' => 'America/La_Paz', '(GMT-04.00) Manaus' => 'America/Manaus', '(GMT-04.00) Santiago' => 'America/Santiago', '(GMT-03.30) Newfoundland' => 'America/St_Johns', '(GMT-03.00) Brasilia' => 'America/Sao_Paulo', '(GMT-03.00) Buenos Aires / Georgetown' => 'America/Argentina/Buenos_Aires', '(GMT-03.00) Greenland' => 'America/Godthab', '(GMT-03.00) Montevideo' => 'America/Montevideo', '(GMT-02.00) Mid-Atlantic' => 'Atlantic/South_Georgia', '(GMT-01.00) Azores' => 'Atlantic/Azores', '(GMT-01.00) Cape Verde Is.' => 'Atlantic/Cape_Verde', '(GMT) Casablanca' => 'Africa/Casablanca', '(GMT) Greenwich Mean Time - Dublin / Edinburgh / Lisbon / London' => 'Europe/London', '(GMT) Casablanca / Monrovia' => 'Africa/Monrovia', '(GMT+01.00) Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna' => 'Europe/Berlin', '(GMT+01.00) Belgrade / Bratislava / Budapest / Ljubljana / Prague' => 'Europe/Belgrade', '(GMT+01.00) Brussels / Copenhagen / Madrid / Paris' => 'Europe/Brussels', '(GMT+01.00) Sarajevo / Skopje / Warsaw / Zagreb' => 'Europe/Warsaw', '(GMT+01.00) West Central Africa' => 'Africa/Algiers', '(GMT+02.00) Windhoek' => 'Africa/Windhoek', '(GMT+02.00) Amman' => 'Asia/Amman', '(GMT+02.00) Bucharest' => 'Europe/Athens', '(GMT+02.00) Beirut' => 'Asia/Beirut', '(GMT+02.00) Cairo' => 'Africa/Cairo', '(GMT+02.00) Harare / Pretoria' => 'Africa/Harare', '(GMT+02.00) Helsinki / Kyiv / Riga / Sofia / Tallinn / Vilnius' => 'Europe/Helsinki', '(GMT+02.00) Jerusalem' => 'Asia/Jerusalem', '(GMT+02.00) Minsk' => 'Europe/Minsk', '(GMT+03.00) Baghdad' => 'Asia/Baghdad', '(GMT+03.00) Kuwait / Riyadh' => 'Asia/Kuwait', '(GMT+03.00) Moscow / St. Petersburg / Volgograd' => 'Europe/Moscow', '(GMT+03.00) Nairobi' => 'Africa/Nairobi', '(GMT+04.00) Caucasus Standard Time' => 'Asia/Tbilisi', '(GMT+03.30) Tehran' => 'Asia/Tehran', '(GMT+04.00) Abu Dhabi / Muscat' => 'Asia/Muscat', '(GMT+04.00) Baku / Tbilisi / Yerevan' => 'Asia/Baku', '(GMT+04.00) Yerevan' => 'Asia/Yerevan', '(GMT+04.30) Kabul' => 'Asia/Kabul', '(GMT+05.00) Ekaterinburg' => 'Asia/Yekaterinburg', '(GMT+05.00) Islamabad / Karachi / Tashkent' => 'Asia/Karachi', '(GMT+05.00) Tashkent' => 'Asia/Tashkent', '(GMT+05.30) Chennai / Kolkata / Mumbai / New Delhi' => 'Asia/Kolkata', '(GMT+06.00) Sri Jayawardenepura' => 'Asia/Colombo', '(GMT+05.45) Kathmandu' => 'Asia/Katmandu', '(GMT+06.00) Almaty / Novosibirsk' => 'Asia/Novosibirsk', '(GMT+06.00) Astana / Dhaka' => 'Asia/Dhaka', '(GMT+06.30) Rangoon' => 'Asia/Rangoon', '(GMT+07.00) Bangkok / Hanoi / Jakarta' => 'Asia/Bangkok', '(GMT+07.00) Krasnoyarsk' => 'Asia/Krasnoyarsk', '(GMT+08.00) Beijing / Chongqing / Hong Kong / Urumqi' => 'Asia/Hong_Kong', '(GMT+08.00) Irkutsk / Ulaan Bataar' => 'Asia/Irkutsk', '(GMT+08.00) Kuala Lumpur / Singapore' => 'Asia/Kuala_Lumpur', '(GMT+08.00) Perth' => 'Australia/Perth', '(GMT+08.00) Taipei' => 'Asia/Taipei', '(GMT+09.00) Osaka / Sapporo / Tokyo' => 'Asia/Tokyo', '(GMT+09.00) Seoul' => 'Asia/Seoul', '(GMT+09.00) Yakutsk' => 'Asia/Yakutsk', '(GMT+09.30) Adelaide' => 'Australia/Adelaide', '(GMT+09.30) Darwin' => 'Australia/Darwin', '(GMT+10.00) Brisbane' => 'Australia/Brisbane', '(GMT+10.00) Canberra / Melbourne / Sydney' => 'Australia/Sydney', '(GMT+10.00) Guam / Port Moresby' => 'Pacific/Guam', '(GMT+10.00) Hobart' => 'Australia/Hobart', '(GMT+10.00) Vladivostok' => 'Asia/Vladivostok', '(GMT+11.00) Magadan / Solomon Is. / New Caledonia' => 'Asia/Magadan', '(GMT+12.00) Auckland / Wellington' => 'Pacific/Auckland', '(GMT+12.00) Fiji / Kamchatka / Marshall Is.' => 'Pacific/Fiji', '(GMT+13.00) Nuku\'alofa' => 'Pacific/Tongatapu' ,'E. South America Standard Time' => 'America/Sao_Paulo' , 'E. South America' => 'America/Sao_Paulo' ); // static $timezonesOutlookID = array('Europe/London' => '1' ,'Europe/Brussels' => '3' ,'Europe/Berlin' => '4' ,'America/New_York' => '5' ,'Europe/Belgrade' => '6' ,'Europe/Minsk' => '7' ,'America/Sao_Paulo' => '8' ,'America/Halifax' => '9' ,'America/New_York' => '10' ,'America/Chicago' => '11' ,'America/Denver' => '12' ,'America/Los_Angeles' => '13' ,'America/Anchorage' => '14' ,'Pacific/Honolulu' => '15' ,'Pacific/Midway' => '16' ,'Pacific/Auckland' => '17' ,'Australia/Brisbane' => '18' ,'Australia/Adelaide' => '19' ,'Asia/Tokyo' => '20' ,'Asia/Hong_Kong' => '21' ,'Asia/Bangkok' => '22' ,'Asia/Kolkata' => '23' ,'Asia/Muscat' => '24' ,'Asia/Tehran' => '25' ,'Asia/Baghdad' => '26' ,'Asia/Jerusalem' => '27' ,'America/St_Johns' => '28' ,'Atlantic/Azores' => '29' ,'Atlantic/South_Georgia' => '30' ,'Africa/Casablanca' => '31' ,'America/La_Paz' => '33' ,'America/Indiana/Indianapolis' => '34' ,'America/Bogota' => '35' ,'America/Regina' => '36' ,'America/Mexico_City' => '37' ,'America/Phoenix' => '38' ,'Etc/GMT+12' => '39' ,'Pacific/Fiji' => '40' ,'Asia/Magadan' => '41' ,'Australia/Hobart' => '42' ,'Pacific/Guam' => '43' ,'Australia/Darwin' => '44' ,'Asia/Hong_Kong' => '45' ,'Asia/Novosibirsk' => '46' ,'Asia/Kabul' => '48' ,'Africa/Cairo' => '49' ,'Africa/Harare' => '50' ,'Europe/Moscow' => '51' ,'Australia/Sydney' => '52' ,'Australia/Sydney' => '53' ,'Australia/Adelaide' => '54' ,'Australia/Hobart' => '55' ,'America/Santiago' => '56' ,'Australia/Pert' => '57' ,'America/Tijuana' => '59' ,'Asia/Tbilisi' => '60' ,'Australia/Sydney' => '61' ,'America/Caracas' => '62' ,'Asia/Amman' => '63' ,'Asia/Baku' => '64' ,'Asia/Yerevan' => '65' ,'Europe/Moscow' => '66' ,'America/Argentina/Buenos_Aires' => '67' ,'America/Montevideo' => '72'); 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'])) { $repeat = array(); foreach ($v['repeat'] as $ir => $rv) { if($rv) { if($ir == 'frequency') $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 !== 'schedulable' && $ir !== 'id' && $ir !== 'startTime') $repeat[$ir] = explode(',', $rv); } } $vevent->setProperty('rrule' , $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($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'] ); //Todo: Implementar Repetição break; default: break; } } return $ical->createCalendar(); } //Trata a criacao de anexos do ics public function createAttachment($attachments, &$vevent){ foreach($attachments as $key => $attachment){ $pParams = array("ENCODING" => "BASE64", "VALUE" => "BINARY", "X-FILENAME" => $attachment['name']); $vevent->setProperty( "attach", $attachment['source'], $pParams ); } } //Trata a criacao de attendees com tratamento de delegate public function createAttendee($attendees, &$vevent){ $delegate = array(); foreach ($attendees as $di => $dv){ if(isset($dv['delegatedFrom']) && $dv['delegatedFrom'] != 0){ $delegate[$dv['delegatedFrom']] = $dv; } } foreach ($attendees as $pi => $pv){ $isResponseDelegated = false; if(isset($pv['delegatedFrom']) && $pv['delegatedFrom'] == 0){ if($pv['isOrganizer'] == 1) $vevent->setProperty( 'organizer' , $pv['user']['mail'], array( 'CN' => $pv['user']['name'] )); else { $pParams = array(); $pParams['CN'] = $pv['user']['name']; $pParams['PARTSTAT'] = self::_getStatus( $pv['status'] ); if(isset($pv['id']) && isset($delegate[$pv['id']])){ $pParams['PARTSTAT'] = self::_getStatus( $delegate[$pv['id']]['status']); $pParams['DELEGATED-TO'] = $delegate[$pv['id']]['user']['mail']; $pParams['CN'] = $pv['user']['name']; $vevent->setProperty( 'attendee' , $pv['user']['mail'], $pParams); if($delegate[$pv['id']]['status'] == STATUS_UNANSWERED){ $pParams['RSVP'] = $pv['receiveNotification'] == 1 ? 'TRUE' : 'FALSE'; unset($pParams['PARTSTAT']); }else $pParams['PARTSTAT'] = self::_getStatus( $delegate[$pv['id']]['status']); unset($pParams['DELEGATED-TO']); $pParams['DELEGATED-FROM'] = $pv['user']['mail']; $vevent->setProperty( 'attendee' , $delegate[$pv['id']]['user']['mail'], $pParams); continue; } $pParams['RSVP'] = 'TRUE'; $vevent->setProperty( 'attendee' , $pv['user']['mail'], $pParams); } } } } public function parse ( $data , $params = false) { Config::regSet('noAlarm', TRUE); //Evita o envio de notificação $vcalendar = new icalCreator( ); $vcalendar->parse(trim($data)); $vcalendar->sort(); $return = array(); $method = $vcalendar->getProperty('method',FALSE , FALSE); $params['prodid'] = $vcalendar->getProperty( 'prodid' , false , false ); while ($component = $vcalendar->getComponent()) { $interation = array(); $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente switch (strtoupper($component->objName)) { case 'VEVENT': switch ($method) { case 'PUBLISH': if( !$schedulable = self::_getSchedulable($uid)) $interation = self::_makeVEVENT($schedulable , $component , $params); break; case 'REQUEST': $schedulable = self::_getSchedulable($uid); if($schedulable) //Caso o evento exista { if(!self::_existInMyCalendars($schedulable['id'])) { $calendarToSchedulable = array(); $calendarToSchedulable['calendar'] = $params['calendar']; $calendarToSchedulable['schedulable'] = $schedulable['id']; $interation['calendarToSchedulable://'.mt_rand().'(Formatter)'] = $calendarToSchedulable; if(isset($params['status'])) { $pID = self::_getParticipantByMail( Config::me('mail') , $schedulable['participants'] ); $interation['participant://'.$pID]['status'] = $params['status']; } Config::regSet('noAlarm', FALSE); //reativa notificação } else { if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento $interation = self::_makeVEVENT($schedulable , $component , $params); else if ( $component->getProperty( 'sequence' , false , false ) === $schedulable['sequence']) { //Ler melhor rfc sobre isto 3.2.2.2 //Aparentemente é para retornar um ical com o evento atualizado para o attende } } }else // Importar evento { $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(isset($startTime['params']['VALUE']) && $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(isset($endTime['params']['VALUE']) && $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['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['status'] = isset($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'] = EVENT_ID; $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' => (isset($sc['allDay']) && $sc['allDay'] ) ? '' : date_format( $sTime , 'H:i') , 'endDate' => date_format( $eTime , 'd/m/Y') , 'endTime' => isset($sc['allDay']) ? '' : date_format( $eTime , 'H:i') , 'eventTitle' => $sc['summary'], 'eventLocation' => isset($sc['location']) ? $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'); $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; switch($params['status']) { case STATUS_ACCEPTED: $tpl = 'notify_accept_body'; $subject['notificationType'] = 'Convite Aceito'; break; case STATUS_TENTATIVE: $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; case 'REFRESH': break; case 'CANCEL': if($schedulable = self::_getSchedulable($uid)) $interation['schedulable://'.$schedulable['id']] = false; break; case 'ADD': break; case 'REPLY': if( $schedulable = self::_getSchedulable($uid) ) { while($property = $component->getProperty('attendee',FALSE , TRUE)) if( $pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) $interation['participant://'.$pID] = array( 'id' => $pID , 'status' => constant('STATUS_'.strtoupper($property['params']['PARTSTAT'])) ); } break; case 'COUNTER': if($params['acceptedSuggestion'] !== 'false' ){ $schedulable = self::_getSchedulable($uid); $params['calendar'] = self::_existInMyCalendars($schedulable['id']); $interation = self::_makeCOUNTER($schedulable , $component , $params); Config::regSet('noAlarm', FALSE); }else{ $response = array(); $response['from'] = $params['from']; $response['type'] = 'suggestionResponse'; $response['status'] = 'DECLINECOUNTER'; $response['schedulable'] = self::_getSchedulable($uid); Controller::create( array( 'concept' => 'notification' ) , $response); } break; case 'DECLINECOUNTER': break; default: $schedulable = self::_getSchedulable($uid); if($schedulable && ( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence'])) //Caso o evento exista $interation = self::_makeVEVENT($schedulable , $component , $params); else // Importar evento $interation = self::_makeVEVENT( array() , $component , $params); break; } $return[] = $interation; break; case 'VTIMEZONE': break; } } return $return; } public function analize ( $data , $params = false) { $vcalendar = new icalCreator( ); $vcalendar->parse(trim($data)); $vcalendar->sort(); $return = array(); $method = $vcalendar->getProperty('method',FALSE , FALSE); while ($component = $vcalendar->getComponent()) { $interation = array(); $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente switch (strtoupper($component->objName)) { case 'VEVENT': switch ($method) { case 'PUBLISH': $interation = ICAL_ACTION_IMPORT; break; case 'REQUEST': $schedulable = self::_getSchedulable($uid); if($schedulable ) //Caso o evento exista { if(!self::_existInMyCalendars($schedulable['id'])) $interation = ICAL_ACTION_IMPORT; else { if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento $interation = ICAL_ACTION_UPDATE; else $interation = ICAL_ACTION_NONE; } }else $interation = ICAL_ACTION_IMPORT; break; case 'REFRESH': break; case 'CANCEL': $interation = ICAL_ACTION_DELETE; break; case 'ADD': break; case 'REPLY': $interation = ICAL_ACTION_REPLY; break; case 'COUNTER': $interation = ICAL_ACTION_SUGGESTION; break; case 'DECLINECOUNTER': $interation = ICAL_ACTION_NONE; break; default: $schedulable = self::_getSchedulable($uid); if($schedulable && ( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence'])) //Caso o evento exista $interation = ICAL_ACTION_UPDATE; else if($schedulable) $interation = ICAL_ACTION_NONE; else // Importar evento $interation = ICAL_ACTION_IMPORT; break; } $return[$uid] = $interation; break; case 'VTIMEZONE': break; } } return $return; } /* Helpers */ private static function _getTzOffset($rTz, $oTz = null , $time = 'now') { if($oTz === null) { if(!is_string($oTz = date_default_timezone_get())) { return false; // A UTC timestamp was returned -- bail out! } } $origin_dtz = new DateTimeZone(self::nomalizeTZID($oTz)); $remote_dtz = new DateTimeZone(self::nomalizeTZID($rTz)); $origin_dt = new DateTime($time, $origin_dtz); $remote_dt = new DateTime("now", $remote_dtz); $offset = $origin_dtz->getOffset($origin_dt) - $remote_dtz->getOffset($remote_dt); return $offset; } private function _getStatus( $id ) { $a = array( STATUS_CONFIRMED => 'ACCEPTED', STATUS_CANCELLED => 'CANCELLED', STATUS_TENTATIVE => 'TENTATIVE', STATUS_UNANSWERED => 'NEEDS-ACTION', STATUS_DELEGATED => 'DELEGATED' ); return isset($a[ $id ]) ? $a[ $id ] : 'NEEDS-ACTION'; } private static function _getParticipantByMail( $mail , &$participants ) { foreach ($participants as $i => $v) if($v['user']['mail'] == $mail || (isset($v['user']['mailAlternateAddress']) && in_array($mail, $v['user']['mailAlternateAddress']))) return $v['id']; return false; } static private function nomalizeTZID ($TZID) { if(isset(self::$timezonesMap[$TZID])) return self::$timezonesMap[$TZID]; else if(in_array($TZID, self::$suportedTimzones)) return $TZID; else return date_default_timezone_get(); } static private function date2timestamp( $datetime, $tz=null ) { if( !isset( $datetime['hour'] )) $datetime['hour'] = '0'; if( !isset( $datetime['min'] )) $datetime['min'] = '0'; if( !isset( $datetime['sec'] )) $datetime['sec'] = '0'; foreach( $datetime as $dkey => $dvalue ) if( 'tz' != $dkey ) $datetime[$dkey] = (integer) $dvalue; if( $tz ) $datetime['tz'] = $tz; $offset = ( isset( $datetime['tz'] ) && ( '' < trim ( $datetime['tz'] ))) ? iCalUtilityFunctions::_tz2offset( $datetime['tz'] ) : 0; return gmmktime( $datetime['hour'], $datetime['min'], ($datetime['sec'] + $offset), $datetime['month'], $datetime['day'], $datetime['year'] ); } static private function _makeCOUNTER( $schedulable , $component ,$params) { $interation = array(); $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand().'(Formatter)'; /* Data de Inicio*/ $startTime = $component->getProperty( 'dtstart', false , true ); /* Tiem zone do evento*/ if(isset($startTime['params']['TZID'])) $schedulable['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); else $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; $objTimezone = new DateTimeZone($schedulable['timezone']); if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) { $schedulable['allDay'] = 1; $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone'], '@'.self::date2timestamp($startTime['value'])) . '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 */ $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID'],'@'.self::date2timestamp($startTime['value'])) . '000'; $schedulable['allDay'] = 0; } else { $schedulable['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)($schedulable['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 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; } } /* Data de Termino*/ $endTime = $component->getProperty( 'dtend', false , true ); if($endTime['params']['VALUE'] === 'DATE') $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone'],'@'.self::date2timestamp($endTime['value'])) . '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 */ $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID'],'@'.self::date2timestamp($endTime['value'])) . '000'; else { $schedulable['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)($schedulable['endTime'] / 1000) ,new DateTimeZone('UTC')); $eTime->setTimezone($objTimezone); if($eTime->format('I')) $schedulable['endTime'] = $schedulable['endTime'] - 3600000; } } unset($schedulable['participants']); $interation['schedulable://'.$eventID] = $schedulable; return $interation; } static private function _makeVEVENT( $schedulable , $component ,$params) { $interation = array(); $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand().'(Formatter)'; /* Data de Inicio*/ $startTime = $component->getProperty( 'dtstart', false , true ); /* Tiem zone do evento*/ if(isset($startTime['params']['TZID'])) $schedulable['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); else $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; $objTimezone = new DateTimeZone($schedulable['timezone']); if(isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) { $schedulable['allDay'] = 1; $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone'],'@'.self::date2timestamp($startTime['value'])) . '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 */ $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID'],'@'.self::date2timestamp($startTime['value'])) . '000'; $schedulable['allDay'] = 0; } else { $schedulable['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)($schedulable['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 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; } } /* Data de Termino*/ $endTime = $component->getProperty( 'dtend', false , true ); if(isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone'],'@'.self::date2timestamp($endTime['value'])) . '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 */ $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID'],'@'.self::date2timestamp($endTime['value'])) . '000'; else { $schedulable['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)($schedulable['endTime'] / 1000) ,new DateTimeZone('UTC')); $eTime->setTimezone($objTimezone); if($eTime->format('I')) $schedulable['endTime'] = $schedulable['endTime'] - 3600000; } } $schedulable['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'ISO-8859-1' , 'UTF-8,ISO-8859-1'); /* Definindo Description */ if($desc = $component->getProperty( 'description' , false , false )) $schedulable['description'] = mb_convert_encoding (str_ireplace (array('\n','\t'), array("\n","\t"), $desc) ,'ISO-8859-1' , 'UTF-8,ISO-8859-1'); /* Definindo location */ if($location = $component->getProperty( 'location' , false , false )) $schedulable['location'] = mb_convert_encoding ( $location , 'ISO-8859-1' , 'UTF-8,ISO-8859-1') ; /* Definindo Class */ $class = $component->getProperty( 'class' , false , false ); if( $class && defined(constant(strtoupper('CLASS_'.$class))) ) $schedulable['class'] = constant(strtoupper('CLASS_'.$class)); else if( !isset($exists['class']) ) $schedulable['class'] = CLASS_PRIVATE ; // padrão classe private /* Definindo RRULE */ if( $rrule = $component->getProperty( 'rrule' , false , false )) { /* Gera um randon id para o contexto formater */ $repeatID = mt_rand().'3(Formatter)'; $repeat = array(); $repeat['schedulable'] = $eventID; foreach($rrule as $i => $v) { if(strtolower($i) == 'freq') $repeat['frequency'] = $v; else if(strtolower($i) == 'until') $repeat['endTime'] = $v; else $repeat[strtolower($i)] = $v; } $interation['repeat://'.$repeatID] = $repeat; } $schedulable['calendar'] = $params['calendar']; $participantsInEvent = array(); //TODO: Participants com delegated não estao sendo levados em conta while($property = $component->getProperty('attendee',FALSE , TRUE)) { $participant = array(); $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); $participantID = mt_rand().'2(Formatter)'; $participant['schedulable'] = $eventID; if(isset($params['status']) && $mailUser == Config::me('mail')) $participant['status'] = $params['status']; else $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; $participant['isOrganizer'] = '0'; /* Verifica se este usuario é um usuario interno do ldap */ $intUser = Controller::find( array( 'concept' => 'user' ) , array('id','isExternal') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); $user = null; if( $intUser && count($intUser) > 0 ) { $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; $participant['user'] = $intUser[0]['id']; } else { $participant['isExternal'] = 1; /* Gera um randon id para o contexto formater */ $userID = mt_rand().'4(Formatter)'; $user['mail'] = $mailUser; $user['isExternal'] = '1'; $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; $user['participants'] = array($participantID); $participant['user'] = $userID; $interation['user://'.$userID] = $user; } $interation['participant://'.$participantID] = $participant; $schedulable['participants'][] = $participantID; }; 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['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; $participant['isOrganizer'] = '1'; $participant['acl'] = 'rowi'; /* Verifica se este usuario é um usuario interno do ldap */ $intUser = Controller::find( array( 'concept' => 'user' ) , array('id','isExternal') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); $user = null; if( $intUser && count($intUser) > 0 ) { $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; $participant['user'] = $intUser[0]['id']; } else { $participant['isExternal'] = 1; /* Gera um randon id para o contexto formater */ $userID = mt_rand().'4(Formatter)'; $user['mail'] = $mailUser; $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; $user['participants'] = array($participantID); $user['isExternal'] = '1'; $participant['user'] = $userID; $interation['user://'.$userID] = $user; } $interation['participant://'.$participantID] = $participant; $schedulable['participants'][] = $participantID; } else if(!is_array($schedulable['participants']) || count($schedulable['participants']) < 1)//caso não tenha organizador o usuario se torna organizador { $user = Controller::read( array( 'concept' => 'user', 'id' => $params['owner'] ) , array('mail')); if(!self::_getParticipantByMail($user['mail'] , $exists['participants'])) { $participantID = mt_rand().'2(Formatter)'; $participant['schedulable'] = $eventID; $participant['status'] = STATUS_CONFIRMED; $participant['isOrganizer'] = '1'; $participant['acl'] = 'rowi'; $participant['isExternal'] = 0; $participant['user'] = $params['owner']; $interation['participant://'.$participantID] = $participant; $schedulable['participants'][] = $participantID; } } /* Definindo DTSTAMP */ if($dtstamp = self::_getTime($component , 'dtstamp') ) $schedulable['dtstamp'] = $dtstamp; /* Definindo TRANSP */ if(($tranp = $component->getProperty( 'transp', false , true )) && $tranp && is_string($tranp) && strtoupper($tranp) == 'OPAQUE') $schedulable['transparent'] = 1; /* Definindo last_update */ if($lastUpdate = self::_getTime($component , 'LAST-MODIFIED')) $schedulable['lastUpdate'] = $lastUpdate; if($sequence = $component->getProperty( 'SEQUENCE', false , false )) $schedulable['sequence'] = $sequence; if($uid = $component->getProperty( 'uid' , false , false )); $schedulable['uid'] = $uid; while($attach = $component->getProperty('ATTACH',FALSE , TRUE)){ $attachCurrent = array( 'name' => $attach['params']['X-FILENAME'], 'size' => strlen($attach['value']), 'type' => self::_getContentType($attach['params']['X-FILENAME']) ); $ids = Controller::find( array( 'concept' => 'attachment' ) , array('id') ,array( 'filter' => array('AND' , array( '=' , 'name' , $attachCurrent['name'] ), array( '=' , 'size' , $attachCurrent['size'] ), array( '=' , 'type' , $attachCurrent['type'] )))); if(!is_array($ids)){ $attachCurrent['source'] = $attach['value']; //insere o anexo no banco e pega id para colcar no relacionamento $idAttachment = Controller::create( array('concept' => 'attachment') , $attachCurrent ); }else $idAttachment = array('id' => $ids[0]['id']); $calendarToAttachmentId = mt_rand().'2(Formatter)'; $calendarToAttachment['attachment'] = $idAttachment['id'] ; $calendarToAttachment['schedulable'] = $eventID ; $interation['schedulableToAttachment://'.$calendarToAttachmentId] = $calendarToAttachment; $schedulable['attachments'][] = $calendarToAttachmentId; } $interation['schedulable://'.$eventID] = $schedulable; return $interation; } static private function _getSchedulable( $uid ) { $schedulable = Controller::find( array( 'concept' => 'schedulable' ) , false , array ( 'filter' => array( '=' , 'uid' , $uid ), 'deepness' => 2 )); return (isset($schedulable[0])) ? $schedulable[0] : false; } static private function _existInMyCalendars( $id ) { $sig = Controller::find(array('concept' => 'calendarSignature'), array('user','calendar'), array('filter' => array( '=' , 'user' , Config::me('uidNumber')))); $calendars = array(); foreach ($sig as $val) $calendars[] = $val['calendar']; $return = Controller::find( array( 'concept' => 'calendarToSchedulable' ) , null , array ( 'filter' => array('AND' , array( 'IN' , 'calendar' , $calendars ),array( '=' , 'schedulable' , $id )))); return (isset($return[0])) ? $return[0]['calendar'] : false; } static private function _getTime(&$component , $property) { if($date = $component->getProperty($property , false , true )) return (isset($date['params']['TZID']) && !isset($date['value']['tz'])) ? (self::date2timestamp($date['value']) - self::_getTzOffset('UTC',$date['params']['TZID'],'@'.self::date2timestamp($date['value']))) . '000' : self::date2timestamp($date['value']) . '000'; return false; } static private function _getContentType( $fileName ) { $strFileType = strtolower(substr ( $fileName , strrpos($fileName, '.') )); switch( $strFileType ) { case ".asf": return "video/x-ms-asf"; case ".avi": return "video/avi"; case ".doc": return "application/msword"; case ".zip": return "application/zip"; case ".xls": return "application/vnd.ms-excel"; case ".gif": return "image/gif"; case ".bmp": return "image/bmp"; case ".jpeg": case ".jpg": return "image/jpeg"; case ".wav": return "audio/wav"; case ".mp3": return "audio/mpeg3"; case ".mpeg": case ".mpg": return "video/mpeg"; case ".rtf": return "application/rtf"; case ".html": case ".htm": return "text/html"; case ".xml": return "text/xml"; case ".xsl": return "text/xsl"; case ".css": return "text/css"; case ".php": return "text/php"; case ".asp": return "text/asp"; case ".pdf": return "application/pdf"; case ".png": return "image/png"; case ".txt": return "text/plain"; case ".log": return "text/plain"; case ".wmv": return "video/x-ms-wmv"; case ".sxc": return "application/vnd.sun.xml.calc"; case ".odt": return "application/vnd.oasis.opendocument.text"; case ".stc": return "application/vnd.sun.xml.calc.template"; case ".sxd": return "application/vnd.sun.xml.draw"; case ".std": return "application/vnd.sun.xml.draw.template"; case ".sxi": return "application/vnd.sun.xml.impress"; case ".sti": return "application/vnd.sun.xml.impress.template"; case ".sxm": return "application/vnd.sun.xml.math"; case ".sxw": return "application/vnd.sun.xml.writer"; case ".sxq": return "application/vnd.sun.xml.writer.global"; case ".stw": return "application/vnd.sun.xml.writer.template"; case ".pps": return "application/vnd.ms-powerpoint"; case ".odt": return "application/vnd.oasis.opendocument.text"; case ".ott": return "application/vnd.oasis.opendocument.text-template"; case ".oth": return "application/vnd.oasis.opendocument.text-web"; case ".odm": return "application/vnd.oasis.opendocument.text-master"; case ".odg": return "application/vnd.oasis.opendocument.graphics"; case ".otg": return "application/vnd.oasis.opendocument.graphics-template"; case ".odp": return "application/vnd.oasis.opendocument.presentation"; case ".otp": return "application/vnd.oasis.opendocument.presentation-template"; case ".ods": return "application/vnd.oasis.opendocument.spreadsheet"; case ".ots": return "application/vnd.oasis.opendocument.spreadsheet-template"; case ".odc": return "application/vnd.oasis.opendocument.chart"; case ".odf": return "application/vnd.oasis.opendocument.formula"; case ".odi": return "application/vnd.oasis.opendocument.image"; case ".ndl": return "application/vnd.lotus-notes"; case ".eml": return "text/plain"; case ".ps" : return "application/postscript"; default : return "application/octet-stream"; } } } ?>