annotate plugins/calendar/calendar.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 3bd5fe8166b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1 <?php
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4 * Calendar plugin for Roundcube webmail
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6 * @author Lazlo Westerhof <hello@lazlo.me>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
7 * @author Thomas Bruederli <bruederli@kolabsys.com>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
8 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
9 * Copyright (C) 2010, Lazlo Westerhof <hello@lazlo.me>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
10 * Copyright (C) 2014-2015, Kolab Systems AG <contact@kolabsys.com>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
11 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
12 * This program is free software: you can redistribute it and/or modify
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
13 * it under the terms of the GNU Affero General Public License as
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
14 * published by the Free Software Foundation, either version 3 of the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
15 * License, or (at your option) any later version.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
16 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
20 * GNU Affero General Public License for more details.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
21 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
22 * You should have received a copy of the GNU Affero General Public License
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
24 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
25
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
26 class calendar extends rcube_plugin
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
27 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
28 const FREEBUSY_UNKNOWN = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
29 const FREEBUSY_FREE = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
30 const FREEBUSY_BUSY = 2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
31 const FREEBUSY_TENTATIVE = 3;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
32 const FREEBUSY_OOF = 4;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
33
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
34 const SESSION_KEY = 'calendar_temp';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
35
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
36 public $task = '?(?!logout).*';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
37 public $rc;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
38 public $lib;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
39 public $resources_dir;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
40 public $home; // declare public to be used in other classes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
41 public $urlbase;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
42 public $timezone;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
43 public $timezone_offset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
44 public $gmt_offset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
45 public $ui;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
46
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
47 public $defaults = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
48 'calendar_default_view' => "agendaWeek",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
49 'calendar_timeslots' => 2,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
50 'calendar_work_start' => 6,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
51 'calendar_work_end' => 18,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
52 'calendar_agenda_range' => 60,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
53 'calendar_agenda_sections' => 'smart',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
54 'calendar_event_coloring' => 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
55 'calendar_time_indicator' => true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
56 'calendar_allow_invite_shared' => false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
57 'calendar_itip_send_option' => 3,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
58 'calendar_itip_after_action' => 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
59 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
60
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
61 // These are implemented with __get()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
62 // private $ical;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
63 // private $itip;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
64 // private $driver;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
65
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
66
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
67 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
68 * Plugin initialization.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
69 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
70 function init()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
71 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
72 $this->rc = rcube::get_instance();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
73
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
74 $this->register_task('calendar', 'calendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
75
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
76 // load calendar configuration
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
77 $this->load_config();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
78
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
79 // catch iTIP confirmation requests that don're require a valid session
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
80 if ($this->rc->action == 'attend' && !empty($_REQUEST['_t'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
81 $this->add_hook('startup', array($this, 'itip_attend_response'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
82 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
83 else if ($this->rc->action == 'feed' && !empty($_REQUEST['_cal'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
84 $this->add_hook('startup', array($this, 'ical_feed_export'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
85 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
86 else if ($this->rc->task != 'login') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
87 // default startup routine
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
88 $this->add_hook('startup', array($this, 'startup'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
89 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
90
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
91 $this->add_hook('user_delete', array($this, 'user_delete'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
92 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
93
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
94 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
95 * Setup basic plugin environment and UI
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
96 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
97 protected function setup()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
98 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
99 $this->require_plugin('libcalendaring');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
100
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
101 $this->lib = libcalendaring::get_instance();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
102 $this->timezone = $this->lib->timezone;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
103 $this->gmt_offset = $this->lib->gmt_offset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
104 $this->dst_active = $this->lib->dst_active;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
105 $this->timezone_offset = $this->gmt_offset / 3600 - $this->dst_active;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
106
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
107 // load localizations
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
108 $this->add_texts('localization/', $this->rc->task == 'calendar' && (!$this->rc->action || $this->rc->action == 'print'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
109
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
110 require($this->home . '/lib/calendar_ui.php');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
111 $this->ui = new calendar_ui($this);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
112 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
113
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
114 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
115 * Startup hook
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
116 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
117 public function startup($args)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
118 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
119 // the calendar module can be enabled/disabled by the kolab_auth plugin
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
120 if ($this->rc->config->get('calendar_disabled', false) || !$this->rc->config->get('calendar_enabled', true))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
121 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
122
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
123 $this->setup();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
124
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
125 // load Calendar user interface
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
126 if (!$this->rc->output->ajax_call && (!$this->rc->output->env['framed'] || $args['action'] == 'preview')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
127 $this->ui->init();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
128
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
129 // settings are required in (almost) every GUI step
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
130 if ($args['action'] != 'attend')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
131 $this->rc->output->set_env('calendar_settings', $this->load_settings());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
132 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
133
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
134 if ($args['task'] == 'calendar' && $args['action'] != 'save-pref') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
135 if ($args['action'] != 'upload') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
136 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
137 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
138
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
139 // register calendar actions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
140 $this->register_action('index', array($this, 'calendar_view'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
141 $this->register_action('event', array($this, 'event_action'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
142 $this->register_action('calendar', array($this, 'calendar_action'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
143 $this->register_action('count', array($this, 'count_events'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
144 $this->register_action('load_events', array($this, 'load_events'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
145 $this->register_action('export_events', array($this, 'export_events'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
146 $this->register_action('import_events', array($this, 'import_events'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
147 $this->register_action('upload', array($this, 'attachment_upload'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
148 $this->register_action('get-attachment', array($this, 'attachment_get'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
149 $this->register_action('freebusy-status', array($this, 'freebusy_status'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
150 $this->register_action('freebusy-times', array($this, 'freebusy_times'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
151 $this->register_action('randomdata', array($this, 'generate_randomdata'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
152 $this->register_action('print', array($this,'print_view'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
153 $this->register_action('mailimportitip', array($this, 'mail_import_itip'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
154 $this->register_action('mailimportattach', array($this, 'mail_import_attachment'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
155 $this->register_action('mailtoevent', array($this, 'mail_message2event'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
156 $this->register_action('inlineui', array($this, 'get_inline_ui'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
157 $this->register_action('check-recent', array($this, 'check_recent'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
158 $this->register_action('itip-status', array($this, 'event_itip_status'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
159 $this->register_action('itip-remove', array($this, 'event_itip_remove'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
160 $this->register_action('itip-decline-reply', array($this, 'mail_itip_decline_reply'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
161 $this->register_action('itip-delegate', array($this, 'mail_itip_delegate'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
162 $this->register_action('resources-list', array($this, 'resources_list'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
163 $this->register_action('resources-owner', array($this, 'resources_owner'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
164 $this->register_action('resources-calendar', array($this, 'resources_calendar'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
165 $this->register_action('resources-autocomplete', array($this, 'resources_autocomplete'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
166 $this->add_hook('refresh', array($this, 'refresh'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
167
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
168 // remove undo information...
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
169 if ($undo = $_SESSION['calendar_event_undo']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
170 // ...after timeout
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
171 $undo_time = $this->rc->config->get('undo_timeout', 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
172 if ($undo['ts'] < time() - $undo_time) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
173 $this->rc->session->remove('calendar_event_undo');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
174 // @TODO: do EXPUNGE on kolab objects?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
175 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
176 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
177 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
178 else if ($args['task'] == 'settings') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
179 // add hooks for Calendar settings
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
180 $this->add_hook('preferences_sections_list', array($this, 'preferences_sections_list'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
181 $this->add_hook('preferences_list', array($this, 'preferences_list'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
182 $this->add_hook('preferences_save', array($this, 'preferences_save'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
183 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
184 else if ($args['task'] == 'mail') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
185 // hooks to catch event invitations on incoming mails
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
186 if ($args['action'] == 'show' || $args['action'] == 'preview') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
187 $this->add_hook('template_object_messagebody', array($this, 'mail_messagebody_html'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
188 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
189
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
190 // add 'Create event' item to message menu
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
191 if ($this->api->output->type == 'html') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
192 $this->api->add_content(html::tag('li', null,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
193 $this->api->output->button(array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
194 'command' => 'calendar-create-from-mail',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
195 'label' => 'calendar.createfrommail',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
196 'type' => 'link',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
197 'classact' => 'icon calendarlink active',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
198 'class' => 'icon calendarlink',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
199 'innerclass' => 'icon calendar',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
200 ))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
201 'messagemenu');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
202
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
203 $this->api->output->add_label('calendar.createfrommail');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
204 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
205
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
206 $this->add_hook('messages_list', array($this, 'mail_messages_list'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
207 $this->add_hook('message_compose', array($this, 'mail_message_compose'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
208 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
209 else if ($args['task'] == 'addressbook') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
210 if ($this->rc->config->get('calendar_contact_birthdays')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
211 $this->add_hook('contact_update', array($this, 'contact_update'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
212 $this->add_hook('contact_create', array($this, 'contact_update'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
213 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
214 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
215
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
216 // add hooks to display alarms
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
217 $this->add_hook('pending_alarms', array($this, 'pending_alarms'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
218 $this->add_hook('dismiss_alarms', array($this, 'dismiss_alarms'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
219 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
220
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
221 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
222 * Helper method to load the backend driver according to local config
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
223 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
224 private function load_driver()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
225 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
226 if (is_object($this->driver))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
227 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
228
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
229 $driver_name = $this->rc->config->get('calendar_driver', 'database');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
230 $driver_class = $driver_name . '_driver';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
231
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
232 require_once($this->home . '/drivers/calendar_driver.php');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
233 require_once($this->home . '/drivers/' . $driver_name . '/' . $driver_class . '.php');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
234
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
235 $this->driver = new $driver_class($this);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
236
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
237 if ($this->driver->undelete)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
238 $this->driver->undelete = $this->rc->config->get('undo_timeout', 0) > 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
239 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
240
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
241 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
242 * Load iTIP functions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
243 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
244 private function load_itip()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
245 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
246 if (!$this->itip) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
247 require_once($this->home . '/lib/calendar_itip.php');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
248 $this->itip = new calendar_itip($this);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
249
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
250 if ($this->rc->config->get('kolab_invitation_calendars'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
251 $this->itip->set_rsvp_actions(array('accepted','tentative','declined','delegated','needs-action'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
252 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
253
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
254 return $this->itip;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
255 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
256
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
257 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
258 * Load iCalendar functions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
259 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
260 public function get_ical()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
261 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
262 if (!$this->ical) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
263 $this->ical = libcalendaring::get_ical();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
264 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
265
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
266 return $this->ical;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
267 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
268
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
269 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
270 * Get properties of the calendar this user has specified as default
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
271 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
272 public function get_default_calendar($sensitivity = null, $calendars = null)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
273 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
274 if ($calendars === null) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
275 $calendars = $this->driver->list_calendars(calendar_driver::FILTER_PERSONAL | calendar_driver::FILTER_WRITEABLE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
276 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
277
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
278 $default_id = $this->rc->config->get('calendar_default_calendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
279 $calendar = $calendars[$default_id] ?: null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
280
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
281 if (!$calendar || $sensitivity) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
282 foreach ($calendars as $cal) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
283 if ($sensitivity && $cal['subtype'] == $sensitivity) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
284 $calendar = $cal;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
285 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
286 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
287 if ($cal['default'] && $cal['editable']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
288 $calendar = $cal;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
289 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
290 if ($cal['editable']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
291 $first = $cal;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
292 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
293 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
294 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
295
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
296 return $calendar ?: $first;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
297 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
298
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
299
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
300 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
301 * Render the main calendar view from skin template
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
302 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
303 function calendar_view()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
304 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
305 $this->rc->output->set_pagetitle($this->gettext('calendar'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
306
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
307 // Add CSS stylesheets to the page header
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
308 $this->ui->addCSS();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
309
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
310 // Add JS files to the page header
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
311 $this->ui->addJS();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
312
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
313 $this->ui->init_templates();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
314 $this->rc->output->add_label('lowest','low','normal','high','highest','delete','cancel','uploading','noemailwarning','close');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
315
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
316 // initialize attendees autocompletion
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
317 $this->rc->autocomplete_init();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
318
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
319 $this->rc->output->set_env('timezone', $this->timezone->getName());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
320 $this->rc->output->set_env('calendar_driver', $this->rc->config->get('calendar_driver'), false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
321 $this->rc->output->set_env('calendar_resources', (bool)$this->rc->config->get('calendar_resources_driver'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
322 $this->rc->output->set_env('identities-selector', $this->ui->identity_select(array('id' => 'edit-identities-list', 'aria-label' => $this->gettext('roleorganizer'))));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
323
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
324 $view = rcube_utils::get_input_value('view', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
325 if (in_array($view, array('agendaWeek', 'agendaDay', 'month', 'table')))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
326 $this->rc->output->set_env('view', $view);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
327
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
328 if ($date = rcube_utils::get_input_value('date', rcube_utils::INPUT_GPC))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
329 $this->rc->output->set_env('date', $date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
330
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
331 if ($msgref = rcube_utils::get_input_value('itip', rcube_utils::INPUT_GPC))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
332 $this->rc->output->set_env('itip_events', $this->itip_events($msgref));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
333
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
334 $this->rc->output->send("calendar.calendar");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
335 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
336
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
337 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
338 * Handler for preferences_sections_list hook.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
339 * Adds Calendar settings sections into preferences sections list.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
340 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
341 * @param array Original parameters
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
342 * @return array Modified parameters
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
343 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
344 function preferences_sections_list($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
345 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
346 $p['list']['calendar'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
347 'id' => 'calendar', 'section' => $this->gettext('calendar'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
348 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
349
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
350 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
351 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
352
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
353 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
354 * Handler for preferences_list hook.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
355 * Adds options blocks into Calendar settings sections in Preferences.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
356 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
357 * @param array Original parameters
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
358 * @return array Modified parameters
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
359 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
360 function preferences_list($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
361 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
362 if ($p['section'] != 'calendar') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
363 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
364 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
365
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
366 $no_override = array_flip((array)$this->rc->config->get('dont_override'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
367
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
368 $p['blocks']['view']['name'] = $this->gettext('mainoptions');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
369
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
370 if (!isset($no_override['calendar_default_view'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
371 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
372 $p['blocks']['view']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
373 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
374 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
375
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
376 $field_id = 'rcmfd_default_view';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
377 $select = new html_select(array('name' => '_default_view', 'id' => $field_id));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
378 $select->add($this->gettext('day'), "agendaDay");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
379 $select->add($this->gettext('week'), "agendaWeek");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
380 $select->add($this->gettext('month'), "month");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
381 $select->add($this->gettext('agenda'), "table");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
382 $p['blocks']['view']['options']['default_view'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
383 'title' => html::label($field_id, rcube::Q($this->gettext('default_view'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
384 'content' => $select->show($this->rc->config->get('calendar_default_view', $this->defaults['calendar_default_view'])),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
385 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
386 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
387
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
388 if (!isset($no_override['calendar_timeslots'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
389 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
390 $p['blocks']['view']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
391 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
392 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
393
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
394 $field_id = 'rcmfd_timeslot';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
395 $choices = array('1', '2', '3', '4', '6');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
396 $select = new html_select(array('name' => '_timeslots', 'id' => $field_id));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
397 $select->add($choices);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
398 $p['blocks']['view']['options']['timeslots'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
399 'title' => html::label($field_id, rcube::Q($this->gettext('timeslots'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
400 'content' => $select->show(strval($this->rc->config->get('calendar_timeslots', $this->defaults['calendar_timeslots']))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
401 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
402 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
403
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
404 if (!isset($no_override['calendar_first_day'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
405 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
406 $p['blocks']['view']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
407 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
408 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
409
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
410 $field_id = 'rcmfd_firstday';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
411 $select = new html_select(array('name' => '_first_day', 'id' => $field_id));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
412 $select->add($this->gettext('sunday'), '0');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
413 $select->add($this->gettext('monday'), '1');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
414 $select->add($this->gettext('tuesday'), '2');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
415 $select->add($this->gettext('wednesday'), '3');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
416 $select->add($this->gettext('thursday'), '4');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
417 $select->add($this->gettext('friday'), '5');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
418 $select->add($this->gettext('saturday'), '6');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
419 $p['blocks']['view']['options']['first_day'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
420 'title' => html::label($field_id, rcube::Q($this->gettext('first_day'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
421 'content' => $select->show(strval($this->rc->config->get('calendar_first_day', $this->defaults['calendar_first_day']))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
422 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
423 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
424
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
425 if (!isset($no_override['calendar_first_hour'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
426 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
427 $p['blocks']['view']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
428 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
429 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
430
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
431 $time_format = $this->rc->config->get('time_format', libcalendaring::to_php_date_format($this->rc->config->get('calendar_time_format', $this->defaults['calendar_time_format'])));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
432 $select_hours = new html_select();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
433 for ($h = 0; $h < 24; $h++)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
434 $select_hours->add(date($time_format, mktime($h, 0, 0)), $h);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
435
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
436 $field_id = 'rcmfd_firsthour';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
437 $p['blocks']['view']['options']['first_hour'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
438 'title' => html::label($field_id, rcube::Q($this->gettext('first_hour'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
439 'content' => $select_hours->show($this->rc->config->get('calendar_first_hour', $this->defaults['calendar_first_hour']), array('name' => '_first_hour', 'id' => $field_id)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
440 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
441 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
442
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
443 if (!isset($no_override['calendar_work_start'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
444 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
445 $p['blocks']['view']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
446 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
447 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
448
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
449 $field_id = 'rcmfd_workstart';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
450 $p['blocks']['view']['options']['workinghours'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
451 'title' => html::label($field_id, rcube::Q($this->gettext('workinghours'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
452 'content' => $select_hours->show($this->rc->config->get('calendar_work_start', $this->defaults['calendar_work_start']), array('name' => '_work_start', 'id' => $field_id)) .
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
453 ' &mdash; ' . $select_hours->show($this->rc->config->get('calendar_work_end', $this->defaults['calendar_work_end']), array('name' => '_work_end', 'id' => $field_id)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
454 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
455 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
456
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
457 if (!isset($no_override['calendar_event_coloring'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
458 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
459 $p['blocks']['view']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
460 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
461 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
462
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
463 $field_id = 'rcmfd_coloring';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
464 $select_colors = new html_select(array('name' => '_event_coloring', 'id' => $field_id));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
465 $select_colors->add($this->gettext('coloringmode0'), 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
466 $select_colors->add($this->gettext('coloringmode1'), 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
467 $select_colors->add($this->gettext('coloringmode2'), 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
468 $select_colors->add($this->gettext('coloringmode3'), 3);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
469
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
470 $p['blocks']['view']['options']['eventcolors'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
471 'title' => html::label($field_id . 'value', rcube::Q($this->gettext('eventcoloring'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
472 'content' => $select_colors->show($this->rc->config->get('calendar_event_coloring', $this->defaults['calendar_event_coloring'])),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
473 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
474 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
475
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
476 // loading driver is expensive, don't do it if not needed
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
477 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
478
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
479 if (!isset($no_override['calendar_default_alarm_type']) || !isset($no_override['calendar_default_alarm_offset'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
480 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
481 $p['blocks']['view']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
482 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
483 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
484
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
485 $alarm_type = $alarm_offset = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
486
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
487 if (!isset($no_override['calendar_default_alarm_type'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
488 $field_id = 'rcmfd_alarm';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
489 $select_type = new html_select(array('name' => '_alarm_type', 'id' => $field_id));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
490 $select_type->add($this->gettext('none'), '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
491
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
492 foreach ($this->driver->alarm_types as $type) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
493 $select_type->add($this->rc->gettext(strtolower("alarm{$type}option"), 'libcalendaring'), $type);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
494 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
495
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
496 $alarm_type = $select_type->show($this->rc->config->get('calendar_default_alarm_type', ''));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
497 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
498
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
499 if (!isset($no_override['calendar_default_alarm_offset'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
500 $field_id = 'rcmfd_alarm';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
501 $input_value = new html_inputfield(array('name' => '_alarm_value', 'id' => $field_id . 'value', 'size' => 3));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
502 $select_offset = new html_select(array('name' => '_alarm_offset', 'id' => $field_id . 'offset'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
503
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
504 foreach (array('-M','-H','-D','+M','+H','+D') as $trigger) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
505 $select_offset->add($this->rc->gettext('trigger' . $trigger, 'libcalendaring'), $trigger);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
506 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
507
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
508 $preset = libcalendaring::parse_alarm_value($this->rc->config->get('calendar_default_alarm_offset', '-15M'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
509 $alarm_offset = $input_value->show($preset[0]) . ' ' . $select_offset->show($preset[1]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
510 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
511
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
512 $p['blocks']['view']['options']['alarmtype'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
513 'title' => html::label($field_id, rcube::Q($this->gettext('defaultalarmtype'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
514 'content' => $alarm_type . ' ' . $alarm_offset,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
515 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
516 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
517
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
518 if (!isset($no_override['calendar_default_calendar'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
519 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
520 $p['blocks']['view']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
521 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
522 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
523 // default calendar selection
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
524 $field_id = 'rcmfd_default_calendar';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
525 $select_cal = new html_select(array('name' => '_default_calendar', 'id' => $field_id, 'is_escaped' => true));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
526 foreach ((array)$this->driver->list_calendars(calendar_driver::FILTER_PERSONAL | calendar_driver::FILTER_ACTIVE) as $id => $prop) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
527 $select_cal->add($prop['name'], strval($id));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
528 if ($prop['default'])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
529 $default_calendar = $id;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
530 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
531 $p['blocks']['view']['options']['defaultcalendar'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
532 'title' => html::label($field_id . 'value', rcube::Q($this->gettext('defaultcalendar'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
533 'content' => $select_cal->show($this->rc->config->get('calendar_default_calendar', $default_calendar)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
534 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
535 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
536
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
537 $p['blocks']['itip']['name'] = $this->gettext('itipoptions');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
538
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
539 // Invitations handling
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
540 if (!isset($no_override['calendar_itip_after_action'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
541 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
542 $p['blocks']['itip']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
543 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
544 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
545
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
546 $field_id = 'rcmfd_after_action';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
547 $select = new html_select(array('name' => '_after_action', 'id' => $field_id,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
548 'onchange' => "\$('#{$field_id}_select')[this.value == 4 ? 'show' : 'hide']()"));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
549
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
550 $select->add($this->gettext('afternothing'), '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
551 $select->add($this->gettext('aftertrash'), 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
552 $select->add($this->gettext('afterdelete'), 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
553 $select->add($this->gettext('afterflagdeleted'), 3);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
554 $select->add($this->gettext('aftermoveto'), 4);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
555
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
556 $val = $this->rc->config->get('calendar_itip_after_action', $this->defaults['calendar_itip_after_action']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
557 if ($val !== null && $val !== '' && !is_int($val)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
558 $folder = $val;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
559 $val = 4;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
560 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
561
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
562 $folders = $this->rc->folder_selector(array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
563 'id' => $field_id . '_select',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
564 'name' => '_after_action_folder',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
565 'maxlength' => 30,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
566 'folder_filter' => 'mail',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
567 'folder_rights' => 'w',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
568 'style' => $val !== 4 ? 'display:none' : '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
569 ));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
570
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
571 $p['blocks']['itip']['options']['after_action'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
572 'title' => html::label($field_id, rcube::Q($this->gettext('afteraction'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
573 'content' => $select->show($val) . $folders->show($folder),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
574 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
575 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
576
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
577 // category definitions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
578 if (!$this->driver->nocategories && !isset($no_override['calendar_categories'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
579 $p['blocks']['categories']['name'] = $this->gettext('categories');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
580
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
581 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
582 $p['blocks']['categories']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
583 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
584 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
585
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
586 $categories = (array) $this->driver->list_categories();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
587 $categories_list = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
588 foreach ($categories as $name => $color) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
589 $key = md5($name);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
590 $field_class = 'rcmfd_category_' . str_replace(' ', '_', $name);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
591 $category_remove = new html_inputfield(array('type' => 'button', 'value' => 'X', 'class' => 'button', 'onclick' => '$(this).parent().remove()', 'title' => $this->gettext('remove_category')));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
592 $category_name = new html_inputfield(array('name' => "_categories[$key]", 'class' => $field_class, 'size' => 30, 'disabled' => $this->driver->categoriesimmutable));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
593 $category_color = new html_inputfield(array('name' => "_colors[$key]", 'class' => "$field_class colors", 'size' => 6));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
594 $hidden = $this->driver->categoriesimmutable ? html::tag('input', array('type' => 'hidden', 'name' => "_categories[$key]", 'value' => $name)) : '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
595 $categories_list .= html::div(null, $hidden . $category_name->show($name) . '&nbsp;' . $category_color->show($color) . '&nbsp;' . $category_remove->show());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
596 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
597
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
598 $p['blocks']['categories']['options']['category_' . $name] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
599 'content' => html::div(array('id' => 'calendarcategories'), $categories_list),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
600 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
601
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
602 $field_id = 'rcmfd_new_category';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
603 $new_category = new html_inputfield(array('name' => '_new_category', 'id' => $field_id, 'size' => 30));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
604 $add_category = new html_inputfield(array('type' => 'button', 'class' => 'button', 'value' => $this->gettext('add_category'), 'onclick' => "rcube_calendar_add_category()"));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
605 $p['blocks']['categories']['options']['categories'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
606 'content' => $new_category->show('') . '&nbsp;' . $add_category->show(),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
607 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
608
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
609 $this->rc->output->add_script('function rcube_calendar_add_category(){
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
610 var name = $("#rcmfd_new_category").val();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
611 if (name.length) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
612 var input = $("<input>").attr("type", "text").attr("name", "_categories[]").attr("size", 30).val(name);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
613 var color = $("<input>").attr("type", "text").attr("name", "_colors[]").attr("size", 6).addClass("colors").val("000000");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
614 var button = $("<input>").attr("type", "button").attr("value", "X").addClass("button").click(function(){ $(this).parent().remove() });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
615 $("<div>").append(input).append("&nbsp;").append(color).append("&nbsp;").append(button).appendTo("#calendarcategories");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
616 color.miniColors({ colorValues:(rcmail.env.mscolors || []) });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
617 $("#rcmfd_new_category").val("");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
618 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
619 }');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
620
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
621 $this->rc->output->add_script('$("#rcmfd_new_category").keypress(function(event){
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
622 if (event.which == 13) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
623 rcube_calendar_add_category();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
624 event.preventDefault();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
625 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
626 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
627 ', 'docready');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
628
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
629 // load miniColors js/css files
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
630 jqueryui::miniColors();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
631 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
632
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
633 // virtual birthdays calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
634 if (!isset($no_override['calendar_contact_birthdays'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
635 $p['blocks']['birthdays']['name'] = $this->gettext('birthdayscalendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
636
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
637 if (!$p['current']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
638 $p['blocks']['birthdays']['content'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
639 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
640 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
641
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
642 $field_id = 'rcmfd_contact_birthdays';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
643 $input = new html_checkbox(array('name' => '_contact_birthdays', 'id' => $field_id, 'value' => 1, 'onclick' => '$(".calendar_birthday_props").prop("disabled",!this.checked)'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
644
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
645 $p['blocks']['birthdays']['options']['contact_birthdays'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
646 'title' => html::label($field_id, $this->gettext('displaybirthdayscalendar')),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
647 'content' => $input->show($this->rc->config->get('calendar_contact_birthdays')?1:0),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
648 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
649
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
650 $input_attrib = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
651 'class' => 'calendar_birthday_props',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
652 'disabled' => !$this->rc->config->get('calendar_contact_birthdays'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
653 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
654
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
655 $sources = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
656 $checkbox = new html_checkbox(array('name' => '_birthday_adressbooks[]') + $input_attrib);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
657 foreach ($this->rc->get_address_sources(false, true) as $source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
658 $active = in_array($source['id'], (array)$this->rc->config->get('calendar_birthday_adressbooks', array())) ? $source['id'] : '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
659 $sources[] = html::label(null, $checkbox->show($active, array('value' => $source['id'])) . '&nbsp;' . rcube::Q($source['realname'] ?: $source['name']));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
660 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
661
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
662 $p['blocks']['birthdays']['options']['birthday_adressbooks'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
663 'title' => rcube::Q($this->gettext('birthdayscalendarsources')),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
664 'content' => join(html::br(), $sources),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
665 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
666
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
667 $field_id = 'rcmfd_birthdays_alarm';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
668 $select_type = new html_select(array('name' => '_birthdays_alarm_type', 'id' => $field_id) + $input_attrib);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
669 $select_type->add($this->gettext('none'), '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
670 foreach ($this->driver->alarm_types as $type) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
671 $select_type->add($this->rc->gettext(strtolower("alarm{$type}option"), 'libcalendaring'), $type);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
672 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
673
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
674 $input_value = new html_inputfield(array('name' => '_birthdays_alarm_value', 'id' => $field_id . 'value', 'size' => 3) + $input_attrib);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
675 $select_offset = new html_select(array('name' => '_birthdays_alarm_offset', 'id' => $field_id . 'offset') + $input_attrib);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
676 foreach (array('-M','-H','-D') as $trigger)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
677 $select_offset->add($this->rc->gettext('trigger' . $trigger, 'libcalendaring'), $trigger);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
678
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
679 $preset = libcalendaring::parse_alarm_value($this->rc->config->get('calendar_birthdays_alarm_offset', '-1D'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
680 $p['blocks']['birthdays']['options']['birthdays_alarmoffset'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
681 'title' => html::label($field_id . 'value', rcube::Q($this->gettext('showalarms'))),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
682 'content' => $select_type->show($this->rc->config->get('calendar_birthdays_alarm_type', '')) . ' ' . $input_value->show($preset[0]) . '&nbsp;' . $select_offset->show($preset[1]),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
683 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
684 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
685
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
686 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
687 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
688
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
689 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
690 * Handler for preferences_save hook.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
691 * Executed on Calendar settings form submit.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
692 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
693 * @param array Original parameters
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
694 * @return array Modified parameters
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
695 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
696 function preferences_save($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
697 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
698 if ($p['section'] == 'calendar') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
699 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
700
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
701 // compose default alarm preset value
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
702 $alarm_offset = rcube_utils::get_input_value('_alarm_offset', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
703 $alarm_value = rcube_utils::get_input_value('_alarm_value', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
704 $default_alarm = $alarm_offset[0] . intval($alarm_value) . $alarm_offset[1];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
705
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
706 $birthdays_alarm_offset = rcube_utils::get_input_value('_birthdays_alarm_offset', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
707 $birthdays_alarm_value = rcube_utils::get_input_value('_birthdays_alarm_value', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
708 $birthdays_alarm_value = $birthdays_alarm_offset[0] . intval($birthdays_alarm_value) . $birthdays_alarm_offset[1];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
709
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
710 $p['prefs'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
711 'calendar_default_view' => rcube_utils::get_input_value('_default_view', rcube_utils::INPUT_POST),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
712 'calendar_timeslots' => intval(rcube_utils::get_input_value('_timeslots', rcube_utils::INPUT_POST)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
713 'calendar_first_day' => intval(rcube_utils::get_input_value('_first_day', rcube_utils::INPUT_POST)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
714 'calendar_first_hour' => intval(rcube_utils::get_input_value('_first_hour', rcube_utils::INPUT_POST)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
715 'calendar_work_start' => intval(rcube_utils::get_input_value('_work_start', rcube_utils::INPUT_POST)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
716 'calendar_work_end' => intval(rcube_utils::get_input_value('_work_end', rcube_utils::INPUT_POST)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
717 'calendar_event_coloring' => intval(rcube_utils::get_input_value('_event_coloring', rcube_utils::INPUT_POST)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
718 'calendar_default_alarm_type' => rcube_utils::get_input_value('_alarm_type', rcube_utils::INPUT_POST),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
719 'calendar_default_alarm_offset' => $default_alarm,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
720 'calendar_default_calendar' => rcube_utils::get_input_value('_default_calendar', rcube_utils::INPUT_POST),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
721 'calendar_date_format' => null, // clear previously saved values
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
722 'calendar_time_format' => null,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
723 'calendar_contact_birthdays' => rcube_utils::get_input_value('_contact_birthdays', rcube_utils::INPUT_POST) ? true : false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
724 'calendar_birthday_adressbooks' => (array) rcube_utils::get_input_value('_birthday_adressbooks', rcube_utils::INPUT_POST),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
725 'calendar_birthdays_alarm_type' => rcube_utils::get_input_value('_birthdays_alarm_type', rcube_utils::INPUT_POST),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
726 'calendar_birthdays_alarm_offset' => $birthdays_alarm_value ?: null,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
727 'calendar_itip_after_action' => intval(rcube_utils::get_input_value('_after_action', rcube_utils::INPUT_POST)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
728 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
729
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
730 if ($p['prefs']['calendar_itip_after_action'] == 4) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
731 $p['prefs']['calendar_itip_after_action'] = rcube_utils::get_input_value('_after_action_folder', rcube_utils::INPUT_POST, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
732 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
733
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
734 // categories
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
735 if (!$this->driver->nocategories) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
736 $old_categories = $new_categories = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
737 foreach ($this->driver->list_categories() as $name => $color) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
738 $old_categories[md5($name)] = $name;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
739 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
740
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
741 $categories = (array) rcube_utils::get_input_value('_categories', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
742 $colors = (array) rcube_utils::get_input_value('_colors', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
743
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
744 foreach ($categories as $key => $name) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
745 $color = preg_replace('/^#/', '', strval($colors[$key]));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
746
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
747 // rename categories in existing events -> driver's job
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
748 if ($oldname = $old_categories[$key]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
749 $this->driver->replace_category($oldname, $name, $color);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
750 unset($old_categories[$key]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
751 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
752 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
753 $this->driver->add_category($name, $color);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
754
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
755 $new_categories[$name] = $color;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
756 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
757
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
758 // these old categories have been removed, alter events accordingly -> driver's job
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
759 foreach ((array)$old_categories[$key] as $key => $name) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
760 $this->driver->remove_category($name);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
761 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
762
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
763 $p['prefs']['calendar_categories'] = $new_categories;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
764 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
765 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
766
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
767 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
768 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
769
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
770 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
771 * Dispatcher for calendar actions initiated by the client
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
772 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
773 function calendar_action()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
774 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
775 $action = rcube_utils::get_input_value('action', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
776 $cal = rcube_utils::get_input_value('c', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
777 $success = $reload = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
778
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
779 if (isset($cal['showalarms']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
780 $cal['showalarms'] = intval($cal['showalarms']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
781
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
782 switch ($action) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
783 case "form-new":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
784 case "form-edit":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
785 echo $this->ui->calendar_editform($action, $cal);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
786 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
787 case "new":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
788 $success = $this->driver->create_calendar($cal);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
789 $reload = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
790 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
791 case "edit":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
792 $success = $this->driver->edit_calendar($cal);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
793 $reload = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
794 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
795 case "delete":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
796 if ($success = $this->driver->delete_calendar($cal))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
797 $this->rc->output->command('plugin.destroy_source', array('id' => $cal['id']));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
798 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
799 case "subscribe":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
800 if (!$this->driver->subscribe_calendar($cal))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
801 $this->rc->output->show_message($this->gettext('errorsaving'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
802 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
803 $calendars = $this->driver->list_calendars();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
804 $calendar = $calendars[$cal['id']];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
805
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
806 // find parent folder and check if it's a "user calendar"
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
807 // if it's also activated we need to refresh it (#5340)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
808 while ($calendar['parent']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
809 if (isset($calendars[$calendar['parent']]))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
810 $calendar = $calendars[$calendar['parent']];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
811 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
812 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
813 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
814
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
815 if ($calendar['id'] != $cal['id'] && $calendar['active'] && $calendar['group'] == "other user")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
816 $this->rc->output->command('plugin.refresh_source', $calendar['id']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
817 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
818 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
819 case "search":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
820 $results = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
821 $color_mode = $this->rc->config->get('calendar_event_coloring', $this->defaults['calendar_event_coloring']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
822 $query = rcube_utils::get_input_value('q', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
823 $source = rcube_utils::get_input_value('source', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
824
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
825 foreach ((array) $this->driver->search_calendars($query, $source) as $id => $prop) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
826 $editname = $prop['editname'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
827 unset($prop['editname']); // force full name to be displayed
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
828 $prop['active'] = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
829
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
830 // let the UI generate HTML and CSS representation for this calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
831 $html = $this->ui->calendar_list_item($id, $prop, $jsenv);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
832 $cal = $jsenv[$id];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
833 $cal['editname'] = $editname;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
834 $cal['html'] = $html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
835 if (!empty($prop['color']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
836 $cal['css'] = $this->ui->calendar_css_classes($id, $prop, $color_mode);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
837
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
838 $results[] = $cal;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
839 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
840 // report more results available
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
841 if ($this->driver->search_more_results)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
842 $this->rc->output->show_message('autocompletemore', 'info');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
843
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
844 $this->rc->output->command('multi_thread_http_response', $results, rcube_utils::get_input_value('_reqid', rcube_utils::INPUT_GPC));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
845 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
846 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
847
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
848 if ($success)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
849 $this->rc->output->show_message('successfullysaved', 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
850 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
851 $error_msg = $this->gettext('errorsaving') . ($this->driver->last_error ? ': ' . $this->driver->last_error :'');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
852 $this->rc->output->show_message($error_msg, 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
853 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
854
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
855 $this->rc->output->command('plugin.unlock_saving');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
856
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
857 if ($success && $reload)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
858 $this->rc->output->command('plugin.reload_view');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
859 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
860
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
861
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
862 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
863 * Dispatcher for event actions initiated by the client
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
864 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
865 function event_action()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
866 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
867 $action = rcube_utils::get_input_value('action', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
868 $event = rcube_utils::get_input_value('e', rcube_utils::INPUT_POST, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
869 $success = $reload = $got_msg = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
870
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
871 // force notify if hidden + active
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
872 if ((int)$this->rc->config->get('calendar_itip_send_option', $this->defaults['calendar_itip_send_option']) === 1)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
873 $event['_notify'] = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
874
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
875 // read old event data in order to find changes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
876 if (($event['_notify'] || $event['_decline']) && $action != 'new') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
877 $old = $this->driver->get_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
878
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
879 // load main event if savemode is 'all' or if deleting 'future' events
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
880 if (($event['_savemode'] == 'all' || ($event['_savemode'] == 'future' && $action == 'remove' && !$event['_decline'])) && $old['recurrence_id']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
881 $old['id'] = $old['recurrence_id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
882 $old = $this->driver->get_event($old);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
883 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
884 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
885
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
886 switch ($action) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
887 case "new":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
888 // create UID for new event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
889 $event['uid'] = $this->generate_uid();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
890 $this->write_preprocess($event, $action);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
891 if ($success = $this->driver->new_event($event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
892 $event['id'] = $event['uid'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
893 $event['_savemode'] = 'all';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
894 $this->cleanup_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
895 $this->event_save_success($event, null, $action, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
896 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
897 $reload = $success && $event['recurrence'] ? 2 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
898 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
899
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
900 case "edit":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
901 $this->write_preprocess($event, $action);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
902 if ($success = $this->driver->edit_event($event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
903 $this->cleanup_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
904 $this->event_save_success($event, $old, $action, $success);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
905 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
906 $reload = $success && ($event['recurrence'] || $event['_savemode'] || $event['_fromcalendar']) ? 2 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
907 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
908
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
909 case "resize":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
910 $this->write_preprocess($event, $action);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
911 if ($success = $this->driver->resize_event($event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
912 $this->event_save_success($event, $old, $action, $success);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
913 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
914 $reload = $event['_savemode'] ? 2 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
915 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
916
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
917 case "move":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
918 $this->write_preprocess($event, $action);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
919 if ($success = $this->driver->move_event($event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
920 $this->event_save_success($event, $old, $action, $success);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
921 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
922 $reload = $success && $event['_savemode'] ? 2 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
923 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
924
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
925 case "remove":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
926 // remove previous deletes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
927 $undo_time = $this->driver->undelete ? $this->rc->config->get('undo_timeout', 0) : 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
928 $this->rc->session->remove('calendar_event_undo');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
929
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
930 // search for event if only UID is given
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
931 if (!isset($event['calendar']) && $event['uid']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
932 if (!($event = $this->driver->get_event($event, calendar_driver::FILTER_WRITEABLE))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
933 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
934 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
935 $undo_time = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
936 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
937
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
938 $success = $this->driver->remove_event($event, $undo_time < 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
939 $reload = (!$success || $event['_savemode']) ? 2 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
940
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
941 if ($undo_time > 0 && $success) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
942 $_SESSION['calendar_event_undo'] = array('ts' => time(), 'data' => $event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
943 // display message with Undo link.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
944 $msg = html::span(null, $this->gettext('successremoval'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
945 . ' ' . html::a(array('onclick' => sprintf("%s.http_request('event', 'action=undo', %s.display_message('', 'loading'))",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
946 rcmail_output::JS_OBJECT_NAME, rcmail_output::JS_OBJECT_NAME)), $this->gettext('undo'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
947 $this->rc->output->show_message($msg, 'confirmation', null, true, $undo_time);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
948 $got_msg = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
949 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
950 else if ($success) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
951 $this->rc->output->show_message('calendar.successremoval', 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
952 $got_msg = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
953 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
954
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
955 // send cancellation for the main event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
956 if ($event['_savemode'] == 'all') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
957 unset($old['_instance'], $old['recurrence_date'], $old['recurrence_id']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
958 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
959 // send an update for the main event's recurrence rule instead of a cancellation message
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
960 else if ($event['_savemode'] == 'future' && $success !== false && $success !== true) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
961 $event['_savemode'] = 'all'; // force event_save_success() to load master event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
962 $action = 'edit';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
963 $success = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
964 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
965
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
966 // send iTIP reply that participant has declined the event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
967 if ($success && $event['_decline']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
968 $emails = $this->get_user_emails();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
969 foreach ($old['attendees'] as $i => $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
970 if ($attendee['role'] == 'ORGANIZER')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
971 $organizer = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
972 else if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
973 $old['attendees'][$i]['status'] = 'DECLINED';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
974 $reply_sender = $attendee['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
975 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
976 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
977
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
978 if ($event['_savemode'] == 'future' && $event['id'] != $old['id']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
979 $old['thisandfuture'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
980 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
981
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
982 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
983 $itip->set_sender_email($reply_sender);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
984 if ($organizer && $itip->send_itip_message($old, 'REPLY', $organizer, 'itipsubjectdeclined', 'itipmailbodydeclined'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
985 $this->rc->output->command('display_message', $this->gettext(array('name' => 'sentresponseto', 'vars' => array('mailto' => $organizer['name'] ? $organizer['name'] : $organizer['email']))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
986 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
987 $this->rc->output->command('display_message', $this->gettext('itipresponseerror'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
988 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
989 else if ($success) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
990 $this->event_save_success($event, $old, $action, $success);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
991 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
992 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
993
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
994 case "undo":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
995 // Restore deleted event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
996 $event = $_SESSION['calendar_event_undo']['data'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
997
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
998 if ($event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
999 $success = $this->driver->restore_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1000
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1001 if ($success) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1002 $this->rc->session->remove('calendar_event_undo');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1003 $this->rc->output->show_message('calendar.successrestore', 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1004 $got_msg = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1005 $reload = 2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1006 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1007
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1008 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1009
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1010 case "rsvp":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1011 $itip_sending = $this->rc->config->get('calendar_itip_send_option', $this->defaults['calendar_itip_send_option']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1012 $status = rcube_utils::get_input_value('status', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1013 $attendees = rcube_utils::get_input_value('attendees', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1014 $reply_comment = $event['comment'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1015
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1016 $this->write_preprocess($event, 'edit');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1017 $ev = $this->driver->get_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1018 $ev['attendees'] = $event['attendees'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1019 $ev['free_busy'] = $event['free_busy'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1020 $ev['_savemode'] = $event['_savemode'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1021 $ev['comment'] = $reply_comment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1022
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1023 // send invitation to delegatee + add it as attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1024 if ($status == 'delegated' && $event['to']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1025 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1026 if ($itip->delegate_to($ev, $event['to'], (bool)$event['rsvp'], $attendees)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1027 $this->rc->output->show_message('calendar.itipsendsuccess', 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1028 $noreply = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1029 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1030 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1031
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1032 $event = $ev;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1033
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1034 // compose a list of attendees affected by this change
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1035 $updated_attendees = array_filter(array_map(function($j) use ($event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1036 return $event['attendees'][$j];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1037 }, $attendees));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1038
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1039 if ($success = $this->driver->edit_rsvp($event, $status, $updated_attendees)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1040 $noreply = rcube_utils::get_input_value('noreply', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1041 $noreply = intval($noreply) || $status == 'needs-action' || $itip_sending === 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1042 $reload = $event['calendar'] != $ev['calendar'] || $event['recurrence'] ? 2 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1043 $organizer = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1044 $emails = $this->get_user_emails();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1045
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1046 foreach ($event['attendees'] as $i => $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1047 if ($attendee['role'] == 'ORGANIZER') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1048 $organizer = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1049 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1050 else if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1051 $reply_sender = $attendee['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1052 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1053 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1054
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1055 if (!$noreply) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1056 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1057 $itip->set_sender_email($reply_sender);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1058 $event['thisandfuture'] = $event['_savemode'] == 'future';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1059 if ($organizer && $itip->send_itip_message($event, 'REPLY', $organizer, 'itipsubject' . $status, 'itipmailbody' . $status))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1060 $this->rc->output->command('display_message', $this->gettext(array('name' => 'sentresponseto', 'vars' => array('mailto' => $organizer['name'] ? $organizer['name'] : $organizer['email']))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1061 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1062 $this->rc->output->command('display_message', $this->gettext('itipresponseerror'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1063 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1064
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1065 // refresh all calendars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1066 if ($event['calendar'] != $ev['calendar']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1067 $this->rc->output->command('plugin.refresh_calendar', array('source' => null, 'refetch' => true));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1068 $reload = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1069 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1070 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1071 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1072
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1073 case "dismiss":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1074 $event['ids'] = explode(',', $event['id']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1075 $plugin = $this->rc->plugins->exec_hook('dismiss_alarms', $event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1076 $success = $plugin['success'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1077 foreach ($event['ids'] as $id) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1078 if (strpos($id, 'cal:') === 0)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1079 $success |= $this->driver->dismiss_alarm(substr($id, 4), $event['snooze']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1080 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1081 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1082
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1083 case "changelog":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1084 $data = $this->driver->get_event_changelog($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1085 if (is_array($data) && !empty($data)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1086 $lib = $this->lib;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1087 $dtformat = $this->rc->config->get('date_format') . ' ' . $this->rc->config->get('time_format');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1088 array_walk($data, function(&$change) use ($lib, $dtformat) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1089 if ($change['date']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1090 $dt = $lib->adjust_timezone($change['date']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1091 if ($dt instanceof DateTime)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1092 $change['date'] = $this->rc->format_date($dt, $dtformat, false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1093 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1094 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1095 $this->rc->output->command('plugin.render_event_changelog', $data);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1096 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1097 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1098 $this->rc->output->command('plugin.render_event_changelog', false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1099 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1100 $got_msg = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1101 $reload = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1102 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1103
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1104 case "diff":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1105 $data = $this->driver->get_event_diff($event, $event['rev1'], $event['rev2']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1106 if (is_array($data)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1107 // convert some properties, similar to self::_client_event()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1108 $lib = $this->lib;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1109 array_walk($data['changes'], function(&$change, $i) use ($event, $lib) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1110 // convert date cols
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1111 foreach (array('start','end','created','changed') as $col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1112 if ($change['property'] == $col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1113 $change['old'] = $lib->adjust_timezone($change['old'], strlen($change['old']) == 10)->format('c');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1114 $change['new'] = $lib->adjust_timezone($change['new'], strlen($change['new']) == 10)->format('c');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1115 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1116 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1117 // create textual representation for alarms and recurrence
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1118 if ($change['property'] == 'alarms') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1119 if (is_array($change['old']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1120 $change['old_'] = libcalendaring::alarm_text($change['old']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1121 if (is_array($change['new']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1122 $change['new_'] = libcalendaring::alarm_text(array_merge((array)$change['old'], $change['new']));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1123 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1124 if ($change['property'] == 'recurrence') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1125 if (is_array($change['old']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1126 $change['old_'] = $lib->recurrence_text($change['old']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1127 if (is_array($change['new']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1128 $change['new_'] = $lib->recurrence_text(array_merge((array)$change['old'], $change['new']));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1129 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1130 if ($change['property'] == 'attachments') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1131 if (is_array($change['old']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1132 $change['old']['classname'] = rcube_utils::file2class($change['old']['mimetype'], $change['old']['name']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1133 if (is_array($change['new']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1134 $change['new']['classname'] = rcube_utils::file2class($change['new']['mimetype'], $change['new']['name']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1135 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1136 // compute a nice diff of description texts
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1137 if ($change['property'] == 'description') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1138 $change['diff_'] = libkolab::html_diff($change['old'], $change['new']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1139 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1140 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1141 $this->rc->output->command('plugin.event_show_diff', $data);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1142 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1143 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1144 $this->rc->output->command('display_message', $this->gettext('objectdiffnotavailable'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1145 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1146 $got_msg = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1147 $reload = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1148 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1149
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1150 case "show":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1151 if ($event = $this->driver->get_event_revison($event, $event['rev'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1152 $this->rc->output->command('plugin.event_show_revision', $this->_client_event($event));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1153 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1154 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1155 $this->rc->output->command('display_message', $this->gettext('objectnotfound'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1156 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1157 $got_msg = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1158 $reload = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1159 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1160
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1161 case "restore":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1162 if ($success = $this->driver->restore_event_revision($event, $event['rev'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1163 $_event = $this->driver->get_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1164 $reload = $_event['recurrence'] ? 2 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1165 $this->rc->output->command('display_message', $this->gettext(array('name' => 'objectrestoresuccess', 'vars' => array('rev' => $event['rev']))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1166 $this->rc->output->command('plugin.close_history_dialog');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1167 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1168 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1169 $this->rc->output->command('display_message', $this->gettext('objectrestoreerror'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1170 $reload = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1171 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1172 $got_msg = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1173 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1174 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1175
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1176 // show confirmation/error message
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1177 if (!$got_msg) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1178 if ($success)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1179 $this->rc->output->show_message('successfullysaved', 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1180 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1181 $this->rc->output->show_message('calendar.errorsaving', 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1182 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1183
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1184 // unlock client
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1185 $this->rc->output->command('plugin.unlock_saving');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1186
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1187 // update event object on the client or trigger a complete refretch if too complicated
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1188 if ($reload) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1189 $args = array('source' => $event['calendar']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1190 if ($reload > 1)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1191 $args['refetch'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1192 else if ($success && $action != 'remove')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1193 $args['update'] = $this->_client_event($this->driver->get_event($event), true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1194 $this->rc->output->command('plugin.refresh_calendar', $args);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1195 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1196 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1197
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1198 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1199 * Helper method sending iTip notifications after successful event updates
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1200 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1201 private function event_save_success(&$event, $old, $action, $success)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1202 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1203 // $success is a new event ID
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1204 if ($success !== true) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1205 // send update notification on the main event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1206 if ($event['_savemode'] == 'future' && $event['_notify'] && $old['attendees'] && $old['recurrence_id']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1207 $master = $this->driver->get_event(array('id' => $old['recurrence_id'], 'calendar' => $old['calendar']), 0, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1208 unset($master['_instance'], $master['recurrence_date']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1209
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1210 $sent = $this->notify_attendees($master, null, $action, $event['_comment'], false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1211 if ($sent < 0)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1212 $this->rc->output->show_message('calendar.errornotifying', 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1213
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1214 $event['attendees'] = $master['attendees']; // this tricks us into the next if clause
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1215 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1216
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1217 // delete old reference if saved as new
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1218 if ($event['_savemode'] == 'future' || $event['_savemode'] == 'new') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1219 $old = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1220 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1221
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1222 $event['id'] = $success;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1223 $event['_savemode'] = 'all';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1224 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1225
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1226 // send out notifications
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1227 if ($event['_notify'] && ($event['attendees'] || $old['attendees'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1228 $_savemode = $event['_savemode'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1229
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1230 // send notification for the main event when savemode is 'all'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1231 if ($action != 'remove' && $_savemode == 'all' && ($event['recurrence_id'] || $old['recurrence_id'] || ($old && $old['id'] != $event['id']))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1232 $event['id'] = $event['recurrence_id'] ?: ($old['recurrence_id'] ?: $old['id']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1233 $event = $this->driver->get_event($event, 0, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1234 unset($event['_instance'], $event['recurrence_date']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1235 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1236 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1237 // make sure we have the complete record
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1238 $event = $action == 'remove' ? $old : $this->driver->get_event($event, 0, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1239 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1240
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1241 $event['_savemode'] = $_savemode;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1242
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1243 if ($old) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1244 $old['thisandfuture'] = $_savemode == 'future';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1245 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1246
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1247 // only notify if data really changed (TODO: do diff check on client already)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1248 if (!$old || $action == 'remove' || self::event_diff($event, $old)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1249 $sent = $this->notify_attendees($event, $old, $action, $event['_comment']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1250 if ($sent > 0)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1251 $this->rc->output->show_message('calendar.itipsendsuccess', 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1252 else if ($sent < 0)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1253 $this->rc->output->show_message('calendar.errornotifying', 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1254 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1255 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1256 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1257
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1258 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1259 * Handler for load-requests from fullcalendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1260 * This will return pure JSON formatted output
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1261 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1262 function load_events()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1263 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1264 $events = $this->driver->load_events(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1265 rcube_utils::get_input_value('start', rcube_utils::INPUT_GET),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1266 rcube_utils::get_input_value('end', rcube_utils::INPUT_GET),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1267 ($query = rcube_utils::get_input_value('q', rcube_utils::INPUT_GET)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1268 rcube_utils::get_input_value('source', rcube_utils::INPUT_GET)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1269 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1270 echo $this->encode($events, !empty($query));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1271 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1272 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1273
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1274 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1275 * Handler for requests fetching event counts for calendars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1276 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1277 public function count_events()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1278 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1279 // don't update session on these requests (avoiding race conditions)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1280 $this->rc->session->nowrite = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1281
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1282 $start = rcube_utils::get_input_value('start', rcube_utils::INPUT_GET);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1283 if (!$start) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1284 $start = new DateTime('today 00:00:00', $this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1285 $start = $start->format('U');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1286 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1287
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1288 $counts = $this->driver->count_events(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1289 rcube_utils::get_input_value('source', rcube_utils::INPUT_GET),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1290 $start,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1291 rcube_utils::get_input_value('end', rcube_utils::INPUT_GET)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1292 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1293
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1294 $this->rc->output->command('plugin.update_counts', array('counts' => $counts));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1295 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1296
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1297 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1298 * Load event data from an iTip message attachment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1299 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1300 public function itip_events($msgref)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1301 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1302 $path = explode('/', $msgref);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1303 $msg = array_pop($path);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1304 $mbox = join('/', $path);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1305 list($uid, $mime_id) = explode('#', $msg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1306 $events = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1307
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1308 if ($event = $this->lib->mail_get_itip_object($mbox, $uid, $mime_id, 'event')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1309 $partstat = 'NEEDS-ACTION';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1310 /*
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1311 $user_emails = $this->lib->get_user_emails();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1312 foreach ($event['attendees'] as $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1313 if (in_array($attendee['email'], $user_emails)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1314 $partstat = $attendee['status'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1315 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1316 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1317 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1318 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1319 $event['id'] = $event['uid'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1320 $event['temporary'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1321 $event['readonly'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1322 $event['calendar'] = '--invitation--itip';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1323 $event['className'] = 'fc-invitation-' . strtolower($partstat);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1324 $event['_mbox'] = $mbox;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1325 $event['_uid'] = $uid;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1326 $event['_part'] = $mime_id;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1327
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1328 $events[] = $this->_client_event($event, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1329
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1330 // add recurring instances
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1331 if (!empty($event['recurrence'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1332 foreach ($this->driver->get_recurring_events($event, $event['start']) as $recurring) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1333 $recurring['temporary'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1334 $recurring['readonly'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1335 $recurring['calendar'] = '--invitation--itip';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1336 $events[] = $this->_client_event($recurring, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1337 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1338 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1339 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1340
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1341 return $events;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1342 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1343
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1344 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1345 * Handler for keep-alive requests
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1346 * This will check for updated data in active calendars and sync them to the client
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1347 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1348 public function refresh($attr)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1349 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1350 // refresh the entire calendar every 10th time to also sync deleted events
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1351 if (rand(0,10) == 10) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1352 $this->rc->output->command('plugin.refresh_calendar', array('refetch' => true));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1353 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1354 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1355
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1356 $counts = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1357
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1358 foreach ($this->driver->list_calendars(calendar_driver::FILTER_ACTIVE) as $cal) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1359 $events = $this->driver->load_events(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1360 rcube_utils::get_input_value('start', rcube_utils::INPUT_GPC),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1361 rcube_utils::get_input_value('end', rcube_utils::INPUT_GPC),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1362 rcube_utils::get_input_value('q', rcube_utils::INPUT_GPC),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1363 $cal['id'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1364 1,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1365 $attr['last']
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1366 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1367
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1368 foreach ($events as $event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1369 $this->rc->output->command('plugin.refresh_calendar',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1370 array('source' => $cal['id'], 'update' => $this->_client_event($event)));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1371 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1372
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1373 // refresh count for this calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1374 if ($cal['counts']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1375 $today = new DateTime('today 00:00:00', $this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1376 $counts += $this->driver->count_events($cal['id'], $today->format('U'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1377 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1378 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1379
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1380 if (!empty($counts)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1381 $this->rc->output->command('plugin.update_counts', array('counts' => $counts));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1382 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1383 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1384
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1385 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1386 * Handler for pending_alarms plugin hook triggered by the calendar module on keep-alive requests.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1387 * This will check for pending notifications and pass them to the client
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1388 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1389 public function pending_alarms($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1390 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1391 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1392 $time = $p['time'] ?: time();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1393 if ($alarms = $this->driver->pending_alarms($time)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1394 foreach ($alarms as $alarm) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1395 $alarm['id'] = 'cal:' . $alarm['id']; // prefix ID with cal:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1396 $p['alarms'][] = $alarm;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1397 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1398 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1399
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1400 // get alarms for birthdays calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1401 if ($this->rc->config->get('calendar_contact_birthdays') && $this->rc->config->get('calendar_birthdays_alarm_type') == 'DISPLAY') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1402 $cache = $this->rc->get_cache('calendar.birthdayalarms', 'db');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1403
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1404 foreach ($this->driver->load_birthday_events($time, $time + 86400 * 60) as $e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1405 $alarm = libcalendaring::get_next_alarm($e);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1406
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1407 // overwrite alarm time with snooze value (or null if dismissed)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1408 if ($dismissed = $cache->get($e['id']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1409 $alarm['time'] = $dismissed['notifyat'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1410
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1411 // add to list if alarm is set
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1412 if ($alarm && $alarm['time'] && $alarm['time'] <= $time) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1413 $e['id'] = 'cal:bday:' . $e['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1414 $e['notifyat'] = $alarm['time'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1415 $p['alarms'][] = $e;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1416 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1417 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1418 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1419
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1420 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1421 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1422
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1423 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1424 * Handler for alarm dismiss hook triggered by libcalendaring
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1425 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1426 public function dismiss_alarms($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1427 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1428 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1429 foreach ((array)$p['ids'] as $id) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1430 if (strpos($id, 'cal:bday:') === 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1431 $p['success'] |= $this->driver->dismiss_birthday_alarm(substr($id, 9), $p['snooze']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1432 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1433 else if (strpos($id, 'cal:') === 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1434 $p['success'] |= $this->driver->dismiss_alarm(substr($id, 4), $p['snooze']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1435 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1436 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1437
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1438 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1439 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1440
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1441 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1442 * Handler for check-recent requests which are accidentally sent to calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1443 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1444 function check_recent()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1445 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1446 // NOP
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1447 $this->rc->output->send();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1448 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1449
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1450 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1451 * Hook triggered when a contact is saved
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1452 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1453 function contact_update($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1454 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1455 // clear birthdays calendar cache
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1456 if (!empty($p['record']['birthday'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1457 $cache = $this->rc->get_cache('calendar.birthdays', 'db');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1458 $cache->remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1459 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1460 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1461
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1462 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1463 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1464 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1465 function import_events()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1466 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1467 // Upload progress update
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1468 if (!empty($_GET['_progress'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1469 $this->rc->upload_progress();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1470 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1471
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1472 @set_time_limit(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1473
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1474 // process uploaded file if there is no error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1475 $err = $_FILES['_data']['error'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1476
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1477 if (!$err && $_FILES['_data']['tmp_name']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1478 $calendar = rcube_utils::get_input_value('calendar', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1479 $rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1480
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1481 // extract zip file
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1482 if ($_FILES['_data']['type'] == 'application/zip') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1483 $count = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1484 if (class_exists('ZipArchive', false)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1485 $zip = new ZipArchive();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1486 if ($zip->open($_FILES['_data']['tmp_name'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1487 $randname = uniqid('zip-' . session_id(), true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1488 $tmpdir = slashify($this->rc->config->get('temp_dir', sys_get_temp_dir())) . $randname;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1489 mkdir($tmpdir, 0700);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1490
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1491 // extract each ical file from the archive and import it
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1492 for ($i = 0; $i < $zip->numFiles; $i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1493 $filename = $zip->getNameIndex($i);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1494 if (preg_match('/\.ics$/i', $filename)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1495 $tmpfile = $tmpdir . '/' . basename($filename);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1496 if (copy('zip://' . $_FILES['_data']['tmp_name'] . '#'.$filename, $tmpfile)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1497 $count += $this->import_from_file($tmpfile, $calendar, $rangestart, $errors);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1498 unlink($tmpfile);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1499 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1500 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1501 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1502
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1503 rmdir($tmpdir);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1504 $zip->close();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1505 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1506 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1507 $errors = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1508 $msg = 'Failed to open zip file.';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1509 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1510 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1511 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1512 $errors = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1513 $msg = 'Zip files are not supported for import.';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1514 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1515 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1516 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1517 // attempt to import teh uploaded file directly
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1518 $count = $this->import_from_file($_FILES['_data']['tmp_name'], $calendar, $rangestart, $errors);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1519 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1520
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1521 if ($count) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1522 $this->rc->output->command('display_message', $this->gettext(array('name' => 'importsuccess', 'vars' => array('nr' => $count))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1523 $this->rc->output->command('plugin.import_success', array('source' => $calendar, 'refetch' => true));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1524 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1525 else if (!$errors) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1526 $this->rc->output->command('display_message', $this->gettext('importnone'), 'notice');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1527 $this->rc->output->command('plugin.import_success', array('source' => $calendar));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1528 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1529 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1530 $this->rc->output->command('plugin.import_error', array('message' => $this->gettext('importerror') . ($msg ? ': ' . $msg : '')));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1531 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1532 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1533 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1534 if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1535 $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1536 'size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1537 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1538 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1539 $msg = $this->rc->gettext('fileuploaderror');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1540 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1541
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1542 $this->rc->output->command('plugin.import_error', array('message' => $msg));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1543 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1544
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1545 $this->rc->output->send('iframe');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1546 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1547
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1548 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1549 * Helper function to parse and import a single .ics file
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1550 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1551 private function import_from_file($filepath, $calendar, $rangestart, &$errors)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1552 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1553 $user_email = $this->rc->user->get_username();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1554
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1555 $ical = $this->get_ical();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1556 $errors = !$ical->fopen($filepath);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1557 $count = $i = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1558 foreach ($ical as $event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1559 // keep the browser connection alive on long import jobs
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1560 if (++$i > 100 && $i % 100 == 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1561 echo "<!-- -->";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1562 ob_flush();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1563 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1564
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1565 // TODO: correctly handle recurring events which start before $rangestart
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1566 if ($event['end'] < $rangestart && (!$event['recurrence'] || ($event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart)))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1567 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1568
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1569 $event['_owner'] = $user_email;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1570 $event['calendar'] = $calendar;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1571 if ($this->driver->new_event($event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1572 $count++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1573 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1574 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1575 $errors++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1576 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1577 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1578
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1579 return $count;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1580 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1581
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1582
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1583 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1584 * Construct the ics file for exporting events to iCalendar format;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1585 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1586 function export_events($terminate = true)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1587 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1588 $start = rcube_utils::get_input_value('start', rcube_utils::INPUT_GET);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1589 $end = rcube_utils::get_input_value('end', rcube_utils::INPUT_GET);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1590
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1591 if (!isset($start))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1592 $start = 'today -1 year';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1593 if (!is_numeric($start))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1594 $start = strtotime($start . ' 00:00:00');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1595 if (!$end)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1596 $end = 'today +10 years';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1597 if (!is_numeric($end))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1598 $end = strtotime($end . ' 23:59:59');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1599
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1600 $event_id = rcube_utils::get_input_value('id', rcube_utils::INPUT_GET);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1601 $attachments = rcube_utils::get_input_value('attachments', rcube_utils::INPUT_GET);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1602 $calid = $filename = rcube_utils::get_input_value('source', rcube_utils::INPUT_GET);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1603
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1604 $calendars = $this->driver->list_calendars();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1605 $events = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1606
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1607 if ($calendars[$calid]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1608 $filename = $calendars[$calid]['name'] ? $calendars[$calid]['name'] : $calid;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1609 $filename = asciiwords(html_entity_decode($filename)); // to 7bit ascii
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1610 if (!empty($event_id)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1611 if ($event = $this->driver->get_event(array('calendar' => $calid, 'id' => $event_id), 0, true)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1612 if ($event['recurrence_id']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1613 $event = $this->driver->get_event(array('calendar' => $calid, 'id' => $event['recurrence_id']), 0, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1614 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1615 $events = array($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1616 $filename = asciiwords($event['title']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1617 if (empty($filename))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1618 $filename = 'event';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1619 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1620 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1621 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1622 $events = $this->driver->load_events($start, $end, null, $calid, 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1623 if (empty($filename))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1624 $filename = $calid;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1625 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1626 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1627
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1628 header("Content-Type: text/calendar");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1629 header("Content-Disposition: inline; filename=".$filename.'.ics');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1630
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1631 $this->get_ical()->export($events, '', true, $attachments ? array($this->driver, 'get_attachment_body') : null);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1632
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1633 if ($terminate)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1634 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1635 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1636
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1637
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1638 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1639 * Handler for iCal feed requests
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1640 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1641 function ical_feed_export()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1642 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1643 $session_exists = !empty($_SESSION['user_id']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1644
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1645 // process HTTP auth info
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1646 if (!empty($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1647 $_POST['_user'] = $_SERVER['PHP_AUTH_USER']; // used for rcmail::autoselect_host()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1648 $auth = $this->rc->plugins->exec_hook('authenticate', array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1649 'host' => $this->rc->autoselect_host(),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1650 'user' => trim($_SERVER['PHP_AUTH_USER']),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1651 'pass' => $_SERVER['PHP_AUTH_PW'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1652 'cookiecheck' => true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1653 'valid' => true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1654 ));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1655 if ($auth['valid'] && !$auth['abort'])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1656 $this->rc->login($auth['user'], $auth['pass'], $auth['host']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1657 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1658
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1659 // require HTTP auth
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1660 if (empty($_SESSION['user_id'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1661 header('WWW-Authenticate: Basic realm="Roundcube Calendar"');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1662 header('HTTP/1.0 401 Unauthorized');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1663 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1664 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1665
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1666 // decode calendar feed hash
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1667 $format = 'ics';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1668 $calhash = rcube_utils::get_input_value('_cal', rcube_utils::INPUT_GET);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1669 if (preg_match(($suff_regex = '/\.([a-z0-9]{3,5})$/i'), $calhash, $m)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1670 $format = strtolower($m[1]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1671 $calhash = preg_replace($suff_regex, '', $calhash);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1672 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1673
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1674 if (!strpos($calhash, ':'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1675 $calhash = base64_decode($calhash);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1676
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1677 list($user, $_GET['source']) = explode(':', $calhash, 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1678
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1679 // sanity check user
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1680 if ($this->rc->user->get_username() == $user) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1681 $this->setup();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1682 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1683 $this->export_events(false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1684 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1685 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1686 header('HTTP/1.0 404 Not Found');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1687 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1688
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1689 // don't save session data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1690 if (!$session_exists)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1691 session_destroy();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1692 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1693 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1694
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1695 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1696 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1697 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1698 function load_settings()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1699 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1700 $this->lib->load_settings();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1701 $this->defaults += $this->lib->defaults;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1702
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1703 $settings = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1704
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1705 // configuration
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1706 $settings['default_calendar'] = $this->rc->config->get('calendar_default_calendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1707 $settings['default_view'] = (string)$this->rc->config->get('calendar_default_view', $this->defaults['calendar_default_view']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1708 $settings['date_agenda'] = (string)$this->rc->config->get('calendar_date_agenda', $this->defaults['calendar_date_agenda']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1709
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1710 $settings['timeslots'] = (int)$this->rc->config->get('calendar_timeslots', $this->defaults['calendar_timeslots']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1711 $settings['first_day'] = (int)$this->rc->config->get('calendar_first_day', $this->defaults['calendar_first_day']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1712 $settings['first_hour'] = (int)$this->rc->config->get('calendar_first_hour', $this->defaults['calendar_first_hour']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1713 $settings['work_start'] = (int)$this->rc->config->get('calendar_work_start', $this->defaults['calendar_work_start']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1714 $settings['work_end'] = (int)$this->rc->config->get('calendar_work_end', $this->defaults['calendar_work_end']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1715 $settings['agenda_range'] = (int)$this->rc->config->get('calendar_agenda_range', $this->defaults['calendar_agenda_range']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1716 $settings['agenda_sections'] = $this->rc->config->get('calendar_agenda_sections', $this->defaults['calendar_agenda_sections']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1717 $settings['event_coloring'] = (int)$this->rc->config->get('calendar_event_coloring', $this->defaults['calendar_event_coloring']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1718 $settings['time_indicator'] = (int)$this->rc->config->get('calendar_time_indicator', $this->defaults['calendar_time_indicator']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1719 $settings['invite_shared'] = (int)$this->rc->config->get('calendar_allow_invite_shared', $this->defaults['calendar_allow_invite_shared']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1720 $settings['invitation_calendars'] = (bool)$this->rc->config->get('kolab_invitation_calendars', false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1721 $settings['itip_notify'] = (int)$this->rc->config->get('calendar_itip_send_option', $this->defaults['calendar_itip_send_option']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1722
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1723 // get user identity to create default attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1724 if ($this->ui->screen == 'calendar') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1725 foreach ($this->rc->user->list_emails() as $rec) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1726 if (!$identity)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1727 $identity = $rec;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1728 $identity['emails'][] = $rec['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1729 $settings['identities'][$rec['identity_id']] = $rec['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1730 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1731 $identity['emails'][] = $this->rc->user->get_username();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1732 $settings['identity'] = array('name' => $identity['name'], 'email' => strtolower($identity['email']), 'emails' => ';' . strtolower(join(';', $identity['emails'])));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1733 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1734
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1735 return $settings;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1736 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1737
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1738 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1739 * Encode events as JSON
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1740 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1741 * @param array Events as array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1742 * @param boolean Add CSS class names according to calendar and categories
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1743 * @return string JSON encoded events
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1744 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1745 function encode($events, $addcss = false)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1746 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1747 $json = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1748 foreach ($events as $event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1749 $json[] = $this->_client_event($event, $addcss);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1750 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1751 return rcube_output::json_serialize($json);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1752 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1753
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1754 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1755 * Convert an event object to be used on the client
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1756 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1757 private function _client_event($event, $addcss = false)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1758 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1759 // compose a human readable strings for alarms_text and recurrence_text
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1760 if ($event['valarms']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1761 $event['alarms_text'] = libcalendaring::alarms_text($event['valarms']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1762 $event['valarms'] = libcalendaring::to_client_alarms($event['valarms']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1763 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1764 if ($event['recurrence']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1765 $event['recurrence_text'] = $this->lib->recurrence_text($event['recurrence']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1766 $event['recurrence'] = $this->lib->to_client_recurrence($event['recurrence'], $event['allday']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1767 unset($event['recurrence_date']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1768 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1769
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1770 foreach ((array)$event['attachments'] as $k => $attachment) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1771 $event['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1772
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1773 unset($event['attachments'][$k]['data'], $event['attachments'][$k]['content']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1774
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1775 if (!$attachment['id']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1776 $event['attachments'][$k]['id'] = $k;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1777 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1778 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1779
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1780 // convert link URIs references into structs
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1781 if (array_key_exists('links', $event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1782 foreach ((array) $event['links'] as $i => $link) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1783 if (strpos($link, 'imap://') === 0 && ($msgref = $this->driver->get_message_reference($link))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1784 $event['links'][$i] = $msgref;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1785 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1786 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1787 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1788
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1789 // check for organizer in attendees list
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1790 $organizer = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1791 foreach ((array)$event['attendees'] as $i => $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1792 if ($attendee['role'] == 'ORGANIZER') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1793 $organizer = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1794 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1795 if ($attendee['status'] == 'DELEGATED' && $attendee['rsvp'] == false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1796 $event['attendees'][$i]['noreply'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1797 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1798 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1799 unset($event['attendees'][$i]['noreply']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1800 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1801 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1802
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1803 if ($organizer === null && !empty($event['organizer'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1804 $organizer = $event['organizer'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1805 $organizer['role'] = 'ORGANIZER';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1806 if (!is_array($event['attendees']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1807 $event['attendees'] = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1808 array_unshift($event['attendees'], $organizer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1809 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1810
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1811 // Convert HTML description into plain text
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1812 if ($this->is_html($event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1813 $h2t = new rcube_html2text($event['description'], false, true, 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1814 $event['description'] = trim($h2t->get_text());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1815 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1816
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1817 // mapping url => vurl because of the fullcalendar client script
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1818 $event['vurl'] = $event['url'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1819 unset($event['url']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1820
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1821 return array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1822 '_id' => $event['calendar'] . ':' . $event['id'], // unique identifier for fullcalendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1823 'start' => $this->lib->adjust_timezone($event['start'], $event['allday'])->format('c'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1824 'end' => $this->lib->adjust_timezone($event['end'], $event['allday'])->format('c'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1825 // 'changed' might be empty for event recurrences (Bug #2185)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1826 'changed' => $event['changed'] ? $this->lib->adjust_timezone($event['changed'])->format('c') : null,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1827 'created' => $event['created'] ? $this->lib->adjust_timezone($event['created'])->format('c') : null,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1828 'title' => strval($event['title']),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1829 'description' => strval($event['description']),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1830 'location' => strval($event['location']),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1831 'className' => ($addcss ? 'fc-event-cal-'.asciiwords($event['calendar'], true).' ' : '') .
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1832 'fc-event-cat-' . asciiwords(strtolower(join('-', (array)$event['categories'])), true) .
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1833 rtrim(' ' . $event['className']),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1834 'allDay' => ($event['allday'] == 1),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1835 ) + $event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1836 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1837
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1838
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1839 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1840 * Generate a unique identifier for an event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1841 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1842 public function generate_uid()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1843 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1844 return strtoupper(md5(time() . uniqid(rand())) . '-' . substr(md5($this->rc->user->get_username()), 0, 16));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1845 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1846
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1847
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1848 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1849 * TEMPORARY: generate random event data for testing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1850 * Create events by opening http://<roundcubeurl>/?_task=calendar&_action=randomdata&_num=500&_date=2014-08-01&_dev=120
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1851 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1852 public function generate_randomdata()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1853 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1854 @set_time_limit(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1855
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1856 $num = $_REQUEST['_num'] ? intval($_REQUEST['_num']) : 100;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1857 $date = $_REQUEST['_date'] ?: 'now';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1858 $dev = $_REQUEST['_dev'] ?: 30;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1859 $cats = array_keys($this->driver->list_categories());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1860 $cals = $this->driver->list_calendars(calendar_driver::FILTER_ACTIVE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1861 $count = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1862
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1863 while ($count++ < $num) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1864 $spread = intval($dev) * 86400; // days
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1865 $refdate = strtotime($date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1866 $start = round(($refdate + rand(-$spread, $spread)) / 600) * 600;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1867 $duration = round(rand(30, 360) / 30) * 30 * 60;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1868 $allday = rand(0,20) > 18;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1869 $alarm = rand(-30,12) * 5;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1870 $fb = rand(0,2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1871
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1872 if (date('G', $start) > 23)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1873 $start -= 3600;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1874
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1875 if ($allday) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1876 $start = strtotime(date('Y-m-d 00:00:00', $start));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1877 $duration = 86399;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1878 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1879
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1880 $title = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1881 $len = rand(2, 12);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1882 $words = explode(" ", "The Hough transform is named after Paul Hough who patented the method in 1962. It is a technique which can be used to isolate features of a particular shape within an image. Because it requires that the desired features be specified in some parametric form, the classical Hough transform is most commonly used for the de- tection of regular curves such as lines, circles, ellipses, etc. A generalized Hough transform can be employed in applications where a simple analytic description of a feature(s) is not possible. Due to the computational complexity of the generalized Hough algorithm, we restrict the main focus of this discussion to the classical Hough transform. Despite its domain restrictions, the classical Hough transform (hereafter referred to without the classical prefix ) retains many applications, as most manufac- tured parts (and many anatomical parts investigated in medical imagery) contain feature boundaries which can be described by regular curves. The main advantage of the Hough transform technique is that it is tolerant of gaps in feature boundary descriptions and is relatively unaffected by image noise.");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1883 // $chars = "!# abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1884 for ($i = 0; $i < $len; $i++)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1885 $title .= $words[rand(0,count($words)-1)] . " ";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1886
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1887 $this->driver->new_event(array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1888 'uid' => $this->generate_uid(),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1889 'start' => new DateTime('@'.$start),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1890 'end' => new DateTime('@'.($start + $duration)),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1891 'allday' => $allday,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1892 'title' => rtrim($title),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1893 'free_busy' => $fb == 2 ? 'outofoffice' : ($fb ? 'busy' : 'free'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1894 'categories' => $cats[array_rand($cats)],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1895 'calendar' => array_rand($cals),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1896 'alarms' => $alarm > 0 ? "-{$alarm}M:DISPLAY" : '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1897 'priority' => rand(0,9),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1898 ));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1899 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1900
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1901 $this->rc->output->redirect('');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1902 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1903
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1904 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1905 * Handler for attachments upload
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1906 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1907 public function attachment_upload()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1908 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1909 $this->lib->attachment_upload(self::SESSION_KEY, 'cal-');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1910 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1911
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1912 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1913 * Handler for attachments download/displaying
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1914 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1915 public function attachment_get()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1916 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1917 // show loading page
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1918 if (!empty($_GET['_preload'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1919 return $this->lib->attachment_loading_page();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1920 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1921
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1922 $event_id = rcube_utils::get_input_value('_event', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1923 $calendar = rcube_utils::get_input_value('_cal', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1924 $id = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1925 $rev = rcube_utils::get_input_value('_rev', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1926
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1927 $event = array('id' => $event_id, 'calendar' => $calendar, 'rev' => $rev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1928
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1929 if ($calendar == '--invitation--itip') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1930 $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1931 $part = rcube_utils::get_input_value('_part', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1932 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1933
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1934 $event = $this->lib->mail_get_itip_object($mbox, $uid, $part, 'event');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1935 $attachment = $event['attachments'][$id];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1936 $attachment['body'] = &$attachment['data'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1937 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1938 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1939 $attachment = $this->driver->get_attachment($id, $event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1940 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1941
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1942 // show part page
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1943 if (!empty($_GET['_frame'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1944 $this->lib->attachment = $attachment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1945 $this->register_handler('plugin.attachmentframe', array($this->lib, 'attachment_frame'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1946 $this->register_handler('plugin.attachmentcontrols', array($this->lib, 'attachment_header'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1947 $this->rc->output->send('calendar.attachment');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1948 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1949 // deliver attachment content
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1950 else if ($attachment) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1951 if ($calendar != '--invitation--itip') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1952 $attachment['body'] = $this->driver->get_attachment_body($id, $event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1953 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1954
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1955 $this->lib->attachment_get($attachment);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1956 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1957
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1958 // if we arrive here, the requested part was not found
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1959 header('HTTP/1.1 404 Not Found');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1960 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1961 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1962
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1963 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1964 * Determine whether the given event description is HTML formatted
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1965 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1966 private function is_html($event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1967 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1968 // check for opening and closing <html> or <body> tags
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1969 return (preg_match('/<(html|body)(\s+[a-z]|>)/', $event['description'], $m) && strpos($event['description'], '</'.$m[1].'>') > 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1970 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1971
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1972 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1973 * Prepares new/edited event properties before save
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1974 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1975 private function write_preprocess(&$event, $action)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1976 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1977 // convert dates into DateTime objects in user's current timezone
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1978 $event['start'] = new DateTime($event['start'], $this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1979 $event['end'] = new DateTime($event['end'], $this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1980 $event['allday'] = (bool)$event['allday'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1981
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1982 // start/end is all we need for 'move' action (#1480)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1983 if ($action == 'move') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1984 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1985 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1986
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1987 // convert the submitted recurrence settings
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1988 if (is_array($event['recurrence'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1989 $event['recurrence'] = $this->lib->from_client_recurrence($event['recurrence'], $event['start']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1990 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1991
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1992 // convert the submitted alarm values
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1993 if ($event['valarms']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1994 $event['valarms'] = libcalendaring::from_client_alarms($event['valarms']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1995 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1996
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1997 $attachments = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1998 $eventid = 'cal-'.$event['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1999
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2000 if (is_array($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY]['id'] == $eventid) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2001 if (!empty($_SESSION[self::SESSION_KEY]['attachments'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2002 foreach ($_SESSION[self::SESSION_KEY]['attachments'] as $id => $attachment) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2003 if (is_array($event['attachments']) && in_array($id, $event['attachments'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2004 $attachments[$id] = $this->rc->plugins->exec_hook('attachment_get', $attachment);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2005 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2006 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2007 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2008 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2009
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2010 $event['attachments'] = $attachments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2011
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2012 // convert link references into simple URIs
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2013 if (array_key_exists('links', $event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2014 $event['links'] = array_map(function($link) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2015 return is_array($link) ? $link['uri'] : strval($link);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2016 }, (array)$event['links']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2017 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2018
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2019 // check for organizer in attendees
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2020 if ($action == 'new' || $action == 'edit') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2021 if (!$event['attendees'])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2022 $event['attendees'] = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2023
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2024 $emails = $this->get_user_emails();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2025 $organizer = $owner = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2026 foreach ((array)$event['attendees'] as $i => $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2027 if ($attendee['role'] == 'ORGANIZER')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2028 $organizer = $i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2029 if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2030 $owner = $i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2031 if (!isset($attendee['rsvp']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2032 $event['attendees'][$i]['rsvp'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2033 else if (is_string($attendee['rsvp']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2034 $event['attendees'][$i]['rsvp'] = $attendee['rsvp'] == 'true' || $attendee['rsvp'] == '1';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2035 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2036
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2037 if (!empty($event['_identity'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2038 $identity = $this->rc->user->get_identity($event['_identity']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2039 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2040
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2041 // set new organizer identity
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2042 if ($organizer !== false && $identity) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2043 $event['attendees'][$organizer]['name'] = $identity['name'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2044 $event['attendees'][$organizer]['email'] = $identity['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2045 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2046 // set owner as organizer if yet missing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2047 else if ($organizer === false && $owner !== false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2048 $event['attendees'][$owner]['role'] = 'ORGANIZER';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2049 unset($event['attendees'][$owner]['rsvp']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2050 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2051 // fallback to the selected identity
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2052 else if ($organizer === false && $identity) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2053 $event['attendees'][] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2054 'role' => 'ORGANIZER',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2055 'name' => $identity['name'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2056 'email' => $identity['email'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2057 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2058 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2059 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2060
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2061 // mapping url => vurl because of the fullcalendar client script
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2062 if (array_key_exists('vurl', $event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2063 $event['url'] = $event['vurl'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2064 unset($event['vurl']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2065 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2066 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2067
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2068 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2069 * Releases some resources after successful event save
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2070 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2071 private function cleanup_event(&$event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2072 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2073 // remove temp. attachment files
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2074 if (!empty($_SESSION[self::SESSION_KEY]) && ($eventid = $_SESSION[self::SESSION_KEY]['id'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2075 $this->rc->plugins->exec_hook('attachments_cleanup', array('group' => $eventid));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2076 $this->rc->session->remove(self::SESSION_KEY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2077 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2078 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2079
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2080 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2081 * Send out an invitation/notification to all event attendees
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2082 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2083 private function notify_attendees($event, $old, $action = 'edit', $comment = null, $rsvp = null)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2084 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2085 if ($action == 'remove' || ($event['status'] == 'CANCELLED' && $old['status'] != $event['status'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2086 $event['cancelled'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2087 $is_cancelled = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2088 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2089
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2090 if ($rsvp === null)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2091 $rsvp = !$old || $event['sequence'] > $old['sequence'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2092
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2093 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2094 $emails = $this->get_user_emails();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2095 $itip_notify = (int)$this->rc->config->get('calendar_itip_send_option', $this->defaults['calendar_itip_send_option']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2096
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2097 // add comment to the iTip attachment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2098 $event['comment'] = $comment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2099
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2100 // set a valid recurrence-id if this is a recurrence instance
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2101 libcalendaring::identify_recurrence_instance($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2102
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2103 // compose multipart message using PEAR:Mail_Mime
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2104 $method = $action == 'remove' ? 'CANCEL' : 'REQUEST';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2105 $message = $itip->compose_itip_message($event, $method, $rsvp);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2106
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2107 // list existing attendees from $old event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2108 $old_attendees = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2109 foreach ((array)$old['attendees'] as $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2110 $old_attendees[] = $attendee['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2111 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2112
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2113 // send to every attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2114 $sent = 0; $current = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2115 foreach ((array)$event['attendees'] as $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2116 $current[] = strtolower($attendee['email']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2117
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2118 // skip myself for obvious reasons
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2119 if (!$attendee['email'] || in_array(strtolower($attendee['email']), $emails))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2120 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2121
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2122 // skip if notification is disabled for this attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2123 if ($attendee['noreply'] && $itip_notify & 2)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2124 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2125
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2126 // skip if this attendee has delegated and set RSVP=FALSE
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2127 if ($attendee['status'] == 'DELEGATED' && $attendee['rsvp'] === false)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2128 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2129
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2130 // which template to use for mail text
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2131 $is_new = !in_array($attendee['email'], $old_attendees);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2132 $is_rsvp = $is_new || $event['sequence'] > $old['sequence'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2133 $bodytext = $is_cancelled ? 'eventcancelmailbody' : ($is_new ? 'invitationmailbody' : 'eventupdatemailbody');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2134 $subject = $is_cancelled ? 'eventcancelsubject' : ($is_new ? 'invitationsubject' : ($event['title'] ? 'eventupdatesubject':'eventupdatesubjectempty'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2135
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2136 $event['comment'] = $comment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2137
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2138 // finally send the message
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2139 if ($itip->send_itip_message($event, $method, $attendee, $subject, $bodytext, $message, $is_rsvp))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2140 $sent++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2141 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2142 $sent = -100;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2143 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2144
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2145 // TODO: on change of a recurring (main) event, also send updates to differing attendess of recurrence exceptions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2146
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2147 // send CANCEL message to removed attendees
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2148 foreach ((array)$old['attendees'] as $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2149 if ($attendee['role'] == 'ORGANIZER' || !$attendee['email'] || in_array(strtolower($attendee['email']), $current))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2150 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2151
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2152 $vevent = $old;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2153 $vevent['cancelled'] = $is_cancelled;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2154 $vevent['attendees'] = array($attendee);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2155 $vevent['comment'] = $comment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2156 if ($itip->send_itip_message($vevent, 'CANCEL', $attendee, 'eventcancelsubject', 'eventcancelmailbody'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2157 $sent++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2158 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2159 $sent = -100;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2160 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2161
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2162 return $sent;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2163 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2164
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2165 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2166 * Echo simple free/busy status text for the given user and time range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2167 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2168 public function freebusy_status()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2169 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2170 $email = rcube_utils::get_input_value('email', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2171 $start = rcube_utils::get_input_value('start', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2172 $end = rcube_utils::get_input_value('end', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2173
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2174 // convert dates into unix timestamps
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2175 if (!empty($start) && !is_numeric($start)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2176 $dts = new DateTime($start, $this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2177 $start = $dts->format('U');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2178 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2179 if (!empty($end) && !is_numeric($end)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2180 $dte = new DateTime($end, $this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2181 $end = $dte->format('U');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2182 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2183
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2184 if (!$start) $start = time();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2185 if (!$end) $end = $start + 3600;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2186
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2187 $fbtypemap = array(calendar::FREEBUSY_UNKNOWN => 'UNKNOWN', calendar::FREEBUSY_FREE => 'FREE', calendar::FREEBUSY_BUSY => 'BUSY', calendar::FREEBUSY_TENTATIVE => 'TENTATIVE', calendar::FREEBUSY_OOF => 'OUT-OF-OFFICE');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2188 $status = 'UNKNOWN';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2189
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2190 // if the backend has free-busy information
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2191 $fblist = $this->driver->get_freebusy_list($email, $start, $end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2192
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2193 if (is_array($fblist)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2194 $status = 'FREE';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2195
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2196 foreach ($fblist as $slot) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2197 list($from, $to, $type) = $slot;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2198 if ($from < $end && $to > $start) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2199 $status = isset($type) && $fbtypemap[$type] ? $fbtypemap[$type] : 'BUSY';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2200 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2201 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2202 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2203 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2204
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2205 // let this information be cached for 5min
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2206 $this->rc->output->future_expire_header(300);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2207
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2208 echo $status;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2209 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2210 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2211
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2212 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2213 * Return a list of free/busy time slots within the given period
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2214 * Echo data in JSON encoding
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2215 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2216 public function freebusy_times()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2217 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2218 $email = rcube_utils::get_input_value('email', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2219 $start = rcube_utils::get_input_value('start', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2220 $end = rcube_utils::get_input_value('end', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2221 $interval = intval(rcube_utils::get_input_value('interval', rcube_utils::INPUT_GPC));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2222 $strformat = $interval > 60 ? 'Ymd' : 'YmdHis';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2223
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2224 // convert dates into unix timestamps
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2225 if (!empty($start) && !is_numeric($start)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2226 $dts = rcube_utils::anytodatetime($start, $this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2227 $start = $dts ? $dts->format('U') : null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2228 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2229 if (!empty($end) && !is_numeric($end)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2230 $dte = rcube_utils::anytodatetime($end, $this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2231 $end = $dte ? $dte->format('U') : null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2232 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2233
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2234 if (!$start) $start = time();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2235 if (!$end) $end = $start + 86400 * 30;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2236 if (!$interval) $interval = 60; // 1 hour
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2237
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2238 if (!$dte) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2239 $dts = new DateTime('@'.$start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2240 $dts->setTimezone($this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2241 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2242
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2243 $fblist = $this->driver->get_freebusy_list($email, $start, $end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2244 $slots = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2245
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2246 // prepare freebusy list before use (for better performance)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2247 if (is_array($fblist)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2248 foreach ($fblist as $idx => $slot) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2249 list($from, $to, ) = $slot;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2250
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2251 // check for possible all-day times
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2252 if (gmdate('His', $from) == '000000' && gmdate('His', $to) == '235959') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2253 // shift into the user's timezone for sane matching
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2254 $fblist[$idx][0] -= $this->gmt_offset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2255 $fblist[$idx][1] -= $this->gmt_offset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2256 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2257 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2258 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2259
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2260 // build a list from $start till $end with blocks representing the fb-status
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2261 for ($s = 0, $t = $start; $t <= $end; $s++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2262 $t_end = $t + $interval * 60;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2263 $dt = new DateTime('@'.$t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2264 $dt->setTimezone($this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2265
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2266 // determine attendee's status
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2267 if (is_array($fblist)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2268 $status = self::FREEBUSY_FREE;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2269
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2270 foreach ($fblist as $slot) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2271 list($from, $to, $type) = $slot;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2272
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2273 if ($from < $t_end && $to > $t) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2274 $status = isset($type) ? $type : self::FREEBUSY_BUSY;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2275 if ($status == self::FREEBUSY_BUSY) // can't get any worse :-)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2276 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2277 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2278 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2279 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2280 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2281 $status = self::FREEBUSY_UNKNOWN;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2282 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2283
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2284 // use most compact format, assume $status is one digit/character
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2285 $slots .= $status;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2286 $t = $t_end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2287 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2288
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2289 $dte = new DateTime('@'.$t_end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2290 $dte->setTimezone($this->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2291
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2292 // let this information be cached for 5min
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2293 $this->rc->output->future_expire_header(300);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2294
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2295 echo rcube_output::json_serialize(array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2296 'email' => $email,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2297 'start' => $dts->format('c'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2298 'end' => $dte->format('c'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2299 'interval' => $interval,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2300 'slots' => $slots,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2301 ));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2302 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2303 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2304
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2305 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2306 * Handler for printing calendars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2307 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2308 public function print_view()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2309 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2310 $title = $this->gettext('print');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2311
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2312 $view = rcube_utils::get_input_value('view', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2313 if (!in_array($view, array('agendaWeek', 'agendaDay', 'month', 'table')))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2314 $view = 'agendaDay';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2315
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2316 $this->rc->output->set_env('view',$view);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2317
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2318 if ($date = rcube_utils::get_input_value('date', rcube_utils::INPUT_GPC))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2319 $this->rc->output->set_env('date', $date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2320
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2321 if ($range = rcube_utils::get_input_value('range', rcube_utils::INPUT_GPC))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2322 $this->rc->output->set_env('listRange', intval($range));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2323
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2324 if (isset($_REQUEST['sections']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2325 $this->rc->output->set_env('listSections', rcube_utils::get_input_value('sections', rcube_utils::INPUT_GPC));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2326
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2327 if ($search = rcube_utils::get_input_value('search', rcube_utils::INPUT_GPC)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2328 $this->rc->output->set_env('search', $search);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2329 $title .= ' "' . $search . '"';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2330 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2331
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2332 // Add CSS stylesheets to the page header
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2333 $skin_path = $this->local_skin_path();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2334 $this->include_stylesheet($skin_path . '/fullcalendar.css');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2335 $this->include_stylesheet($skin_path . '/print.css');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2336
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2337 // Add JS files to the page header
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2338 $this->include_script('print.js');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2339 $this->include_script('lib/js/fullcalendar.js');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2340
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2341 $this->register_handler('plugin.calendar_css', array($this->ui, 'calendar_css'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2342 $this->register_handler('plugin.calendar_list', array($this->ui, 'calendar_list'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2343
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2344 $this->rc->output->set_pagetitle($title);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2345 $this->rc->output->send("calendar.print");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2346 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2347
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2348 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2349 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2350 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2351 public function get_inline_ui()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2352 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2353 foreach (array('save','cancel','savingdata') as $label)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2354 $texts['calendar.'.$label] = $this->gettext($label);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2355
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2356 $texts['calendar.new_event'] = $this->gettext('createfrommail');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2357
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2358 $this->ui->init_templates();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2359 $this->ui->calendar_list(); # set env['calendars']
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2360 echo $this->api->output->parse('calendar.eventedit', false, false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2361 echo html::tag('script', array('type' => 'text/javascript'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2362 "rcmail.set_env('calendars', " . rcube_output::json_serialize($this->api->output->env['calendars']) . ");\n".
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2363 "rcmail.set_env('deleteicon', '" . $this->api->output->env['deleteicon'] . "');\n".
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2364 "rcmail.set_env('cancelicon', '" . $this->api->output->env['cancelicon'] . "');\n".
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2365 "rcmail.set_env('loadingicon', '" . $this->api->output->env['loadingicon'] . "');\n".
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2366 "rcmail.gui_object('attachmentlist', '" . $this->ui->attachmentlist_id . "');\n".
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2367 "rcmail.add_label(" . rcube_output::json_serialize($texts) . ");\n"
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2368 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2369 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2370 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2371
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2372 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2373 * Compare two event objects and return differing properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2374 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2375 * @param array Event A
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2376 * @param array Event B
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2377 * @return array List of differing event properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2378 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2379 public static function event_diff($a, $b)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2380 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2381 $diff = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2382 $ignore = array('changed' => 1, 'attachments' => 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2383 foreach (array_unique(array_merge(array_keys($a), array_keys($b))) as $key) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2384 if (!$ignore[$key] && $key[0] != '_' && $a[$key] != $b[$key])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2385 $diff[] = $key;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2386 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2387
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2388 // only compare number of attachments
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2389 if (count($a['attachments']) != count($b['attachments']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2390 $diff[] = 'attachments';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2391
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2392 return $diff;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2393 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2394
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2395 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2396 * Update attendee properties on the given event object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2397 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2398 * @param array The event object to be altered
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2399 * @param array List of hash arrays each represeting an updated/added attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2400 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2401 public static function merge_attendee_data(&$event, $attendees, $removed = null)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2402 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2403 if (!empty($attendees) && !is_array($attendees[0])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2404 $attendees = array($attendees);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2405 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2406
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2407 foreach ($attendees as $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2408 $found = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2409
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2410 foreach ($event['attendees'] as $i => $candidate) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2411 if ($candidate['email'] == $attendee['email']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2412 $event['attendees'][$i] = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2413 $found = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2414 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2415 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2416 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2417
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2418 if (!$found) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2419 $event['attendees'][] = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2420 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2421 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2422
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2423 // filter out removed attendees
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2424 if (!empty($removed)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2425 $event['attendees'] = array_filter($event['attendees'], function($attendee) use ($removed) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2426 return !in_array($attendee['email'], $removed);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2427 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2428 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2429 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2430
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2431
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2432 /**** Resource management functions ****/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2433
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2434 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2435 * Getter for the configured implementation of the resource directory interface
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2436 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2437 private function resources_directory()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2438 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2439 if (is_object($this->resources_dir)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2440 return $this->resources_dir;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2441 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2442
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2443 if ($driver_name = $this->rc->config->get('calendar_resources_driver')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2444 $driver_class = 'resources_driver_' . $driver_name;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2445
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2446 require_once($this->home . '/drivers/resources_driver.php');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2447 require_once($this->home . '/drivers/' . $driver_name . '/' . $driver_class . '.php');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2448
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2449 $this->resources_dir = new $driver_class($this);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2450 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2451
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2452 return $this->resources_dir;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2453 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2454
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2455 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2456 * Handler for resoruce autocompletion requests
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2457 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2458 public function resources_autocomplete()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2459 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2460 $search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2461 $sid = rcube_utils::get_input_value('_reqid', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2462 $maxnum = (int)$this->rc->config->get('autocomplete_max', 15);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2463 $results = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2464
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2465 if ($directory = $this->resources_directory()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2466 foreach ($directory->load_resources($search, $maxnum) as $rec) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2467 $results[] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2468 'name' => $rec['name'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2469 'email' => $rec['email'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2470 'type' => $rec['_type'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2471 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2472 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2473 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2474
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2475 $this->rc->output->command('ksearch_query_results', $results, $search, $sid);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2476 $this->rc->output->send();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2477 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2478
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2479 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2480 * Handler for load-requests for resource data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2481 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2482 function resources_list()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2483 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2484 $data = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2485
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2486 if ($directory = $this->resources_directory()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2487 foreach ($directory->load_resources() as $rec) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2488 $data[] = $rec;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2489 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2490 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2491
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2492 $this->rc->output->command('plugin.resource_data', $data);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2493 $this->rc->output->send();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2494 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2495
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2496 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2497 * Handler for requests loading resource owner information
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2498 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2499 function resources_owner()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2500 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2501 if ($directory = $this->resources_directory()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2502 $id = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2503 $data = $directory->get_resource_owner($id);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2504 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2505
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2506 $this->rc->output->command('plugin.resource_owner', $data);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2507 $this->rc->output->send();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2508 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2509
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2510 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2511 * Deliver event data for a resource's calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2512 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2513 function resources_calendar()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2514 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2515 $events = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2516
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2517 if ($directory = $this->resources_directory()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2518 $events = $directory->get_resource_calendar(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2519 rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2520 rcube_utils::get_input_value('start', rcube_utils::INPUT_GET),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2521 rcube_utils::get_input_value('end', rcube_utils::INPUT_GET));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2522 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2523
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2524 echo $this->encode($events);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2525 exit;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2526 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2527
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2528
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2529 /**** Event invitation plugin hooks ****/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2530
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2531 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2532 * Find an event in user calendars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2533 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2534 protected function find_event($event, &$mode)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2535 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2536 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2537
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2538 // We search for writeable calendars in personal namespace by default
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2539 $mode = calendar_driver::FILTER_WRITEABLE | calendar_driver::FILTER_PERSONAL;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2540 $result = $this->driver->get_event($event, $mode);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2541 // ... now check shared folders if not found
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2542 if (!$result) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2543 $result = $this->driver->get_event($event, calendar_driver::FILTER_WRITEABLE | calendar_driver::FILTER_SHARED);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2544 if ($result) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2545 $mode |= calendar_driver::FILTER_SHARED;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2546 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2547 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2548
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2549 return $result;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2550 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2551
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2552 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2553 * Handler for calendar/itip-status requests
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2554 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2555 function event_itip_status()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2556 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2557 $data = rcube_utils::get_input_value('data', rcube_utils::INPUT_POST, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2558
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2559 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2560
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2561 // find local copy of the referenced event (in personal namespace)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2562 $existing = $this->find_event($data, $mode);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2563 $is_shared = $mode & calendar_driver::FILTER_SHARED;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2564 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2565 $response = $itip->get_itip_status($data, $existing);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2566
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2567 // get a list of writeable calendars to save new events to
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2568 if ((!$existing || $is_shared)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2569 && !$data['nosave']
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2570 && ($response['action'] == 'rsvp' || $response['action'] == 'import')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2571 ) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2572 $calendars = $this->driver->list_calendars($mode);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2573 $calendar_select = new html_select(array('name' => 'calendar', 'id' => 'itip-saveto', 'is_escaped' => true));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2574 $calendar_select->add('--', '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2575 $numcals = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2576 foreach ($calendars as $calendar) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2577 if ($calendar['editable']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2578 $calendar_select->add($calendar['name'], $calendar['id']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2579 $numcals++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2580 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2581 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2582 if ($numcals < 1)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2583 $calendar_select = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2584 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2585
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2586 if ($calendar_select) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2587 $default_calendar = $this->get_default_calendar($data['sensitivity'], $calendars);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2588 $response['select'] = html::span('folder-select', $this->gettext('saveincalendar') . '&nbsp;' .
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2589 $calendar_select->show($is_shared ? $existing['calendar'] : $default_calendar['id']));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2590 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2591 else if ($data['nosave']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2592 $response['select'] = html::tag('input', array('type' => 'hidden', 'name' => 'calendar', 'id' => 'itip-saveto', 'value' => ''));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2593 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2594
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2595 // render small agenda view for the respective day
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2596 if ($data['method'] == 'REQUEST' && !empty($data['date']) && $response['action'] == 'rsvp') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2597 $event_start = rcube_utils::anytodatetime($data['date']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2598 $day_start = new Datetime(gmdate('Y-m-d 00:00', $data['date']), $this->lib->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2599 $day_end = new Datetime(gmdate('Y-m-d 23:59', $data['date']), $this->lib->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2600
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2601 // get events on that day from the user's personal calendars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2602 $calendars = $this->driver->list_calendars(calendar_driver::FILTER_PERSONAL);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2603 $events = $this->driver->load_events($day_start->format('U'), $day_end->format('U'), null, array_keys($calendars));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2604 usort($events, function($a, $b) { return $a['start'] > $b['start'] ? 1 : -1; });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2605
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2606 $before = $after = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2607 foreach ($events as $event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2608 // TODO: skip events with free_busy == 'free' ?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2609 if ($event['uid'] == $data['uid'] || $event['end'] < $day_start || $event['start'] > $day_end)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2610 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2611 else if ($event['start'] < $event_start)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2612 $before[] = $this->mail_agenda_event_row($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2613 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2614 $after[] = $this->mail_agenda_event_row($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2615 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2616
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2617 $response['append'] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2618 'selector' => '.calendar-agenda-preview',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2619 'replacements' => array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2620 '%before%' => !empty($before) ? join("\n", array_slice($before, -3)) : html::div('event-row no-event', $this->gettext('noearlierevents')),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2621 '%after%' => !empty($after) ? join("\n", array_slice($after, 0, 3)) : html::div('event-row no-event', $this->gettext('nolaterevents')),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2622 ),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2623 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2624 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2625
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2626 $this->rc->output->command('plugin.update_itip_object_status', $response);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2627 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2628
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2629 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2630 * Handler for calendar/itip-remove requests
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2631 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2632 function event_itip_remove()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2633 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2634 $success = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2635 $uid = rcube_utils::get_input_value('uid', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2636 $instance = rcube_utils::get_input_value('_instance', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2637 $savemode = rcube_utils::get_input_value('_savemode', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2638 $listmode = calendar_driver::FILTER_WRITEABLE | calendar_driver::FILTER_PERSONAL;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2639
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2640 // search for event if only UID is given
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2641 if ($event = $this->driver->get_event(array('uid' => $uid, '_instance' => $instance), $listmode)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2642 $event['_savemode'] = $savemode;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2643 $success = $this->driver->remove_event($event, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2644 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2645
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2646 if ($success) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2647 $this->rc->output->show_message('calendar.successremoval', 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2648 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2649 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2650 $this->rc->output->show_message('calendar.errorsaving', 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2651 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2652 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2653
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2654 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2655 * Handler for URLs that allow an invitee to respond on his invitation mail
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2656 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2657 public function itip_attend_response($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2658 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2659 $this->setup();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2660
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2661 if ($p['action'] == 'attend') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2662 $this->ui->init();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2663
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2664 $this->rc->output->set_env('task', 'calendar'); // override some env vars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2665 $this->rc->output->set_env('refresh_interval', 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2666 $this->rc->output->set_pagetitle($this->gettext('calendar'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2667
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2668 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2669 $token = rcube_utils::get_input_value('_t', rcube_utils::INPUT_GPC);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2670
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2671 // read event info stored under the given token
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2672 if ($invitation = $itip->get_invitation($token)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2673 $this->token = $token;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2674 $this->event = $invitation['event'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2675
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2676 // show message about cancellation
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2677 if ($invitation['cancelled']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2678 $this->invitestatus = html::div('rsvp-status declined', $itip->gettext('eventcancelled'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2679 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2680 // save submitted RSVP status
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2681 else if (!empty($_POST['rsvp'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2682 $status = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2683 foreach (array('accepted','tentative','declined') as $method) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2684 if ($_POST['rsvp'] == $itip->gettext('itip' . $method)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2685 $status = $method;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2686 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2687 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2688 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2689
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2690 // send itip reply to organizer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2691 $invitation['event']['comment'] = rcube_utils::get_input_value('_comment', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2692 if ($status && $itip->update_invitation($invitation, $invitation['attendee'], strtoupper($status))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2693 $this->invitestatus = html::div('rsvp-status ' . strtolower($status), $itip->gettext('youhave'.strtolower($status)));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2694 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2695 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2696 $this->rc->output->command('display_message', $this->gettext('errorsaving'), 'error', -1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2697
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2698 // if user is logged in...
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2699 // FIXME: we should really consider removing this functionality
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2700 // it's confusing that it creates/updates an event only for logged-in user
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2701 // what if the logged-in user is not the same as the attendee?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2702 if ($this->rc->user->ID) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2703 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2704
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2705 $invitation = $itip->get_invitation($token);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2706 $existing = $this->driver->get_event($this->event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2707
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2708 // save the event to his/her default calendar if not yet present
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2709 if (!$existing && ($calendar = $this->get_default_calendar($invitation['event']['sensitivity']))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2710 $invitation['event']['calendar'] = $calendar['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2711 if ($this->driver->new_event($invitation['event']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2712 $this->rc->output->command('display_message', $this->gettext(array('name' => 'importedsuccessfully', 'vars' => array('calendar' => $calendar['name']))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2713 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2714 $this->rc->output->command('display_message', $this->gettext('errorimportingevent'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2715 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2716 else if ($existing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2717 && ($this->event['sequence'] >= $existing['sequence'] || $this->event['changed'] >= $existing['changed'])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2718 && ($calendar = $this->driver->get_calendar($existing['calendar']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2719 ) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2720 $this->event = $invitation['event'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2721 $this->event['id'] = $existing['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2722
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2723 unset($this->event['comment']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2724
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2725 // merge attendees status
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2726 // e.g. preserve my participant status for regular updates
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2727 $this->lib->merge_attendees($this->event, $existing, $status);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2728
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2729 // update attachments list
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2730 $event['deleted_attachments'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2731
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2732 // show me as free when declined (#1670)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2733 if ($status == 'declined')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2734 $this->event['free_busy'] = 'free';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2735
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2736 if ($this->driver->edit_event($this->event))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2737 $this->rc->output->command('display_message', $this->gettext(array('name' => 'updatedsuccessfully', 'vars' => array('calendar' => $calendar->get_name()))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2738 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2739 $this->rc->output->command('display_message', $this->gettext('errorimportingevent'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2740 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2741 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2742 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2743
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2744 $this->register_handler('plugin.event_inviteform', array($this, 'itip_event_inviteform'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2745 $this->register_handler('plugin.event_invitebox', array($this->ui, 'event_invitebox'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2746
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2747 if (!$this->invitestatus) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2748 $this->itip->set_rsvp_actions(array('accepted','tentative','declined'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2749 $this->register_handler('plugin.event_rsvp_buttons', array($this->ui, 'event_rsvp_buttons'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2750 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2751
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2752 $this->rc->output->set_pagetitle($itip->gettext('itipinvitation') . ' ' . $this->event['title']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2753 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2754 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2755 $this->rc->output->command('display_message', $this->gettext('itipinvalidrequest'), 'error', -1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2756
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2757 $this->rc->output->send('calendar.itipattend');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2758 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2759 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2760
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2761 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2762 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2763 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2764 public function itip_event_inviteform($attrib)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2765 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2766 $hidden = new html_hiddenfield(array('name' => "_t", 'value' => $this->token));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2767 return html::tag('form', array('action' => $this->rc->url(array('task' => 'calendar', 'action' => 'attend')), 'method' => 'post', 'noclose' => true) + $attrib) . $hidden->show();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2768 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2769
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2770 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2771 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2772 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2773 private function mail_agenda_event_row($event, $class = '')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2774 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2775 $time = $event['allday'] ? $this->gettext('all-day') :
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2776 $this->rc->format_date($event['start'], $this->rc->config->get('time_format')) . ' - ' .
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2777 $this->rc->format_date($event['end'], $this->rc->config->get('time_format'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2778
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2779 return html::div(rtrim('event-row ' . $class),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2780 html::span('event-date', $time) .
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2781 html::span('event-title', rcube::Q($event['title']))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2782 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2783 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2784
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2785 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2786 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2787 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2788 public function mail_messages_list($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2789 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2790 if (in_array('attachment', (array)$p['cols']) && !empty($p['messages'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2791 foreach ($p['messages'] as $header) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2792 $part = new StdClass;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2793 $part->mimetype = $header->ctype;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2794 if (libcalendaring::part_is_vcalendar($part)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2795 $header->list_flags['attachmentClass'] = 'ical';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2796 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2797 else if (in_array($header->ctype, array('multipart/alternative', 'multipart/mixed'))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2798 // TODO: fetch bodystructure and search for ical parts. Maybe too expensive?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2799
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2800 if (!empty($header->structure) && is_array($header->structure->parts)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2801 foreach ($header->structure->parts as $part) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2802 if (libcalendaring::part_is_vcalendar($part) && !empty($part->ctype_parameters['method'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2803 $header->list_flags['attachmentClass'] = 'ical';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2804 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2805 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2806 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2807 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2808 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2809 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2810 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2811 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2812
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2813 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2814 * Add UI element to copy event invitations or updates to the calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2815 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2816 public function mail_messagebody_html($p)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2817 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2818 // load iCalendar functions (if necessary)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2819 if (!empty($this->lib->ical_parts)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2820 $this->get_ical();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2821 $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2822 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2823
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2824 $html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2825 $has_events = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2826 $ical_objects = $this->lib->get_mail_ical_objects();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2827
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2828 // show a box for every event in the file
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2829 foreach ($ical_objects as $idx => $event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2830 if ($event['_type'] != 'event') // skip non-event objects (#2928)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2831 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2832
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2833 $has_events = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2834
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2835 // get prepared inline UI for this event object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2836 if ($ical_objects->method) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2837 $append = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2838
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2839 // prepare a small agenda preview to be filled with actual event data on async request
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2840 if ($ical_objects->method == 'REQUEST') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2841 $append = html::div('calendar-agenda-preview',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2842 html::tag('h3', 'preview-title', $this->gettext('agenda') . ' ' .
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2843 html::span('date', $this->rc->format_date($event['start'], $this->rc->config->get('date_format')))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2844 ) . '%before%' . $this->mail_agenda_event_row($event, 'current') . '%after%');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2845 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2846
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2847 $html .= html::div('calendar-invitebox',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2848 $this->itip->mail_itip_inline_ui(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2849 $event,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2850 $ical_objects->method,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2851 $ical_objects->mime_id . ':' . $idx,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2852 'calendar',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2853 rcube_utils::anytodatetime($ical_objects->message_date),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2854 $this->rc->url(array('task' => 'calendar')) . '&view=agendaDay&date=' . $event['start']->format('U')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2855 ) . $append
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2856 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2857 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2858
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2859 // limit listing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2860 if ($idx >= 3)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2861 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2862 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2863
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2864 // prepend event boxes to message body
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2865 if ($html) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2866 $this->ui->init();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2867 $p['content'] = $html . $p['content'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2868 $this->rc->output->add_label('calendar.savingdata','calendar.deleteventconfirm','calendar.declinedeleteconfirm');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2869 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2870
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2871 // add "Save to calendar" button into attachment menu
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2872 if ($has_events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2873 $this->add_button(array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2874 'id' => 'attachmentsavecal',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2875 'name' => 'attachmentsavecal',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2876 'type' => 'link',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2877 'wrapper' => 'li',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2878 'command' => 'attachment-save-calendar',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2879 'class' => 'icon calendarlink',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2880 'classact' => 'icon calendarlink active',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2881 'innerclass' => 'icon calendar',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2882 'label' => 'calendar.savetocalendar',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2883 ), 'attachmentmenu');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2884 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2885
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2886 return $p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2887 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2888
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2889
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2890 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2891 * Handler for POST request to import an event attached to a mail message
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2892 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2893 public function mail_import_itip()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2894 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2895 $itip_sending = $this->rc->config->get('calendar_itip_send_option', $this->defaults['calendar_itip_send_option']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2896
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2897 $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2898 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2899 $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2900 $status = rcube_utils::get_input_value('_status', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2901 $delete = intval(rcube_utils::get_input_value('_del', rcube_utils::INPUT_POST));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2902 $noreply = intval(rcube_utils::get_input_value('_noreply', rcube_utils::INPUT_POST));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2903 $noreply = $noreply || $status == 'needs-action' || $itip_sending === 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2904 $instance = rcube_utils::get_input_value('_instance', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2905 $savemode = rcube_utils::get_input_value('_savemode', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2906 $comment = rcube_utils::get_input_value('_comment', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2907
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2908 $error_msg = $this->gettext('errorimportingevent');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2909 $success = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2910
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2911 if ($status == 'delegated') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2912 $delegates = rcube_mime::decode_address_list(rcube_utils::get_input_value('_to', rcube_utils::INPUT_POST, true), 1, false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2913 $delegate = reset($delegates);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2914
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2915 if (empty($delegate) || empty($delegate['mailto'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2916 $this->rc->output->command('display_message', $this->rc->gettext('libcalendaring.delegateinvalidaddress'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2917 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2918 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2919 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2920
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2921 // successfully parsed events?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2922 if ($event = $this->lib->mail_get_itip_object($mbox, $uid, $mime_id, 'event')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2923 // forward iTip request to delegatee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2924 if ($delegate) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2925 $rsvpme = rcube_utils::get_input_value('_rsvp', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2926 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2927
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2928 $event['comment'] = $comment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2929
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2930 if ($itip->delegate_to($event, $delegate, !empty($rsvpme))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2931 $this->rc->output->show_message('calendar.itipsendsuccess', 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2932 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2933 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2934 $this->rc->output->command('display_message', $this->gettext('itipresponseerror'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2935 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2936
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2937 unset($event['comment']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2938
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2939 // the delegator is set to non-participant, thus save as non-blocking
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2940 $event['free_busy'] = 'free';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2941 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2942
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2943 $mode = calendar_driver::FILTER_PERSONAL
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2944 | calendar_driver::FILTER_SHARED
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2945 | calendar_driver::FILTER_WRITEABLE;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2946
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2947 // find writeable calendar to store event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2948 $cal_id = rcube_utils::get_input_value('_folder', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2949 $dontsave = $cal_id === '' && $event['_method'] == 'REQUEST';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2950 $calendars = $this->driver->list_calendars($mode);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2951 $calendar = $calendars[$cal_id];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2952
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2953 // select default calendar except user explicitly selected 'none'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2954 if (!$calendar && !$dontsave)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2955 $calendar = $this->get_default_calendar($event['sensitivity'], $calendars);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2956
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2957 $metadata = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2958 'uid' => $event['uid'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2959 '_instance' => $event['_instance'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2960 'changed' => is_object($event['changed']) ? $event['changed']->format('U') : 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2961 'sequence' => intval($event['sequence']),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2962 'fallback' => strtoupper($status),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2963 'method' => $event['_method'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2964 'task' => 'calendar',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2965 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2966
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2967 // update my attendee status according to submitted method
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2968 if (!empty($status)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2969 $organizer = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2970 $emails = $this->get_user_emails();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2971 foreach ($event['attendees'] as $i => $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2972 if ($attendee['role'] == 'ORGANIZER') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2973 $organizer = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2974 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2975 else if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2976 $event['attendees'][$i]['status'] = strtoupper($status);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2977 if (!in_array($event['attendees'][$i]['status'], array('NEEDS-ACTION','DELEGATED')))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2978 $event['attendees'][$i]['rsvp'] = false; // unset RSVP attribute
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2979
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2980 $metadata['attendee'] = $attendee['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2981 $metadata['rsvp'] = $attendee['role'] != 'NON-PARTICIPANT';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2982 $reply_sender = $attendee['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2983 $event_attendee = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2984 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2985 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2986
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2987 // add attendee with this user's default identity if not listed
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2988 if (!$reply_sender) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2989 $sender_identity = $this->rc->user->list_emails(true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2990 $event['attendees'][] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2991 'name' => $sender_identity['name'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2992 'email' => $sender_identity['email'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2993 'role' => 'OPT-PARTICIPANT',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2994 'status' => strtoupper($status),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2995 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2996 $metadata['attendee'] = $sender_identity['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2997 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2998 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2999
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3000 // save to calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3001 if ($calendar && $calendar['editable']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3002 // check for existing event with the same UID
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3003 $existing = $this->find_event($event, $mode);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3004
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3005 // we'll create a new copy if user decided to change the calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3006 if ($existing && $cal_id && $calendar && $calendar['id'] != $existing['calendar']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3007 $existing = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3008 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3009
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3010 if ($existing) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3011 $calendar = $calendars[$existing['calendar']];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3012
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3013 // forward savemode for correct updates of recurring events
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3014 $existing['_savemode'] = $savemode ?: $event['_savemode'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3015
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3016 // only update attendee status
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3017 if ($event['_method'] == 'REPLY') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3018 // try to identify the attendee using the email sender address
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3019 $existing_attendee = -1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3020 $existing_attendee_emails = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3021 foreach ($existing['attendees'] as $i => $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3022 $existing_attendee_emails[] = $attendee['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3023 if ($this->itip->compare_email($attendee['email'], $event['_sender'], $event['_sender_utf'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3024 $existing_attendee = $i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3025 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3026 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3027 $event_attendee = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3028 $update_attendees = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3029 foreach ($event['attendees'] as $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3030 if ($this->itip->compare_email($attendee['email'], $event['_sender'], $event['_sender_utf'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3031 $event_attendee = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3032 $update_attendees[] = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3033 $metadata['fallback'] = $attendee['status'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3034 $metadata['attendee'] = $attendee['email'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3035 $metadata['rsvp'] = $attendee['rsvp'] || $attendee['role'] != 'NON-PARTICIPANT';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3036 if ($attendee['status'] != 'DELEGATED') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3037 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3038 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3039 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3040 // also copy delegate attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3041 else if (!empty($attendee['delegated-from'])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3042 && $this->itip->compare_email($attendee['delegated-from'], $event['_sender'], $event['_sender_utf'])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3043 ) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3044 $update_attendees[] = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3045 if (!in_array_nocase($attendee['email'], $existing_attendee_emails)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3046 $existing['attendees'][] = $attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3047 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3048 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3049 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3050
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3051 // if delegatee has declined, set delegator's RSVP=True
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3052 if ($event_attendee && $event_attendee['status'] == 'DECLINED' && $event_attendee['delegated-from']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3053 foreach ($existing['attendees'] as $i => $attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3054 if ($attendee['email'] == $event_attendee['delegated-from']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3055 $existing['attendees'][$i]['rsvp'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3056 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3057 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3058 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3059 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3060
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3061 // found matching attendee entry in both existing and new events
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3062 if ($existing_attendee >= 0 && $event_attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3063 $existing['attendees'][$existing_attendee] = $event_attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3064 $success = $this->driver->update_attendees($existing, $update_attendees);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3065 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3066 // update the entire attendees block
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3067 else if (($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) && $event_attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3068 $existing['attendees'][] = $event_attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3069 $success = $this->driver->update_attendees($existing, $update_attendees);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3070 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3071 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3072 $error_msg = $this->gettext('newerversionexists');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3073 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3074 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3075 // delete the event when declined (#1670)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3076 else if ($status == 'declined' && $delete) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3077 $deleted = $this->driver->remove_event($existing, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3078 $success = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3079 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3080 // import the (newer) event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3081 else if ($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3082 $event['id'] = $existing['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3083 $event['calendar'] = $existing['calendar'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3084
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3085 // merge attendees status
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3086 // e.g. preserve my participant status for regular updates
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3087 $this->lib->merge_attendees($event, $existing, $status);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3088
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3089 // set status=CANCELLED on CANCEL messages
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3090 if ($event['_method'] == 'CANCEL')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3091 $event['status'] = 'CANCELLED';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3092
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3093 // update attachments list, allow attachments update only on REQUEST (#5342)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3094 if ($event['_method'] == 'REQUEST')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3095 $event['deleted_attachments'] = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3096 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3097 unset($event['attachments']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3098
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3099 // show me as free when declined (#1670)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3100 if ($status == 'declined' || $event['status'] == 'CANCELLED' || $event_attendee['role'] == 'NON-PARTICIPANT')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3101 $event['free_busy'] = 'free';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3102
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3103 $success = $this->driver->edit_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3104 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3105 else if (!empty($status)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3106 $existing['attendees'] = $event['attendees'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3107 if ($status == 'declined' || $event_attendee['role'] == 'NON-PARTICIPANT') // show me as free when declined (#1670)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3108 $existing['free_busy'] = 'free';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3109 $success = $this->driver->edit_event($existing);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3110 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3111 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3112 $error_msg = $this->gettext('newerversionexists');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3113 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3114 else if (!$existing && ($status != 'declined' || $this->rc->config->get('kolab_invitation_calendars'))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3115 if ($status == 'declined' || $event['status'] == 'CANCELLED' || $event_attendee['role'] == 'NON-PARTICIPANT') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3116 $event['free_busy'] = 'free';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3117 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3118
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3119 // if the RSVP reply only refers to a single instance:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3120 // store unmodified master event with current instance as exception
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3121 if (!empty($instance) && !empty($savemode) && $savemode != 'all') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3122 $master = $this->lib->mail_get_itip_object($mbox, $uid, $mime_id, 'event');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3123 if ($master['recurrence'] && !$master['_instance']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3124 // compute recurring events until this instance's date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3125 if ($recurrence_date = rcube_utils::anytodatetime($instance, $master['start']->getTimezone())) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3126 $recurrence_date->setTime(23,59,59);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3127
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3128 foreach ($this->driver->get_recurring_events($master, $master['start'], $recurrence_date) as $recurring) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3129 if ($recurring['_instance'] == $instance) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3130 // copy attendees block with my partstat to exception
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3131 $recurring['attendees'] = $event['attendees'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3132 $master['recurrence']['EXCEPTIONS'][] = $recurring;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3133 $event = $recurring; // set reference for iTip reply
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3134 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3135 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3136 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3137
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3138 $master['calendar'] = $event['calendar'] = $calendar['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3139 $success = $this->driver->new_event($master);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3140 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3141 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3142 $master = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3143 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3144 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3145 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3146 $master = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3147 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3148 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3149
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3150 // save to the selected/default calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3151 if (!$master) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3152 $event['calendar'] = $calendar['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3153 $success = $this->driver->new_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3154 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3155 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3156 else if ($status == 'declined')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3157 $error_msg = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3158 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3159 else if ($status == 'declined' || $dontsave)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3160 $error_msg = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3161 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3162 $error_msg = $this->gettext('nowritecalendarfound');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3163 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3164
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3165 if ($success) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3166 $message = $event['_method'] == 'REPLY' ? 'attendeupdateesuccess' : ($deleted ? 'successremoval' : ($existing ? 'updatedsuccessfully' : 'importedsuccessfully'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3167 $this->rc->output->command('display_message', $this->gettext(array('name' => $message, 'vars' => array('calendar' => $calendar['name']))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3168 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3169
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3170 if ($success || $dontsave) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3171 $metadata['calendar'] = $event['calendar'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3172 $metadata['nosave'] = $dontsave;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3173 $metadata['rsvp'] = intval($metadata['rsvp']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3174 $metadata['after_action'] = $this->rc->config->get('calendar_itip_after_action', $this->defaults['calendar_itip_after_action']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3175 $this->rc->output->command('plugin.itip_message_processed', $metadata);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3176 $error_msg = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3177 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3178 else if ($error_msg) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3179 $this->rc->output->command('display_message', $error_msg, 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3180 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3181
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3182 // send iTip reply
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3183 if ($event['_method'] == 'REQUEST' && $organizer && !$noreply && !in_array(strtolower($organizer['email']), $emails) && !$error_msg) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3184 $event['comment'] = $comment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3185 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3186 $itip->set_sender_email($reply_sender);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3187 if ($itip->send_itip_message($event, 'REPLY', $organizer, 'itipsubject' . $status, 'itipmailbody' . $status))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3188 $this->rc->output->command('display_message', $this->gettext(array('name' => 'sentresponseto', 'vars' => array('mailto' => $organizer['name'] ? $organizer['name'] : $organizer['email']))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3189 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3190 $this->rc->output->command('display_message', $this->gettext('itipresponseerror'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3191 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3192
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3193 $this->rc->output->send();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3194 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3195
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3196 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3197 * Handler for calendar/itip-remove requests
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3198 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3199 function mail_itip_decline_reply()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3200 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3201 $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3202 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3203 $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3204
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3205 if (($event = $this->lib->mail_get_itip_object($mbox, $uid, $mime_id, 'event')) && $event['_method'] == 'REPLY') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3206 $event['comment'] = rcube_utils::get_input_value('_comment', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3207
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3208 foreach ($event['attendees'] as $_attendee) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3209 if ($_attendee['role'] != 'ORGANIZER') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3210 $attendee = $_attendee;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3211 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3212 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3213 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3214
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3215 $itip = $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3216 if ($itip->send_itip_message($event, 'CANCEL', $attendee, 'itipsubjectcancel', 'itipmailbodycancel'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3217 $this->rc->output->command('display_message', $this->gettext(array('name' => 'sentresponseto', 'vars' => array('mailto' => $attendee['name'] ? $attendee['name'] : $attendee['email']))), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3218 else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3219 $this->rc->output->command('display_message', $this->gettext('itipresponseerror'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3220 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3221 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3222 $this->rc->output->command('display_message', $this->gettext('itipresponseerror'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3223 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3224 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3225
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3226 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3227 * Handler for calendar/itip-delegate requests
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3228 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3229 function mail_itip_delegate()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3230 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3231 // forward request to mail_import_itip() with the right status
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3232 $_POST['_status'] = $_REQUEST['_status'] = 'delegated';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3233 $this->mail_import_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3234 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3235
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3236 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3237 * Import the full payload from a mail message attachment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3238 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3239 public function mail_import_attachment()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3240 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3241 $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3242 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3243 $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3244 $charset = RCUBE_CHARSET;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3245
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3246 // establish imap connection
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3247 $imap = $this->rc->get_storage();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3248 $imap->set_folder($mbox);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3249
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3250 if ($uid && $mime_id) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3251 $part = $imap->get_message_part($uid, $mime_id);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3252 if ($part->ctype_parameters['charset'])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3253 $charset = $part->ctype_parameters['charset'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3254 // $headers = $imap->get_message_headers($uid);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3255
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3256 if ($part) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3257 $events = $this->get_ical()->import($part, $charset);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3258 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3259 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3260
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3261 $success = $existing = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3262 if (!empty($events)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3263 // find writeable calendar to store event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3264 $cal_id = !empty($_REQUEST['_calendar']) ? rcube_utils::get_input_value('_calendar', rcube_utils::INPUT_POST) : null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3265 $calendars = $this->driver->list_calendars(calendar_driver::FILTER_PERSONAL);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3266
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3267 foreach ($events as $event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3268 // save to calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3269 $calendar = $calendars[$cal_id] ?: $this->get_default_calendar($event['sensitivity']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3270 if ($calendar && $calendar['editable'] && $event['_type'] == 'event') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3271 $event['calendar'] = $calendar['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3272
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3273 if (!$this->driver->get_event($event['uid'], calendar_driver::FILTER_WRITEABLE)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3274 $success += (bool)$this->driver->new_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3275 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3276 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3277 $existing++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3278 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3279 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3280 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3281 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3282
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3283 if ($success) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3284 $this->rc->output->command('display_message', $this->gettext(array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3285 'name' => 'importsuccess',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3286 'vars' => array('nr' => $success),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3287 )), 'confirmation');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3288 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3289 else if ($existing) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3290 $this->rc->output->command('display_message', $this->gettext('importwarningexists'), 'warning');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3291 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3292 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3293 $this->rc->output->command('display_message', $this->gettext('errorimportingevent'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3294 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3295 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3296
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3297 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3298 * Read email message and return contents for a new event based on that message
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3299 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3300 public function mail_message2event()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3301 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3302 $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3303 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3304 $event = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3305
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3306 // establish imap connection
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3307 $imap = $this->rc->get_storage();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3308 $imap->set_folder($mbox);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3309 $message = new rcube_message($uid);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3310
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3311 if ($message->headers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3312 $event['title'] = trim($message->subject);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3313 $event['description'] = trim($message->first_text_part());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3314
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3315 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3316
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3317 // add a reference to the email message
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3318 if ($msgref = $this->driver->get_message_reference($message->headers, $mbox)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3319 $event['links'] = array($msgref);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3320 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3321 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3322 // hack around missing database_driver implementation of that method
17
3bd5fe8166b8 switch to using vurl as well for better display, and it gets saved
Charlie Root
parents: 3
diff changeset
3323 $mbox_u = str_replace('/','%2F',$mbox); // e.g. Bookings%2FBigHouse%2FPending
3bd5fe8166b8 switch to using vurl as well for better display, and it gets saved
Charlie Root
parents: 3
diff changeset
3324 $url = "https://hppllc.org/roundcube/?_task=mail&_mbox=$mbox_u&_uid=$uid";
3
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3325 $event['links'] = array(
17
3bd5fe8166b8 switch to using vurl as well for better display, and it gets saved
Charlie Root
parents: 3
diff changeset
3326 array('mailurl' => $url,
3
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3327 'subject' => 'link to original email'));
17
3bd5fe8166b8 switch to using vurl as well for better display, and it gets saved
Charlie Root
parents: 3
diff changeset
3328 $event['vurl'] = $url; // so it gets saved
3bd5fe8166b8 switch to using vurl as well for better display, and it gets saved
Charlie Root
parents: 3
diff changeset
3329
3bd5fe8166b8 switch to using vurl as well for better display, and it gets saved
Charlie Root
parents: 3
diff changeset
3330 rcube::write_log('cal',"$mbox $mbox_u ".$event['links'][0]['mailurl']);
3
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3331 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3332 // copy mail attachments to event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3333 if ($message->attachments) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3334 $eventid = 'cal-';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3335 if (!is_array($_SESSION[self::SESSION_KEY]) || $_SESSION[self::SESSION_KEY]['id'] != $eventid) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3336 $_SESSION[self::SESSION_KEY] = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3337 $_SESSION[self::SESSION_KEY]['id'] = $eventid;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3338 $_SESSION[self::SESSION_KEY]['attachments'] = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3339 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3340
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3341 foreach ((array)$message->attachments as $part) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3342 $attachment = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3343 'data' => $imap->get_message_part($uid, $part->mime_id, $part),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3344 'size' => $part->size,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3345 'name' => $part->filename,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3346 'mimetype' => $part->mimetype,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3347 'group' => $eventid,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3348 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3349
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3350 $attachment = $this->rc->plugins->exec_hook('attachment_save', $attachment);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3351
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3352 if ($attachment['status'] && !$attachment['abort']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3353 $id = $attachment['id'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3354 $attachment['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3355
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3356 // store new attachment in session
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3357 unset($attachment['status'], $attachment['abort'], $attachment['data']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3358 $_SESSION[self::SESSION_KEY]['attachments'][$id] = $attachment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3359
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3360 $attachment['id'] = 'rcmfile' . $attachment['id']; // add prefix to consider it 'new'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3361 $event['attachments'][] = $attachment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3362 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3363 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3364 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3365
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3366 $this->rc->output->command('plugin.mail2event_dialog', $event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3367 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3368 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3369 $this->rc->output->command('display_message', $this->gettext('messageopenerror'), 'error');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3370 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3371
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3372 $this->rc->output->send();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3373 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3374
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3375 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3376 * Handler for the 'message_compose' plugin hook. This will check for
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3377 * a compose parameter 'calendar_event' and create an attachment with the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3378 * referenced event in iCal format
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3379 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3380 public function mail_message_compose($args)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3381 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3382 // set the submitted event ID as attachment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3383 if (!empty($args['param']['calendar_event'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3384 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3385
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3386 list($cal, $id) = explode(':', $args['param']['calendar_event'], 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3387 if ($event = $this->driver->get_event(array('id' => $id, 'calendar' => $cal))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3388 $filename = asciiwords($event['title']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3389 if (empty($filename))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3390 $filename = 'event';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3391
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3392 // save ics to a temp file and register as attachment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3393 $tmp_path = tempnam($this->rc->config->get('temp_dir'), 'rcmAttmntCal');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3394 file_put_contents($tmp_path, $this->get_ical()->export(array($event), '', false, array($this->driver, 'get_attachment_body')));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3395
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3396 $args['attachments'][] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3397 'path' => $tmp_path,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3398 'name' => $filename . '.ics',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3399 'mimetype' => 'text/calendar',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3400 'size' => filesize($tmp_path),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3401 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3402 $args['param']['subject'] = $event['title'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3403 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3404 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3405
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3406 return $args;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3407 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3408
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3409
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3410 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3411 * Get a list of email addresses of the current user (from login and identities)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3412 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3413 public function get_user_emails()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3414 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3415 return $this->lib->get_user_emails();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3416 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3417
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3418
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3419 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3420 * Build an absolute URL with the given parameters
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3421 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3422 public function get_url($param = array())
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3423 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3424 $param += array('task' => 'calendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3425 return $this->rc->url($param, true, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3426 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3427
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3428
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3429 public function ical_feed_hash($source)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3430 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3431 return base64_encode($this->rc->user->get_username() . ':' . $source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3432 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3433
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3434 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3435 * Handler for user_delete plugin hook
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3436 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3437 public function user_delete($args)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3438 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3439 // delete itipinvitations entries related to this user
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3440 $db = $this->rc->get_dbh();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3441 $table_itipinvitations = $db->table_name('itipinvitations', true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3442 $db->query("DELETE FROM $table_itipinvitations WHERE `user_id` = ?", $args['user']->ID);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3443
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3444 $this->setup();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3445 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3446 return $this->driver->user_delete($args);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3447 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3448
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3449 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3450 * Magic getter for public access to protected members
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3451 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3452 public function __get($name)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3453 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3454 switch ($name) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3455 case 'ical':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3456 return $this->get_ical();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3457
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3458 case 'itip':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3459 return $this->load_itip();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3460
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3461 case 'driver':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3462 $this->load_driver();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3463 return $this->driver;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3464 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3465
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3466 return null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3467 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3468
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3469 }