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 UpdateListItems($listName, $updates) { global $USER; $arStatusValues = array_flip($this->arStatusValues); $arPriorityValues = array_flip($this->arPriorityValues); if (!$listName_original = CIntranetUtils::checkGUID($listName)) return new CSoapFault('Data error', 'Wrong GUID - '.$listName); $obResponse = new CXMLCreator('Results'); $listName = ToUpper(CIntranetUtils::makeGUID($listName_original)); $arSections = CCalendarSect::GetList(array('arFilter' => array('XML_ID' => $listName_original))); if (!$arSections || !is_array($arSections[0])) return new CSoapFault( 'List not found', 'List with '.$listName.' GUID not found' ); $arSection = $arSections[0]; $bGroup = $arSection['CAL_TYPE'] == 'group'; $calType = $arSection['CAL_TYPE']; $ownerId = $arSection['OWNER_ID']; if ($bGroup) { CModule::IncludeModule('socialnetwork'); $arGroupTmp = CSocNetGroup::GetByID($arSection['SOCNET_GROUP_ID']); if ($arGroupTmp["CLOSED"] == "Y") if (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") != "Y") return new CSoapFault('Cannot modify archive group calendar', 'Cannot modify archive group calendar'); } $obBatch = $updates->children[0]; $atrONERROR = $obBatch->getAttribute('OnError'); $atrDATEINUTC = $obBatch->getAttribute('DateInUtc'); $atrPROPERTIES = $obBatch->getAttribute('Properties'); $arChanges = $obBatch->children; $arResultIDs = array(); $dateStart = ConvertTimeStamp(strtotime('-1 hour'), 'FULL'); $arResponseRows = array(); $arReplicationIDs = array(); $userId = (is_object($USER) && $USER->GetID()) ? $USER->GetID() : 1; foreach ($arChanges as $obMethod) { $arData = array('_command' => $obMethod->getAttribute('Cmd')); foreach ($obMethod->children as $obField) { $name = $obField->getAttribute('Name'); if ($name == 'MetaInfo') $name .= '_'.$obField->getAttribute('Property'); $arData[$name] = $obField->content; } if ($arData['_command'] == 'Delete') { $obRes = new CXMLCreator('Result'); $obRes->setAttribute('ID', $obMethod->getAttribute('ID').','.$arData['_command']); $obRes->setAttribute('List', $listName); $obRes->addChild($obNode = new CXMLCreator('ErrorCode')); $res = CCalendar::DeleteEvent($arData['ID']); if ($res === true) $obNode->setData('0x00000000'); else $obNode->setData('0x81020014'); /* 0x00000000 - ok 0x81020015 - data conflict 0x81020014 - generic error such as invalid value for Field 0x81020016 - item does not exist */ $obResponse->addChild($obRes); } elseif ($arData['_command'] == 'New' || $arData['_command'] == 'Update') { $q = ToLower($arData['Description']); if (($pos = strrpos($q, '</body>')) !== false) $arData['Description'] = substr($arData['Description'], 0, $pos); if (($pos = strpos($q, '<body>')) !== false) $arData['Description'] = substr($arData['Description'], $pos + 6); $arData['Description'] = str_replace('</DIV>', "\r\n</DIV>", $arData['Description']); $arData['Description'] = str_replace(array(" ", " "), "", $arData['Description']); $arData['Description'] = preg_replace("/<![^>]*>/", '', $arData['Description']); //$arData['Description'] = strip_tags($arData['Description']); $arData['Description'] = trim($arData['Description']); $arData['Location'] = trim($arData['Location']); if (isset($arData['EventDate'])) { $arData['EventDate'] = $this->__makeTS($arData['EventDate']); $arData['EndDate'] = $this->__makeTS($arData['EndDate']) + ($arData['fAllDayEvent'] ? -86340 : 0); $TZBias = intval(date('Z', $arData['EventDate'])); } $arData['EventType'] = intval($arData['EventType']); if ($arData['EventType'] == 2) $arData['EventType'] = 0; if ($arData['EventType'] > 2 /* || ($arData['EventType'] == 1 && !$arData['RecurrenceData'])*/) return new CSoapFault( 'Unsupported event type', 'Event type unsupported' ); $arData['fRecurrence'] = intval($arData['fRecurrence']); $arData['RRULE'] = ''; $id = $arData['_command'] == 'New' ? 0 : intVal($arData['ID']); if ($arData['RecurrenceData']) { //$xmlstr = $arData['XMLTZone']; //$arData['XMLTZone'] = new CDataXML(); //$arData['XMLTZone']->LoadString($xmlstr); $xmlstr = $arData['RecurrenceData']; $obRecurData = new CDataXML(); $obRecurData->LoadString($xmlstr); /* <recurrence> <rule> <firstDayOfWeek>mo</firstDayOfWeek> <repeat> <weekly mo='TRUE' tu='TRUE' th='TRUE' sa='TRUE' weekFrequency='1' /> </repeat> <repeatForever>FALSE</repeatForever> </rule> </recurrence> <deleteExceptions>true</deleteExceptions> */ $obRecurRule = $obRecurData->tree->children[0]->children[0]; $obRecurRepeat = $obRecurRule->children[1]; $obNode = $obRecurRepeat->children[0]; $arData['RRULE'] = array(); switch($obNode->name) { case 'daily': // hack. we have no "work days" daily recurence if ($obNode->getAttribute('weekday') == 'TRUE') { $arData['RRULE']['FREQ'] = 'WEEKLY'; $arData['RRULE']['BYDAY'] = 'MO,TU,WE,TH,FR'; $arData['RRULE']['INTERVAL'] = 1; } else { $arData['RRULE']['FREQ'] = 'DAILY'; $arData['RRULE']['INTERVAL'] = $obNode->getAttribute('dayFrequency'); } $time_end = strtotime( date(date('Y-m-d', $arData['EventDate']).' H:i:s', $arData['EndDate']) ); $arData['DT_LENGTH'] = $time_end - $arData['EventDate']; break; case 'weekly': $arData['RRULE']['FREQ'] = 'WEEKLY'; $arData['RRULE']['BYDAY'] = ''; $arWeekDays = array('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'); foreach ($arWeekDays as $day => $value) { if ($obNode->getAttribute($value)) $arData['RRULE']['BYDAY'][] = strtoupper($value); } $arData['RRULE']['BYDAY'] = implode(',', $arData['RRULE']['BYDAY']); $arData['RRULE']['INTERVAL'] = $obNode->getAttribute('weekFrequency'); $time_end = strtotime(date(date('Y-m-d', $arData['EventDate']).' H:i:s', $arData['EndDate'])); $arData['DT_LENGTH'] = $time_end - $arData['EventDate']; break; case 'monthly': $arData['RRULE']['FREQ'] = 'MONTHLY'; $arData['RRULE']['INTERVAL'] = $obNode->getAttribute('monthFrequency'); $time_end = strtotime(date(date('Y-m', $arData['EventDate']).'-d H:i:s', $arData['EndDate'])); $arData['DT_LENGTH'] = $time_end - $arData['EventDate']; break; case 'yearly': $arData['RRULE']['FREQ'] = 'YEARLY'; $arData['RRULE']['INTERVAL'] = $obNode->getAttribute('yearFrequency'); $time_end = strtotime(date(date('Y', $arData['EventDate']).'-m-d H:i:s', $arData['EndDate'])); $arData['DT_LENGTH'] = $time_end - $arData['EventDate']; break; } if ($arData['DT_LENGTH'] == 0 && isset($arData['RRULE']['FREQ'])) $arData['DT_LENGTH'] = 86400; $obWhile = $obRecurRule->children[2]; if ($obWhile->name == 'repeatForever') { $arData['EndDate'] = MakeTimeStamp(''); } elseif ($obWhile->name == 'windowEnd') { $arData['EndDate'] = $this->__makeTS($obWhile->textContent()); $arData['RRULE']['UNTIL'] = ConvertTimeStamp($arData['EndDate'], 'FULL'); } } elseif($arData['fRecurrence'] == -1 && $id > 0) { $arData['RRULE'] = -1; } if (isset($arData['EventDate'])) { $skipTime = $arData['fAllDayEvent'] ? 'Y' : 'N'; $TZBias = $arData['fAllDayEvent'] ? 0 : $TZBias; $arData['EventDate'] += $TZBias; $arData['EndDate'] += $TZBias; // $arData["DT_FROM"] = ConvertTimeStamp($arData['EventDate'], 'FULL'); // $arData["DT_TO"] = ConvertTimeStamp($arData['EndDate'], 'FULL'); } else { $arData["DT_FROM"] = -1; $arData["DT_TO"] = -1; } // fields $arFields = array( "ID" => $id, 'CAL_TYPE' => $calType, 'OWNER_ID' => $ownerId, 'CREATED_BY' => $userId, 'DT_FROM_TS' => $arData['EventDate'], 'DT_TO_TS' => $arData['EndDate'], 'DT_SKIP_TIME' => $skipTime, // "DT_FROM" => $arData["DT_FROM"], // "DT_TO" => $arData["DT_TO"], 'NAME' => $arData['Title'], 'DESCRIPTION' => CCalendar::ParseHTMLToBB($arData['Description']), 'SECTIONS' => array($arSection['ID']), 'ACCESSIBILITY' => $arStatusValues[$arData['MetaInfo_BusyStatus']], 'IMPORTANCE' => $arPriorityValues[$arData['MetaInfo_Priority']], 'RRULE' => $arData['RRULE'], 'LOCATION' => CCalendar::UnParseTextLocation($arData['Location']) ); if (isset($arData['DT_LENGTH']) && $arData['DT_LENGTH'] > 0) $arFields['DT_LENGTH'] = $arData['DT_LENGTH']; $EventID = CCalendar::SaveEvent( array( 'arFields' => $arFields, 'fromWebservice' => true ) ); if ($EventID) { // dirty hack $arReplicationIDs[$EventID] = $arData['MetaInfo_ReplicationID']; $arResponseRows[$EventID] = new CXMLCreator('Result'); $arResponseRows[$EventID]->setAttribute('ID', $obMethod->getAttribute('ID').','.$arData['_command']); $arResponseRows[$EventID]->setAttribute('List', $listName); $arResponseRows[$EventID]->addChild($obNode = new CXMLCreator('ErrorCode')); $obNode->setData('0x00000000'); //$arResponseRows[$EventID]->setAttribute('Version', 3); } } } $userId = (is_object($USER) && $USER->GetID()) ? $USER->GetID() : 1; $fetchMeetings = CCalendar::GetMeetingSection($userId) == $arSection['ID']; $arEvents = CCalendarEvent::GetList( array( 'arFilter' => array( 'CAL_TYPE' => $calType, 'OWNER_ID' => $ownerId, 'SECTION' => $arSection['ID'], //'INCLUDE_INVITINGS' => 'N' ), 'getUserfields' => false, 'parseRecursion' => false, 'fetchAttendees' => false, 'fetchMeetings' => $fetchMeetings, 'userId' => $userId ) ); foreach ($arEvents as $key => $event) { if ($arResponseRows[$event['ID']]) { $obRow = $this->__getRow($event, $listName, $last_change = 0); $obRow->setAttribute('xmlns:z', "#RowsetSchema"); if ($arReplicationIDs[$event['ID']]) $obRow->setAttribute('MetaInfo_ReplicationID', $arReplicationIDs[$event['ID']]); $arResponseRows[$event['ID']]->addChild($obRow); } $obResponse->addChild($arResponseRows[$event['ID']]); } return array('UpdateListItemsResult' => $obResponse); }
public static function AddEvent($MEETING_ID, $arFields, $arParams = array()) { global $USER; $EventID = false; if (self::IsNewCalendar()) { $arEventFields = array('ID' => $arFields['EVENT_ID'], 'CAL_TYPE' => 'user', 'OWNER_ID' => $arFields['OWNER_ID'], 'DT_FROM' => $arFields['DATE_START'], 'DT_TO' => ConvertTimeStamp(MakeTimeStamp($arFields['DATE_START']) + $arFields['DURATION'], 'FULL'), 'NAME' => $arFields['TITLE'], 'DESCRIPTION' => CCalendar::ParseHTMLToBB($arFields['DESCRIPTION']), 'IS_MEETING' => true, 'MEETING_HOST' => $arFields['OWNER_ID'], 'MEETING' => array('HOST_NAME' => CCalendar::GetUserName($arFields['OWNER_ID'])), 'ATTENDEES' => array_keys($arFields['USERS'])); if ($arFields['CURRENT_STATE'] == CMeeting::STATE_CLOSED) { $arEventFields['DT_TO'] = MakeTimeStamp($arFields['DATE_FINISH']) > MakeTimeStamp($arFields['DATE_START']) ? $arFields['DATE_FINISH'] : $arEventFields['DT_TO']; } $matches = array(); if (preg_match('/^mr_([\\d]+)_([\\d]+)$/', $arFields["PLACE"], $matches)) { $arEventFields['LOCATION'] = 'ECMR_' . $matches[2]; if ($arFields['EVENT_ID'] > 0) { $arCurrentEvent = CCalendarEvent::GetById($arFields['EVENT_ID']); if ($arCurrentEvent['LOCATION']) { $res = CCalendar::ParseLocation($arCurrentEvent['LOCATION']); if ($res['mrevid']) { $arEventFields['LOCATION'] .= '_' . $res['mrevid']; } } } } else { $arEventFields['LOCATION'] = $arFields['PLACE']; } if (isset($arFields['REINVITE'])) { $arEventFields['MEETING']['REINVITE'] = $arFields['REINVITE']; } else { $arEventFields['MEETING']['REINVITE'] = false; } if (isset($arFields['NOTIFY'])) { $arEventFields['MEETING']['NOTIFY'] = $arFields['NOTIFY']; } $EventID = CCalendar::SaveEvent(array('arFields' => $arEventFields, 'userId' => $arFields['OWNER_ID'], 'autoDetectSection' => true, 'autoCreateSection' => true)); } elseif (!$arFields['EVENT_ID']) { $iblockId = $arParams['CALENDAR_IBLOCK_ID'] ? $arParams['CALENDAR_IBLOCK_ID'] : COption::GetOptionInt('intranet', 'iblock_calendar', 0, SITE_ID); $obCalendar = new CEventCalendar(); $obCalendar->Init(array('ownerType' => 'USER', 'ownerId' => $USER->GetID(), 'bOwner' => true, 'iblockId' => $iblockId, 'userIblockId' => $iblockId, 'bCache' => false, 'pathToUserCalendar' => '/company/personal/user/#user_id#/calendar/')); $guestCalendarId = false; $guestSection = $obCalendar->GetSectionIDByOwnerId($USER->GetID(), 'USER', $iblockId); $arGuestCalendars = array(); if (!$guestSection) { $guestSection = $obCalendar->CreateSectionForOwner($USER->GetID(), "USER", $iblockId); } $arGuestCalendars = $obCalendar->GetCalendars(array('sectionId' => $guestSection, 'iblockId' => $iblockId, 'ownerType' => 'USER', 'ownerId' => $USER->GetID(), 'bOwner' => 1, 'forExport' => true, 'bOnlyID' => true)); if (count($arGuestCalendars) > 0) { $arUserSet = $obCalendar->GetUserSettings(array('static' => false, 'userId' => $USER->GetID())); if ($arUserSet && isset($arUserSet['MeetCalId']) && in_array($arUserSet['MeetCalId'], $arGuestCalendars)) { $guestCalendarId = intVal($arUserSet['MeetCalId']); } else { $guestCalendarId = $arGuestCalendars[0]; } } //$bGroup = $arParams['GROUP_ID'] > 0; $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true)); $arEventFields = array('iblockId' => $obCalendar->iblockId, 'ownerType' => $obCalendar->ownerType, 'ownerId' => $obCalendar->ownerId, 'RMiblockId' => self::__getRMIblockID(), 'allowResMeeting' => true, 'bNew' => true, 'fullUrl' => $obCalendar->fullUrl, 'userId' => $obCalendar->userId, 'pathToUserCalendar' => $obCalendar->pathToUserCalendar, 'pathToGroupCalendar' => $obCalendar->pathToGroupCalendar, 'userIblockId' => $obCalendar->iblockId, 'calendarId' => $guestCalendarId, 'sectionId' => $guestSection, 'dateFrom' => $arFields['DATE_START'], 'dateTo' => $arFields['DATE_FINISH'] ? $arFields['DATE_FINISH'] : ConvertTimeStamp(MakeTimeStamp($arFields['DATE_START']) + $arFields['DURATION'], 'FULL'), 'name' => $arFields['TITLE'], 'desc' => $arFields['DESCRIPTION'], 'prop' => array(), 'isMeeting' => true, 'guests' => array_keys($arFields['USERS']), 'notDisplayCalendar' => true); if ($EventID = $obCalendar->SaveEvent($arEventFields)) { CEventCalendar::ClearCache('/event_calendar/events/' . $arEventFields['iblockId'] . '/'); CEventCalendar::ClearCache('/event_calendar/events/' . $arEventFields['userIblockId'] . '/'); } } if ($EventID) { self::Update($MEETING_ID, array('EVENT_ID' => $EventID)); } return $EventID; }