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