source: trunk/prototype/modules/calendar/interceptors/Notifications.php @ 6331

Revision 6331, 22.0 KB checked in by acoutinho, 12 years ago (diff)

Ticket #2795 - Problema ao tentar aceitar convite da agenda para a conta compartilhada

RevLine 
[5341]1<?php
[6027]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;
[5514]18        }
[6027]19    }
[5514]20
[6027]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.
[5514]34
[6027]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            }
[6177]45            else if ($concept['concept'] === 'schedulable') { //Caso exista schedulable no commit antecipa o carregamento do owner             
[6027]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))
49                        break;
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]);
[5947]61                }
[6027]62            }
63        }
[5947]64
[6027]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'));
[6177]71                if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))
[6027]72                    continue; //Escapa eventos do passado
[5341]73
[6027]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;
[5514]79                }
80
[6027]81                switch ($pCreated['status']) {
82                    case STATUS_CONFIRMED:
83                        self::participantStatusChange($pCreated['id'], $schedulable, $organizer, STATUS_ACCEPTED);
84                        break;
85                    case STATUS_UNANSWERED:
86                        self::participantCreated($pCreated['id'], $schedulable, false, false, $organizer);
87                        break;
[5514]88                }
[6027]89            }
[5514]90        }
[6027]91
92        if (isset($updated)) {
93            $psUpdated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $updated)));
[6331]94
[6027]95            foreach ($psUpdated as $i => $pUpdated) {
96                if ($pUpdated['isOrganizer'] == '1')
97                    continue; //escapa organizador
98                $schedulable = isset($schedulables[$pUpdated['schedulable']]) ? $schedulables[$pUpdated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pUpdated['schedulable']), false, array('deepness' => '2'));
[6177]99                if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))
[6027]100                    continue; //Escapa eventos do passado
101
102                foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador     
103                    if (($v['isOrganizer'] === '1') && ($organizer = $v))
104                        break;
105
106                if ($pUpdated['delegatedFrom'] != 0) {
107                    self::participantDelegatedStatusChange($pUpdated, $schedulable, $organizer, $pUpdated['status']);
108                } else if ($pUpdated['status'] != STATUS_UNANSWERED && $pUpdated['status'] != STATUS_DELEGATED)
109                    self::participantStatusChange($pUpdated['id'], $schedulable, $organizer, $pUpdated['status']);
110            }
[5514]111        }
[6027]112    }
113
114    public function formatSuggestion(&$params) {
115
116        $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $params['schedulable']), null, array('deepness' => '2'));
117
118        foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador     
119            if (($v['isOrganizer'] === '1') && ($organizer = $v))
120                break;
121
122        $method = 'COUNTER';
123        $notificationType = 'Sugestão de horário';
124        $part = 'other';
125
126        $schedulableReference = $schedulable;
127
[6038]128        $referenceSuggestion = array('startTime' => strtotime($params['startTime'] . ' ' . $schedulable['timezone']) . '000',
129            'endTime' => strtotime($params['endTime'] . ' ' . $schedulable['timezone']) . '000',
[6027]130            'allDay' => $params['allDay']
131        );
[6038]132
[6027]133        $schedulable = array_merge($schedulable, $referenceSuggestion);
134
135        self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType);
136
137
138        $timezone = new DateTimeZone('UTC');
139        $sTime = new DateTime('@' . (int) ($schedulableReference['startTime'] / 1000), $timezone);
140        $eTime = new DateTime('@' . (int) ($schedulableReference['endTime'] / 1000), $timezone);
141
142        if (isset($schedulableReference['timezone'])) {
143            $sTime->setTimezone(new DateTimeZone($schedulableReference['timezone']));
144            $eTime->setTimezone(new DateTimeZone($schedulableReference['timezone']));
[5514]145        }
[6027]146
147        $data['nowStartDate'] = date_format($sTime, 'd/m/Y');
148        $data['nowStartTime'] = ($schedulableReference['allDay']) ? '' : date_format($sTime, 'H:i');
149        $data['nowEndDate'] = date_format($eTime, 'd/m/Y');
150        $data['nowEndTime'] = ($schedulableReference['allDay']) ? '' : date_format($eTime, 'H:i');
151        $data['userRequest'] = Config::me('uid');
152
153        $ical2 = $ical;
154        $ical2['type'] = 'text/calendar';
155        $ical2['name'] = 'thunderbird.ics';
156        $params['attachments'][] = $ical2;
157        $params['attachments'][] = $ical;
158        $params['isHtml'] = true;
159        $params['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/notify_suggestion_body.tpl');
160        $params['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl');
161        ;
162        $params['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>';
163        $params['to'] = $organizer['user']['mail'];
164    }
165
166    public function formatSuggestionResponse(&$params) {
167        $schedulable = $params['schedulable'];
168        foreach ($schedulable['participants'] as $i => $v) {//salva em $organizer as informações do organizador     
169            if ($v['isOrganizer'] === '1')
170                $organizer = $v;
171            if ($v['user']['mail'] == Config::me('mail'))
172                $me = $v;
173        }
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        ;
194        $params['to'] = $params['from'];
195        $params['from'] = $params['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>';
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
[5947]204    /**
[6027]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) {
[5947]215
[6027]216        $delegatedParams = array();
[5947]217
[6027]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        $delegatedParams = array();
241
242        $delegated = self::_getAttendeeById($partID['id'], $schedulable);
243        $delegatedParams['delegated'] = $delegated['user']['uid'];
244
245        switch ($partID['status']) {
246            case STATUS_ACCEPTED:
247                $delegatedParams['status'] = 'aceitou';
248                break;
249            case STATUS_TENTATIVE:
250                $delegatedParams['status'] = 'marcou como tentativa';
251                break;
252            case STATUS_CANCELLED:
253                $delegatedParams['status'] = 'rejeitou';
254                break;
[5947]255            case STATUS_DELEGATED:
[6027]256                $delegatedParams['status'] = 'delegou para um novo participante';
257                break;
258        }
259        //notifica o organizador a resposta do delegado
260        self::participantStatusChange($partID['delegatedFrom'], $schedulable, $organizer, $type, $delegatedParams);
[5947]261
[6027]262        $method = 'REQUEST';
263        $notificationType = 'Resposta Delegação';
264        $part = 'attendees';
265        self::mountStruture($partID['delegatedFrom'], $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType);
[5947]266
[6027]267        $data = array_merge($data, $delegatedParams);
268
269        self::sendMail($data, $ical, $part['user']['mail'], $subject, 'notify_response_delegated_status_body');
[5514]270    }
271
[6331]272    public static function mountStruture(&$partID, &$schedulable, $type = false, &$data, &$subject, &$ical, &$part = false, &$method, &$notificationType, $regSet = false) {
[5947]273
[6027]274        if ((Config::regGet('ical://' . $schedulable['id'] . '/' . $method) === false) || ($method == 'CANCEL')) { //Verifica se o ical ja não esta no reg
275            $schedulable['URI']['concept'] = 'schedulable';
276            $ical['source'] = Controller::format(array('service' => 'iCal'), array($schedulable), array('method' => $method));
277            $ical['type'] = 'text/plain';
278            $ical['name'] = 'outlook.ics';
279            if ($regSet)
280                Config::regSet('ical://' . $schedulable['id'] . '/' . $method, $ical);
281        }
282        else
283            $ical = Config::regGet('ical://' . $schedulable['id'] . '/' . $method);
[6038]284
[6034]285        if (!is_numeric($schedulable['endTime']))
[6038]286            $schedulable['startTime'] = self::parseTimeDate($schedulable['startTime'], $schedulable['timezone']);
[5514]287
[6038]288        if (!is_numeric($schedulable['endTime'])) {
289            $schedulable['endTime'] = self::parseTimeDate($schedulable['endTime'], $schedulable['timezone']);
290
291            if ($schedulable['allDay'])
292                $schedulable['endTime'] = $schedulable['endTime'] + 86400000;
[6034]293        }
[6038]294
[6027]295        $timezone = new DateTimeZone('UTC');
296        $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), $timezone);
297        $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), $timezone);
[6038]298
[6027]299        if (isset($schedulable['timezone'])) {
300            $sTime->setTimezone(new DateTimeZone($schedulable['timezone']));
301            $eTime->setTimezone(new DateTimeZone($schedulable['timezone']));
[5514]302        }
[6027]303
304        $data = array('startDate' => date_format($sTime, 'd/m/Y'),
305            'startTime' => ($schedulable['allDay']) ? '' : date_format($sTime, 'H:i'),
306            'endDate' => date_format($eTime, 'd/m/Y'),
307            'endTime' => ($schedulable['allDay']) ? '' : date_format($eTime, 'H:i'),
308            'eventTitle' => $schedulable['summary'],
309            'eventLocation' => $schedulable['location'],
310            'timezone' => ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC');
311        $temp = $part;
312        $part = false;
313
314        switch ($temp) {
315            case 'attendees':
316                $attList = '<UL> ';
317                foreach ($schedulable['participants'] as $i => $v) {
318                    if ($part === false && $v['id'] == $partID)
319                        $part = $v;
320
321                    $attList .= ' <LI> ' . (isset($v['user']['name']) ? $v['user']['name'] : $v['user']['mail']);
322                }
323                $attList .= '</UL>';
324                $data['participants'] = $attList;
325                break;
326            case 'me':
327                $part = self::_getAttendeeById($partID, $schedulable);
328                $data['participant'] = isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail'];
[6331]329                $partID = $part;
[6027]330                break;
331            case 'othersAttendees':
332                $data['participants'] = '<UL> ';
333                foreach ($schedulable['participants'] as $ii => $participant) {
334                    if (Config::me('mail') !== $participant['user']['mail'])
335                        $part[] = $participant['user']['mail'];
336
337                    $data['participants'] .= ' <LI> ' . (isset($participant['user']['name']) ? $participant['user']['name'] : $participant['user']['mail']);
338                }
339                break;
340        }
341        $subject['notificationType'] = $notificationType;
342        $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8');
343        $subject['startDate'] = date_format($sTime, 'd/m/Y');
344        $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format($sTime, 'H:i');
345        $subject['endDate'] = date_format($eTime, 'd/m/Y');
346        $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format($eTime, 'H:i');
[6331]347        $subject['participant'] = (is_array($partID) && isset($partID['user']) )? $partID['user']['uid'] : Config::me('uid');
[6027]348    }
349
[5514]350    /**
[6027]351     * Monta o email de convite que sera enviado ao participant
352     *
353     * @license    http://www.gnu.org/copyleft/gpl.html GPL
354     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
355     * @sponsor    Caixa Econômica Federal
356     * @author     Cristiano Corrêa Schmidt
357     * @return     void
358     * @access     public
359     */
360    public static function participantCreated(&$partID, &$schedulable, $type = false, $delegatedParams = false, $organizer = false) {
[5947]361        $method = 'REQUEST';
[6027]362        $notificationType = 'Convite de Calendario';
[5947]363        $part = 'attendees';
[6027]364        self::mountStruture($partID, $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType, true);
[5947]365
[6027]366        if ($delegatedParams)
367            $data = array_merge($data, $delegatedParams);
[5947]368
[6027]369        self::sendMail($data, $ical, $part['user']['mail'], $subject, !$delegatedParams ? 'notify_create_body' : 'notify_create_delegated_body', $organizer);
[5341]370    }
[6027]371
[5341]372    /**
[6027]373     * Monta o email de aceito que sera enviado ao organizador
374     *
375     * @license    http://www.gnu.org/copyleft/gpl.html GPL
376     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
377     * @sponsor    Caixa Econômica Federal
378     * @author     Cristiano Corrêa Schmidt
379     * @return     void
380     * @access     public
381     */
[6331]382    public static function participantStatusChange(&$partID, &$schedulable, &$organizer, $type, $delegatedParams = false) {     
[6027]383        $method = 'REPLY';
[5947]384        $notificationType = 'Convite Aceito';
385        $part = 'me';
[5514]386
[6027]387        self::mountStruture($partID, $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType, true);
[5947]388
[6027]389        if ($delegatedParams) {
390            $data = array_merge($data, $delegatedParams);
391            $tplDelegated = 'notify_delegated_status_body';
[5947]392        }
393
[6027]394        switch ($type) {
395            case STATUS_ACCEPTED:
396                $tpl = !$delegatedParams ? 'notify_accept_body' : $tplDelegated;
397                $subject['notificationType'] = 'Convite Aceito';
398                break;
399            case STATUS_TENTATIVE:
400                $tpl = !$delegatedParams ? 'notify_attempt_body' : $tplDelegated;
401                $subject['notificationType'] = 'Convite  aceito provisoriamente';
402                break;
403            case STATUS_CANCELLED:
404                $tpl = !$delegatedParams ? 'notify_reject_body' : $tplDelegated;
405                $subject['notificationType'] = 'Convite rejeitado';
406                break;
407            case STATUS_DELEGATED:
408                if ($delegatedParams)
409                    $data = array_merge($data, $delegatedParams);
410                $tpl = 'notify_delegated_body';
411                $subject['notificationType'] = 'Convite delegado';
412                break;
413        }
[5341]414
[6331]415        self::sendMail($data, $ical, $organizer['user']['mail'], $subject, $tpl, $partID);
[5341]416    }
[6027]417
[5341]418    /**
[6027]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        $ical2 = $ical;
430        $ical2['type'] = 'text/calendar';
431        $ical2['name'] = 'thunderbird.ics';
432        $mail['attachments'][] = $ical2;
433        $mail['attachments'][] = $ical;
434        $mail['isHtml'] = true;
435        $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $template . '.tpl');
436        $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl');
437        ;
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);
[5341]441    }
[6027]442
[5341]443    /**
[6027]444     * Monta o email de cancelado que sera enviado a todos os participantes
445     *
446     * @license    http://www.gnu.org/copyleft/gpl.html GPL
447     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
448     * @sponsor    Caixa Econômica Federal
449     * @author     Cristiano Corrêa Schmidt
450     * @return     void
451     * @access     public
452     */
453    public function deleteEvent(&$uri, &$result, &$params, $original) {
454        $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $uri['id']), null, array('deepness' => '2'));
[6177]455        if ((Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))) {
[5947]456            $method = 'CANCEL';
457            $notificationType = 'Cancelamento de Calendario';
458            $part = 'othersAttendees';
[6027]459            self::mountStruture($uri['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType);
460
461            if (count($part) > 0)
462                self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_cancel_body');
463        }
[5341]464    }
[6027]465
[5341]466    /**
[6027]467     * Monta o email de cancelado que sera enviado ao participant deleteado
468     *
469     * @license    http://www.gnu.org/copyleft/gpl.html GPL
470     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
471     * @sponsor    Caixa Econômica Federal
472     * @author     Cristiano Corrêa Schmidt
473     * @return     void
474     * @access     public
475     */
476    public function deleteParticipant(&$uri, &$result, &$params, $original) {
477
478        $participant = Controller::read(array('concept' => 'participant', 'id' => $uri['id']), null, array('deepness' => '1'));
479        $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $participant['schedulable']));
480
[6177]481        if ((Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))) {
[5947]482            $method = 'CANCEL';
483            $notificationType = 'Cancelamento de Calendario';
484            $part = 'others';
[6027]485            self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType);
[5947]486
[6027]487            self::sendMail($data, $ical, $participant['user']['mail'], $subject, 'notify_cancel_body');
488        }
[5341]489    }
[6027]490
[5341]491    /**
[6027]492     * Faz um diff do update se ouve realmente uma alteração envia um email a todos os participants
493     *
494     * @license    http://www.gnu.org/copyleft/gpl.html GPL
495     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
496     * @sponsor    Caixa Econômica Federal
497     * @author     Cristiano Corrêa Schmidt
498     * @return     void
499     * @access     public
500     */
[6190]501    public function updateEvent(&$uri, $params, &$criteria, $original) {
[6027]502        $schedulableOld = Controller::read(array('concept' => 'schedulable', 'id' => $uri['id']), null, array('deepness' => '2'));
503        $schedulable = $schedulableOld;
504        $alt = false;
[5514]505
[6027]506        foreach ($params as $i => $v) //Verifica se ouve alteração no evento
507            if (isset($schedulableOld[$i]) && $schedulableOld[$i] != $v && $i != 'participants') {
508                $schedulable[$i] = $v;
509                $alt = true;
510            }
[6190]511
[6177]512        if (($alt === true) && (Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))) {
[5947]513            $method = 'REQUEST';
[6027]514            $notificationType = 'Modificação de Calendario';
[6038]515            $part = 'othersAttendees';
[6027]516            self::mountStruture($uri['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType);
[5341]517
[6027]518            if (isset($part) && $part && count($part) > 0)
519                self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_modify_body');
520        }
[5341]521    }
[6038]522
523    static private function parseTimeDate($time, $timezone) {
524        return strtotime($time . ' ' . $timezone) . '000';
525    }
526
[6036]527}
[6038]528
[5341]529?>
Note: See TracBrowser for help on using the repository browser.