Changeset 6891 for sandbox/2.4.2-expresso1/prototype/services/iCal.php
- Timestamp:
- 07/27/12 14:47:35 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.4.2-expresso1/prototype/services/iCal.php
r6528 r6891 122 122 break; 123 123 124 case TASK_ID: 125 126 $todo = $ical->newComponent('todo'); 127 128 $todo->setProperty('summary', $v['summary']); 129 $todo->setProperty('description', isset($v['description']) ? $v['description'] : ''); 130 $todo->setProperty('priority', $v['priority']); 131 $todo->setProperty('percent-complete', $v['percentage']); 132 $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 133 134 $timezone = new DateTimeZone('UTC'); 135 $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 136 $apTimezoneOBJ = new DateTimeZone($apTimezone); 137 138 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 139 $sTime->setTimezone($apTimezoneOBJ); 140 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 141 $eTime->setTimezone($apTimezoneOBJ); 142 143 if (isset($v['allDay']) && $v['allDay'] == 1) { 144 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 145 $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 146 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 147 } else { 148 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 149 $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 150 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 151 } 152 153 if(isset($v['due']) && $v['due'] != ''){ 154 $dueTime = new DateTime('@' . (int) ($v['due'] / 1000), $timezone); 155 $dueTime->setTimezone($apTimezoneOBJ); 156 157 $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 158 } 159 160 $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 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, $todo); 183 } 184 185 } 186 187 188 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 189 $this->createAttendee($v['participants'], $todo); 190 191 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 192 $this->createAttachment($v['attachments'], $todo); 193 194 $todo->setProperty('uid', $v['uid']); 195 196 break; 197 124 198 default: 125 199 break; … … 219 293 220 294 public function parse($data, $params = false) { 221 Config::regSet('noAlarm', TRUE); //Evita o envio de notifica ção295 Config::regSet('noAlarm', TRUE); //Evita o envio de notificação 222 296 $vcalendar = new icalCreator( ); 223 297 $vcalendar->parse(trim($data)); … … 232 306 $interation = array(); 233 307 $uid = $component->getProperty('uid', false, false); //Resgata o uid do componente 308 309 ob_start(); 310 print_r(strtoupper($component->objName)); 311 $output = ob_get_clean(); 312 file_put_contents( "/tmp/acoutinho.log", $output , FILE_APPEND); 313 234 314 235 315 switch (strtoupper($component->objName)) { … … 238 318 switch ($method) { 239 319 case 'PUBLISH': 240 //Caso o evento n ão exista o mesmo cria um novo evento, se jáexistir o mesmo referencia o evento com agenda320 //Caso o evento não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 241 321 if (!$schedulable = self::_getSchedulable($uid)) 242 322 $interation = self::_makeVEVENT($schedulable, $component, $params); … … 273 353 } 274 354 275 Config::regSet('noAlarm', FALSE); //reativa notifica ção355 Config::regSet('noAlarm', FALSE); //reativa notificação 276 356 } else { 277 357 278 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que voc êatualize o evento358 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 279 359 $interation = self::_makeVEVENT($schedulable, $component, $params); 280 360 else if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) { 281 361 //Ler melhor rfc sobre isto 3.2.2.2 282 //Aparentemente épara retornar um ical com o evento atualizado para o attende362 //Aparentemente é para retornar um ical com o evento atualizado para o attende 283 363 } 284 364 … … 289 369 }else 290 370 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 291 //Verifica a importa ção de eventos em que não participo371 //Verifica a importação de eventos em que não participo 292 372 if ($pID) { 293 373 $interation['participant://' . $pID]['status'] = $params['status']; … … 298 378 $interation = self::_makeVEVENT(array(), $component, $params); 299 379 300 if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notifica ção para fora380 if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 301 381 302 382 /* Data de Inicio */ … … 316 396 $sc['allDay'] = 1; 317 397 $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 318 } 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 */398 } 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 */ 319 399 $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000'; 320 400 else { 321 401 $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 322 402 if (strpos($params['prodid'], 'Outlook') !== false) { 323 //Se o ics veio em utc n ão aplicar horario de verão403 //Se o ics veio em utc não aplicar horario de verão 324 404 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC')); 325 405 $sTime->setTimezone($objTimezone); 326 if ($sTime->format('I')) //Se o ics veio em utc n ão aplicar horario de verão406 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 327 407 $sc['startTime'] = $sc['startTime'] - 3600000; 328 408 } … … 335 415 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 336 416 $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 337 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 */417 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 */ 338 418 $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000'; 339 419 else { 340 420 $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 341 421 if (strpos($params['prodid'], 'Outlook') !== false) { 342 //Se o ics veio em utc n ão aplicar horario de verão422 //Se o ics veio em utc não aplicar horario de verão 343 423 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC')); 344 424 $eTime->setTimezone($objTimezone); … … 527 607 else // Importar evento 528 608 $interation = self::_makeVEVENT(array(), $component, $params); 529 530 531 532 609 break; 533 610 } … … 536 613 $return[] = $interation; 537 614 break; 538 case 'VTIMEZONE': 539 540 541 break; 615 /***********************************************************************TODO*******************************************************************************/ 616 case 'VTODO': 617 switch ($method) { 618 case 'PUBLISH': 619 //Caso a tarefa não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 620 if (!$schedulable = self::_getSchedulable($uid)) 621 $interation = self::_makeVEVENT($schedulable, $component, $params); 622 else{ 623 $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 624 array('AND', 625 array('=', 'calendar', $params['calendar']), 626 array('=', 'schedulable', $schedulable['id']) 627 ))); 628 629 if(!$links && !isset($links[0])) 630 Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id'])); 631 } 632 break; 633 634 case 'REQUEST': 635 $schedulable = self::_getSchedulable($uid); 636 637 if ($schedulable) { //Caso tarefa exista 638 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 639 640 $calendarToSchedulable = array(); 641 $calendarToSchedulable['calendar'] = $params['calendar']; 642 $calendarToSchedulable['schedulable'] = $schedulable['id']; 643 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 644 645 if (isset($params['status'])) { 646 if($params['owner'] != Config::me("uidNumber")){ 647 $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) ); 648 $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 649 }else 650 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 651 $interation['participant://' . $pID]['status'] = $params['status']; 652 } 653 Config::regSet('noAlarm', FALSE); //reativa notificação 654 } else { 655 656 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 657 $interation = self::_makeVEVENT($schedulable, $component, $params); 658 else if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) { 659 //Ler melhor rfc sobre isto 3.2.2.2 660 //Aparentemente é para retornar um ical com o evento atualizado para o attende 661 } 662 663 if (isset($params['status'])) { 664 if($params['owner'] != Config::me("uidNumber")){ 665 $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) ); 666 $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 667 }else 668 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 669 //Verifica a importação de eventos em que não participo 670 if ($pID) { 671 $interation['participant://' . $pID]['status'] = $params['status']; 672 } 673 } 674 } 675 } else { // Importar tarefa 676 $interation = self::_makeVEVENT(array(), $component, $params); 677 678 if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 679 680 /* Data de Inicio */ 681 $startTime = $component->getProperty('dtstart', false, true); 682 $tzid = isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 683 684 /* Tiem zone do evento */ 685 if ($tzid) 686 $sc['timezone'] = self::nomalizeTZID($tzid); 687 else 688 $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 689 690 $objTimezone = new DateTimeZone($sc['timezone']); 691 692 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 693 $sc['allDay'] = 1; 694 $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 695 } 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 */ 696 $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000'; 697 else { 698 $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 699 if (strpos($params['prodid'], 'Outlook') !== false) { 700 //Se o ics veio em utc não aplicar horario de verão 701 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC')); 702 $sTime->setTimezone($objTimezone); 703 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 704 $sc['startTime'] = $sc['startTime'] - 3600000; 705 } 706 } 707 708 /* Data de Termino */ 709 $endTime = $component->getProperty('dtend', false, true); 710 711 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 712 $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 713 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 */ 714 $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000'; 715 else { 716 $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 717 if (strpos($params['prodid'], 'Outlook') !== false) { 718 //Se o ics veio em utc não aplicar horario de verão 719 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC')); 720 $eTime->setTimezone($objTimezone); 721 if ($eTime->format('I')) 722 $sc['endTime'] = $sc['endTime'] - 3600000; 723 } 724 } 725 726 727 if ($uid = $component->getProperty('uid', false, false)) 728 $sc['uid'] = $uid; 729 730 $sc['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'UTF-8', 'UTF-8,ISO-8859-1'); 731 732 /* Definindo Description */ 733 if ($desc = $component->getProperty('description', false, false)) 734 $sc['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'UTF-8', 'UTF-8,ISO-8859-1'); 735 736 if ($priority = $component->getProperty('priority', false, false)) 737 $sc['priority'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $priority), 'UTF-8', 'UTF-8,ISO-8859-1'); 738 739 if ($status = $component->getProperty('status', false, false)) 740 $sc['status'] = $this->decodeStatusTodo(mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $status), 'UTF-8', 'UTF-8,ISO-8859-1')); 741 742 if ($percentage = $component->getProperty('percent-complete', false, false)) 743 $sc['percentage'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $percentage), 'UTF-8', 'UTF-8,ISO-8859-1'); 744 745 $todo->setProperty('priority', $v['priority']); 746 $todo->setProperty('percent-complete', $v['percentage']); 747 $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 748 749 /* Definindo location */ 750 if ($location = $component->getProperty('location', false, false)) 751 $sc['location'] = mb_convert_encoding($location, 'UTF-8', 'UTF-8,ISO-8859-1'); 752 753 754 755 if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 756 $participant = array(); 757 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 758 759 $participantID = mt_rand() . '2(Formatter)'; 760 761 $participant['isOrganizer'] = '1'; 762 763 $user = null; 764 765 $participant['isExternal'] = 1; 766 /* Gera um randon id para o contexto formater */ 767 $userID = mt_rand() . '4(Formatter)'; 768 769 $user['mail'] = $mailUser; 770 $organizerMail = $mailUser; 771 772 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 773 $user['isExternal'] = '1'; 774 $participant['user'] = $user; 775 776 $sc['participants'][] = $participant; 777 } 778 779 780 $participant['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 781 $participant['isOrganizer'] = '0'; 782 $participant['isExternal'] = 0; 783 $participant['user'] = array('mail' => Config::me('mail'), 'name' => Config::me('cn')); 784 $sc['participants'][] = $participant; 785 $sc['type'] = TODO_ID; 786 787 788 $ical['source'] = Controller::format(array('service' => 'iCal'), array($sc), array('method' => 'REPLY')); 789 $ical['type'] = 'application/ics'; 790 $ical['name'] = 'outlook.ics'; 791 792 $ical2['source'] = $ical['source']; 793 $ical2['type'] = 'text/calendar; method=REPLY'; 794 $ical2['name'] = 'thunderbird.ics'; 795 796 $timezone = new DateTimeZone('UTC'); 797 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), $timezone); 798 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), $timezone); 799 800 if (isset($sc['timezone'])) { 801 $sTime->setTimezone(new DateTimeZone($sc['timezone'])); 802 $eTime->setTimezone(new DateTimeZone($sc['timezone'])); 803 } 804 805 $data = array('startDate' => date_format($sTime, 'd/m/Y'), 806 'startTime' => (isset($sc['allDay']) && $sc['allDay'] ) ? '' : date_format($sTime, 'H:i'), 807 'endDate' => date_format($eTime, 'd/m/Y'), 808 'endTime' => isset($sc['allDay']) ? '' : date_format($eTime, 'H:i'), 809 'eventTitle' => $sc['summary'], 810 'eventLocation' => isset($sc['location']) ? $sc['location'] : '', 811 'timezone' => ($sc['timezone']) ? $sc['timezone'] : 'UTC', 812 'participant' => (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail'])); 813 814 $subject['notificationType'] = 'Convite Aceito'; 815 $subject['eventTitle'] = mb_convert_encoding($sc['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8'); 816 $subject['startDate'] = date_format($sTime, 'd/m/Y'); 817 $subject['startTime'] = ($sc['allDay']) ? '' : date_format($sTime, 'H:i'); 818 $subject['endDate'] = date_format($eTime, 'd/m/Y'); 819 $subject['endTime'] = ($sc['allDay']) ? '' : date_format($eTime, 'H:i'); 820 $subject['participant'] = Config::me('uid'); 821 822 $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 823 824 switch ($params['status']) { 825 case STATUS_ACCEPTED: 826 $tpl = 'notify_accept_body'; 827 $subject['notificationType'] = 'Convite Aceito'; 828 break; 829 case STATUS_TENTATIVE: 830 $tpl = 'notify_attempt_body'; 831 $subject['notificationType'] = 'Convite aceito provisoriamente'; 832 break; 833 case STATUS_CANCELLED: 834 $tpl = 'notify_reject_body'; 835 $subject['notificationType'] = 'Convite rejeitado'; 836 break; 837 } 838 839 require_once ROOTPATH . '/api/parseTPL.php'; 840 841 $mail = array(); 842 $mail['attachments'][] = $ical; 843 $mail['attachments'][] = $ical2; 844 845 $mail['isHtml'] = true; 846 $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $tpl . '.tpl'); 847 $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); 848 849 $mail['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; 850 $mail['to'] = $organizerMail; 851 852 853 Controller::create(array('service' => 'SMTP'), $mail); 854 } 855 } 856 break; 857 858 case 'REFRESH': 859 break; 860 861 case 'CANCEL': 862 if ($schedulable = self::_getSchedulable($uid)) 863 $interation['schedulable://' . $schedulable['id']] = false; 864 break; 865 866 case 'ADD': 867 break; 868 869 case 'REPLY': 870 if ($schedulable = self::_getSchedulable($uid)) { 871 while ($property = $component->getProperty('attendee', FALSE, TRUE)) 872 if ($pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) 873 $interation['participant://' . $pID] = array('id' => $pID, 'status' => constant('STATUS_' . strtoupper($property['params']['PARTSTAT']))); 874 875 $interation['schedulable://' . $schedulable['id']]['sequence'] = $schedulable['sequence'] + 1; 876 } 877 break; 878 879 case 'COUNTER': 880 if ($params['acceptedSuggestion'] !== 'false') { 881 882 $schedulable = self::_getSchedulable($uid); 883 $params['calendar'] = self::_existInMyCalendars($schedulable['id'], $params['owner']); 884 885 $interation = self::_makeCOUNTER($schedulable, $component, $params); 886 Config::regSet('noAlarm', FALSE); 887 } else { 888 $response = array(); 889 $response['from'] = $params['from']; 890 $response['type'] = 'suggestionResponse'; 891 $response['status'] = 'DECLINECOUNTER'; 892 $response['schedulable'] = self::_getSchedulable($uid); 893 894 Controller::create(array('concept' => 'notification'), $response); 895 } 896 break; 897 898 case 'DECLINECOUNTER': 899 break; 900 901 default: 902 903 $schedulable = self::_getSchedulable($uid); 904 905 if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) { //Caso o evento exista 906 $interation = self::_makeVEVENT($schedulable, $component, $params); 907 908 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 909 $calendarToSchedulable = array(); 910 $calendarToSchedulable['calendar'] = $params['calendar']; 911 $calendarToSchedulable['schedulable'] = $schedulable['id']; 912 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 913 } 914 } 915 else // Importar evento 916 $interation = self::_makeVEVENT(array(), $component, $params); 917 918 break; 919 } 920 921 $return[] = $interation; 922 break; 923 /***********************************************************************TODO*******************************************************************************/ 924 case 'VTIMEZONE': 925 break; 542 926 } 543 927 } … … 556 940 $interation = array(); 557 941 $uid = $component->getProperty('uid', false, false); //Resgata o uid do componente 558 559 942 switch (strtoupper($component->objName)) { 560 943 case 'VEVENT': … … 583 966 } 584 967 } else { 585 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que voc êatualize o evento968 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 586 969 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 587 970 else … … 649 1032 $return[$uid] = $interation; 650 1033 break; 1034 case 'VTODO': 1035 switch ($method) { 1036 case 'PUBLISH': 1037 $interation = ICAL_ACTION_IMPORT; 1038 break; 1039 1040 case 'REQUEST': 1041 $schedulable = self::_getSchedulable($uid); 1042 1043 if ($schedulable) { //Caso o evento exista 1044 $isOrganizer = false; 1045 $isParticipant = false; 1046 1047 foreach ($schedulable['participants'] as $value) 1048 if ($value['user']['id'] == $params['owner']) { 1049 $isParticipant = true; 1050 if ($value['isOrganizer']) 1051 $isOrganizer = true; 1052 1053 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 1054 1055 ob_start(); 1056 print_r($schedulable['id']); 1057 print_r( $params['owner']); 1058 $output = ob_get_clean(); 1059 file_put_contents( "/tmp/acoutinho.log", $output , FILE_APPEND); 1060 1061 $interation = ICAL_ACTION_IMPORT; 1062 break; 1063 } 1064 } else { 1065 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 1066 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 1067 else 1068 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE; 1069 } 1070 if (!$isParticipant){ 1071 $interation = self::_checkParticipantByPermissions($schedulable); 1072 } 1073 }else 1074 $interation = ICAL_ACTION_IMPORT; 1075 break; 1076 1077 case 'REFRESH': 1078 break; 1079 1080 case 'CANCEL': 1081 $interation = ICAL_ACTION_DELETE; 1082 break; 1083 1084 case 'ADD': 1085 break; 1086 1087 case 'REPLY': 1088 $interation = ICAL_ACTION_REPLY; 1089 break; 1090 1091 case 'COUNTER': 1092 $interation = ICAL_ACTION_SUGGESTION; 1093 break; 1094 1095 case 'DECLINECOUNTER': 1096 $interation = ICAL_ACTION_NONE; 1097 break; 1098 1099 default: 1100 $schedulable = self::_getSchedulable($uid); 1101 1102 if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) //Caso o evento exista 1103 $interation = ICAL_ACTION_UPDATE; 1104 else if ($schedulable) 1105 $interation = ICAL_ACTION_NONE; 1106 else // Importar evento 1107 $interation = ICAL_ACTION_IMPORT; 1108 1109 break; 1110 } 1111 1112 $return[$uid] = $interation; 1113 break; 651 1114 case 'VTIMEZONE': 652 653 654 break; 1115 break; 655 1116 } 656 1117 } … … 690 1151 } 691 1152 1153 public function decodeStatusTodo( $action ) 1154 { 1155 $a = array( 1156 'NEED_ACTION' => STATUS_TODO_NEED_ACTION, 1157 'IN_PROGRESS' => STATUS_TODO_IN_PROGRESS , 1158 'COMPLETED' => STATUS_TODO_COMPLETED , 1159 'CANCELLED' => STATUS_TODO_CANCELLED 1160 ); 1161 1162 return isset($a[$id]) ? $a[$id] : 'STATUS_TODO_NEED_ACTION'; 1163 1164 } 1165 1166 1167 private function _getStatusTodo($id) { 1168 $a = array( 1169 STATUS_TODO_NEED_ACTION => 'NEED_ACTION', 1170 STATUS_TODO_IN_PROGRESS => 'IN_PROGRESS', 1171 STATUS_TODO_COMPLETED => 'COMPLETED', 1172 STATUS_TODO_CANCELLED => 'CANCELLED' 1173 ); 1174 1175 return isset($a[$id]) ? $a[$id] : 'NEED_ACTION'; 1176 } 1177 692 1178 private static function _checkParticipantByPermissions($schedulable) { 693 1179 … … 768 1254 $schedulable['allDay'] = 1; 769 1255 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 770 } 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 */1256 } 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 */ 771 1257 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID'], '@' . self::date2timestamp($startTime['value'])) . '000'; 772 1258 $schedulable['allDay'] = 0; … … 774 1260 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 775 1261 if (strpos($params['prodid'], 'Outlook') !== false) { 776 //Se o ics veio em utc n ão aplicar horario de verão1262 //Se o ics veio em utc não aplicar horario de verão 777 1263 $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 778 1264 $sTime->setTimezone($objTimezone); 779 if ($sTime->format('I')) //Se o ics veio em utc n ão aplicar horario de verão1265 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 780 1266 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 781 1267 } … … 787 1273 if ($endTime['params']['VALUE'] === 'DATE') 788 1274 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 789 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 */1275 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 */ 790 1276 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID'], '@' . self::date2timestamp($endTime['value'])) . '000'; 791 1277 else { 792 1278 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 793 1279 if (strpos($params['prodid'], 'Outlook') !== false) { 794 //Se o ics veio em utc n ão aplicar horario de verão1280 //Se o ics veio em utc não aplicar horario de verão 795 1281 $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 796 1282 $eTime->setTimezone($objTimezone); … … 826 1312 $schedulable['allDay'] = 1; 827 1313 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 828 } 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 */1314 } 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 */ 829 1315 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 830 1316 $schedulable['allDay'] = 0; … … 832 1318 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 833 1319 if (strpos($params['prodid'], 'Outlook') !== false) { 834 //Se o ics veio em utc n ão aplicar horario de verão1320 //Se o ics veio em utc não aplicar horario de verão 835 1321 $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 836 1322 $sTime->setTimezone($objTimezone); 837 if ($sTime->format('I')) //Se o ics veio em utc n ão aplicar horario de verão1323 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 838 1324 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 839 1325 } … … 850 1336 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 851 1337 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 852 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 */1338 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 */ 853 1339 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 854 1340 else { 855 1341 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 856 1342 if (strpos($params['prodid'], 'Outlook') !== false) { 857 //Se o ics veio em utc n ão aplicar horario de verão1343 //Se o ics veio em utc não aplicar horario de verão 858 1344 $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 859 1345 $eTime->setTimezone($objTimezone); … … 880 1366 $schedulable['class'] = constant(strtoupper('CLASS_' . $class)); 881 1367 else if (!isset($schedulable['class'])) 882 $schedulable['class'] = CLASS_PRIVATE; // padr ão classe private1368 $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 883 1369 884 1370 /* Definindo RRULE */ … … 906 1392 $participantsInEvent = array(); 907 1393 908 //TODO: Participants com delegated n ão estao sendo levados em conta1394 //TODO: Participants com delegated não estao sendo levados em conta 909 1395 while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 910 1396 $participant = array(); … … 923 1409 $participant['isOrganizer'] = '0'; 924 1410 925 /* Verifica se este usuario éum usuario interno do ldap */1411 /* Verifica se este usuario é um usuario interno do ldap */ 926 1412 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 927 1413 … … 958 1444 $participant['acl'] = 'rowi'; 959 1445 960 /* Verifica se este usuario éum usuario interno do ldap */1446 /* Verifica se este usuario é um usuario interno do ldap */ 961 1447 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 962 1448 … … 980 1466 $interation['participant://' . $participantID] = $participant; 981 1467 $schedulable['participants'][] = $participantID; 982 } else if (!is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso n ão tenha organizador o usuario se torna organizador1468 } else if (!is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 983 1469 $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 984 1470 … … 1094 1580 1095 1581 static private function _existInMyCalendars($id, $owner) { 1096 $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', ' user', $owner), array('=', 'isOwner', '1'))));1582 $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'isOwner', '1'), array('=', 'user', $owner)))); 1097 1583 $calendars = array(); 1098 1584 foreach ($sig as $val)
Note: See TracChangeset
for help on using the changeset viewer.