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