63 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
72 $isNew = (!isset($id) || !$id);
74 $ownerId = (int)
$request->getPost(
'ownerId');
75 $name = trim(
$request->getPost(
'name'));
77 $customization =
$request->getPost(
'customization') ===
'Y';
78 $userId = \CCalendar::GetUserId();
79 $isPersonal = $type ===
'user' && $ownerId === $userId;
91 'OWNER_ID' => $ownerId,
92 'ACCESS' =>
$request->getPost(
'access'),
93 'EXTERNAL_TYPE' =>
$request->getPost(
'external_type') ??
'local',
96 if ($customization && !$isNew)
102 if (Loader::includeModule(
'extranet') && !\CExtranet::IsIntranetUser(SITE_ID, $userId))
106 && Loader::includeModule(
'socialnetwork')
109 $r = \Bitrix\Socialnetwork\UserToGroupTable::getList([
111 '@ROLE' => \
Bitrix\Socialnetwork\UserToGroupTable::getRolesMember(),
112 '=GROUP_ID' => $ownerId,
113 '=USER_ID' => $userId,
117 if (!$group = $r->fetch())
137 SectionModel::createNew()
138 ->setType($type ??
'')
139 ->setOwnerId($userId ?? 0);
140 if (!$accessController->check(ActionDictionary::ACTION_SECTION_ADD, $sectionModel))
147 if ($type ===
'group' && Loader::includeModule(
'socialnetwork'))
149 $result = \Bitrix\Socialnetwork\UserToGroupTable::getList([
151 '@ROLE' => \
Bitrix\Socialnetwork\UserToGroupTable::getRolesMember(),
152 '=GROUP_ID' => $ownerId,
153 '=USER_ID' => $userId,
157 $group = $result->fetch();
166 $fields[
'IS_EXCHANGE'] =
$request->getPost(
'is_exchange') ===
'Y';
170 $section = \CCalendarSect::GetById($id);
171 $sectionModel = SectionModel::createFromArray($section);
175 || !$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel, [])
184 $fields[
'CAL_TYPE'] = $section[
'CAL_TYPE'];
185 $fields[
'OWNER_ID'] = $section[
'OWNER_ID'];
190 $id = \CCalendar::SaveSection([
'arFields' => $fields]);
193 \CCalendarSect::SetClearOperationCache(
true);
194 $response[
'section'] = \CCalendarSect::GetById($id,
true,
true);
195 if (!$response[
'section'])
201 $response[
'accessNames'] = \CCalendar::GetAccessNames();
203 $response[
'sectionList'] = \CCalendarSect::prepareSectionListResponse($type, $ownerId);
224 !\CCalendar::IsPersonal()
225 && !SectionAccessController::can(\CCalendar::GetUserId(), ActionDictionary::ACTION_SECTION_EDIT, $id)
231 $section = \CCalendarSect::GetById($id);
233 if ($section && $section[
'CAL_DAV_CON'])
235 \CCalendarSect::Edit([
243 $sections = \CCalendarSect::GetList([
245 'CAL_DAV_CON' => $section[
'CAL_DAV_CON'],
250 if (empty($sections))
252 \CCalendar::setOwnerId(\CCalendar::GetUserId());
253 \CCalendar::RemoveConnection([
'id' => (
int)$section[
'CAL_DAV_CON'],
'del_calendars' =>
true]);
262 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
271 if ($mode ===
'users')
273 $userIds =
$request->get(
'userIdList');
274 $ormRes = \Bitrix\Main\UserTable::getList([
275 'filter' => [
'=ID' => $userIds],
276 'select' => [
'ID',
'LOGIN',
'NAME',
'LAST_NAME',
'SECOND_NAME']
278 while ($user = $ormRes->fetch())
280 $user[
'FORMATTED_NAME'] = \CCalendar::GetUserName($user);
284 $sections = \CCalendarSect::getSuperposedList([
'USERS' => $userIds]);
286 elseif ($mode ===
'groups')
288 $groupIds =
$request->get(
'groupIdList') ?? [];
289 $sections = \CCalendarSect::getSuperposedList([
'GROUPS' => $groupIds]);
291 if (Loader::includeModule(
'socialnetwork'))
293 foreach ($groupIds as $groupId)
295 $groupId = (int)$groupId;
296 $createDefaultGroupSection = \CSocNetFeatures::isActiveFeature(
302 if ($createDefaultGroupSection)
304 foreach ($sections as $section)
306 if ((
int)$section[
'OWNER_ID'] === $groupId)
308 $createDefaultGroupSection =
false;
314 if ($createDefaultGroupSection)
316 $sections[] = \CCalendarSect::createDefault([
318 'ownerId' => $groupId
327 $typesRes = \CCalendarType::GetList();
328 foreach ($typesRes as $type)
331 $type[
'XML_ID'] !==
'user'
332 && $type[
'XML_ID'] !==
'group'
333 && $type[
'XML_ID'] !==
'location'
336 $types[] = $type[
'XML_ID'];
340 $sections = \CCalendarSect::getSuperposedList([
'TYPES' => $types]);
345 'sections' => $sections
373 Loader::includeModule(
'intranet')
374 && !ToolsManager::getInstance()->checkAvailabilityByToolId(
'calendar')
380 'isAvailable' =>
false,
384 $responseParams = [];
385 $uniqueId =
'calendar_edit_slider_' . mt_rand();
386 $formType = preg_replace(
'/\W/',
'',
$request->get(
'form_type'));
387 $entryId = (int)
$request->get(
'event_id');
388 $userCodes =
$request->get(
'userCodes');
389 $userId = \CCalendar::GetCurUserId();
390 $ownerId = (int)
$request->get(
'ownerId');
396 $fromTs = !empty($_REQUEST[
'date_from_offset']) ? \CCalendar::Timestamp($_REQUEST[
'date_from'])
397 - $_REQUEST[
'date_from_offset'] : \CCalendar::Timestamp($_REQUEST[
'date_from']);
398 $entry = \CCalendarEvent::getEventForEditInterface($entryId, [
'eventDate' => \CCalendar::Date($fromTs)]);
399 $entryId = is_array($entry) && isset($entry[
'ID']) ? (int)$entry[
'ID'] : $entryId;
406 if (!$entryId || (!empty($entry) && \CCalendarSceleton::CheckBitrix24Limits([
'id' => $uniqueId])))
408 $responseParams[
'uniqueId'] = $uniqueId;
409 $responseParams[
'userId'] = $userId;
410 $responseParams[
'editorId'] = $uniqueId .
'_entry_slider_editor';
411 $responseParams[
'entry'] = $entry;
413 $responseParams[
'timezoneList'] = \CCalendar::GetTimezoneList();
418 if (($type ===
'user' && $ownerId !== $userId) || $type !==
'user')
420 $sectionList = \CCalendar::getSectionList([
422 'OWNER_ID' => $ownerId,
424 'checkPermissions' =>
true,
425 'getPermissions' =>
true
428 foreach ($sectionList as $section)
430 if ($section[
'PERM'][
'edit'] || $section[
'PERM'][
'add'])
432 $sections[] = $section;
437 if (empty($sections) && $type ===
'group')
439 $sections[] = \CCalendarSect::createDefault([
441 'ownerId' => $ownerId
444 \CCalendarSect::setClearOperationCache();
447 $sections = array_merge(
449 \CCalendar::getSectionListAvailableForUser($userId, (array)($entry[
'SECTION_ID'] ??
null))
452 $responseParams[
'sections'] = [];
453 foreach ($sections as $section)
456 ($section[
'PERM'][
'edit'] ??
false)
457 && !\CCalendarSect::CheckGoogleVirtualSection(
458 $section[
'GAPI_CALENDAR_ID'] ??
null,
459 $section[
'EXTERNAL_TYPE'] ??
null,
463 $responseParams[
'sections'][] = $section;
467 $responseParams[
'dayOfWeekMonthFormat'] = stripslashes(
470 ->getDayOfWeekMonthFormat()
474 $responseParams[
'eventWithEmailGuestLimit'] = Bitrix24Manager::getEventWithEmailGuestLimit();
475 $responseParams[
'countEventWithEmailGuestAmount'] = Bitrix24Manager::getCountEventWithEmailGuestAmount();
476 $responseParams[
'iblockMeetingRoomList'] = Rooms\IBlockMeetingRoom::getMeetingRoomList();
477 $responseParams[
'userIndex'] = \CCalendarEvent::getUserIndex();
478 $responseParams[
'locationFeatureEnabled'] = Bitrix24Manager::isFeatureEnabled(
"calendar_location");
479 if ($responseParams[
'locationFeatureEnabled'])
481 $responseParams[
'locationList'] = Rooms\Manager::getRoomsList();
482 $responseParams[
'locationAccess'] = Rooms\Util::getLocationAccess($userId);
484 $responseParams[
'plannerFeatureEnabled'] = Bitrix24Manager::isPlannerFeatureEnabled();
485 $responseParams[
'attendeesEntityList'] = ($entryId > 0 && !empty($entry[
'attendeesEntityList']))
486 ? $entry[
'attendeesEntityList']
488 $responseParams[
'meetSection'] =
null;
489 if ($type === Dictionary::EVENT_TYPE[
'user'])
491 $responseParams[
'meetSection'] =
UserSettings::get($ownerId)[
'meetSection'] ??
null;
494 return new \Bitrix\Main\Engine\Response\Component(
495 'bitrix:calendar.edit.slider',
500 'formType' => $formType,
501 'type' => \CCalendar::GetType(),
502 'bIntranet' => \CCalendar::IsIntranetEnabled(),
503 'bSocNet' => \CCalendar::IsSocNet(),
505 'ATTENDEES_CODES' => $userCodes,
506 'hiddenFields' => $this->getEventEditFormHiddenFields($entry),
545 $responseParams = [];
546 $uniqueId =
'calendar_view_slider_' . mt_rand();
547 $entryId = (int)
$request->get(
'entryId');
548 $userId = \CCalendar::GetCurUserId();
553 $entry = \CCalendarEvent::getEventForViewInterface($entryId,
555 'eventDate' =>
$request->get(
'dateFrom'),
556 'timezoneOffset' => (
int)
$request->get(
'timezoneOffset'),
568 $responseParams[
'uniqueId'] = $uniqueId;
569 $responseParams[
'userId'] = $userId;
570 $responseParams[
'userTimezone'] = \CCalendar::GetUserTimezoneName($userId);
571 $responseParams[
'entry'] = $entry;
572 $responseParams[
'userIndex'] = \CCalendarEvent::getUserIndex();
574 $responseParams[
'plannerFeatureEnabled'] = Bitrix24Manager::isPlannerFeatureEnabled();
575 $responseParams[
'entryUrl'] = \CHTTP::urlAddParams(
576 \CCalendar::GetPath($entry[
'CAL_TYPE'], $entry[
'OWNER_ID'],
true),
578 'EVENT_ID' => (
int)$entry[
'ID'],
579 'EVENT_DATE' => urlencode($entry[
'DATE_FROM'])
581 $responseParams[
'dayOfWeekMonthFormat'] = stripslashes(
584 ->getDayOfWeekMonthFormat()
587 $sections = \CCalendarSect::GetList([
589 'ID' => $entry[
'SECTION_ID'],
592 'checkPermissions' =>
false,
593 'getPermissions' =>
true
596 $responseParams[
'section'] = isset($sections[0]) ? $sections[0] :
null;
598 return new \Bitrix\Main\Engine\Response\Component(
599 'bitrix:calendar.view.slider',
604 'type' => \CCalendar::GetType(),
605 'sectionName' => $_REQUEST[
'section_name'],
606 'bIntranet' => \CCalendar::IsIntranetEnabled(),
607 'bSocNet' => \CCalendar::IsSocNet(),
645 $entryId = (int)
$request[
'entryId'];
646 $parentId = (int)(
$request[
'entry'][
'parentId'] ?? 0);
647 $userId = \CCalendar::getCurUserId();
648 $ownerId = (int)
$request[
'ownerId'];
654 if (!$hostId && $type ===
'user' && !$entryId)
659 if (Loader::includeModule(
'intranet'))
661 if (!\
Bitrix\Intranet\Util::isIntranetUser($userId) && !$isExtranetUser)
670 $entries = \CExtranet::getMyGroupsUsersSimple(\CExtranet::GetExtranetSiteID());
673 if (!$entryId &&
$request[
'cur_event_id'])
675 $entryId = (int)
$request[
'cur_event_id'];
688 if ($entryId > 0 && empty($codes))
690 $codes[] =
'U' . $hostId;
692 if (
$request[
'add_cur_user_to_list'] ===
'Y' || empty($codes))
694 $codes[] =
'U' . $userId;
697 $prevUserList = is_array(
$request[
'prevUserList']) ?
$request[
'prevUserList'] : [];
702 return \CCalendarPlanner::prepareData([
703 'parent_id' => $parentId,
704 'entry_id' => $entryId,
705 'user_id' => $userId,
706 'host_id' => $hostId,
708 'entryLocation' => trim(
$request[
'entryLocation'] ??
""),
709 'entries' => $entries,
710 'date_from' => $dateFrom,
711 'date_to' => $dateTo,
713 'location' => trim(
$request[
'location'] ??
""),
714 'roomEventId' => (
int)
$request[
'roomEventId'],
715 'initPullWatches' =>
true,
716 'prevUserList' => $prevUserList
750 $response = [
'result' =>
false];
752 $event = \CCalendarEvent::GetById((
int)$entryId);
753 $untilTimestamp = \CCalendar::Timestamp($untilDate);
758 if (\CCalendarEvent::CheckRecurcion($event))
760 $event[
'RRULE'] = \CCalendarEvent::ParseRRULE($event[
'RRULE']);
761 $event[
'RRULE'][
'UNTIL'] = \CCalendar::Date($untilTimestamp,
false);
762 if (isset($event[
'RRULE'][
'COUNT']))
764 unset($event[
'RRULE'][
'COUNT']);
767 $id = \CCalendar::SaveEvent([
769 "ID" => $event[
"ID"],
770 "RRULE" => $event[
'RRULE']
772 'silentErrorMode' =>
false,
773 'recursionEditMode' =>
'skip',
774 'editParentEvents' =>
true,
775 'editEntryUntil' =>
true,
777 $recId = $event[
"ID"];
778 $response[
'id'] = $id;
781 if ($event[
"RECURRENCE_ID"] > 0)
783 $recParentEvent = \CCalendarEvent::GetById($event[
"RECURRENCE_ID"]);
784 if ($recParentEvent && \CCalendarEvent::CheckRecurcion($recParentEvent))
786 $recParentEvent[
'RRULE'] = \CCalendarEvent::ParseRRULE($recParentEvent[
'RRULE']);
789 $recParentEvent[
'RRULE'][
'UNTIL']
790 && \CCalendar::Timestamp($recParentEvent[
'RRULE'][
'UNTIL']) > $untilTimestamp
793 $recParentEvent[
'RRULE'][
'UNTIL'] = \CCalendar::Date($untilTimestamp,
false);
795 if (isset($recParentEvent[
'RRULE'][
'COUNT']))
797 unset($recParentEvent[
'RRULE'][
'COUNT']);
800 $id = \CCalendar::SaveEvent([
802 "ID" => $recParentEvent[
"ID"],
803 "RRULE" => $recParentEvent[
'RRULE']
805 'silentErrorMode' =>
false,
806 'recursionEditMode' =>
'skip',
807 'editParentEvents' =>
true,
808 'editEntryUntil' =>
true,
810 $response[
'id'] = $id;
814 $recId = $event[
"RECURRENCE_ID"];
819 $recRelatedEvents = \CCalendarEvent::GetEventsByRecId($recId,
false);
820 foreach ($recRelatedEvents as $ev)
822 if (\CCalendar::Timestamp($ev[
'DATE_FROM']) > $untilTimestamp)
824 \CCalendar::DeleteEvent((
int)$ev[
'ID'],
true, [
'recursionMode' =>
'this']);
829 $response[
'result'] =
true;
832 if ($response[
'result'] !==
true)
835 'change_recurcive_entry_until'));
851 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
856 $sectionList = SectionTable::getList([
864 if (!($section = $sectionList->fetch()))
872 $sectionModel = SectionModel::createFromArray($section);
874 if (!$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel))
881 \CCalendar::DeleteSection($id);
911 $entryId = (int)
$request->getPost(
'entryId');
912 $userId = \CCalendar::GetUserId();
913 $entry = \CCalendarEvent::GetById($entryId);
923 $eventModel = \CCalendarEvent::getEventModelForPermissionCheck($entryId, $entry, $userId);
925 if ($accessController->check(ActionDictionary::ACTION_EVENT_EDIT, $eventModel, [
'checkCurrentEvent' =>
'Y']))
927 $entry[
'REMIND'] = \CCalendarReminder::prepareReminder(
$request->getPost(
'reminders'));
928 $response[
'REMIND'] = $entry[
'REMIND'];
929 $response[
'id'] = \CCalendar::SaveEvent([
931 'ID' => $entry[
'ID'],
932 'REMIND' => $entry[
'REMIND']
934 'updateReminders' =>
true,
935 'checkPermission' =>
false,
938 \CCalendar::ClearCache(
'event_list');
960 $attestedSectionsStatus = [];
962 $sectionsStatus =
$request[
'sectionStatus'];
963 $userId = \CCalendar::getCurUserId();
965 foreach ($sectionsStatus as $sectionId => $sectionStatus)
967 $sectionStatus = json_decode($sectionStatus);
968 if (is_int($sectionId) && is_bool($sectionStatus))
970 $attestedSectionsStatus[$sectionId] = $sectionStatus;
974 if ($attestedSectionsStatus && $userId > 0)
976 \CCalendarSync::SetSectionStatus($userId, $attestedSectionsStatus);
992 $entryId = intVal(
$request->getPost(
'entryId'));
993 $userId = \CCalendar::GetUserId();
994 $entry = \CCalendarEvent::GetById($entryId);
1004 $eventModel = \CCalendarEvent::getEventModelForPermissionCheck($entryId, $entry, $userId);
1006 if ($accessController->check(ActionDictionary::ACTION_EVENT_EDIT, $eventModel, [
'checkCurrentEvent' =>
'Y']))
1008 \CCalendarEvent::updateColor($entryId,
$request->getPost(
'color'));
1009 \CCalendar::ClearCache(
'event_list');
1021 $uid = preg_replace(
'/\W/',
'', $uid);
1023 $userId = \CCalendar::getCurUserId();
1024 $additionalResponseParams = [
1026 'mailboxList' => \Bitrix\Calendar\Integration\Sender\AllowedSender::getList($userId)
1029 return new \Bitrix\Main\Engine\Response\Component(
1030 'bitrix:calendar.settings.slider',
1034 'is_personal' => $showPersonalSettings ===
'Y',
1035 'show_general_settings' => $showGeneralSettings ===
'Y',
1036 'show_access_control' => $showAccessControl ===
'Y'
1038 $additionalResponseParams
1108 public function saveSettingsAction(
string $type, array $user_settings = [],
string $user_timezone_name =
'',
1109 array $settings = []): void
1112 $userId = \CCalendar::GetCurUserId();
1119 $typeModel = TypeModel::createFromXmlId($type);
1121 if ($accessController->check(ActionDictionary::ACTION_TYPE_ACCESS, $typeModel))
1124 if (!empty($settings))
1126 \CCalendar::SetSettings($settings);
1129 if (!empty(
$request[
'type_access']))
1131 \CCalendarType::Edit([
1134 'ACCESS' =>
$request[
'type_access']
1140 if (!empty($user_timezone_name))
1142 \CCalendar::SaveUserTimezoneName($userId, $user_timezone_name);
1143 \CCalendar::ClearCache(
'event_list');
1149 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
1160 if ($type ===
'user')
1163 'ownerId' => \CCalendar::GetCurUserId(),
1164 'userId' => \CCalendar::GetCurUserId(),
1168 else if (in_array($type, [
'company_calendar',
'calendar_company',
'company',
'group'],
true))
1171 $typeModel = TypeModel::createFromXmlId($type);
1173 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel))
1181 'ownerId' =>
$request->getPost(
'ownerId'),
1182 'userId' => \CCalendar::GetCurUserId(),
1193 return CalendarFilter::getFilterData($params);