From 3ffa80a3a7413d44fa9303278a92b82447c8e00f Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 7 Jul 2014 11:04:00 +0200 Subject: [PATCH] Allow a custom invitation text to be sent to attendees (#1788) - Send the text in iTip COMMENT field only --- plugins/calendar/calendar.php | 12 +++++++++--- plugins/calendar/calendar_ui.js | 2 ++ plugins/calendar/lib/calendar_ui.php | 11 +++++++---- plugins/calendar/localization/en_US.inc | 1 + plugins/calendar/skins/larry/calendar.css | 6 ++++++ plugins/libcalendaring/lib/libcalendaring_itip.php | 7 +++---- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index 0313bb17..a370c22e 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -930,7 +930,7 @@ class calendar extends rcube_plugin // only notify if data really changed (TODO: do diff check on client already) if (!$old || $action == 'remove' || self::event_diff($event, $old)) { - $sent = $this->notify_attendees($event, $old, $action); + $sent = $this->notify_attendees($event, $old, $action, $event['_comment']); if ($sent > 0) $this->rc->output->show_message('calendar.itipsendsuccess', 'confirmation'); else if ($sent < 0) @@ -1599,7 +1599,7 @@ class calendar extends rcube_plugin /** * Send out an invitation/notification to all event attendees */ - private function notify_attendees($event, $old, $action = 'edit') + private function notify_attendees($event, $old, $action = 'edit', $comment = null) { if ($action == 'remove' || ($event['status'] == 'CANCELLED' && $old['status'] != $event['status'])) { $event['cancelled'] = true; @@ -1609,6 +1609,9 @@ class calendar extends rcube_plugin $itip = $this->load_itip(); $emails = $this->get_user_emails(); + // add comment to the iTip attachment + $event['comment'] = $comment; + // compose multipart message using PEAR:Mail_Mime $method = $action == 'remove' ? 'CANCEL' : 'REQUEST'; $message = $itip->compose_itip_message($event, $method); @@ -1632,7 +1635,9 @@ class calendar extends rcube_plugin $is_new = !in_array($attendee['email'], $old_attendees); $bodytext = $is_cancelled ? 'eventcancelmailbody' : ($is_new ? 'invitationmailbody' : 'eventupdatemailbody'); $subject = $is_cancelled ? 'eventcancelsubject' : ($is_new ? 'invitationsubject' : ($event['title'] ? 'eventupdatesubject':'eventupdatesubjectempty')); - + + $event['comment'] = $comment; + // finally send the message if ($itip->send_itip_message($event, $method, $attendee, $subject, $bodytext, $message)) $sent++; @@ -1648,6 +1653,7 @@ class calendar extends rcube_plugin $vevent = $old; $vevent['cancelled'] = $is_cancelled; $vevent['attendees'] = array($attendee); + $vevent['comment'] = $comment; if ($itip->send_itip_message($vevent, 'CANCEL', $attendee, 'eventcancelsubject', 'eventcancelmailbody')) $sent++; else diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js index d10e8990..bc95b3e0 100644 --- a/plugins/calendar/calendar_ui.js +++ b/plugins/calendar/calendar_ui.js @@ -615,6 +615,7 @@ function rcube_calendar_ui(settings) var allday = $('#edit-allday').get(0); var notify = $('#edit-attendees-donotify').get(0); var invite = $('#edit-attendees-invite').get(0); + var comment = $('#edit-attendees-comment'); notify.checked = has_attendees(event), invite.checked = true; if (event.allDay) { @@ -750,6 +751,7 @@ function rcube_calendar_ui(settings) // tell server to send notifications if ((data.attendees.length || (event.id && event.attendees.length)) && allow_invitations && (notify.checked || invite.checked)) { data._notify = 1; + data._comment = comment.val(); } data.calendar = calendars.val(); diff --git a/plugins/calendar/lib/calendar_ui.php b/plugins/calendar/lib/calendar_ui.php index 8da5e386..9e6835ea 100644 --- a/plugins/calendar/lib/calendar_ui.php +++ b/plugins/calendar/lib/calendar_ui.php @@ -708,15 +708,18 @@ class calendar_ui */ function attendees_form($attrib = array()) { - $input = new html_inputfield(array('name' => 'participant', 'id' => 'edit-attendee-name', 'size' => 30)); + $input = new html_inputfield(array('name' => 'participant', 'id' => 'edit-attendee-name', 'size' => 30)); $checkbox = new html_checkbox(array('name' => 'invite', 'id' => 'edit-attendees-invite', 'value' => 1)); - + $textarea = new html_textarea(array('name' => 'comment', 'id' => 'edit-attendees-comment', + 'rows' => 4, 'cols' => 55, 'title' => $this->cal->gettext('itipcommenttitle'))); + return html::div($attrib, html::div(null, $input->show() . " " . html::tag('input', array('type' => 'button', 'class' => 'button', 'id' => 'edit-attendee-add', 'value' => $this->cal->gettext('addattendee'))) . " " . html::tag('input', array('type' => 'button', 'class' => 'button', 'id' => 'edit-attendee-schedule', 'value' => $this->cal->gettext('scheduletime').'...'))) . - html::p('attendees-invitebox', html::label(null, $checkbox->show(1) . $this->cal->gettext('sendinvitations'))) - ); + html::p('attendees-invitebox', html::label(null, $checkbox->show(1) . $this->cal->gettext('sendinvitations'))) . + html::p('attendees-commentbox', html::label(null, $this->cal->gettext('comment') . $textarea->show())) + ); } /** diff --git a/plugins/calendar/localization/en_US.inc b/plugins/calendar/localization/en_US.inc index 87a3e652..52da7460 100644 --- a/plugins/calendar/localization/en_US.inc +++ b/plugins/calendar/localization/en_US.inc @@ -168,6 +168,7 @@ $labels['itipmailbodycancel'] = "\$sender has rejected your participation in the $labels['itipdeclineevent'] = 'Do you want to decline your invitation to this event?'; $labels['declinedeleteconfirm'] = 'Do you also want to delete this declined event from your calendar?'; +$labels['itipcommenttitle'] = 'This comment will be attached to the invitation/notification message send to participants'; $labels['notanattendee'] = 'You\'re not listed as an attendee of this event'; $labels['eventcancelled'] = 'The event has been cancelled'; diff --git a/plugins/calendar/skins/larry/calendar.css b/plugins/calendar/skins/larry/calendar.css index 5c7dd53c..c79e3346 100644 --- a/plugins/calendar/skins/larry/calendar.css +++ b/plugins/calendar/skins/larry/calendar.css @@ -1106,6 +1106,12 @@ td.topalign { text-align: center; } +#eventedit .attendees-commentbox textarea { + width: auto; + margin-left: 10px; + vertical-align: middle; +} + a.dropdown-link { font-size: 12px; text-decoration: none; diff --git a/plugins/libcalendaring/lib/libcalendaring_itip.php b/plugins/libcalendaring/lib/libcalendaring_itip.php index b03900d2..ec4eb1a8 100644 --- a/plugins/libcalendaring/lib/libcalendaring_itip.php +++ b/plugins/libcalendaring/lib/libcalendaring_itip.php @@ -118,10 +118,9 @@ class libcalendaring_itip ) )); - // append sender's comment - if (!empty($event['comment'])) { - $mailbody .= "\n\n" . $this->gettext('itipsendercomment') . $event['comment']; - } + // if (!empty($event['comment'])) { + // $mailbody .= "\n\n" . $this->gettext('itipsendercomment') . $event['comment']; + // } // append links for direct invitation replies if ($method == 'REQUEST' && ($token = $this->store_invitation($event, $recipient['email']))) {