Changeset 6027


Ignore:
Timestamp:
04/25/12 15:23:28 (12 years ago)
Author:
acoutinho
Message:

Ticket #2653 - Inconsistencia na atualizacao de eventos

File:
1 edited

Legend:

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

    r5947 r6027  
    11<?php 
    2 require_once ROOTPATH.'/modules/calendar/constants.php'; 
    3 require_once ROOTPATH.'/modules/calendar/interceptors/Helpers.php'; 
    4 require_once ROOTPATH.'/plugins/icalcreator/iCalcreator.class.php'; 
    5 require_once ROOTPATH.'/api/parseTPL.php'; 
    6   
    7 class Notifications extends Helpers  
    8 { 
    9      
    10         public function formatNotification(&$uri , &$params , &$data , $original){       
    11             switch ($params['type']) { 
    12                 case 'suggestion': 
    13                         self::formatSuggestion($params);     
     2 
     3require_once ROOTPATH . '/modules/calendar/constants.php'; 
     4require_once ROOTPATH . '/modules/calendar/interceptors/Helpers.php'; 
     5require_once ROOTPATH . '/plugins/icalcreator/iCalcreator.class.php'; 
     6require_once ROOTPATH . '/api/parseTPL.php'; 
     7 
     8class Notifications extends Helpers { 
     9 
     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     * Analisa o commit do conceito participant e encaminha cada participant para seu devido metodo de notrificação 
     23     * 
     24     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     25     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     26     * @sponsor    Caixa Econômica Federal 
     27     * @author     Cristiano Corrêa Schmidt 
     28     * @return     void 
     29     * @access     public 
     30     */ 
     31    public function commitParticipant(&$uri, &$result, &$data, $original) { 
     32        if (Config::regGet('noAlarm') !== false) 
     33            return; //Escapa notificações caso a flag de noAlarm esteja ativa. 
     34 
     35        $organizers = array(); //Cache Organizadores 
     36        $schedulables = array(); //Cache Schedulables 
     37 
     38        foreach ($data as $i => $concept) { 
     39            if ($concept['concept'] === 'participant') { 
     40                if ($concept['method'] == 'create') 
     41                    $created[] = $concept['id']; 
     42                else if ($concept['method'] == 'update') 
     43                    $updated[] = $concept['id']; 
     44            } 
     45            else if ($concept['concept'] === 'schedulable') { //Caso exista schedulable no commit antecipa o carregamento do owner 
     46                $schedulables[$concept['id']] = Controller::read(array('concept' => 'schedulable', 'id' => $concept['id']), false, array('deepness' => '2')); 
     47                foreach ($schedulables[$concept['id']]['participants'] as $i => $v) //salva em $organizers as informações do organizador       
     48                    if (($v['isOrganizer'] === '1') && ($organizers[$concept['id']] = $v)) 
    1449                        break; 
    15                 case 'suggestionResponse': 
    16                         self::formatSuggestionResponse($params);     
     50            }else if ($concept['concept'] === 'schedulableToAttachment') { 
     51                $relationAttachment = Controller::find(array('concept' => 'schedulableToAttachment'), false, array('filter' => array('=', 'id', $concept['id']))); 
     52 
     53 
     54 
     55                foreach ($relationAttachment as $key => $value) { 
     56                    if (!array_key_exists('attachments', $schedulables[$value['schedulable']])) 
     57                        $schedulables[$value['schedulable']]['attachments'] = array(); 
     58 
     59                    $temp = Controller::find(array('concept' => 'attachment'), false, array('filter' => array('=', 'id', $value['attachment']))); 
     60                    array_push($schedulables[$value['schedulable']]['attachments'], $temp[0]); 
     61                } 
     62            } 
     63        } 
     64 
     65        if (isset($created)) { 
     66            $psCreated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $created))); 
     67            foreach ($psCreated as $i => $pCreated) { 
     68                if ($pCreated['isOrganizer'] == '1') 
     69                    continue; //escapa organizador 
     70                $schedulable = isset($schedulables[$pCreated['schedulable']]) ? $schedulables[$pCreated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pCreated['schedulable']), false, array('deepness' => '2')); 
     71                if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'])) 
     72                    continue; //Escapa eventos do passado 
     73 
     74                $organizer = isset($organizers[$pCreated['schedulable']]) ? $organizers[$pCreated['schedulable']] : self::getOrganizer($pCreated['schedulable']); 
     75 
     76                if ($pCreated['delegatedFrom'] != 0) { 
     77                    self::participantDelegated($pCreated, $schedulable, $organizer); 
     78                    continue; 
     79                } 
     80 
     81                switch ($pCreated['status']) { 
     82                    case STATUS_CONFIRMED: 
     83                        self::participantStatusChange($pCreated['id'], $schedulable, $organizer, STATUS_ACCEPTED); 
    1784                        break; 
    18                 }  
    19         } 
    20          
    21          
    22         /** 
    23     * Analisa o commit do conceito participant e encaminha cada participant para seu devido metodo de notrificação 
    24     * 
    25     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    26     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    27     * @sponsor    Caixa Econômica Federal 
    28     * @author     Cristiano Corrêa Schmidt 
    29     * @return     void 
    30     * @access     public 
    31     */ 
    32     public function commitParticipant(&$uri , &$result , &$data , $original) 
    33     {                            
    34         if(Config::regGet('noAlarm') !== false) return; //Escapa notificações caso a flag de noAlarm esteja ativa. 
    35                  
    36         $organizers = array(); //Cache Organizadores 
    37         $schedulables = array(); //Cache Schedulables 
    38  
    39         foreach ($data as $i => $concept)  
    40         { 
    41             if($concept['concept'] === 'participant') 
    42             { 
    43                if( $concept['method'] == 'create' ) 
    44                    $created[] = $concept['id']; 
    45                else if( $concept['method'] == 'update' ) 
    46                    $updated[] = $concept['id']; 
    47             } 
    48             else if($concept['concept'] === 'schedulable') //Caso exista schedulable no commit antecipa o carregamento do owner 
    49             { 
    50                 $schedulables[ $concept['id'] ] = Controller::read( array('concept' => 'schedulable', 'id' => $concept['id']) , false , array('deepness' => '2')); 
    51                 foreach ($schedulables[ $concept['id'] ]['participants'] as $i => $v) //salva em $organizers as informações do organizador       
    52                     if(($v['isOrganizer'] === '1') && ($organizers[$concept['id']] = $v) ) break; 
    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                         } 
    67         } 
    68          
    69         if( isset( $created ) ) 
    70         { 
    71            $psCreated =  Controller::find(array('concept' => 'participant'), false , array('deepness' => '1' , 'filter' => array('IN', 'id' , $created )));                 
    72                    foreach ($psCreated as $i => $pCreated)    
    73            {     
    74                if($pCreated['isOrganizer'] == '1') continue; //escapa organizador 
    75                $schedulable = isset( $schedulables[$pCreated['schedulable']] ) ? $schedulables[$pCreated['schedulable']] : Controller::read( array('concept' => 'schedulable', 'id' => $pCreated['schedulable']) , false , array('deepness' => '2')); 
    76                if(!self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd'])) continue; //Escapa eventos do passado 
    77                 
    78                $organizer = isset( $organizers[$pCreated['schedulable']] ) ? $organizers[ $pCreated['schedulable'] ] : self::getOrganizer( $pCreated['schedulable'] ); 
    79                             
    80                 if($pCreated['delegatedFrom'] != 0){ 
    81                         self::participantDelegated( $pCreated , $schedulable , $organizer);     
    82                         continue; 
     85                    case STATUS_UNANSWERED: 
     86                        self::participantCreated($pCreated['id'], $schedulable, false, false, $organizer); 
     87                        break; 
    8388                } 
    84                             
    85                switch ($pCreated['status'])  
    86                { 
    87                    case STATUS_CONFIRMED: 
    88                         self::participantStatusChange( $pCreated['id'] , $schedulable , $organizer  , STATUS_ACCEPTED); 
    89                        break; 
    90                    case STATUS_UNANSWERED: 
    91                         self::participantCreated( $pCreated['id'] , $schedulable, false, false, $organizer ); 
    92                        break; 
    93                }  
    94            } 
    95         } 
    96          
    97         if( isset( $updated ) ) 
    98         { 
    99             $psUpdated  = Controller::find(array('concept' => 'participant'), false , array('deepness' => '1' , 'filter' => array('IN', 'id' , $updated ))); 
    100                         foreach ($psUpdated as $i => $pUpdated)    
    101             {                    
    102                 if($pUpdated['isOrganizer'] == '1') continue; //escapa organizador 
    103                 $schedulable = isset( $schedulables[$pUpdated['schedulable']] ) ? $schedulables[ $pUpdated['schedulable'] ] : Controller::read( array('concept' => 'schedulable', 'id' => $pUpdated['schedulable']) , false , array('deepness' => '2')); 
    104                 if(!self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd'])) continue; //Escapa eventos do passado 
    105                    
    106                 foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador       
    107                     if(($v['isOrganizer'] === '1') && ($organizer = $v) ) break; 
    108                      
    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'] );     
    113             } 
    114         } 
    115     } 
    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'])); 
     89            } 
     90        } 
     91 
     92        if (isset($updated)) { 
     93            $psUpdated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $updated))); 
     94            foreach ($psUpdated as $i => $pUpdated) { 
     95                if ($pUpdated['isOrganizer'] == '1') 
     96                    continue; //escapa organizador 
     97                $schedulable = isset($schedulables[$pUpdated['schedulable']]) ? $schedulables[$pUpdated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pUpdated['schedulable']), false, array('deepness' => '2')); 
     98                if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'])) 
     99                    continue; //Escapa eventos do passado 
     100 
     101                foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador       
     102                    if (($v['isOrganizer'] === '1') && ($organizer = $v)) 
     103                        break; 
     104 
     105                if ($pUpdated['delegatedFrom'] != 0) { 
     106                    self::participantDelegatedStatusChange($pUpdated, $schedulable, $organizer, $pUpdated['status']); 
     107                } else if ($pUpdated['status'] != STATUS_UNANSWERED && $pUpdated['status'] != STATUS_DELEGATED) 
     108                    self::participantStatusChange($pUpdated['id'], $schedulable, $organizer, $pUpdated['status']); 
     109            } 
     110        } 
     111    } 
     112 
     113    public function formatSuggestion(&$params) { 
     114 
     115        $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $params['schedulable']), null, array('deepness' => '2')); 
     116 
     117        foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador       
     118            if (($v['isOrganizer'] === '1') && ($organizer = $v)) 
     119                break; 
     120 
     121        $method = 'COUNTER'; 
     122        $notificationType = 'Sugestão de horário'; 
     123        $part = 'other'; 
     124 
     125        $schedulableReference = $schedulable; 
     126 
     127        $referenceSuggestion = array('startTime' => $params['startTime'], 
     128            'endTime' => $params['endTime'], 
     129            'allDay' => $params['allDay'] 
     130        ); 
     131        $schedulable = array_merge($schedulable, $referenceSuggestion); 
     132 
     133        self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); 
     134 
     135 
     136        $timezone = new DateTimeZone('UTC'); 
     137        $sTime = new DateTime('@' . (int) ($schedulableReference['startTime'] / 1000), $timezone); 
     138        $eTime = new DateTime('@' . (int) ($schedulableReference['endTime'] / 1000), $timezone); 
     139 
     140        if (isset($schedulableReference['timezone'])) { 
     141            $sTime->setTimezone(new DateTimeZone($schedulableReference['timezone'])); 
     142            $eTime->setTimezone(new DateTimeZone($schedulableReference['timezone'])); 
     143        } 
     144 
     145        $data['nowStartDate'] = date_format($sTime, 'd/m/Y'); 
     146        $data['nowStartTime'] = ($schedulableReference['allDay']) ? '' : date_format($sTime, 'H:i'); 
     147        $data['nowEndDate'] = date_format($eTime, 'd/m/Y'); 
     148        $data['nowEndTime'] = ($schedulableReference['allDay']) ? '' : date_format($eTime, 'H:i'); 
     149        $data['userRequest'] = Config::me('uid'); 
     150 
     151        $ical2 = $ical; 
     152        $ical2['type'] = 'text/calendar'; 
     153        $ical2['name'] = 'thunderbird.ics'; 
     154        $params['attachments'][] = $ical2; 
     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        ; 
     160        $params['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; 
     161        $params['to'] = $organizer['user']['mail']; 
     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') 
     168                $organizer = $v; 
     169            if ($v['user']['mail'] == Config::me('mail')) 
     170                $me = $v; 
     171        } 
     172        $method = 'DECLINECOUNTER'; 
     173        $notificationType = 'Sugestão de horário'; 
     174        $part = 'other'; 
     175 
     176        $schedulable['participants'] = array(); 
     177        array_push($schedulable['participants'], $me, $organizer); 
     178 
     179        self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); 
     180 
     181        if ($params['status'] == 'DECLINECOUNTER') 
     182            $data['status'] = 'não pode ser aceito'; 
     183        $ical2 = $ical; 
     184        $ical2['type'] = 'text/calendar'; 
     185        $ical2['name'] = 'thunderbird.ics'; 
     186        $params['attachments'][] = $ical2; 
     187        $params['attachments'][] = $ical; 
     188        $params['isHtml'] = true; 
     189        $params['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/notify_suggestion_response_body.tpl'); 
     190        $params['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); 
     191        ; 
     192        $params['to'] = $params['from']; 
     193        $params['from'] = $params['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; 
     194    } 
     195 
     196    public static function _getAttendeeById($attendeId, $schedulable) { 
     197        foreach ($schedulable['participants'] as $id => $dv) 
     198            if ($dv['id'] == $attendeId) 
     199                return $dv; 
     200    } 
     201 
     202    /** 
     203     * Prepara para criação de email de delegação 
     204     * 
     205     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     206     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     207     * @sponsor    Caixa Econômica Federal 
     208     * @author     Adriano Coutinho da Silva 
     209     * @return     void 
     210     * @access     public 
     211     */ 
     212    public static function participantDelegated(&$partID, &$schedulable, &$organizer) { 
     213 
     214        $delegatedParams = array(); 
     215 
     216        $delegatedFrom = self::_getAttendeeById($partID['delegatedFrom'], $schedulable); 
     217        $delegatedParams['delegatedFrom'] = $delegatedFrom['user']['uid']; 
     218 
     219        self::participantCreated($partID['id'], $schedulable, STATUS_DELEGATED, $delegatedParams); 
     220 
     221        $delegatedTo = self::_getAttendeeById($partID['id'], $schedulable); 
     222        $delegatedParams['delegated'] = $delegatedTo['user']['uid']; 
     223 
     224        self::participantStatusChange($partID['delegatedFrom'], $schedulable, $organizer, STATUS_DELEGATED, $delegatedParams); 
     225    } 
     226 
     227    /** 
     228     * Monta o email de resposta que sera enviado ao delegatedFrom 
     229     * 
     230     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     231     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     232     * @sponsor    Caixa Econômica Federal 
     233     * @author     Cristiano Corrêa Schmidt 
     234     * @return     void 
     235     * @access     public 
     236     */ 
     237    public static function participantDelegatedStatusChange(&$partID, &$schedulable, $organizer, &$type = false) { 
     238 
     239        $delegatedParams = array(); 
     240 
     241        $delegated = self::_getAttendeeById($partID['id'], $schedulable); 
     242        $delegatedParams['delegated'] = $delegated['user']['uid']; 
     243 
     244        switch ($partID['status']) { 
     245            case STATUS_ACCEPTED: 
     246                $delegatedParams['status'] = 'aceitou'; 
     247                break; 
     248            case STATUS_TENTATIVE: 
     249                $delegatedParams['status'] = 'marcou como tentativa'; 
     250                break; 
     251            case STATUS_CANCELLED: 
     252                $delegatedParams['status'] = 'rejeitou'; 
     253                break; 
     254            case STATUS_DELEGATED: 
     255                $delegatedParams['status'] = 'delegou para um novo participante'; 
     256                break; 
     257        } 
     258        //notifica o organizador a resposta do delegado 
     259        self::participantStatusChange($partID['delegatedFrom'], $schedulable, $organizer, $type, $delegatedParams); 
     260 
     261        $method = 'REQUEST'; 
     262        $notificationType = 'Resposta Delegação'; 
     263        $part = 'attendees'; 
     264        self::mountStruture($partID['delegatedFrom'], $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType); 
     265 
     266        $data = array_merge($data, $delegatedParams); 
     267 
     268        self::sendMail($data, $ical, $part['user']['mail'], $subject, 'notify_response_delegated_status_body'); 
     269    } 
     270 
     271    public static function mountStruture($partID, &$schedulable, $type = false, &$data, &$subject, &$ical, &$part = false, &$method, &$notificationType, $regSet = false) { 
     272 
     273        if ((Config::regGet('ical://' . $schedulable['id'] . '/' . $method) === false) || ($method == 'CANCEL')) { //Verifica se o ical ja não esta no reg 
     274            $schedulable['URI']['concept'] = 'schedulable'; 
     275            $ical['source'] = Controller::format(array('service' => 'iCal'), array($schedulable), array('method' => $method)); 
     276            $ical['type'] = 'text/plain'; 
     277            $ical['name'] = 'outlook.ics'; 
     278            if ($regSet) 
     279                Config::regSet('ical://' . $schedulable['id'] . '/' . $method, $ical); 
     280        } 
     281        else 
     282            $ical = Config::regGet('ical://' . $schedulable['id'] . '/' . $method); 
     283 
     284        $timezone = new DateTimeZone('UTC'); 
     285        $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), $timezone); 
     286        $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), $timezone); 
     287 
     288        if (isset($schedulable['timezone'])) { 
     289            $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
     290            $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
     291        } 
     292 
     293        $data = array('startDate' => date_format($sTime, 'd/m/Y'), 
     294            'startTime' => ($schedulable['allDay']) ? '' : date_format($sTime, 'H:i'), 
     295            'endDate' => date_format($eTime, 'd/m/Y'), 
     296            'endTime' => ($schedulable['allDay']) ? '' : date_format($eTime, 'H:i'), 
     297            'eventTitle' => $schedulable['summary'], 
     298            'eventLocation' => $schedulable['location'], 
     299            'timezone' => ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC'); 
     300        $temp = $part; 
     301        $part = false; 
     302 
     303        switch ($temp) { 
     304            case 'attendees': 
     305                $attList = '<UL> '; 
     306                foreach ($schedulable['participants'] as $i => $v) { 
     307                    if ($part === false && $v['id'] == $partID) 
     308                        $part = $v; 
     309 
     310                    $attList .= ' <LI> ' . (isset($v['user']['name']) ? $v['user']['name'] : $v['user']['mail']); 
    147311                } 
    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                 $ical2 = $ical; 
    156                 $ical2['type'] = 'text/calendar';  
    157                 $ical2['name'] = 'thunderbird.ics'; 
    158                 $params['attachments'][] = $ical2; 
    159                 $params['attachments'][] = $ical; 
    160                 $params['isHtml'] = true;                          
    161                 $params['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/notify_suggestion_body.tpl'); 
    162                 $params['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');; 
    163                 $params['from'] ='"'.Config::me('cn').'" <'.Config::me('mail').'>';    
    164                 $params['to'] = $organizer['user']['mail']; 
    165                  
    166         }   
    167          
    168         public function formatSuggestionResponse(&$params){      
    169                 $schedulable = $params['schedulable']; 
    170                 foreach ($schedulable['participants'] as $i => $v) {//salva em $organizer as informações do organizador       
    171             if($v['isOrganizer'] === '1') $organizer = $v; 
    172                         if($v['user']['mail'] == Config::me('mail')) $me = $v; 
     312                $attList .= '</UL>'; 
     313                $data['participants'] = $attList; 
     314                break; 
     315            case 'me': 
     316                $part = self::_getAttendeeById($partID, $schedulable); 
     317                $data['participant'] = isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']; 
     318                break; 
     319            case 'othersAttendees': 
     320                $data['participants'] = '<UL> '; 
     321                foreach ($schedulable['participants'] as $ii => $participant) { 
     322                    if (Config::me('mail') !== $participant['user']['mail']) 
     323                        $part[] = $participant['user']['mail']; 
     324 
     325                    $data['participants'] .= ' <LI> ' . (isset($participant['user']['name']) ? $participant['user']['name'] : $participant['user']['mail']); 
    173326                } 
    174                 $method = 'DECLINECOUNTER'; 
    175                 $notificationType = 'Sugestão de horário'; 
    176                 $part = 'other'; 
    177                  
    178                 $schedulable['participants'] = array(); 
    179                 array_push($schedulable['participants'], $me, $organizer); 
    180                  
    181                 self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType); 
    182                  
    183                 if($params['status'] == 'DECLINECOUNTER') 
    184                         $data['status'] = 'não pode ser aceito'; 
    185                                 $ical2 = $ical; 
    186                 $ical2['type'] = 'text/calendar';  
    187                 $ical2['name'] = 'thunderbird.ics'; 
    188                 $params['attachments'][] = $ical2;       
    189                 $params['attachments'][] = $ical; 
    190                 $params['isHtml'] = true;                          
    191                 $params['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/notify_suggestion_response_body.tpl'); 
    192                 $params['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');; 
    193                 $params['to'] = $params['from']; 
    194                 $params['from'] = $params['from'] ='"'.Config::me('cn').'" <'.Config::me('mail').'>'; 
    195         } 
    196          
    197          
    198         public static function _getAttendeeById($attendeId, $schedulable){ 
    199                 foreach ($schedulable['participants'] as $id => $dv)  
    200                         if($dv['id'] == $attendeId ) 
    201                                 return $dv; 
    202         } 
    203          
    204         /** 
    205     * Prepara para criação de email de delegação 
    206     * 
    207     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    208     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    209     * @sponsor    Caixa Econômica Federal 
    210     * @author     Adriano Coutinho da Silva 
    211     * @return     void 
    212     * @access     public 
    213     */ 
    214         public static function participantDelegated( &$partID , &$schedulable , &$organizer){ 
    215          
    216                 $delegatedParams = array(); 
    217                  
    218                 $delegatedFrom = self::_getAttendeeById($partID['delegatedFrom'], $schedulable); 
    219                 $delegatedParams['delegatedFrom'] = $delegatedFrom['user']['uid']; 
    220                  
    221                 self::participantCreated( $partID['id'] , $schedulable , STATUS_DELEGATED, $delegatedParams );           
    222                  
    223                 $delegatedTo = self::_getAttendeeById($partID['id'], $schedulable); 
    224                 $delegatedParams['delegated'] = $delegatedTo['user']['uid']; 
    225                  
    226                 self::participantStatusChange( $partID['delegatedFrom'] , $schedulable , $organizer , STATUS_DELEGATED, $delegatedParams ); 
    227         } 
    228          
    229     /** 
    230     * Monta o email de resposta que sera enviado ao delegatedFrom 
    231     * 
    232     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    233     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    234     * @sponsor    Caixa Econômica Federal 
    235     * @author     Cristiano Corrêa Schmidt 
    236     * @return     void 
    237     * @access     public 
    238     */ 
    239     public static function participantDelegatedStatusChange( &$partID , &$schedulable, $organizer, &$type = false){ 
    240          
    241             $delegatedParams = array(); 
    242  
    243             $delegated = self::_getAttendeeById($partID['id'], $schedulable); 
    244             $delegatedParams['delegated'] = $delegated['user']['uid'];           
    245  
    246             switch($partID['status']){ 
    247             case STATUS_ACCEPTED: 
    248                 $delegatedParams['status'] = 'aceitou'; 
    249             break; 
    250             case STATUS_TENTATIVE: 
    251                 $delegatedParams['status'] = 'marcou como tentativa'; 
    252             break; 
    253             case STATUS_CANCELLED: 
    254                 $delegatedParams['status'] = 'rejeitou'; 
    255             break; 
    256             case STATUS_DELEGATED: 
    257                     $delegatedParams['status'] = 'delegou para um novo participante'; 
    258             break; 
    259                 } 
    260             //notifica o organizador a resposta do delegado 
    261             self::participantStatusChange( $partID['delegatedFrom'] , $schedulable , $organizer , $type, $delegatedParams ); 
    262  
    263             $method = 'REQUEST'; 
    264             $notificationType = 'Resposta Delegação';  
    265             $part = 'attendees'; 
    266             self::mountStruture($partID['delegatedFrom'], $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType ); 
    267  
     327                break; 
     328        } 
     329        $subject['notificationType'] = $notificationType; 
     330        $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8'); 
     331        $subject['startDate'] = date_format($sTime, 'd/m/Y'); 
     332        $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format($sTime, 'H:i'); 
     333        $subject['endDate'] = date_format($eTime, 'd/m/Y'); 
     334        $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format($eTime, 'H:i'); 
     335        $subject['participant'] = Config::me('uid'); 
     336    } 
     337 
     338    /** 
     339     * Monta o email de convite que sera enviado ao participant 
     340     * 
     341     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     342     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     343     * @sponsor    Caixa Econômica Federal 
     344     * @author     Cristiano Corrêa Schmidt 
     345     * @return     void 
     346     * @access     public 
     347     */ 
     348    public static function participantCreated(&$partID, &$schedulable, $type = false, $delegatedParams = false, $organizer = false) { 
     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) 
    268355            $data = array_merge($data, $delegatedParams); 
    269                          
    270             self::sendMail($data, $ical , $part['user']['mail'] , $subject , 'notify_response_delegated_status_body'); 
    271         
    272     } 
    273  
    274         public static function mountStruture( $partID , &$schedulable, $type = false, &$data, &$subject, &$ical, &$part = false, &$method, &$notificationType, $regSet = false) { 
    275                  
    276                 if( (Config::regGet('ical://'.$schedulable['id'].'/'.$method) === false) || ($method == 'CANCEL') ) //Verifica se o ical ja não esta no reg 
    277                 { 
    278                         $schedulable['URI']['concept'] = 'schedulable'; 
    279                         $ical['source'] = Controller::format( array( 'service' => 'iCal' ) , array($schedulable) , array('method' => $method) );   
    280                         $ical['type'] = 'text/plain'; 
    281                         $ical['name'] = 'outlook.ics'; 
    282                         if($regSet) 
    283                                 Config::regSet('ical://'.$schedulable['id'].'/'.$method, $ical); 
    284                 } 
    285                 else 
    286                         $ical = Config::regGet('ical://'.$schedulable['id'].'/'.$method); 
    287          
    288                         $timezone = new DateTimeZone('UTC'); 
    289                         $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , $timezone ); 
    290                         $eTime =  new DateTime( '@'.(int)($schedulable['endTime'] / 1000) , $timezone );  
    291             
    292                         if(isset($schedulable['timezone'])) 
    293                         { 
    294                                 $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    295                                 $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); 
    296                         } 
    297              
    298                         $data = array(     'startDate' =>  date_format( $sTime , 'd/m/Y') , 
    299                               'startTime' =>  ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i') , 
    300                               'endDate' =>  date_format( $eTime , 'd/m/Y') , 
    301                               'endTime' =>  ($schedulable['allDay']) ? '' :  date_format( $eTime , 'H:i') , 
    302                               'eventTitle' =>  $schedulable['summary'], 
    303                               'eventLocation' =>  $schedulable['location'], 
    304                               'timezone' =>  ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC'); 
    305                         $temp = $part; 
    306                         $part = false; 
    307  
    308                         switch($temp){ 
    309                                 case 'attendees': 
    310                                         $attList = '<UL> '; 
    311                                         foreach ($schedulable['participants'] as $i => $v)   
    312                                         {                
    313                                                 if($part === false && $v['id'] == $partID) 
    314                                                    $part = $v; 
    315  
    316                                                 $attList .= ' <LI> '. (isset($v['user']['name']) ? $v['user']['name'] : $v['user']['mail']) ; 
    317                                         } 
    318                                         $attList .= '</UL>'; 
    319                                         $data['participants'] = $attList; 
    320                                 break; 
    321                                 case 'me': 
    322                                         $part = self::_getAttendeeById($partID, $schedulable); 
    323                                         $data['participant'] = isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']; 
    324                                 break; 
    325                                 case 'othersAttendees': 
    326                                         $data['participants'] = '<UL> '; 
    327                                         foreach ($schedulable['participants'] as $ii => $participant){ 
    328                                                 if(Config::me('mail') !== $participant['user']['mail']) 
    329                                                         $part[] = $participant['user']['mail']; 
    330                                          
    331                                         $data['participants'] .= ' <LI> '. (isset($participant['user']['name']) ? $participant['user']['name'] : $participant['user']['mail']) ; 
    332                                         } 
    333                                 break; 
    334                         }          
    335                         $subject['notificationType'] = $notificationType; 
    336                         $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'],'ISO-8859-1','ISO-8859-1,UTF-8'); 
    337                         $subject['startDate'] = date_format( $sTime , 'd/m/Y'); 
    338                         $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format( $sTime , 'H:i'); 
    339                         $subject['endDate'] = date_format( $eTime , 'd/m/Y'); 
    340                         $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format( $eTime , 'H:i'); 
    341                         $subject['participant'] = Config::me('uid'); 
    342         } 
    343          
    344          
    345     /** 
    346     * Monta o email de convite que sera enviado ao participant 
    347     * 
    348     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    349     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    350     * @sponsor    Caixa Econômica Federal 
    351     * @author     Cristiano Corrêa Schmidt 
    352     * @return     void 
    353     * @access     public 
    354     */ 
    355     public static function participantCreated( &$partID , &$schedulable, $type = false, $delegatedParams = false, $organizer = false) 
    356     {    
    357         $method = 'REQUEST'; 
    358         $notificationType = 'Convite de Calendario';  
    359         $part = 'attendees'; 
    360         self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true); 
    361  
    362         if($delegatedParams) 
    363                 $data = array_merge($data, $delegatedParams); 
    364  
    365             self::sendMail($data, $ical , $part['user']['mail'] , $subject , !$delegatedParams  ? 'notify_create_body' : 'notify_create_delegated_body', $organizer ); 
    366         
    367     } 
    368      
    369     /** 
    370     * Monta o email de aceito que sera enviado ao organizador  
    371     * 
    372     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    373     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    374     * @sponsor    Caixa Econômica Federal 
    375     * @author     Cristiano Corrêa Schmidt 
    376     * @return     void 
    377     * @access     public 
    378     */ 
    379     public static function participantStatusChange( &$partID , &$schedulable , &$organizer , $type, $delegatedParams = false ) 
    380     {    
    381         $method = 'REPLY'; 
     356 
     357        self::sendMail($data, $ical, $part['user']['mail'], $subject, !$delegatedParams ? 'notify_create_body' : 'notify_create_delegated_body', $organizer); 
     358    } 
     359 
     360    /** 
     361     * Monta o email de aceito que sera enviado ao organizador  
     362     * 
     363     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     364     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     365     * @sponsor    Caixa Econômica Federal 
     366     * @author     Cristiano Corrêa Schmidt 
     367     * @return     void 
     368     * @access     public 
     369     */ 
     370    public static function participantStatusChange(&$partID, &$schedulable, &$organizer, $type, $delegatedParams = false) { 
     371        $method = 'REPLY'; 
    382372        $notificationType = 'Convite Aceito'; 
    383373        $part = 'me'; 
    384374 
    385         self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true ); 
    386  
    387         if($delegatedParams){ 
    388                 $data = array_merge($data, $delegatedParams); 
    389                 $tplDelegated = 'notify_delegated_status_body'; 
    390         } 
    391  
    392        switch($type) 
    393        { 
    394             case STATUS_ACCEPTED: 
    395                 $tpl =   !$delegatedParams ? 'notify_accept_body' : $tplDelegated; 
    396                 $subject['notificationType'] = 'Convite Aceito'; 
    397             break; 
    398             case STATUS_TENTATIVE: 
    399                 $tpl =   !$delegatedParams ? 'notify_attempt_body' : $tplDelegated; 
    400                 $subject['notificationType'] = 'Convite  aceito provisoriamente'; 
    401             break; 
    402             case STATUS_CANCELLED: 
    403                 $tpl =   !$delegatedParams ? 'notify_reject_body' : $tplDelegated; 
    404                 $subject['notificationType'] = 'Convite rejeitado'; 
    405             break; 
    406                 case STATUS_DELEGATED: 
    407                     if($delegatedParams) 
    408                         $data = array_merge($data, $delegatedParams); 
    409                 $tpl =   'notify_delegated_body'; 
    410                 $subject['notificationType'] = 'Convite delegado'; 
    411             break; 
    412  
    413        } 
    414          
    415         self::sendMail($data, $ical , $organizer['user']['mail'] , $subject , $tpl, false); 
    416     } 
    417      
    418     /** 
    419     * Monta o body e envia o email  
    420     * 
    421     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    422     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    423     * @sponsor    Caixa Econômica Federal 
    424     * @author     Cristiano Corrêa Schmidt 
    425     * @return     void 
    426     * @access     public 
    427     */ 
    428     private static function sendMail(&$data , &$ical , $to ,  &$subject , $template, $from = false ) 
    429     {  
    430        $ical2 = $ical; 
    431        $ical2['type'] = 'text/calendar';  
    432        $ical2['name'] = 'thunderbird.ics'; 
    433        $mail['attachments'][] = $ical2; 
    434        $mail['attachments'][] = $ical; 
    435        $mail['isHtml'] = true;                          
    436        $mail['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/'.$template.'.tpl'); 
    437        $mail['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');; 
    438        $mail['from'] = $from ? ('"'.$from['user']['name'].'" <'.$from['user']['mail'].'>') : ('"'.Config::me('cn').'" <'.Config::me('mail').'>'); 
    439        $mail['to'] = $to; 
    440        Controller::create( array( 'service' => 'SMTP' ), $mail );  
    441     } 
    442      
    443    
    444     /** 
    445     * Monta o email de cancelado que sera enviado a todos os participantes  
    446     * 
    447     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    448     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    449     * @sponsor    Caixa Econômica Federal 
    450     * @author     Cristiano Corrêa Schmidt 
    451     * @return     void 
    452     * @access     public 
    453     */ 
    454     public function deleteEvent( &$uri , &$result , &$params , $original  ) 
    455     {            
    456        $schedulable =  Controller::read(  array( 'concept' => 'schedulable' , 'id' => $uri['id'] ) , null , array('deepness' => '2') ) ; 
    457        if((Config::regGet('noAlarm') === false) && (self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd']))) 
    458        { 
     375        self::mountStruture($partID, $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType, true); 
     376 
     377        if ($delegatedParams) { 
     378            $data = array_merge($data, $delegatedParams); 
     379            $tplDelegated = 'notify_delegated_status_body'; 
     380        } 
     381 
     382        switch ($type) { 
     383            case STATUS_ACCEPTED: 
     384                $tpl = !$delegatedParams ? 'notify_accept_body' : $tplDelegated; 
     385                $subject['notificationType'] = 'Convite Aceito'; 
     386                break; 
     387            case STATUS_TENTATIVE: 
     388                $tpl = !$delegatedParams ? 'notify_attempt_body' : $tplDelegated; 
     389                $subject['notificationType'] = 'Convite  aceito provisoriamente'; 
     390                break; 
     391            case STATUS_CANCELLED: 
     392                $tpl = !$delegatedParams ? 'notify_reject_body' : $tplDelegated; 
     393                $subject['notificationType'] = 'Convite rejeitado'; 
     394                break; 
     395            case STATUS_DELEGATED: 
     396                if ($delegatedParams) 
     397                    $data = array_merge($data, $delegatedParams); 
     398                $tpl = 'notify_delegated_body'; 
     399                $subject['notificationType'] = 'Convite delegado'; 
     400                break; 
     401        } 
     402 
     403        self::sendMail($data, $ical, $organizer['user']['mail'], $subject, $tpl, false); 
     404    } 
     405 
     406    /** 
     407     * Monta o body e envia o email  
     408     * 
     409     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     410     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     411     * @sponsor    Caixa Econômica Federal 
     412     * @author     Cristiano Corrêa Schmidt 
     413     * @return     void 
     414     * @access     public 
     415     */ 
     416    private static function sendMail(&$data, &$ical, $to, &$subject, $template, $from = false) { 
     417        $ical2 = $ical; 
     418        $ical2['type'] = 'text/calendar'; 
     419        $ical2['name'] = 'thunderbird.ics'; 
     420        $mail['attachments'][] = $ical2; 
     421        $mail['attachments'][] = $ical; 
     422        $mail['isHtml'] = true; 
     423        $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $template . '.tpl'); 
     424        $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); 
     425        ; 
     426        $mail['from'] = $from ? ('"' . $from['user']['name'] . '" <' . $from['user']['mail'] . '>') : ('"' . Config::me('cn') . '" <' . Config::me('mail') . '>'); 
     427        $mail['to'] = $to; 
     428        Controller::create(array('service' => 'SMTP'), $mail); 
     429    } 
     430 
     431    /** 
     432     * Monta o email de cancelado que sera enviado a todos os participantes  
     433     * 
     434     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     435     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     436     * @sponsor    Caixa Econômica Federal 
     437     * @author     Cristiano Corrêa Schmidt 
     438     * @return     void 
     439     * @access     public 
     440     */ 
     441    public function deleteEvent(&$uri, &$result, &$params, $original) { 
     442        $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $uri['id']), null, array('deepness' => '2')); 
     443        if ((Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd']))) { 
    459444            $method = 'CANCEL'; 
    460445            $notificationType = 'Cancelamento de Calendario'; 
    461446            $part = 'othersAttendees'; 
    462             self::mountStruture($uri['id'], $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType ); 
    463                  
    464             if(count($part) > 0) 
    465                 self::sendMail($data, $ical , implode(',' , $part) ,$subject, 'notify_cancel_body'); 
    466        } 
    467     } 
    468      
    469     /** 
    470     * Monta o email de cancelado que sera enviado ao participant deleteado  
    471     * 
    472     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    473     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    474     * @sponsor    Caixa Econômica Federal 
    475     * @author     Cristiano Corrêa Schmidt 
    476     * @return     void 
    477     * @access     public 
    478     */ 
    479     public function deleteParticipant( &$uri , &$result , &$params , $original  ) 
    480     { 
    481         
    482        $participant =  Controller::read(  array( 'concept' => 'participant' , 'id' => $uri['id'] ) , null , array('deepness' => '1') ) ; 
    483        $schedulable =  Controller::read(  array( 'concept' => 'schedulable' , 'id' => $participant['schedulable'] ) ) ; 
    484                
    485        if((Config::regGet('noAlarm') === false) && (self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd']))) 
    486        {   
     447            self::mountStruture($uri['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); 
     448 
     449            if (count($part) > 0) 
     450                self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_cancel_body'); 
     451        } 
     452    } 
     453 
     454    /** 
     455     * Monta o email de cancelado que sera enviado ao participant deleteado  
     456     * 
     457     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     458     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     459     * @sponsor    Caixa Econômica Federal 
     460     * @author     Cristiano Corrêa Schmidt 
     461     * @return     void 
     462     * @access     public 
     463     */ 
     464    public function deleteParticipant(&$uri, &$result, &$params, $original) { 
     465 
     466        $participant = Controller::read(array('concept' => 'participant', 'id' => $uri['id']), null, array('deepness' => '1')); 
     467        $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $participant['schedulable'])); 
     468 
     469        if ((Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd']))) { 
    487470            $method = 'CANCEL'; 
    488471            $notificationType = 'Cancelamento de Calendario'; 
    489472            $part = 'others'; 
    490             self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType ); 
    491  
    492             self::sendMail($data, $ical , $participant['user']['mail'] , $subject , 'notify_cancel_body');   
    493         } 
    494     } 
    495      
    496     /** 
    497     * Faz um diff do update se ouve realmente uma alteração envia um email a todos os participants 
    498     * 
    499     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    500     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    501     * @sponsor    Caixa Econômica Federal 
    502     * @author     Cristiano Corrêa Schmidt 
    503     * @return     void 
    504     * @access     public 
    505     */ 
    506     public function updateEvent( &$uri , &$params , &$criteria , $original  ) 
    507     {        
    508        $schedulableOld =  Controller::find( array( 'concept' => 'schedulable' , 'id' => $uri['id'] ) , null , array('deepness' => '2') ) ;       
    509        $schedulable = $schedulableOld; 
    510        $alt = false; 
    511  
    512        foreach ($params as $i => $v) //Verifica se ouve alteração no evento 
    513            if( isset( $schedulableOld[$i] ) && $schedulableOld[$i] != $v && $i != 'participants') 
    514            { 
    515                $schedulable[$i] = $v; 
    516                $alt = true;    
    517            } 
    518             
    519        if ( ($alt === true) && (Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'])) )  
    520        {                         
     473            self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); 
     474 
     475            self::sendMail($data, $ical, $participant['user']['mail'], $subject, 'notify_cancel_body'); 
     476        } 
     477    } 
     478 
     479    /** 
     480     * Faz um diff do update se ouve realmente uma alteração envia um email a todos os participants 
     481     * 
     482     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     483     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     484     * @sponsor    Caixa Econômica Federal 
     485     * @author     Cristiano Corrêa Schmidt 
     486     * @return     void 
     487     * @access     public 
     488     */ 
     489    public function updateEvent(&$uri, &$params, &$criteria, $original) { 
     490        $schedulableOld = Controller::read(array('concept' => 'schedulable', 'id' => $uri['id']), null, array('deepness' => '2')); 
     491        $schedulable = $schedulableOld; 
     492        $alt = false; 
     493 
     494        foreach ($params as $i => $v) //Verifica se ouve alteração no evento 
     495            if (isset($schedulableOld[$i]) && $schedulableOld[$i] != $v && $i != 'participants') { 
     496                $schedulable[$i] = $v; 
     497                $alt = true; 
     498            } 
     499 
     500        if (($alt === true) && (Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd']))) { 
    521501            $method = 'REQUEST'; 
    522             $notificationType = 'Modificação de Calendario';  
     502            $notificationType = 'Modificação de Calendario'; 
    523503            $part = 'othersAttendees'; 
    524             self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType); 
    525  
    526             if ( isset($part) && count($part) > 0) 
    527                 self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_modify_body'); 
    528         } 
    529     } 
     504            self::mountStruture($uri['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); 
     505 
     506            if (isset($part) && $part && count($part) > 0) 
     507                self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_modify_body'); 
     508        } 
     509    } 
     510 
    530511} 
    531512 
Note: See TracChangeset for help on using the changeset viewer.