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

Revision 8000, 24.1 KB checked in by cristiano, 11 years ago (diff)

Ticket #3385 - ERRO ao Ao excluir um evento de uma agenda compartilhada

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