Changeset 6996 for trunk/prototype/services/iCal.php
- Timestamp:
- 08/10/12 19:11:37 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/services/iCal.php
r6861 r6996 197 197 default: 198 198 break; 199 } 200 } 199 200 case TASK_ID: 201 202 $todo = $ical->newComponent('todo'); 203 204 $todo->setProperty('summary', $v['summary']); 205 $todo->setProperty('description', isset($v['description']) ? $v['description'] : ''); 206 $todo->setProperty('priority', $v['priority']); 207 $todo->setProperty('percent-complete', $v['percentage']); 208 $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 209 210 $timezone = new DateTimeZone('UTC'); 211 $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 212 $apTimezoneOBJ = new DateTimeZone($apTimezone); 213 214 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 215 $sTime->setTimezone($apTimezoneOBJ); 216 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 217 $eTime->setTimezone($apTimezoneOBJ); 218 219 if (isset($v['allDay']) && $v['allDay'] == 1) { 220 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 221 $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 222 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 223 } else { 224 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 225 $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 226 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 227 } 228 229 if(isset($v['due']) && $v['due'] != ''){ 230 $dueTime = new DateTime('@' . (int) ($v['due'] / 1000), $timezone); 231 $dueTime->setTimezone($apTimezoneOBJ); 232 233 $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 234 } 235 236 $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 237 238 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 239 $participants = $v['participants']; 240 else 241 $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 242 243 if (is_array($participants) && count($participants) > 0) 244 foreach ($participants as $ii => $vv) { 245 246 if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 247 { 248 if ($vv['isExternal'] == 1) 249 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 250 else 251 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 252 } 253 254 if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 255 { 256 $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'])))); 257 if(is_array($alarms)) 258 self::createAlarms($alarms, $todo); 259 } 260 261 } 262 263 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 264 $this->createAttendee($v['participants'], $todo); 265 266 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 267 $this->createAttachment($v['attachments'], $todo); 268 269 $todo->setProperty('uid', $v['uid']); 270 271 break; 272 273 default: 274 break; 275 } 276 } 201 277 202 278 203 279 return $ical->createCalendar(); 204 280 } 205 281 … … 624 700 else // Importar evento 625 701 $interation = self::_makeVEVENT(array(), $component, $params); 626 627 628 629 702 break; 630 703 } … … 633 706 $return[] = $interation; 634 707 break; 635 case 'VTIMEZONE': 636 637 638 break; 708 /***********************************************************************TODO*******************************************************************************/ 709 case 'VTODO': 710 switch ($method) { 711 case 'PUBLISH': 712 //Caso a tarefa não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 713 if (!$schedulable = self::_getSchedulable($uid)) 714 $interation = self::_makeVTODO($schedulable, $component, $params); 715 else{ 716 $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 717 array('AND', 718 array('=', 'calendar', $params['calendar']), 719 array('=', 'schedulable', $schedulable['id']) 720 ))); 721 722 if(!$links && !isset($links[0])) 723 Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id'])); 724 } 725 break; 726 727 case 'REQUEST': 728 $schedulable = self::_getSchedulable($uid); 729 730 if ($schedulable) { //Caso tarefa exista 731 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 732 733 $calendarToSchedulable = array(); 734 $calendarToSchedulable['calendar'] = $params['calendar']; 735 $calendarToSchedulable['schedulable'] = $schedulable['id']; 736 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 737 738 if (isset($params['status'])) { 739 if($params['owner'] != Config::me("uidNumber")){ 740 $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) ); 741 $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 742 }else 743 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 744 $interation['participant://' . $pID]['status'] = $params['status']; 745 } 746 Config::regSet('noAlarm', FALSE); //reativa notificação 747 } else { 748 749 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 750 $interation = self::_makeVEVENT($schedulable, $component, $params); 751 else if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) { 752 //Ler melhor rfc sobre isto 3.2.2.2 753 //Aparentemente é para retornar um ical com o evento atualizado para o attende 754 } 755 756 if (isset($params['status'])) { 757 if($params['owner'] != Config::me("uidNumber")){ 758 $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) ); 759 $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 760 }else 761 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 762 //Verifica a importação de eventos em que não participo 763 if ($pID) { 764 $interation['participant://' . $pID]['status'] = $params['status']; 765 } 766 } 767 } 768 } else { // Importar tarefa 769 $interation = self::_makeVEVENT(array(), $component, $params); 770 771 if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 772 773 /* Data de Inicio */ 774 $startTime = $component->getProperty('dtstart', false, true); 775 $tzid = isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 776 777 /* Tiem zone do evento */ 778 if ($tzid) 779 $sc['timezone'] = self::nomalizeTZID($tzid); 780 else 781 $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 782 783 $objTimezone = new DateTimeZone($sc['timezone']); 784 785 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 786 $sc['allDay'] = 1; 787 $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 788 } 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 */ 789 $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000'; 790 else { 791 $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 792 if (strpos($params['prodid'], 'Outlook') !== false) { 793 //Se o ics veio em utc não aplicar horario de verão 794 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC')); 795 $sTime->setTimezone($objTimezone); 796 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 797 $sc['startTime'] = $sc['startTime'] - 3600000; 798 } 799 } 800 801 /* Data de Termino */ 802 $endTime = $component->getProperty('dtend', false, true); 803 804 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 805 $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 806 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 */ 807 $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000'; 808 else { 809 $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 810 if (strpos($params['prodid'], 'Outlook') !== false) { 811 //Se o ics veio em utc não aplicar horario de verão 812 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC')); 813 $eTime->setTimezone($objTimezone); 814 if ($eTime->format('I')) 815 $sc['endTime'] = $sc['endTime'] - 3600000; 816 } 817 } 818 819 820 if ($uid = $component->getProperty('uid', false, false)) 821 $sc['uid'] = $uid; 822 823 $sc['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'UTF-8', 'UTF-8,ISO-8859-1'); 824 825 /* Definindo Description */ 826 if ($desc = $component->getProperty('description', false, false)) 827 $sc['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'UTF-8', 'UTF-8,ISO-8859-1'); 828 829 if ($priority = $component->getProperty('priority', false, false)) 830 $sc['priority'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $priority), 'UTF-8', 'UTF-8,ISO-8859-1'); 831 832 if ($status = $component->getProperty('status', false, false)) 833 $sc['status'] = $this->decodeStatusTodo(mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $status), 'UTF-8', 'UTF-8,ISO-8859-1')); 834 835 if ($percentage = $component->getProperty('percent-complete', false, false)) 836 $sc['percentage'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $percentage), 'UTF-8', 'UTF-8,ISO-8859-1'); 837 838 $todo->setProperty('priority', $v['priority']); 839 $todo->setProperty('percent-complete', $v['percentage']); 840 $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 841 842 /* Definindo location */ 843 if ($location = $component->getProperty('location', false, false)) 844 $sc['location'] = mb_convert_encoding($location, 'UTF-8', 'UTF-8,ISO-8859-1'); 845 846 847 848 if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 849 $participant = array(); 850 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 851 852 $participantID = mt_rand() . '2(Formatter)'; 853 854 $participant['isOrganizer'] = '1'; 855 856 $user = null; 857 858 $participant['isExternal'] = 1; 859 /* Gera um randon id para o contexto formater */ 860 $userID = mt_rand() . '4(Formatter)'; 861 862 $user['mail'] = $mailUser; 863 $organizerMail = $mailUser; 864 865 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 866 $user['isExternal'] = '1'; 867 $participant['user'] = $user; 868 869 $sc['participants'][] = $participant; 870 } 871 872 873 $participant['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 874 $participant['isOrganizer'] = '0'; 875 $participant['isExternal'] = 0; 876 $participant['user'] = array('mail' => Config::me('mail'), 'name' => Config::me('cn')); 877 $sc['participants'][] = $participant; 878 $sc['type'] = TODO_ID; 879 880 881 $ical['source'] = Controller::format(array('service' => 'iCal'), array($sc), array('method' => 'REPLY')); 882 $ical['type'] = 'application/ics'; 883 $ical['name'] = 'outlook.ics'; 884 885 $ical2['source'] = $ical['source']; 886 $ical2['type'] = 'text/calendar; method=REPLY'; 887 $ical2['name'] = 'thunderbird.ics'; 888 889 $timezone = new DateTimeZone('UTC'); 890 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), $timezone); 891 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), $timezone); 892 893 if (isset($sc['timezone'])) { 894 $sTime->setTimezone(new DateTimeZone($sc['timezone'])); 895 $eTime->setTimezone(new DateTimeZone($sc['timezone'])); 896 } 897 898 $data = array('startDate' => date_format($sTime, 'd/m/Y'), 899 'startTime' => (isset($sc['allDay']) && $sc['allDay'] ) ? '' : date_format($sTime, 'H:i'), 900 'endDate' => date_format($eTime, 'd/m/Y'), 901 'endTime' => isset($sc['allDay']) ? '' : date_format($eTime, 'H:i'), 902 'eventTitle' => $sc['summary'], 903 'eventLocation' => isset($sc['location']) ? $sc['location'] : '', 904 'timezone' => ($sc['timezone']) ? $sc['timezone'] : 'UTC', 905 'participant' => (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail'])); 906 907 $subject['notificationType'] = 'Convite Aceito'; 908 $subject['eventTitle'] = mb_convert_encoding($sc['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8'); 909 $subject['startDate'] = date_format($sTime, 'd/m/Y'); 910 $subject['startTime'] = ($sc['allDay']) ? '' : date_format($sTime, 'H:i'); 911 $subject['endDate'] = date_format($eTime, 'd/m/Y'); 912 $subject['endTime'] = ($sc['allDay']) ? '' : date_format($eTime, 'H:i'); 913 $subject['participant'] = Config::me('uid'); 914 915 $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 916 917 switch ($params['status']) { 918 case STATUS_ACCEPTED: 919 $tpl = 'notify_accept_body'; 920 $subject['notificationType'] = 'Convite Aceito'; 921 break; 922 case STATUS_TENTATIVE: 923 $tpl = 'notify_attempt_body'; 924 $subject['notificationType'] = 'Convite aceito provisoriamente'; 925 break; 926 case STATUS_CANCELLED: 927 $tpl = 'notify_reject_body'; 928 $subject['notificationType'] = 'Convite rejeitado'; 929 break; 930 } 931 932 require_once ROOTPATH . '/api/parseTPL.php'; 933 934 $mail = array(); 935 $mail['attachments'][] = $ical; 936 $mail['attachments'][] = $ical2; 937 938 $mail['isHtml'] = true; 939 $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $tpl . '.tpl'); 940 $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); 941 942 $mail['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; 943 $mail['to'] = $organizerMail; 944 945 946 Controller::create(array('service' => 'SMTP'), $mail); 947 } 948 } 949 break; 950 951 case 'REFRESH': 952 break; 953 954 case 'CANCEL': 955 if ($schedulable = self::_getSchedulable($uid)) 956 $interation['schedulable://' . $schedulable['id']] = false; 957 break; 958 959 case 'ADD': 960 break; 961 962 case 'REPLY': 963 if ($schedulable = self::_getSchedulable($uid)) { 964 while ($property = $component->getProperty('attendee', FALSE, TRUE)) 965 if ($pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) 966 $interation['participant://' . $pID] = array('id' => $pID, 'status' => constant('STATUS_' . strtoupper($property['params']['PARTSTAT']))); 967 968 $interation['schedulable://' . $schedulable['id']]['sequence'] = $schedulable['sequence'] + 1; 969 } 970 break; 971 972 case 'COUNTER': 973 if ($params['acceptedSuggestion'] !== 'false') { 974 975 $schedulable = self::_getSchedulable($uid); 976 $params['calendar'] = self::_existInMyCalendars($schedulable['id'], $params['owner']); 977 978 $interation = self::_makeCOUNTER($schedulable, $component, $params); 979 Config::regSet('noAlarm', FALSE); 980 } else { 981 $response = array(); 982 $response['from'] = $params['from']; 983 $response['type'] = 'suggestionResponse'; 984 $response['status'] = 'DECLINECOUNTER'; 985 $response['schedulable'] = self::_getSchedulable($uid); 986 987 Controller::create(array('concept' => 'notification'), $response); 988 } 989 break; 990 991 case 'DECLINECOUNTER': 992 break; 993 994 default: 995 996 $schedulable = self::_getSchedulable($uid); 997 998 if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) { //Caso o evento exista 999 $interation = self::_makeVEVENT($schedulable, $component, $params); 1000 1001 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 1002 $calendarToSchedulable = array(); 1003 $calendarToSchedulable['calendar'] = $params['calendar']; 1004 $calendarToSchedulable['schedulable'] = $schedulable['id']; 1005 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 1006 } 1007 } 1008 else // Importar evento 1009 $interation = self::_makeVEVENT(array(), $component, $params); 1010 1011 break; 1012 } 1013 1014 $return[] = $interation; 1015 break; 1016 /***********************************************************************TODO*******************************************************************************/ 1017 case 'VTIMEZONE': 1018 break; 639 1019 } 640 1020 } … … 653 1033 $interation = array(); 654 1034 $uid = $component->getProperty('uid', false, false); //Resgata o uid do componente 655 656 1035 switch (strtoupper($component->objName)) { 657 1036 case 'VEVENT': … … 659 1038 switch ($method) { 660 1039 case 'PUBLISH': 661 $interation = ICAL_ACTION_IMPORT;1040 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 662 1041 break; 663 1042 … … 676 1055 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 677 1056 $interation = ICAL_ACTION_UPDATE; 678 $interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : ICAL_ACTION_IMPORT;1057 $interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 679 1058 break; 680 1059 } … … 689 1068 } 690 1069 }else 691 $interation = ICAL_ACTION_IMPORT;1070 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 692 1071 693 1072 if(($interation != ICAL_ACTION_NONE) && ($interation != ICAL_ACTION_ORGANIZER_NONE) && ($interation != ICAL_ACTION_ORGANIZER_UPDATE) && ($interation != ICAL_ACTION_NONE)) { … … 744 1123 $interation = ICAL_ACTION_NONE; 745 1124 else // Importar evento 746 $interation = ICAL_ACTION_IMPORT; 1125 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 1126 1127 break; 1128 } 1129 1130 $return[$uid] = $interation; 1131 break; 1132 case 'VTODO': 1133 switch ($method) { 1134 case 'PUBLISH': 1135 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds'); 1136 break; 1137 1138 case 'REQUEST': 1139 $schedulable = self::_getSchedulable($uid); 1140 1141 if ($schedulable) { //Caso o evento exista 1142 $isOrganizer = false; 1143 $isParticipant = false; 1144 1145 foreach ($schedulable['participants'] as $value) 1146 if ($value['user']['id'] == $params['owner']) { 1147 $isParticipant = true; 1148 if ($value['isOrganizer']) 1149 $isOrganizer = true; 1150 1151 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 1152 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds'); 1153 break; 1154 } 1155 } else { 1156 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 1157 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 1158 else 1159 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE; 1160 } 1161 if (!$isParticipant){ 1162 $interation = self::_checkParticipantByPermissions($schedulable); 1163 } 1164 }else 1165 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds'); 1166 break; 1167 1168 case 'REFRESH': 1169 break; 1170 1171 case 'CANCEL': 1172 $interation = ICAL_ACTION_DELETE; 1173 break; 1174 1175 case 'ADD': 1176 break; 1177 1178 case 'REPLY': 1179 $interation = ICAL_ACTION_REPLY; 1180 break; 1181 1182 case 'COUNTER': 1183 $interation = ICAL_ACTION_SUGGESTION; 1184 break; 1185 1186 case 'DECLINECOUNTER': 1187 $interation = ICAL_ACTION_NONE; 1188 break; 1189 1190 default: 1191 $schedulable = self::_getSchedulable($uid); 1192 1193 if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) //Caso o evento exista 1194 $interation = ICAL_ACTION_UPDATE; 1195 else if ($schedulable) 1196 $interation = ICAL_ACTION_NONE; 1197 else // Importar evento 1198 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds'); 747 1199 748 1200 break; … … 752 1204 break; 753 1205 case 'VTIMEZONE': 754 755 756 break; 1206 break; 757 1207 } 758 1208 } … … 790 1240 791 1241 return isset($a[$id]) ? $a[$id] : 'NEEDS-ACTION'; 1242 } 1243 1244 public function decodeStatusTodo( $action ) 1245 { 1246 $a = array( 1247 'NEED_ACTION' => STATUS_TODO_NEED_ACTION, 1248 'IN_PROGRESS' => STATUS_TODO_IN_PROGRESS , 1249 'COMPLETED' => STATUS_TODO_COMPLETED , 1250 'CANCELLED' => STATUS_TODO_CANCELLED 1251 ); 1252 1253 return isset($a[$id]) ? $a[$id] : 'STATUS_TODO_NEED_ACTION'; 1254 1255 } 1256 1257 1258 private function _getStatusTodo($id) { 1259 $a = array( 1260 STATUS_TODO_NEED_ACTION => 'NEED_ACTION', 1261 STATUS_TODO_IN_PROGRESS => 'IN_PROGRESS', 1262 STATUS_TODO_COMPLETED => 'COMPLETED', 1263 STATUS_TODO_CANCELLED => 'CANCELLED' 1264 ); 1265 1266 return isset($a[$id]) ? $a[$id] : 'NEED_ACTION'; 792 1267 } 793 1268 … … 907 1382 } 908 1383 909 static private function _makeVEVENT($schedulable, $component, $params) {1384 static private function _makeVEVENT($schedulable, $component, $params) { 910 1385 $interation = array(); 911 1386 $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)'; … … 1008 1483 $participantsInEvent = array(); 1009 1484 1010 //TODO: Participants com delegated n ão estao sendo levados em conta1485 //TODO: Participants com delegated nao estao sendo levados em conta 1011 1486 while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 1012 1487 $participant = array(); … … 1189 1664 return $interation; 1190 1665 } 1666 1667 static private function _makeVTODO($schedulable, $component, $params) { 1668 $interation = array(); 1669 $todoID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)'; 1670 1671 /* Data de Inicio */ 1672 $startTime = $component->getProperty('dtstart', false, true); 1673 1674 $tzid = (isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']); 1675 1676 /* Tiem zone do evento */ 1677 if ($tzid){ 1678 $tzid = self::nomalizeTZID($tzid); 1679 $schedulable['timezone'] = $tzid; 1680 }else 1681 $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 1682 1683 $objTimezone = new DateTimeZone($schedulable['timezone']); 1684 1685 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 1686 $schedulable['allDay'] = 1; 1687 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 1688 } 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 */ 1689 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 1690 $schedulable['allDay'] = 0; 1691 } else { 1692 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 1693 if (strpos($params['prodid'], 'Outlook') !== false) { 1694 //Se o ics veio em utc não aplicar horario de verão 1695 $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 1696 $sTime->setTimezone($objTimezone); 1697 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 1698 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 1699 } 1700 } 1701 1702 /* Data de Termino */ 1703 $endTime = $component->getProperty('dtend', false, true); 1704 1705 $tzid = isset($endTime['params']['TZID']) ? $endTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 1706 1707 if($tzid) 1708 $tzid = self::nomalizeTZID($tzid); 1709 1710 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 1711 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 1712 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 */ 1713 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 1714 else { 1715 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 1716 if (strpos($params['prodid'], 'Outlook') !== false) { 1717 //Se o ics veio em utc não aplicar horario de verão 1718 $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 1719 $eTime->setTimezone($objTimezone); 1720 if ($eTime->format('I')) 1721 $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 1722 } 1723 } 1724 1725 $schedulable['type'] = '2'; //type schedulable 1726 $schedulable['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1727 1728 /* Definindo Description */ 1729 if ($desc = $component->getProperty('description', false, false)) 1730 $schedulable['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1731 1732 /* Definindo Class */ 1733 $class = $component->getProperty('class', false, false); 1734 if ($class && defined(constant(strtoupper('CLASS_' . $class)))) 1735 $schedulable['class'] = constant(strtoupper('CLASS_' . $class)); 1736 else if (!isset($schedulable['class'])) 1737 $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 1738 1739 $schedulable['calendar'] = $params['calendar']; 1740 1741 $participantsInTodo = array(); 1742 1743 //TODO: Participants com delegated nao estao sendo levados em conta 1744 while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 1745 $participant = array(); 1746 1747 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 1748 1749 $participantID = ($tpID = self::_getParticipantByMail($mailUser, $schedulable['participants'])) ? $tpID : mt_rand() . '2(Formatter)'; 1750 $participant['schedulable'] = $eventID; 1751 1752 if (isset($params['status']) && $mailUser == Config::me('mail')) 1753 $participant['status'] = $params['status']; 1754 else 1755 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1756 1757 1758 $participant['isOrganizer'] = '0'; 1759 1760 /* Verifica se este usuario é um usuario interno do ldap */ 1761 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 1762 1763 $user = null; 1764 if ($intUser && count($intUser) > 0) { 1765 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 1766 $participant['user'] = $intUser[0]['id']; 1767 } else { 1768 $participant['isExternal'] = 1; 1769 /* Gera um randon id para o contexto formater */ 1770 $userID = mt_rand() . '4(Formatter)'; 1771 1772 $user['mail'] = $mailUser; 1773 $user['isExternal'] = '1'; 1774 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 1775 $user['participants'] = array($participantID); 1776 $participant['user'] = $userID; 1777 $interation['user://' . $userID] = $user; 1778 } 1779 1780 $interation['participant://' . $participantID] = $participant; 1781 $schedulable['participants'][] = $participantID; 1782 }; 1783 1784 if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 1785 $participant = array(); 1786 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 1787 1788 $participantID = mt_rand() . '2(Formatter)'; 1789 1790 $participant['schedulable'] = $eventID; 1791 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1792 $participant['isOrganizer'] = '1'; 1793 $participant['acl'] = 'rowi'; 1794 1795 /* Verifica se este usuario é um usuario interno do ldap */ 1796 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 1797 1798 $user = null; 1799 if ($intUser && count($intUser) > 0) { 1800 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 1801 $participant['user'] = $intUser[0]['id']; 1802 } else { 1803 $participant['isExternal'] = 1; 1804 /* Gera um randon id para o contexto formater */ 1805 $userID = mt_rand() . '4(Formatter)'; 1806 1807 $user['mail'] = $mailUser; 1808 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 1809 $user['participants'] = array($participantID); 1810 $user['isExternal'] = '1'; 1811 $participant['user'] = $userID; 1812 $interation['user://' . $userID] = $user; 1813 } 1814 1815 $interation['participant://' . $participantID] = $participant; 1816 $schedulable['participants'][] = $participantID; 1817 } else if (!isset($schedulable['participants']) || !is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 1818 $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 1819 1820 if (!self::_getParticipantByMail($user['mail'], $schedulable['participants'])) { 1821 $participantID = mt_rand() . '2(Formatter)'; 1822 1823 $participant['schedulable'] = $todoID; 1824 $participant['status'] = STATUS_CONFIRMED; 1825 $participant['isOrganizer'] = '1'; 1826 $participant['acl'] = 'rowi'; 1827 $participant['isExternal'] = 0; 1828 $participant['user'] = $params['owner']; 1829 $interation['participant://' . $participantID] = $participant; 1830 $schedulable['participants'][] = $participantID; 1831 } 1832 } 1833 1834 $alarms = array(); 1835 1836 /* Definindo ALARMES */ 1837 while ($alarmComp = $component->getComponent('valarm')) 1838 { 1839 $alarm = array(); 1840 $alarmID = mt_rand() . '6(Formatter)'; 1841 $action = $alarmComp->getProperty('action', false, true); 1842 $trygger = $alarmComp->getProperty('trigger', false, true); 1843 $alarm['type'] = self::decodeAlarmAction($action['value']); 1844 1845 if(isset($trygger['value']['day'])) 1846 { 1847 $alarm['time'] = $trygger['value']['day']; 1848 $alarm['unit'] = 'd'; 1849 } 1850 else if(isset($trygger['value']['hour'])) 1851 { 1852 $alarm['time'] = $trygger['value']['hour']; 1853 $alarm['unit'] = 'h'; 1854 } 1855 else if(isset($trygger['value']['min'])) 1856 { 1857 $alarm['time'] = $trygger['value']['min']; 1858 $alarm['unit'] = 'm'; 1859 } 1860 1861 foreach ($interation as $iint => &$vint) 1862 { 1863 if(isset($vint['user']) && $vint['user'] == Config::me('uidNumber')) 1864 { 1865 $alarm['participant'] = str_replace('participant://', '', $iint); 1866 $vint['alarms'][] = $alarmID; 1867 } 1868 } 1869 $alarm['schedulable'] = $eventID; 1870 1871 $interation['alarm://' . $alarmID ] = $alarm; 1872 1873 } 1874 1875 1876 /* Definindo DTSTAMP */ 1877 if ($dtstamp = self::_getTime($component, 'dtstamp')) 1878 $schedulable['dtstamp'] = $dtstamp; 1879 1880 /* Definindo TRANSP */ 1881 if (($tranp = $component->getProperty('transp', false, true)) && $tranp && is_string($tranp) && strtoupper($tranp) == 'OPAQUE') 1882 $schedulable['transparent'] = 1; 1883 1884 /* Definindo last_update */ 1885 if ($lastUpdate = self::_getTime($component, 'LAST-MODIFIED')) 1886 $schedulable['lastUpdate'] = $lastUpdate; 1887 1888 1889 if ($sequence = $component->getProperty('SEQUENCE', false, false)) 1890 $schedulable['sequence'] = $sequence; 1891 1892 if ($uid = $component->getProperty('uid', false, false)) 1893 ; 1894 $schedulable['uid'] = $uid; 1895 1896 while ($attach = $component->getProperty('ATTACH', FALSE, TRUE)) { 1897 1898 $attachCurrent = array('name' => $attach['params']['X-FILENAME'], 1899 'size' => strlen($attach['value']), 1900 'type' => self::_getContentType($attach['params']['X-FILENAME']) 1901 ); 1902 1903 $ids = Controller::find(array('concept' => 'attachment'), array('id'), array('filter' => array('AND', array('=', 'name', $attachCurrent['name']), array('=', 'size', $attachCurrent['size']), array('=', 'type', $attachCurrent['type'])))); 1904 1905 if (!is_array($ids)) { 1906 $attachCurrent['source'] = $attach['value']; 1907 //insere o anexo no banco e pega id para colcar no relacionamento 1908 $idAttachment = Controller::create(array('concept' => 'attachment'), $attachCurrent); 1909 }else 1910 $idAttachment = array('id' => $ids[0]['id']); 1911 1912 $calendarToAttachmentId = mt_rand() . '2(Formatter)'; 1913 $calendarToAttachment['attachment'] = $idAttachment['id']; 1914 $calendarToAttachment['schedulable'] = $eventID; 1915 $interation['schedulableToAttachment://' . $calendarToAttachmentId] = $calendarToAttachment; 1916 1917 $schedulable['attachments'][] = $calendarToAttachmentId; 1918 } 1919 1920 $interation['schedulable://' . $todoID] = $schedulable; 1921 1922 return $interation; 1923 } 1191 1924 1192 1925 static private function _getSchedulable($uid) { … … 1196 1929 1197 1930 static private function _existInMyCalendars($id, $owner) { 1198 $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', ' user', $owner), array('=', 'isOwner', '1'))));1931 $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'isOwner', '1'), array('=', 'user', $owner)))); 1199 1932 $calendars = array(); 1200 1933 foreach ($sig as $val)
Note: See TracChangeset
for help on using the changeset viewer.