Changeset 5415


Ignore:
Timestamp:
01/24/12 17:22:37 (12 years ago)
Author:
cristiano
Message:

Ticket #2434 - Correções no importar ical

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoCalendar/setup/tables_current.inc.php

    r5341 r5415  
    122122                'tzid' => array('type' => 'varchar', 'precision' => '50' ,'nullable' => True), 
    123123                'transp' => array( 'type' => 'int', 'precision' => '2', 'nullable' => FALSE , 'default' => 0 ), 
     124                'sequence' => array( 'type' => 'int', 'precision' => '8', 'nullable' => FALSE , 'default' => 0 ), 
    124125            ), 
    125126            'pk' => array('id'), 
  • trunk/expressoMail1_2/inc/class.db_functions.inc.php

    r5409 r5415  
    400400                                $_REQUEST['params']['calendar'] = $params['selected']; 
    401401                                $_REQUEST['readable'] = $params['readable'] ? true : false; 
     402                                $_REQUEST['analize'] = isset($params['readable']) ? true : false; 
    402403                                $_REQUEST['params']['status'] = $params['status']; 
    403404                                $_REQUEST['params']['owner'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id']; 
     
    409410                                        if(!$valid) 
    410411                                        { 
    411                                                 $return = false; 
    412                                                 $output = unserialize($output);                                                                          
    413                                                 foreach($output[0] as $key => &$value){ 
    414                                                  
    415                                                         if(isset($value['user'])){                                                       
    416                                                                 if($user == $value['user']) 
    417                                                                         return  $value['schedulable']; 
    418                                                         } 
    419                                                 } 
     412                                                $output = unserialize($output);  
     413                                                foreach($output as $key => $value) 
     414                                                    return $value; 
    420415                                        } 
    421416                                        return false; 
  • trunk/expressoMail1_2/js/main.js

    r5409 r5415  
    33823382                }); 
    33833383                $.ajax({ 
    3384                         url: "controller.php?action="+import_url+'&from_ajax=true&id_user='+User.me.id+'&readable=true&cirus_delimiter='+cyrus_delimiter, 
     3384                        url: "controller.php?action="+import_url+'&from_ajax=true&id_user='+User.me.id+'&readable=true&cirus_delimiter='+cyrus_delimiter+'&analize=true', 
    33853385                        async: false, 
    33863386                        success: function(data){ 
     
    33883388 
    33893389 
    3390                                 var createDialog = function(isCorrentEvent, propaget){ 
    3391  
    3392                                         if(!(!!isCorrentEvent)){ 
     3390                                var createDialog = function(typeImport, propaget){ 
     3391 
     3392                                        if(typeImport == '1'){ 
    33933393                                                $("#select-agenda").html(''); 
    33943394                                                for(var calendario in Calendar.calendarIds){ 
     
    34203420                                                 });                                     
    34213421 
    3422                                         }else{ 
     3422                                        }else if(data == '4'){ 
     3423                                            alert('Seu evento já se encontra atualizado'); 
     3424                                            return; 
     3425                                        }else if(data == '3'){ 
     3426                                           $.ajax({ 
     3427                                                        url: "controller.php?action="+import_url+'&from_ajax=true&selected=true', 
     3428                                                        success: function(msg){ 
     3429                                                        alert( ( ( connector.unserialize(msg)) == "ok") ? "Seu evento foi removido " : "Ocorreu um erro ao remover o evento" ); 
     3430                                                        } 
     3431                                                }); 
     3432                                                return; 
     3433                                        } 
     3434                                        else if(data == '5'){ 
     3435                                                $.ajax({ 
     3436                                                        url: "controller.php?action="+import_url+'&from_ajax=true&selected=true', 
     3437                                                        success: function(msg){ 
     3438                                                        alert( ( ( connector.unserialize(msg)) == "ok") ? "Atualizado com sucesso " : "Ocorreu um erro ao atualizar o evento" ); 
     3439                                                        } 
     3440                                                }); 
     3441                                                return; 
     3442                                        }else { 
    34233443                                                up = true; 
    34243444                                                $("#select-agenda").css("display", "none"); 
     
    34323452                                                            }, 
    34333453                                                           "Atualizar": function() { 
    3434                                                            if ($(".ui-dialog-buttonpane").find(".ui-button:last").children().html() == 'Atualizar'){ 
    3435                                                                 
    3436                                                                                                                             
    3437                                                                                                                             
    3438                                                                var isOk = propaget || DataLayer.put('participant', { id: ( DataLayer.get('participant', ['AND', ['=', 'user', User.me.id], ['=', 'schedulable', isCorrentEvent[0].schedulable]] ) )[0].id,  
    3439                                                                                                          status: $("#select-status option:selected").val() }); 
    3440  
    3441                                                                 DataLayer.commit(); 
    3442  
    3443                                                                 alert( !!isOk ? "Evento atualizado com sucesso ... " : "Ocorreu um erro ao atualizar o evento  ... "); 
    3444  
    3445                                                                $( this ).dialog( "close" ); 
    3446  
    3447                                                            } 
     3454                                                                 
     3455                                                                $.ajax({ 
     3456                                                                     url: "controller.php?action="+import_url+'&from_ajax=true&selected='+$("#select-agenda option:selected").val()+'&status='+$("#select-status option:selected").val(), 
     3457                                                                     success: function(msg){ 
     3458                                                                            alert( ( (msg = connector.unserialize(msg)) == "ok") ? "Atualizado com sucesso para " : "Ocorreu um erro ao atualizar o evento" ); 
     3459                                                                    } 
     3460                                                                }); 
     3461                                                         
     3462                                                                $( this ).dialog( "close" ); 
    34483463                                                        } 
    34493464                                                    } 
     
    34533468                                        $( "#import-dialog" ).dialog( "open" );  
    34543469                                }; 
    3455  
    3456  
    3457  
    3458                                 if(!!data){ 
    3459                                         var isCorrentEvent = false; 
    3460                                         var count = 0; 
    3461  
    3462                                         $.getJSON("../prototype/request.php", 
    3463                                         { 
    3464                                                 concept : "calendarToSchedulable", 
    3465                                                 filter : ['AND', ['IN', 'calendar', Calendar.calendarIds], ['=', 'schedulable', data]] 
    3466                                         }, createDialog); 
    3467                                 }else{ 
    3468                                         createDialog(true, true); 
    3469                                 } 
     3470                                createDialog(data, true); 
     3471                                 
    34703472                }}); 
    34713473                         
  • trunk/prototype/api/config.php

    r5399 r5415  
    2929        if( !isset( $_SESSION['wallet'][$service] ) || !isset( $_SESSION['wallet'][$service][$config] )) 
    3030            $_SESSION['wallet'][$service] = parse_ini_file( ROOTPATH."/config/$service.srv", true ); 
    31          
    32         return isset($_SESSION['wallet'][$service][$config]) ? $_SESSION['wallet'][$service][$config] : false; 
     31        
     32        return (isset($_SESSION['wallet'][$service][$config])) ? $_SESSION['wallet'][$service][$config] : false; 
    3333    } 
    3434     
  • trunk/prototype/api/controller.php

    r5399 r5415  
    597597 
    598598                        case 'format': $return = $params['service']->format( $params['properties'], $params['criteria'] ); break; 
     599                         
     600                        default:  $return = $params['service']->$method( $params['properties'], $params['criteria'] ); break; 
    599601            } 
    600602 
  • trunk/prototype/converter.php

    r5399 r5415  
    33require_once 'api/controller.php'; 
    44 
    5 $args = Controller::call( 'parse', 
     5$method =  $_REQUEST['analize'] ? 'analize' : 'parse'; 
     6 
     7$args = Controller::call( $method, 
    68 
    79                          array( 'service' => $_REQUEST['type'] ), 
  • trunk/prototype/modules/calendar/constants.php

    r5341 r5415  
    2323define('CLASS_CONFIDENTIAL', 3); 
    2424 
     25 
     26define('ICAL_ACTION_IMPORT', 1); 
     27define('ICAL_ACTION_UPDATE', 2); 
     28define('ICAL_ACTION_DELETE', 3); 
     29define('ICAL_ACTION_NONE', 4); 
     30define('ICAL_ACTION_REPLY', 5); 
     31 
    2532?> 
  • trunk/prototype/modules/calendar/interceptors/DBMapping.php

    r5399 r5415  
    2424                                         'lastUpdate' => 'last_update', 
    2525                                         'dtstamp' => 'dtstamp', 
     26                                         'sequence' => 'sequence', 
    2627                                         'timezone' => 'tzid'); 
    2728       
     
    287288 
    288289    public function encodeUpdateSchedulable( &$uri , &$params , &$criteria , $original ){        
    289         if(isset($params['rangeStart'])) 
     290        if(isset($params['startTime'])) 
    290291                $params['rangeStart'] = gmdate( 'd-m-Y' , (int)($params['startTime'] / 1000) ); 
    291         if(isset($params['rangeEnd'])) 
     292        if(isset($params['endTime'])) 
    292293                $params['rangeEnd'] = gmdate( 'd-m-Y' , (int)($params['endTime'] / 1000) );        
    293294         
     
    679680        $newCriteria = $original['criteria']; 
    680681        $valid = true; 
    681         self::validExternalUserCriteria($newCriteria, self::$calendar_ex_participantMap, $valid); 
     682        self::validExternalUserCriteria($newCriteria['filter'], self::$calendar_ex_participantMap, $valid); 
    682683        if($valid == true) 
    683684        { 
     
    979980        if (!is_array($filter) || count($filter) <= 0) 
    980981            return null; 
    981  
     982         
    982983        $op = array_shift($filter); 
    983984 
     
    985986            foreach ($filter as $i => $f) 
    986987                $filter[$i] = self::validExternalUserCriteria($f, $map ,$findCalendar ); 
    987         } 
    988         else 
    989         { 
     988        } 
     989        else 
     990        {            
    990991           if( isset($filter[0]) && !in_array($filter[0] , self::$calendar_ex_participantMap)) 
    991992             $ref = false; 
     
    994995                $filter[0] = isset($map[$filter[0]]) ? $map[$filter[0]] : $filter[0]; 
    995996        } 
    996  
    997         array_unshift($filter, $op); 
    998  
     997         
    999998        return( $filter ); 
    1000999    } 
  • trunk/prototype/modules/calendar/js/calendar.codecs.js

    r5409 r5415  
    415415                                         
    416416                                        if( attend.user.id ===  me.id ){ 
    417                                             participantInfo = { 
     417                                            participantInfo.user = { 
    418418                                                        status : attend.status, 
    419419                                                        alarms : $.map(attend.alarms || [], function( alarm ){ 
     
    422422                                                }; 
    423423                                                me.id = attend.id; 
     424                                                return(null); 
    424425                                        }; 
    425426                                         
     
    433434                                        if( !!parseInt(attend.isOrganizer )){ 
    434435                                                isOrganizer = ((attend.user.id == User.me.id) || (!!!attend.user)) ? 1 : 0; 
    435                                             participantInfo.organizer = person; 
     436                                            participantInfo.organizer = DataLayer.copy(person); 
    436437                                                return(null); 
    437438                                        };                                       
     
    440441                                }), 
    441442                            organizer: participantInfo.organizer || me, 
    442                             alarms: participantInfo.alarms || [], 
    443                             status: participantInfo.status || 1, 
     443                            alarms: !!participantInfo.user ?  participantInfo.user.alarms : [], 
     444                            status: !!participantInfo.user ? participantInfo.user.status : 1, 
    444445                            me: me, 
    445446                                isOrganizer: isOrganizer, 
  • trunk/prototype/services/iCal.php

    r5399 r5415  
    105105        $vcalendar = new icalCreator( );  
    106106        $vcalendar->parse(trim($data));  
    107         $vcalendar->sort(); 
    108         
     107        $vcalendar->sort();          
     108         
    109109        $return = array(); 
    110          
    111110        $method = $vcalendar->getProperty('method',FALSE , FALSE); 
    112                 
     111        $params['prodid'] =  $vcalendar->getProperty( 'prodid' , false , false ); 
     112         
    113113        while ($component = $vcalendar->getComponent()) 
    114         { 
    115              
     114        {      
    116115            $interation = array(); 
     116            $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente 
    117117             
    118118            switch (strtoupper($component->objName)) { 
    119119                case 'VEVENT': 
    120                     $vevent = array();                     
    121                     $vevent['uid'] = $component->getProperty( 'uid' , false , false ); 
    122                     $vevent['type'] = EVENT_ID; 
    123120                     
    124                     $exists =  Controller::find(array('concept' => 'schedulable') , null , array ( 'deepness' => '*' , 'filter' =>  array('=' , 'uid' , $vevent['uid'] ))); 
    125                     $exists = ( is_array($exists) && count($exists) > 0 ) ? $exists[0] : false; 
    126  
    127121                    switch ($method)  
    128122                    { 
    129                          case 'REPLY': 
    130                               
    131                                if($exists !== false) 
    132                                { 
    133                                    while($property = $component->getProperty('attendee',FALSE , TRUE))                                  
    134                                        if( $pID  = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $exists['participants'])) 
    135                                             $interation['participant://'.$pID] = array( 'id' => $pID , 'status' => constant('STATUS_'.strtoupper($property['params']['PARTSTAT'])) ); 
    136                                } 
     123                         case 'PUBLISH':             
     124                             if( !$schedulable = self::_getSchedulable($uid)) 
     125                                  $interation['schedulable://'.mt_rand().'(Formatter)'] = self::_makeCreateVEVENT($component); 
    137126                               break; 
    138127 
    139                          case 'CANCEL': 
    140                                if($exists !== false) 
    141                                     $interation['schedulable://'.$exists['id']] = false; 
    142                                break; 
    143  
    144                          default:                              
    145                                $veventID = mt_rand().'1(Formatter)'; 
    146                                 
    147                                if($exists !== false) 
    148                                { 
    149                                   Config::regSet('noAlarm', False); //Reativa o envio de notificação 
    150                                   $existsCalendarToSchedulable = Controller::find( array( 'concept' => 'calendarToSchedulable' ) , array('id') ,array( 'filter' => array('AND' , array('=' , 'calendar' ,  $params['calendar'] ), array('=' , 'schedulable' ,  $exists['id'] ) )) );  
    151                                              
    152                                      
    153                                   if( !is_array($existsCalendarToSchedulable) || count($existsCalendarToSchedulable) < 1 ) 
    154                                   {   
     128                         case 'REQUEST': 
     129                             $schedulable = self::_getSchedulable($uid); 
     130                               
     131                             if($schedulable) //Caso o evento exista 
     132                             { 
     133                                if(!self::_existInMyCalendars($schedulable['id'])) 
     134                                { 
    155135                                      $calendarToSchedulable = array(); 
    156136                                      $calendarToSchedulable['calendar'] = $params['calendar']; 
    157                                       $calendarToSchedulable['schedulable'] = $exists['id']; 
     137                                      $calendarToSchedulable['schedulable'] = $schedulable['id']; 
    158138                                      $interation['calendarToSchedulable://'.mt_rand().'(Formatter)'] = $calendarToSchedulable; 
    159                                       continue; 
    160                                   } 
    161 // Codigo para atualizar status do importador. não nescessario pois sera enviado um email de configmação para o organizador. 
    162 //                         foreach ($exists['participants'] as  $participant) 
    163 //                           if($participant['user']['id'] == Config::me('uidNumber')) 
    164 //                               $interation['participant://'.$participant['id']] = array( 'id' => $participant['id'], 'status' => STATUS_CONFIRMED); 
    165                                      
    166                                  $veventID = $exists['id']; 
    167                                  $vevent = $exists; 
    168                                } 
    169                            
    170                                 /* Data de Inicio*/ 
    171                                     $startTime = $component->getProperty( 'dtstart', false , true ); 
    172  
    173                                 /* Tiem zone do evento*/     
    174                                    if(isset($startTime['params']['TZID'])) 
    175                                       $vevent['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']);  
    176                                    else 
    177                                       $vevent['timezone'] = $params['calendar_timezone'] ? $params['calendar_timezone'] : 'America/Sao_Paulo';  
    178  
    179                                     if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) 
     139                                       
     140                                      if(isset($params['status'])) 
     141                                      { 
     142                                        $pID = self::_getParticipantByMail( Config::me('mail') , $schedulable['participants'] ); 
     143                                        $interation['participant://'.$pID]['status'] = $params['status']; 
     144                                      } 
     145                                } 
     146                                else 
     147                                { 
     148                                    if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     149                                       $interation = self::_makeVEVENT($schedulable , $component , $params); 
     150                                    else if ( $component->getProperty( 'sequence' , false , false ) === $schedulable['sequence'])  
    180151                                    { 
    181                                         $vevent['allDay'] = 1; 
    182                                         $vevent['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$params['calendar_timezone']) . '000'; 
    183                                     } 
    184                                     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 */ 
    185                                         $vevent['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000';       
    186                                     else 
    187                                         $vevent['startTime'] = self::date2timestamp($startTime['value']) . '000';                          
    188  
    189                                  /* Data de Termino*/ 
    190                                     $endTime = $component->getProperty( 'dtend', false , true );  
    191  
    192                                     if($endTime['params']['VALUE'] === 'DATE') 
    193                                         $vevent['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$params['calendar_timezone']) . '000'; 
    194                                     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 */ 
    195                                         $vevent['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000'; 
    196                                     else 
    197                                         $vevent['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
    198  
    199                                 $vevent['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'UTF-8' , 'UTF-8,ISO-8859-1'); 
    200  
    201                                 /* Definindo Description */ 
    202                                     if($desc = $component->getProperty( 'description' , false , false )) 
    203                                         $vevent['description'] = mb_convert_encoding (str_ireplace ('\n', "\n", $desc) ,'UTF-8' , 'UTF-8,ISO-8859-1'); 
    204  
    205                                  /* Definindo location */ 
    206                                     if($location = $component->getProperty( 'location' , false , false )) 
    207                                         $vevent['location'] = mb_convert_encoding ( $location , 'UTF-8' , 'UTF-8,ISO-8859-1') ; 
    208  
    209  
    210                                 /* Definindo Class */ 
    211                                     $class = $component->getProperty( 'class' , false , false ); 
    212                                     if( $class && defined(constant(strtoupper('CLASS_'.$class))) ) 
    213                                         $vevent['class'] = constant(strtoupper('CLASS_'.$class)); 
    214                                     else if( !isset($exists['class']) ) 
    215                                         $vevent['class'] = CLASS_PRIVATE ; // padrão classe private 
    216  
    217                                 /* Definindo RRULE */ 
    218                                     if(  $rrule = $component->getProperty( 'rrule' , false , false )) 
    219                                     {    
    220                                         /* Gera um randon id para o contexto formater */ 
    221                                             $repeatID = mt_rand().'3(Formatter)'; 
    222  
    223                                         $repeat = array(); 
    224                                         $repeat['schedulable'] = $veventID; 
    225                                         foreach($rrule as $i => $v) 
    226                                            $repeat[strtolower($i)] = $v; 
    227  
    228                                         $interation['repeat://'.$repeatID] = $repeat; 
    229                                     } 
    230  
    231  
    232                                 $vevent['calendar'] = $params['calendar'];            
    233  
    234                                 $participantsInEvent = array(); 
    235  
    236                                 //TODO: Participants com delegated não estao sendo levados em conta 
    237                                 while($property = $component->getProperty('attendee',FALSE , TRUE)) 
    238                                 { 
    239                                     $participant = array(); 
    240  
    241                                     $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
    242  
    243                                     $participantID = mt_rand().'2(Formatter)'; 
    244                                     $participant['schedulable'] = $veventID;                                       
    245                                     $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 
    246                                     $participant['isOrganizer'] = '0'; 
    247  
    248                                     /* Verifica se este usuario é um usuario interno do ldap */      
    249                                     $intUser = Controller::find( array( 'concept' => 'user', 'service' => 'OpenLDAP' ) , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' ,  $mailUser ), array('=' , 'mailAlternateAddress' ,  $mailUser ) )) );  
    250  
    251                                     if( !is_array($intUser) || count($intUser) < 1 ) 
    252                                          $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' ,  $mailUser )) );  
    253  
    254  
    255                                     $user = null;     
    256                                     if( $intUser && count($intUser) > 0 ) 
    257                                     { 
    258                                         $participant['isExternal']  = 0; 
    259                                         $participant['user'] = $intUser[0]['id']; 
    260                                     } 
    261                                     else 
    262                                     { 
    263                                         $participant['isExternal']  = 1; 
    264                                          /* Gera um randon id para o contexto formater */ 
    265                                             $userID = mt_rand().'4(Formatter)'; 
    266  
    267                                         $user['mail'] = $mailUser; 
    268                                         $user['isExternal'] = '1'; 
    269                                         $user['name'] =  ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 
    270                                         $user['participants'] = array($participantID); 
    271                                         $participant['user'] = $userID; 
    272                                         $interation['user://'.$userID] = $user; 
    273                                     } 
    274  
    275                                     $interation['participant://'.$participantID] = $participant; 
    276                                     $vevent['participants'][] = $participantID; 
    277  
    278                                 }; 
    279  
    280                                 if($property = $component->getProperty('organizer',FALSE , TRUE)) 
    281                                 { 
    282                                     $participant = array(); 
    283                                     $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
    284  
    285                                     $participantID = mt_rand().'2(Formatter)'; 
    286  
    287                                     $participant['schedulable'] = $veventID; 
    288                                     $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 
    289                                     $participant['isOrganizer'] = '1'; 
    290  
    291                                     /* Verifica se este usuario é um usuario interno do ldap */      
    292                                     $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'OpenLDAP') , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' ,  $mailUser ), array('=' , 'mailAlternateAddress' ,  $mailUser ) )) );  
    293  
    294                                     if( !is_array($intUser) || count($intUser) < 1 ) 
    295                                          $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' ,  $mailUser )) );  
    296  
    297  
    298  
    299                                     $user = null;     
    300                                     if( $intUser && count($intUser) > 0 ) 
    301                                     { 
    302                                         $participant['isExternal']  = 0; 
    303                                         $participant['user'] = $intUser[0]['id']; 
    304                                     } 
    305                                     else 
    306                                     { 
    307                                         $participant['isExternal']  = 1; 
    308                                          /* Gera um randon id para o contexto formater */ 
    309                                             $userID = mt_rand().'4(Formatter)'; 
    310  
    311                                         $user['mail'] = $mailUser; 
    312                                         $user['name'] =  ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 
    313                                         $user['participants'] = array($participantID); 
    314                                         $user['isExternal'] = '1'; 
    315                                         $participant['user'] = $userID; 
    316                                         $interation['user://'.$userID] = $user; 
    317                                     } 
    318  
    319                                     $interation['participant://'.$participantID] = $participant; 
    320                                     $vevent['participants'][] = $participantID; 
    321  
     152                                        //Ler melhor rfc sobre isto 3.2.2.2 
     153                                        //Aparentemente é para retornar um ical com o evento atualizado para o attende 
     154                                    }  
    322155                                } 
    323                                 else //caso não tenha organizador o usuario se torna organizador 
    324                                 { 
    325                                    $user = Controller::read( array( 'concept' => 'user', 'id' => $params['owner'] ) , array('mail'));  
    326  
    327                                    if(!self::_getParticipantByMail($user['mail'] , $exists['participants'])) 
    328                                    { 
    329                                         $participantID = mt_rand().'2(Formatter)'; 
    330  
    331                                         $participant['schedulable'] = $veventID; 
    332                                         $participant['status'] = STATUS_CONFIRMED; 
    333                                         $participant['isOrganizer'] = '1'; 
    334                                         $participant['isExternal']  = 0; 
    335                                         $participant['user'] =  $params['owner']; 
    336                                         $interation['participant://'.$participantID] = $participant; 
    337                                         $vevent['participants'][] = $participantID; 
    338                                    } 
    339                                 } 
    340  
    341                                  /* Definindo DTSTAMP */ 
    342                                 if($dtstamp = $component->getProperty( 'dtstamp', false , true )) 
    343                                 { 
    344                                     if(isset($dtstamp['params']['TZID']) && !isset($dtstamp['value']['tz'])) 
    345                                         $vevent['dtstamp'] = self::date2timestamp($dtstamp['value']) - self::_getTzOffset('UTC',$dtstamp['params']['TZID']) . '000'; 
    346                                     else 
    347                                         $vevent['dtstamp'] = self::date2timestamp($dtstamp['value']) . '000'; 
    348                                 } 
    349  
    350                                 /* Definindo TRANSP */ 
    351                                 if(($tranp = $component->getProperty( 'transp', false , true )) && strtoupper($tranp) == 'OPAQUE') 
    352                                     $vevent['transparent'] = 1; 
    353  
    354                                  /* Definindo last_update */ 
    355                                 if($lastUpdate = $component->getProperty( 'LAST-MODIFIED', false , true )) 
    356                                 { 
    357                                     if(isset($lastUpdate['params']['TZID']) && !isset($lastUpdate['value']['tz'])) 
    358                                         $vevent['lasUpdate'] = self::date2timestamp($lastUpdate['value']) - self::_getTzOffset('UTC',$lastUpdate['params']['TZID']) . '000'; 
    359                                     else 
    360                                         $vevent['lastUpdate'] = self::date2timestamp($lastUpdate['value']) . '000'; 
    361                                 } 
    362  
    363                                 $interation['schedulable://'.$veventID] = $vevent; 
    364  
     156     
     157                             }else // Importar evento 
     158                                $interation = self::_makeVEVENT( array() , $component , $params); 
     159                              
     160                             break;   
     161                            
     162                         case 'REFRESH': 
     163                               break;   
     164                          
     165                         case 'CANCEL': 
     166                             if($schedulable = self::_getSchedulable($uid))                               
     167                                $interation['schedulable://'.$schedulable['id']] = false; 
    365168                               break; 
     169                            
     170                         case 'ADD': 
     171                               break; 
     172                          
     173                         case 'REPLY': 
     174                             if(  $schedulable = self::_getSchedulable($uid) ) 
     175                             { 
     176                                   while($property = $component->getProperty('attendee',FALSE , TRUE))                                  
     177                                       if( $pID  = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) 
     178                                            $interation['participant://'.$pID] = array( 'id' => $pID , 'status' => constant('STATUS_'.strtoupper($property['params']['PARTSTAT'])) );                             
     179                             } 
     180                               break; 
     181                          
     182                         case 'COUNTER': 
     183                               break; 
     184                          
     185                         case 'DECLINE-COUNTER': 
     186                               break; 
     187                            
     188                         default: 
     189                             $schedulable = self::_getSchedulable($uid); 
    366190                              
     191                             if($schedulable && ( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence'])) //Caso o evento exista 
     192                                $interation = self::_makeVEVENT($schedulable , $component , $params); 
     193                             else // Importar evento 
     194                                 $interation = self::_makeVEVENT( array() , $component , $params); 
     195 
     196                             break; 
    367197                    } 
    368198                     
     
    376206         
    377207        } 
    378          
     208                 
    379209         return $return;    
    380210    } 
     211     
     212        public function analize ( $data , $params = false) 
     213        { 
     214            $vcalendar = new icalCreator( );  
     215            $vcalendar->parse(trim($data));  
     216            $vcalendar->sort();          
     217 
     218            $return = array(); 
     219            $method = $vcalendar->getProperty('method',FALSE , FALSE); 
     220 
     221            while ($component = $vcalendar->getComponent()) 
     222            {      
     223                $interation = array(); 
     224                $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente 
     225 
     226                switch (strtoupper($component->objName)) { 
     227                    case 'VEVENT': 
     228 
     229                        switch ($method)  
     230                        { 
     231                             case 'PUBLISH':             
     232                                   $interation = ICAL_ACTION_IMPORT; 
     233                                   break; 
     234 
     235                             case 'REQUEST': 
     236                                 $schedulable = self::_getSchedulable($uid); 
     237 
     238                                 if($schedulable ) //Caso o evento exista 
     239                                 { 
     240                                    if(!self::_existInMyCalendars($schedulable['id'])) 
     241                                          $interation = ICAL_ACTION_IMPORT;    
     242                                    else 
     243                                    { 
     244                                        if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     245                                           $interation = ICAL_ACTION_UPDATE;    
     246                                        else 
     247                                           $interation = ICAL_ACTION_NONE;     
     248                                    } 
     249                                 }else 
     250                                   $interation =  ICAL_ACTION_IMPORT; 
     251 
     252                                 break;   
     253 
     254                             case 'REFRESH': 
     255                                   break;   
     256 
     257                             case 'CANCEL': 
     258                                    $interation = ICAL_ACTION_DELETE; 
     259                                   break; 
     260 
     261                             case 'ADD': 
     262                                   break; 
     263 
     264                             case 'REPLY': 
     265                                     $interation = ICAL_ACTION_REPLY; 
     266                                   break; 
     267 
     268                             case 'COUNTER': 
     269                                   break; 
     270 
     271                             case 'DECLINE-COUNTER': 
     272                                   break; 
     273 
     274                             default: 
     275                                 $schedulable = self::_getSchedulable($uid); 
     276 
     277                                 if($schedulable && ( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence'])) //Caso o evento exista 
     278                                      $interation = ICAL_ACTION_UPDATE; 
     279                                 else if($schedulable)  
     280                                     $interation = ICAL_ACTION_NONE; 
     281                                 else // Importar evento 
     282                                      $interation = ICAL_ACTION_IMPORT; 
     283 
     284                                 break; 
     285                        } 
     286 
     287                        $return[$uid] = $interation; 
     288                        break; 
     289                   case 'VTIMEZONE': 
     290 
     291 
     292                        break; 
     293                } 
     294 
     295            } 
     296 
     297             return $return;    
     298        } 
     299     
    381300     
    382301    /* Helpers */ 
     
    410329         
    411330        private static function _getParticipantByMail( $mail , &$participants ) 
    412         { 
    413                      
     331        {           
    414332            foreach ($participants as $i => $v) 
    415333                if($v['user']['mail'] == $mail  || (isset($v['user']['mailAlternateAddress']) && in_array($mail, $v['user']['mailAlternateAddress']))) 
     
    447365        } 
    448366 
     367        static private function _makeVEVENT( $schedulable , $component ,$params) 
     368        { 
     369            $interation = array();                   
     370            $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand().'(Formatter)'; 
     371             
     372            /* Data de Inicio*/ 
     373                $startTime = $component->getProperty( 'dtstart', false , true ); 
     374          
     375                    
     376            /* Tiem zone do evento*/     
     377               if(isset($startTime['params']['TZID'])) 
     378                  $schedulable['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']);  
     379               else 
     380                  $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo';  
     381                
     382                $objTimezone =  new DateTimeZone($schedulable['timezone']);   
     383                 
     384                if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) 
     385                { 
     386                    $schedulable['allDay'] = 1; 
     387                    $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone']) . '000'; 
     388                } 
     389                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 */ 
     390                    $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000';       
     391                else 
     392                { 
     393                    $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
     394                     if( strpos($params['prodid'], 'Outlook') !== false ) 
     395                    { 
     396                        //Se o ics veio em utc não aplicar horario de verão 
     397                        $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , new DateTimeZone('UTC') );  
     398                        $sTime->setTimezone($objTimezone); 
     399                        if($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     400                         $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 
     401                    } 
     402                } 
     403                 
     404 
     405             /* Data de Termino*/ 
     406                $endTime = $component->getProperty( 'dtend', false , true );  
     407 
     408                if($endTime['params']['VALUE'] === 'DATE') 
     409                    $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone']) . '000'; 
     410                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 */ 
     411                    $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000'; 
     412                else 
     413                { 
     414                    $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
     415                    if( strpos($params['prodid'], 'Outlook') !== false ) 
     416                    { 
     417                    //Se o ics veio em utc não aplicar horario de verão 
     418                        $eTime = new DateTime( '@'.(int)($schedulable['endTime'] / 1000)  ,new DateTimeZone('UTC'));  
     419                        $eTime->setTimezone($objTimezone); 
     420                        if($eTime->format('I'))  
     421                            $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 
     422                    } 
     423                } 
     424         
     425 
     426            $schedulable['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'UTF-8' , 'UTF-8,ISO-8859-1'); 
     427 
     428            /* Definindo Description */ 
     429                if($desc = $component->getProperty( 'description' , false , false )) 
     430                    $schedulable['description'] = mb_convert_encoding (str_ireplace ('\n', "\n", $desc) ,'UTF-8' , 'UTF-8,ISO-8859-1'); 
     431 
     432             /* Definindo location */ 
     433                if($location = $component->getProperty( 'location' , false , false )) 
     434                    $schedulable['location'] = mb_convert_encoding ( $location , 'UTF-8' , 'UTF-8,ISO-8859-1') ; 
     435 
     436 
     437            /* Definindo Class */ 
     438                $class = $component->getProperty( 'class' , false , false ); 
     439                if( $class && defined(constant(strtoupper('CLASS_'.$class))) ) 
     440                    $schedulable['class'] = constant(strtoupper('CLASS_'.$class)); 
     441                else if( !isset($exists['class']) ) 
     442                    $schedulable['class'] = CLASS_PRIVATE ; // padrão classe private 
     443 
     444            /* Definindo RRULE */ 
     445                if(  $rrule = $component->getProperty( 'rrule' , false , false )) 
     446                {    
     447                    /* Gera um randon id para o contexto formater */ 
     448                        $repeatID = mt_rand().'3(Formatter)'; 
     449 
     450                    $repeat = array(); 
     451                    $repeat['schedulable'] = $eventID; 
     452                    foreach($rrule as $i => $v) 
     453                       $repeat[strtolower($i)] = $v; 
     454 
     455                    //$interation['repeat://'.$repeatID] = $repeat; 
     456                } 
     457 
     458 
     459            $schedulable['calendar'] = $params['calendar'];            
     460 
     461            $participantsInEvent = array(); 
     462 
     463            //TODO: Participants com delegated não estao sendo levados em conta 
     464            while($property = $component->getProperty('attendee',FALSE , TRUE)) 
     465            { 
     466                $participant = array(); 
     467 
     468                $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
     469 
     470                $participantID = mt_rand().'2(Formatter)'; 
     471                $participant['schedulable'] = $eventID;                                       
     472                 
     473                if(isset($params['status']) && $mailUser == Config::me('mail')) 
     474                    $participant['status'] = $params['status']; 
     475                else 
     476                    $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 
     477                  
     478                 
     479                $participant['isOrganizer'] = '0'; 
     480 
     481                /* Verifica se este usuario é um usuario interno do ldap */      
     482                $intUser = Controller::find( array( 'concept' => 'user', 'service' => 'OpenLDAP' ) , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' ,  $mailUser ), array('=' , 'mailAlternateAddress' ,  $mailUser ) )) );  
     483 
     484                if( !is_array($intUser) || count($intUser) < 1 ) 
     485                     $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' ,  $mailUser )) );  
     486 
     487 
     488                $user = null;     
     489                if( $intUser && count($intUser) > 0 ) 
     490                { 
     491                    $participant['isExternal']  = 0; 
     492                    $participant['user'] = $intUser[0]['id']; 
     493                } 
     494                else 
     495                { 
     496                    $participant['isExternal']  = 1; 
     497                     /* Gera um randon id para o contexto formater */ 
     498                        $userID = mt_rand().'4(Formatter)'; 
     499 
     500                    $user['mail'] = $mailUser; 
     501                    $user['isExternal'] = '1'; 
     502                    $user['name'] =  ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 
     503                    $user['participants'] = array($participantID); 
     504                    $participant['user'] = $userID; 
     505                    $interation['user://'.$userID] = $user; 
     506                } 
     507 
     508                $interation['participant://'.$participantID] = $participant; 
     509                $schedulable['participants'][] = $participantID; 
     510 
     511            }; 
     512 
     513            if($property = $component->getProperty('organizer',FALSE , TRUE)) 
     514            { 
     515                $participant = array(); 
     516                $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
     517 
     518                $participantID = mt_rand().'2(Formatter)'; 
     519 
     520                $participant['schedulable'] = $eventID; 
     521                $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 
     522                $participant['isOrganizer'] = '1'; 
     523 
     524                /* Verifica se este usuario é um usuario interno do ldap */      
     525                $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'OpenLDAP') , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' ,  $mailUser ), array('=' , 'mailAlternateAddress' ,  $mailUser ) )) );  
     526 
     527                if( !is_array($intUser) || count($intUser) < 1 ) 
     528                     $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' ,  $mailUser )) );  
     529 
     530                $user = null;     
     531                if( $intUser && count($intUser) > 0 ) 
     532                { 
     533                    $participant['isExternal']  = 0; 
     534                    $participant['user'] = $intUser[0]['id']; 
     535                } 
     536                else 
     537                { 
     538                    $participant['isExternal']  = 1; 
     539                     /* Gera um randon id para o contexto formater */ 
     540                        $userID = mt_rand().'4(Formatter)'; 
     541 
     542                    $user['mail'] = $mailUser; 
     543                    $user['name'] =  ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 
     544                    $user['participants'] = array($participantID); 
     545                    $user['isExternal'] = '1'; 
     546                    $participant['user'] = $userID; 
     547                    $interation['user://'.$userID] = $user; 
     548                } 
     549 
     550                $interation['participant://'.$participantID] = $participant; 
     551                $schedulable['participants'][] = $participantID; 
     552 
     553            } 
     554            else if(!is_array($schedulable['participants']) || count($schedulable['participants']) < 1)//caso não tenha organizador o usuario se torna organizador 
     555            { 
     556               $user = Controller::read( array( 'concept' => 'user', 'id' => $params['owner'] ) , array('mail'));  
     557 
     558               if(!self::_getParticipantByMail($user['mail'] , $exists['participants'])) 
     559               { 
     560                    $participantID = mt_rand().'2(Formatter)'; 
     561 
     562                    $participant['schedulable'] = $eventID; 
     563                    $participant['status'] = STATUS_CONFIRMED; 
     564                    $participant['isOrganizer'] = '1'; 
     565                    $participant['isExternal']  = 0; 
     566                    $participant['user'] =  $params['owner']; 
     567                    $interation['participant://'.$participantID] = $participant; 
     568                    $schedulable['participants'][] = $participantID; 
     569               } 
     570            } 
     571 
     572             /* Definindo DTSTAMP */ 
     573            if($dtstamp = self::_getTime($component , 'dtstamp') ) 
     574                $schedulable['dtstamp'] = $dtstamp; 
     575       
     576            /* Definindo TRANSP */ 
     577            if(($tranp = $component->getProperty( 'transp', false , true )) && strtoupper($tranp) == 'OPAQUE') 
     578                $schedulable['transparent'] = 1; 
     579 
     580             /* Definindo last_update */ 
     581            if($lastUpdate =  self::_getTime($component , 'LAST-MODIFIED')) 
     582                  $schedulable['lastUpdate'] = $lastUpdate; 
     583             
     584             
     585            if($sequence = $component->getProperty( 'SEQUENCE', false , false )) 
     586                  $schedulable['sequence'] = $sequence; 
     587               
     588            if($uid = $component->getProperty( 'uid' , false , false )); 
     589                  $schedulable['uid'] = $uid; 
     590                 
     591             $interation['schedulable://'.$eventID] = $schedulable; 
     592                          
     593             return $interation; 
     594        } 
     595         
     596        static private function _getSchedulable( $uid ) 
     597        { 
     598           $schedulable =  Controller::find( array( 'concept' => 'schedulable' ) , null , array ( 'deepness' => '2' , 'filter' => array( '=' , 'uid' , $uid ))); 
     599           return (isset($schedulable[0])) ? $schedulable[0] : false; 
     600        } 
     601         
     602        static private function _existInMyCalendars( $id ) 
     603        { 
     604           $sig = Controller::find(array('concept' => 'calendarSignature'), array('user','calendar'), array('filter' => array( '=' , 'user' , Config::me('uidNumber'))));        
     605           $calendars = array(); 
     606           foreach ($sig as $val) 
     607               $calendars[] = $val['calendar']; 
     608            
     609           $return =  Controller::find( array( 'concept' => 'calendarToSchedulable' ) , null , array ( 'filter' => array('AND' , array( 'IN' , 'calendar' , $calendars ),array( '=' , 'schedulable' , $id )))); 
     610            
     611           return (isset($return[0])) ? true : false; 
     612        } 
     613         
     614        static private function _getTime(&$component , $property) 
     615        { 
     616           if($date = $component->getProperty($property , false , true )) 
     617                return (isset($date['params']['TZID']) && !isset($date['value']['tz'])) ? (self::date2timestamp($date['value']) - self::_getTzOffset('UTC',$date['params']['TZID'])) . '000' : self::date2timestamp($date['value']) . '000'; 
     618            
     619           return false; 
     620        } 
    449621} 
    450622?> 
Note: See TracChangeset for help on using the changeset viewer.