source: sandbox/2.4.2-expresso1/prototype/modules/calendar/export.php @ 5863

Revision 5863, 3.1 KB checked in by acoutinho, 10 years ago (diff)

Ticket #2587 - Bugs encontrados na nova agenga(expressoCalendar)

Line 
1<?php
2require_once '../../api/controller.php';
3$params = $_GET;
4
5//if( isset($params['calendars']) )
6//{
7//    if(!is_array($params['calendars']))
8//       $params['calendars'] = array($params['calendars']);
9//   
10//   foreach ($params['calendars'] as &$calendar)
11//   {
12//       $eventLinks = Controller::find(array('concept' => 'calendarToSchedulable') , array('schedulable') , array('filter' => array( '=' , 'calendar' , $calendar)));
13//       
14//       $eventsIds = array();
15//       foreach ($eventLinks as &$eventLink)
16//           $eventsIds[] = $eventLink['schedulable'];
17//       
18//       $events = Controller::find(array('concept' => 'schedulable') , false , array('filter' => array('IN','id',$eventsIds) , 'deepness' => '2' ));
19//       $ics = Controller::format( array( 'service' => 'iCal' ) , $events );
20//       
21//   }
22//
23//}
24
25if( isset($params['calendar']) )
26{
27    $eventLinks = Controller::find(array('concept' => 'calendarToSchedulable') , array('schedulable') , array('filter' => array( '=' , 'calendar' , $params['calendar'])));
28    $calendar = Controller::read(array('concept' => 'calendar' , 'id' => $params['calendar']));
29
30    $eventsIds = array();
31    foreach ($eventLinks as &$eventLink)
32       $eventsIds[] = $eventLink['schedulable'];
33
34    $events = Controller::find(array('concept' => 'schedulable') , false , array('filter' => array('IN','id',$eventsIds) , 'deepness' => '2', 'timezones' => array($calendar['id'] => $calendar['timezone']) ));       
35    $ics = Controller::format( array( 'service' => 'iCal' ) , $events , array('defaultTZI' => $calendar['timezone']) );
36
37    header( 'Content-Type: text/calendar; charset=utf-8' );
38    header( 'Content-Length: '.  mb_strlen($ics) );
39    header( 'Content-Disposition: attachment; filename="Calendar.ics"' );
40    header( 'Cache-Control: max-age=10' );
41    echo $ics;
42    die();
43}
44
45if( isset($params['event']) )
46{   
47    $event = Controller::read(array('concept' => 'schedulable' , 'id' => $params['event']));
48        $attachmentRelation = Controller::find( array( 'concept' => 'schedulableToAttachment' ) , false ,array( 'filter' => array('=', 'schedulable'  ,  $event['id']) ));
49        if(is_array($attachmentRelation)){
50                $attachments = array();
51                foreach($attachmentRelation as $key => $value)
52                        if(isset($value['attachment']) || !!$value['attachment'])
53                                $attachments[$key]  = $value['attachment'];
54                //Pega os anexos sem source
55                $event['attachments'] = Controller::find( array( 'concept' => 'attachment' ) , false ,array( 'filter' => array('IN', 'id' , $attachments) ));
56        }
57       
58    $repeat = Controller::find( array( 'concept' => 'repeat' ) , false ,array( 'filter' => array('=', 'schedulable'  ,  $event['id']) ));   
59       
60    if(is_array($repeat))
61        $event['repeat'] = $repeat[0];
62
63     
64    $ics = Controller::format( array( 'service' => 'iCal' ) , array($event) , array('defaultTZI' => $event['timezone']) );
65   
66    header( 'Content-Type: text/calendar; charset=utf-8' );
67    header( 'Content-Length: '.  mb_strlen($ics) );
68    header( 'Content-Disposition: attachment; filename="'.$event['summary'].'.ics"' );
69    header( 'Cache-Control: max-age=10' );
70    echo $ics;
71    die();
72}
73
74?>
Note: See TracBrowser for help on using the repository browser.