55 private $changeFields;
56 private $counterInvitations;
65 $this->method =
$params[
'icalMethod'];
66 $this->eventFields =
$params[
'arFields'];
67 $this->attendees =
$params[
'userIndex'];
68 $this->receiver =
$params[
'receiver'];
69 $this->sender =
$params[
'sender'];
70 $this->changeFields =
$params[
'changeFields'] ??
null;
71 $this->counterInvitations = 0;
72 $this->answer =
$params[
'answer'] ??
null;
79 'eventFields' => $this->eventFields,
80 'attendees' => $this->attendees,
81 'receiver' => $this->receiver,
82 'sender' => $this->sender,
83 'changeFields' => $this->changeFields,
89 $this->method =
$data[
'method'];
90 $this->eventFields =
$data[
'eventFields'];
91 $this->attendees =
$data[
'attendees'];
92 $this->receiver =
$data[
'receiver'];
93 $this->sender =
$data[
'sender'];
94 $this->changeFields =
$data[
'changeFields'];
99 $this->checkOrganizerEmail();
100 $filesContent = $this->getRequestContent();
101 $mailEventFields = $this->getRequestMailEventFields();
102 $files = $this->getFiles();
103 $this->status = \CEvent::sendImmediate(
'SEND_ICAL_INVENT',
SITE_ID, $mailEventFields,
"Y",
"",
$files,
'', $filesContent);
110 $this->prepareEventFields();
112 $filesContent = $this->getReplyContent();
113 $mailEventFields = $this->getReplyMailEventFields();
114 $files = $this->getFiles();
115 $this->status = \CEvent::sendImmediate(
'SEND_ICAL_INVENT',
SITE_ID, $mailEventFields,
"Y",
"",
$files,
'', $filesContent);
122 $filesContent = $this->getCancelContent();
123 $mailEventFields = $this->getCancelMailEventFields();
125 $this->status = \CEvent::sendImmediate(
'SEND_ICAL_INVENT',
SITE_ID, $mailEventFields,
"Y",
"",
$files,
'', $filesContent);
137 $this->counterInvitations++;
142 return $this->eventFields[
'ID'];
147 return $this->eventFields;
157 return $this->counterInvitations;
167 return $this->receiver;
170 private function getSenderAddress(): string
172 return $this->eventFields[
'MEETING'][
'MAIL_FROM'] ?? $this->sender[
'EMAIL'];
175 private function getReceiverAddress(): string
177 if (isset($this->receiver[
'MAILTO']))
179 return $this->receiver[
'MAILTO'];
182 return $this->receiver[
'EMAIL'];
185 private function getBodyMessage(): string
187 return 'ical body message';
190 private function getSubjectMessage(): string
193 $siteName = \COption::GetOptionString(
"main",
"site_name",
'');
194 if ($siteName !==
'')
201 $result .=
": ".$this->eventFields[
'NAME'];
208 return match ($this->method)
210 'request' => Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_REQUEST'),
211 'edit' => Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_EDIT'),
212 'cancel' => Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_CANCEL'),
213 'reply' => match ($this->answer)
215 IncomingInvitationRequestHandler::MEETING_STATUS_ACCEPTED_CODE => Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_REPLY_ACCEPTED'),
216 IncomingInvitationRequestHandler::MEETING_STATUS_DECLINED_CODE => Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_REPLY_DECLINED'),
223 private function getFiles():
array
228 private function getRequestContent():
array
230 $attachmentManager =
new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
231 $attachmentManager->prepareRequestAttachment();
232 $this->uid = $attachmentManager->getUid();
236 'CONTENT_TYPE' => self::CONTENT_TYPE,
238 'CHARSET' => self::CHARSET,
239 'NAME' => self::ATTACHMENT_NAME,
240 'ID' => Helper::getUniqId(),
244 private function getRequestMailEventFields():
array
249 private function getReplyMailEventFields():
array
252 'EMAIL_FROM' => $this->getSenderAddress(),
253 'EMAIL_TO' => $this->getReceiverAddress(),
254 'MESSAGE_SUBJECT' => $this->getSubjectMessage(),
255 'MESSAGE_PHP' => $this->getReplyBodyMessage(),
259 'EVENT_NAME' => $this->eventFields[
'NAME'],
260 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
261 'DATE_TO' => $this->eventFields[
'DATE_TO'],
262 'IS_FULL_DAY' => $this->eventFields[
'DT_SKIP_TIME'] ===
'Y',
263 'TZ_FROM' => $this->eventFields[
'TZ_FROM'],
264 'TZ_TO' => $this->eventFields[
'TZ_TO'],
265 'AVATARS' => $this->eventFields[
'AVATARS'],
266 'OWNER_STATUS' => $this->eventFields[
'OWNER_STATUS'],
268 'BITRIX24_LINK' => Sharing\Helper::getBitrix24Link(),
274 $rrule = \CCalendarEvent::ParseRRULE($this->eventFields[
'RRULE']);
275 if (is_array($rrule))
277 return Helper::getIcalTemplateRRule(
280 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
288 private function getCancelMailEventFields()
291 "=Reply-To" => $this->getOrganizerName().
' <'.$this->getReceiverAddress().
'>',
292 "=From" => $this->getOrganizerName().
' <'.$this->getSenderAddress().
'>',
293 "=Message-Id" => $this->getMessageId(),
294 "=In-Reply-To" => $this->getMessageReplyTo(),
295 'EMAIL_FROM' => $this->getSenderAddress(),
296 'EMAIL_TO' => $this->getReceiverAddress(),
297 'MESSAGE_SUBJECT' => $this->getSubjectMessage(),
298 'MESSAGE_PHP' => $this->getBodyMessage(),
299 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
300 'DATE_TO' => $this->eventFields[
'DATE_TO'],
301 'NAME' => $this->eventFields[
'NAME'],
302 'DESCRIPTION' => str_replace(
"\r\n",
"#$&#$&#$&", $this->eventFields[
'DESCRIPTION']),
303 'ATTENDEES' => $this->getAttendeesList(),
304 'ORGANIZER' => $this->getOrganizerName(),
305 'LOCATION' => $this->eventFields[
'LOCATION'],
306 'FILES_LINK' =>$this->getFilesLink(),
311 private function getAttendeesList(): string
313 if ($this->eventFields[
'MEETING'][
'HIDE_GUESTS'] ??
false)
315 return (
string)Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_HIDE_GUESTS_INFORMATION');
321 foreach ($this->attendees as $attendee)
323 if (!empty($attendee->getFullName()))
325 $attendees[] = $attendee->getFullName();
329 return implode(
", ", $attendees);
332 private function getOrganizerName(): string
335 $organizer = $this->eventFields[
'ICAL_ORGANIZER'];
336 return $organizer->getFullName() .
' (' . $organizer->getEmail() .
')';
339 private function getFilesLink()
341 if (empty($this->eventFields[
'ATTACHES']))
348 foreach ($this->eventFields[
'ATTACHES'] as $attach)
350 $attaches[] =
'<a href="'.$attach[
'link'].
'">'.$attach[
'name'].
'</a><br />' ;
353 return implode(
" ", $attaches);
356 private function getMessageId(): string
358 return "<CALENDAR_EVENT_".$this->eventFields[
'PARENT_ID'].
"@".
$GLOBALS[
"SERVER_NAME"].
">";
361 private function getMessageReplyTo(): string
363 return $this->getMessageId();
366 private function getReplyContent():
array
368 $attachmentManager =
new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
369 $attachmentManager->prepareReplyAttachment();
373 'CONTENT_TYPE' => self::CONTENT_TYPE,
375 'CHARSET' => self::CHARSET,
376 'NAME' => self::ATTACHMENT_NAME,
377 'ID' => Helper::getUniqId(),
381 private function getReplyBodyMessage()
383 return 'reply body message';
386 private function getCancelContent():
array
388 $attachmentManager =
new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
389 $attachmentManager->prepareCancelAttachment();
393 'CONTENT_TYPE' => self::CONTENT_TYPE,
395 'CHARSET' => self::CHARSET,
396 'NAME' => self::ATTACHMENT_NAME,
397 'ID' => ICalUtil::getUniqId(),
401 private function getDateForTemplate()
403 $res = Util::getIcalTemplateDate([
404 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
405 'DATE_TO' => $this->eventFields[
'DATE_TO'],
406 'TZ_FROM' => $this->eventFields[
'TZ_FROM'],
407 'TZ_TO' => $this->eventFields[
'TZ_TO'],
408 'FULL_DAY' => $this->eventFields[
'SKIP_TIME'],
411 $res .=
' (' . $this->eventFields[
'TZ_FROM'] .
', ' .
'UTC' . $offset .
')';
413 if (isset($this->eventFields[
'RRULE'][
'FREQ']) && $this->eventFields[
'RRULE'][
'FREQ'] !==
'NONE')
415 $rruleString = Util::getIcalTemplateRRule($this->eventFields[
'RRULE'],
417 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
418 'DATE_TO' => $this->eventFields[
'DATE_TO'],
419 'TZ_FROM' => $this->eventFields[
'TZ_FROM'],
420 'TZ_TO' => $this->eventFields[
'TZ_TO'],
421 'FULL_DAY' => $this->eventFields[
'SKIP_TIME'],
424 $res .=
', (' . $rruleString .
')';
430 private function getEditTitle()
432 if ($this->method !==
'edit')
437 if (
count($this->changeFields) === 1)
439 switch ($this->changeFields[0][
'fieldKey'])
442 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_DATE');
444 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_LOCATION');
446 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_ATTENDEES');
448 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_RRULE');
450 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_NAME');
452 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_EDIT');
456 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_EDIT');
459 private function getChangeFieldsString()
462 if (!empty($this->changeFields))
464 foreach ($this->changeFields as $changeField)
466 $res[] = $changeField[
'fieldKey'];
469 return implode(
';',
$res);
472 private function checkOrganizerEmail()
474 if (Loader::includeModule(
'mail'))
476 if (empty($this->sender[
'EMAIL']))
478 $boxes = \Bitrix\Mail\MailboxTable::getUserMailboxes($this->eventFields[
'MEETING_HOST']);
479 $email = array_shift($boxes)[
'EMAIL'];
480 $this->sender[
'EMAIL'] =
$email;
481 $this->attendees[$this->eventFields[
'MEETING_HOST']][
'EMAIL'] =
$email;
486 protected function prepareEventFields(): void
488 $event = (
new Core\Mappers\Event())->getByArray($this->eventFields);
489 $this->eventFields[
'DESCRIPTION'] = Public\PublicEvent::prepareEventDescriptionForIcs(
$event);
490 $this->eventFields[
'OWNER_STATUS'] = $this->answer ===
'accepted' ?
'Y' :
'N';
491 $this->eventFields[
'AVATARS'] = [];
494 $parentEvent = (
new Core\Mappers\Event())->getById($this->eventFields[
'PARENT_ID']);
495 $this->eventFields[
'DAV_XML_ID'] = $parentEvent->getUid();
$GLOBALS['____1690880296']