1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
calendarajax.php
См. документацию.
1<?php
3
4use Bitrix\Bitrix24\Feature;
24use Bitrix\Intranet\Settings\Tools\ToolsManager;
34
35Loc::loadMessages(__FILE__);
36
41{
43 'repeatRule' => 'rrule',
44 'crm' => 'crm',
45 'accessibility' => 'accessibility',
46 ];
47
48 public function configureActions()
49 {
50 return [
51 'getTimezoneList' => [
52 '-prefilters' => [
53 Authentication::class
54 ]
55 ],
56 'editCalendarSection' => [
57 '+prefilters' => [
59 ],
60 ],
61 'deleteCalendarSection' => [
62 '+prefilters' => [
64 ],
65 ],
66 'hideExternalCalendarSection' => [
67 '+prefilters' => [
69 ],
70 ],
71 ];
72 }
73
74 public function getTimezoneListAction()
75 {
76 $timezones = \CCalendar::getTimezoneList();
77 $defaultTimezone = \CCalendar::getGoodTimezoneForOffset(\CCalendar::getCurrentOffsetUTC(\CCalendar::getCurUserId()));
78 if (isset($timezones[$defaultTimezone]))
79 {
80 $timezones[$defaultTimezone]['default'] = true;
81 }
82
83 return $timezones;
84 }
85
86 public function editCalendarSectionAction()
87 {
88 $request = $this->getRequest();
89 $response = [];
90
91 $id = $request->getPost('id');
92 $isNew = (!isset($id) || !$id);
93 $type = $request->getPost('type');
94 $ownerId = (int)$request->getPost('ownerId');
95 $name = trim($request->getPost('name'));
96 $color = $request->getPost('color');
97 $customization = $request->getPost('customization') === 'Y';
98 $userId = \CCalendar::GetUserId();
99
100 if ($id === 'tasks')
101 {
102 $id .= $ownerId;
103 }
104
105 $fields = [
106 'ID' => $id,
107 'NAME' => $name,
108 'COLOR' => $color,
109 'CAL_TYPE' => $type,
110 'OWNER_ID' => $ownerId,
111 'ACCESS' => $request->getPost('access'),
112 'EXTERNAL_TYPE' => $request->getPost('external_type') ?? 'local',
113 ];
114
115 if ($customization && !$isNew)
116 {
117 UserSettings::setSectionCustomization($userId, [$id => ['name' => $name, 'color' => $color]]);
118 }
119 else
120 {
121 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
122 {
123 if (
124 $type === 'group'
125 && Loader::includeModule('socialnetwork')
126 )
127 {
128 $rights = \Bitrix\Socialnetwork\UserToGroupTable::getList([
129 'filter' => [
130 '@ROLE' => \Bitrix\Socialnetwork\UserToGroupTable::getRolesMember(),
131 '=GROUP_ID' => $ownerId,
132 '=USER_ID' => $userId,
133 ],
134 'limit' => 1,
135 ]);
136
137 if (!$rights->fetch())
138 {
139 $this->addError(
140 new Error(Loc::getMessage('EC_ACCESS_DENIED'), 'access_denied_extranet_group')
141 );
142 }
143 }
144 else if ($type === 'user')
145 {
146 if ($userId !== $ownerId)
147 {
148 $this->addError(
149 new Error(Loc::getMessage('EC_ACCESS_DENIED'), 'access_denied_extranet_user')
150 );
151 }
152 }
153 else
154 {
155 $this->addError(
156 new Error(Loc::getMessage('EC_ACCESS_DENIED'), 'access_denied_extranet')
157 );
158 }
159 }
160
161 if ($this->getErrors())
162 {
163 return $response;
164 }
165
167
168 if ($isNew) // For new sections
169 {
170 $sectionModel =
171 SectionModel::createNew()
172 ->setType($type ?? '')
173 ->setOwnerId($userId ?? 0);
174 if (!$accessController->check(ActionDictionary::ACTION_SECTION_ADD, $sectionModel))
175 {
176 $this->addError(
177 new Error(Loc::getMessage('EC_ACCESS_DENIED'), 'access_denied')
178 );
179 }
180
181 if ($type === 'group' && Loader::includeModule('socialnetwork'))
182 {
183 $result = \Bitrix\Socialnetwork\UserToGroupTable::getList([
184 'filter' => [
185 '@ROLE' => \Bitrix\Socialnetwork\UserToGroupTable::getRolesMember(),
186 '=GROUP_ID' => $ownerId,
187 '=USER_ID' => $userId,
188 ],
189 ]);
190
191 $group = $result->fetch();
192 if (!$group)
193 {
194 $this->addError(
195 new Error(Loc::getMessage('EC_ACCESS_DENIED'), 'access_denied_user')
196 );
197 }
198 }
199
200 $fields['IS_EXCHANGE'] = $request->getPost('is_exchange') === 'Y';
201 }
202 else
203 {
204 $section = \CCalendarSect::GetById($id);
205 $sectionModel = SectionModel::createFromArray($section);
206
207 if (
208 !$section
209 || !$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel, [])
210
211 )
212 {
213 $this->addError(
214 new Error(Loc::getMessage('EC_ACCESS_DENIED'), 'access_denied_04')
215 );
216 }
217
218 $fields['CAL_TYPE'] = $section['CAL_TYPE'];
219 $fields['OWNER_ID'] = $section['OWNER_ID'];
220 }
221
222 if (empty($this->getErrors()))
223 {
224 $id = \CCalendar::SaveSection(['arFields' => $fields]);
225 if ((int)$id > 0)
226 {
227 \CCalendarSect::SetClearOperationCache(true);
228 $response['section'] = \CCalendarSect::GetById($id, true, true);
229 if (!$response['section'])
230 {
231 $this->addError(
232 new Error(Loc::getMessage('EC_CALENDAR_SAVE_ERROR'), 'saving_error_05')
233 );
234 }
235 $response['accessNames'] = \CCalendar::GetAccessNames();
236
237 $response['sectionList'] = \CCalendarSect::prepareSectionListResponse($type, $ownerId);
238 }
239 else
240 {
241 $this->addError(
242 new Error(Loc::getMessage('EC_CALENDAR_SAVE_ERROR'), 'saving_error_06')
243 );
244 }
245 }
246 }
247
248 return $response;
249 }
250
252 {
253 $request = $this->getRequest();
254 $response = [];
255 $id = $request->getPost('id');
256
257 if (
258 !\CCalendar::IsPersonal()
259 && !SectionAccessController::can(\CCalendar::GetUserId(), ActionDictionary::ACTION_SECTION_EDIT, $id)
260 )
261 {
262 $this->addError(new Error('[sd02]' . Loc::getMessage('EC_ACCESS_DENIED'), 'access_denied'));
263 }
264
265 $section = \CCalendarSect::GetById($id);
266 // For exchange we change only calendar name
267 if ($section && $section['CAL_DAV_CON'])
268 {
269 \CCalendarSect::Edit([
270 'arFields' => [
271 'ID' => $id,
272 'ACTIVE' => 'N'
273 ]
274 ]);
275
276 // Check if it's last section from connection - remove it
277 $sections = \CCalendarSect::GetList([
278 'arFilter' => [
279 'CAL_DAV_CON' => $section['CAL_DAV_CON'],
280 'ACTIVE' => 'Y'
281 ]
282 ]);
283
284 if (empty($sections))
285 {
286 \CCalendar::setOwnerId(\CCalendar::GetUserId());
287 \CCalendar::RemoveConnection(['id' => (int)$section['CAL_DAV_CON'], 'del_calendars' => true]);
288 }
289 }
290
291 return $response;
292 }
293
295 {
296 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
297 {
298 return [];
299 }
300
301 $request = $this->getRequest();
302 $mode = $request->get('type');
303
304 $users = [];
305 if ($mode === 'users')
306 {
307 $userIds = $request->get('userIdList');
309 'filter' => ['=ID' => $userIds],
310 'select' => ['ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME']
311 ]);
312 while ($user = $ormRes->fetch())
313 {
314 $user['FORMATTED_NAME'] = \CCalendar::GetUserName($user);
315 $users[] = $user;
316 }
317
318 $sections = \CCalendarSect::getSuperposedList(['USERS' => $userIds]);
319 }
320 elseif ($mode === 'groups' || $mode === 'collabs')
321 {
322 $sections = [];
323 $groupIds = $request->get('groupIdList') ?? [];
324
325 if (Loader::includeModule('socialnetwork'))
326 {
327 if (!empty($groupIds))
328 {
329 $sections = \CCalendarSect::getSuperposedList(['GROUPS' => $groupIds]);
330 }
331
332 foreach ($groupIds as $groupId)
333 {
334 $groupId = (int)$groupId;
335 $createDefaultGroupSection = \CSocNetFeatures::isActiveFeature(
337 $groupId,
338 "calendar"
339 );
340
341 if ($createDefaultGroupSection)
342 {
343 foreach ($sections as $section)
344 {
345 if ((int)$section['OWNER_ID'] === $groupId)
346 {
347 $createDefaultGroupSection = false;
348 break;
349 }
350 }
351 }
352
353 if ($createDefaultGroupSection)
354 {
355 $sections[] = \CCalendarSect::createDefault([
356 'type' => 'group',
357 'ownerId' => $groupId
358 ]);
359 }
360 }
361 }
362 }
363 else
364 {
365 $types = [];
366 $typesRes = \CCalendarType::GetList();
367 foreach ($typesRes as $type)
368 {
369 if (
370 $type['XML_ID'] !== 'user'
371 && $type['XML_ID'] !== 'group'
372 && $type['XML_ID'] !== 'location'
373 )
374 {
375 $types[] = $type['XML_ID'];
376 }
377 }
378
379 $sections = \CCalendarSect::getSuperposedList(['TYPES' => $types]);
380 }
381
382 return [
383 'users' => $users,
384 'sections' => $sections
385 ];
386 }
387
389 {
390 $request = $this->getRequest();
391 $type = $request->get('type');
392
393 $userId = \CCalendar::getCurUserId();
394 if ($type === 'users')
395 {
397 }
398
399 $sections = $request->get('sections');
400 if (!$sections)
401 {
402 $sections = [];
403 }
404
405 \CCalendar::setDisplayedSuperposed($userId, $sections);
406
407 return [];
408 }
409
410 public function getEditEventSliderAction()
411 {
412 if (
413 Loader::includeModule('intranet')
414 && !ToolsManager::getInstance()->checkAvailabilityByToolId('calendar')
415 )
416 {
417 $this->addError(new Error('Tool not available'));
418
419 return [
420 'isAvailable' => false,
421 ];
422 }
423 $request = $this->getRequest();
424 $responseParams = [];
425 $uniqueId = 'calendar_edit_slider_' . mt_rand();
426 $formType = preg_replace('/\W/', '', $request->get('form_type'));
427 $entryId = (int)$request->get('event_id');
428 $userCodes = $request->get('userCodes');
429 $userId = \CCalendar::GetCurUserId();
430 $ownerId = (int)$request->get('ownerId');
431 $type = $request->get('type');
432 $sections = [];
433
434 if ($entryId > 0)
435 {
436 $fromTs = !empty($_REQUEST['date_from_offset']) ? \CCalendar::Timestamp($_REQUEST['date_from'])
437 - $_REQUEST['date_from_offset'] : \CCalendar::Timestamp($_REQUEST['date_from']);
438 $entry = \CCalendarEvent::getEventForEditInterface($entryId, ['eventDate' => \CCalendar::Date($fromTs)]);
439 $entryId = is_array($entry) && isset($entry['ID']) ? (int)$entry['ID'] : $entryId;
440 }
441 else
442 {
443 $entry = [];
444 }
445
446 if (!$entryId || (!empty($entry) && \CCalendarSceleton::CheckBitrix24Limits(['id' => $uniqueId])))
447 {
448 $responseParams['uniqueId'] = $uniqueId;
449 $responseParams['userId'] = $userId;
450 $responseParams['editorId'] = $uniqueId . '_entry_slider_editor';
451 $responseParams['entry'] = $entry;
452 $responseParams['timezoneHint'] = !empty($entry) ? Util::getTimezoneHint($userId, $entry) : '';
453 $responseParams['timezoneList'] = \CCalendar::GetTimezoneList();
454 $responseParams['absenceAvailable'] = (!\CCalendar::IsBitrix24()
455 || \COption::GetOptionString("bitrix24", "absence_limits_enabled", "") !== "Y"
456 || Feature::isFeatureEnabled("absence"))
457 ;
458 $responseParams['formSettings'] = UserSettings::getFormSettings($formType);
459 $isOpenEvent = $type === Dictionary::CALENDAR_TYPE['open_event'];
460 $isCollabUser = Util::isCollabUser($userId);
461
462 if ($type)
463 {
464 $sectionList = [];
465 if ($isOpenEvent)
466 {
467 $sectionList = \CCalendar::getSectionList([
468 'CAL_TYPE' => Dictionary::CALENDAR_TYPE['open_event'],
469 ]);
470 }
471 else if ($isCollabUser)
472 {
473 $userCollabIds = UserCollabs::getInstance()->getIds($userId);
474 if (
475 $type === Dictionary::CALENDAR_TYPE['group']
476 && !in_array($ownerId, $userCollabIds, true)
477 )
478 {
479 $this->addError(new Error('access denied'));
480
481 return [];
482 }
483
484 $sectionList = \CCalendar::getSectionList([
485 'CAL_TYPE' => Dictionary::CALENDAR_TYPE['group'],
486 'OWNER_ID' => $userCollabIds,
487 'ACTIVE' => 'Y',
488 'checkPermissions' => true,
489 'getPermissions' => true
490 ]);
491 }
492 else if (($type === 'user' && $ownerId !== $userId) || $type !== 'user')
493 {
494 $sectionList = \CCalendar::getSectionList([
495 'CAL_TYPE' => $type,
496 'OWNER_ID' => $ownerId,
497 'ACTIVE' => 'Y',
498 'checkPermissions' => true,
499 'getPermissions' => true
500 ]);
501 }
502
503 $hasCurrentCalendarInSections = false;
504 foreach ($sectionList as $section)
505 {
506 if ($section['CAL_TYPE'] === Dictionary::CALENDAR_TYPE['open_event'])
507 {
508 $section['PERM']['edit'] = true;
509 }
510
511 if ($section['PERM']['edit'] || $section['PERM']['add'])
512 {
513 $sections[] = $section;
514
515 if (
516 $section['CAL_TYPE'] === Dictionary::CALENDAR_TYPE['group']
517 && (int)$section['OWNER_ID'] === $ownerId
518 )
519 {
520 $hasCurrentCalendarInSections = true;
521 }
522 }
523 }
524
525 if (
526 $type === Dictionary::CALENDAR_TYPE['group']
527 && (empty($sections) || !$hasCurrentCalendarInSections)
528 )
529 {
530 $sections[] = \CCalendarSect::createDefault([
531 'type' => $type,
532 'ownerId' => $ownerId
533 ]);
534
535 \CCalendarSect::setClearOperationCache();
536 }
537 }
538
539 if (!$isOpenEvent && !$isCollabUser)
540 {
541 $sections = array_merge(
542 $sections,
543 \CCalendar::getSectionListAvailableForUser($userId, (array)($entry['SECTION_ID'] ?? null))
544 );
545 }
546
547 $responseParams['sections'] = [];
548 foreach ($sections as $section)
549 {
550 if (
551 ($section['PERM']['edit'] ?? false)
552 && !\CCalendarSect::CheckGoogleVirtualSection(
553 $section['GAPI_CALENDAR_ID'] ?? null,
554 $section['EXTERNAL_TYPE'] ?? null,
555 )
556 )
557 {
558 $responseParams['sections'][] = $section;
559 }
560 }
561
562 $responseParams['dayOfWeekMonthFormat'] = (
563 \Bitrix\Main\Context::getCurrent()
564 ->getCulture()
565 ->getDayOfWeekMonthFormat()
566 );
567 $responseParams['trackingUsersList'] = UserSettings::getTrackingUsers($userId);
568 $responseParams['userSettings'] = UserSettings::get($userId);
569 $responseParams['iblockMeetingRoomList'] = Rooms\IBlockMeetingRoom::getMeetingRoomList();
570 $responseParams['userIndex'] = \CCalendarEvent::getUserIndex();
571 $locationFeatureEnabled = Bitrix24Manager::isFeatureEnabled(FeatureDictionary::CALENDAR_LOCATION);
572
573 // collab user not have access to rooms management, but if it already set for event, it should display
574 $responseParams['locationFeatureEnabled'] = !$isCollabUser && $locationFeatureEnabled;
575 if ($locationFeatureEnabled || $isCollabUser)
576 {
577 $responseParams['locationList'] = Rooms\Manager::getRoomsList();
578 $responseParams['locationAccess'] = Rooms\Util::getLocationAccess($userId);
579 }
580 $responseParams['plannerFeatureEnabled'] = Bitrix24Manager::isPlannerFeatureEnabled();
581 $responseParams['attendeesEntityList'] = ($entryId > 0 && !empty($entry['attendeesEntityList']))
582 ? $entry['attendeesEntityList']
584 $responseParams['meetSection'] = null;
585 if ($type === Dictionary::CALENDAR_TYPE['user'])
586 {
587 $responseParams['meetSection'] = UserSettings::get($ownerId)['meetSection'] ?? null;
588 }
589 $responseParams['eventWithEmailGuestEnabled'] = Bitrix24Manager::isFeatureEnabled(FeatureDictionary::CALENDAR_EVENTS_WITH_EMAIL_GUESTS);
590
591 if ($isOpenEvent)
592 {
593 $responseParams['defaultCategoryId'] = DefaultCategoryService::getInstance()->getCategoryId();
594 }
595
596 if (Loader::includeModule('socialnetwork'))
597 {
599
600 $responseParams['projectFeatureEnabled'] = \Bitrix\Socialnetwork\Helper\Feature::isFeatureEnabled($projectLimitFeatureId)
602 ;
603 }
604
605 $responseParams['isCollabUser'] = $isCollabUser;
606
607 return new \Bitrix\Main\Engine\Response\Component(
608 'bitrix:calendar.edit.slider',
609 '',
610 [
611 'id' => $uniqueId,
612 'event' => $entry,
613 'formType' => $formType,
614 'type' => $isOpenEvent ? Dictionary::CALENDAR_TYPE['open_event'] : \CCalendar::GetType(),
615 'bIntranet' => \CCalendar::IsIntranetEnabled(),
616 'bSocNet' => \CCalendar::IsSocNet(),
617 'AVATAR_SIZE' => 21,
618 'ATTENDEES_CODES' => $userCodes,
619 'hiddenFields' => $this->getEventEditFormHiddenFields($entry),
620 'sections' => $responseParams['sections'],
621 ],
622 $responseParams
623 );
624 }
625
626 $this->addError(new Error('[se05] No entry found'));
627
628 return [];
629 }
630
631 private function getEventEditFormHiddenFields(array $entry): array
632 {
633 $hiddenFields = [];
634
635 if ($this->isSharingEvent($entry))
636 {
637 $hiddenFields = array_merge(
638 $hiddenFields,
639 [
640 self::EVENT_EDIT_FORM_FIELDS_THAT_CAN_BE_HIDDEN['crm'],
641 ]
642 );
643 }
644
645 return $hiddenFields;
646 }
647
648 private function isSharingEvent(array $entry): bool
649 {
650 return
651 isset($entry['EVENT_TYPE'])
652 && in_array($entry['EVENT_TYPE'], Sharing\SharingEventManager::getSharingEventTypes())
653 ;
654 }
655
656 public function getViewEventSliderAction()
657 {
658 $request = $this->getRequest();
659 $responseParams = [];
660 $uniqueId = 'calendar_view_slider_' . mt_rand();
661 $entryId = (int)$request->get('entryId');
662 $userId = \CCalendar::GetCurUserId();
663 $entry = null;
664
665 if ($entryId)
666 {
667 $entry = \CCalendarEvent::getEventForViewInterface($entryId,
668 [
669 'eventDate' => $request->get('dateFrom'),
670 'timezoneOffset' => (int)$request->get('timezoneOffset'),
671 'userId' => $userId
672 ]
673 );
674 }
675 else
676 {
677 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND'), 'EVENT_NOT_FOUND_01'));
678 }
679
680 if ($entry)
681 {
682 $responseParams['uniqueId'] = $uniqueId;
683 $responseParams['userId'] = $userId;
684 $responseParams['userTimezone'] = \CCalendar::GetUserTimezoneName($userId);
685 $responseParams['entry'] = $entry;
686 $responseParams['userIndex'] = \CCalendarEvent::getUserIndex();
687 $responseParams['userSettings'] = UserSettings::get($userId);
688 $responseParams['plannerFeatureEnabled'] = Bitrix24Manager::isPlannerFeatureEnabled();
689 $responseParams['entryUrl'] = \CCalendar::getEntryUrl(
690 $entry['CAL_TYPE'],
691 $entry['OWNER_ID'],
692 $entry['ID'],
693 $entry['DATE_FROM']
694 );
695 $responseParams['dayOfWeekMonthFormat'] = (
696 \Bitrix\Main\Context::getCurrent()
697 ->getCulture()
698 ->getDayOfWeekMonthFormat()
699 );
700
701 $sections = \CCalendarSect::GetList([
702 'arFilter' => [
703 'ID' => $entry['SECTION_ID'],
704 'ACTIVE' => 'Y',
705 ],
706 'checkPermissions' => false,
707 'getPermissions' => true
708 ]);
709
710 $responseParams['section'] = isset($sections[0]) ? $sections[0] : null;
711
712 return new \Bitrix\Main\Engine\Response\Component(
713 'bitrix:calendar.view.slider',
714 '',
715 [
716 'id' => $uniqueId,
717 'event' => $entry,
718 'type' => \CCalendar::GetType(),
719 'sectionName' => $_REQUEST['section_name'],
720 'bIntranet' => \CCalendar::IsIntranetEnabled(),
721 'bSocNet' => \CCalendar::IsSocNet(),
722 'AVATAR_SIZE' => 21
723 ],
724 $responseParams
725 );
726 }
727
728 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND'), 'EVENT_NOT_FOUND_02'));
729
730 return [];
731 }
732
733 public function getCrmUserfieldAction()
734 {
735 $request = $this->getRequest();
736 $UF = \CCalendarEvent::GetEventUserFields(['PARENT_ID' => (int)$request->get('event_id')]);
737 if (isset($UF['UF_CRM_CAL_EVENT']))
738 {
739 $crmUF = $UF['UF_CRM_CAL_EVENT'];
740 $additionalResponseParams = [];
741 return new \Bitrix\Main\Engine\Response\Component(
742 'bitrix:system.field.edit',
743 $crmUF["USER_TYPE"]["USER_TYPE_ID"],
744 [
745 "bVarsFromForm" => false,
746 "arUserField" => $crmUF,
747 "form_name" => 'event_edit_form'
748 ],
749 $additionalResponseParams
750 );
751 }
752
753 return [];
754 }
755
756 public function updatePlannerAction()
757 {
758 $request = $this->getRequest();
759 $entryId = (int)$request['entryId'];
760 $parentId = (int)($request['entry']['parentId'] ?? $request['parentId'] ?? 0);
761 $userId = \CCalendar::getCurUserId();
762 $ownerId = (int)$request['ownerId'];
763 $type = $request['type'];
764 $entries = $request['entries'];
765 $isExtranetUser = Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser($userId);
766
767 $hostId = (int)$request['hostId'];
768 if (!$hostId && $type === 'user' && !$entryId)
769 {
770 $hostId = $ownerId;
771 }
772
773 if ($isExtranetUser)
774 {
775 $entries = \CExtranet::getMyGroupsUsersSimple(\CExtranet::GetExtranetSiteID());
776 }
777
778 if (!$entryId && $request['cur_event_id'])
779 {
780 $entryId = (int)$request['cur_event_id'];
781 }
782
783 $codes = [];
784 // open event need only location planner, so ignore entityList
785 if ($type !== Dictionary::CALENDAR_TYPE['open_event'])
786 {
787 if (isset($request['entityList']) && is_array($request['entityList']))
788 {
789 $codes = Util::convertEntitiesToCodes($request['entityList']);
790 }
791 elseif (isset($request['codes']) && is_array($request['codes']))
792 {
793 $codes = $request['codes'];
794 }
795
796 if ($entryId > 0 && empty($codes))
797 {
798 $codes[] = 'U' . $hostId;
799 }
800 if ($request['add_cur_user_to_list'] === 'Y' || empty($codes))
801 {
802 $codes[] = 'U' . $userId;
803 }
804 }
805
806 $entryType = $request['entry']['data']['CAL_TYPE'] ?? null;
807 if ($entryType === Dictionary::CALENDAR_TYPE['open_event'])
808 {
809 $codes = ['U' . $userId];
810 }
811
812 $prevUserList = is_array($request['prevUserList']) ? $request['prevUserList'] : [];
813 $skipFeatureCheck = ($request['skipFeatureCheck'] ?? null) === 'Y';
814
815 $dateFrom = isset($request['dateFrom']) ? $request['dateFrom'] : $request['date_from'];
816 $dateTo = isset($request['dateTo']) ? $request['dateTo'] : $request['date_to'];
817
818 return \CCalendarPlanner::prepareData([
819 'parent_id' => $parentId,
820 'entry_id' => $entryId,
821 'user_id' => $userId,
822 'host_id' => $hostId,
823 'codes' => $codes,
824 'entryLocation' => trim($request['entryLocation'] ?? ""),
825 'entries' => $entries,
826 'date_from' => $dateFrom,
827 'date_to' => $dateTo,
828 'timezone' => $request['timezone'],
829 'location' => trim($request['location'] ?? ""),
830 'roomEventId' => (int)$request['roomEventId'],
831 'initPullWatches' => true,
832 'prevUserList' => $prevUserList,
833 'skipFeatureCheck' => $skipFeatureCheck,
834 ]);
835 }
836
837 public function getPlannerAction()
838 {
839 $request = $this->getRequest();
840 \CCalendarPlanner::Init(['id' => $request['planner_id']]);
841 return [];
842 }
843
844 public function deleteCalendarEntryAction($entryId, $recursionMode, $requestUid)
845 {
846 $response = [];
847
848 $response['result'] = \CCalendar::deleteEvent(
849 $entryId,
850 true,
851 [
852 'recursionMode' => $recursionMode,
853 'requestUid' => (int)$requestUid
854 ]
855 );
856
857 if ($response['result'] !== true)
858 {
859 $this->addError(new Error('[ed01]' . Loc::getMessage('EC_EVENT_DEL_ERROR'), 'delete_entry_error'));
860 }
861
862 return $response;
863 }
864
865 public function changeRecurciveEntryUntilAction($entryId, $untilDate)
866 {
867 $response = ['result' => false];
868
869 $event = \CCalendarEvent::GetById((int)$entryId);
870 $untilTimestamp = \CCalendar::Timestamp($untilDate);
871 $recId = false;
872
873 if ($event)
874 {
875 if (\CCalendarEvent::CheckRecurcion($event))
876 {
877 $event['RRULE'] = \CCalendarEvent::ParseRRULE($event['RRULE']);
878 $event['RRULE']['UNTIL'] = \CCalendar::Date($untilTimestamp, false);
879 if (isset($event['RRULE']['COUNT']))
880 {
881 unset($event['RRULE']['COUNT']);
882 }
883
884 $id = \CCalendar::SaveEvent([
885 'arFields' => [
886 "ID" => $event["ID"],
887 "RRULE" => $event['RRULE']
888 ],
889 'silentErrorMode' => false,
890 'recursionEditMode' => 'skip',
891 'editParentEvents' => true,
892 'editEntryUntil' => true,
893 ]);
894 $recId = $event["ID"];
895 $response['id'] = $id;
896 }
897
898 if ($event["RECURRENCE_ID"] > 0)
899 {
900 $recParentEvent = \CCalendarEvent::GetById($event["RECURRENCE_ID"]);
901 if ($recParentEvent && \CCalendarEvent::CheckRecurcion($recParentEvent))
902 {
903 $recParentEvent['RRULE'] = \CCalendarEvent::ParseRRULE($recParentEvent['RRULE']);
904
905 if (
906 $recParentEvent['RRULE']['UNTIL']
907 && \CCalendar::Timestamp($recParentEvent['RRULE']['UNTIL']) > $untilTimestamp
908 )
909 {
910 $recParentEvent['RRULE']['UNTIL'] = \CCalendar::Date($untilTimestamp, false);
911
912 if (isset($recParentEvent['RRULE']['COUNT']))
913 {
914 unset($recParentEvent['RRULE']['COUNT']);
915 }
916
917 $id = \CCalendar::SaveEvent([
918 'arFields' => [
919 "ID" => $recParentEvent["ID"],
920 "RRULE" => $recParentEvent['RRULE']
921 ],
922 'silentErrorMode' => false,
923 'recursionEditMode' => 'skip',
924 'editParentEvents' => true,
925 'editEntryUntil' => true,
926 ]);
927 $response['id'] = $id;
928 }
929 }
930
931 $recId = $event["RECURRENCE_ID"];
932 }
933
934 if ($recId)
935 {
936 $recRelatedEvents = \CCalendarEvent::GetEventsByRecId($recId, false);
937 foreach ($recRelatedEvents as $ev)
938 {
939 if (\CCalendar::Timestamp($ev['DATE_FROM']) > $untilTimestamp)
940 {
941 \CCalendar::DeleteEvent((int)$ev['ID'], true, ['recursionMode' => 'this']);
942 }
943 }
944 }
945
946 $response['result'] = true;
947 }
948
949 if ($response['result'] !== true)
950 {
951 $this->addError(new Error('[ed01]' . Loc::getMessage('EC_EVENT_DEL_ERROR'),
952 'change_recurcive_entry_until'));
953 }
954
955 return $response;
956 }
957
958 public function excludeRecursionDateAction($entryId, $excludeDate)
959 {
960 \CCalendarEvent::ExcludeInstance((int)$entryId, $excludeDate);
961
962 return [];
963 }
964
965 public function deleteCalendarSectionAction($id)
966 {
967 $response = [];
968
969 $sectionList = SectionTable::getList([
970 'filter' => [
971 '=ACTIVE' => 'Y',
972 '=ID' => (int)$id
973 ],
974 'limit' => 1,
975 ]
976 );
977
978 if (!($section = $sectionList->fetch()))
979 {
980 $this->addError(new Error(Loc::getMessage('EC_SECTION_NOT_FOUND'), 'section_not_found'));
981
982 return $response;
983 }
984
985 $accessController = new SectionAccessController(\CCalendar::GetUserId());
986 $sectionModel = SectionModel::createFromArray($section);
987
988 if (!$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel))
989 {
990 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED'), 'access_denied'));
991
992 return $response;
993 }
994
995 \CCalendar::DeleteSection($id);
996
997 return $response;
998 }
999
1000 public function setMeetingStatusAction()
1001 {
1002 $userId = \CCalendar::GetCurUserId();
1003 $request = $this->getRequest();
1004 $response = [];
1005
1006 $entryId = (int)$request->getPost('entryId');
1008 $mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
1010 $event = $mapperFactory->getEvent()->getById($entryId);
1011 if ($event->isOpenEvent())
1012 {
1013 OpenEventAttendeeService::getInstance()->setEventAttendeeStatus(
1014 $userId,
1016 $event->getId(),
1017 $request->getPost('status') === 'Y'
1018 )
1019 );
1020 }
1021 else
1022 {
1023 \CCalendarEvent::SetMeetingStatusEx([
1024 'attendeeId' => $userId,
1025 'eventId' => (int)$request->getPost('entryId'),
1026 'parentId' => (int)$request->getPost('entryParentId'),
1027 'status' => $request->getPost('status'),
1028 'reccurentMode' => $request->getPost('recursionMode'),
1029 'currentDateFrom' => $request->getPost('currentDateFrom')
1030 ]);
1031 }
1032
1033 \CCalendar::UpdateCounter([$userId], [$event->getId()]);
1034 $response['counters'] = CountersManager::getValues($userId);
1035
1036 return $response;
1037 }
1038
1039 public function updateRemindersAction()
1040 {
1041 $request = $this->getRequest();
1042 $response = [];
1043 $entryId = (int)$request->getPost('entryId');
1044 $userId = \CCalendar::GetUserId();
1045 $entry = \CCalendarEvent::GetById($entryId);
1046
1047 if (empty($entry))
1048 {
1049 $this->addError(new Error('Event not found'));
1050
1051 return $response;
1052 }
1053
1055 $eventModel = \CCalendarEvent::getEventModelForPermissionCheck($entryId, $entry, $userId);
1056
1057 if ($accessController->check(ActionDictionary::ACTION_EVENT_EDIT, $eventModel, ['checkCurrentEvent' => 'Y']))
1058 {
1059 $entry['REMIND'] = \CCalendarReminder::prepareReminder($request->getPost('reminders'));
1060 $response['REMIND'] = $entry['REMIND'];
1061 $response['id'] = \CCalendar::SaveEvent([
1062 'arFields' => [
1063 'ID' => $entry['ID'],
1064 'REMIND' => $entry['REMIND']
1065 ],
1066 'updateReminders' => true,
1067 'checkPermission' => false,
1068 ]);
1069
1070 \CCalendar::ClearCache('event_list');
1071 }
1072 else
1073 {
1074 $this->addError(new Error('Access denied'));
1075 }
1076
1077 return $response;
1078 }
1079
1080 public function getSyncInfoAction()
1081 {
1082 $params = [];
1083 $request = $this->getRequest();
1084 $params['type'] = $request->getPost('type');
1085 $params['userId'] = \CCalendar::getCurUserId();
1086
1087 return \CCalendarSync::GetSyncInfo($params);
1088 }
1089
1090 public function setSectionStatusAction()
1091 {
1092 $attestedSectionsStatus = [];
1093 $request = $this->getRequest();
1094 $sectionsStatus = $request['sectionStatus'];
1095 $userId = \CCalendar::getCurUserId();
1096
1097 foreach ($sectionsStatus as $sectionId => $sectionStatus)
1098 {
1099 $sectionStatus = json_decode($sectionStatus);
1100 if (is_int($sectionId) && is_bool($sectionStatus))
1101 {
1102 $attestedSectionsStatus[$sectionId] = $sectionStatus;
1103 }
1104 }
1105
1106 if ($attestedSectionsStatus && $userId > 0)
1107 {
1108 \CCalendarSync::SetSectionStatus($userId, $attestedSectionsStatus);
1109 return true;
1110 }
1111
1112 return false;
1113 }
1114
1116 {
1117 return null;
1118 }
1119
1120 public function updateColorAction()
1121 {
1122 $request = $this->getRequest();
1123 $response = [];
1124 $entryId = intVal($request->getPost('entryId'));
1125 $userId = \CCalendar::GetUserId();
1126 $entry = \CCalendarEvent::GetById($entryId);
1127
1128 if (empty($entry))
1129 {
1130 $this->addError(new Error('Event not found'));
1131
1132 return $response;
1133 }
1134
1136 $eventModel = \CCalendarEvent::getEventModelForPermissionCheck($entryId, $entry, $userId);
1137
1138 if ($accessController->check(ActionDictionary::ACTION_EVENT_EDIT, $eventModel, ['checkCurrentEvent' => 'Y']))
1139 {
1140 \CCalendarEvent::updateColor($entryId, $request->getPost('color'));
1141 \CCalendar::ClearCache('event_list');
1142 }
1143 else
1144 {
1145 $this->addError(new Error('Access denied'));
1146 }
1147
1148 return $response;
1149 }
1150
1151 public function getSettingsSliderAction($uid, $showPersonalSettings, $showGeneralSettings, $showAccessControl)
1152 {
1153 $uid = preg_replace('/\W/', '', $uid);
1154
1155 $userId = \CCalendar::getCurUserId();
1156 $additionalResponseParams = [
1157 'uid' => $uid,
1159 ];
1160
1161 $listLockedFeatures = [];
1162
1163 if (\Bitrix\Main\Loader::includeModule('tasks'))
1164 {
1165 $featureName = \Bitrix\Tasks\Integration\Bitrix24\FeatureDictionary::TASK_CALENDAR_INTEGRATION;
1166 $tasksCalendarIntegration = \Bitrix\Tasks\Integration\Bitrix24::checkFeatureEnabled($featureName);
1167
1168 if ($tasksCalendarIntegration === false)
1169 {
1170 $listLockedFeatures['sync_tasks'] = [
1171 'locked' => true,
1172 'code' => $featureName,
1173 ];
1174 }
1175 }
1176
1177 return new \Bitrix\Main\Engine\Response\Component(
1178 'bitrix:calendar.settings.slider',
1179 '',
1180 [
1181 'id' => $uid,
1182 'is_personal' => $showPersonalSettings === 'Y',
1183 'show_general_settings' => $showGeneralSettings === 'Y',
1184 'show_access_control' => $showAccessControl === 'Y',
1185 'list_locked_features' => $listLockedFeatures,
1186 ],
1187 $additionalResponseParams
1188 );
1189 }
1190
1192 {
1193 $userId = \CCalendar::getCurUserId();
1194 return new \Bitrix\Main\Engine\Response\Component(
1195 'bitrix:main.mail.confirm',
1196 '',
1197 [],
1198 [
1199 'mailboxList' => \Bitrix\Calendar\Integration\Sender\AllowedSender::getList($userId)
1200 ]
1201 );
1202 }
1203
1205 {
1206 $userId = \CCalendar::getCurUserId();
1207 return [
1209 ];
1210 }
1211
1213 {
1214 $request = $this->getRequest();
1215 $loadSectionId = (int)$request['loadSectionId'];
1216 $result = [];
1217 if ($loadSectionId > 0)
1218 {
1219 $result['section'] = \CCalendarSect::GetById($loadSectionId);
1220 }
1221
1222 return $result;
1223 }
1224
1225 public function getSectionListAction($type, $ownerId): array
1226 {
1227 return [
1228 'sections' => \CCalendarSect::prepareSectionListResponse($type, (int)$ownerId)
1229 ];
1230 }
1231
1232 public function updateCountersAction(?string $type, ?string $ownerId): array
1233 {
1234 $userId = \CCalendar::GetCurUserId();
1235 \CCalendar::UpdateCounter([$userId]);
1236
1237 $groupIds = $type === Dictionary::CALENDAR_TYPE['group'] ? [$ownerId] : [];
1238
1239 return [
1240 'counters' => CountersManager::getValues($userId, $groupIds),
1241 ];
1242 }
1243
1244 public function updateDefaultSectionIdAction(string $key, int $sectionId): void
1245 {
1246 $userId = \CCalendar::GetCurUserId();
1247 $key = preg_replace("/[^a-zA-Z0-9_:\.]/is", "", $key);
1248 if ($key && $sectionId)
1249 {
1250 $userSettings = UserSettings::get($userId);
1251 $userSettings['defaultSections'][$key] = $sectionId;
1252 UserSettings::set($userSettings, $userId);
1253 }
1254 }
1255
1256 public function analyticalAction(): void
1257 {
1258 }
1259
1260 public function saveSettingsAction(string $type, array $user_settings = [], string $user_timezone_name = '',
1261 array $settings = []): void
1262 {
1263 $request = $this->getRequest();
1264 $userId = \CCalendar::GetCurUserId();
1265
1266 // Personal
1267 UserSettings::set($user_settings);
1268
1269 // Save access for type
1271 $typeModel = TypeModel::createFromXmlId($type);
1272
1273 if ($accessController->check(ActionDictionary::ACTION_TYPE_ACCESS, $typeModel))
1274 {
1275 // General
1276 if (!empty($settings))
1277 {
1278 \CCalendar::SetSettings($settings);
1279 }
1280
1281 if (!empty($request['type_access']))
1282 {
1283 \CCalendarType::Edit([
1284 'arFields' => [
1285 'XML_ID' => $type,
1286 'ACCESS' => $request['type_access']
1287 ]
1288 ]);
1289 }
1290 }
1291
1292 if (!empty($user_timezone_name))
1293 {
1294 \CCalendar::SaveUserTimezoneName($userId, $user_timezone_name);
1295 \CCalendar::ClearCache('event_list');
1296 }
1297 }
1298
1299 public function getFilterDataAction()
1300 {
1301 $request = $this->getRequest();
1302 $type = $request->getPost('type');
1303
1304 $isCollaber = Util::isCollabUser(\CCalendar::getUserId());
1305
1306 if ((Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser()) && !$isCollaber)
1307 {
1308 $this->addError(new Error('Intranet user only'));
1309
1310 return [];
1311 }
1312
1313 if ($isCollaber && !in_array($type, ['user', 'group'], true))
1314 {
1315 $this->addError(new Error('Collaber only can access user or group'));
1316
1317 return [];
1318 }
1319
1320 if ($type === 'user')
1321 {
1322 $params = [
1323 'ownerId' => \CCalendar::GetCurUserId(),
1324 'userId' => \CCalendar::GetCurUserId(),
1325 'type' => $type,
1326 ];
1327 }
1328 else if (in_array($type, ['company_calendar', 'calendar_company', 'company', 'group'], true))
1329 {
1330 $accessController = new TypeAccessController(\CCalendar::GetCurUserId());
1331 $typeModel = TypeModel::createFromXmlId($type);
1332
1333 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel))
1334 {
1335 $this->addError(new Error('Type access denied'));
1336
1337 return [];
1338 }
1339
1340 $params = [
1341 'ownerId' => $request->getPost('ownerId'),
1342 'userId' => \CCalendar::GetCurUserId(),
1343 'type' => $type,
1344 ];
1345 }
1346 else
1347 {
1348 $this->addError(new Error('Type not found'));
1349
1350 return [];
1351 }
1352
1353 return CalendarFilter::getFilterData($params);
1354 }
1355
1356 public function getConferenceChatIdAction(int $eventId)
1357 {
1358 $result = [];
1359
1360 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
1361 {
1362 return $result;
1363 }
1364
1366 $eventLink = (new Sharing\Link\Factory())->getEventLinkByEventId($eventId);
1367 if (!$eventLink)
1368 {
1369 $this->addError(new Error('Event not found'));
1370
1371 return $result;
1372 }
1373
1374 $chatId = (new Sharing\SharingConference($eventLink))->getConferenceChatId();
1375
1376 if (!$chatId)
1377 {
1378 $this->addError(new Error('Conference not found'));
1379
1380 return $result;
1381 }
1382
1383 $result['chatId'] = $chatId;
1384
1385 return $result;
1386 }
1387}
$type
Определения options.php:106
$accessController
Определения options.php:23
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getSettingsSliderAction($uid, $showPersonalSettings, $showGeneralSettings, $showAccessControl)
Определения calendarajax.php:1151
getSectionListAction($type, $ownerId)
Определения calendarajax.php:1225
updateDefaultSectionIdAction(string $key, int $sectionId)
Определения calendarajax.php:1244
changeRecurciveEntryUntilAction($entryId, $untilDate)
Определения calendarajax.php:865
saveSettingsAction(string $type, array $user_settings=[], string $user_timezone_name='', array $settings=[])
Определения calendarajax.php:1260
const EVENT_EDIT_FORM_FIELDS_THAT_CAN_BE_HIDDEN
Определения calendarajax.php:42
updateCountersAction(?string $type, ?string $ownerId)
Определения calendarajax.php:1232
deleteCalendarEntryAction($entryId, $recursionMode, $requestUid)
Определения calendarajax.php:844
excludeRecursionDateAction($entryId, $excludeDate)
Определения calendarajax.php:958
static getList($forUserId=null)
Определения allowedsender.php:12
static getMeetingRoomList(array $params=[])
Определения iblockmeetingroom.php:20
static getRoomsList()
Определения manager.php:161
static getFormSettings($formType, $userId=false, ?string $entryType=null)
Определения usersettings.php:145
static setTrackingUsers($userId=false, $value=[])
Определения usersettings.php:237
static set($settings=[], $userId=false)
Определения usersettings.php:50
static get($userId=null)
Определения usersettings.php:86
static setSectionCustomization($userId=false, $data=[])
Определения usersettings.php:305
static getTrackingUsers($userId=false, $params=[])
Определения usersettings.php:180
Определения util.php:21
static getDefaultEntityList($userId, $type, $ownerId)
Определения util.php:250
static getTimezoneHint(int $userId, array $event)
Определения util.php:795
static convertEntitiesToCodes($entityList=[])
Определения util.php:167
static isCollabUser(int $userId)
Определения util.php:337
addError(Error $error)
Определения controller.php:1070
Определения error.php:15
Определения loader.php:13
static getList(array $parameters=array())
Определения datamanager.php:431
static canTurnOnTrial(string $featureName)
Определения feature.php:70
static isFeatureEnabled(string $featureName, int $groupId=0)
Определения feature.php:21
const PROJECTS_GROUPS
Определения feature.php:14
static Init($config=[], $initialParams=false)
Определения calendar_planner.php:11
static prepareReminder($reminder=[])
Определения calendar_reminder.php:431
static CheckBitrix24Limits($params)
Определения calendar_sceleton.php:182
static SetSectionStatus(?int $userId=0, ?array $sectionsStatus=[])
Определения calendar_sync.php:1185
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$result
Определения get_property_values.php:14
$uid
Определения hot_keys_act.php:8
$name
Определения menu_edit.php:35
$user
Определения mysql_to_pgsql.php:33
$settings
Определения product_settings.php:43
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$response
Определения result.php:21
const SONET_ENTITY_GROUP
Определения include.php:117
$rights
Определения options.php:4
$fields
Определения yandex_run.php:501