annotate plugins/calendar/calendar.php @ 57:ade98a608cd3

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