Ignore:
Timestamp:
02/14/12 16:52:04 (12 years ago)
Author:
acoutinho
Message:

Ticket #2434 - Implementacao anexos, acls e delegacao de participantes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/calendar/interceptors/Notifications.php

    r5437 r5514  
    88{ 
    99     
    10     /** 
     10        public function formatNotification(&$uri , &$params , &$data , $original){       
     11                switch ($params['type']) { 
     12                        case 'suggestion': 
     13                                self::formatSuggestion($params);     
     14                                break; 
     15                        case 'suggestionResponse': 
     16                                self::formatSuggestionResponse($params);     
     17                                break; 
     18                        }  
     19        } 
     20         
     21         
     22        /** 
    1123    * Analisa o commit do conceito participant e encaminha cada participant para seu devido metodo de notrificação 
    1224    * 
     
    1931    */ 
    2032    public function commitParticipant(&$uri , &$result , &$data , $original) 
    21     {     
     33    {                            
    2234        if(Config::regGet('noAlarm') !== false) return; //Escapa notificações caso a flag de noAlarm esteja ativa. 
    23                
     35                 
    2436        $organizers = array(); //Cache Organizadores 
    2537        $schedulables = array(); //Cache Schedulables 
    26          
     38 
    2739        foreach ($data as $i => $concept)  
    2840        { 
     
    3951                foreach ($schedulables[ $concept['id'] ]['participants'] as $i => $v) //salva em $organizers as informações do organizador       
    4052                    if(($v['isOrganizer'] === '1') && ($organizers[$concept['id']] = $v) ) break; 
    41             } 
     53                        }else if($concept['concept'] === 'schedulableToAttachment') 
     54                        { 
     55                                $relationAttachment = Controller::find( array( 'concept' => 'schedulableToAttachment' ) , false ,array( 'filter' => array('=', 'id' , $concept['id'])));                         
     56                                                         
     57                                 
     58                                         
     59                                foreach($relationAttachment as $key => $value){ 
     60                                        if(!array_key_exists('attachments',$schedulables[$value['schedulable']])) 
     61                                                $schedulables[$value['schedulable']]['attachments'] = array(); 
     62 
     63                                        $temp = Controller::find( array( 'concept' => 'attachment' ) , false ,array( 'filter' => array('=', 'id' , $value['attachment']))); 
     64                                        array_push($schedulables[$value['schedulable']]['attachments'] , $temp[0]);                              
     65                                } 
     66                        } 
    4267        } 
    4368         
    4469        if( isset( $created ) ) 
    4570        { 
    46            $psCreated =  Controller::find(array('concept' => 'participant'), false , array('deepness' => '1' , 'filter' => array('IN', 'id' , $created ))); 
    47            foreach ($psCreated as $i => $pCreated)    
     71           $psCreated =  Controller::find(array('concept' => 'participant'), false , array('deepness' => '1' , 'filter' => array('IN', 'id' , $created )));                 
     72                   foreach ($psCreated as $i => $pCreated)    
    4873           {     
    4974               if($pCreated['isOrganizer'] == '1') continue; //escapa organizador 
     
    5277                
    5378               $organizer = isset( $organizers[$pCreated['schedulable']] ) ? $organizers[ $pCreated['schedulable'] ] : self::getOrganizer( $pCreated['schedulable'] ); 
    54                 
     79                            
     80                                if($pCreated['delegatedFrom'] != 0){ 
     81                                        self::participantDelegated( $pCreated , $schedulable , $organizer);     
     82                                        continue; 
     83                                } 
     84                            
    5585               switch ($pCreated['status'])  
    5686               { 
     
    6898        { 
    6999            $psUpdated  = Controller::find(array('concept' => 'participant'), false , array('deepness' => '1' , 'filter' => array('IN', 'id' , $updated ))); 
    70             foreach ($psUpdated as $i => $pUpdated)    
    71             { 
     100                        foreach ($psUpdated as $i => $pUpdated)    
     101            {                    
    72102                if($pUpdated['isOrganizer'] == '1') continue; //escapa organizador 
    73103                $schedulable = isset( $schedulables[$pUpdated['schedulable']] ) ? $schedulables[ $pUpdated['schedulable'] ] : Controller::read( array('concept' => 'schedulable', 'id' => $pUpdated['schedulable']) , false , array('deepness' => '2')); 
     
    77107                    if(($v['isOrganizer'] === '1') && ($organizer = $v) ) break; 
    78108                     
    79                  
    80                 if( $pUpdated['status'] != STATUS_UNANSWERED) 
    81                 self::participantStatusChange( $pUpdated['id'] , $schedulable , $organizer , $pUpdated['status'] );     
     109                if($pUpdated['delegatedFrom'] != 0){ 
     110                                        self::participantDelegatedStatusChange( $pUpdated , $schedulable , $organizer , $pUpdated['status'] );     
     111                }else if( $pUpdated['status'] != STATUS_UNANSWERED && $pUpdated['status'] != STATUS_DELEGATED) 
     112                                        self::participantStatusChange( $pUpdated['id'] , $schedulable , $organizer , $pUpdated['status'] );     
    82113            } 
    83114        } 
    84115    } 
    85      
    86  
    87     /** 
    88     * Monta o email de convite que sera enviado ao participant 
    89     * 
    90     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    91     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    92     * @sponsor    Caixa Econômica Federal 
    93     * @author     Cristiano Corrêa Schmidt 
    94     * @return     void 
    95     * @access     public 
    96     */ 
    97     public static function participantCreated( &$partID , &$schedulable ) 
    98     { 
     116         
     117        public function formatSuggestion(&$params){ 
     118             
     119                $schedulable =  Controller::read(  array( 'concept' => 'schedulable' , 'id' => $params['schedulable'] ) , null , array('deepness' => '2') ) ; 
     120                 
     121                foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador       
     122            if(($v['isOrganizer'] === '1') && ($organizer = $v) ) break; 
     123                 
     124                $method = 'COUNTER'; 
     125                $notificationType = 'Sugestão de horário'; 
     126                $part = 'other'; 
     127                 
     128                $schedulableReference = $schedulable; 
     129                 
     130                $referenceSuggestion = array( 'startTime' => $params['startTime'], 
     131                                                                        'endTime' => $params['endTime'], 
     132                                                                        'allDay' => $params['allDay'] 
     133                                                                ); 
     134                $schedulable = array_merge($schedulable, $referenceSuggestion); 
     135                 
     136                self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType); 
     137                        
     138 
     139                $timezone = new DateTimeZone('UTC'); 
     140                $sTime = new DateTime( '@'.(int)($schedulableReference['startTime'] / 1000) , $timezone ); 
     141                $eTime =  new DateTime( '@'.(int)($schedulableReference['endTime'] / 1000) , $timezone );  
     142            
     143                if(isset($schedulableReference['timezone'])) 
     144                { 
     145                        $sTime->setTimezone(new DateTimeZone($schedulableReference['timezone'])); 
     146                        $eTime->setTimezone(new DateTimeZone($schedulableReference['timezone'])); 
     147                } 
     148 
     149                $data['nowStartDate'] = date_format( $sTime , 'd/m/Y'); 
     150        $data['nowStartTime'] = ($schedulableReference['allDay']) ? '' : date_format( $sTime , 'H:i'); 
     151        $data['nowEndDate'] = date_format( $eTime , 'd/m/Y'); 
     152        $data['nowEndTime'] = ($schedulableReference['allDay']) ? '' :  date_format( $eTime , 'H:i'); 
     153                $data['userRequest'] = Config::me('uid'); 
     154                 
     155                $params['attachments'][] = $ical; 
     156                $params['isHtml'] = true;                          
     157                $params['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/notify_suggestion_body.tpl'); 
     158                $params['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');; 
     159                $params['from'] = Config::me('mail');    
     160                $params['to'] = $organizer['user']['mail']; 
     161                 
     162        }   
     163         
     164        public function formatSuggestionResponse(&$params){      
     165                $schedulable = $params['schedulable']; 
     166                foreach ($schedulable['participants'] as $i => $v) {//salva em $organizer as informações do organizador       
     167            if($v['isOrganizer'] === '1') $organizer = $v; 
     168                        if($v['user']['mail'] == Config::me('mail')) $me = $v; 
     169                } 
     170                $method = 'DECLINECOUNTER'; 
     171                $notificationType = 'Sugestão de horário'; 
     172                $part = 'other'; 
     173                 
     174                $schedulable['participants'] = array(); 
     175                array_push($schedulable['participants'], $me, $organizer); 
     176                 
     177                self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType); 
     178                 
     179                if($params['status'] == 'DECLINECOUNTER') 
     180                        $data['status'] = 'não pode ser aceito'; 
     181                         
     182                $params['attachments'][] = $ical; 
     183                $params['isHtml'] = true;                          
     184                $params['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/notify_suggestion_response_body.tpl'); 
     185                $params['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');; 
     186                $params['to'] = $params['from']; 
     187                $params['from'] = Config::me('mail');    
     188        } 
     189         
     190         
     191        public static function _getAttendeeById($attendeId, $schedulable){ 
     192                foreach ($schedulable['participants'] as $id => $dv)  
     193                        if($dv['id'] == $attendeId ) 
     194                                return $dv; 
     195        } 
     196         
     197        /** 
     198    * Prepara para criação de email de delegação 
     199    * 
     200    * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     201    * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     202    * @sponsor    Caixa Econômica Federal 
     203    * @author     Adriano Coutinho da Silva 
     204    * @return     void 
     205    * @access     public 
     206    */ 
     207        public static function participantDelegated( &$partID , &$schedulable , &$organizer){ 
     208         
     209                $delegatedParams = array(); 
     210                 
     211                $delegatedFrom = self::_getAttendeeById($partID['delegatedFrom'], $schedulable); 
     212                $delegatedParams['delegatedFrom'] = $delegatedFrom['user']['uid']; 
     213                 
     214                self::participantCreated( $partID['id'] , $schedulable , STATUS_DELEGATED, $delegatedParams );           
     215                 
     216                $delegatedTo = self::_getAttendeeById($partID['id'], $schedulable); 
     217                $delegatedParams['delegated'] = $delegatedTo['user']['uid']; 
     218                 
     219                self::participantStatusChange( $partID['delegatedFrom'] , $schedulable , $organizer , STATUS_DELEGATED, $delegatedParams ); 
     220        } 
     221         
     222        /** 
     223    * Monta o email de resposta que sera enviado ao delegatedFrom 
     224    * 
     225    * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     226    * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     227    * @sponsor    Caixa Econômica Federal 
     228    * @author     Cristiano Corrêa Schmidt 
     229    * @return     void 
     230    * @access     public 
     231    */ 
     232    public static function participantDelegatedStatusChange( &$partID , &$schedulable, $organizer, &$type = false){ 
     233         
     234                $delegatedParams = array(); 
     235                                         
     236                $delegated = self::_getAttendeeById($partID['id'], $schedulable); 
     237                $delegatedParams['delegated'] = $delegated['user']['uid'];               
     238                 
     239                switch($partID['status']){ 
     240            case STATUS_ACCEPTED: 
     241                $delegatedParams['status'] = 'aceitou'; 
     242            break; 
     243            case STATUS_TENTATIVE: 
     244                $delegatedParams['status'] = 'marcou como tentativa'; 
     245            break; 
     246            case STATUS_CANCELLED: 
     247                $delegatedParams['status'] = 'rejeitou'; 
     248            break; 
     249                        case STATUS_DELEGATED: 
     250                                $delegatedParams['status'] = 'delegou para um novo participante'; 
     251            break; 
     252                } 
     253                        //notifica o organizador a resposta do delegado 
     254                        self::participantStatusChange( $partID['delegatedFrom'] , $schedulable , $organizer , $type, $delegatedParams ); 
     255         
     256                        $method = 'REQUEST'; 
     257                        $notificationType = 'Resposta Delegação';  
     258                        $part = 'attendees'; 
     259                        self::mountStruture($partID['delegatedFrom'], $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType ); 
     260                         
     261                        $data = array_merge($data, $delegatedParams); 
     262                         
     263            self::sendMail($data, $ical , $part['user']['mail'] , $subject , 'notify_response_delegated_status_body'); 
     264        
     265    } 
     266 
     267        public static function mountStruture( $partID , &$schedulable, $type = false, &$data, &$subject, &$ical, &$part = false, &$method, &$notificationType, $regSet = false) { 
     268                 
     269                if( (Config::regGet('ical://'.$schedulable['id'].'/'.$method) === false) || ($method == 'CANCEL') ) //Verifica se o ical ja não esta no reg 
     270                { 
     271                        $schedulable['URI']['concept'] = 'schedulable'; 
     272                        $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($schedulable) , array('method' => $method) );   
     273                        $ical['type'] = 'text/calendar'; 
     274                        $ical['name'] = 'calendar.ics'; 
     275                        if($regSet) 
     276                                Config::regSet('ical://'.$schedulable['id'].'/'.$method, $ical); 
     277                } 
     278                else 
     279                        $ical = Config::regGet('ical://'.$schedulable['id'].'/'.$method); 
    99280         
    100            $part = false; 
    101            if( Config::regGet('ical://'.$schedulable['id'].'/REQUEST') === false ) //Verifica se o ical ja não esta no reg 
    102            { 
    103                   $schedulable['URI']['concept'] = 'schedulable'; 
    104                   $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($schedulable) , array('method' => 'REQUEST') );   
    105                   $ical['type'] = 'text/calendar'; 
    106                   $ical['name'] = 'calendar.ics'; 
    107                   Config::regSet('ical://'.$schedulable['id'].'/REQUEST', $ical); 
    108            } 
    109            else 
    110                 $ical = Config::regGet('ical://'.$schedulable['id'].'/REQUEST'); 
    111          
    112            $timezone = new DateTimeZone('UTC'); 
    113            $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , $timezone ); 
    114            $eTime =  new DateTime( '@'.(int)($schedulable['endTime'] / 1000) , $timezone );  
     281                        $timezone = new DateTimeZone('UTC'); 
     282                        $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , $timezone ); 
     283                        $eTime =  new DateTime( '@'.(int)($schedulable['endTime'] / 1000) , $timezone );  
    115284            
    116            if(isset($schedulable['timezone'])) 
    117            { 
    118                $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    119                $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    120            } 
     285                        if(isset($schedulable['timezone'])) 
     286                        { 
     287                                $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
     288                                $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
     289                        } 
    121290             
    122            $attList = '<UL> '; 
    123            foreach ($schedulable['participants'] as $i => $v)   
    124            {    
    125                 if($part === false && $v['id'] == $partID) 
    126                    $part = $v; 
    127  
    128                 $attList .= ' <LI> '. (isset($v['user']['name']) ? $v['user']['name'] : $v['user']['mail']) ; 
    129            } 
    130            $attList .= '</UL>'; 
    131                              
    132            $data = array(     'startDate' =>  date_format( $sTime , 'd/m/Y') , 
     291                        $data = array(     'startDate' =>  date_format( $sTime , 'd/m/Y') , 
    133292                              'startTime' =>  ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i') , 
    134293                              'endDate' =>  date_format( $eTime , 'd/m/Y') , 
     
    136295                              'eventTitle' =>  $schedulable['summary'], 
    137296                              'eventLocation' =>  $schedulable['location'], 
    138                               'timezone' =>  ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC' , 
    139                               'participants' =>  $attList); 
    140              
    141              $subject['notificationType'] = 'Convite de Calendario'; 
    142              $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); 
    143              $subject['startDate'] = date_format( $sTime , 'd/m/Y'); 
    144              $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i'); 
    145              $subject['endDate'] = date_format( $eTime , 'd/m/Y'); 
    146              $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format( $eTime , 'H:i'); 
    147              $subject['participant'] = Config::me('uid'); 
    148   
    149              self::sendMail($data, $ical , $part['user']['mail'] , $subject , 'notify_create_body'); 
     297                              'timezone' =>  ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC'); 
     298                        $temp = $part; 
     299                        $part = false; 
     300                        switch($temp){ 
     301                                case 'attendees': 
     302                                        $attList = '<UL> '; 
     303                                        foreach ($schedulable['participants'] as $i => $v)   
     304                                        {                
     305                                                if($part === false && $v['id'] == $partID) 
     306                                                   $part = $v; 
     307 
     308                                                $attList .= ' <LI> '. (isset($v['user']['name']) ? $v['user']['name'] : $v['user']['mail']) ; 
     309                                        } 
     310                                        $attList .= '</UL>'; 
     311                                        $data['participants'] = $attList; 
     312                                break; 
     313                                case 'me': 
     314                                        $part = self::_getAttendeeById($partID, $schedulable); 
     315                                        $data['participant'] = isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']; 
     316                                break; 
     317                                case 'othersAttendees': 
     318                                        $data['participants'] = '<UL> '; 
     319                                        foreach ($schedulable['participants'] as $ii => $participant){ 
     320                                                if(Config::me('mail') !== $participant['user']['mail']) 
     321                                                        $part[] = $participant['user']['mail']; 
     322                                         
     323                                        $data['participants'] .= ' <LI> '. (isset($participant['user']['name']) ? $participant['user']['name'] : $participant['user']['mail']) ; 
     324                                        } 
     325                                break; 
     326                        }          
     327                        $subject['notificationType'] = $notificationType; 
     328                        $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); 
     329                        $subject['startDate'] = date_format( $sTime , 'd/m/Y'); 
     330                        $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i'); 
     331                        $subject['endDate'] = date_format( $eTime , 'd/m/Y'); 
     332                        $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format( $eTime , 'H:i'); 
     333                        $subject['participant'] = Config::me('uid'); 
     334        } 
     335         
     336         
     337    /** 
     338    * Monta o email de convite que sera enviado ao participant 
     339    * 
     340    * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     341    * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     342    * @sponsor    Caixa Econômica Federal 
     343    * @author     Cristiano Corrêa Schmidt 
     344    * @return     void 
     345    * @access     public 
     346    */ 
     347    public static function participantCreated( &$partID , &$schedulable, $type = false, $delegatedParams = false) 
     348    {    
     349                $method = 'REQUEST'; 
     350                $notificationType = 'Convite de Calendario';  
     351                $part = 'attendees'; 
     352                self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true); 
     353         
     354                if($delegatedParams) 
     355                        $data = array_merge($data, $delegatedParams); 
     356                                          
     357                 self::sendMail($data, $ical , $part['user']['mail'] , $subject , !$delegatedParams  ? 'notify_create_body' : 'notify_create_delegated_body' ); 
    150358        
    151359    } 
     
    161369    * @access     public 
    162370    */ 
    163     public static function participantStatusChange( &$partID , &$schedulable , &$organizer , $type ) 
    164     { 
    165         $part = false; 
    166          
    167         foreach ($schedulable['participants'] as $i => $v) //salva em $part as informações do participant a ser notificado      
    168             if(($v['id'] == $partID) && ($part = $v) ) break; 
    169              
    170         if( Config::regGet('ical://'.$schedulable['id'].'/REPLY') === false ) //Verifica se o ical ja não esta no reg 
    171         { 
    172                   $schedulable['URI']['concept'] = 'schedulable'; 
    173                   $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($schedulable) , array('method' => 'REPLY' , 'participant' => $partID) );   
    174                   $ical['type'] = 'text/calendar'; 
    175                   $ical['name'] = 'calendar.ics'; 
    176                   Config::regSet('ical://'.$schedulable['id'].'/REPLY', $ical); 
    177          } 
    178          else 
    179             $ical = Config::regGet('ical://'.$schedulable['id'].'/REPLY'); 
    180          
    181          
    182         $timezone = new DateTimeZone('UTC'); 
    183         $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , $timezone ); 
    184         $eTime =  new DateTime( '@'.(int)($schedulable['endTime'] / 1000) , $timezone );  
    185          
    186         if(isset($schedulable['timezone'])) 
    187         { 
    188             $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    189             $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    190         } 
    191          
    192         $data = array('startDate' =>  date_format( $sTime , 'd/m/Y') , 
    193                           'startTime' =>  ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i') , 
    194                           'endDate' =>  date_format( $eTime , 'd/m/Y') , 
    195                           'endTime' =>  ($schedulable['allDay']) ? '' :  date_format( $eTime , 'H:i') , 
    196                           'eventTitle' =>  $schedulable['summary'], 
    197                           'eventLocation' =>  $schedulable['location'], 
    198                           'timezone' =>  ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC' , 
    199                           'participant' =>  (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']) ); 
    200            
    201         $subject['notificationType'] = 'Convite Aceito'; 
    202         $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); 
    203         $subject['startDate'] = date_format( $sTime , 'd/m/Y'); 
    204         $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i'); 
    205         $subject['endDate'] = date_format( $eTime , 'd/m/Y'); 
    206         $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format( $eTime , 'H:i'); 
    207         $subject['participant'] = Config::me('uid'); 
    208            
     371    public static function participantStatusChange( &$partID , &$schedulable , &$organizer , $type, $delegatedParams = false ) 
     372    {    
     373        $method = 'REPLY'; 
     374                $notificationType = 'Convite Aceito'; 
     375                $part = 'me'; 
     376                 
     377                self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true ); 
     378                        
     379                if($delegatedParams){ 
     380                        $data = array_merge($data, $delegatedParams); 
     381                        $tplDelegated = 'notify_delegated_status_body'; 
     382                } 
     383 
    209384       switch($type) 
    210385       { 
    211386            case STATUS_ACCEPTED: 
    212                 $tpl =   'notify_accept_body'; 
     387                $tpl =   !$delegatedParams ? 'notify_accept_body' : $tplDelegated; 
    213388                $subject['notificationType'] = 'Convite Aceito'; 
    214389            break; 
    215             case STATUS_TENATIVE: 
    216                 $tpl =   'notify_attempt_body'; 
     390            case STATUS_TENTATIVE: 
     391                $tpl =   !$delegatedParams ? 'notify_attempt_body' : $tplDelegated; 
    217392                $subject['notificationType'] = 'Convite  aceito provisoriamente'; 
    218393            break; 
    219394            case STATUS_CANCELLED: 
    220                 $tpl =   'notify_reject_body'; 
     395                $tpl =   !$delegatedParams ? 'notify_reject_body' : $tplDelegated; 
    221396                $subject['notificationType'] = 'Convite rejeitado'; 
     397            break; 
     398                        case STATUS_DELEGATED: 
     399                                if($delegatedParams) 
     400                                        $data = array_merge($data, $delegatedParams); 
     401                $tpl =   'notify_delegated_body'; 
     402                $subject['notificationType'] = 'Convite delegado'; 
    222403            break; 
    223404 
     
    264445       if((Config::regGet('noAlarm') === false) && (self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd']))) 
    265446       { 
    266            $schedulable['URI']['concept'] = 'schedulable';  
    267            $timezone = new DateTimeZone('UTC'); 
    268            $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , $timezone ); 
    269            $eTime =  new DateTime( '@'.(int)($schedulable['endTime'] / 1000) , $timezone );  
    270             
    271            if(isset($schedulable['timezone'])) 
    272            { 
    273                $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    274                $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    275            } 
    276             
    277            $data =  array('startDate' =>  date_format( $sTime , 'd/m/Y') , 
    278                               'startTime' =>  ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i') , 
    279                               'endDate' =>  date_format( $eTime , 'd/m/Y') , 
    280                               'endTime' =>  ($schedulable['allDay']) ? '' : date_format( $eTime , 'H:i') , 
    281                               'eventTitle' =>  $schedulable['summary'], 
    282                               'eventLocation' =>  $schedulable['location'], 
    283                               'timezone' =>  ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC'); 
    284                                
    285             
    286            $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($schedulable) , array('method' => 'CANCEL'));   
    287            $ical['type'] = 'text/calendar'; 
    288            $ical['name'] = 'calendar.ics'; 
    289             
    290            foreach ($schedulable['participants'] as $ii => $participant) 
    291                 if(Config::me('mail') !== $participant['user']['mail']) 
    292                     $to[] = $participant['user']['mail']; 
    293                      
    294              $subject['notificationType'] = 'Cancelamento de Calendario'; 
    295              $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); 
    296              $subject['startDate'] = date_format( $sTime , 'd/m/Y'); 
    297              $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i'); 
    298              $subject['endDate'] = date_format( $eTime , 'd/m/Y'); 
    299              $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format( $eTime , 'H:i'); 
    300              $subject['participant'] = Config::me('uid');      
     447                        $method = 'CANCEL'; 
     448                        $notificationType = 'Cancelamento de Calendario'; 
     449                        $part = 'othersAttendees'; 
     450                        self::mountStruture($uri['id'], $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType ); 
    301451                 
    302            if(count($to) > 0) 
    303             self::sendMail($data, $ical , implode(',' , $to) ,$subject, 'notify_cancel_body'); 
     452           if(count($part) > 0) 
     453            self::sendMail($data, $ical , implode(',' , $part) ,$subject, 'notify_cancel_body'); 
    304454       } 
    305455    } 
     
    323473       if((Config::regGet('noAlarm') === false) && (self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd']))) 
    324474       {   
    325            $schedulable['URI']['concept'] = 'schedulable';  
    326            $timezone = new DateTimeZone('UTC'); 
    327            $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , $timezone ); 
    328            $eTime =  new DateTime( '@'.(int)($schedulable['endTime'] / 1000) , $timezone );  
    329             
    330            if(isset($schedulable['timezone'])) 
    331            { 
    332                $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    333                $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    334            } 
    335             
    336            $data =  array('startDate' =>  date_format( $sTime , 'd/m/Y') , 
    337                               'startTime' => ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i') , 
    338                               'endDate' =>  date_format( $eTime , 'd/m/Y') , 
    339                               'endTime' => ($schedulable['allDay']) ? '' : date_format( $eTime , 'H:i') , 
    340                               'eventTitle' =>  $schedulable['summary'], 
    341                               'eventLocation' =>  $schedulable['location'], 
    342                               'timezone' =>  ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC'); 
    343  
    344            $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($schedulable) , array('method' => 'CANCEL'));   
    345            $ical['type'] = 'text/calendar'; 
    346            $ical['name'] = 'calendar.ics'; 
    347             
    348              $subject['notificationType'] = 'Cancelamento de Calendario'; 
    349              $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); 
    350              $subject['startDate'] = date_format( $sTime , 'd/m/Y'); 
    351              $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i'); 
    352              $subject['endDate'] = date_format( $eTime , 'd/m/Y'); 
    353              $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format( $eTime , 'H:i'); 
    354              $subject['participant'] = Config::me('uid'); 
    355                            
    356            self::sendMail($data, $ical , $participant['user']['mail'] , $subject , 'notify_cancel_body');   
     475                        $method = 'CANCEL'; 
     476                        $notificationType = 'Cancelamento de Calendario'; 
     477                        $part = 'others'; 
     478                        self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType ); 
     479                                             
     480                        self::sendMail($data, $ical , $participant['user']['mail'] , $subject , 'notify_cancel_body');   
    357481        } 
    358482    } 
     
    369493    */ 
    370494    public function updateEvent( &$uri , &$params , &$criteria , $original  ) 
    371     { 
    372         
    373        $schedulableOld =  Controller::read( array( 'concept' => 'schedulable' , 'id' => $uri['id'] ) , null , array('deepness' => '2') ) ;       
     495    {        
     496       $schedulableOld =  Controller::find( array( 'concept' => 'schedulable' , 'id' => $uri['id'] ) , null , array('deepness' => '2') ) ;       
    374497       $schedulable = $schedulableOld; 
    375498       $alt = false; 
    376         
    377        
     499 
    378500       foreach ($params as $i => $v) //Verifica se ouve alteração no evento 
    379501           if( isset( $schedulableOld[$i] ) && $schedulableOld[$i] != $v && $i != 'participants') 
     
    384506            
    385507       if ( ($alt === true) && (Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'])) )  
    386        { 
    387             $schedulable['URI']['concept'] = 'schedulable'; 
    388             $ical['source'] = Controller::format(array('service' => 'iCal'), array($schedulable), array('method' => 'REQUEST')); 
    389             $ical['type'] = 'text/calendar'; 
    390             $ical['name'] = 'calendar.ics'; 
    391  
    392             $timezone = new DateTimeZone('UTC'); 
    393             $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), $timezone); 
    394             $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), $timezone); 
    395  
    396             if (isset($schedulable['timezone'])) { 
    397                 $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    398                 $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    399             } 
    400             ///Montando lista de participantes 
    401             $attList = '<UL> '; 
    402             foreach ($schedulable['participants'] as $ii => $participant) 
    403                 $attList .= ' <LI> ' . (isset($participant['user']['name']) ? $participant['user']['name'] : $participant['user']['mail']); 
    404             $attList .= ' </UL>'; 
    405             ///////////////////////// 
    406  
    407             $data = array('startDate' => date_format($sTime, 'd/m/Y'), 
    408                 'startTime' => ($schedulable['allDay']) ? '' : date_format($sTime, 'H:i'), 
    409                 'endDate' => date_format($eTime, 'd/m/Y'), 
    410                 'endTime' => ($schedulable['allDay']) ? '' : date_format($eTime, 'H:i'), 
    411                 'eventTitle' => $schedulable['summary'], 
    412                 'eventLocation' => $schedulable['location'], 
    413                 'timezone' => ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC', 
    414                 'participants' => $attList 
    415             ); 
    416  
    417  
    418             foreach ($schedulable['participants'] as $ii => $participant) 
    419                 if (Config::me('mail') !== $participant['user']['mail']) 
    420                     $to[] = $participant['user']['mail']; 
    421  
    422             $subject['notificationType'] = 'Modificação de Calendario'; 
    423             $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); 
    424             $subject['startDate'] = date_format($sTime, 'd/m/Y'); 
    425             $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format($sTime, 'H:i'); 
    426             $subject['endDate'] = date_format($eTime, 'd/m/Y'); 
    427             $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format($eTime, 'H:i'); 
    428             $subject['participant'] = Config::me('uid'); 
    429               
    430             if ( isset($to) && count($to) > 0) 
    431                 self::sendMail($data, $ical, implode(',', $to), $subject, 'notify_modify_body'); 
     508       {                         
     509                        $method = 'REQUEST'; 
     510                        $notificationType = 'Modificação de Calendario';  
     511                        $part = 'othersAttendees'; 
     512                        self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType); 
     513 
     514            if ( isset($part) && count($part) > 0) 
     515                self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_modify_body'); 
    432516        } 
    433517    } 
Note: See TracChangeset for help on using the changeset viewer.