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

Revision 6331, 42.7 KB checked in by acoutinho, 8 years ago (diff)

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

Line 
1<?php
2
3//Definindo Constantes
4require_once ROOTPATH . '/modules/calendar/constants.php';
5
6require_once ROOTPATH . '/modules/calendar/interceptors/Helpers.php';
7
8class DBMapping extends Helpers {
9
10    static function encodeCreateSchedulable(&$uri, &$params, &$criteria, $original) {
11        $params['type_id'] = EVENT_ID;
12
13        if (!is_numeric($params['startTime']))
14            $params['startTime'] = self::parseTimeDate($params['startTime'], $params['timezone']);
15
16        if (!is_numeric($params['endTime'])) {
17            $params['endTime'] = self::parseTimeDate($params['endTime'], $params['timezone']);
18
19            if ($params['allDay'])
20                $params['endTime'] = $params['endTime'] + 86400000;
21        }
22
23        $params['rangeEnd'] = $params['endTime'];
24        $params['rangeStart'] = $params['startTime'];
25
26        ///////////////////////////////////////////////////////////////////
27
28        $params['dtstamp'] = (isset($params['dtstamp'])) ? $params['dtstamp'] : time() . '000';
29        $params['lastUpdate'] = (isset($params['lastUpdate'])) ? $params['lastUpdate'] : time() . '000';
30        $params['type'] = EVENT_ID;
31        $params['uid'] = isset($params['uid']) ? $params['uid'] : self::_makeUid();
32    }
33
34    static function parseTimeDate($time, $timezone) {
35        return strtotime($time . ' ' . $timezone) . '000';
36    }
37
38     public function encodeCreateAlarm( &$uri , &$params , &$criteria , $original ){
39       
40        if(!isset($params['schedulable']) || !isset($params['rangeStart']) || !isset($params['rangeEnd']) )
41        {
42            $participant = Controller::read( array( 'concept' => 'participant' , 'id' => $params['participant'] ) , array('schedulable')  );
43
44            $params['schedulable'] = $participant['schedulable'];
45
46            $params['type'] = self::codeAlarmType($params['type']);
47
48            $params['offset'] = $params['time'] * 1000;
49
50            switch( strtolower($params['unit']) )
51            {
52                case 'd': $params['offset'] *= 24;
53                case 'h': $params['offset'] *= 60;
54                case 'm': $params['offset'] *= 60;
55            }
56        }
57    }
58
59    public function encodeCreateSuggestion(&$uri, &$params, &$criteria, $original) {
60        $params['dtstamp'] = (isset($params['dtstamp'])) ? $params['dtstamp'] : time() . '000';
61    }
62
63    public function encodeUpdateAlarm(&$uri, &$params, &$criteria, $original) {
64        if (isset($params['type']))
65            $params['type'] = self::codeAlarmType($params['type']);
66    }
67
68    public function encodeCreateAttachment(&$uri, &$params, &$criteria, $original) {
69
70        if (!isset($params['source']))
71            return false;
72
73        if (isset($_FILES[$params['source']]))
74            if (isset($params['id']))
75                $params = array_merge($_FILES[$params['source']], array('id' => $params['id']));
76            else
77                $params = $_FILES[$params['source']];
78
79        if (isset($params['owner']))
80            $params['owner'] = Config::me('uidNumber');
81    }
82
83///////////////////////////////////////////////////////////////////////////////////////////////////////////////
84
85    public function encodeSignatureAlarmType(&$uri, &$params, &$criteria, $original) {
86        $params['type'] = self::codeAlarmType($params['type']);
87    }
88
89    public function insertOwnerLink(&$uri, &$params, &$criteria, $original) {
90        $params['owner'] = Config::me('uidNumber');
91    }
92
93    public function encodeServiceUser(&$uri, &$params, &$criteria, $original) {
94        if (isset($params['isExternal']) && $params['isExternal'] == '1')
95            $uri['service'] = 'PostgreSQL';
96    }
97
98    public function prepareRepeat(&$uri, &$params, &$criteria, $original) {
99        if (isset($params['startTime']) || isset($params['endTime'])) {
100           
101            if(!isset($params['schedulable']))
102                $params = array_merge($params , Controller::read(array('concept' => 'repeat', 'id' => $params['id']), array('schedulable')));
103 
104            $timezone = Controller::read(array('concept' => 'schedulable', 'id' => $params['schedulable']), array('timezone'));
105
106            if (isset($params['startTime']))
107                $params['startTime'] = self::parseTimeDate($params['startTime'], $timezone['timezone']);
108            if (isset($params['endTime']))
109                $params['endTime'] = self::parseTimeDate($params['endTime'], $timezone['timezone']);
110        }
111    }
112
113    public function findSchedulable(&$uri, &$params, &$criteria, $original) {
114        if (isset($criteria['filter'][2][1]) && $criteria['filter'][2][1] == 'calendar') {
115
116            $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", '
117                .'calendar_object.dtstart as "startTime", calendar_object.summary as "summary", '
118                .'calendar_object.description as "description", calendar_object.dtend as "endTime" , '
119                .'calendar_object.location as "location", calendar_object.allday as "allDay", '
120                .'calendar_object.transp as "transparent", calendar_object.class_id as "class", '
121                .'calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart", '
122                .'calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", '
123                .'calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence", '
124                .'calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as '
125                .'calendar FROM calendar_to_calendar_object , calendar_object '
126                .'WHERE ( calendar_to_calendar_object.calendar_id IN (\'' . implode('\',\'', $criteria['filter'][2][2]) . '\')) '
127                .'AND calendar_to_calendar_object.calendar_object_id = calendar_object.id ';   
128           
129            if(isset($criteria['searchEvent']) && $criteria['searchEvent']){
130                $where = 'AND (((upper("summary") like upper(\'%'.$criteria['filter'][1][1][2].'%\') OR upper("description") like upper(\'%'.$criteria['filter'][1][2][2].'%\')))) ORDER BY dtstart LIMIT '.$criteria['limit'].'  OFFSET '.$criteria['offset'].' ';
131                $params = Controller::service('PostgreSQL')->execResultSql($sql.$where);
132
133            }else{
134                $start = array( $criteria['filter'][1][1][1][2] , $criteria['filter'][1][2][1][2], $criteria['filter'][1][3][1][2] );
135                $end = array( $criteria['filter'][1][1][2][2] , $criteria['filter'][1][2][2][2], $criteria['filter'][1][3][2][2] );
136
137                $ids = array();
138                $occ = array();
139
140                if ($occurrences = self::checkOccurrences($start[0], $end[0], $criteria['filter'][2][2]))
141                    foreach ($occurrences as $id => $occurrence) {
142                        $ids[] = $id;
143                        $occ[] = $occurrence;
144                    }   
145
146                $where = 'AND ((range_end >= \'' . $start[0] . '\' AND range_end <= \'' . $end[0] . '\') OR '
147                        .'(range_start >= \'' . $start[1] . '\' AND range_start <= \'' . $end[1] . '\') OR '
148                        .'(range_start <= \'' . $start[2] . '\' AND range_end >= \'' . $end[2] . '\')) '
149                .(!empty($ids) ? ' ' .'AND calendar_object.id NOT IN (\'' . implode('\',\'', $ids) . '\') ' : ' ');
150
151
152                $params = Controller::service('PostgreSQL')->execResultSql($sql.$where);
153                $params = array_merge($params, $occ);           
154            }
155            $params = self::deepnessFindEvent($uri, $params, $criteria, $original);
156            return false;
157        }
158    }
159
160    public function deepnessFindRepeatOccurrence(&$uri, &$result, &$criteria, $original) {
161
162        if (!isset($criteria['deepness']) || $criteria['deepness'] == 0)
163            return;
164
165        foreach ($result as $i => &$res)
166            if (isset($res['repeat']))
167                $res['repeat'] = Controller::read(array('concept' => 'repeat', 'id' => $res['repeat']), false, array('deepness' => intval($criteria['deepness']) - 1));
168    }
169
170    public function deepnessRepeat(&$uri, &$result, &$criteria, $original) {
171
172        if (!isset($criteria['deepness']) || $criteria['deepness'] == 0)
173            return;
174
175        $result['schedulable'] = Controller::find(array('concept' => 'schedulable'), false, array('filter' => array('=', 'id', $result['schedulable']), 'deepness' => intval($criteria['deepness']) - 1));
176        $result['schedulable'] = $result['schedulable'][0];
177    }
178
179    public function saveOccurrences(&$uri, &$result, &$criteria, $original) {
180        $ranges = Controller::find(array('concept' => 'repeatRange'), array('rangeStart', 'rangeEnd'), array('filter' => array('=', 'user', Config::me("uidNumber"))));
181
182        if (!is_array($ranges) || !isset($ranges[0]['rangeStart']) || !isset($ranges[0]['rangeEnd']))
183            return;
184
185        if (isset($result['id']))
186            $id = $result['id'];
187        else
188            $id = $uri['id'];
189
190        $repeat = Controller::read(array('concept' => 'repeat', 'id' => $id));
191
192        unset($repeat['schedulable']);
193        unset($repeat['id']);
194
195        $exceptions = array();
196
197        if (isset($original['properties']['exceptions'])) {
198            $exceptions = explode(',', $original['properties']['exceptions']);
199            unset($repeat['exceptions']);
200        }
201
202        $lastExceptions = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('AND', array('=', 'repeat', $id), array('=', 'exception', 1))));
203
204        //Recurepa as execeções anteriores caso exista
205        if (isset($lastExceptions) && count($lastExceptions) && $lastExceptions)
206            foreach ($lastExceptions as $key => $value)
207                array_push($exceptions, $lastExceptions[$key]['occurrence']);
208
209        $params = array_diff(self::decodeRepeat($repeat, $ranges[0]['rangeStart'], $ranges[0]['rangeEnd']), $exceptions);
210
211        Controller::delete(array('concept' => 'repeatOccurrence'), false, array('filter' => array('=', 'repeat', $id)));
212
213        if (!empty($params))
214            Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,exception,occurrence)VALUES('" . $id . "','0','" . implode("'),('" . $id . "','0','", $params) . "')" . ( empty($exceptions) ? "" : ",('" . $id . "','1','" . implode("'),('" . $id . "','1','", $exceptions) . "')" ));
215    }
216
217    public function checkOccurrences($start, $end, $calendarIds) {
218
219        $ranges = Controller::find(array('concept' => 'repeatRange'), array('rangeStart', 'rangeEnd'), array('filter' => array('=', 'user', Config::me("uidNumber"))));
220        $ranges = $ranges[0];
221
222        $origStart = $start;
223        $origEnd = $end;
224
225        if ($initialized = (isset($ranges['rangeStart']) && isset($ranges['rangeEnd']))) {
226            if ($ranges['rangeStart'] <= $start)
227                $start = false;
228            if ($ranges['rangeEnd'] >= $end)
229                $end = false;
230        }
231
232        $repeats = self::findRepeats($calendarIds);
233        if (!is_array($repeats) || empty($repeats))
234            return( false );
235
236        $result = array();
237        $ids = array();
238
239        foreach ($repeats as $repeat) {
240            $ids[] = $id = $repeat['id'];
241            unset($repeat['id']);
242
243            if (!isset($result[$id]))
244                $result[$id] = !$initialized ? array($repeat['startTime']) : array();
245
246            if (!$initialized)
247                $result[$id] = array_merge($result[$id], self::decodeRepeat($repeat, $start, $end));
248            else {
249                if ($start)
250                    $result[$id] = array_merge($result[$id], self::decodeRepeat($repeat, $start, $ranges['rangeStart']));
251
252                if ($end)
253                    $result[$id] = array_merge($result[$id], self::decodeRepeat($repeat, $ranges['rangeEnd'], $end));
254            }
255
256            if (empty($result[$id]))
257                unset($result[$id]);
258        }
259
260        if ($start || $end) {
261            Controller::begin(array('service' => 'PostgreSQL'));
262
263            foreach ($result as $id => $res)
264                Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,occurrence)VALUES('" . $id . "','" . implode("'),('" . $id . "', '", $res) . "')");
265
266            $data = array();
267
268            if ($start)
269                $data['rangeStart'] = $start;
270
271            if ($end)
272                $data['rangeEnd'] = $end;
273
274            if (!$initialized)
275                $data['user'] = Config::me('uidNumber');
276
277            Controller::call(( $initialized ? 'replace' : 'create'), array('concept' => 'repeatRange'), $data, array('filter' => array('=', 'user', Config::me('uidNumber'))));
278
279            Controller::commit(array('service' => 'PostgreSQL'));
280        }
281
282//      $return = Controller::find( array( 'concept' => 'repeatOccurrence' ), false, array( 'filter' => array( 'AND', array( '>=', 'occurrence', $origStart ), array( '<=', 'occurrence', $origEnd ), array( 'IN', 'repeat', $ids ) ), 'deepness' => $deep ) );
283
284        $return = Controller::service('PostgreSQL')->execResultSql('SELECT calendar_repeat_occurrence.occurrence as "occurrence", calendar_repeat.object_id as "schedulable" FROM calendar_repeat, calendar_repeat_occurrence WHERE calendar_repeat_occurrence.occurrence >= \'' . $origStart . '\' AND calendar_repeat_occurrence.occurrence <= \'' . $origEnd . '\' AND calendar_repeat_occurrence.repeat_id IN (\'' . implode('\',\'', $ids) . '\') AND calendar_repeat.id = calendar_repeat_occurrence.repeat_id AND calendar_repeat_occurrence.exception != 1');
285
286        if (!is_array($return))
287            return( false );
288
289        $result = array();
290        $params = array();
291
292        foreach ($return as $ret) {
293            $currentId = $ret['schedulable'];
294
295            if (!isset($result[$currentId])) {
296                $result[$currentId] = Controller::read(array('concept' => 'schedulable', 'id' => $currentId));
297                $result[$currentId]['occurrences'] = array();
298
299                $calendarToCalendarObj = self::schedulable2calendarToObject($currentId);
300                $result[$currentId]['calendar'] = $calendarToCalendarObj[0]['calendar_id'];
301            }
302
303            $result[$currentId]['occurrences'][] = $ret['occurrence'];
304        }
305
306        return( $result );
307    }
308
309    public static function findRepeats($ids) {
310        return Controller::service('PostgreSQL')->execResultSql('SELECT calendar_repeat.wkst as "wkst", calendar_repeat.byweekno as "byweekno", calendar_repeat.byminute as "byminute", calendar_repeat.bysecond as "bysecond", calendar_repeat.byyearday as "byyearday", calendar_repeat.bymonthday as "bymonthday", calendar_repeat.bysetpos as "bysetpos", calendar_repeat.byday as "byday", calendar_repeat.byhour as "byhour", calendar_repeat.interval as "interval", calendar_repeat.frequency as "frequency", calendar_repeat.until as "endTime", calendar_repeat.id as "id", calendar_repeat.count as "count", calendar_repeat.dtstart as "startTime" FROM calendar_repeat, calendar_to_calendar_object WHERE calendar_repeat.object_id = calendar_to_calendar_object.calendar_object_id AND calendar_to_calendar_object.calendar_id IN (\'' . implode('\',\'', $ids) . '\')');
311    }
312
313//HELPERS
314    public static function decodeRepeat($repeat, $start, $end) {
315
316        date_default_timezone_set('UTC');
317
318        require_once ROOTPATH . '/plugins/when/When.php';
319
320        $r = new When();
321
322        if ($repeat['frequency'] === 'none')
323            return( array() );
324
325        //Nao deve ser usando o horário da repeticao pois nela contem apenas o dias,
326        //deve se recuperar o horário do evento para um correto calculo.
327        if (max($start, $repeat['startTime']) != $repeat['startTime']) {
328            $time = new DateTime('@' . (int) ( $repeat['startTime'] / 1000 ), new DateTimeZone('UTC'));
329
330            $hoursOcurrence = new DateTime('@' . (int) ( $start / 1000 ), new DateTimeZone('UTC'));
331            $hoursOcurrence = $hoursOcurrence->format('H');
332
333            $diffTime = ((($time->format('H') - $hoursOcurrence) * (3600000)) + ($time->format('i') * (60000)));
334            $start = new DateTime('@' . (int) ( ( $start + $diffTime ) / 1000 ), new DateTimeZone('UTC'));
335        }else
336            $start = new DateTime('@' . (int) ( max($start, $repeat['startTime']) / 1000 ), new DateTimeZone('UTC'));
337
338        foreach ($repeat as $rule => $value) {
339            if (!isset($value) || !$value || $value === "0")
340                continue;
341
342            switch (strtolower($rule)) {
343                case "starttime": break;
344                case "frequency":
345                    $r->recur($start, $value);
346                    break;
347                case "endtime":
348                    $r->until(new DateTime('@' . (int) ( $value / 1000 )));
349                    break;
350                case "count": case "interval": case "wkst":
351                    $r->$rule($value);
352                    break;
353                default :
354                    $r->$rule(!is_array($value) ? explode(',', $value) : $value );
355                    break;
356            }
357        }
358
359        $return = array();
360
361        while ($result = $r->next()) {
362            $u = $result->format('U') * 1000;
363
364            if ($u > $end) //data da repetição atual maior que a data final da busca do usuario ?
365                break;
366
367            $return[] = $u;
368        }
369
370        return( $return );
371    }
372
373///////////////////////////////////////////////////////////////////////////////////////////////////////////////
374
375    public function updateCalendar(&$uri, &$params, &$criteria, $original) {       
376        if (isset($params['calendar'])) {
377            if(isset($params['lastCalendar'])){
378                $calendarObjects = self::referenceCalendarToObject($uri['id'], $params['lastCalendar']);
379                $params2['calendar'] = $params['calendar'];
380            }else{
381                $calendarObjects = self::schedulable2calendarToObject($uri['id']);
382                $params2['calendar'] = $params['calendar'];
383            }
384           
385            foreach ($calendarObjects as $calendarObject)
386                Controller::update(array('concept' => 'calendarToSchedulable', 'id' => $calendarObject['calendar_to_calendar_object']), $params2);
387
388            unset($params['calendar']);
389
390            if (count($params) < 1)
391                return false;
392        }
393    }
394
395//Encode Update
396
397    public function encodeUpdateSchedulable(&$uri, &$params, &$criteria, $original) {
398
399        $event = Controller::read(array('concept' => 'schedulable', 'id' => $params['id']));
400       
401        if (isset($params['startTime'])) {
402
403            if (!is_numeric($params['startTime']))
404                $params['startTime'] = self::parseTimeDate($params['startTime'], $event['timezone']);
405
406            $params['rangeStart'] = $params['startTime'];
407        }if (isset($params['endTime'])) {
408
409            if (!is_numeric($params['endTime'])) {
410                $params['endTime'] = self::parseTimeDate($params['endTime'], $event['timezone']);
411
412            if ((isset($params['allDay']) && $params['allDay']) || ( !isset($params['allDay']) && $event['allDay']))
413                $params['endTime'] = $params['endTime'] + 86400000;
414            }
415            $params['rangeEnd'] = $params['endTime'];
416        }
417    }
418
419    static function putEvent(&$uri, &$result, &$criteria, $original) {
420        if (Config::module('useCaldav', 'expressoCalendar')) { //Ignorar Put dos eventos ja vindos do caldav
421            require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
422
423            $eventID = (isset($result['id'])) ? $result['id'] : $uri['id'];
424            $event = Controller::read(array('concept' => 'schedulable', 'id' => $eventID));
425
426            $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $eventID)));
427
428            if (is_array($participants) && count($participants) > 0)
429                foreach ($participants as $ii => $vv) {
430                    if ($vv['isExternal'] == 1)
431                        $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL'));
432                    else
433                        $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user']));
434                }
435
436            $event['URI']['concept'] = 'schedulable';
437            $event['participants'] = $participants;
438
439            $ical = Controller::format(array('service' => 'iCal'), array($event));
440            $calendars = self::schedulable2calendarToObject($original['properties']['id']); //Busca os calendarios do usuario logado que contenham o evento
441            if (is_array($calendars))
442                foreach ($calendars as $calendar)
443                    DAViCalAdapter::putIcal($ical, array('uid' => $event['uid'], 'location' => $calendar['calendar_location']));
444        }
445    }
446
447///////////////////////////////////////////////////////////////////////////////////////////////////////////////
448
449    public function verifyCalendarLocation(&$uri, &$params, &$criteria, $original) {
450        if (!isset($params['location']))
451            $params['location'] = Config::me('uid') . '/' . $params['name'];
452    }
453
454    //TODO: Remover apos suporte a ManytoMany na api
455    public function createCalendarToSchedulable(&$uri, &$result, &$criteria, $original) {
456
457        Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $original['properties']['calendar'], 'schedulable' => $result['id']));
458    }
459
460    public function createCreateSchedulableToAttachment(&$uri, &$params, &$criteria, $original) {
461        if (array_key_exists('attachments', $original['properties']))
462            foreach ($original['properties']['attachments'] as $key => $value) {
463                if (isset($params['id']))
464                    Controller::create(array('concept' => 'schedulableToAttachment'), array('attachment' => $value['attachment'], 'schedulable' => $params['id']));
465            }
466    }
467
468    public function deepnessFindCalendarShared(&$uri, &$result, &$criteria, $original) {
469        if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != '0' && count($result) > 0) {
470
471            $calendarIds = array();
472            foreach ($result as $key => $value)
473                array_push($calendarIds, $value['calendar']);
474
475            $calendar = Controller::find(array('concept' => 'calendar'), false, array('filter' => array('AND', array('IN', 'id', $calendarIds), $original['criteria']['filter'])));
476
477            if ($calendar && count($calendar) > 0){
478                $newResult = array();
479                foreach ($calendar as $key => $value) {
480                    foreach ($result as $k => $r) {
481
482                        if ($r['calendar'] == $value['id']) {
483                            $r['calendar'] = $value;
484                            array_push($newResult, $r);
485                        }
486                    }
487                }
488
489                foreach ($newResult as $key => &$value) {
490                    if ($value['user'] != 0) {
491                        $user = $value['user'];
492                        $value['user'] = Controller::read(array('concept' => 'user', 'id' => $user));
493
494                        if (!$value['user'])
495                            $value['user'] = Controller::read(array('concept' => 'group', 'id' => $user));
496                    }
497                }
498
499                $result = $newResult;
500            }else
501                $result = '';
502        }
503    }
504
505    //TODO: Remover apos suporte a deepness na api
506    public function deepnessFindEvent(&$uri, &$result, &$criteria, $original) {
507        if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) {
508            $Time = new DateTime('now', new DateTimeZone('UTC'));
509            $DayLigth = array();
510            foreach ($result as $i => $v) {
511
512                if (!isset($currentTimezone) || $currentTimezone != $original['criteria']['timezones'][$v['calendar']]) {
513                    $currentTimezone = isset($original['criteria']['timezones'][$v['calendar']]) ? $original['criteria']['timezones'][$v['calendar']] : $v['timezone'];
514                    $Time->setTimezone(new DateTimeZone($currentTimezone));
515                }
516
517                $Time->setTimestamp((int) ($v['startTime'] / 1000));
518                $DayLigth['calendar']['startTime'] = $Time->format('I') ? 1 : 0;
519
520                $Time->setTimestamp((int) ($v['endTime'] / 1000));
521                $DayLigth['calendar']['endTime'] = $Time->format('I') ? 1 : 0;
522
523                if ($currentTimezone != $v['timezone']) {
524                    $currentTimezone = $v['timezone'];
525                    $Time->setTimezone(new DateTimeZone($v['timezone']));
526
527                    $Time->setTimestamp((int) ($v['startTime'] / 1000));
528                    $DayLigth['event']['startTime'] = $Time->format('I') ? 1 : 0;
529
530                    $Time->setTimestamp((int) ($v['endTime'] / 1000));
531                    $DayLigth['event']['endTime'] = $Time->format('I') ? 1 : 0;
532                }else
533                    $DayLigth['event'] = $DayLigth['calendar'];
534
535
536                $result[$i]['DayLigth'] = $DayLigth;
537
538                if (isset($v['id'])) {
539                    $result[$i]['participants'] = Controller::find( array( 'concept' => 'participant' ) , false ,array( 'filter' => array('=', 'schedulable'  ,  $v['id']),'deepness' => $original['criteria']['deepness'] - 1 ));
540
541                    $attachmentRelation = Controller::find(array('concept' => 'schedulableToAttachment'), false, array('filter' => array('=', 'schedulable', $v['id'])));
542                    if (is_array($attachmentRelation)) {
543                        $attachments = array();
544                        foreach ($attachmentRelation as $key => $value)
545                            if (isset($value['attachment']) || !!$value['attachment'])
546                                $attachments[$key] = $value['attachment'];
547                        //Pega os anexos sem source
548                        $result[$i]['attachments'] = Controller::find(array('concept' => 'attachment'), array('id', 'name', 'type', 'size'), array('filter' => array('IN', 'id', $attachments)));
549                    }
550
551                    $repeat = Controller::find(array('concept' => 'repeat'), false, array('filter' => array('=', 'schedulable', $v['id'])));
552
553                    unset($result[$i]['repeat']);
554
555                    if (is_array($repeat))
556                        $result[$i]['repeat'] = $repeat[0];
557                }
558            }
559        }
560
561        return $result;
562    }
563
564//TODO: Remover apos suporte a deepness na api
565    public function deepnessReadParticipant( &$uri , &$result , &$criteria , $original ){
566       
567       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0)
568       {
569            if(isset($result['id']) && isset($result['user']))
570            {
571                $result['user'] = Controller::read( array( 'concept' => 'user' , 'id' => $result['user'] , 'service' => ( $result['isExternal'] == 1 ? 'PostgreSQL' : 'OpenLDAP' ) ) );
572
573                if($result['user']['id'] == Config::me('uidNumber'))
574                  $result['alarms'] = Controller::find( array( 'concept' => 'alarm' ) , null , array('filter' => array('=', 'participant' ,$result['id'] ) ) );
575            }
576       }
577       
578     
579       
580   }
581
582    //TODO: Remover apos suporte a deepness na api
583    public function deepnessReadEvent( &$uri , &$result , &$criteria , $original ){             
584   
585       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0)
586       {
587            if(isset($result['id']))
588            {
589                $result['participants'] = Controller::find( array( 'concept' => 'participant' ) , false ,array( 'filter' => array('=' ,  'schedulable' ,  $result['id']), 'deepness' => $original['criteria']['deepness'] - 1) );
590
591                $repeat =  Controller::find( array( 'concept' => 'repeat' ), false, array( 'filter' => array( '=', 'schedulable', $result['id'] ) ) );
592
593                if(is_array($repeat))
594                    $result['repeat'] = $repeat[0];
595            }
596           
597       }
598   }
599   
600    //TODO: Remover apos suporte a deepness na api
601    public function deepnessFindParticipant( &$uri , &$result , &$criteria , $original ){
602       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0)
603       {
604           foreach ($result as $i => &$v)
605           {
606                self::deepnessReadParticipant( $uri, $v, $criteria, $original );
607           }
608       } 
609       
610   }
611
612    //TODO: Remover apos suporte a deepness na api
613    public function deepnessReadCalendarSignature(&$uri, &$result, &$criteria, $original) {
614
615        if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0)
616            if (isset($result['calendar'])) {
617                $result['calendar'] = Controller::read(array('concept' => 'calendar', 'id' => $result['calendar']));
618                $result['defaultAlarms'] = Controller::find(array('concept' => 'calendarSignatureAlarm'), false, array('filter' => array('=', 'calendarSignature', $result['id'])));
619            }
620    }
621
622    //TODO: Remover apos suporte a deepness na api
623    public function deepnessFindCalendarSignature(&$uri, &$result, &$criteria, $original) {
624
625        if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) {
626            foreach ($result as $i => $v) {
627                if (isset($v['calendar'])) {
628                    $result[$i]['calendar'] = Controller::read(array('concept' => 'calendar', 'id' => $v['calendar']), false, false);
629                    $result[$i]['defaultAlarms'] = Controller::find(array('concept' => 'calendarSignatureAlarm'), false, array('filter' => array('=', 'calendarSignature', $v['id'])));
630                    //Caso não seja o dono da agenda retorna o objeto permission com as acls
631                    if ($result[$i]['isOwner'] == 0) {
632                        $permission = Controller::find(array('concept' => 'calendarToPermission'), false, array('filter' => array('AND', array('=', 'calendar', $v['calendar']), array('=', 'user', Config::me('uidNumber')))));
633
634                        if (!is_array($permission) || !$permission) {
635
636                            $permission = Controller::find(array('concept' => 'calendarToPermission'), false, array('filter' => array('AND', array('=', 'calendar', $v['calendar']), array('=', 'type', '1'))));
637                        }
638                        $result[$i]['permission'] = $permission[0];
639                    }
640                }
641                //TODO - Padronizar retorno do deepness
642                if (isset($v['user']))
643                    $result[$i]['user'] = Controller::read(array('concept' => 'user', 'id' => $v['user']), false, false);
644            }
645        }
646    }
647
648//Decode Find       
649    public function decodeFindConcept(&$uri, &$result, &$criteria, $original) {
650        if ($result && is_array($result)) {
651            $m = array_flip(self::${$uri['concept'] . 'Map'});
652            $new = array();
653            foreach ($result as $i => $v)
654                $new[$i] = self::parseConcept($result[$i], $m);
655
656
657            $result = $new;
658        }
659    }
660
661    public function decodeFindSchedulable(&$uri, &$result, &$criteria, $original) {
662        if ($result && is_array($result)) {
663            $m = array_flip(self::${$uri['concept'] . 'Map'});
664            $m['calendar_id'] = 'calendar';
665            $new = array();
666            foreach ($result as $i => $v)
667                $new[$i] = self::parseConcept($result[$i], $m);
668
669
670            $result = $new;
671        }
672    }
673
674    public function decodeFindAttachment(&$uri, &$result, &$criteria, $original) {
675        if (isset($result))
676            foreach ($result as $key => &$value)
677                $value['source'] = base64_decode($value['source']);
678    }
679
680    public function decodeSignatureAlarmType(&$uri, &$result, &$criteria, $original) {
681        if (is_array($result))
682            foreach ($result as &$param)
683                if (isset($param['type']))
684                    $param['type'] = self::decodeAlarmType($param['type']);
685    }
686
687/////////////////////////////////////////////////////////////////////////
688
689    static function dayAlarm( &$uri , &$params , &$criteria , $original ) {     
690        if(isset($criteria['filter'][1]) && $criteria['filter'][1] == 'date')
691        {
692            $target = $criteria['filter'][2];
693
694            $params = array();
695
696            $al = Controller::service('PostgreSQL')->execSql("SELECT distinct co.id as \"id\", co.cal_uid as \"uid\", co.type_id as \"type\", co.dtstart as \"startTime\", co.summary as \"summary\", co.description as \"description\", co.dtend as \"endTime\", co.location as \"location\", co.allday as \"allDay\", co.transp as transparent, co.class_id as class, ".
697                "co.range_start as \"rangeStart\", co.range_end as \"rangeEnd\", co.last_update as \"lastUpdate\", co.dtstamp as \"dtstamp\", co.sequence as \"sequence\", co.tzid as \"timezone\", CASE WHEN rep.object_id = co.id THEN occ.occurrence - al.alarm_offset ELSE co.dtstart - al.alarm_offset END as \"sendTime\", ".
698                "al.unit as \"unit\", al.time as \"time\" FROM calendar_alarm as al, calendar_object as co, calendar_repeat as rep, calendar_repeat_occurrence as occ, calendar_participant as part WHERE ".
699                "al.action_id = '".ALARM_ALERT."' AND al.sent = '0' AND ( (al.participant_id = part.id) AND (part.user_info_id = '". Config::me('uidNumber') ."') ) AND part.object_id = co.id AND ".
700                "CASE WHEN rep.object_id = co.id ".
701                "THEN rep.id = occ.repeat_id AND occ.occurrence - al.alarm_offset >= '$target' AND occ.occurrence - al.alarm_offset <= '".( $target + 86400000)."' ".
702                "ELSE (co.range_start - al.alarm_offset) >= '$target' AND (co.range_start - al.alarm_offset) <= '".( $target + 86400000)."' END");
703           
704            if(is_array($al))
705              foreach( $al as $v )
706                $params[] = array('schedulable' =>  $v);
707             
708            else
709              $params = false;
710 
711            return false;
712        }
713    }
714
715    public function deleteSchedulable(&$uri, &$params, &$criteria, $original) {
716
717        if (Config::module('useCaldav', 'expressoCalendar'))
718            require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
719       
720        if(isset($criteria['filter']) && $criteria['filter'] && isset($criteria['filter'][1][2])){
721            $idSchedulable = $criteria['filter'][1][2];
722            $idCalendar = $criteria['filter'][2][2];
723           
724            if(!self::ownerSchedulable($idSchedulable, $criteria['filter'][3][2])){
725                $isPermissionFromOwner = self::permissionFromCalendarSignature($idCalendar, $idSchedulable);
726               
727                if($isPermissionFromOwner){
728                    Controller::delete(array('concept' => 'schedulable', 'id' => $idSchedulable));
729
730                }else{
731                    $calendarsToSchedulable = self::schedulable2calendarToObject($idSchedulable);
732
733                    foreach($calendarsToSchedulable as $value)
734                        if($value['calendar_id'] == $idCalendar){   
735
736                            $participant = Controller::read(array('concept' => 'participant'), array('id'), array('filter' =>
737                                array('AND',
738                                    array('=', 'user', $criteria['filter'][3][2]),
739                                    array('=', 'schedulable', $idSchedulable)
740                                )));
741
742                            Controller::call(('update'), array('concept' => 'participant', 'id' => $participant[0]['id']), array('status' => STATUS_CANCELLED));
743                            Controller::delete(array('concept' => 'calendarToSchedulable', 'id' => $value['calendar_to_calendar_object']));
744                            break;
745                        }
746                }
747                return false;
748            }
749
750            $uri['id'] = $idSchedulable;
751        }
752
753        $calendarsToSchedulable = self::schedulable2calendarToObject($uri['id']);
754
755        if (!self::ownerSchedulable($uri['id'], Config::me('uidNumber')) && !self::isAllowDeleteInCalendar($calendarsToSchedulable[0]['calendar_id'])) {
756
757            foreach ($calendarsToSchedulable as $i => $v) {
758                Controller::delete(array('concept' => 'calendarToSchedulable', 'id' => $v['calendar_to_calendar_object']));
759
760                if (Config::module('useCaldav', 'expressoCalendar'))
761                    DAViCalAdapter::deleteEvent($uri['id'], array('location' => $v['calendar_location']));
762            }
763
764            /* Seta o participante como rejeitado */
765            $participant = Controller::read(array('concept' => 'participant'), array('id'), array('filter' =>
766                array('AND',
767                    array('=', 'user', Config::me('uidNumber')),
768                    array('=', 'schedulable', $idSchedulable)
769                )));
770
771            Controller::call(('update'), array('concept' => 'participant', 'id' => $participant[0]['id']), array('status' => STATUS_CANCELLED));
772
773            return false; /* Mata o restante da execução */
774        }
775
776        if (Config::module('useCaldav', 'expressoCalendar'))
777            foreach ($calendarsToSchedulable as $i => $v)
778                DAViCalAdapter::deleteEvent($uri['id'], array('location' => $v['calendar_location']));
779    }
780
781    public function deleteCalendarToPermissionDependences(&$uri, &$params, &$criteria, $original) {
782        $permission = Controller::read($uri, array('user', 'calendar'));
783
784        $calendarSignature = Controller::find(array('concept' => 'calendarSignature'), array('id'), array('filter' => array('AND', array('=', 'calendar', $permission['calendar']), array('=', 'user', $permission['user']), array('=', 'isOwner', '0'))));
785
786        if ($calendarSignature)
787            Controller::delete(array('concept' => 'calendarSignature', 'id' => $calendarSignature[0]['id']));
788    }
789
790    public function deleteCalendarSignatureDependences(&$uri, &$params, &$criteria, $original) {
791        $signature = Controller::read($uri, array('isOwner', 'calendar'));
792
793        if ($signature['isOwner'] == '1') {
794            $calendarToSchedulables = Controller::find(array('concept' => 'calendarToSchedulable'), null, array('filter' => array('=', 'calendar', $signature['calendar'])));
795
796            $schedulables = array();
797            if (is_array($calendarToSchedulables))
798                foreach ($calendarToSchedulables as $key => $calendarToSchedulable)
799                    $schedulables[] = $calendarToSchedulable['schedulable'];
800
801            if (!empty($schedulables))
802                        Controller::deleteALL(array('concept' => 'schedulable'), null, array('filter' => array('IN', 'id', $schedulables)));
803
804            Controller::delete(array('concept' => 'calendar', 'id' => $signature['calendar']));
805               
806                $permissions = Controller::find(array('concept' => 'calendarToPermission'), array('id'), array('filter' => array('=', 'calendar', $signature['calendar'])));
807
808               
809               
810                if($permissions && count($permissions) > 0){
811                        $ids = array();
812                        foreach($permissions as $key => $value)
813                                array_push($ids, $value['id']);
814               
815                        Controller::deleteALL(array('concept' => 'calendarToPermission'), null, array('filter' => array('IN', 'id', $ids)));
816                       
817                }
818               
819               
820        }
821    }
822
823    public function deleteAttachmentDependences(&$uri, &$params, &$criteria, $original) {
824
825        if (isset($original['URI']['id']))
826            Controller::delete(array('concept' => 'schedulableToAttachment', null, array('filter' => array('=', 'attachment', $original['URI']['id']))));
827    }
828
829    public function createDefaultSignature(&$uri, &$result, &$criteria, $original) {
830
831        //Caso uma busca não retorne nenhum resultado e foi buscado pelas assinaturas do usuario logado apenas
832        $isValidSignature = false;
833
834        //Veirifica pois o usuário pode ter varias assinaturas mas não ser dona de nenhuma
835        if (count($result) > 0) {
836            foreach ($result as $value) {
837                if (isset($value['isOwner']) && $value['isOwner'] != 0)
838                    $isValidSignature = true;
839            }
840        }
841
842        if (!$isValidSignature &&
843                ( $original['criteria']['filter'][1][0] == '=' &&
844                $original['criteria']['filter'][1][1] == 'user' &&
845                $original['criteria']['filter'][1][2] == $_SESSION['phpgw_session']['account_id']
846                )) {
847
848            if (Config::module('useCaldav', 'expressoCalendar')) {
849                require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
850
851                $calendario = DAViCalAdapter::findCalendars();
852            }
853
854            if (Config::module('useCaldav', 'expressoCalendar') && is_array($calendario) && count($calendario) > 0) {
855                foreach ($calendario as $i => $v) {
856
857                    $urlA = explode('/', $v->url);
858                    $name = isset($v->displayname) ? $v->displayname : $urlA[(count($urlA) - 2)];
859                    $cal = array('name' => $name,
860                        'description' => isset($v->description) ? $v->description : $name,
861                        'timezone' => isset($v->timezone) ? $v->timezone : (date_default_timezone_get()) ? date_default_timezone_get() : 'America/Sao_Paulo',
862                        'dtstamp' => time() . '000',
863                        'location' => $urlA[(count($urlA) - 3)] . '/' . $urlA[(count($urlA) - 2)]
864                    );
865
866                    $calCreated = Controller::create(array('concept' => 'calendar'), $cal);
867
868
869
870                    $sig = array('user' => $_SESSION['wallet']['user']['uidNumber'],
871                        'calendar' => $calCreated['id'],
872                        'isOwner' => '1',
873                        'dtstamp' => time() . '000',
874                        'fontColor' => 'FFFFFF',
875                        'backgroundColor' => '3366CC',
876                        'borderColor' => '3366CC',
877                    );
878
879                    $sigCreated = Controller::create(array('concept' => 'calendarSignature'), $sig);
880
881
882                    DAViCalAdapter::importCollection($v->url, $calCreated['id']);
883                }
884            } else {
885                //Criaremos uma agenda padrão
886                $cal = array('name' => 'Calendario',
887                    'description' => 'Calendario Padrão',
888                    'timezone' => (date_default_timezone_get()) ? date_default_timezone_get() : 'America/Sao_Paulo',
889                    'dtstamp' => time() . '000'
890                );
891
892                $calCreated = Controller::create(array('concept' => 'calendar'), $cal);
893
894                $sig = array('user' => $_SESSION['wallet']['user']['uidNumber'],
895                    'calendar' => $calCreated['id'],
896                    'isOwner' => '1',
897                    'dtstamp' => time() . '000',
898                    'fontColor' => 'FFFFFF',
899                    'backgroundColor' => '3366CC',
900                    'borderColor' => '3366CC',
901                );
902
903                $sigCreated = Controller::create(array('concept' => 'calendarSignature'), $sig);
904            }
905
906            $result = Controller::find($original['URI'], $original['properties'] ? $original['properties'] : null, $original['criteria']);
907            return false;
908        }
909    }
910
911    //TODO - Criar conceito separado para participantes externos e remover o criterio notExternal
912    public function findExternalPaticipants(&$uri, &$result, &$criteria, $original) {
913        if (Config::me('uidNumber') && !isset($criteria['notExternal'])) {
914            $newuri['concept'] = 'user';
915            $newuri['service'] = 'PostgreSQL';
916
917            $newCriteria = $original['criteria'];
918            $valid = true;
919
920            $newCriteria['filter'] = array('AND', $newCriteria['filter'], array('=', 'owner', Config::me('uidNumber')));
921            $externalUsers = Controller::find($newuri, $original['properties'] ? $original['properties'] : null, $newCriteria);
922
923            if (is_array($externalUsers)) {
924                foreach ($externalUsers as $i => $v)
925                    $externalUsers[$i]['isExternal'] = '1';
926            }
927            else
928                $externalUsers = array();
929
930            if (!is_array($result))
931                $result = array();
932
933            return array_merge($result, $externalUsers);
934        }
935    }
936
937    public function davcalCreateCollection(&$uri, &$params, &$criteria, $original) {
938        if (Config::module('useCaldav', 'expressoCalendar')) {
939            require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
940            DAViCalAdapter::mkcalendar($params['location'], $params['name'], isset($params['description']) ? $params['description'] : '' );
941        }
942    }
943
944    public function davcalDeleteCollection(&$uri, &$params, &$criteria, $original) {
945        if (Config::module('useCaldav', 'expressoCalendar') && Config::module('onRemoveCascadeCalDav')) {
946            require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
947            $calendar = Controller::read($uri);
948            DAViCalAdapter::rmCalendar($calendar['location']);
949        }
950    }
951
952    public function davcalUpdateCollection(&$uri, &$params, &$criteria, $original) {
953        if (Config::module('useCaldav', 'expressoCalendar')) {
954            require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
955            if (isset($params['location'])) {
956                $calendar = Controller::read($uri);
957                if ($calendar['location'] !== $params['location'])
958                    DAViCalAdapter::mvcalendar($calendar['location'], $params['location']);
959            }
960        }
961    }
962
963    private static function _makeUid() {
964
965        $date = date('Ymd\THisT');
966        $unique = substr(microtime(), 2, 4);
967        $base = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPrRsStTuUvVxXuUvVwWzZ1234567890';
968        $start = 0;
969        $end = strlen($base) - 1;
970        $length = 6;
971        $str = null;
972        for ($p = 0; $p < $length; $p++)
973            $unique .= $base{mt_rand($start, $end)};
974
975        return $date . $unique . '@expresso-calendar';
976    }
977
978    private function getStatus($id) {
979        $a = array(
980            STATUS_CONFIRMED => 'CONFIRMED',
981            STATUS_CANCELLED => 'CANCELLED',
982            STATUS_TENATIVE => 'TENATIVE',
983            STATUS_UNANSWERED => 'NEEDS-ACTION',
984            STATUS_DELEGATED => 'DELEGATED'
985        );
986        return $a[$id];
987    }
988
989    private static function decodeAlarmType($id) {
990        $a = array(ALARM_ALERT => 'alert',
991            ALARM_MAIL => 'mail',
992            ALARM_SMS => 'sms');
993
994        return $a[$id];
995    }
996
997    private static function codeAlarmType($type) {
998        $a = array('alert' => ALARM_ALERT,
999            'mail' => ALARM_MAIL,
1000            'sms' => ALARM_SMS);
1001
1002        return $a[$type];
1003    }
1004
1005    private static function codeAlarmUnit($u) {
1006        if ($u === 'd')
1007            return 'days';
1008        if ($u === 'm')
1009            return 'minutes';
1010        if ($u === 'H')
1011            return 'hours';
1012    }
1013
1014    private static function permissionFromCalendarSignature($idCalendar, $idEvent) {
1015        $signature = Controller::find(array('concept' => 'calendarSignature'), false, array( 'filter' => array('AND', array('=', 'calendar', $idCalendar), array('=', 'isOwner', '1')), 'deepness' => 2));
1016       
1017        $signature = is_array($signature) ? $signature[0] : $signature;
1018
1019        if($signature['user']['id'] == Config::me('uidNumber')){
1020            return false;
1021        }else{
1022           $isOwner = Controller::find(array('concept' => 'participant'), array('id'), array('filter' =>
1023                    array('AND',
1024                        array('=', 'isOrganizer', '1'),
1025                        array('=', 'user', $signature['user']['id']),
1026                        array('=', 'schedulable', $idEvent)
1027                        )));
1028
1029        return ( isset($isOwner[0]['id']) ) ? true : false;
1030        }
1031    }
1032   
1033   
1034    private static function ownerSchedulable($id, $me) {
1035
1036        $isOwner = Controller::find(array('concept' => 'participant'), array('id'), array('filter' =>
1037                    array('AND',
1038                        array('=', 'isOrganizer', '1'),
1039                        array('=', 'user', $me),
1040                        array('=', 'schedulable', $id)
1041                        )));
1042
1043        return ( isset($isOwner[0]['id']) ) ? true : false;
1044    }
1045   
1046   
1047    private static function referenceCalendarToObject($schedulable, $calendar) {
1048        return Controller::service('PostgreSQL')->execResultSql('SELECT calendar_to_calendar_object.id as calendar_to_calendar_Object FROM calendar_to_calendar_object'
1049            . ' WHERE calendar_to_calendar_object.calendar_id = '. $calendar
1050            . ' AND calendar_to_calendar_object.calendar_object_id = ' . addslashes($schedulable));
1051    }
1052   
1053    private static function schedulable2calendarToObject($Schedulable) {
1054        return Controller::service('PostgreSQL')->execResultSql('SELECT calendar_to_calendar_object.id as calendar_to_calendar_Object , calendar.name as calendar_name ,calendar.location as calendar_location, calendar.id as calendar_id FROM calendar_to_calendar_object , calendar , calendar_signature'
1055                        . ' WHERE calendar_signature.user_uidnumber = ' . $_SESSION['wallet']['user']['uidNumber']
1056                        //      .' AND calendar_signature.is_owner = 1'
1057                        . ' AND calendar_signature.calendar_id = calendar.id'
1058                        . ' AND calendar_to_calendar_object.calendar_id = calendar.id'
1059                        . ' AND calendar_to_calendar_object.calendar_object_id = ' . addslashes($Schedulable));
1060    }
1061
1062    protected static function isAllowDeleteInCalendar($calendar) {
1063        $f = Controller::find(array('concept' => 'calendarToPermission'), false, array('filter' => array('AND', array('=', 'user', Config::me('uidNumber')), array('=', 'calendar', $calendar))));
1064        return (strpos($f[0]['acl'], CALENDAR_ACL_REMOVE) === false) ? false : true;
1065    }
1066
1067}
1068
1069?>
Note: See TracBrowser for help on using the repository browser.