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

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
[6528]8use prototype\api\Config as Config;
9
[6027]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;
[5514]20        }
[6027]21    }
[5514]22
[6027]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.
[5514]36
[7910]37
38
[6027]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            }
[6177]49            else if ($concept['concept'] === 'schedulable') { //Caso exista schedulable no commit antecipa o carregamento do owner             
[6027]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]);
[5947]65                }
[6027]66            }
67        }
[5947]68
[6027]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) {
[7358]72                if ($pCreated['isOrganizer'] == '1' && $pCreated['delegatedFrom'] == '0')
[6027]73                    continue; //escapa organizador
[7358]74
[6027]75                $schedulable = isset($schedulables[$pCreated['schedulable']]) ? $schedulables[$pCreated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pCreated['schedulable']), false, array('deepness' => '2'));
[6177]76                if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))
[6027]77                    continue; //Escapa eventos do passado
[5341]78
[6027]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;
[5514]84                }
85
[6027]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;
[5514]93                }
[6027]94            }
[5514]95        }
[6027]96
97        if (isset($updated)) {
[7358]98
[6027]99            $psUpdated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $updated)));
[6331]100
[7910]101
[6027]102            foreach ($psUpdated as $i => $pUpdated) {
[7910]103                if ($pUpdated['isOrganizer'] == '1' && $pUpdated['delegatedFrom'] == '0'){
[6027]104                    continue; //escapa organizador
[7358]105        }
106
[6027]107                $schedulable = isset($schedulables[$pUpdated['schedulable']]) ? $schedulables[$pUpdated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pUpdated['schedulable']), false, array('deepness' => '2'));
[6177]108                if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))
[6027]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
[7358]115                if ($pUpdated['delegatedFrom'] != '0') {
[6027]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            }
[5514]120        }
[6027]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
[6038]137        $referenceSuggestion = array('startTime' => strtotime($params['startTime'] . ' ' . $schedulable['timezone']) . '000',
138            'endTime' => strtotime($params['endTime'] . ' ' . $schedulable['timezone']) . '000',
[6027]139            'allDay' => $params['allDay']
140        );
[6038]141
[6027]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']));
[5514]154        }
[6027]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
[7163]213    public static function _getAttendeeOrganizer($schedulable) {
214        foreach ($schedulable['participants'] as $v)
215            if ($v['isOrganizer'] == '1')
216                return $v;
217    }
218
[5947]219    /**
[6027]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) {
[7358]230        $delegatedParams = array();
[5947]231
[7358]232        $delegatedFrom = self::_getAttendeeById($partID['delegatedFrom'], $schedulable);
233        $delegatedParams['delegatedFrom'] = $delegatedFrom['user']['uid'];
[5947]234
[7358]235        self::participantCreated($partID['id'], $schedulable, STATUS_DELEGATED, $delegatedParams);
[6027]236
[7358]237        $delegatedTo = self::_getAttendeeById($partID['id'], $schedulable);
238        $delegatedParams['delegated'] = $delegatedTo['user']['uid'];
[6027]239
[7358]240        if($partID['isOrganizer'] == '0'){
241            self::participantStatusChange($partID['delegatedFrom'], $schedulable, $organizer, STATUS_DELEGATED, $delegatedParams);
242        }
[6027]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) {
[7358]256        $delegatedParams = array();
[6027]257
[7358]258        $delegated = self::_getAttendeeById($partID['id'], $schedulable);
259        $delegatedParams['delegated'] = $delegated['user']['uid'];
[6027]260
[7358]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);
[5947]278
[7358]279        $method = 'REQUEST';
280        $notificationType = 'Resposta Delegação';
281        $part = 'attendees';
282        self::mountStruture($partID['delegatedFrom'], $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType);
[5947]283
[7358]284        $data = array_merge($data, $delegatedParams);
[6027]285
[7358]286        self::sendMail($data, $ical, $part['user']['mail'], $subject, $schedulable['type'] == '1' ? 'notify_response_delegated_status_body' : 'notify_response_delegated_status_body_task');
[5514]287    }
288
[6331]289    public static function mountStruture(&$partID, &$schedulable, $type = false, &$data, &$subject, &$ical, &$part = false, &$method, &$notificationType, $regSet = false) {
[5947]290
[6027]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';
[6791]293            $ical = Controller::format(array('service' => 'iCal'), array($schedulable), array('method' => $method , 'compatible' => true ));
[6027]294            if ($regSet)
295                Config::regSet('ical://' . $schedulable['id'] . '/' . $method, $ical);
296        }
297        else
298            $ical = Config::regGet('ical://' . $schedulable['id'] . '/' . $method);
[6038]299
[6034]300        if (!is_numeric($schedulable['endTime']))
[6038]301            $schedulable['startTime'] = self::parseTimeDate($schedulable['startTime'], $schedulable['timezone']);
[5514]302
[6038]303        if (!is_numeric($schedulable['endTime'])) {
304            $schedulable['endTime'] = self::parseTimeDate($schedulable['endTime'], $schedulable['timezone']);
305
306            if ($schedulable['allDay'])
[7350]307                    $schedulable['endTime'] = $schedulable['endTime'] + 86400000;
[6034]308        }
[6038]309
[6027]310        $timezone = new DateTimeZone('UTC');
311        $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), $timezone);
312        $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), $timezone);
[6038]313
[6027]314        if (isset($schedulable['timezone'])) {
315            $sTime->setTimezone(new DateTimeZone($schedulable['timezone']));
316            $eTime->setTimezone(new DateTimeZone($schedulable['timezone']));
[5514]317        }
[6027]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'];
[6331]344                $partID = $part;
[6027]345                break;
346            case 'othersAttendees':
347                $data['participants'] = '<UL> ';
348                foreach ($schedulable['participants'] as $ii => $participant) {
[7163]349                    if ($participant['isOrganizer'] != '1')
[6027]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');
[6331]362        $subject['participant'] = (is_array($partID) && isset($partID['user']) )? $partID['user']['uid'] : Config::me('uid');
[6027]363    }
364
[5514]365    /**
[6027]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) {
[7350]376        $method = 'REQUEST';
377        $notificationType = 'Convite de Calendario';
378        $part = 'attendees';
[5947]379
[7350]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        }
[5947]385
[7350]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);
[5341]392    }
[6027]393
[5341]394    /**
[6027]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     */
[6331]404    public static function participantStatusChange(&$partID, &$schedulable, &$organizer, $type, $delegatedParams = false) {     
[6027]405        $method = 'REPLY';
[5947]406        $notificationType = 'Convite Aceito';
407        $part = 'me';
[5514]408
[6027]409        self::mountStruture($partID, $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType, true);
[5947]410
[6027]411        if ($delegatedParams) {
412            $data = array_merge($data, $delegatedParams);
[7350]413            $tplDelegated = $schedulable['type'] == '1' ? 'notify_delegated_status_body' : 'notify_delegated_status_body_task';
[5947]414        }
415
[6027]416        switch ($type) {
417            case STATUS_ACCEPTED:
[7350]418                $tpl = $delegatedParams ? $tplDelegated : ($schedulable['type'] == '1' ? 'notify_accept_body' : 'notify_accept_body_task');
[6027]419                $subject['notificationType'] = 'Convite Aceito';
420                break;
421            case STATUS_TENTATIVE:
[7350]422                $tpl = $delegatedParams ? $tplDelegated :($schedulable['type'] == '1' ? 'notify_attempt_body' : 'notify_attempt_body_task');
[6027]423                $subject['notificationType'] = 'Convite  aceito provisoriamente';
424                break;
425            case STATUS_CANCELLED:
[7350]426                $tpl = $delegatedParams ? $tplDelegated :($schedulable['type'] == '1' ? 'notify_reject_body' : 'notify_reject_body_task');
[6027]427                $subject['notificationType'] = 'Convite rejeitado';
428                break;
429            case STATUS_DELEGATED:
430                if ($delegatedParams)
431                    $data = array_merge($data, $delegatedParams);
[7350]432                $tpl = $schedulable['type'] == '1' ? 'notify_delegated_body' : 'notify_delegated_body_task';
[6027]433                $subject['notificationType'] = 'Convite delegado';
434                break;
435        }
[5341]436
[6331]437        self::sendMail($data, $ical, $organizer['user']['mail'], $subject, $tpl, $partID);
[5341]438    }
[6027]439
[5341]440    /**
[6027]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) {
[6791]451
452
453    $ical1['type'] = 'text/plain';
454    $ical1['source'] = $ical['compatible'];
[7174]455    $ical1['name'] = 'outlook2003.ics';
[6791]456    $ical2['source'] = $ical['ical'];
[6027]457        $ical2['type'] = 'text/calendar';
[7174]458        $ical2['name'] = 'calendar.ics';
[6791]459
460        unset($ical);
[6027]461        $mail['attachments'][] = $ical2;
[6791]462        $mail['attachments'][] = $ical1;
463        unset($ical1);
464        unset($ical2);
[6027]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);
[5341]471    }
[6027]472
[5341]473    /**
[6027]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'));
[8000]485
[6177]486        if ((Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))) {
[5947]487            $method = 'CANCEL';
488            $notificationType = 'Cancelamento de Calendario';
489            $part = 'othersAttendees';
[6027]490            self::mountStruture($uri['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType);
491
492            if (count($part) > 0)
[8000]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        }
[6027]503        }
[5341]504    }
[6027]505
[5341]506    /**
[6027]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'));
[8000]519    $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $participant['schedulable']) , false , array('deepness' => '2'));
[6027]520
[6177]521        if ((Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))) {
[5947]522            $method = 'CANCEL';
523            $notificationType = 'Cancelamento de Calendario';
[8000]524            $part = 'me';
525            self::mountStruture($schedulable['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType);
[5947]526
[8000]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);
[6027]534        }
[5341]535    }
[6027]536
[5341]537    /**
[6027]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     */
[6190]547    public function updateEvent(&$uri, $params, &$criteria, $original) {
[6027]548        $schedulableOld = Controller::read(array('concept' => 'schedulable', 'id' => $uri['id']), null, array('deepness' => '2'));
549        $schedulable = $schedulableOld;
550        $alt = false;
[5514]551
[6027]552        foreach ($params as $i => $v) //Verifica se ouve alteração no evento
553            if (isset($schedulableOld[$i]) && $schedulableOld[$i] != $v && $i != 'participants') {
[7163]554                $schedulable[$i] = $v;
555                $alt = true;
[6027]556            }
[6190]557
[7163]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);
[5341]563
[7163]564            $from = self::_getAttendeeOrganizer($schedulable);
565
566            if (isset($part) && $part && count($part) > 0)
[7350]567                self::sendMail($data, $ical, implode(',', $part), $subject, $schedulableOld['type'] == '1' ?  'notify_modify_body' : 'notify_modify_body_task', $from);
[7163]568        }
[5341]569    }
[6038]570
571    static private function parseTimeDate($time, $timezone) {
[7163]572        return strtotime($time . ' ' . $timezone) . '000';
[6038]573    }
574
[6036]575}
[6038]576
[5341]577?>
Note: See TracBrowser for help on using the repository browser.