Changeset 7228 for branches/2.4/prototype/services/iCal.php
- Timestamp:
- 09/17/12 14:30:47 (12 years ago)
- Location:
- branches/2.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.4
- Property svn:mergeinfo changed
-
branches/2.4/prototype/services/iCal.php
r6834 r7228 16 16 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'); 17 17 18 public function format($data, $params = false) 19 { 20 $timezones = array_flip(self::$timezonesMap); 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 $params['X-WR-TIMEZONE'] = isset($timezones[$params['defaultTZI']]) ? $timezones[$params['defaultTZI']] : $params['defaultTZI']; 24 25 return (isset($params['compatible']) && $params['compatible']) ? 26 array('ical' => $this->createIcal($data, $params) , 'compatible' => $this->createCompatibleIcal($data, $params)) : 27 $this->createIcal($data, $params); 28 29 } 30 31 protected function createIcal($data, $params = false ) 32 { 33 $ical = new icalCreator(); 34 $ical->setProperty('method', isset($params['method']) ? $params['method'] : 'PUBLISH' ); 35 36 /* 37 * Seta propiedades obrigatorias para alguns softwares (Outlook) 38 */ 39 $ical->setProperty('x-wr-calname', 'Calendar Expresso'); 40 $ical->setProperty('X-WR-CALDESC', 'Calendar Expresso'); 41 $ical->setProperty('X-WR-TIMEZONE', $params['X-WR-TIMEZONE']); 42 43 foreach ($data as $i => $v) { 44 45 switch ($v['type']) { 46 case EVENT_ID: 47 $vevent = $ical->newComponent('vevent'); 48 49 $vevent->setProperty('summary', $v['summary']); 50 $vevent->setProperty('description', isset($v['description']) ? $v['description'] : ''); 51 $vevent->setProperty('location', $v['location']); 52 $vevent->setProperty('tranp', (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ) ? 'TRANSPARENT' : 'OPAQUE' ); 53 54 $timezone = new DateTimeZone('UTC'); 55 $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 56 $apTimezoneOBJ = new DateTimeZone($apTimezone); 57 58 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 59 $sTime->setTimezone($apTimezoneOBJ); 60 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 61 $eTime->setTimezone($apTimezoneOBJ); 62 63 if (( isset($v['repeat']) ) && ( isset($v['repeat']['frequency']) && $v['repeat']['frequency'] && $v['repeat']['frequency'] != 'none' )) 64 $vevent->setProperty('rrule', $this->formatIcalRepeat($v['repeat'])); 65 66 67 if (isset($v['allDay']) && $v['allDay'] == 1) { 68 $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 69 $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 70 $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 71 } else { 72 $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 73 $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 74 $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 18 public function format($data, $params = false) 19 { 20 $timezones = array_flip(self::$timezonesMap); 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 $params['X-WR-TIMEZONE'] = isset($timezones[$params['defaultTZI']]) ? $timezones[$params['defaultTZI']] : $params['defaultTZI']; 24 25 return (isset($params['compatible']) && $params['compatible']) ? 26 array('ical' => $this->createIcal($data, $params) , 'compatible' => $this->createCompatibleIcal($data, $params)) : 27 $this->createIcal($data, $params); 28 29 } 30 31 protected function createIcal($data, $params = false ) 32 { 33 $ical = new icalCreator(); 34 $ical->setProperty('method', isset($params['method']) ? $params['method'] : 'PUBLISH' ); 35 36 /* 37 * Seta propiedades obrigatorias para alguns softwares (Outlook) 38 */ 39 $ical->setProperty('x-wr-calname', 'Calendar Expresso'); 40 $ical->setProperty('X-WR-CALDESC', 'Calendar Expresso'); 41 $ical->setProperty('X-WR-TIMEZONE', $params['X-WR-TIMEZONE']); 42 43 foreach ($data as $i => $v) { 44 45 switch ($v['type']) { 46 case EVENT_ID: 47 $vevent = $ical->newComponent('vevent'); 48 49 $vevent->setProperty('summary', $v['summary']); 50 $vevent->setProperty('description', isset($v['description']) ? $v['description'] : ''); 51 $vevent->setProperty('location', $v['location']); 52 $vevent->setProperty('tranp', (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ) ? 'TRANSPARENT' : 'OPAQUE' ); 53 54 $timezone = new DateTimeZone('UTC'); 55 $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 56 $apTimezoneOBJ = new DateTimeZone($apTimezone); 57 58 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 59 $sTime->setTimezone($apTimezoneOBJ); 60 61 if (( isset($v['repeat']) ) && ( isset($v['repeat']['frequency']) && $v['repeat']['frequency'] && $v['repeat']['frequency'] != 'none' )) 62 $vevent->setProperty('rrule', $this->formatIcalRepeat($v['repeat'])); 63 64 65 if (isset($v['allDay']) && $v['allDay'] == 1) 66 { 67 $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 68 $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 69 } else 70 { 71 $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 72 $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 75 73 } 76 77 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 78 $participants = $v['participants']; 79 else 80 $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 81 82 if (is_array($participants) && count($participants) > 0) 83 foreach ($participants as $ii => $vv) { 84 85 if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 86 { 87 if ($vv['isExternal'] == 1) 88 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 89 else 90 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 91 } 92 93 if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 94 { 95 $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 96 if(is_array($alarms)) 97 self::createAlarms($alarms, $vevent); 98 } 99 100 } 101 102 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 103 $this->createAttendee($v['participants'], $vevent); 104 105 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 106 $this->createAttachment($v['attachments'], $vevent); 107 108 $vevent->setProperty('uid', $v['uid']); 109 110 break; 111 112 default: 113 break; 114 } 115 116 } 117 118 119 return $ical->createCalendar(); 120 } 121 122 protected function createCompatibleIcal($data, $params = false ) 123 { 124 $ical = new icalCreator(); 125 $ical->setProperty('method', isset($params['method']) ? $params['method'] : 'PUBLISH' ); 126 127 /* 128 * Seta propiedades obrigatorias para alguns softwares (Outlook) 129 */ 130 $ical->setProperty('x-wr-calname', 'Calendar Expresso'); 131 $ical->setProperty('X-WR-CALDESC', 'Calendar Expresso'); 132 $ical->setProperty('X-WR-TIMEZONE', $params['X-WR-TIMEZONE']); 133 134 foreach ($data as $i => $v) { 135 136 switch ($v['type']) { 137 case EVENT_ID: 138 $vevent = $ical->newComponent('vevent'); 139 140 $vevent->setProperty('summary', $v['summary']); 141 $vevent->setProperty('description', isset($v['description']) ? $v['description'] : ''); 142 $vevent->setProperty('location', $v['location']); 143 $vevent->setProperty('tranp', (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ) ? 'TRANSPARENT' : 'OPAQUE' ); 144 145 $timezone = new DateTimeZone('UTC'); 146 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 147 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 148 149 if (( isset($v['repeat']) ) && ( isset($v['repeat']['frequency']) && $v['repeat']['frequency'] && $v['repeat']['frequency'] != 'none' )) 150 $vevent->setProperty('rrule', $this->formatIcalRepeat($v['repeat'])); 151 152 if (isset($v['allDay']) && $v['allDay'] == 1) { 153 $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 154 $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 155 $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 156 } else { 157 $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822)); 158 $vevent->setProperty('dtend', $eTime->format(DATE_RFC822)); 159 $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 160 } 161 162 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 163 $participants = $v['participants']; 164 else 165 $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 166 167 if (is_array($participants) && count($participants) > 0) 168 foreach ($participants as $ii => $vv) { 169 170 if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 171 { 172 if ($vv['isExternal'] == 1) 173 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 174 else 175 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 176 } 177 178 if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 179 { 180 $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 181 if(is_array($alarms)) 182 self::createAlarms($alarms, $vevent); 183 } 184 185 } 186 187 188 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 189 $this->createAttendee($v['participants'], $vevent); 190 191 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 192 $this->createAttachment($v['attachments'], $vevent); 193 194 $vevent->setProperty('uid', $v['uid']); 195 196 break; 197 198 default: 199 break; 74 75 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 76 $participants = $v['participants']; 77 else 78 $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 79 80 if (is_array($participants) && count($participants) > 0) 81 foreach ($participants as $ii => $vv) { 82 83 if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 84 { 85 if ($vv['isExternal'] == 1) 86 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 87 else 88 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 89 } 90 91 if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 92 { 93 $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 94 if(is_array($alarms)) 95 self::createAlarms($alarms, $vevent); 96 } 97 98 } 99 100 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 101 $this->createAttendee($v['participants'], $vevent); 102 103 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 104 $this->createAttachment($v['attachments'], $vevent); 105 106 $vevent->setProperty('uid', $v['uid']); 107 break; 108 case TODO_ID: 109 110 $todo = $ical->newComponent('todo'); 111 112 $todo->setProperty('summary', $v['summary']); 113 $todo->setProperty('description', isset($v['description']) ? $v['description'] : ''); 114 $todo->setProperty('priority', $v['priority']); 115 $todo->setProperty('percent-complete', $v['percentage']); 116 $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 117 118 $timezone = new DateTimeZone('UTC'); 119 $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 120 $apTimezoneOBJ = new DateTimeZone($apTimezone); 121 122 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 123 $sTime->setTimezone($apTimezoneOBJ); 124 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 125 $eTime->setTimezone($apTimezoneOBJ); 126 127 if (isset($v['allDay']) && $v['allDay'] == 1) { 128 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 129 $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 130 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 131 } else { 132 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 133 $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 134 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 135 } 136 137 if(isset($v['due']) && $v['due'] != '' && (int)$v['due'] > 0){ 138 $dueTime = new DateTime('@' . (int) ($v['due'] / 1000), $timezone); 139 $dueTime->setTimezone($apTimezoneOBJ); 140 141 $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 142 $todo->setProperty('dueTime', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 143 } 144 145 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 146 $participants = $v['participants']; 147 else 148 $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 149 150 if (is_array($participants) && count($participants) > 0) 151 foreach ($participants as $ii => $vv) { 152 153 if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 154 { 155 if ($vv['isExternal'] == 1) 156 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 157 else 158 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 159 } 160 161 if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 162 { 163 $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 164 if(is_array($alarms)) 165 self::createAlarms($alarms, $todo); 166 } 167 168 } 169 170 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 171 $this->createAttendee($v['participants'], $todo); 172 173 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 174 $this->createAttachment($v['attachments'], $todo); 175 176 $todo->setProperty('uid', $v['uid']); 177 178 break; 179 default: 180 break; 200 181 } 201 182 } 183 return $ical->createCalendar(); 184 } 185 186 protected function createCompatibleIcal($data, $params = false ) 187 { 188 $ical = new icalCreator(); 189 $ical->setProperty('method', isset($params['method']) ? $params['method'] : 'PUBLISH' ); 190 191 /* 192 * Seta propiedades obrigatorias para alguns softwares (Outlook) 193 */ 194 $ical->setProperty('x-wr-calname', 'Calendar Expresso'); 195 $ical->setProperty('X-WR-CALDESC', 'Calendar Expresso'); 196 $ical->setProperty('X-WR-TIMEZONE', $params['X-WR-TIMEZONE']); 197 198 foreach ($data as $i => $v) { 199 200 switch ($v['type']) { 201 case EVENT_ID: 202 $vevent = $ical->newComponent('vevent'); 203 204 $vevent->setProperty('summary', $v['summary']); 205 $vevent->setProperty('description', isset($v['description']) ? $v['description'] : ''); 206 $vevent->setProperty('location', $v['location']); 207 $vevent->setProperty('tranp', (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ) ? 'TRANSPARENT' : 'OPAQUE' ); 208 209 $timezone = new DateTimeZone('UTC'); 210 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 211 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 212 213 if (( isset($v['repeat']) ) && ( isset($v['repeat']['frequency']) && $v['repeat']['frequency'] && $v['repeat']['frequency'] != 'none' )) 214 $vevent->setProperty('rrule', $this->formatIcalRepeat($v['repeat'])); 215 216 if (isset($v['allDay']) && $v['allDay'] == 1) { 217 $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 218 $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 219 $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 220 } else { 221 $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822)); 222 $vevent->setProperty('dtend', $eTime->format(DATE_RFC822)); 223 $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 224 } 225 226 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 227 $participants = $v['participants']; 228 else 229 $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 230 231 if (is_array($participants) && count($participants) > 0) 232 foreach ($participants as $ii => $vv) { 233 234 if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 235 { 236 if ($vv['isExternal'] == 1) 237 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 238 else 239 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 240 } 241 242 if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 243 { 244 $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 245 if(is_array($alarms)) 246 self::createAlarms($alarms, $vevent); 247 } 248 249 } 250 251 252 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 253 $this->createAttendee($v['participants'], $vevent); 254 255 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 256 $this->createAttachment($v['attachments'], $vevent); 257 258 $vevent->setProperty('uid', $v['uid']); 259 260 break; 261 262 default: 263 break; 264 265 case TODO_ID: 266 267 $todo = $ical->newComponent('todo'); 268 269 $todo->setProperty('summary', $v['summary']); 270 $todo->setProperty('description', isset($v['description']) ? $v['description'] : ''); 271 $todo->setProperty('priority', $v['priority']); 272 $todo->setProperty('percent-complete', $v['percentage']); 273 $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 274 275 $timezone = new DateTimeZone('UTC'); 276 $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 277 $apTimezoneOBJ = new DateTimeZone($apTimezone); 278 279 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 280 $sTime->setTimezone($apTimezoneOBJ); 281 282 if (isset($v['allDay']) && $v['allDay'] == 1) { 283 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 284 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 285 } else { 286 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 287 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 288 } 289 290 if(isset($v['due']) && $v['due'] != '' && (int)$v['due'] > 0){ 291 $dueTime = new DateTime('@' . (int) ($v['due'] / 1000), $timezone); 292 $dueTime->setTimezone($apTimezoneOBJ); 293 294 $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 295 } 296 297 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 298 $participants = $v['participants']; 299 else 300 $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 301 302 if (is_array($participants) && count($participants) > 0) 303 foreach ($participants as $ii => $vv) { 304 305 if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 306 { 307 if ($vv['isExternal'] == 1) 308 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 309 else 310 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 311 } 312 313 if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 314 { 315 $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 316 if(is_array($alarms)) 317 self::createAlarms($alarms, $todo); 318 } 319 320 } 321 322 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 323 $this->createAttendee($v['participants'], $todo); 324 325 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 326 $this->createAttachment($v['attachments'], $todo); 327 328 $todo->setProperty('uid', $v['uid']); 329 330 break; 331 332 default: 333 break; 334 } 335 } 202 336 203 337 … … 205 339 } 206 340 207 protected function formatIcalRepeat($pRepeat) 208 { 209 $repeat = array(); 210 211 foreach ($pRepeat as $ir => $rv) { 212 if ($rv) { 213 if ($ir == 'frequency' && $rv !== 'none') 214 $repeat['FREQ'] = $rv; 215 else if ($ir == 'endTime') { 216 $time = new DateTime('@' . (int) ($rv / 1000), new DateTimeZone('UTC')); 217 $time->setTimezone($apTimezoneOBJ); 218 $repeat['until'] = $time->format(DATE_RFC822); 219 } else if ($ir == 'count') 220 $repeat[$ir] = $rv; 221 else if ($ir == 'interval') 222 $repeat[$ir] = $rv; 223 else if ($ir !== 'schedulable' && $ir !== 'id' && $ir !== 'startTime') 224 $repeat[$ir] = explode(',', $rv); 225 } 226 } 227 return $repeat; 228 } 341 protected function formatIcalRepeat($pRepeat) 342 { 343 $repeat = array(); 344 345 foreach ($pRepeat as $ir => $rv) { 346 if ($rv) { 347 if ($ir == 'frequency' && $rv !== 'none') 348 $repeat['FREQ'] = $rv; 349 else if ($ir == 'endTime') { 350 $time = new DateTime('@' . (int) ($rv / 1000), new DateTimeZone('UTC')); 351 $time->setTimezone($apTimezoneOBJ); 352 $repeat['until'] = $time->format(DATE_RFC822); 353 } else if ($ir == 'count') 354 $repeat[$ir] = $rv; 355 else if ($ir == 'interval') 356 $repeat[$ir] = $rv; 357 else if ($ir !== 'schedulable' && $ir !== 'id' && $ir !== 'startTime') 358 $repeat[$ir] = explode(',', $rv); 359 } 360 } 361 return $repeat; 362 } 363 229 364 230 365 public function createAlarms($alarms, &$vevent) 231 366 { 232 foreach ($alarms as $ ia => $va)367 foreach ($alarms as $va) 233 368 { 234 369 $valarm = new valarm(); … … 336 471 case 'PUBLISH': 337 472 //Caso o evento não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 338 339 $interation = self::_makeVEVENT($schedulable, $component, $params);340 341 342 array('AND',343 array('=', 'calendar', $params['calendar']),344 array('=', 'schedulable', $schedulable['id'])345 )));346 347 348 349 350 473 if (!$schedulable = self::_getSchedulable($uid)) 474 $interation = self::_makeVEVENT($schedulable, $component, $params); 475 else{ 476 $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 477 array('AND', 478 array('=', 'calendar', $params['calendar']), 479 array('=', 'schedulable', $schedulable['id']) 480 ))); 481 482 if(!$links && !isset($links[0])) 483 Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id'])); 484 485 } 351 486 break; 352 487 … … 365 500 $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) ); 366 501 $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 367 }else 368 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 369 $interation['participant://' . $pID]['status'] = $params['status']; 502 }else{ 503 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 504 //caso nõa seja participante adiciona a lista de participantes 505 if(!$pID){ 506 $pID = mt_rand() . '2(Formatter)'; 507 $interation['participant://' . $pID]['status'] = $params['status']; 508 $interation['participant://' . $pID]['user'] = $params['owner']; 509 $interation['participant://' . $pID]['isOrganizer'] = '0'; 510 $interation['participant://' . $pID]['schedulable'] = $schedulable['id']; 511 }else 512 $interation['participant://' . $pID]['status'] = $params['status']; 513 } 370 514 } 371 515 … … 572 716 $interation['schedulable://' . $schedulable['id']] = false; 573 717 break; 574 718 575 719 case 'ADD': 576 720 break; … … 624 768 else // Importar evento 625 769 $interation = self::_makeVEVENT(array(), $component, $params); 626 627 628 629 770 break; 630 771 } … … 633 774 $return[] = $interation; 634 775 break; 635 case 'VTIMEZONE': 636 637 638 break; 776 /***********************************************************************TODO*******************************************************************************/ 777 case 'VTODO': 778 switch ($method) { 779 case 'PUBLISH': 780 //Caso a tarefa não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 781 if (!$schedulable = self::_getSchedulable($uid)) 782 $interation = self::_makeVTODO($schedulable, $component, $params); 783 else{ 784 $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 785 array('AND', 786 array('=', 'calendar', $params['calendar']), 787 array('=', 'schedulable', $schedulable['id']) 788 ))); 789 790 if(!$links && !isset($links[0])) 791 Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id'])); 792 } 793 break; 794 795 case 'REQUEST': 796 $schedulable = self::_getSchedulable($uid); 797 798 if ($schedulable) { //Caso tarefa exista 799 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 800 801 $calendarToSchedulable = array(); 802 $calendarToSchedulable['calendar'] = $params['calendar']; 803 $calendarToSchedulable['schedulable'] = $schedulable['id']; 804 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 805 806 if (isset($params['status'])) { 807 if($params['owner'] != Config::me("uidNumber")){ 808 $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) ); 809 $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 810 }else 811 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 812 $interation['participant://' . $pID]['status'] = $params['status']; 813 } 814 Config::regSet('noAlarm', FALSE); //reativa notificação 815 } else { 816 817 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 818 $interation = self::_makeVEVENT($schedulable, $component, $params); 819 else if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) { 820 //Ler melhor rfc sobre isto 3.2.2.2 821 //Aparentemente é para retornar um ical com o evento atualizado para o attende 822 } 823 824 if (isset($params['status'])) { 825 if($params['owner'] != Config::me("uidNumber")){ 826 $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) ); 827 $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 828 }else{ 829 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 830 //Verifica a importação de tarefas em que não participo 831 if ($pID) { 832 $pID = mt_rand() . '2(Formatter)'; 833 $interation['participant://' . $pID]['status'] = $params['status']; 834 $interation['participant://' . $pID]['user'] = $params['owner']; 835 $interation['participant://' . $pID]['isOrganizer'] = '0'; 836 $interation['participant://' . $pID]['schedulable'] = $schedulable['id']; 837 }else 838 $interation['participant://' . $pID]['status'] = $params['status']; 839 } 840 } 841 } 842 } else { // Importar tarefa 843 $interation = self::_makeVTODO(array(), $component, $params); 844 845 if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 846 847 /* Data de Inicio */ 848 $startTime = $component->getProperty('dtstart', false, true); 849 $tzid = isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 850 851 /* Tiem zone do evento */ 852 if ($tzid) 853 $sc['timezone'] = self::nomalizeTZID($tzid); 854 else 855 $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 856 857 $objTimezone = new DateTimeZone($sc['timezone']); 858 859 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 860 $sc['allDay'] = 1; 861 $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 862 } 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 */ 863 $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000'; 864 else { 865 $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 866 if (strpos($params['prodid'], 'Outlook') !== false) { 867 //Se o ics veio em utc não aplicar horario de verão 868 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC')); 869 $sTime->setTimezone($objTimezone); 870 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 871 $sc['startTime'] = $sc['startTime'] - 3600000; 872 } 873 } 874 875 /* Data de Termino */ 876 $endTime = $component->getProperty('dtend', false, true); 877 878 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 879 $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 880 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 */ 881 $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000'; 882 else { 883 $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 884 if (strpos($params['prodid'], 'Outlook') !== false) { 885 //Se o ics veio em utc não aplicar horario de verão 886 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC')); 887 $eTime->setTimezone($objTimezone); 888 if ($eTime->format('I')) 889 $sc['endTime'] = $sc['endTime'] - 3600000; 890 } 891 } 892 893 894 if ($uid = $component->getProperty('uid', false, false)) 895 $sc['uid'] = $uid; 896 897 $sc['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'UTF-8', 'UTF-8,ISO-8859-1'); 898 899 /* Definindo Description */ 900 if ($desc = $component->getProperty('description', false, false)) 901 $sc['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'UTF-8', 'UTF-8,ISO-8859-1'); 902 903 if ($priority = $component->getProperty('priority', false, false)) 904 $sc['priority'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $priority), 'UTF-8', 'UTF-8,ISO-8859-1'); 905 906 if ($status = $component->getProperty('status', false, false)) 907 $sc['status'] = $this->decodeStatusTodo(mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $status), 'UTF-8', 'UTF-8,ISO-8859-1')); 908 909 if ($percentage = $component->getProperty('percent-complete', false, false)) 910 $sc['percentage'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $percentage), 'UTF-8', 'UTF-8,ISO-8859-1'); 911 912 /* Definindo location */ 913 if ($location = $component->getProperty('location', false, false)) 914 $sc['location'] = mb_convert_encoding($location, 'UTF-8', 'UTF-8,ISO-8859-1'); 915 916 917 918 if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 919 $participant = array(); 920 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 921 922 $participantID = mt_rand() . '2(Formatter)'; 923 924 $participant['isOrganizer'] = '1'; 925 926 $user = null; 927 928 $participant['isExternal'] = 1; 929 /* Gera um randon id para o contexto formater */ 930 $userID = mt_rand() . '4(Formatter)'; 931 932 $user['mail'] = $mailUser; 933 $organizerMail = $mailUser; 934 935 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 936 $user['isExternal'] = '1'; 937 $participant['user'] = $user; 938 939 $sc['participants'][] = $participant; 940 } 941 942 943 $participant['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 944 $participant['isOrganizer'] = '0'; 945 $participant['isExternal'] = 0; 946 $participant['user'] = array('mail' => Config::me('mail'), 'name' => Config::me('cn')); 947 $sc['participants'][] = $participant; 948 $sc['type'] = TODO_ID; 949 950 951 $ical['source'] = Controller::format(array('service' => 'iCal'), array($sc), array('method' => 'REPLY')); 952 $ical['type'] = 'application/ics'; 953 $ical['name'] = 'outlook.ics'; 954 955 $ical2['source'] = $ical['source']; 956 $ical2['type'] = 'text/calendar; method=REPLY'; 957 $ical2['name'] = 'thunderbird.ics'; 958 959 $timezone = new DateTimeZone('UTC'); 960 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), $timezone); 961 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), $timezone); 962 963 if (isset($sc['timezone'])) { 964 $sTime->setTimezone(new DateTimeZone($sc['timezone'])); 965 $eTime->setTimezone(new DateTimeZone($sc['timezone'])); 966 } 967 968 $data = array('startDate' => date_format($sTime, 'd/m/Y'), 969 'startTime' => (isset($sc['allDay']) && $sc['allDay'] ) ? '' : date_format($sTime, 'H:i'), 970 'endDate' => date_format($eTime, 'd/m/Y'), 971 'endTime' => isset($sc['allDay']) ? '' : date_format($eTime, 'H:i'), 972 'eventTitle' => $sc['summary'], 973 'eventLocation' => isset($sc['location']) ? $sc['location'] : '', 974 'timezone' => ($sc['timezone']) ? $sc['timezone'] : 'UTC', 975 'participant' => (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail'])); 976 977 $subject['notificationType'] = 'Convite Aceito'; 978 $subject['eventTitle'] = mb_convert_encoding($sc['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8'); 979 $subject['startDate'] = date_format($sTime, 'd/m/Y'); 980 $subject['startTime'] = ($sc['allDay']) ? '' : date_format($sTime, 'H:i'); 981 $subject['endDate'] = date_format($eTime, 'd/m/Y'); 982 $subject['endTime'] = ($sc['allDay']) ? '' : date_format($eTime, 'H:i'); 983 $subject['participant'] = Config::me('uid'); 984 985 $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 986 987 switch ($params['status']) { 988 case STATUS_ACCEPTED: 989 $tpl = 'notify_accept_body'; 990 $subject['notificationType'] = 'Convite Aceito'; 991 break; 992 case STATUS_TENTATIVE: 993 $tpl = 'notify_attempt_body'; 994 $subject['notificationType'] = 'Convite aceito provisoriamente'; 995 break; 996 case STATUS_CANCELLED: 997 $tpl = 'notify_reject_body'; 998 $subject['notificationType'] = 'Convite rejeitado'; 999 break; 1000 } 1001 1002 require_once ROOTPATH . '/api/parseTPL.php'; 1003 1004 $mail = array(); 1005 $mail['attachments'][] = $ical; 1006 $mail['attachments'][] = $ical2; 1007 1008 $mail['isHtml'] = true; 1009 $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $tpl . '.tpl'); 1010 $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); 1011 1012 $mail['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; 1013 $mail['to'] = $organizerMail; 1014 1015 1016 Controller::create(array('service' => 'SMTP'), $mail); 1017 } 1018 } 1019 break; 1020 1021 case 'REFRESH': 1022 break; 1023 1024 case 'CANCEL': 1025 if ($schedulable = self::_getSchedulable($uid)) 1026 $interation['schedulable://' . $schedulable['id']] = false; 1027 break; 1028 1029 case 'ADD': 1030 break; 1031 1032 case 'REPLY': 1033 if ($schedulable = self::_getSchedulable($uid)) { 1034 while ($property = $component->getProperty('attendee', FALSE, TRUE)) 1035 if ($pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) 1036 $interation['participant://' . $pID] = array('id' => $pID, 'status' => constant('STATUS_' . strtoupper($property['params']['PARTSTAT']))); 1037 1038 $interation['schedulable://' . $schedulable['id']]['sequence'] = $schedulable['sequence'] + 1; 1039 } 1040 break; 1041 1042 case 'COUNTER': 1043 if ($params['acceptedSuggestion'] !== 'false') { 1044 1045 $schedulable = self::_getSchedulable($uid); 1046 $params['calendar'] = self::_existInMyCalendars($schedulable['id'], $params['owner']); 1047 1048 $interation = self::_makeCOUNTER($schedulable, $component, $params); 1049 Config::regSet('noAlarm', FALSE); 1050 } else { 1051 $response = array(); 1052 $response['from'] = $params['from']; 1053 $response['type'] = 'suggestionResponse'; 1054 $response['status'] = 'DECLINECOUNTER'; 1055 $response['schedulable'] = self::_getSchedulable($uid); 1056 1057 Controller::create(array('concept' => 'notification'), $response); 1058 } 1059 break; 1060 1061 case 'DECLINECOUNTER': 1062 break; 1063 1064 default: 1065 1066 $schedulable = self::_getSchedulable($uid); 1067 1068 if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) { //Caso o evento exista 1069 $interation = self::_makeVEVENT($schedulable, $component, $params); 1070 1071 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 1072 $calendarToSchedulable = array(); 1073 $calendarToSchedulable['calendar'] = $params['calendar']; 1074 $calendarToSchedulable['schedulable'] = $schedulable['id']; 1075 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 1076 } 1077 } 1078 else // Importar evento 1079 $interation = self::_makeVEVENT(array(), $component, $params); 1080 1081 break; 1082 } 1083 1084 $return[] = $interation; 1085 break; 1086 /***********************************************************************TODO*******************************************************************************/ 1087 case 'VTIMEZONE': 1088 break; 639 1089 } 640 1090 } … … 653 1103 $interation = array(); 654 1104 $uid = $component->getProperty('uid', false, false); //Resgata o uid do componente 655 656 1105 switch (strtoupper($component->objName)) { 657 1106 case 'VEVENT': … … 659 1108 switch ($method) { 660 1109 case 'PUBLISH': 661 $interation = ICAL_ACTION_IMPORT;1110 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 662 1111 break; 663 1112 … … 670 1119 foreach ($schedulable['participants'] as $value) 671 1120 if ($value['user']['id'] == $params['owner']) { 1121 $isParticipant = true; 1122 if ($value['isOrganizer']) 1123 $isOrganizer = true; 1124 1125 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 1126 $interation = ICAL_ACTION_UPDATE; 1127 $interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 1128 break; 1129 } 1130 } else { 1131 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 1132 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 1133 else 1134 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE; 1135 } 1136 if (!$isParticipant){ 1137 $interation = self::_checkParticipantByPermissions($schedulable); 1138 } 1139 }else 1140 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 1141 1142 if(($interation != ICAL_ACTION_NONE) && ($interation != ICAL_ACTION_ORGANIZER_NONE) && ($interation != ICAL_ACTION_ORGANIZER_UPDATE) && ($interation != ICAL_ACTION_NONE)) { 1143 if($params['owner'] != Config::me("uidNumber")){ 1144 $sig = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=', 'user', $params['owner']), array('=', 'isOwner', '1')))); 1145 $calendars = array(); 1146 foreach ($sig as $val) 1147 $calendars[] = $val['calendar']; 1148 1149 $calendarsPermission = Controller::find(array('concept' => 'calendarToPermission'), array('calendar'), array('filter' => array('AND', array('=', 'user', Config::me("uidNumber")), array('IN', 'calendar', $calendars)))); 1150 1151 foreach ($calendarsPermission as $val) 1152 $ids[] = $val['calendar']; 1153 1154 $interation = array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION ,'calendar' => $ids); 1155 } 1156 } 1157 1158 break; 1159 1160 case 'REFRESH': 1161 break; 1162 1163 case 'CANCEL': 1164 $interation = ICAL_ACTION_DELETE; 1165 break; 1166 1167 case 'ADD': 1168 break; 1169 1170 case 'REPLY': 1171 if ($schedulable = self::_getSchedulable($uid)) { 1172 while ($property = $component->getProperty('attendee', FALSE, TRUE)) 1173 if ($attendee = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'], true)) 1174 $interation = (constant('STATUS_' . strtoupper($property['params']['PARTSTAT'])) == $attendee['status']) ? ICAL_ACTION_NONE : ICAL_ACTION_REPLY; 1175 }else 1176 $interation = ICAL_NOT_FOUND; 1177 break; 1178 1179 case 'COUNTER': 1180 $interation = ICAL_ACTION_SUGGESTION; 1181 break; 1182 1183 case 'DECLINECOUNTER': 1184 $interation = ICAL_ACTION_NONE; 1185 break; 1186 1187 default: 1188 $schedulable = self::_getSchedulable($uid); 1189 1190 if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) //Caso o evento exista 1191 $interation = ICAL_ACTION_UPDATE; 1192 else if ($schedulable) 1193 $interation = ICAL_ACTION_NONE; 1194 else // Importar evento 1195 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 1196 1197 break; 1198 } 1199 1200 $return[$uid] = $interation; 1201 break; 1202 case 'VTODO': 1203 switch ($method) { 1204 case 'PUBLISH': 1205 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds'); 1206 break; 1207 1208 case 'REQUEST': 1209 $schedulable = self::_getSchedulable($uid); 1210 1211 if ($schedulable) { //Caso o evento exista 1212 $isOrganizer = false; 1213 $isParticipant = false; 1214 1215 foreach ($schedulable['participants'] as $value) 1216 if ($value['user']['id'] == $params['owner']) { 672 1217 $isParticipant = true; 673 1218 if ($value['isOrganizer']) 674 1219 $isOrganizer = true; 675 1220 676 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 677 $interation = ICAL_ACTION_UPDATE; 678 $interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : ICAL_ACTION_IMPORT; 1221 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 1222 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds'); 679 1223 break; 680 1224 } … … 689 1233 } 690 1234 }else 691 $interation = ICAL_ACTION_IMPORT; 692 693 if(($interation != ICAL_ACTION_NONE) && ($interation != ICAL_ACTION_ORGANIZER_NONE) && ($interation != ICAL_ACTION_ORGANIZER_UPDATE) && ($interation != ICAL_ACTION_NONE)) { 694 if($params['owner'] != Config::me("uidNumber")){ 695 $sig = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=', 'user', $params['owner']), array('=', 'isOwner', '1')))); 696 $calendars = array(); 697 foreach ($sig as $val) 698 $calendars[] = $val['calendar']; 699 700 $calendarsPermission = Controller::find(array('concept' => 'calendarToPermission'), array('calendar'), array('filter' => array('AND', array('=', 'user', Config::me("uidNumber")), array('IN', 'calendar', $calendars)))); 701 702 foreach ($calendarsPermission as $val) 703 $ids[] = $val['calendar']; 704 705 $interation = array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION ,'calendar' => $ids); 706 } 707 } 708 1235 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds'); 709 1236 break; 710 1237 … … 739 1266 $interation = ICAL_ACTION_NONE; 740 1267 else // Importar evento 741 $interation = ICAL_ACTION_IMPORT;1268 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds'); 742 1269 743 1270 break; … … 747 1274 break; 748 1275 case 'VTIMEZONE': 749 750 751 break; 1276 break; 752 1277 } 753 1278 } … … 787 1312 } 788 1313 1314 public function decodeStatusTodo( $action ) 1315 { 1316 $a = array( 1317 'NEED_ACTION' => STATUS_TODO_NEED_ACTION, 1318 'IN_PROGRESS' => STATUS_TODO_IN_PROGRESS , 1319 'COMPLETED' => STATUS_TODO_COMPLETED , 1320 'CANCELLED' => STATUS_TODO_CANCELLED 1321 ); 1322 1323 return isset($a[$action]) ? $a[$action] : 'STATUS_TODO_NEED_ACTION'; 1324 1325 } 1326 1327 1328 private function _getStatusTodo($id) { 1329 $a = array( 1330 STATUS_TODO_NEED_ACTION => 'NEED_ACTION', 1331 STATUS_TODO_IN_PROGRESS => 'IN_PROGRESS', 1332 STATUS_TODO_COMPLETED => 'COMPLETED', 1333 STATUS_TODO_CANCELLED => 'CANCELLED' 1334 ); 1335 1336 return isset($a[$id]) ? $a[$id] : 'NEED_ACTION'; 1337 } 1338 789 1339 private static function _checkParticipantByPermissions($schedulable) { 790 1340 791 $calendarIds = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=','isOwner','0'), array('=', 'user', Config::me("uidNumber")))));792 793 if($calendarIds && isset($calendarIds[0])){794 $ids = array();795 foreach($calendarIds as $value)796 array_push($ids, $value['calendar']);797 798 $signaturesOfOwners = Controller::find(array('concept' => 'calendarSignature'), false, array('filter' => array('AND', array('IN', 'calendar', $ids) , array('=','isOwner','1')), 'deepness' => 2 ));799 800 foreach($signaturesOfOwners as $value){801 if(self::_getParticipantByMail($value['user']['mail'], $schedulable['participants'])){802 $eventoFromCalendar = Controller::read( array( 'concept' => 'calendarToSchedulable') , false, array('filter' => array('AND', array('=','schedulable',$schedulable['id']), array('=','calendar', $value['calendar']['id']))));803 804 return ($eventoFromCalendar && isset($eventoFromCalendar[0])) ? ICAL_ACTION_NONE_FROM_PERMISSION : array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION, 'calendar' => array($value['calendar']['id']) );805 }806 }807 }808 return ICAL_ACTION_ORGANIZER_NONE;1341 $calendarIds = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=','isOwner','0'), array('=', 'user', Config::me("uidNumber"))))); 1342 1343 if($calendarIds && isset($calendarIds[0])){ 1344 $ids = array(); 1345 foreach($calendarIds as $value) 1346 array_push($ids, $value['calendar']); 1347 1348 $signaturesOfOwners = Controller::find(array('concept' => 'calendarSignature'), false, array('filter' => array('AND', array('IN', 'calendar', $ids) , array('=','isOwner','1')), 'deepness' => 2 )); 1349 1350 foreach($signaturesOfOwners as $value){ 1351 if(self::_getParticipantByMail($value['user']['mail'], $schedulable['participants'])){ 1352 $eventoFromCalendar = Controller::read( array( 'concept' => 'calendarToSchedulable') , false, array('filter' => array('AND', array('=','schedulable',$schedulable['id']), array('=','calendar', $value['calendar']['id'])))); 1353 1354 return ($eventoFromCalendar && isset($eventoFromCalendar[0])) ? ICAL_ACTION_NONE_FROM_PERMISSION : array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION, 'calendar' => array($value['calendar']['id']) ); 1355 } 1356 } 1357 } 1358 return array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 809 1359 } 810 1360 811 1361 812 private static function _getParticipantByMail($mail, &$participants ) {1362 private static function _getParticipantByMail($mail, &$participants, $isFull = false) { 813 1363 if ($participants && $participants != '') 814 1364 foreach ($participants as $i => $v) 815 1365 if ((is_array($v) && isset($v['user'])) && ($v['user']['mail'] == $mail || (isset($v['user']['mailAlternateAddress']) && in_array($mail, $v['user']['mailAlternateAddress'])))) 816 return$v['id'];1366 return !!$isFull ? $v : $v['id']; 817 1367 return false; 818 1368 } … … 903 1453 904 1454 static private function _makeVEVENT($schedulable, $component, $params) { 1455 $interation = array(); 1456 $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)'; 1457 1458 /* Data de Inicio */ 1459 $startTime = $component->getProperty('dtstart', false, true); 1460 1461 $tzid = (isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']); 1462 1463 /* Tiem zone do evento */ 1464 if ($tzid){ 1465 $tzid = self::nomalizeTZID($tzid); 1466 $schedulable['timezone'] = $tzid; 1467 }else 1468 $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 1469 1470 $objTimezone = new DateTimeZone($schedulable['timezone']); 1471 1472 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 1473 $schedulable['allDay'] = 1; 1474 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 1475 } elseif ($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 */ 1476 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 1477 $schedulable['allDay'] = 0; 1478 } else { 1479 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 1480 if (strpos($params['prodid'], 'Outlook') !== false) { 1481 //Se o ics veio em utc não aplicar horario de verão 1482 $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 1483 $sTime->setTimezone($objTimezone); 1484 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 1485 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 1486 } 1487 } 1488 1489 /* Data de Termino */ 1490 $endTime = $component->getProperty('dtend', false, true); 1491 1492 $tzid = isset($endTime['params']['TZID']) ? $endTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 1493 1494 if($tzid) 1495 $tzid = self::nomalizeTZID($tzid); 1496 1497 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 1498 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 1499 else if ($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 */ 1500 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 1501 else { 1502 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 1503 if (strpos($params['prodid'], 'Outlook') !== false) { 1504 //Se o ics veio em utc não aplicar horario de verão 1505 $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 1506 $eTime->setTimezone($objTimezone); 1507 if ($eTime->format('I')) 1508 $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 1509 } 1510 } 1511 1512 1513 $schedulable['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1514 1515 /* Definindo Description */ 1516 if ($desc = $component->getProperty('description', false, false)) 1517 $schedulable['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1518 1519 /* Definindo location */ 1520 if ($location = $component->getProperty('location', false, false)) 1521 $schedulable['location'] = mb_convert_encoding($location, 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1522 1523 1524 /* Definindo Class */ 1525 $class = $component->getProperty('class', false, false); 1526 if ($class && defined(constant(strtoupper('CLASS_' . $class)))) 1527 $schedulable['class'] = constant(strtoupper('CLASS_' . $class)); 1528 else if (!isset($schedulable['class'])) 1529 $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 1530 1531 /* Definindo RRULE */ 1532 if ($rrule = $component->getProperty('rrule', false, false)) { 1533 /* Gera um randon id para o contexto formater */ 1534 $repeatID = mt_rand() . '3(Formatter)'; 1535 1536 $repeat = array(); 1537 $repeat['schedulable'] = $eventID; 1538 foreach ($rrule as $i => $v) { 1539 if (strtolower($i) == 'freq') 1540 $repeat['frequency'] = $v; 1541 else if (strtolower($i) == 'until') 1542 $repeat['endTime'] = $v; 1543 else 1544 $repeat[strtolower($i)] = $v; 1545 } 1546 1547 $interation['repeat://' . $repeatID] = $repeat; 1548 } 1549 1550 1551 $schedulable['calendar'] = $params['calendar']; 1552 1553 $participantsInEvent = array(); 1554 1555 //TODO: Participants com delegated nao estao sendo levados em conta 1556 while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 1557 $participant = array(); 1558 1559 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 1560 1561 $participantID = ($tpID = self::_getParticipantByMail($mailUser, $schedulable['participants'])) ? $tpID : mt_rand() . '2(Formatter)'; 1562 $participant['schedulable'] = $eventID; 1563 1564 if (isset($params['status']) && $mailUser == Config::me('mail')) 1565 $participant['status'] = $params['status']; 1566 else 1567 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1568 1569 1570 $participant['isOrganizer'] = '0'; 1571 1572 /* Verifica se este usuario é um usuario interno do ldap */ 1573 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 1574 1575 $user = null; 1576 if ($intUser && count($intUser) > 0) { 1577 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 1578 $participant['user'] = $intUser[0]['id']; 1579 } else { 1580 $participant['isExternal'] = 1; 1581 /* Gera um randon id para o contexto formater */ 1582 $userID = mt_rand() . '4(Formatter)'; 1583 1584 $user['mail'] = $mailUser; 1585 $user['isExternal'] = '1'; 1586 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 1587 $user['participants'] = array($participantID); 1588 $participant['user'] = $userID; 1589 $interation['user://' . $userID] = $user; 1590 } 1591 1592 $interation['participant://' . $participantID] = $participant; 1593 $schedulable['participants'][] = $participantID; 1594 }; 1595 1596 if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 1597 $participant = array(); 1598 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 1599 1600 $participantID = mt_rand() . '2(Formatter)'; 1601 1602 $participant['schedulable'] = $eventID; 1603 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1604 $participant['isOrganizer'] = '1'; 1605 $participant['acl'] = 'rowi'; 1606 1607 /* Verifica se este usuario é um usuario interno do ldap */ 1608 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 1609 1610 $user = null; 1611 if ($intUser && count($intUser) > 0) { 1612 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 1613 $participant['user'] = $intUser[0]['id']; 1614 } else { 1615 $participant['isExternal'] = 1; 1616 /* Gera um randon id para o contexto formater */ 1617 $userID = mt_rand() . '4(Formatter)'; 1618 1619 $user['mail'] = $mailUser; 1620 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 1621 $user['participants'] = array($participantID); 1622 $user['isExternal'] = '1'; 1623 $participant['user'] = $userID; 1624 $interation['user://' . $userID] = $user; 1625 } 1626 1627 $interation['participant://' . $participantID] = $participant; 1628 $schedulable['participants'][] = $participantID; 1629 } else if (!isset($schedulable['participants']) || !is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 1630 $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 1631 1632 if (!self::_getParticipantByMail($user['mail'], $schedulable['participants'])) { 1633 $participantID = mt_rand() . '2(Formatter)'; 1634 1635 $participant['schedulable'] = $eventID; 1636 $participant['status'] = STATUS_CONFIRMED; 1637 $participant['isOrganizer'] = '1'; 1638 $participant['acl'] = 'rowi'; 1639 $participant['isExternal'] = 0; 1640 $participant['user'] = $params['owner']; 1641 $interation['participant://' . $participantID] = $participant; 1642 $schedulable['participants'][] = $participantID; 1643 } 1644 } 1645 1646 $alarms = array(); 1647 1648 /* Definindo ALARMES */ 1649 while ($alarmComp = $component->getComponent('valarm')) 1650 { 1651 $alarm = array(); 1652 $alarmID = mt_rand() . '6(Formatter)'; 1653 $action = $alarmComp->getProperty('action', false, true); 1654 $trygger = $alarmComp->getProperty('trigger', false, true); 1655 $alarm['type'] = self::decodeAlarmAction($action['value']); 1656 1657 if(isset($trygger['value']['day'])) 1658 { 1659 $alarm['time'] = $trygger['value']['day']; 1660 $alarm['unit'] = 'd'; 1661 } 1662 else if(isset($trygger['value']['hour'])) 1663 { 1664 $alarm['time'] = $trygger['value']['hour']; 1665 $alarm['unit'] = 'h'; 1666 } 1667 else if(isset($trygger['value']['min'])) 1668 { 1669 $alarm['time'] = $trygger['value']['min']; 1670 $alarm['unit'] = 'm'; 1671 } 1672 1673 foreach ($interation as $iint => &$vint) 1674 { 1675 if(isset($vint['user']) && $vint['user'] == Config::me('uidNumber')) 1676 { 1677 $alarm['participant'] = str_replace('participant://', '', $iint); 1678 $vint['alarms'][] = $alarmID; 1679 } 1680 } 1681 $alarm['schedulable'] = $eventID; 1682 1683 $interation['alarm://' . $alarmID ] = $alarm; 1684 1685 } 1686 1687 1688 /* Definindo DTSTAMP */ 1689 if ($dtstamp = self::_getTime($component, 'dtstamp')) 1690 $schedulable['dtstamp'] = $dtstamp; 1691 1692 /* Definindo TRANSP */ 1693 if (($tranp = $component->getProperty('transp', false, true)) && $tranp && is_string($tranp) && strtoupper($tranp) == 'OPAQUE') 1694 $schedulable['transparent'] = 1; 1695 1696 /* Definindo last_update */ 1697 if ($lastUpdate = self::_getTime($component, 'LAST-MODIFIED')) 1698 $schedulable['lastUpdate'] = $lastUpdate; 1699 1700 1701 if ($sequence = $component->getProperty('SEQUENCE', false, false)) 1702 $schedulable['sequence'] = $sequence; 1703 1704 if ($uid = $component->getProperty('uid', false, false)) 1705 ; 1706 $schedulable['uid'] = $uid; 1707 1708 while ($attach = $component->getProperty('ATTACH', FALSE, TRUE)) { 1709 1710 $attachCurrent = array('name' => $attach['params']['X-FILENAME'], 1711 'size' => strlen($attach['value']), 1712 'type' => self::_getContentType($attach['params']['X-FILENAME']) 1713 ); 1714 1715 $ids = Controller::find(array('concept' => 'attachment'), array('id'), array('filter' => array('AND', array('=', 'name', $attachCurrent['name']), array('=', 'size', $attachCurrent['size']), array('=', 'type', $attachCurrent['type'])))); 1716 1717 if (!is_array($ids)) { 1718 $attachCurrent['source'] = $attach['value']; 1719 //insere o anexo no banco e pega id para colcar no relacionamento 1720 $idAttachment = Controller::create(array('concept' => 'attachment'), $attachCurrent); 1721 }else 1722 $idAttachment = array('id' => $ids[0]['id']); 1723 1724 $calendarToAttachmentId = mt_rand() . '2(Formatter)'; 1725 $calendarToAttachment['attachment'] = $idAttachment['id']; 1726 $calendarToAttachment['schedulable'] = $eventID; 1727 $interation['schedulableToAttachment://' . $calendarToAttachmentId] = $calendarToAttachment; 1728 1729 $schedulable['attachments'][] = $calendarToAttachmentId; 1730 } 1731 1732 $schedulable['type'] = '1'; 1733 1734 $interation['schedulable://' . $eventID] = $schedulable; 1735 1736 return $interation; 1737 } 1738 1739 static private function _makeVTODO($schedulable, $component, $params) { 905 1740 $interation = array(); 906 $ eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)';1741 $todoID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)'; 907 1742 908 1743 /* Data de Inicio */ … … 938 1773 939 1774 /* Data de Termino */ 940 $endTime = $component->getProperty('dtend', false, true); 941 942 $tzid = isset($endTime['params']['TZID']) ? $endTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 943 944 if($tzid) 945 $tzid = self::nomalizeTZID($tzid); 946 947 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 948 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 949 else if ($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 */ 950 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 951 else { 952 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 953 if (strpos($params['prodid'], 'Outlook') !== false) { 954 //Se o ics veio em utc não aplicar horario de verão 955 $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 956 $eTime->setTimezone($objTimezone); 957 if ($eTime->format('I')) 958 $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 959 } 960 } 961 962 1775 if($due = $component->getProperty('due', false, true)){ 1776 1777 $tzid = isset($due['params']['TZID']) ? $due['params']['TZID'] : $params['X-WR-TIMEZONE']; 1778 1779 if($tzid) 1780 $tzid = self::nomalizeTZID($tzid); 1781 1782 if (isset($due['params']['VALUE']) && $due['params']['VALUE'] === 'DATE') 1783 $schedulable['due'] = self::date2timestamp($due['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($due['value'])) . '000'; 1784 else if ($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 */ 1785 $schedulable['due'] = self::date2timestamp($due['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($due['value'])) . '000'; 1786 else { 1787 $schedulable['due'] = self::date2timestamp($due['value']) . '000'; 1788 if (strpos($params['prodid'], 'Outlook') !== false) { 1789 //Se o ics veio em utc não aplicar horario de verão 1790 $dueTime = new DateTime('@' . (int) ($schedulable['due'] / 1000), new DateTimeZone('UTC')); 1791 $dueTime->setTimezone($objTimezone); 1792 1793 if ($dueTime->format('I')) 1794 $schedulable['due'] = $schedulable['due'] - 3600000; 1795 } 1796 } 1797 $schedulable['endTime'] = $schedulable['due']; 1798 }else 1799 $schedulable['endTime'] = $schedulable['startTime']; 1800 1801 $schedulable['type'] = '2'; //type schedulable 963 1802 $schedulable['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 964 1803 … … 966 1805 if ($desc = $component->getProperty('description', false, false)) 967 1806 $schedulable['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 968 969 /* Definindo location */970 if ($location = $component->getProperty('location', false, false))971 $schedulable['location'] = mb_convert_encoding($location, 'ISO-8859-1', 'UTF-8,ISO-8859-1');972 973 1807 974 1808 /* Definindo Class */ … … 979 1813 $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 980 1814 981 /* Definindo RRULE */982 if ($rrule = $component->getProperty('rrule', false, false)) {983 /* Gera um randon id para o contexto formater */984 $repeatID = mt_rand() . '3(Formatter)';985 986 $repeat = array();987 $repeat['schedulable'] = $eventID;988 foreach ($rrule as $i => $v) {989 if (strtolower($i) == 'freq')990 $repeat['frequency'] = $v;991 else if (strtolower($i) == 'until')992 $repeat['endTime'] = $v;993 else994 $repeat[strtolower($i)] = $v;995 }996 997 $interation['repeat://' . $repeatID] = $repeat;998 }999 1000 1001 1815 $schedulable['calendar'] = $params['calendar']; 1002 1816 1003 $participantsIn Event= array();1004 1005 //TODO: Participants com delegated n ão estao sendo levados em conta1817 $participantsInTodo = array(); 1818 1819 //TODO: Participants com delegated nao estao sendo levados em conta 1006 1820 while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 1007 1821 $participant = array(); … … 1010 1824 1011 1825 $participantID = ($tpID = self::_getParticipantByMail($mailUser, $schedulable['participants'])) ? $tpID : mt_rand() . '2(Formatter)'; 1012 $participant['schedulable'] = $ eventID;1826 $participant['schedulable'] = $todoID; 1013 1827 1014 1828 if (isset($params['status']) && $mailUser == Config::me('mail')) … … 1050 1864 $participantID = mt_rand() . '2(Formatter)'; 1051 1865 1052 $participant['schedulable'] = $ eventID;1866 $participant['schedulable'] = $todoID; 1053 1867 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1054 1868 $participant['isOrganizer'] = '1'; … … 1077 1891 $interation['participant://' . $participantID] = $participant; 1078 1892 $schedulable['participants'][] = $participantID; 1079 } else if (!is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador1893 } else if (!isset($schedulable['participants']) || !is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 1080 1894 $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 1081 1895 … … 1083 1897 $participantID = mt_rand() . '2(Formatter)'; 1084 1898 1085 $participant['schedulable'] = $ eventID;1899 $participant['schedulable'] = $todoID; 1086 1900 $participant['status'] = STATUS_CONFIRMED; 1087 1901 $participant['isOrganizer'] = '1'; … … 1180 1994 } 1181 1995 1182 $interation['schedulable://' . $ eventID] = $schedulable;1183 1184 1996 $interation['schedulable://' . $todoID] = $schedulable; 1997 1998 return $interation; 1185 1999 } 1186 2000 … … 1191 2005 1192 2006 static private function _existInMyCalendars($id, $owner) { 1193 $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'user', $owner), array('=', 'isOwner', '1')))); 2007 $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'isOwner', '1'), array('=', 'user', $owner)))); 2008 $sig2 = Controller::find(array('concept' => 'calendarToPermission'), array('calendar'), array('filter' => array('AND', array('*', 'acl', 'w'), array('=', 'user', $owner)))); 2009 1194 2010 $calendars = array(); 1195 foreach ($sig as $val) 1196 $calendars[] = $val['calendar']; 2011 if(is_array($sig)) 2012 foreach ($sig as $val) 2013 $calendars[] = $val['calendar']; 2014 if(is_array($sig2)) 2015 foreach ($sig2 as $val) 2016 $calendars[] = $val['calendar']; 2017 1197 2018 1198 2019 $return = Controller::find(array('concept' => 'calendarToSchedulable'), null, array('filter' => array('AND', array('IN', 'calendar', $calendars), array('=', 'schedulable', $id))));
Note: See TracChangeset
for help on using the changeset viewer.