annotate plugins/libcalendaring/lib/libcalendaring_itip.php @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4 * iTIP functions for the calendar-based Roudncube plugins
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6 * Class providing functionality to manage iTIP invitations
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * @author Thomas Bruederli <bruederli@kolabsys.com>
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * Copyright (C) 2011-2014, Kolab Systems AG <contact@kolabsys.com>
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * This program is free software: you can redistribute it and/or modify
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * it under the terms of the GNU Affero General Public License as
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * published by the Free Software Foundation, either version 3 of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 * License, or (at your option) any later version.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * GNU Affero General Public License for more details.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * You should have received a copy of the GNU Affero General Public License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 class libcalendaring_itip
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 protected $rc;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 protected $lib;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 protected $plugin;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 protected $sender;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 protected $domain;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 protected $itip_send = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 protected $rsvp_actions = array('accepted','tentative','declined','delegated');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 protected $rsvp_status = array('accepted','tentative','declined','delegated');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 function __construct($plugin, $domain = 'libcalendaring')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 $this->plugin = $plugin;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 $this->rc = rcube::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 $this->lib = libcalendaring::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 $this->domain = $domain;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 $hook = $this->rc->plugins->exec_hook('calendar_load_itip',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 array('identity' => $this->rc->user->list_emails(true)));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 $this->sender = $hook['identity'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 $this->plugin->add_hook('message_before_send', array($this, 'before_send_hook'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 $this->plugin->add_hook('smtp_connect', array($this, 'smtp_connect_hook'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 public function set_sender_email($email)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 if (!empty($email))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 $this->sender['email'] = $email;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 public function set_rsvp_actions($actions)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 $this->rsvp_actions = (array)$actions;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 $this->rsvp_status = array_merge($this->rsvp_actions, array('delegated'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 public function set_rsvp_status($status)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 $this->rsvp_status = $status;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 * Wrapper for rcube_plugin::gettext()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 * Checking for a label in different domains
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 * @see rcube::gettext()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 public function gettext($p)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 $label = is_array($p) ? $p['name'] : $p;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 $domain = $this->domain;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 if (!$this->rc->text_exists($label, $domain)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 $domain = 'libcalendaring';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 return $this->rc->gettext($p, $domain);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 * Send an iTip mail message
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 * @param array Event object to send
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 * @param string iTip method (REQUEST|REPLY|CANCEL)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 * @param array Hash array with recipient data (name, email)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 * @param string Mail subject
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 * @param string Mail body text label
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92 * @param object Mail_mime object with message data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 * @param boolean Request RSVP
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94 * @return boolean True on success, false on failure
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96 public function send_itip_message($event, $method, $recipient, $subject, $bodytext, $message = null, $rsvp = true)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98 if (!$this->sender['name'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99 $this->sender['name'] = $this->sender['email'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 if (!$message) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 libcalendaring::identify_recurrence_instance($event);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 $message = $this->compose_itip_message($event, $method, $rsvp);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106 $mailto = rcube_utils::idn_to_ascii($recipient['email']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108 $headers = $message->headers();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 $headers['To'] = format_email_recipient($mailto, $recipient['name']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110 $headers['Subject'] = $this->gettext(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111 'name' => $subject,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
112 'vars' => array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
113 'title' => $event['title'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
114 'name' => $this->sender['name']
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
115 )
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 // compose a list of all event attendees
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119 $attendees_list = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120 foreach ((array)$event['attendees'] as $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121 $attendees_list[] = ($attendee['name'] && $attendee['email']) ?
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122 $attendee['name'] . ' <' . $attendee['email'] . '>' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123 ($attendee['name'] ? $attendee['name'] : $attendee['email']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126 $recurrence_info = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 if (!empty($event['recurrence_id'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
128 $recurrence_info = "\n\n** " . $this->gettext($event['thisandfuture'] ? 'itipmessagefutureoccurrence' : 'itipmessagesingleoccurrence') . ' **';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
129 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
130 else if (!empty($event['recurrence'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 $recurrence_info = sprintf("\n%s: %s", $this->gettext('recurring'), $this->lib->recurrence_text($event['recurrence']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
133
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
134 $mailbody = $this->gettext(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
135 'name' => $bodytext,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
136 'vars' => array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
137 'title' => $event['title'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
138 'date' => $this->lib->event_date_text($event, true) . $recurrence_info,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
139 'attendees' => join(",\n ", $attendees_list),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 'sender' => $this->sender['name'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
141 'organizer' => $this->sender['name'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
142 )
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
143 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
144
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145 // if (!empty($event['comment'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146 // $mailbody .= "\n\n" . $this->gettext('itipsendercomment') . $event['comment'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147 // }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149 // append links for direct invitation replies
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150 if ($method == 'REQUEST' && $rsvp && ($token = $this->store_invitation($event, $recipient['email']))) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151 $mailbody .= "\n\n" . $this->gettext(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 'name' => 'invitationattendlinks',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153 'vars' => array('url' => $this->plugin->get_url(array('action' => 'attend', 't' => $token))),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156 else if ($method == 'CANCEL' && $event['cancelled']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157 $this->cancel_itip_invitation($event);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160 $message->headers($headers, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 $message->setTXTBody(rcube_mime::format_flowed($mailbody, 79));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 if ($this->rc->config->get('libcalendaring_itip_debug', false)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164 rcube::console('iTip ' . $method, $message->txtHeaders() . "\r\n" . $message->get());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167 // finally send the message
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168 $this->itip_send = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169 $sent = $this->rc->deliver_message($message, $headers['X-Sender'], $mailto, $smtp_error);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170 $this->itip_send = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172 return $sent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 * Plugin hook triggered by rcube::deliver_message() before delivering a message.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177 * Here we can set the 'smtp_server' config option to '' in order to use
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178 * PHP's mail() function for unauthenticated email sending.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180 public function before_send_hook($p)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
181 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
182 if ($this->itip_send && !$this->rc->user->ID && $this->rc->config->get('calendar_itip_smtp_server', null) === '') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
183 $this->rc->config->set('smtp_server', '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
184 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
185
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
186 return $p;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
187 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
188
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
189 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
190 * Plugin hook to alter SMTP authentication.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
191 * This is used if iTip messages are to be sent from an unauthenticated session
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
192 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
193 public function smtp_connect_hook($p)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
194 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
195 // replace smtp auth settings if we're not in an authenticated session
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
196 if ($this->itip_send && !$this->rc->user->ID) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
197 foreach (array('smtp_server', 'smtp_user', 'smtp_pass') as $prop) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
198 $p[$prop] = $this->rc->config->get("calendar_itip_$prop", $p[$prop]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
199 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
200 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
201
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
202 return $p;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
203 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
204
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
205 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
206 * Helper function to build a Mail_mime object to send an iTip message
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
207 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
208 * @param array Event object to send
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
209 * @param string iTip method (REQUEST|REPLY|CANCEL)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
210 * @param boolean Request RSVP
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
211 * @return object Mail_mime object with message data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
212 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
213 public function compose_itip_message($event, $method, $rsvp = true)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
214 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
215 $from = rcube_utils::idn_to_ascii($this->sender['email']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
216 $from_utf = rcube_utils::idn_to_utf8($from);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
217 $sender = format_email_recipient($from, $this->sender['name']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
218
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
219 // truncate list attendees down to the recipient of the iTip Reply.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
220 // constraints for a METHOD:REPLY according to RFC 5546
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
221 if ($method == 'REPLY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
222 $replying_attendee = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
223 $reply_attendees = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
224 foreach ($event['attendees'] as $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
225 if ($attendee['role'] == 'ORGANIZER') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
226 $reply_attendees[] = $attendee;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
227 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
228 else if (strcasecmp($attendee['email'], $from) == 0 || strcasecmp($attendee['email'], $from_utf) == 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
229 $replying_attendee = $attendee;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
230 if ($attendee['status'] != 'DELEGATED') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
231 unset($replying_attendee['rsvp']); // unset the RSVP attribute
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
232 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
233 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
234 // include attendees relevant for delegation (RFC 5546, Section 4.2.5)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
235 else if ((!empty($attendee['delegated-to']) &&
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
236 (strcasecmp($attendee['delegated-to'], $from) == 0 || strcasecmp($attendee['delegated-to'], $from_utf) == 0)) ||
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
237 (!empty($attendee['delegated-from']) &&
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
238 (strcasecmp($attendee['delegated-from'], $from) == 0 || strcasecmp($attendee['delegated-from'], $from_utf) == 0))) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
239 $reply_attendees[] = $attendee;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
240 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
241 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
242 if ($replying_attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
243 array_unshift($reply_attendees, $replying_attendee);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
244 $event['attendees'] = $reply_attendees;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
245 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
246 if ($event['recurrence']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
247 unset($event['recurrence']['EXCEPTIONS']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
248 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
249 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
250 // set RSVP for every attendee
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
251 else if ($method == 'REQUEST') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
252 foreach ($event['attendees'] as $i => $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
253 if (($rsvp || !isset($attendee['rsvp'])) && ($attendee['status'] != 'DELEGATED' && $attendee['role'] != 'NON-PARTICIPANT')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
254 $event['attendees'][$i]['rsvp']= (bool)$rsvp;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
255 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
256 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
257 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
258 else if ($method == 'CANCEL') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
259 if ($event['recurrence']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
260 unset($event['recurrence']['EXCEPTIONS']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
261 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
262 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
263
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
264 // Set SENT-BY property if the sender is not the organizer
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
265 if ($method == 'CANCEL' || $method == 'REQUEST') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
266 foreach ((array)$event['attendees'] as $idx => $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
267 if ($attendee['role'] == 'ORGANIZER'
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
268 && $attendee['email']
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
269 && strcasecmp($attendee['email'], $from) != 0
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
270 && strcasecmp($attendee['email'], $from_utf) != 0
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
271 ) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
272 $attendee['sent-by'] = 'mailto:' . $from_utf;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
273 $event['organizer'] = $event['attendees'][$idx] = $attendee;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
274 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
275 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
276 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
277 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
278
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
279 // compose multipart message using PEAR:Mail_Mime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
280 $message = new Mail_mime("\r\n");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
281 $message->setParam('text_encoding', 'quoted-printable');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
282 $message->setParam('head_encoding', 'quoted-printable');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
283 $message->setParam('head_charset', RCUBE_CHARSET);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
284 $message->setParam('text_charset', RCUBE_CHARSET . ";\r\n format=flowed");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
285 $message->setContentType('multipart/alternative');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
286
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
287 // compose common headers array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
288 $headers = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
289 'From' => $sender,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
290 'Date' => $this->rc->user_date(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
291 'Message-ID' => $this->rc->gen_message_id(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
292 'X-Sender' => $from,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
293 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
294 if ($agent = $this->rc->config->get('useragent')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
295 $headers['User-Agent'] = $agent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
296 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
297
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
298 $message->headers($headers);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
299
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
300 // attach ics file for this event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
301 $ical = libcalendaring::get_ical();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
302 $ics = $ical->export(array($event), $method, false, $method == 'REQUEST' && $this->plugin->driver ? array($this->plugin->driver, 'get_attachment_body') : false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
303 $filename = $event['_type'] == 'task' ? 'todo.ics' : 'event.ics';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
304 $message->addAttachment($ics, 'text/calendar', $filename, false, '8bit', '', RCUBE_CHARSET . "; method=" . $method);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
305
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
306 return $message;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
307 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
308
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
309 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
310 * Forward the given iTip event as delegation to another person
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
311 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
312 * @param array Event object to delegate
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
313 * @param mixed Delegatee as string or hash array with keys 'name' and 'mailto'
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
314 * @param boolean The delegator's RSVP flag
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
315 * @param array List with indexes of new/updated attendees
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
316 * @return boolean True on success, False on failure
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
317 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
318 public function delegate_to(&$event, $delegate, $rsvp = false, &$attendees = array())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
319 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
320 if (is_string($delegate)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
321 $delegates = rcube_mime::decode_address_list($delegate, 1, false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
322 if (count($delegates) > 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
323 $delegate = reset($delegates);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
324 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
325 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
326
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
327 $emails = $this->lib->get_user_emails();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
328 $me = $this->rc->user->list_emails(true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
329
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
330 // find/create the delegate attendee
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
331 $delegate_attendee = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
332 'email' => $delegate['mailto'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
333 'name' => $delegate['name'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
334 'role' => 'REQ-PARTICIPANT',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
335 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
336 $delegate_index = count($event['attendees']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
337
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
338 foreach ($event['attendees'] as $i => $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
339 // set myself the DELEGATED-TO parameter
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
340 if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
341 $event['attendees'][$i]['delegated-to'] = $delegate['mailto'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
342 $event['attendees'][$i]['status'] = 'DELEGATED';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
343 $event['attendees'][$i]['role'] = 'NON-PARTICIPANT';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
344 $event['attendees'][$i]['rsvp'] = $rsvp;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
345
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
346 $me['email'] = $attendee['email'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
347 $delegate_attendee['role'] = $attendee['role'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
348 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
349 // the disired delegatee is already listed as an attendee
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
350 else if (stripos($delegate['mailto'], $attendee['email']) !== false && $attendee['role'] != 'ORGANIZER') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
351 $delegate_attendee = $attendee;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
352 $delegate_index = $i;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
353 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
354 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
355 // TODO: remove previous delegatee (i.e. attendee that has DELEGATED-FROM == $me)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
356 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
357
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
358 // set/add delegate attendee with RSVP=TRUE and DELEGATED-FROM parameter
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
359 $delegate_attendee['rsvp'] = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
360 $delegate_attendee['status'] = 'NEEDS-ACTION';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
361 $delegate_attendee['delegated-from'] = $me['email'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
362 $event['attendees'][$delegate_index] = $delegate_attendee;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
363
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
364 $attendees[] = $delegate_index;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
365
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
366 $this->set_sender_email($me['email']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
367 return $this->send_itip_message($event, 'REQUEST', $delegate_attendee, 'itipsubjectdelegatedto', 'itipmailbodydelegatedto');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
368 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
369
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
370 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
371 * Handler for calendar/itip-status requests
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
372 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
373 public function get_itip_status($event, $existing = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
374 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
375 $action = $event['rsvp'] ? 'rsvp' : '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
376 $status = $event['fallback'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
377 $latest = $resheduled = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
378 $html = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
379
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
380 if (is_numeric($event['changed']))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
381 $event['changed'] = new DateTime('@'.$event['changed']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
382
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
383 // check if the given itip object matches the last state
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
384 if ($existing) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
385 $latest = (isset($event['sequence']) && intval($existing['sequence']) == intval($event['sequence'])) ||
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
386 (!isset($event['sequence']) && $existing['changed'] && $existing['changed'] >= $event['changed']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
387 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
388
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
389 // determine action for REQUEST
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
390 if ($event['method'] == 'REQUEST') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
391 $html = html::div('rsvp-status', $this->gettext('acceptinvitation'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
392
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
393 if ($existing) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
394 $rsvp = $event['rsvp'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
395 $emails = $this->lib->get_user_emails();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
396 foreach ($existing['attendees'] as $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
397 if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
398 $status = strtoupper($attendee['status']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
399 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
400 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
401 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
402
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
403 // Detect re-sheduling
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
404 if (!$latest) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
405 // FIXME: This is probably to simplistic, or maybe we should just check
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
406 // attendee's RSVP flag in the new event?
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
407 $resheduled = $existing['start'] != $event['start'] || $existing['end'] > $event['end'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
408 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
409 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
410 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
411 $rsvp = $event['rsvp'] && $this->rc->config->get('calendar_allow_itip_uninvited', true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
412 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
413
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
414 $status_lc = strtolower($status);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
415
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
416 if ($status_lc == 'unknown' && !$this->rc->config->get('calendar_allow_itip_uninvited', true)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
417 $html = html::div('rsvp-status', $this->gettext('notanattendee'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
418 $action = 'import';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
419 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
420 else if (in_array($status_lc, $this->rsvp_status)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
421 $status_text = $this->gettext(($latest ? 'youhave' : 'youhavepreviously') . $status_lc);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
422
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
423 if ($existing && ($existing['sequence'] > $event['sequence'] || (!isset($event['sequence']) && $existing['changed'] && $existing['changed'] > $event['changed']))) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
424 $action = ''; // nothing to do here, outdated invitation
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
425 if ($status_lc == 'needs-action')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
426 $status_text = $this->gettext('outdatedinvitation');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
427 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
428 else if (!$existing && !$rsvp) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
429 $action = 'import';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
430 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
431 else if ($resheduled) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
432 $action = 'rsvp';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
433 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
434 else if ($status_lc != 'needs-action') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
435 $action = !$latest ? 'update' : '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
436 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
437
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
438 $html = html::div('rsvp-status ' . $status_lc, $status_text);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
439 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
440 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
441 // determine action for REPLY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
442 else if ($event['method'] == 'REPLY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
443 // check whether the sender already is an attendee
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
444 if ($existing) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
445 $action = $this->rc->config->get('calendar_allow_itip_uninvited', true) ? 'accept' : '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
446 $listed = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
447 foreach ($existing['attendees'] as $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
448 if ($attendee['role'] != 'ORGANIZER' && strcasecmp($attendee['email'], $event['attendee']) == 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
449 $status_lc = strtolower($status);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
450 if (in_array($status_lc, $this->rsvp_status)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
451 $html = html::div('rsvp-status ' . $status_lc, $this->gettext(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
452 'name' => 'attendee' . $status_lc,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
453 'vars' => array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
454 'delegatedto' => rcube::Q($event['delegated-to'] ?: ($attendee['delegated-to'] ?: '?')),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
455 )
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
456 )));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
457 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
458 $action = $attendee['status'] == $status || !$latest ? '' : 'update';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
459 $listed = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
460 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
461 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
462 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
463
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
464 if (!$listed) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
465 $html = html::div('rsvp-status', $this->gettext('itipnewattendee'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
466 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
467 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
468 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
469 $html = html::div('rsvp-status hint', $this->gettext('itipobjectnotfound'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
470 $action = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
471 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
472 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
473 else if ($event['method'] == 'CANCEL') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
474 if (!$existing) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
475 $html = html::div('rsvp-status hint', $this->gettext('itipobjectnotfound'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
476 $action = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
477 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
478 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
479
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
480 return array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
481 'uid' => $event['uid'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
482 'id' => asciiwords($event['uid'], true),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
483 'existing' => $existing ? true : false,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
484 'saved' => $existing ? true : false,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
485 'latest' => $latest,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
486 'status' => $status,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
487 'action' => $action,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
488 'resheduled' => $resheduled,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
489 'html' => $html,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
490 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
491 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
492
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
493 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
494 * Build inline UI elements for iTip messages
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
495 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
496 public function mail_itip_inline_ui($event, $method, $mime_id, $task, $message_date = null, $preview_url = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
497 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
498 $buttons = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
499 $dom_id = asciiwords($event['uid'], true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
500 $rsvp_status = 'unknown';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
501
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
502 // pass some metadata about the event and trigger the asynchronous status check
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
503 $changed = is_object($event['changed']) ? $event['changed'] : $message_date;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
504 $metadata = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
505 'uid' => $event['uid'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
506 '_instance' => $event['_instance'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
507 'changed' => $changed ? $changed->format('U') : 0,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
508 'sequence' => intval($event['sequence']),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
509 'method' => $method,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
510 'task' => $task,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
511 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
512
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
513 // create buttons to be activated from async request checking existence of this event in local calendars
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
514 $buttons[] = html::div(array('id' => 'loading-'.$dom_id, 'class' => 'rsvp-status loading'), $this->gettext('loading'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
515
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
516 // on iTip REPLY we have two options:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
517 if ($method == 'REPLY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
518 $title = $this->gettext('itipreply');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
519
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
520 foreach ($event['attendees'] as $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
521 if (!empty($attendee['email']) && $attendee['role'] != 'ORGANIZER') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
522 if (empty($event['_sender']) || self::compare_email($attendee['email'], $event['_sender'], $event['_sender_utf'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
523 $metadata['attendee'] = $attendee['email'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
524 $rsvp_status = strtoupper($attendee['status']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
525 if ($attendee['delegated-to']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
526 $metadata['delegated-to'] = $attendee['delegated-to'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
527 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
528 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
529 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
530 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
531 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
532
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
533 // 1. update the attendee status on our copy
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
534 $update_button = html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
535 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
536 'class' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
537 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . rcube::JQ($mime_id) . "', '$task')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
538 'value' => $this->gettext('updateattendeestatus'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
539 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
540
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
541 // 2. accept or decline a new or delegate attendee
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
542 $accept_buttons = html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
543 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
544 'class' => "button accept",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
545 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . rcube::JQ($mime_id) . "', '$task')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
546 'value' => $this->gettext('acceptattendee'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
547 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
548 $accept_buttons .= html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
549 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
550 'class' => "button decline",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
551 'onclick' => "rcube_libcalendaring.decline_attendee_reply('" . rcube::JQ($mime_id) . "', '$task')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
552 'value' => $this->gettext('declineattendee'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
553 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
554
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
555 $buttons[] = html::div(array('id' => 'update-'.$dom_id, 'style' => 'display:none'), $update_button);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
556 $buttons[] = html::div(array('id' => 'accept-'.$dom_id, 'style' => 'display:none'), $accept_buttons);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
557 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
558 // when receiving iTip REQUEST messages:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
559 else if ($method == 'REQUEST') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
560 $emails = $this->lib->get_user_emails();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
561 $title = $event['sequence'] > 0 ? $this->gettext('itipupdate') : $this->gettext('itipinvitation');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
562 $metadata['rsvp'] = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
563 $metadata['sensitivity'] = $event['sensitivity'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
564
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
565 if (is_object($event['start'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
566 $metadata['date'] = $event['start']->format('U');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
567 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
568
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
569 // check for X-KOLAB-INVITATIONTYPE property and only show accept/decline buttons
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
570 if (self::get_custom_property($event, 'X-KOLAB-INVITATIONTYPE') == 'CONFIRMATION') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
571 $this->rsvp_actions = array('accepted','declined');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
572 $metadata['nosave'] = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
573 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
574
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
575 // 1. display RSVP buttons (if the user was invited)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
576 foreach ($this->rsvp_actions as $method) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
577 $rsvp_buttons .= html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
578 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
579 'class' => "button $method",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
580 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . rcube::JQ($mime_id) . "', '$task', '$method', '$dom_id')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
581 'value' => $this->gettext('itip' . $method),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
582 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
583 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
584
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
585 // add button to open calendar/preview
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
586 if (!empty($preview_url)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
587 $msgref = $this->lib->ical_message->folder . '/' . $this->lib->ical_message->uid . '#' . $mime_id;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
588 $rsvp_buttons .= html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
589 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
590 'class' => "button preview",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
591 'onclick' => "rcube_libcalendaring.open_itip_preview('" . rcube::JQ($preview_url) . "', '" . rcube::JQ($msgref) . "')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
592 'value' => $this->gettext('openpreview'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
593 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
594 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
595
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
596 // 2. update the local copy with minor changes
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
597 $update_button = html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
598 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
599 'class' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
600 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . rcube::JQ($mime_id) . "', '$task')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
601 'value' => $this->gettext('updatemycopy'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
602 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
603
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
604 // 3. Simply import the event without replying
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
605 $import_button = html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
606 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
607 'class' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
608 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . rcube::JQ($mime_id) . "', '$task')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
609 'value' => $this->gettext('importtocalendar'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
610 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
611
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
612 // check my status
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
613 foreach ($event['attendees'] as $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
614 if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
615 $metadata['attendee'] = $attendee['email'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
616 $metadata['rsvp'] = $attendee['rsvp'] || $attendee['role'] != 'NON-PARTICIPANT';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
617 $rsvp_status = !empty($attendee['status']) ? strtoupper($attendee['status']) : 'NEEDS-ACTION';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
618 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
619 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
620 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
621
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
622 // add itip reply message controls
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
623 $rsvp_buttons .= html::div('itip-reply-controls', $this->itip_rsvp_options_ui($dom_id, $metadata['nosave']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
624
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
625 $buttons[] = html::div(array('id' => 'rsvp-'.$dom_id, 'class' => 'rsvp-buttons', 'style' => 'display:none'), $rsvp_buttons);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
626 $buttons[] = html::div(array('id' => 'update-'.$dom_id, 'style' => 'display:none'), $update_button);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
627
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
628 // prepare autocompletion for delegation dialog
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
629 if (in_array('delegated', $this->rsvp_actions)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
630 $this->rc->autocomplete_init();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
631 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
632 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
633 // for CANCEL messages, we can:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
634 else if ($method == 'CANCEL') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
635 $title = $this->gettext('itipcancellation');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
636 $event_prop = array_filter(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
637 'uid' => $event['uid'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
638 '_instance' => $event['_instance'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
639 '_savemode' => $event['_savemode'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
640 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
641
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
642 // 1. remove the event from our calendar
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
643 $button_remove = html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
644 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
645 'class' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
646 'onclick' => "rcube_libcalendaring.remove_from_itip(" . rcube_output::json_serialize($event_prop) . ", '$task', '" . rcube::JQ($event['title']) . "')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
647 'value' => $this->gettext('removefromcalendar'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
648 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
649
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
650 // 2. update our copy with status=cancelled
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
651 $button_update = html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
652 'type' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
653 'class' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
654 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . rcube::JQ($mime_id) . "', '$task')",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
655 'value' => $this->gettext('updatemycopy'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
656 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
657
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
658 $buttons[] = html::div(array('id' => 'rsvp-'.$dom_id, 'style' => 'display:none'), $button_remove . $button_update);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
659
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
660 $rsvp_status = 'CANCELLED';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
661 $metadata['rsvp'] = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
662 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
663
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
664 // append generic import button
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
665 if ($import_button) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
666 $buttons[] = html::div(array('id' => 'import-'.$dom_id, 'style' => 'display:none'), $import_button);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
667 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
668
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
669 // pass some metadata about the event and trigger the asynchronous status check
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
670 $metadata['fallback'] = $rsvp_status;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
671 $metadata['rsvp'] = intval($metadata['rsvp']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
672
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
673 $this->rc->output->add_script("rcube_libcalendaring.fetch_itip_object_status(" . rcube_output::json_serialize($metadata) . ")", 'docready');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
674
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
675 // get localized texts from the right domain
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
676 foreach (array('savingdata','deleteobjectconfirm','declinedeleteconfirm','declineattendee',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
677 'cancel','itipdelegated','declineattendeeconfirm','itipcomment','delegateinvitation',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
678 'delegateto','delegatersvpme','delegateinvalidaddress') as $label) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
679 $this->rc->output->command('add_label', "itip.$label", $this->gettext($label));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
680 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
681
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
682 // show event details with buttons
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
683 return $this->itip_object_details_table($event, $title) .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
684 html::div(array('class' => 'itip-buttons', 'id' => 'itip-buttons-' . asciiwords($metadata['uid'], true)), join('', $buttons));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
685 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
686
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
687 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
688 * Render an RSVP UI widget with buttons to respond on iTip invitations
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
689 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
690 function itip_rsvp_buttons($attrib = array(), $actions = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
691 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
692 $attrib += array('type' => 'button');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
693
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
694 if (!$actions)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
695 $actions = $this->rsvp_actions;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
696
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
697 foreach ($actions as $method) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
698 $buttons .= html::tag('input', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
699 'type' => $attrib['type'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
700 'name' => $attrib['iname'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
701 'class' => 'button',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
702 'rel' => $method,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
703 'value' => $this->gettext('itip' . $method),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
704 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
705 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
706
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
707 // add localized texts for the delegation dialog
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
708 if (in_array('delegated', $actions)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
709 foreach (array('itipdelegated','itipcomment','delegateinvitation',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
710 'delegateto','delegatersvpme','delegateinvalidaddress','cancel') as $label) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
711 $this->rc->output->command('add_label', "itip.$label", $this->gettext($label));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
712 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
713 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
714
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
715 foreach (array('all','current','future') as $mode) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
716 $this->rc->output->command('add_label', "rsvpmode$mode", $this->gettext("rsvpmode$mode"));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
717 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
718
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
719 $savemode_radio = new html_radiobutton(array('name' => '_rsvpmode', 'class' => 'rsvp-replymode'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
720
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
721 return html::div($attrib,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
722 html::div('label', $this->gettext('acceptinvitation')) .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
723 html::div('rsvp-buttons',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
724 $buttons .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
725 html::div('itip-reply-controls', $this->itip_rsvp_options_ui($attrib['id']))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
726 )
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
727 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
728 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
729
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
730 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
731 * Render UI elements to control iTip reply message sending
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
732 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
733 public function itip_rsvp_options_ui($dom_id, $disable = false)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
734 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
735 $itip_sending = $this->rc->config->get('calendar_itip_send_option', 3);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
736
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
737 // itip sending is entirely disabled
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
738 if ($itip_sending === 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
739 return '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
740 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
741 // add checkbox to suppress itip reply message
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
742 else if ($itip_sending >= 2) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
743 $rsvp_additions = html::label(array('class' => 'noreply-toggle'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
744 html::tag('input', array('type' => 'checkbox', 'id' => 'noreply-'.$dom_id, 'value' => 1, 'disabled' => $disable, 'checked' => ($itip_sending & 1) == 0))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
745 . ' ' . $this->gettext('itipsuppressreply')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
746 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
747 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
748
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
749 // add input field for reply comment
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
750 $toggle_attrib = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
751 'href' => '#toggle',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
752 'class' => 'reply-comment-toggle',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
753 'onclick' => '$(this).hide().parent().find(\'textarea\').show().focus()'
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
754 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
755 $textarea_attrib = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
756 'id' => 'reply-comment-' . $dom_id,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
757 'name' => '_comment',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
758 'cols' => 40,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
759 'rows' => 6,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
760 'style' => 'display:none',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
761 'placeholder' => $this->gettext('itipcomment')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
762 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
763
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
764 $rsvp_additions .= html::a($toggle_attrib, $this->gettext('itipeditresponse'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
765 . html::div('itip-reply-comment', html::tag('textarea', $textarea_attrib, ''));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
766
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
767 return $rsvp_additions;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
768 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
769
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
770 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
771 * Render event/task details in a table
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
772 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
773 function itip_object_details_table($event, $title)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
774 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
775 $table = new html_table(array('cols' => 2, 'border' => 0, 'class' => 'calendar-eventdetails'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
776 $table->add('ititle', $title);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
777 $table->add('title', rcube::Q($event['title']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
778 if ($event['start'] && $event['end']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
779 $table->add('label', $this->gettext('date'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
780 $table->add('date', rcube::Q($this->lib->event_date_text($event)));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
781 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
782 else if ($event['due'] && $event['_type'] == 'task') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
783 $table->add('label', $this->gettext('date'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
784 $table->add('date', rcube::Q($this->lib->event_date_text($event)));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
785 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
786 if (!empty($event['recurrence_date'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
787 $table->add('label', '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
788 $table->add('recurrence-id', $this->gettext($event['thisandfuture'] ? 'itipfutureoccurrence' : 'itipsingleoccurrence'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
789 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
790 else if (!empty($event['recurrence'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
791 $table->add('label', $this->gettext('recurring'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
792 $table->add('recurrence', $this->lib->recurrence_text($event['recurrence']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
793 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
794 if ($event['location']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
795 $table->add('label', $this->gettext('location'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
796 $table->add('location', rcube::Q($event['location']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
797 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
798 if ($event['sensitivity'] && $event['sensitivity'] != 'public') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
799 $table->add('label', $this->gettext('sensitivity'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
800 $table->add('sensitivity', ucfirst($this->gettext($event['sensitivity'])) . '!');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
801 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
802 if ($event['status'] == 'COMPLETED' || $event['status'] == 'CANCELLED') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
803 $table->add('label', $this->gettext('status'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
804 $table->add('status', $this->gettext('status-' . strtolower($event['status'])));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
805 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
806 if ($event['comment']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
807 $table->add('label', $this->gettext('comment'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
808 $table->add('location', rcube::Q($event['comment']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
809 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
810
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
811 return $table->show();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
812 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
813
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
814
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
815 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
816 * Create iTIP invitation token for later replies via URL
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
817 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
818 * @param array Hash array with event properties
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
819 * @param string Attendee email address
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
820 * @return string Invitation token
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
821 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
822 public function store_invitation($event, $attendee)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
823 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
824 // empty stub
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
825 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
826 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
827
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
828 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
829 * Mark invitations for the given event as cancelled
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
830 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
831 * @param array Hash array with event properties
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
832 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
833 public function cancel_itip_invitation($event)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
834 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
835 // empty stub
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
836 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
837 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
838
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
839 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
840 * Utility function to get the value of a custom property
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
841 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
842 public static function get_custom_property($event, $name)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
843 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
844 $ret = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
845
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
846 if (is_array($event['x-custom'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
847 array_walk($event['x-custom'], function($prop, $i) use ($name, &$ret) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
848 if (strcasecmp($prop[0], $name) === 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
849 $ret = $prop[1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
850 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
851 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
852 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
853
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
854 return $ret;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
855 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
856
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
857 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
858 * Compare email address
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
859 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
860 public static function compare_email($value, $email, $email_utf = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
861 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
862 $v1 = !empty($email) && strcasecmp($value, $email) === 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
863 $v2 = !empty($email_utf) && strcasecmp($value, $email_utf) === 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
864
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
865 return $v1 || $v2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
866 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
867 }