source: branches/2.4/prototype/modules/calendar/interceptors/Notifications.php @ 7364

Revision 7364, 23.5 KB checked in by eduardow, 12 years ago (diff)

Ticket #3144 - Não é enviado email para o usuario ao qual é delegado um evento.

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