1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * |
---|
5 | * Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or modify |
---|
8 | * it under the terms of the GNU General Public License as published by |
---|
9 | * the Free Software Foundation; either version 3 of the License, or |
---|
10 | * any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
15 | * details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software Foundation, |
---|
19 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
20 | * |
---|
21 | * You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, |
---|
22 | * 6731, PTI, Edifício do Saber, 3º floor, room 306, Foz do Iguaçu - PR - Brasil |
---|
23 | * or at e-mail address prognus@prognus.com.br. |
---|
24 | * |
---|
25 | * Neste arquivo são ser implementadas regras de negócio para a exportação de eventos e tarefas do ExpressoCalendar. |
---|
26 | * |
---|
27 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
28 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
29 | * @version 1.0 |
---|
30 | * @sponsor Caixa Econômica Federal |
---|
31 | * @since Arquivo disponibilizado na versão Expresso 2.4.0 |
---|
32 | */ |
---|
33 | |
---|
34 | require_once '../../api/controller.php'; |
---|
35 | $params = $_GET; |
---|
36 | |
---|
37 | //if( isset($params['calendars']) ) |
---|
38 | //{ |
---|
39 | // if(!is_array($params['calendars'])) |
---|
40 | // $params['calendars'] = array($params['calendars']); |
---|
41 | // |
---|
42 | // foreach ($params['calendars'] as &$calendar) |
---|
43 | // { |
---|
44 | // $eventLinks = Controller::find(array('concept' => 'calendarToSchedulable') , array('schedulable') , array('filter' => array( '=' , 'calendar' , $calendar))); |
---|
45 | // |
---|
46 | // $eventsIds = array(); |
---|
47 | // foreach ($eventLinks as &$eventLink) |
---|
48 | // $eventsIds[] = $eventLink['schedulable']; |
---|
49 | // |
---|
50 | // $events = Controller::find(array('concept' => 'schedulable') , false , array('filter' => array('IN','id',$eventsIds) , 'deepness' => '2' )); |
---|
51 | // $ics = Controller::format( array( 'service' => 'iCal' ) , $events ); |
---|
52 | // |
---|
53 | // } |
---|
54 | // |
---|
55 | //} |
---|
56 | |
---|
57 | if( isset($params['calendar']) ) |
---|
58 | { |
---|
59 | $eventLinks = Controller::find(array('concept' => 'calendarToSchedulable') , array('schedulable') , array('filter' => array( '=' , 'calendar' , $params['calendar']))); |
---|
60 | $calendar = Controller::read(array('concept' => 'calendar' , 'id' => $params['calendar'])); |
---|
61 | |
---|
62 | $eventsIds = array(); |
---|
63 | foreach ($eventLinks as &$eventLink) |
---|
64 | $eventsIds[] = $eventLink['schedulable']; |
---|
65 | |
---|
66 | $events = Controller::find(array('concept' => 'schedulable') , false , array('filter' => array('IN','id',$eventsIds) , 'deepness' => '2', 'timezones' => array($calendar['id'] => $calendar['timezone']) )); |
---|
67 | $ics = Controller::format( array( 'service' => 'iCal' ) , $events , array('defaultTZI' => $calendar['timezone']) ); |
---|
68 | |
---|
69 | header( 'Content-Type: text/calendar; charset=utf-8' ); |
---|
70 | header( 'Content-Length: '. mb_strlen($ics) ); |
---|
71 | header( 'Content-Disposition: attachment; filename="Calendar.ics"' ); |
---|
72 | header( 'Cache-Control: max-age=10' ); |
---|
73 | echo $ics; |
---|
74 | die(); |
---|
75 | } |
---|
76 | |
---|
77 | if( isset($params['event']) ) |
---|
78 | { |
---|
79 | $event = Controller::read(array('concept' => 'schedulable' , 'id' => $params['event'])); |
---|
80 | $attachmentRelation = Controller::find( array( 'concept' => 'schedulableToAttachment' ) , false ,array( 'filter' => array('=', 'schedulable' , $event['id']) )); |
---|
81 | if(is_array($attachmentRelation)){ |
---|
82 | $attachments = array(); |
---|
83 | foreach($attachmentRelation as $key => $value) |
---|
84 | if(isset($value['attachment']) || !!$value['attachment']) |
---|
85 | $attachments[$key] = $value['attachment']; |
---|
86 | //Pega os anexos sem source |
---|
87 | $event['attachments'] = Controller::find( array( 'concept' => 'attachment' ) , false ,array( 'filter' => array('IN', 'id' , $attachments) )); |
---|
88 | } |
---|
89 | |
---|
90 | $repeat = Controller::find( array( 'concept' => 'repeat' ) , false ,array( 'filter' => array('=', 'schedulable' , $event['id']) )); |
---|
91 | |
---|
92 | if(is_array($repeat)) |
---|
93 | $event['repeat'] = $repeat[0]; |
---|
94 | |
---|
95 | |
---|
96 | $ics = Controller::format( array( 'service' => 'iCal' ) , array($event) , array('defaultTZI' => $event['timezone']) ); |
---|
97 | |
---|
98 | header( 'Content-Type: text/calendar; charset=utf-8' ); |
---|
99 | header( 'Content-Length: '. mb_strlen($ics) ); |
---|
100 | header( 'Content-Disposition: attachment; filename="'.$event['summary'].'.ics"' ); |
---|
101 | header( 'Cache-Control: max-age=10' ); |
---|
102 | echo $ics; |
---|
103 | die(); |
---|
104 | } |
---|
105 | |
---|
106 | ?> |
---|