Changeset 5514 for trunk/prototype/services/iCal.php
- Timestamp:
- 02/14/12 16:52:04 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/services/iCal.php
r5481 r5514 14 14 15 15 public function format ($data , $params = false) 16 { 16 { 17 17 $timezones = array_flip(self::$timezonesMap); 18 18 … … 63 63 $vevent->setProperty( 'X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE' ); 64 64 } 65 66 if(isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0 ) 67 foreach ($v['participants'] as $pi => $pv) 68 { 69 if($pv['isOrganizer'] == 1) 70 $vevent->setProperty( 'organizer' , $pv['user']['mail'], array( 'CN' => $pv['user']['name'] )); 71 else 72 { 73 $pParams = array(); 74 $pParams['CN'] = $pv['user']['name']; 75 $pParams['PARTSTAT'] = self::_getStatus( $pv['status'] ); 76 $pParams['RSVP'] = 'TRUE'; 77 78 79 //TODO: Implementar o delegated 80 $vevent->setProperty( 'attendee' , $pv['user']['mail'], $pParams); 81 } 82 83 } 84 65 66 if(isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0 ) 67 $this->createAttendee($v['participants'], $vevent); 68 69 if(isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0 ) 70 $this->createAttachment($v['attachments'], $vevent); 71 85 72 $vevent->setProperty( 'uid' , $v['uid'] ); 86 73 87 74 //Todo: Implementar Repetição 88 75 … … 91 78 default: 92 79 break; 93 } 94 95 80 } 96 81 } 97 82 … … 99 84 100 85 } 86 //Trata a criacao de anexos do ics 87 public function createAttachment($attachments, &$vevent){ 88 foreach($attachments as $key => $attachment){ 89 $pParams = array("ENCODING" => "BASE64", "VALUE" => "BINARY", 90 "X-FILENAME" => $attachment['name']); 91 92 $vevent->setProperty( "attach", $attachment['source'], $pParams ); 93 } 94 } 95 96 //Trata a criacao de attendees com tratamento de delegate 97 public function createAttendee($attendees, &$vevent){ 98 $delegate = array(); 99 foreach ($attendees as $di => $dv){ 100 if($dv['delegatedFrom'] != 0){ 101 $delegate[$dv['delegatedFrom']] = $dv; 102 } 103 } 104 105 foreach ($attendees as $pi => $pv){ 106 $isResponseDelegated = false; 107 if($pv['delegatedFrom'] == 0){ 108 if($pv['isOrganizer'] == 1) 109 $vevent->setProperty( 'organizer' , $pv['user']['mail'], array( 'CN' => $pv['user']['name'] )); 110 else 111 { 112 $pParams = array(); 113 $pParams['CN'] = $pv['user']['name']; 114 $pParams['PARTSTAT'] = self::_getStatus( $pv['status'] ); 115 116 if(isset($delegate[$pv['id']])){ 117 $pParams['PARTSTAT'] = self::_getStatus( $delegate[$pv['id']]['status']); 118 $pParams['DELEGATED-TO'] = $delegate[$pv['id']]['user']['mail']; 119 $pParams['CN'] = $pv['user']['name']; 120 121 $vevent->setProperty( 'attendee' , $pv['user']['mail'], $pParams); 122 123 if($delegate[$pv['id']]['status'] == STATUS_UNANSWERED){ 124 $pParams['RSVP'] = $pv['receiveNotification'] == 1 ? 'TRUE' : 'FALSE'; 125 unset($pParams['PARTSTAT']); 126 }else 127 $pParams['PARTSTAT'] = self::_getStatus( $delegate[$pv['id']]['status']); 128 129 unset($pParams['DELEGATED-TO']); 130 $pParams['DELEGATED-FROM'] = $pv['user']['mail']; 131 132 $vevent->setProperty( 'attendee' , $delegate[$pv['id']]['user']['mail'], $pParams); 133 continue; 134 } 135 $pParams['RSVP'] = 'TRUE'; 136 137 $vevent->setProperty( 'attendee' , $pv['user']['mail'], $pParams); 138 } 139 } 140 } 141 } 101 142 102 143 public function parse ( $data , $params = false) 103 144 { 104 145 Config::regSet('noAlarm', TRUE); //Evita o envio de notificação … … 110 151 $method = $vcalendar->getProperty('method',FALSE , FALSE); 111 152 $params['prodid'] = $vcalendar->getProperty( 'prodid' , false , false ); 112 153 113 154 while ($component = $vcalendar->getComponent()) 114 155 { … … 183 224 184 225 case 'COUNTER': 226 if($params['acceptedSuggestion'] !== 'false' ){ 227 228 $schedulable = self::_getSchedulable($uid); 229 $params['calendar'] = self::_existInMyCalendars($schedulable['id']); 230 231 $interation = self::_makeCOUNTER($schedulable , $component , $params); 232 Config::regSet('noAlarm', FALSE); 233 }else{ 234 $response = array(); 235 $response['from'] = $params['from']; 236 $response['type'] = 'suggestionResponse'; 237 $response['status'] = 'DECLINECOUNTER'; 238 $response['schedulable'] = self::_getSchedulable($uid); 239 240 Controller::create( array( 'concept' => 'notification' ) , $response); 241 } 185 242 break; 186 243 187 case 'DECLINE -COUNTER':244 case 'DECLINECOUNTER': 188 245 break; 189 246 … … 194 251 $interation = self::_makeVEVENT($schedulable , $component , $params); 195 252 else // Importar evento 196 253 $interation = self::_makeVEVENT( array() , $component , $params); 197 254 198 255 break; … … 214 271 public function analize ( $data , $params = false) 215 272 { 216 273 $vcalendar = new icalCreator( ); 217 274 $vcalendar->parse(trim($data)); 218 275 $vcalendar->sort(); … … 223 280 while ($component = $vcalendar->getComponent()) 224 281 { 225 282 $interation = array(); 226 283 $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente 227 284 … … 269 326 270 327 case 'COUNTER': 328 $interation = ICAL_ACTION_SUGGESTION; 271 329 break; 272 330 273 case 'DECLINE-COUNTER': 274 break; 331 case 'DECLINECOUNTER': 332 $interation = ICAL_ACTION_NONE; 333 break; 275 334 276 335 default: … … 322 381 STATUS_CONFIRMED => 'CONFIRMED', 323 382 STATUS_CANCELLED => 'CANCELLED', 324 STATUS_TEN ATIVE => 'TENATIVE',383 STATUS_TENTATIVE => 'TENTATIVE', 325 384 STATUS_UNANSWERED => 'NEEDS-ACTION', 326 385 STATUS_DELEGATED => 'DELEGATED' … … 367 426 } 368 427 369 static private function _makeVEVENT( $schedulable , $component ,$params)370 { 371 428 static private function _makeCOUNTER( $schedulable , $component ,$params) 429 { 430 $interation = array(); 372 431 $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand().'(Formatter)'; 373 432 374 433 /* Data de Inicio*/ 375 434 $startTime = $component->getProperty( 'dtstart', false , true ); 376 377 435 378 436 /* Tiem zone do evento*/ 379 437 if(isset($startTime['params']['TZID'])) … … 389 447 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone']) . '000'; 390 448 } 391 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 */449 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 */ 392 450 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000'; 451 $schedulable['allDay'] = 0; 452 } 453 else 454 { 455 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 456 if( strpos($params['prodid'], 'Outlook') !== false ) 457 { 458 //Se o ics veio em utc não aplicar horario de verão 459 $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , new DateTimeZone('UTC') ); 460 $sTime->setTimezone($objTimezone); 461 if($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 462 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 463 } 464 } 465 466 467 /* Data de Termino*/ 468 $endTime = $component->getProperty( 'dtend', false , true ); 469 470 if($endTime['params']['VALUE'] === 'DATE') 471 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone']) . '000'; 472 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 */ 473 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000'; 393 474 else 475 { 476 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 477 if( strpos($params['prodid'], 'Outlook') !== false ) 478 { 479 //Se o ics veio em utc não aplicar horario de verão 480 $eTime = new DateTime( '@'.(int)($schedulable['endTime'] / 1000) ,new DateTimeZone('UTC')); 481 $eTime->setTimezone($objTimezone); 482 if($eTime->format('I')) 483 $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 484 485 } 486 } 487 unset($schedulable['participants']); 488 $interation['schedulable://'.$eventID] = $schedulable; 489 490 return $interation; 491 } 492 493 static private function _makeVEVENT( $schedulable , $component ,$params) 494 { 495 496 $interation = array(); 497 $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand().'(Formatter)'; 498 499 /* Data de Inicio*/ 500 $startTime = $component->getProperty( 'dtstart', false , true ); 501 502 /* Tiem zone do evento*/ 503 if(isset($startTime['params']['TZID'])) 504 $schedulable['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); 505 else 506 $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 507 508 $objTimezone = new DateTimeZone($schedulable['timezone']); 509 510 if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) 511 { 512 $schedulable['allDay'] = 1; 513 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone']) . '000'; 514 } 515 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 */ 516 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000'; 517 $schedulable['allDay'] = 0; 518 } 519 else 394 520 { 395 521 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; … … 519 645 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 520 646 $participant['isOrganizer'] = '1'; 647 $participant['acl'] = 'rowi'; 521 648 522 649 /* Verifica se este usuario é um usuario interno do ldap */ … … 558 685 $participant['status'] = STATUS_CONFIRMED; 559 686 $participant['isOrganizer'] = '1'; 687 $participant['acl'] = 'rowi'; 560 688 $participant['isExternal'] = 0; 561 689 $participant['user'] = $params['owner']; … … 583 711 if($uid = $component->getProperty( 'uid' , false , false )); 584 712 $schedulable['uid'] = $uid; 585 586 $interation['schedulable://'.$eventID] = $schedulable; 587 588 return $interation; 713 714 while($attach = $component->getProperty('ATTACH',FALSE , TRUE)){ 715 716 $attachCurrent = array( 'name' => $attach['params']['X-FILENAME'], 717 'size' => strlen($attach['value']), 718 'type' => self::_getContentType($attach['params']['X-FILENAME']) 719 ); 720 721 $ids = Controller::find( array( 'concept' => 'attachment' ) , array('id') ,array( 'filter' => array('AND' , array( '=' , 'name' , $attachCurrent['name'] ), array( '=' , 'size' , $attachCurrent['size'] ), array( '=' , 'type' , $attachCurrent['type'] )))); 722 723 if(!is_array($ids)){ 724 $attachCurrent['source'] = $attach['value']; 725 //insere o anexo no banco e pega id para colcar no relacionamento 726 $idAttachment = Controller::create( array('concept' => 'attachment') , $attachCurrent ); 727 }else 728 $idAttachment = array('id' => $ids[0]['id']); 729 730 $calendarToAttachmentId = mt_rand().'2(Formatter)'; 731 $calendarToAttachment['attachment'] = $idAttachment['id'] ; 732 $calendarToAttachment['schedulable'] = $eventID ; 733 $interation['schedulableToAttachment://'.$calendarToAttachmentId] = $calendarToAttachment; 734 735 $schedulable['attachments'][] = $calendarToAttachmentId; 736 737 } 738 739 $interation['schedulable://'.$eventID] = $schedulable; 740 741 return $interation; 589 742 } 590 743 … … 603 756 604 757 $return = Controller::find( array( 'concept' => 'calendarToSchedulable' ) , null , array ( 'filter' => array('AND' , array( 'IN' , 'calendar' , $calendars ),array( '=' , 'schedulable' , $id )))); 605 606 return (isset($return[0])) ? true: false;758 759 return (isset($return[0])) ? $return[0]['calendar'] : false; 607 760 } 608 761 … … 614 767 return false; 615 768 } 769 770 771 static private function _getContentType( $fileName ) 772 { 773 $strFileType = strtolower(substr ( $fileName , strrpos($fileName, '.') )); 774 775 switch( $strFileType ) 776 { 777 case ".asf": return "video/x-ms-asf"; 778 case ".avi": return "video/avi"; 779 case ".doc": return "application/msword"; 780 case ".zip": return "application/zip"; 781 case ".xls": return "application/vnd.ms-excel"; 782 case ".gif": return "image/gif"; 783 case ".bmp": return "image/bmp"; 784 case ".jpeg": 785 case ".jpg": return "image/jpeg"; 786 case ".wav": return "audio/wav"; 787 case ".mp3": return "audio/mpeg3"; 788 case ".mpeg": 789 case ".mpg": return "video/mpeg"; 790 case ".rtf": return "application/rtf"; 791 case ".html": 792 case ".htm": return "text/html"; 793 case ".xml": return "text/xml"; 794 case ".xsl": return "text/xsl"; 795 case ".css": return "text/css"; 796 case ".php": return "text/php"; 797 case ".asp": return "text/asp"; 798 case ".pdf": return "application/pdf"; 799 case ".png": return "image/png"; 800 case ".txt": return "text/plain"; 801 case ".log": return "text/plain"; 802 case ".wmv": return "video/x-ms-wmv"; 803 case ".sxc": return "application/vnd.sun.xml.calc"; 804 case ".odt": return "application/vnd.oasis.opendocument.text"; 805 case ".stc": return "application/vnd.sun.xml.calc.template"; 806 case ".sxd": return "application/vnd.sun.xml.draw"; 807 case ".std": return "application/vnd.sun.xml.draw.template"; 808 case ".sxi": return "application/vnd.sun.xml.impress"; 809 case ".sti": return "application/vnd.sun.xml.impress.template"; 810 case ".sxm": return "application/vnd.sun.xml.math"; 811 case ".sxw": return "application/vnd.sun.xml.writer"; 812 case ".sxq": return "application/vnd.sun.xml.writer.global"; 813 case ".stw": return "application/vnd.sun.xml.writer.template"; 814 case ".pps": return "application/vnd.ms-powerpoint"; 815 case ".odt": return "application/vnd.oasis.opendocument.text"; 816 case ".ott": return "application/vnd.oasis.opendocument.text-template"; 817 case ".oth": return "application/vnd.oasis.opendocument.text-web"; 818 case ".odm": return "application/vnd.oasis.opendocument.text-master"; 819 case ".odg": return "application/vnd.oasis.opendocument.graphics"; 820 case ".otg": return "application/vnd.oasis.opendocument.graphics-template"; 821 case ".odp": return "application/vnd.oasis.opendocument.presentation"; 822 case ".otp": return "application/vnd.oasis.opendocument.presentation-template"; 823 case ".ods": return "application/vnd.oasis.opendocument.spreadsheet"; 824 case ".ots": return "application/vnd.oasis.opendocument.spreadsheet-template"; 825 case ".odc": return "application/vnd.oasis.opendocument.chart"; 826 case ".odf": return "application/vnd.oasis.opendocument.formula"; 827 case ".odi": return "application/vnd.oasis.opendocument.image"; 828 case ".ndl": return "application/vnd.lotus-notes"; 829 case ".eml": return "text/plain"; 830 case ".ps" : return "application/postscript"; 831 default : return "application/octet-stream"; 832 } 833 } 616 834 } 617 835 ?>
Note: See TracChangeset
for help on using the changeset viewer.