[5341] | 1 | <?php |
---|
[5399] | 2 | require_once ROOTPATH.'/plugins/icalcreator/iCalUtilityFunctions.class.php'; |
---|
| 3 | require_once ROOTPATH.'/plugins/icalcreator/iCalcreator.class.php'; |
---|
[5341] | 4 | require_once ROOTPATH.'/modules/calendar/constants.php'; |
---|
| 5 | |
---|
| 6 | //TODO:Timeout request |
---|
| 7 | set_time_limit( 600 ); |
---|
| 8 | class iCal implements Formatter |
---|
| 9 | { |
---|
[5903] | 10 | static $timezonesMap = array ('(GMT-12.00) International Date Line West' => '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 -0300 (Standard) / GMT -0200 (Daylight)' => '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' ); |
---|
[5341] | 11 | // 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'); |
---|
| 12 | 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'); |
---|
| 13 | |
---|
| 14 | public function format ($data , $params = false) |
---|
[5514] | 15 | { |
---|
[5341] | 16 | $timezones = array_flip(self::$timezonesMap); |
---|
| 17 | |
---|
| 18 | $ical = new icalCreator(); |
---|
| 19 | |
---|
| 20 | $ical->setProperty( 'method' , isset($params['method']) ? $params['method'] : 'PUBLISH' ); |
---|
| 21 | $sytemTimezone = (date_default_timezone_get()) ? date_default_timezone_get() : 'America/Sao_Paulo'; |
---|
| 22 | $params['defaultTZI'] = self::nomalizeTZID((isset($params['defaultTZI']) && $params['defaultTZI'] != 'null') ? $params['defaultTZI'] : $sytemTimezone ); |
---|
| 23 | |
---|
| 24 | /* |
---|
| 25 | * Seta propiedades obrigatorias para alguns softwares (Outlook) |
---|
| 26 | */ |
---|
| 27 | $ical->setProperty( 'x-wr-calname', 'Calendar Expresso' ); |
---|
| 28 | $ical->setProperty( 'X-WR-CALDESC', 'Calendar Expresso' ); |
---|
| 29 | $ical->setProperty( 'X-WR-TIMEZONE', isset($timezones[$params['defaultTZI']]) ? $timezones[$params['defaultTZI']] : $params['defaultTZI']); |
---|
| 30 | |
---|
| 31 | foreach($data as $i => $v) |
---|
| 32 | { |
---|
| 33 | |
---|
| 34 | switch ($v['type']) { |
---|
| 35 | case EVENT_ID: |
---|
| 36 | |
---|
| 37 | $vevent = $ical->newComponent( 'vevent' ); |
---|
[5715] | 38 | |
---|
[5341] | 39 | $vevent->setProperty( 'summary' , $v['summary'] ); |
---|
[5736] | 40 | $vevent->setProperty( 'description' , isset($v['description']) ? $v['description'] : ''); |
---|
[5341] | 41 | $vevent->setProperty( 'location' , $v['location'] ); |
---|
| 42 | $vevent->setProperty( 'tranp' , (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT )? 'TRANSPARENT' : 'OPAQUE' ); |
---|
| 43 | |
---|
| 44 | $timezone = new DateTimeZone('UTC'); |
---|
| 45 | $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); |
---|
[5715] | 46 | $apTimezoneOBJ = new DateTimeZone($apTimezone); |
---|
| 47 | |
---|
[5341] | 48 | $sTime = new DateTime( '@'.(int)($v['startTime'] / 1000) , $timezone ); |
---|
[5715] | 49 | $sTime->setTimezone($apTimezoneOBJ); |
---|
[5341] | 50 | $eTime = new DateTime( '@'.(int)($v['endTime'] / 1000) , $timezone ); |
---|
[5715] | 51 | $eTime->setTimezone($apTimezoneOBJ); |
---|
[6011] | 52 | |
---|
| 53 | if( ( isset($v['repeat']) ) && ( $v['repeat']['frequency'] != 'none' ) ) |
---|
[5715] | 54 | { |
---|
| 55 | $repeat = array(); |
---|
| 56 | |
---|
| 57 | foreach ($v['repeat'] as $ir => $rv) |
---|
| 58 | { |
---|
| 59 | if($rv) |
---|
| 60 | { |
---|
[5998] | 61 | if($ir == 'frequency' && $rv !== 'none') |
---|
[5715] | 62 | $repeat['FREQ'] = $rv; |
---|
| 63 | else if($ir == 'endTime' ) |
---|
| 64 | { |
---|
| 65 | $time = new DateTime( '@'.(int)($rv / 1000) , $timezone ); |
---|
| 66 | $time->setTimezone($apTimezoneOBJ); |
---|
| 67 | $repeat['until'] = $time->format(DATE_RFC822); |
---|
| 68 | } |
---|
| 69 | else if($ir == 'count') |
---|
| 70 | $repeat[$ir] = $rv; |
---|
| 71 | else if($ir !== 'schedulable' && $ir !== 'id' && $ir !== 'startTime') |
---|
| 72 | $repeat[$ir] = explode(',', $rv); |
---|
| 73 | } |
---|
| 74 | } |
---|
[5998] | 75 | |
---|
| 76 | if(isset($repeat['FREQ'])) |
---|
[6006] | 77 | $vevent->setProperty('rrule' , $repeat); |
---|
[5715] | 78 | } |
---|
| 79 | |
---|
[5341] | 80 | if( isset($v['allDay']) && $v['allDay'] == 1 ) |
---|
| 81 | { |
---|
| 82 | $vevent->setProperty( 'dtstart' , $sTime->format(DATE_RFC822), array( "VALUE" => "DATE" )); |
---|
| 83 | $vevent->setProperty( 'dtend' , $eTime->format(DATE_RFC822), array( "VALUE" => "DATE" )); |
---|
| 84 | $vevent->setProperty( 'X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE' ); |
---|
| 85 | } |
---|
| 86 | else |
---|
| 87 | { |
---|
| 88 | $vevent->setProperty( 'dtstart' , $sTime->format(DATE_RFC822) , array('TZID' => $apTimezone ) ); |
---|
| 89 | $vevent->setProperty( 'dtend' , $eTime->format(DATE_RFC822), array('TZID' => $apTimezone ) ); |
---|
| 90 | $vevent->setProperty( 'X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE' ); |
---|
| 91 | } |
---|
| 92 | |
---|
[5514] | 93 | if(isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0 ) |
---|
| 94 | $this->createAttendee($v['participants'], $vevent); |
---|
[5341] | 95 | |
---|
[5514] | 96 | if(isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0 ) |
---|
| 97 | $this->createAttachment($v['attachments'], $vevent); |
---|
| 98 | |
---|
| 99 | $vevent->setProperty( 'uid' , $v['uid'] ); |
---|
[5341] | 100 | |
---|
| 101 | //Todo: Implementar Repetição |
---|
| 102 | |
---|
| 103 | break; |
---|
| 104 | |
---|
| 105 | default: |
---|
| 106 | break; |
---|
[5514] | 107 | } |
---|
[5341] | 108 | } |
---|
| 109 | |
---|
| 110 | return $ical->createCalendar(); |
---|
| 111 | |
---|
| 112 | } |
---|
[5514] | 113 | //Trata a criacao de anexos do ics |
---|
| 114 | public function createAttachment($attachments, &$vevent){ |
---|
| 115 | foreach($attachments as $key => $attachment){ |
---|
| 116 | $pParams = array("ENCODING" => "BASE64", "VALUE" => "BINARY", |
---|
| 117 | "X-FILENAME" => $attachment['name']); |
---|
| 118 | |
---|
| 119 | $vevent->setProperty( "attach", $attachment['source'], $pParams ); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | //Trata a criacao de attendees com tratamento de delegate |
---|
| 124 | public function createAttendee($attendees, &$vevent){ |
---|
| 125 | $delegate = array(); |
---|
| 126 | foreach ($attendees as $di => $dv){ |
---|
[5736] | 127 | if(isset($dv['delegatedFrom']) && $dv['delegatedFrom'] != 0){ |
---|
[5514] | 128 | $delegate[$dv['delegatedFrom']] = $dv; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | foreach ($attendees as $pi => $pv){ |
---|
| 133 | $isResponseDelegated = false; |
---|
[5736] | 134 | if(isset($pv['delegatedFrom']) && $pv['delegatedFrom'] == 0){ |
---|
[6017] | 135 | if($pv['isOrganizer'] == 1) |
---|
[5998] | 136 | $vevent->setProperty( 'organizer' , $pv['user']['mail'], array( 'CN' => $pv['user']['name'])); |
---|
[5514] | 137 | else |
---|
| 138 | { |
---|
| 139 | $pParams = array(); |
---|
| 140 | $pParams['CN'] = $pv['user']['name']; |
---|
| 141 | $pParams['PARTSTAT'] = self::_getStatus( $pv['status'] ); |
---|
| 142 | |
---|
[5736] | 143 | if(isset($pv['id']) && isset($delegate[$pv['id']])){ |
---|
[5514] | 144 | $pParams['PARTSTAT'] = self::_getStatus( $delegate[$pv['id']]['status']); |
---|
| 145 | $pParams['DELEGATED-TO'] = $delegate[$pv['id']]['user']['mail']; |
---|
| 146 | $pParams['CN'] = $pv['user']['name']; |
---|
| 147 | |
---|
| 148 | $vevent->setProperty( 'attendee' , $pv['user']['mail'], $pParams); |
---|
| 149 | |
---|
| 150 | if($delegate[$pv['id']]['status'] == STATUS_UNANSWERED){ |
---|
| 151 | $pParams['RSVP'] = $pv['receiveNotification'] == 1 ? 'TRUE' : 'FALSE'; |
---|
| 152 | unset($pParams['PARTSTAT']); |
---|
| 153 | }else |
---|
| 154 | $pParams['PARTSTAT'] = self::_getStatus( $delegate[$pv['id']]['status']); |
---|
| 155 | |
---|
| 156 | unset($pParams['DELEGATED-TO']); |
---|
| 157 | $pParams['DELEGATED-FROM'] = $pv['user']['mail']; |
---|
| 158 | |
---|
| 159 | $vevent->setProperty( 'attendee' , $delegate[$pv['id']]['user']['mail'], $pParams); |
---|
| 160 | continue; |
---|
| 161 | } |
---|
| 162 | $pParams['RSVP'] = 'TRUE'; |
---|
| 163 | |
---|
| 164 | $vevent->setProperty( 'attendee' , $pv['user']['mail'], $pParams); |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | } |
---|
[5341] | 169 | |
---|
[5514] | 170 | public function parse ( $data , $params = false) |
---|
[5341] | 171 | { |
---|
| 172 | Config::regSet('noAlarm', TRUE); //Evita o envio de notificação |
---|
| 173 | $vcalendar = new icalCreator( ); |
---|
| 174 | $vcalendar->parse(trim($data)); |
---|
[5415] | 175 | $vcalendar->sort(); |
---|
| 176 | |
---|
[5341] | 177 | $return = array(); |
---|
[5415] | 178 | $method = $vcalendar->getProperty('method',FALSE , FALSE); |
---|
| 179 | $params['prodid'] = $vcalendar->getProperty( 'prodid' , false , false ); |
---|
[5514] | 180 | |
---|
[5341] | 181 | while ($component = $vcalendar->getComponent()) |
---|
[5415] | 182 | { |
---|
[5341] | 183 | $interation = array(); |
---|
[5415] | 184 | $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente |
---|
[5341] | 185 | |
---|
| 186 | switch (strtoupper($component->objName)) { |
---|
| 187 | case 'VEVENT': |
---|
| 188 | |
---|
| 189 | switch ($method) |
---|
| 190 | { |
---|
[5415] | 191 | case 'PUBLISH': |
---|
| 192 | if( !$schedulable = self::_getSchedulable($uid)) |
---|
[5481] | 193 | $interation = self::_makeVEVENT($schedulable , $component , $params); |
---|
[5341] | 194 | break; |
---|
| 195 | |
---|
[5415] | 196 | case 'REQUEST': |
---|
| 197 | $schedulable = self::_getSchedulable($uid); |
---|
| 198 | |
---|
| 199 | if($schedulable) //Caso o evento exista |
---|
| 200 | { |
---|
| 201 | if(!self::_existInMyCalendars($schedulable['id'])) |
---|
| 202 | { |
---|
[5341] | 203 | $calendarToSchedulable = array(); |
---|
| 204 | $calendarToSchedulable['calendar'] = $params['calendar']; |
---|
[5415] | 205 | $calendarToSchedulable['schedulable'] = $schedulable['id']; |
---|
[5341] | 206 | $interation['calendarToSchedulable://'.mt_rand().'(Formatter)'] = $calendarToSchedulable; |
---|
[5415] | 207 | |
---|
| 208 | if(isset($params['status'])) |
---|
| 209 | { |
---|
| 210 | $pID = self::_getParticipantByMail( Config::me('mail') , $schedulable['participants'] ); |
---|
| 211 | $interation['participant://'.$pID]['status'] = $params['status']; |
---|
| 212 | } |
---|
[5437] | 213 | |
---|
| 214 | Config::regSet('noAlarm', FALSE); //reativa notificação |
---|
[5415] | 215 | } |
---|
| 216 | else |
---|
| 217 | { |
---|
[5835] | 218 | |
---|
[5415] | 219 | if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento |
---|
| 220 | $interation = self::_makeVEVENT($schedulable , $component , $params); |
---|
| 221 | else if ( $component->getProperty( 'sequence' , false , false ) === $schedulable['sequence']) |
---|
[5344] | 222 | { |
---|
[5415] | 223 | //Ler melhor rfc sobre isto 3.2.2.2 |
---|
| 224 | //Aparentemente é para retornar um ical com o evento atualizado para o attende |
---|
| 225 | } |
---|
[5916] | 226 | |
---|
| 227 | if(isset($params['status'])) |
---|
[5835] | 228 | { |
---|
[5916] | 229 | $pID = self::_getParticipantByMail( Config::me('mail') , $schedulable['participants'] ); |
---|
| 230 | //Verifica a importação de eventos em que não participo |
---|
| 231 | if($pID){ |
---|
| 232 | $interation['participant://'.$pID]['status'] = $params['status']; |
---|
| 233 | } |
---|
| 234 | } |
---|
[5415] | 235 | } |
---|
| 236 | |
---|
| 237 | }else // Importar evento |
---|
[5736] | 238 | { |
---|
| 239 | $interation = self::_makeVEVENT( array() , $component , $params); |
---|
| 240 | |
---|
| 241 | if( strpos($params['prodid'], 'kigkonsult.se') !== false ) //envia notificação para fora |
---|
[5682] | 242 | { |
---|
| 243 | |
---|
| 244 | /* Data de Inicio*/ |
---|
| 245 | $startTime = $component->getProperty( 'dtstart', false , true ); |
---|
| 246 | |
---|
| 247 | /* Tiem zone do evento*/ |
---|
| 248 | if(isset($startTime['params']['TZID'])) |
---|
| 249 | $sc['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); |
---|
| 250 | else |
---|
| 251 | $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; |
---|
| 252 | |
---|
| 253 | $objTimezone = new DateTimeZone($sc['timezone']); |
---|
| 254 | |
---|
[5736] | 255 | if(isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) |
---|
[5682] | 256 | { |
---|
| 257 | $sc['allDay'] = 1; |
---|
| 258 | $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$sc['timezone']) . '000'; |
---|
| 259 | } |
---|
| 260 | 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 */ |
---|
| 261 | $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000'; |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; |
---|
| 265 | if( strpos($params['prodid'], 'Outlook') !== false ) |
---|
| 266 | { |
---|
| 267 | //Se o ics veio em utc não aplicar horario de verão |
---|
| 268 | $sTime = new DateTime( '@'.(int)($sc['startTime'] / 1000) , new DateTimeZone('UTC') ); |
---|
| 269 | $sTime->setTimezone($objTimezone); |
---|
| 270 | if($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão |
---|
| 271 | $sc['startTime'] = $sc['startTime'] - 3600000; |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | /* Data de Termino*/ |
---|
| 277 | $endTime = $component->getProperty( 'dtend', false , true ); |
---|
| 278 | |
---|
[5736] | 279 | if(isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') |
---|
[5682] | 280 | $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$sc['timezone']) . '000'; |
---|
| 281 | 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 */ |
---|
| 282 | $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000'; |
---|
| 283 | else |
---|
| 284 | { |
---|
| 285 | $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; |
---|
| 286 | if( strpos($params['prodid'], 'Outlook') !== false ) |
---|
| 287 | { |
---|
| 288 | //Se o ics veio em utc não aplicar horario de verão |
---|
| 289 | $eTime = new DateTime( '@'.(int)($sc['endTime'] / 1000) ,new DateTimeZone('UTC')); |
---|
| 290 | $eTime->setTimezone($objTimezone); |
---|
| 291 | if($eTime->format('I')) |
---|
| 292 | $sc['endTime'] = $sc['endTime'] - 3600000; |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | if($uid = $component->getProperty( 'uid' , false , false )); |
---|
| 298 | $sc['uid'] = $uid; |
---|
| 299 | |
---|
| 300 | |
---|
| 301 | $sc['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'UTF-8' , 'UTF-8,ISO-8859-1'); |
---|
| 302 | |
---|
| 303 | /* Definindo Description */ |
---|
| 304 | if($desc = $component->getProperty( 'description' , false , false )) |
---|
| 305 | $sc['description'] = mb_convert_encoding (str_ireplace (array('\n','\t'), array("\n","\t"), $desc) ,'UTF-8' , 'UTF-8,ISO-8859-1'); |
---|
| 306 | |
---|
| 307 | /* Definindo location */ |
---|
| 308 | if($location = $component->getProperty( 'location' , false , false )) |
---|
| 309 | $sc['location'] = mb_convert_encoding ( $location , 'UTF-8' , 'UTF-8,ISO-8859-1') ; |
---|
| 310 | |
---|
| 311 | |
---|
| 312 | |
---|
| 313 | if($property = $component->getProperty('organizer',FALSE , TRUE)) |
---|
| 314 | { |
---|
| 315 | $participant = array(); |
---|
| 316 | $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); |
---|
| 317 | |
---|
| 318 | $participantID = mt_rand().'2(Formatter)'; |
---|
| 319 | |
---|
| 320 | $participant['isOrganizer'] = '1'; |
---|
| 321 | |
---|
| 322 | $user = null; |
---|
| 323 | |
---|
| 324 | $participant['isExternal'] = 1; |
---|
| 325 | /* Gera um randon id para o contexto formater */ |
---|
| 326 | $userID = mt_rand().'4(Formatter)'; |
---|
| 327 | |
---|
| 328 | $user['mail'] = $mailUser; |
---|
| 329 | $organizerMail = $mailUser; |
---|
| 330 | |
---|
| 331 | $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; |
---|
| 332 | $user['isExternal'] = '1'; |
---|
| 333 | $participant['user'] = $user; |
---|
| 334 | |
---|
| 335 | $sc['participants'][] = $participant; |
---|
| 336 | |
---|
| 337 | } |
---|
| 338 | |
---|
[5736] | 339 | |
---|
| 340 | $participant['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; |
---|
[5682] | 341 | $participant['isOrganizer'] = '0'; |
---|
| 342 | $participant['isExternal'] = 0; |
---|
| 343 | $participant['user'] = array('mail' => Config::me('mail') , 'name' => Config::me('cn')); |
---|
| 344 | $sc['participants'][] = $participant; |
---|
[5736] | 345 | $sc['type'] = EVENT_ID; |
---|
[5682] | 346 | |
---|
| 347 | |
---|
| 348 | $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($sc) , array('method' => 'REPLY')); |
---|
| 349 | $ical['type'] = 'application/ics'; |
---|
| 350 | $ical['name'] = 'outlook.ics'; |
---|
| 351 | |
---|
| 352 | $ical2['source'] = $ical['source']; |
---|
| 353 | $ical2['type'] = 'text/calendar; method=REPLY'; |
---|
| 354 | $ical2['name'] = 'thunderbird.ics'; |
---|
| 355 | |
---|
| 356 | $timezone = new DateTimeZone('UTC'); |
---|
| 357 | $sTime = new DateTime( '@'.(int)($sc['startTime'] / 1000) , $timezone ); |
---|
| 358 | $eTime = new DateTime( '@'.(int)($sc['endTime'] / 1000) , $timezone ); |
---|
| 359 | |
---|
| 360 | if(isset($sc['timezone'])) |
---|
| 361 | { |
---|
| 362 | $sTime->setTimezone(new DateTimeZone($sc['timezone'])); |
---|
| 363 | $eTime->setTimezone(new DateTimeZone($sc['timezone'])); |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | $data = array('startDate' => date_format( $sTime , 'd/m/Y') , |
---|
[5736] | 367 | 'startTime' => (isset($sc['allDay']) && $sc['allDay'] ) ? '' : date_format( $sTime , 'H:i') , |
---|
[5682] | 368 | 'endDate' => date_format( $eTime , 'd/m/Y') , |
---|
[5736] | 369 | 'endTime' => isset($sc['allDay']) ? '' : date_format( $eTime , 'H:i') , |
---|
[5682] | 370 | 'eventTitle' => $sc['summary'], |
---|
[5736] | 371 | 'eventLocation' => isset($sc['location']) ? $sc['location'] : '', |
---|
[5682] | 372 | 'timezone' => ($sc['timezone']) ? $sc['timezone'] : 'UTC' , |
---|
| 373 | 'participant' => (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']) ); |
---|
| 374 | |
---|
| 375 | $subject['notificationType'] = 'Convite Aceito'; |
---|
| 376 | $subject['eventTitle'] = mb_convert_encoding($sc['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); |
---|
| 377 | $subject['startDate'] = date_format( $sTime , 'd/m/Y'); |
---|
| 378 | $subject['startTime'] = ($sc['allDay']) ? '' : date_format( $sTime , 'H:i'); |
---|
| 379 | $subject['endDate'] = date_format( $eTime , 'd/m/Y'); |
---|
| 380 | $subject['endTime'] = ($sc['allDay']) ? '' : date_format( $eTime , 'H:i'); |
---|
| 381 | $subject['participant'] = Config::me('uid'); |
---|
[5736] | 382 | |
---|
| 383 | $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; |
---|
| 384 | |
---|
| 385 | switch($params['status']) |
---|
[5682] | 386 | { |
---|
| 387 | case STATUS_ACCEPTED: |
---|
| 388 | $tpl = 'notify_accept_body'; |
---|
| 389 | $subject['notificationType'] = 'Convite Aceito'; |
---|
| 390 | break; |
---|
[5736] | 391 | case STATUS_TENTATIVE: |
---|
[5682] | 392 | $tpl = 'notify_attempt_body'; |
---|
| 393 | $subject['notificationType'] = 'Convite aceito provisoriamente'; |
---|
| 394 | break; |
---|
| 395 | case STATUS_CANCELLED: |
---|
| 396 | $tpl = 'notify_reject_body'; |
---|
| 397 | $subject['notificationType'] = 'Convite rejeitado'; |
---|
| 398 | break; |
---|
| 399 | |
---|
| 400 | } |
---|
| 401 | require_once ROOTPATH.'/api/parseTPL.php'; |
---|
| 402 | |
---|
| 403 | $mail = array(); |
---|
| 404 | $mail['attachments'][] = $ical; |
---|
| 405 | $mail['attachments'][] = $ical2; |
---|
| 406 | |
---|
| 407 | $mail['isHtml'] = true; |
---|
| 408 | $mail['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/'.$tpl.'.tpl'); |
---|
| 409 | $mail['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');; |
---|
[5804] | 410 | $mail['from'] = '"'.Config::me('cn').'" <'.Config::me('mail').'>'; |
---|
[5682] | 411 | $mail['to'] = $organizerMail; |
---|
| 412 | |
---|
| 413 | |
---|
| 414 | Controller::create( array( 'service' => 'SMTP' ), $mail ); |
---|
| 415 | } |
---|
[5736] | 416 | } |
---|
[5415] | 417 | break; |
---|
| 418 | |
---|
| 419 | case 'REFRESH': |
---|
| 420 | break; |
---|
| 421 | |
---|
| 422 | case 'CANCEL': |
---|
| 423 | if($schedulable = self::_getSchedulable($uid)) |
---|
| 424 | $interation['schedulable://'.$schedulable['id']] = false; |
---|
| 425 | break; |
---|
| 426 | |
---|
| 427 | case 'ADD': |
---|
| 428 | break; |
---|
| 429 | |
---|
| 430 | case 'REPLY': |
---|
| 431 | if( $schedulable = self::_getSchedulable($uid) ) |
---|
| 432 | { |
---|
| 433 | while($property = $component->getProperty('attendee',FALSE , TRUE)) |
---|
| 434 | if( $pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) |
---|
| 435 | $interation['participant://'.$pID] = array( 'id' => $pID , 'status' => constant('STATUS_'.strtoupper($property['params']['PARTSTAT'])) ); |
---|
| 436 | } |
---|
| 437 | break; |
---|
| 438 | |
---|
| 439 | case 'COUNTER': |
---|
[5514] | 440 | if($params['acceptedSuggestion'] !== 'false' ){ |
---|
| 441 | |
---|
| 442 | $schedulable = self::_getSchedulable($uid); |
---|
| 443 | $params['calendar'] = self::_existInMyCalendars($schedulable['id']); |
---|
| 444 | |
---|
| 445 | $interation = self::_makeCOUNTER($schedulable , $component , $params); |
---|
| 446 | Config::regSet('noAlarm', FALSE); |
---|
| 447 | }else{ |
---|
| 448 | $response = array(); |
---|
| 449 | $response['from'] = $params['from']; |
---|
| 450 | $response['type'] = 'suggestionResponse'; |
---|
| 451 | $response['status'] = 'DECLINECOUNTER'; |
---|
| 452 | $response['schedulable'] = self::_getSchedulable($uid); |
---|
| 453 | |
---|
| 454 | Controller::create( array( 'concept' => 'notification' ) , $response); |
---|
| 455 | } |
---|
[5415] | 456 | break; |
---|
| 457 | |
---|
[5514] | 458 | case 'DECLINECOUNTER': |
---|
[5415] | 459 | break; |
---|
| 460 | |
---|
| 461 | default: |
---|
| 462 | $schedulable = self::_getSchedulable($uid); |
---|
| 463 | |
---|
| 464 | if($schedulable && ( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence'])) //Caso o evento exista |
---|
| 465 | $interation = self::_makeVEVENT($schedulable , $component , $params); |
---|
| 466 | else // Importar evento |
---|
[5514] | 467 | $interation = self::_makeVEVENT( array() , $component , $params); |
---|
[5341] | 468 | |
---|
[5415] | 469 | break; |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | $return[] = $interation; |
---|
| 473 | break; |
---|
| 474 | case 'VTIMEZONE': |
---|
[5341] | 475 | |
---|
| 476 | |
---|
[5415] | 477 | break; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | } |
---|
| 481 | |
---|
[5916] | 482 | return $return; |
---|
[5415] | 483 | } |
---|
| 484 | |
---|
| 485 | public function analize ( $data , $params = false) |
---|
| 486 | { |
---|
[5780] | 487 | $vcalendar = new icalCreator( ); |
---|
[5415] | 488 | $vcalendar->parse(trim($data)); |
---|
| 489 | $vcalendar->sort(); |
---|
[5341] | 490 | |
---|
[5415] | 491 | $return = array(); |
---|
| 492 | $method = $vcalendar->getProperty('method',FALSE , FALSE); |
---|
[5341] | 493 | |
---|
[5415] | 494 | while ($component = $vcalendar->getComponent()) |
---|
| 495 | { |
---|
[5514] | 496 | $interation = array(); |
---|
[5415] | 497 | $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente |
---|
[5341] | 498 | |
---|
[5415] | 499 | switch (strtoupper($component->objName)) { |
---|
| 500 | case 'VEVENT': |
---|
[5341] | 501 | |
---|
[5415] | 502 | switch ($method) |
---|
| 503 | { |
---|
| 504 | case 'PUBLISH': |
---|
| 505 | $interation = ICAL_ACTION_IMPORT; |
---|
| 506 | break; |
---|
[5341] | 507 | |
---|
[5415] | 508 | case 'REQUEST': |
---|
| 509 | $schedulable = self::_getSchedulable($uid); |
---|
| 510 | if($schedulable ) //Caso o evento exista |
---|
| 511 | { |
---|
[5947] | 512 | $isOrganizer = false; |
---|
| 513 | $isParticipant = false; |
---|
[5903] | 514 | |
---|
[5947] | 515 | foreach($schedulable['participants'] as $value) |
---|
| 516 | if($value['user']['id'] == Config::me('uidNumber')){ |
---|
| 517 | $isParticipant = true; |
---|
| 518 | if($value['isOrganizer']) |
---|
| 519 | $isOrganizer = true; |
---|
| 520 | |
---|
| 521 | if(!self::_existInMyCalendars($schedulable['id'])){ |
---|
| 522 | $interation = ICAL_ACTION_UPDATE; |
---|
| 523 | $interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : ICAL_ACTION_IMPORT; |
---|
| 524 | break; |
---|
| 525 | } |
---|
| 526 | }else |
---|
[5344] | 527 | { |
---|
[5415] | 528 | if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento |
---|
[5903] | 529 | $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; |
---|
[5415] | 530 | else |
---|
[5903] | 531 | $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE; |
---|
[5344] | 532 | } |
---|
[5916] | 533 | if(!$isParticipant) |
---|
| 534 | $interation = ICAL_ACTION_ORGANIZER_NONE; |
---|
[5415] | 535 | }else |
---|
| 536 | $interation = ICAL_ACTION_IMPORT; |
---|
[5341] | 537 | |
---|
[5415] | 538 | break; |
---|
[5341] | 539 | |
---|
[5415] | 540 | case 'REFRESH': |
---|
| 541 | break; |
---|
[5341] | 542 | |
---|
[5415] | 543 | case 'CANCEL': |
---|
| 544 | $interation = ICAL_ACTION_DELETE; |
---|
| 545 | break; |
---|
[5341] | 546 | |
---|
[5415] | 547 | case 'ADD': |
---|
| 548 | break; |
---|
[5341] | 549 | |
---|
[5415] | 550 | case 'REPLY': |
---|
| 551 | $interation = ICAL_ACTION_REPLY; |
---|
| 552 | break; |
---|
[5344] | 553 | |
---|
[5415] | 554 | case 'COUNTER': |
---|
[5903] | 555 | $interation = ICAL_ACTION_SUGGESTION; |
---|
[5415] | 556 | break; |
---|
[5344] | 557 | |
---|
[5514] | 558 | case 'DECLINECOUNTER': |
---|
| 559 | $interation = ICAL_ACTION_NONE; |
---|
| 560 | break; |
---|
[5344] | 561 | |
---|
[5415] | 562 | default: |
---|
| 563 | $schedulable = self::_getSchedulable($uid); |
---|
[5344] | 564 | |
---|
[5415] | 565 | if($schedulable && ( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence'])) //Caso o evento exista |
---|
| 566 | $interation = ICAL_ACTION_UPDATE; |
---|
| 567 | else if($schedulable) |
---|
| 568 | $interation = ICAL_ACTION_NONE; |
---|
| 569 | else // Importar evento |
---|
| 570 | $interation = ICAL_ACTION_IMPORT; |
---|
[5344] | 571 | |
---|
[5415] | 572 | break; |
---|
| 573 | } |
---|
[5341] | 574 | |
---|
[5415] | 575 | $return[$uid] = $interation; |
---|
| 576 | break; |
---|
| 577 | case 'VTIMEZONE': |
---|
[5344] | 578 | |
---|
| 579 | |
---|
[5415] | 580 | break; |
---|
| 581 | } |
---|
[5344] | 582 | |
---|
[5415] | 583 | } |
---|
[5341] | 584 | |
---|
[5415] | 585 | return $return; |
---|
[5341] | 586 | } |
---|
| 587 | |
---|
[5415] | 588 | |
---|
[5341] | 589 | /* Helpers */ |
---|
[5523] | 590 | private static function _getTzOffset($rTz, $oTz = null , $time = 'now') |
---|
[5341] | 591 | { |
---|
| 592 | if($oTz === null) { |
---|
| 593 | if(!is_string($oTz = date_default_timezone_get())) { |
---|
[5523] | 594 | return false; // A UTC timestamp was returned -- bail out! |
---|
[5341] | 595 | } |
---|
| 596 | } |
---|
| 597 | $origin_dtz = new DateTimeZone(self::nomalizeTZID($oTz)); |
---|
| 598 | $remote_dtz = new DateTimeZone(self::nomalizeTZID($rTz)); |
---|
[5523] | 599 | $origin_dt = new DateTime($time, $origin_dtz); |
---|
[5341] | 600 | $remote_dt = new DateTime("now", $remote_dtz); |
---|
[5523] | 601 | |
---|
[5341] | 602 | $offset = $origin_dtz->getOffset($origin_dt) - $remote_dtz->getOffset($remote_dt); |
---|
[5523] | 603 | |
---|
| 604 | |
---|
[5341] | 605 | return $offset; |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | private function _getStatus( $id ) |
---|
| 609 | { |
---|
| 610 | $a = array( |
---|
[5523] | 611 | STATUS_CONFIRMED => 'ACCEPTED', |
---|
[5341] | 612 | STATUS_CANCELLED => 'CANCELLED', |
---|
[5514] | 613 | STATUS_TENTATIVE => 'TENTATIVE', |
---|
[5341] | 614 | STATUS_UNANSWERED => 'NEEDS-ACTION', |
---|
| 615 | STATUS_DELEGATED => 'DELEGATED' |
---|
| 616 | ); |
---|
| 617 | |
---|
| 618 | return isset($a[ $id ]) ? $a[ $id ] : 'NEEDS-ACTION'; |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | private static function _getParticipantByMail( $mail , &$participants ) |
---|
[5415] | 622 | { |
---|
[5341] | 623 | foreach ($participants as $i => $v) |
---|
| 624 | if($v['user']['mail'] == $mail || (isset($v['user']['mailAlternateAddress']) && in_array($mail, $v['user']['mailAlternateAddress']))) |
---|
| 625 | return $v['id']; |
---|
| 626 | |
---|
| 627 | return false; |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | static private function nomalizeTZID ($TZID) |
---|
| 631 | { |
---|
| 632 | if(isset(self::$timezonesMap[$TZID])) |
---|
| 633 | return self::$timezonesMap[$TZID]; |
---|
| 634 | else if(in_array($TZID, self::$suportedTimzones)) |
---|
| 635 | return $TZID; |
---|
| 636 | else |
---|
| 637 | return date_default_timezone_get(); |
---|
| 638 | } |
---|
| 639 | |
---|
| 640 | static private function date2timestamp( $datetime, $tz=null ) |
---|
| 641 | { |
---|
| 642 | if( !isset( $datetime['hour'] )) $datetime['hour'] = '0'; |
---|
| 643 | if( !isset( $datetime['min'] )) $datetime['min'] = '0'; |
---|
| 644 | if( !isset( $datetime['sec'] )) $datetime['sec'] = '0'; |
---|
| 645 | |
---|
| 646 | foreach( $datetime as $dkey => $dvalue ) |
---|
| 647 | if( 'tz' != $dkey ) |
---|
| 648 | $datetime[$dkey] = (integer) $dvalue; |
---|
| 649 | |
---|
| 650 | if( $tz ) |
---|
| 651 | $datetime['tz'] = $tz; |
---|
| 652 | |
---|
| 653 | $offset = ( isset( $datetime['tz'] ) && ( '' < trim ( $datetime['tz'] ))) ? iCalUtilityFunctions::_tz2offset( $datetime['tz'] ) : 0; |
---|
| 654 | |
---|
| 655 | return gmmktime( $datetime['hour'], $datetime['min'], ($datetime['sec'] + $offset), $datetime['month'], $datetime['day'], $datetime['year'] ); |
---|
| 656 | } |
---|
| 657 | |
---|
[5514] | 658 | static private function _makeCOUNTER( $schedulable , $component ,$params) |
---|
| 659 | { |
---|
| 660 | $interation = array(); |
---|
| 661 | $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand().'(Formatter)'; |
---|
| 662 | |
---|
| 663 | /* Data de Inicio*/ |
---|
| 664 | $startTime = $component->getProperty( 'dtstart', false , true ); |
---|
| 665 | |
---|
| 666 | /* Tiem zone do evento*/ |
---|
| 667 | if(isset($startTime['params']['TZID'])) |
---|
| 668 | $schedulable['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); |
---|
| 669 | else |
---|
| 670 | $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; |
---|
| 671 | |
---|
| 672 | $objTimezone = new DateTimeZone($schedulable['timezone']); |
---|
| 673 | |
---|
| 674 | if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) |
---|
| 675 | { |
---|
| 676 | $schedulable['allDay'] = 1; |
---|
[5523] | 677 | $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone'], '@'.self::date2timestamp($startTime['value'])) . '000'; |
---|
[5514] | 678 | } |
---|
| 679 | 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 */ |
---|
[5523] | 680 | $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID'],'@'.self::date2timestamp($startTime['value'])) . '000'; |
---|
[5514] | 681 | $schedulable['allDay'] = 0; |
---|
| 682 | } |
---|
| 683 | else |
---|
| 684 | { |
---|
| 685 | $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; |
---|
| 686 | if( strpos($params['prodid'], 'Outlook') !== false ) |
---|
| 687 | { |
---|
| 688 | //Se o ics veio em utc não aplicar horario de verão |
---|
| 689 | $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , new DateTimeZone('UTC') ); |
---|
| 690 | $sTime->setTimezone($objTimezone); |
---|
| 691 | if($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão |
---|
| 692 | $schedulable['startTime'] = $schedulable['startTime'] - 3600000; |
---|
| 693 | } |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | |
---|
| 697 | /* Data de Termino*/ |
---|
| 698 | $endTime = $component->getProperty( 'dtend', false , true ); |
---|
| 699 | |
---|
| 700 | if($endTime['params']['VALUE'] === 'DATE') |
---|
[5523] | 701 | $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone'],'@'.self::date2timestamp($endTime['value'])) . '000'; |
---|
[5514] | 702 | 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 */ |
---|
[5523] | 703 | $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID'],'@'.self::date2timestamp($endTime['value'])) . '000'; |
---|
[5514] | 704 | else |
---|
| 705 | { |
---|
| 706 | $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; |
---|
| 707 | if( strpos($params['prodid'], 'Outlook') !== false ) |
---|
| 708 | { |
---|
| 709 | //Se o ics veio em utc não aplicar horario de verão |
---|
| 710 | $eTime = new DateTime( '@'.(int)($schedulable['endTime'] / 1000) ,new DateTimeZone('UTC')); |
---|
| 711 | $eTime->setTimezone($objTimezone); |
---|
| 712 | if($eTime->format('I')) |
---|
| 713 | $schedulable['endTime'] = $schedulable['endTime'] - 3600000; |
---|
| 714 | |
---|
| 715 | } |
---|
| 716 | } |
---|
| 717 | unset($schedulable['participants']); |
---|
| 718 | $interation['schedulable://'.$eventID] = $schedulable; |
---|
| 719 | |
---|
| 720 | return $interation; |
---|
| 721 | } |
---|
| 722 | |
---|
[5415] | 723 | static private function _makeVEVENT( $schedulable , $component ,$params) |
---|
| 724 | { |
---|
[5514] | 725 | |
---|
[5415] | 726 | $interation = array(); |
---|
| 727 | $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand().'(Formatter)'; |
---|
| 728 | |
---|
| 729 | /* Data de Inicio*/ |
---|
| 730 | $startTime = $component->getProperty( 'dtstart', false , true ); |
---|
[5863] | 731 | |
---|
[5415] | 732 | /* Tiem zone do evento*/ |
---|
| 733 | if(isset($startTime['params']['TZID'])) |
---|
| 734 | $schedulable['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); |
---|
| 735 | else |
---|
| 736 | $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; |
---|
| 737 | |
---|
| 738 | $objTimezone = new DateTimeZone($schedulable['timezone']); |
---|
| 739 | |
---|
[5592] | 740 | if(isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) |
---|
[5415] | 741 | { |
---|
| 742 | $schedulable['allDay'] = 1; |
---|
[5523] | 743 | $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone'],'@'.self::date2timestamp($startTime['value'])) . '000'; |
---|
[5415] | 744 | } |
---|
[5514] | 745 | 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 */ |
---|
[5523] | 746 | $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID'],'@'.self::date2timestamp($startTime['value'])) . '000'; |
---|
[5863] | 747 | $schedulable['allDay'] = 0; |
---|
| 748 | } |
---|
| 749 | else |
---|
[5415] | 750 | { |
---|
| 751 | $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; |
---|
| 752 | if( strpos($params['prodid'], 'Outlook') !== false ) |
---|
| 753 | { |
---|
| 754 | //Se o ics veio em utc não aplicar horario de verão |
---|
| 755 | $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , new DateTimeZone('UTC') ); |
---|
| 756 | $sTime->setTimezone($objTimezone); |
---|
| 757 | if($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão |
---|
| 758 | $schedulable['startTime'] = $schedulable['startTime'] - 3600000; |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | |
---|
| 762 | |
---|
| 763 | /* Data de Termino*/ |
---|
| 764 | $endTime = $component->getProperty( 'dtend', false , true ); |
---|
| 765 | |
---|
[5736] | 766 | if(isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') |
---|
[5523] | 767 | $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone'],'@'.self::date2timestamp($endTime['value'])) . '000'; |
---|
[5415] | 768 | 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 */ |
---|
[5523] | 769 | $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID'],'@'.self::date2timestamp($endTime['value'])) . '000'; |
---|
[5415] | 770 | else |
---|
| 771 | { |
---|
| 772 | $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; |
---|
| 773 | if( strpos($params['prodid'], 'Outlook') !== false ) |
---|
| 774 | { |
---|
| 775 | //Se o ics veio em utc não aplicar horario de verão |
---|
| 776 | $eTime = new DateTime( '@'.(int)($schedulable['endTime'] / 1000) ,new DateTimeZone('UTC')); |
---|
| 777 | $eTime->setTimezone($objTimezone); |
---|
| 778 | if($eTime->format('I')) |
---|
| 779 | $schedulable['endTime'] = $schedulable['endTime'] - 3600000; |
---|
| 780 | } |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | |
---|
[5592] | 784 | $schedulable['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'ISO-8859-1' , 'UTF-8,ISO-8859-1'); |
---|
[5415] | 785 | |
---|
| 786 | /* Definindo Description */ |
---|
| 787 | if($desc = $component->getProperty( 'description' , false , false )) |
---|
[5592] | 788 | $schedulable['description'] = mb_convert_encoding (str_ireplace (array('\n','\t'), array("\n","\t"), $desc) ,'ISO-8859-1' , 'UTF-8,ISO-8859-1'); |
---|
[5415] | 789 | |
---|
| 790 | /* Definindo location */ |
---|
| 791 | if($location = $component->getProperty( 'location' , false , false )) |
---|
[5592] | 792 | $schedulable['location'] = mb_convert_encoding ( $location , 'ISO-8859-1' , 'UTF-8,ISO-8859-1') ; |
---|
[5415] | 793 | |
---|
| 794 | |
---|
| 795 | /* Definindo Class */ |
---|
| 796 | $class = $component->getProperty( 'class' , false , false ); |
---|
| 797 | if( $class && defined(constant(strtoupper('CLASS_'.$class))) ) |
---|
| 798 | $schedulable['class'] = constant(strtoupper('CLASS_'.$class)); |
---|
| 799 | else if( !isset($exists['class']) ) |
---|
| 800 | $schedulable['class'] = CLASS_PRIVATE ; // padrão classe private |
---|
| 801 | |
---|
| 802 | /* Definindo RRULE */ |
---|
| 803 | if( $rrule = $component->getProperty( 'rrule' , false , false )) |
---|
| 804 | { |
---|
| 805 | /* Gera um randon id para o contexto formater */ |
---|
| 806 | $repeatID = mt_rand().'3(Formatter)'; |
---|
| 807 | |
---|
| 808 | $repeat = array(); |
---|
| 809 | $repeat['schedulable'] = $eventID; |
---|
| 810 | foreach($rrule as $i => $v) |
---|
[5715] | 811 | { |
---|
| 812 | if(strtolower($i) == 'freq') |
---|
| 813 | $repeat['frequency'] = $v; |
---|
| 814 | else if(strtolower($i) == 'until') |
---|
| 815 | $repeat['endTime'] = $v; |
---|
| 816 | else |
---|
| 817 | $repeat[strtolower($i)] = $v; |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | $interation['repeat://'.$repeatID] = $repeat; |
---|
[5415] | 821 | } |
---|
| 822 | |
---|
| 823 | |
---|
| 824 | $schedulable['calendar'] = $params['calendar']; |
---|
| 825 | |
---|
| 826 | $participantsInEvent = array(); |
---|
| 827 | |
---|
| 828 | //TODO: Participants com delegated não estao sendo levados em conta |
---|
| 829 | while($property = $component->getProperty('attendee',FALSE , TRUE)) |
---|
| 830 | { |
---|
| 831 | $participant = array(); |
---|
| 832 | |
---|
| 833 | $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); |
---|
| 834 | |
---|
| 835 | $participantID = mt_rand().'2(Formatter)'; |
---|
| 836 | $participant['schedulable'] = $eventID; |
---|
| 837 | |
---|
| 838 | if(isset($params['status']) && $mailUser == Config::me('mail')) |
---|
| 839 | $participant['status'] = $params['status']; |
---|
| 840 | else |
---|
| 841 | $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; |
---|
| 842 | |
---|
| 843 | |
---|
| 844 | $participant['isOrganizer'] = '0'; |
---|
| 845 | |
---|
| 846 | /* Verifica se este usuario é um usuario interno do ldap */ |
---|
[5441] | 847 | $intUser = Controller::find( array( 'concept' => 'user' ) , array('id','isExternal') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); |
---|
[5415] | 848 | |
---|
| 849 | $user = null; |
---|
| 850 | if( $intUser && count($intUser) > 0 ) |
---|
| 851 | { |
---|
[5441] | 852 | $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; |
---|
[5415] | 853 | $participant['user'] = $intUser[0]['id']; |
---|
| 854 | } |
---|
| 855 | else |
---|
| 856 | { |
---|
| 857 | $participant['isExternal'] = 1; |
---|
| 858 | /* Gera um randon id para o contexto formater */ |
---|
| 859 | $userID = mt_rand().'4(Formatter)'; |
---|
| 860 | |
---|
| 861 | $user['mail'] = $mailUser; |
---|
| 862 | $user['isExternal'] = '1'; |
---|
| 863 | $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; |
---|
| 864 | $user['participants'] = array($participantID); |
---|
| 865 | $participant['user'] = $userID; |
---|
| 866 | $interation['user://'.$userID] = $user; |
---|
| 867 | } |
---|
| 868 | |
---|
| 869 | $interation['participant://'.$participantID] = $participant; |
---|
| 870 | $schedulable['participants'][] = $participantID; |
---|
| 871 | |
---|
| 872 | }; |
---|
| 873 | |
---|
| 874 | if($property = $component->getProperty('organizer',FALSE , TRUE)) |
---|
| 875 | { |
---|
| 876 | $participant = array(); |
---|
| 877 | $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); |
---|
| 878 | |
---|
| 879 | $participantID = mt_rand().'2(Formatter)'; |
---|
| 880 | |
---|
| 881 | $participant['schedulable'] = $eventID; |
---|
| 882 | $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; |
---|
| 883 | $participant['isOrganizer'] = '1'; |
---|
[5514] | 884 | $participant['acl'] = 'rowi'; |
---|
[5415] | 885 | |
---|
| 886 | /* Verifica se este usuario é um usuario interno do ldap */ |
---|
[5441] | 887 | $intUser = Controller::find( array( 'concept' => 'user' ) , array('id','isExternal') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); |
---|
| 888 | |
---|
[5415] | 889 | $user = null; |
---|
| 890 | if( $intUser && count($intUser) > 0 ) |
---|
| 891 | { |
---|
[5441] | 892 | $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; |
---|
[5415] | 893 | $participant['user'] = $intUser[0]['id']; |
---|
| 894 | } |
---|
| 895 | else |
---|
| 896 | { |
---|
| 897 | $participant['isExternal'] = 1; |
---|
| 898 | /* Gera um randon id para o contexto formater */ |
---|
| 899 | $userID = mt_rand().'4(Formatter)'; |
---|
| 900 | |
---|
| 901 | $user['mail'] = $mailUser; |
---|
| 902 | $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; |
---|
| 903 | $user['participants'] = array($participantID); |
---|
| 904 | $user['isExternal'] = '1'; |
---|
| 905 | $participant['user'] = $userID; |
---|
| 906 | $interation['user://'.$userID] = $user; |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | $interation['participant://'.$participantID] = $participant; |
---|
| 910 | $schedulable['participants'][] = $participantID; |
---|
| 911 | |
---|
| 912 | } |
---|
| 913 | else if(!is_array($schedulable['participants']) || count($schedulable['participants']) < 1)//caso não tenha organizador o usuario se torna organizador |
---|
| 914 | { |
---|
| 915 | $user = Controller::read( array( 'concept' => 'user', 'id' => $params['owner'] ) , array('mail')); |
---|
| 916 | |
---|
| 917 | if(!self::_getParticipantByMail($user['mail'] , $exists['participants'])) |
---|
| 918 | { |
---|
| 919 | $participantID = mt_rand().'2(Formatter)'; |
---|
| 920 | |
---|
| 921 | $participant['schedulable'] = $eventID; |
---|
| 922 | $participant['status'] = STATUS_CONFIRMED; |
---|
| 923 | $participant['isOrganizer'] = '1'; |
---|
[5514] | 924 | $participant['acl'] = 'rowi'; |
---|
[5415] | 925 | $participant['isExternal'] = 0; |
---|
| 926 | $participant['user'] = $params['owner']; |
---|
| 927 | $interation['participant://'.$participantID] = $participant; |
---|
| 928 | $schedulable['participants'][] = $participantID; |
---|
| 929 | } |
---|
| 930 | } |
---|
| 931 | |
---|
| 932 | /* Definindo DTSTAMP */ |
---|
| 933 | if($dtstamp = self::_getTime($component , 'dtstamp') ) |
---|
| 934 | $schedulable['dtstamp'] = $dtstamp; |
---|
| 935 | |
---|
| 936 | /* Definindo TRANSP */ |
---|
[5736] | 937 | if(($tranp = $component->getProperty( 'transp', false , true )) && $tranp && is_string($tranp) && strtoupper($tranp) == 'OPAQUE') |
---|
[5415] | 938 | $schedulable['transparent'] = 1; |
---|
| 939 | |
---|
| 940 | /* Definindo last_update */ |
---|
| 941 | if($lastUpdate = self::_getTime($component , 'LAST-MODIFIED')) |
---|
| 942 | $schedulable['lastUpdate'] = $lastUpdate; |
---|
| 943 | |
---|
| 944 | |
---|
| 945 | if($sequence = $component->getProperty( 'SEQUENCE', false , false )) |
---|
| 946 | $schedulable['sequence'] = $sequence; |
---|
| 947 | |
---|
| 948 | if($uid = $component->getProperty( 'uid' , false , false )); |
---|
| 949 | $schedulable['uid'] = $uid; |
---|
[5514] | 950 | |
---|
| 951 | while($attach = $component->getProperty('ATTACH',FALSE , TRUE)){ |
---|
| 952 | |
---|
| 953 | $attachCurrent = array( 'name' => $attach['params']['X-FILENAME'], |
---|
| 954 | 'size' => strlen($attach['value']), |
---|
| 955 | 'type' => self::_getContentType($attach['params']['X-FILENAME']) |
---|
| 956 | ); |
---|
| 957 | |
---|
| 958 | $ids = Controller::find( array( 'concept' => 'attachment' ) , array('id') ,array( 'filter' => array('AND' , array( '=' , 'name' , $attachCurrent['name'] ), array( '=' , 'size' , $attachCurrent['size'] ), array( '=' , 'type' , $attachCurrent['type'] )))); |
---|
| 959 | |
---|
| 960 | if(!is_array($ids)){ |
---|
| 961 | $attachCurrent['source'] = $attach['value']; |
---|
| 962 | //insere o anexo no banco e pega id para colcar no relacionamento |
---|
| 963 | $idAttachment = Controller::create( array('concept' => 'attachment') , $attachCurrent ); |
---|
| 964 | }else |
---|
| 965 | $idAttachment = array('id' => $ids[0]['id']); |
---|
| 966 | |
---|
| 967 | $calendarToAttachmentId = mt_rand().'2(Formatter)'; |
---|
| 968 | $calendarToAttachment['attachment'] = $idAttachment['id'] ; |
---|
| 969 | $calendarToAttachment['schedulable'] = $eventID ; |
---|
| 970 | $interation['schedulableToAttachment://'.$calendarToAttachmentId] = $calendarToAttachment; |
---|
| 971 | |
---|
| 972 | $schedulable['attachments'][] = $calendarToAttachmentId; |
---|
| 973 | |
---|
| 974 | } |
---|
| 975 | |
---|
| 976 | $interation['schedulable://'.$eventID] = $schedulable; |
---|
| 977 | |
---|
| 978 | return $interation; |
---|
[5415] | 979 | } |
---|
| 980 | |
---|
| 981 | static private function _getSchedulable( $uid ) |
---|
| 982 | { |
---|
[5682] | 983 | $schedulable = Controller::find( array( 'concept' => 'schedulable' ) , false , array ( 'filter' => array( '=' , 'uid' , $uid ), 'deepness' => 2 )); |
---|
[5615] | 984 | return (isset($schedulable[0])) ? $schedulable[0] : false; |
---|
[5415] | 985 | } |
---|
| 986 | |
---|
| 987 | static private function _existInMyCalendars( $id ) |
---|
| 988 | { |
---|
[5947] | 989 | $sig = Controller::find(array('concept' => 'calendarSignature'), array('user','calendar', 'isOwner'), array('filter' => array('AND', array( '=' , 'user' , Config::me('uidNumber') ) , array('=' , 'isOwner' , '1' )))); |
---|
[5415] | 990 | $calendars = array(); |
---|
| 991 | foreach ($sig as $val) |
---|
| 992 | $calendars[] = $val['calendar']; |
---|
| 993 | |
---|
| 994 | $return = Controller::find( array( 'concept' => 'calendarToSchedulable' ) , null , array ( 'filter' => array('AND' , array( 'IN' , 'calendar' , $calendars ),array( '=' , 'schedulable' , $id )))); |
---|
[5514] | 995 | |
---|
| 996 | return (isset($return[0])) ? $return[0]['calendar'] : false; |
---|
[5415] | 997 | } |
---|
| 998 | |
---|
| 999 | static private function _getTime(&$component , $property) |
---|
| 1000 | { |
---|
| 1001 | if($date = $component->getProperty($property , false , true )) |
---|
[5523] | 1002 | 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'; |
---|
[5415] | 1003 | |
---|
| 1004 | return false; |
---|
| 1005 | } |
---|
[5514] | 1006 | |
---|
| 1007 | |
---|
| 1008 | static private function _getContentType( $fileName ) |
---|
| 1009 | { |
---|
| 1010 | $strFileType = strtolower(substr ( $fileName , strrpos($fileName, '.') )); |
---|
| 1011 | |
---|
| 1012 | switch( $strFileType ) |
---|
| 1013 | { |
---|
| 1014 | case ".asf": return "video/x-ms-asf"; |
---|
| 1015 | case ".avi": return "video/avi"; |
---|
| 1016 | case ".doc": return "application/msword"; |
---|
| 1017 | case ".zip": return "application/zip"; |
---|
| 1018 | case ".xls": return "application/vnd.ms-excel"; |
---|
| 1019 | case ".gif": return "image/gif"; |
---|
| 1020 | case ".bmp": return "image/bmp"; |
---|
| 1021 | case ".jpeg": |
---|
| 1022 | case ".jpg": return "image/jpeg"; |
---|
| 1023 | case ".wav": return "audio/wav"; |
---|
| 1024 | case ".mp3": return "audio/mpeg3"; |
---|
| 1025 | case ".mpeg": |
---|
| 1026 | case ".mpg": return "video/mpeg"; |
---|
| 1027 | case ".rtf": return "application/rtf"; |
---|
| 1028 | case ".html": |
---|
| 1029 | case ".htm": return "text/html"; |
---|
| 1030 | case ".xml": return "text/xml"; |
---|
| 1031 | case ".xsl": return "text/xsl"; |
---|
| 1032 | case ".css": return "text/css"; |
---|
| 1033 | case ".php": return "text/php"; |
---|
| 1034 | case ".asp": return "text/asp"; |
---|
| 1035 | case ".pdf": return "application/pdf"; |
---|
| 1036 | case ".png": return "image/png"; |
---|
| 1037 | case ".txt": return "text/plain"; |
---|
| 1038 | case ".log": return "text/plain"; |
---|
| 1039 | case ".wmv": return "video/x-ms-wmv"; |
---|
| 1040 | case ".sxc": return "application/vnd.sun.xml.calc"; |
---|
| 1041 | case ".odt": return "application/vnd.oasis.opendocument.text"; |
---|
| 1042 | case ".stc": return "application/vnd.sun.xml.calc.template"; |
---|
| 1043 | case ".sxd": return "application/vnd.sun.xml.draw"; |
---|
| 1044 | case ".std": return "application/vnd.sun.xml.draw.template"; |
---|
| 1045 | case ".sxi": return "application/vnd.sun.xml.impress"; |
---|
| 1046 | case ".sti": return "application/vnd.sun.xml.impress.template"; |
---|
| 1047 | case ".sxm": return "application/vnd.sun.xml.math"; |
---|
| 1048 | case ".sxw": return "application/vnd.sun.xml.writer"; |
---|
| 1049 | case ".sxq": return "application/vnd.sun.xml.writer.global"; |
---|
| 1050 | case ".stw": return "application/vnd.sun.xml.writer.template"; |
---|
| 1051 | case ".pps": return "application/vnd.ms-powerpoint"; |
---|
| 1052 | case ".odt": return "application/vnd.oasis.opendocument.text"; |
---|
| 1053 | case ".ott": return "application/vnd.oasis.opendocument.text-template"; |
---|
| 1054 | case ".oth": return "application/vnd.oasis.opendocument.text-web"; |
---|
| 1055 | case ".odm": return "application/vnd.oasis.opendocument.text-master"; |
---|
| 1056 | case ".odg": return "application/vnd.oasis.opendocument.graphics"; |
---|
| 1057 | case ".otg": return "application/vnd.oasis.opendocument.graphics-template"; |
---|
| 1058 | case ".odp": return "application/vnd.oasis.opendocument.presentation"; |
---|
| 1059 | case ".otp": return "application/vnd.oasis.opendocument.presentation-template"; |
---|
| 1060 | case ".ods": return "application/vnd.oasis.opendocument.spreadsheet"; |
---|
| 1061 | case ".ots": return "application/vnd.oasis.opendocument.spreadsheet-template"; |
---|
| 1062 | case ".odc": return "application/vnd.oasis.opendocument.chart"; |
---|
| 1063 | case ".odf": return "application/vnd.oasis.opendocument.formula"; |
---|
| 1064 | case ".odi": return "application/vnd.oasis.opendocument.image"; |
---|
| 1065 | case ".ndl": return "application/vnd.lotus-notes"; |
---|
| 1066 | case ".eml": return "text/plain"; |
---|
| 1067 | case ".ps" : return "application/postscript"; |
---|
| 1068 | default : return "application/octet-stream"; |
---|
| 1069 | } |
---|
| 1070 | } |
---|
[5341] | 1071 | } |
---|
| 1072 | ?> |
---|