10 $MAIL_TYPE_EXTERNAL =
"CALENDAR_INVITATION_EXTERNAL";
15 $eventFields = $params[
'arFields'];
16 $invitedUser = $params[
'userIndex'][$userId];
17 $email = $invitedUser[
'EMAIL'];
19 $nameFormatted = str_replace([
'<',
'>',
'"'],
'', \CCalendar::GetUserName($invitedUser));
20 $mailMessageId =
"<CALENDAR_INVITE_".$eventFields[
"PARENT_ID"].
"@".
$GLOBALS[
"SERVER_NAME"].
">";
21 $mailMessageInReplyTo =
"<CALENDAR_INVITE_".$eventFields[
"PARENT_ID"].
"@".
$GLOBALS[
"SERVER_NAME"].
">";
24 $responseEmailAddress =
"CALENDAR_INVITE_".$eventFields[
"PARENT_ID"].
"@".
$GLOBALS[
"SERVER_NAME"];
26 $res = \Bitrix\Mail\User::getReplyTo(
30 $eventFields[
"PARENT_ID"],
36 list($replyTo, $backUrl) = $res;
43 $icsAttachment = self::getIcsFileAttachment($eventFields,
45 'attendees' => self::prepareAttendeesData(
46 $eventFields[
'ATTENDEES'],
47 $params[
'currentAttendees'],
51 'responseEmailAddress' => $responseEmailAddress
53 $attachments = [$icsAttachment];
59 $fromName = str_replace([
'<',
'>',
'"'],
'', $fromName);
61 self::$MAIL_TYPE_EXTERNAL,
64 "=Reply-To" => $fromName.
' <'.$replyTo.
'>',
65 "=Message-Id" => $mailMessageId,
66 "=In-Reply-To" => $mailMessageInReplyTo == $mailMessageId ?
'' : $mailMessageInReplyTo,
67 "EMAIL_FROM" => $fromName.
' <'.\Bitrix\Mail\User::getDefaultEmailFrom().
'>',
68 "EMAIL_TO" => (!empty($nameFormatted) ?
''.$nameFormatted.
' <'.$email.
'>' : $email),
69 "RECIPIENT_ID" => $userId,
71 "POST_ID" => intval($eventFields[
"PARENT_ID"]),
72 "POST_TITLE" =>
'calendar invitation',
73 "URL" => self::getPublicUrl()
83 private static function prepareAttendeesData($attendeeIdList, $currentAttendees, $userIndex, $currentUserId)
87 if (is_array($currentAttendees))
89 foreach($currentAttendees as $user)
91 $attendeeIndex[$user[
'USER_ID']] = $user;
95 if (is_array($attendeeIdList))
97 foreach($attendeeIdList as $userId)
99 if (isset($userIndex[$userId]))
101 if ($attendeeIndex[$userId])
104 'id' => $userIndex[$userId][
'ID'],
105 'email' => $userIndex[$userId][
'EMAIL'],
106 'external_auth_id' => $userIndex[$userId][
'EXTERNAL_AUTH_ID'],
107 'name' => $attendeeIndex[$userId][
'DISPLAY_NAME'],
108 'status' => $attendeeIndex[$userId][
'STATUS']
114 'id' => $userIndex[$userId][
'ID'],
115 'email' => $userIndex[$userId][
'EMAIL'],
116 'external_auth_id' => $userIndex[$userId][
'EXTERNAL_AUTH_ID'],
117 'name' => \CCalendar::getUserName($userIndex[$userId]),
118 'status' => $currentUserId === $userId ?
'H' :
'Q'
126 return $attendeesList;
129 private static function getPublicUrl()
131 return '/pub/event.php';
139 private static function getIcsFileAttachment($eventFields, $params = [])
141 $fileName =
'invite.ics';
144 'type' =>
'text/calendar',
145 'content' => self::getIcsFileContent($eventFields, $params),
146 'MODULE_ID' =>
'calendar'
148 $fileId = \CFile::SaveFile($fileData,
'calendar');
149 $fileArray = \CFile::GetFileArray($fileId);
150 if (!is_array($fileArray))
162 $ics = new \Bitrix\Calendar\ICal\IcsBuilder(
164 'summary' => $eventFields[
'NAME'],
168 'location' => \CCalendar::getTextLocation($eventFields[
'LOCATION'][
'NEW']),
169 'uid' => isset($eventFields[
'DAV_XML_ID']) ? $eventFields[
'DAV_XML_ID'] : uniqid()
172 if ($eventFields[
'SKIP_TIME'] !==
'Y')
174 $ics->setFullDayMode($eventFields[
'SKIP_TIME'] ==
'Y');
177 'timezoneFrom' => $eventFields[
'TZ_FROM'],
178 'timezoneTo' => !empty($eventFields[
'TZ_TO']) ? $eventFields[
'TZ_TO'] : $eventFields[
'TZ_FROM']
183 $ics->setOrganizer($eventFields[
'MEETING'][
'HOST_NAME'], $params[
'responseEmailAddress']);
184 $ics->setAttendees($params[
'attendees']);
185 return $ics->render();
static getMessage($code, $replace=null, $language=null)
$GLOBALS['____1444769544']