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

Revision 7360, 23.2 KB checked in by eduardow, 8 years ago (diff)

Ticket #3140 - Problemas naas tarefas e atividades (title e formato de emails).

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