3namespace Bitrix\Mail\Controller;
5use Bitrix\Forum\ForumTable;
6use Bitrix\Mail\Helper\Message;
7use Bitrix\Mail\Integration\Calendar\ICal\ICalMailManager;
8use Bitrix\Mail\Internals\MailMessageAttachmentTable;
9use Bitrix\Main\Application;
10use Bitrix\Main\Config\Option;
11use Bitrix\Main\Engine\Action;
12use Bitrix\Main\Engine\Controller;
14use Bitrix\Main\Loader;
15use Bitrix\Main\Localization\Loc;
21 if (! Loader::includeModule(
'intranet'))
25 return parent::processBeforeAction(
$action);
36 'createChatFromMessage' => [
38 new \Bitrix\Main\Engine\ActionFilter\HttpMethod([
'POST']),
39 new \Bitrix\Main\Engine\ActionFilter\Csrf(),
44 new \Bitrix\Main\Engine\ActionFilter\HttpMethod([
'POST']),
45 new \Bitrix\Main\Engine\ActionFilter\Csrf(),
48 'getCalendarEventDataFromMessage' => [
50 new \Bitrix\Main\Engine\ActionFilter\HttpMethod([
'POST']),
51 new \Bitrix\Main\Engine\ActionFilter\Csrf(),
56 if (Loader::includeModule(
'intranet'))
58 $config[
'createChatFromMessage'][
'+prefilters'][] = new \Bitrix\Intranet\ActionFilter\IntranetUser();
59 $config[
'onCalendarSave'][
'+prefilters'][] = new \Bitrix\Intranet\ActionFilter\IntranetUser();
60 $config[
'getCalendarEventDataFromMessage'][
'+prefilters'][] = new \Bitrix\Intranet\ActionFilter\IntranetUser();
75 if (!Loader::includeModule(
'im'))
85 $this->addError(
new Error(Loc::getMessage(
'MAIL_SECRETARY_ACCESS_DENIED')));
91 $messageData[
'USER_IDS'] = [
$USER->GetID()];
93 if ($chatId = \
Bitrix\Intranet\Secretary::getChatIdIfExists(
$messageId,
'MAIL'))
96 if (! \
Bitrix\Intranet\Secretary::isUserInChat($chatId,
$userId))
98 \Bitrix\Intranet\Secretary::addUserToChat($chatId,
$userId,
false);
105 $lockName =
"chat_create_mail_{$messageId}";
106 if (!Application::getConnection()->lock($lockName))
108 $this->addError(
new Error(
109 Loc::getMessage(
'MAIL_SECRETARY_CREATE_CHAT_LOCK_ERROR'),
'lock_error')
114 $chatId = \Bitrix\Intranet\Secretary::createMailChat($messageData,
$userId);
116 Application::getConnection()->unlock($lockName);
119 if (Loader::includeModule(
'pull'))
125 \CPullWatch::addToStack(
126 'mail_mailbox_' . $mailboxId,
128 'module_id' =>
'mail',
129 'command' =>
'messageBindingCreated',
132 'mailboxId' => $mailboxId,
133 'entityType' => Message::ENTITY_TYPE_IM_CHAT,
134 'entityId' => $chatId,
135 'bindingEntityLink' =>
137 '/online/?IM_DIALOG=chat#chat_id#',
139 'chat_id' => $chatId,
153 if ($this->provideAccessToMessage(
$messageId, $calendarEventId))
155 if ($this->postCalendarBackLinkComment(
$messageId, $calendarEventId))
157 $this->assignCreatedCalendarLabelToMessage(
$messageId, $calendarEventId);
161 $this->addError(
new Error(
'secretary: comment post error'));
166 $this->addError(
new Error(
'secretary: grant access to message failed'));
178 private function assignCreatedCalendarLabelToMessage(
int $messageId,
int $calendarEventId): bool
180 if (Loader::includeModule(
'pull'))
190 \CPullWatch::addToStack(
191 'mail_mailbox_' . $mailboxId,
193 'module_id' =>
'mail',
194 'command' =>
'messageBindingCreated',
197 'mailboxId' => $mailboxId,
198 'entityType' => Message::ENTITY_TYPE_CALENDAR_EVENT,
199 'entityId' => $calendarEventId,
200 'bindingEntityLink' =>
202 $userPage .
'user/#user_id#/calendar/?EVENT_ID=#event_id#',
204 'user_id' =>
$USER->getId(),
205 'event_id' => $calendarEventId,
226 private function provideAccessToMessage(
int $messageId,
int $calendarEventId): bool
231 return \Bitrix\Mail\Integration\Intranet\Secretary::provideAccessToMessage(
233 Message::ENTITY_TYPE_CALENDAR_EVENT,
247 private function postCalendarBackLinkComment(
int $messageId,
int $calendarEventId): bool
249 if (! Loader::includeModule(
'calendar'))
255 if (! Loader::includeModule(
'forum'))
264 $xmlId =
'EVENT_' . $calendarEventId;
266 $calendarEntry = \CCalendarEvent::getEventForViewInterface($calendarEventId, [
273 $this->
addError(
new Error(Loc::getMessage(
'MAIL_SECRETARY_ACCESS_DENIED')));
277 if (! isset($calendarEntry[
'CREATED_BY']) || (
int)$calendarEntry[
'CREATED_BY'] !==
$userId)
279 $this->
addError(
new Error(Loc::getMessage(
'MAIL_SECRETARY_ACCESS_DENIED_CALENDAR')));
285 $xmlId = \CCalendarEvent::getEventCommentXmlId($calendarEntry);
290 'id' => $calendarEventId,
294 $forumId = self::getForumId(array_merge($feedParams, [
304 $feed = new \Bitrix\Forum\Comments\Feed(
310 $link = \Bitrix\Mail\Integration\Intranet\Secretary::getMessageUrlForCalendarEvent(
$messageId, $calendarEventId);
311 $commentMessage = Loc::getMessage(
'MAIL_SECRETARY_POST_MESSAGE_CALENDAR_EVENT', [
315 $forumMessageFields = [
316 'POST_MESSAGE' => $commentMessage,
318 $forumComment = $feed->add($forumMessageFields);
346 if (! Loader::includeModule(
'intranet'))
348 $this->addError(
new Error(
'module intranet unloaded'));
355 $this->addError(
new Error(Loc::getMessage(
'MAIL_SECRETARY_ACCESS_DENIED')));
360 $address = new \Bitrix\Main\Mail\Address(
$message->getFrom());
361 $desc = Loc::getMessage(
'MAIL_SECRETARY_CALENDAR_EVENT_DESC', [
364 '#DATE#' =>
$message->getDate()->toString(),
369 $isIcal = Message::isIcalMessage(
$message);
375 'isNewEvent' => !$isIcal,
381 private static function getForumId(
$params = [])
400 && Loader::includeModule(
'forum')
403 $res = ForumTable::getList([
405 '=XML_ID' =>
'intranet_tasks',
407 'select' => [
'ID' ],
409 if ($forumFields =
$res->fetch())
411 $result = (int)$forumFields[
'ID'];
421 $res = ForumTable::getList([
423 '=XML_ID' =>
'bizproc_workflow',
425 'select' => [
'ID' ],
427 if ($forumFields =
$res->fetch())
429 $result = (int)$forumFields[
'ID'];
439 && Loader::includeModule(
'calendar')
442 $calendarSettings = \CCalendar::getSettings();
443 $result = $calendarSettings[
"forum_id"];
447 && Loader::includeModule(
'forum')
452 '=XML_ID' =>
'PHOTOGALLERY_COMMENTS'
454 'select' =>
array(
'ID')
456 if ($forumFields =
$res->fetch())
458 $result = (int)$forumFields[
'ID'];
469 '=XML_ID' =>
'USERS_AND_GROUPS'
471 'select' =>
array(
'ID')
473 if ($forumFields =
$res->fetch())
475 $result = (int)$forumFields[
'ID'];
492 return \Bitrix\Mail\MessageAccess::createByMessageId(
$messageId,
$userId)->canModifyMessage();
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
getCalendarEventDataFromMessageAction(int $messageId)
processBeforeAction(Action $action)
onCalendarSaveAction(int $messageId, int $calendarEventId)
createChatFromMessageAction(int $messageId)
static getMessage(int $id)
static getMailboxIdForMessage(int $messageId)
static get($moduleId, $name, $default="", $siteId=false)
static makePathFromTemplate($template, $arParams=array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
addError(string $class, string $message='')
if(mb_strlen($order)< 6) $desc
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']