public function Add($arParams) { global $USER; $res = null; $calendar_id = $arParams['calendar_id']; $calIblock = COption::GetOptionInt('intranet', 'iblock_calendar', null, $arParams['site_id']); $calIblockSection = CEventCalendar::GetSectionIDByOwnerId($USER->GetID(), 'USER', $calIblock); if (!$calendar_id) { $calendar_id = CUserOptions::GetOption('timeman', 'default_calendar', 0); } if ($calIblockSection > 0) { $arCalendars = CEventCalendar::GetCalendarList(array($calIblock, $calIblockSection, 0, 'USER')); if (count($arCalendars) == 1) { if ($calendar_id && $calendar_id != $arCalendars[0]['ID']) { CUserOptions::DeleteOption('timeman', 'default_calendar'); } $calendar_id = $arCalendars[0]['ID']; } else { $bCalendarFound = false; $arCalsList = array(); foreach ($arCalendars as $cal) { if ($cal['ID'] == $calendar_id) { $bCalendarFound = true; break; } $arCalsList[] = array('ID' => $cal['ID'], 'NAME' => $cal['NAME'], 'COLOR' => $cal['COLOR']); } if (!$bCalendarFound) { $bReturnRes = true; $res = array('error_id' => 'CHOOSE_CALENDAR', 'error' => array('TEXT' => GetMessage('TM_CALENDAR_CHOOSE'), 'CALENDARS' => $arCalsList)); } } } if (!$bReturnRes) { if (!$calIblockSection) { $calIblockSection = 'none'; } $today = CTimeMan::RemoveHoursTS(time()); $data = array('DATE_FROM' => $today + CTimeMan::MakeShortTS($arParams['from']), 'DATE_TO' => $today + CTimeMan::MakeShortTS($arParams['to']), 'NAME' => $arParams['name'], 'ABSENCE' => $arParams['absence'] == 'Y'); $obCalendar = new CEventCalendar(); $obCalendar->Init(array('ownerType' => 'USER', 'ownerId' => $USER->GetID(), 'bOwner' => true, 'iblockId' => $calIblock, 'bCache' => false)); $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true)); $arRes = array('iblockId' => $obCalendar->iblockId, 'ownerType' => $obCalendar->ownerType, 'ownerId' => $obCalendar->ownerId, 'bNew' => true, 'fullUrl' => $obCalendar->fullUrl, 'userId' => $obCalendar->userId, 'pathToUserCalendar' => $obCalendar->pathToUserCalendar, 'pathToGroupCalendar' => $obCalendar->pathToGroupCalendar, 'userIblockId' => $obCalendar->userIblockId, 'calendarId' => $calendar_id, 'sectionId' => $calIblockSection, 'dateFrom' => ConvertTimeStamp($data['DATE_FROM'], 'FULL'), 'dateTo' => ConvertTimeStamp($data['DATE_TO'], 'FULL'), 'name' => $data['NAME'], 'desc' => '', 'prop' => array('ACCESSIBILITY' => $data['ABSENCE'] ? 'absent' : 'busy'), 'notDisplayCalendar' => true); if ($GLOBALS['BX_TIMEMAN_RECENTLY_ADDED_EVENT_ID'] = $obCalendar->SaveEvent($arRes)) { if ($_REQUEST['cal_set_default'] == 'Y') { CUserOptions::SetOption('timeman', 'default_calendar', $calendar_id); } } } return $res; }
public static function ConvertEntity($ownerType, $ownerId, $sectionId, $iblockId, $createdBy) { $eventsCount = 0; $sectCount = 0; $bs = new CIBlockSection(); $ent_id = "IBLOCK_" . $iblockId . "_SECTION"; $result = array('eventsCount' => 0, 'sectCount' => 0); $bSetAccessFromCalendar = true; $Access = array('G2' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_denied')); // CONVERT ACCESS: if ($ownerType == 'user') { if (!CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $ownerId, "calendar")) { return $result; } // Read $read = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ownerId, "calendar", 'view'); $taskId = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view'); if ($read == 'A') { // All users $Access['G2'] = $taskId; } elseif ($read == 'C') { // All autorized $Access['AU'] = $taskId; } elseif ($read == 'M' || $read == 'E') { // Friends $Access['SU' . $ownerId . '_F'] = $taskId; } elseif ($bSetAccessFromCalendar) { $bSetAccessFromCalendar = false; } // Write - will override read access $write = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ownerId, "calendar", 'write'); $taskId = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit'); if ($write == 'A') { // All users $Access['G2'] = $taskId; } elseif ($write == 'C') { // All autorized $Access['AU'] = $taskId; } elseif ($write == 'M' || $write == 'E') { // Friends $Access['SU' . $ownerId . '_F'] = $taskId; } } elseif ($ownerType == 'group') { if (!CSocNetFeatures::IsActiveFeature(SONET_ENTITY_GROUP, $ownerId, "calendar")) { return $result; } // Read $read = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $ownerId, "calendar", 'view'); $taskId = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view'); if ($read == 'A') { // Group owner $Access['SG' . $ownerId . '_A'] = $taskId; } elseif ($read == 'E') { // Group moderator $Access['SG' . $ownerId . '_E'] = $taskId; } elseif ($read == 'K') { // User $Access['SG' . $ownerId . '_K'] = $taskId; } elseif ($read == 'L') { // Authorized $Access['AU'] = $taskId; } elseif ($read == 'N') { // Authorized $Access['G2'] = $taskId; } // Write - will override read access $write = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $ownerId, "calendar", 'write'); $taskId = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit'); if ($write == 'A') { // Group owner $Access['SG' . $ownerId . '_A'] = $taskId; } elseif ($write == 'E') { // Group moderator $Access['SG' . $ownerId . '_E'] = $taskId; } elseif ($write == 'K') { // User $Access['SG' . $ownerId . '_K'] = $taskId; } elseif ($write == 'L') { // Authorized $Access['AU'] = $taskId; } elseif ($write == 'N') { // Authorized $Access['G2'] = $taskId; } } else { $arGroupPerm = CIBlock::GetGroupPermissions($iblockId); $taskByLetter = array('D' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_denied'), 'R' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view'), 'W' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit'), 'X' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_access')); foreach ($arGroupPerm as $groupId => $letter) { $Access['G' . $groupId] = $taskByLetter[$letter]; } } // 1. Fetch sections $arUserSections = CEventCalendar::GetCalendarList(array($iblockId, $sectionId, 0, $ownerType)); $calendarIndex = array(); foreach ($arUserSections as $section) { $arUF = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields($ent_id, $section['ID']); if (isset($arUF["UF_CAL_CONVERTED"]) && strlen($arUF["UF_CAL_CONVERTED"]['VALUE']) > 0) { continue; } $SectionAccess = array(); if ($bSetAccessFromCalendar && $ownerType == 'user') { if ($section['PRIVATE_STATUS'] == 'private') { $deniedTask = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_denied'); $SectionAccess['G2'] = $deniedTask; } elseif ($section['PRIVATE_STATUS'] == 'time') { $viewTimeTask = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view_time'); $SectionAccess['G2'] = $viewTimeTask; } elseif ($section['PRIVATE_STATUS'] == 'title') { $viewTitleTask = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view_title'); $SectionAccess['G2'] = $viewTitleTask; } else { $SectionAccess = $Access; // nested from common access settings from socnet } } else { $SectionAccess = $Access; // G2 => denied } $new_sect_id = CCalendarSect::Edit(array('arFields' => array("CAL_TYPE" => $ownerType, "NAME" => $section['NAME'], "OWNER_ID" => $ownerId, "CREATED_BY" => $createdBy, "DESCRIPTION" => $section['DESCRIPTION'], "COLOR" => $section["COLOR"], "ACCESS" => $SectionAccess))); // Set converted property $bs->Update($section['ID'], array('UF_CAL_CONVERTED' => 1)); $calendarIndex[$section['ID']] = $new_sect_id; $sectCount++; } // 2. Create events $arEvents = CEventCalendar::GetCalendarEventsList(array($iblockId, $sectionId, 0), array()); foreach ($arEvents as $event) { if (!isset($calendarIndex[$event['IBLOCK_SECTION_ID']]) || $event['PROPERTY_PARENT'] > 0) { continue; } $arFields = array("CAL_TYPE" => $ownerType, "OWNER_ID" => $ownerId, "CREATED_BY" => $event["CREATED_BY"], "DT_FROM" => $event['ACTIVE_FROM'], "DT_TO" => $event['ACTIVE_TO'], 'NAME' => htmlspecialcharsback($event['NAME']), 'DESCRIPTION' => CCalendar::ParseHTMLToBB(htmlspecialcharsback($event['DETAIL_TEXT'])), 'SECTIONS' => array($calendarIndex[$event['IBLOCK_SECTION_ID']]), 'ACCESSIBILITY' => $event['PROPERTY_ACCESSIBILITY'], 'IMPORTANCE' => $event['PROPERTY_IMPORTANCE'], 'PRIVATE_EVENT' => $event['PROPERTY_PRIVATE'] && $event['PROPERTY_PRIVATE'] == 'true' ? '1' : '', 'RRULE' => array(), 'LOCATION' => array('NEW' => $event['PROPERTY_LOCATION'], 'RE_RESERVE' => 'N'), "REMIND" => array(), "IS_MEETING" => $event['PROPERTY_IS_MEETING'] == 'Y'); if (!empty($event['PROPERTY_REMIND_SETTINGS'])) { $ar = explode("_", $event["PROPERTY_REMIND_SETTINGS"]); if (count($ar) == 2) { $arFields["REMIND"][] = array('type' => $ar[1], 'count' => floatVal($ar[0])); } } if (isset($event["PROPERTY_PERIOD_TYPE"]) && in_array($event["PROPERTY_PERIOD_TYPE"], array("DAILY", "WEEKLY", "MONTHLY", "YEARLY"))) { $arFields['RRULE']['FREQ'] = $event["PROPERTY_PERIOD_TYPE"]; $arFields['RRULE']['INTERVAL'] = $event["PROPERTY_PERIOD_COUNT"]; if (!empty($event['PROPERTY_EVENT_LENGTH'])) { $arFields['DT_LENGTH'] = intval($event['PROPERTY_EVENT_LENGTH']); } if (!$arFields['DT_LENGTH']) { $arFields['DT_LENGTH'] = 86400; } if ($arFields['RRULE']['FREQ'] == "WEEKLY" && !empty($event['PROPERTY_PERIOD_ADDITIONAL'])) { $arFields['RRULE']['BYDAY'] = array(); $bydays = explode(',', $event['PROPERTY_PERIOD_ADDITIONAL']); foreach ($bydays as $day) { $day = CCalendar::WeekDayByInd($day); if ($day !== false) { $arFields['RRULE']['BYDAY'][] = $day; } } $arFields['RRULE']['BYDAY'] = implode(',', $arFields['RRULE']['BYDAY']); } $arFields['RRULE']['UNTIL'] = $event['ACTIVE_TO']; } if ($arFields['IS_MEETING']) { if ($event['PROPERTY_PARENT'] > 0) { continue; } $host = intVal($event['CREATED_BY']); $arFields['ATTENDEES'] = array(); if ($event['PROPERTY_HOST_IS_ABSENT'] == 'N') { $arFields['ATTENDEES'][] = $host; } $arGuests = CECEvent::GetGuests(self::$userIblockId, $event['ID']); $attendeesStatuses = array(); foreach ($arGuests as $userId => $ev) { $attendeesStatuses[$userId] = $ev['PROPERTY_VALUES']['CONFIRMED']; $arFields['ATTENDEES'][] = $userId; } $arFields['MEETING_HOST'] = $host; $arFields['MEETING'] = array('HOST_NAME' => CCalendar::GetUserName($host), 'TEXT' => is_array($event['PROPERTY_MEETING_TEXT']) && is_string($event['PROPERTY_MEETING_TEXT']['TEXT']) ? trim($event['PROPERTY_MEETING_TEXT']['TEXT']) : '', 'OPEN' => false, 'NOTIFY' => false, 'REINVITE' => false); } $new_event_id = CCalendar::SaveEvent(array('arFields' => $arFields, 'bAffectToDav' => false, 'attendeesStatuses' => $attendeesStatuses, 'bSendInvitations' => false)); $eventsCount++; } // 3. Set userfield $bs->Update($sectionId, array('UF_CAL_CONVERTED' => 1)); return array('eventsCount' => $eventsCount, 'sectCount' => $sectCount); }
public function Propfind(&$arResources, $siteId, $account, $arPath, $id = null) { $calendarId = $this->GetCalendarId($siteId, $account, $arPath); if ($calendarId == null) { return '404 Not Found'; } $request = $this->groupdav->GetRequest(); $currentPrincipal = $request->GetPrincipal(); if (!$this->CheckPrivileges('urn:ietf:params:xml:ns:caldav:read-free-busy', $currentPrincipal, $calendarId)) { return '403 Forbidden'; } $requestDocument = $request->GetXmlDocument(); $path = CDav::CheckIfRightSlashAdded($request->GetPath()); list($iblockId, $sectionId, $subSectionId, $accountType) = $calendarId; $isCalendarCollection = !empty($accountType) && $subSectionId != 0 || empty($accountType) && $sectionId != 0; if (!$isCalendarCollection) { $arCalendarList = CEventCalendar::GetCalendarList($calendarId); foreach ($arCalendarList as $calendar) { $resource = new CDavResource($path . $calendar["ID"] . "/"); $this->GetCalendarProperties($resource, $siteId, $account, array($calendar["ID"]), 0); $arResources[] = $resource; } return true; } $bCalendarData = count($requestDocument->GetPath('/*/DAV::allprop')) > 0; if (!$bCalendarData || $requestDocument->GetRoot()->GetXmlns() != CDavGroupDav::CALDAV) { $arProp = $requestDocument->GetPath('/*/DAV::prop/*'); foreach ($arProp as $prop) { if ($prop->GetTag() == 'calendar-data') { $bCalendarData = true; break; } } } $arFilter = array('DATE_START' => ConvertTimeStamp(time() - 31 * 24 * 3600, "FULL"), 'DATE_END' => ConvertTimeStamp(time() + 365 * 24 * 3600, "FULL")); if (($id || $requestDocument->GetRoot() && $requestDocument->GetRoot()->GetTag() != 'propfind') && !$this->PrepareFilters($arFilter, $requestDocument, $id)) { return false; } $arEvents = CEventCalendar::GetCalendarEventsList($calendarId, $arFilter); foreach ($arEvents as $event) { if (!$this->CheckPrivileges('DAV::read', $currentPrincipal, $calendarId)) { $this->ClearPrivateData($event); } $resource = new CDavResource($path . $this->GetPath($event)); $resource->AddProperty('getetag', $this->GetETag($calendarId, $event)); $resource->AddProperty('getcontenttype', $request->GetAgent() != 'kde' ? 'text/calendar; charset=utf-8; component=VEVENT' : 'text/calendar'); $resource->AddProperty('getlastmodified', MakeTimeStamp($event['TIMESTAMP_X'])); $resource->AddProperty('resourcetype', ''); if ($bCalendarData) { $content = $this->GetICalContent($event, $siteId); $resource->AddProperty('getcontentlength', strlen($content)); $resource->AddProperty('calendar-data', $content, CDavGroupDav::CALDAV); } else { $resource->AddProperty('getcontentlength', ""); } $arResources[] = $resource; } return true; }