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