public static function GetList($arOrder = array('CREATED_DATE' => 'DESC'), $arFilter = array(), $arSelect = array(), $nPageTop = false) { // Fix for #27449 if (!CModule::IncludeModule('calendar')) { $obRes = new CDBResult(); $obRes->InitFromArray(array()); return $obRes; } global $USER; $ENTITY_ID = 'CALENDAR_EVENT'; $arElement = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields($ENTITY_ID, 0, LANGUAGE_ID); if ($arElement == false || !isset($arElement['UF_CRM_CAL_EVENT'])) { $arFields = array(); $arFields['ENTITY_ID'] = $ENTITY_ID; $arFields['FIELD_NAME'] = 'UF_CRM_CAL_EVENT'; $arFields['USER_TYPE_ID'] = 'crm'; $arFields['EDIT_FORM_LABEL'][LANGUAGE_ID] = GetMessage('CRM_UF_NAME'); $arFields['LIST_COLUMN_LABEL'][LANGUAGE_ID] = GetMessage('CRM_UF_NAME'); $arFields['LIST_FILTER_LABEL'][LANGUAGE_ID] = GetMessage('CRM_UF_NAME'); $arFields['SETTINGS']['LEAD'] = 'Y'; $arFields['SETTINGS']['CONTACT'] = 'Y'; $arFields['SETTINGS']['COMPANY'] = 'Y'; $arFields['SETTINGS']['DEAL'] = 'Y'; $arFields['MULTIPLE'] = 'Y'; $CAllUserTypeEntity = new CUserTypeEntity(); $CAllUserTypeEntity->Add($arFields); } if (isset($arFilter['ENTITY_TYPE']) && isset($arFilter['ENTITY_ID'])) { $arFilter['ENTITY_TYPE'] = CUserTypeCrm::GetShortEntityType($arFilter['ENTITY_TYPE']); $arFilter['UF_CRM_CAL_EVENT'] = $arFilter['ENTITY_TYPE'] . '_' . $arFilter['ENTITY_ID']; unset($arFilter['ENTITY_TYPE'], $arFilter['ENTITY_ID']); } else { if (!empty($arFilter['ENTITY_TYPE'])) { $arFilter['ENTITY_TYPE'] = CUserTypeCrm::GetShortEntityType($arFilter['ENTITY_TYPE']); $arFilter['%UF_CRM_CAL_EVENT'] = $arFilter['ENTITY_TYPE'] . '_'; unset($arFilter['ENTITY_TYPE']); } else { $arFilter['!=UF_CRM_CAL_EVENT'] = ''; } } $arFilter['CAL_TYPE'] = 'user'; $arFilter['DELETED'] = 'N'; if (isset($arFilter['OWNER_ID']) && is_array($arFilter['OWNER_ID'])) { $arFilter['OWNER_ID'] = current($arFilter['OWNER_ID']); } $arCal = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'parseRecursion' => false, 'userId' => $USER->GetID(), 'fetchAttendees' => false, 'fetchMeetings' => true)); $obRes = new CDBResult(); $obRes->InitFromArray($arCal); return $obRes; }
public static function ConvertCalEvents($checkPerms = true, $regEvent = true) { if (!(IsModuleInstalled('calendar') && CModule::IncludeModule('calendar'))) { return 0; } $arEvents = CCalendarEvent::GetList(array('arFilter' => array('!UF_CRM_CAL_EVENT' => null, 'DELETED' => 'N'), 'getUserfields' => true)); $total = 0; foreach ($arEvents as $arEvent) { $eventID = $arEvent['ID']; $count = CCrmActivity::GetCount(array('@TYPE_ID' => array(CCrmActivityType::Call, CCrmActivityType::Meeting), '=ASSOCIATED_ENTITY_ID' => $eventID)); if ($count === 0 && CCrmActivity::CreateFromCalendarEvent($eventID, $arEvent, $checkPerms, $regEvent) > 0) { $total++; } } return $total; }
protected static function getEvent($arParams) { global $USER; $arEvents = CCalendarEvent::GetList(array('arFilter' => array("ID" => $arParams['ID'], "DELETED" => "N"), 'parseRecursion' => true, 'fetchAttendees' => true, 'checkPermissions' => true)); if (is_array($arEvents) && count($arEvents) > 0) { $arEvent = $arEvents[0]; if ($arEvent['IS_MEETING']) { $arGuests = $arEvent['~ATTENDEES']; $arEvent['GUESTS'] = array(); foreach ($arGuests as $guest) { $arEvent['GUESTS'][] = array('id' => $guest['USER_ID'], 'name' => CUser::FormatName(CSite::GetNameFormat(null, $arParams['SITE_ID']), $guest, true), 'status' => $guest['STATUS'], 'accessibility' => $guest['ACCESSIBILITY'], 'bHost' => $guest['USER_ID'] == $arEvent['MEETING_HOST']); if ($guest['USER_ID'] == $USER->GetID()) { $arEvent['STATUS'] = $guest['STATUS']; } } } $set = CCalendar::GetSettings(); $url = str_replace('#user_id#', $arEvent['CREATED_BY'], $set['path_to_user_calendar']) . '?EVENT_ID=' . $arEvent['ID']; return array('ID' => $arEvent['ID'], 'NAME' => $arEvent['NAME'], 'DETAIL_TEXT' => $arEvent['DESCRIPTION'], 'DATE_FROM' => $arEvent['DT_FROM'], 'DATE_TO' => $arEvent['DT_TO'], 'ACCESSIBILITY' => $arEvent['ACCESSIBILITY'], 'IMPORTANCE' => $arEvent['IMPORTANCE'], 'STATUS' => $arEvent['STATUS'], 'IS_MEETING' => $arEvent['IS_MEETING'] ? 'Y' : 'N', 'GUESTS' => $arEvent['GUESTS'], 'UF_WEBDAV_CAL_EVENT' => $arEvent['UF_WEBDAV_CAL_EVENT'], 'URL' => $url); } }
public static function CanView($eventId, $userId) { CModule::IncludeModule("calendar"); $Event = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId), 'parseRecursion' => false, 'fetchAttendees' => true, 'checkPermissions' => true, 'userId' => $userId)); if ($Event && is_array($Event[0])) { // Event is not partly accessible - so it was not cleaned before by ApplyAccessRestrictions if (isset($Event[0]['DESCRIPTION']) || isset($Event[0]['IS_MEETING']) || isset($Event[0]['LOCATION'])) { return true; } } return false; }
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 SyncCalendarItems($connectionType, $calendarId, $arCalendarItems) { self::$silentErrorMode = true; // $arCalendarItems: //Array( // [0] => Array( // [XML_ID] => AAATAGFudGlfYn... // [MODIFICATION_LABEL] => DwAAABYAAA... // ) // [1] => Array( // [XML_ID] => AAATAGFudGlfYnVn... // [MODIFICATION_LABEL] => DwAAABYAAAAQ... // ) //) list($sectionId, $entityType, $entityId) = $calendarId; $entityType = strtolower($entityType); if ($connectionType == 'exchange') { $xmlIdField = "DAV_EXCH_LABEL"; } elseif ($connectionType == 'caldav') { $xmlIdField = "CAL_DAV_LABEL"; } else { return array(); } $arCalendarItemsMap = array(); foreach ($arCalendarItems as $value) { $arCalendarItemsMap[$value["XML_ID"]] = $value["MODIFICATION_LABEL"]; } $arModified = array(); $arEvents = CCalendarEvent::GetList(array('arFilter' => array('CAL_TYPE' => $entityType, 'OWNER_ID' => $entityId, 'SECTION' => $sectionId), 'getUserfields' => false, 'parseRecursion' => false, 'fetchAttendees' => false, 'fetchMeetings' => false, 'userId' => $entityType == 'user' ? $entityId : '0')); foreach ($arEvents as $Event) { if (isset($arCalendarItemsMap[$Event["DAV_XML_ID"]])) { if ($Event[$xmlIdField] != $arCalendarItemsMap[$Event["DAV_XML_ID"]]) { $arModified[$Event["DAV_XML_ID"]] = $Event["ID"]; } unset($arCalendarItemsMap[$Event["DAV_XML_ID"]]); } else { self::DeleteCalendarEvent($calendarId, $Event["ID"], self::$userId, $Event); } } $arResult = array(); foreach ($arCalendarItems as $value) { if (array_key_exists($value["XML_ID"], $arModified)) { $arResult[] = array("XML_ID" => $value["XML_ID"], "ID" => $arModified[$value["XML_ID"]]); } } foreach ($arCalendarItemsMap as $key => $value) { $arResult[] = array("XML_ID" => $key, "ID" => 0); } self::$silentErrorMode = false; return $arResult; }
public static function GetAbsent($users = false, $Params = array()) { global $DB; $curUserId = isset($Params['userId']) ? intVal($Params['userId']) : CCalendar::GetCurUserId(); $arUsers = array(); if ($users !== false && is_array($users)) { foreach($users as $id) { if ($id > 0) $arUsers[] = intVal($id); } } if (!count($arUsers)) $users = false; // Part 1: select ordinary events $arFilter = array( 'CAL_TYPE' => 'user', 'DELETED' => 'N', 'ACCESSIBILITY' => 'absent' ); if (isset($Params['fromLimit'])) $arFilter['FROM_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['fromLimit'], false), true, false); if (isset($Params['toLimit'])) $arFilter['TO_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['toLimit'], false), true, false); $arEvents = CCalendarEvent::GetList( array( 'arFilter' => $arFilter, 'getUserfields' => false, 'parseRecursion' => true, 'fetchAttendees' => false, 'fetchMeetings' => true, 'userId' => $curUserId, 'checkPermissions' => false, 'preciseLimits' => true ) ); // Part 2: select attendees if (count($arUsers) > 0) $userQ = ' AND CA.USER_ID in ('.implode(',',$arUsers).')'; else $userQ = ''; $strSql = " SELECT CA.EVENT_ID as ID, CA.USER_ID, CA.STATUS, CA.ACCESSIBILITY, CE.CAL_TYPE,CE.OWNER_ID,CE.NAME,".$DB->DateToCharFunction("CE.DT_FROM")." as DT_FROM,".$DB->DateToCharFunction("CE.DT_TO")." as DT_TO, CE.DT_LENGTH, CE.PRIVATE_EVENT, CE.ACCESSIBILITY, CE.IMPORTANCE, CE.IS_MEETING, CE.MEETING_HOST, CE.MEETING, CE.LOCATION, CE.RRULE, CE.EXRULE, CE.RDATE, CE.EXDATE, CES.SECT_ID FROM b_calendar_attendees CA LEFT JOIN b_calendar_event CE ON(CA.EVENT_ID=CE.ID) LEFT JOIN b_calendar_event_sect CES ON (CA.EVENT_ID=CES.EVENT_ID) WHERE CE.ID IS NOT NULL AND STATUS='Y' AND CA.ACCESSIBILITY='absent' $userQ "; if(isset($arFilter['FROM_LIMIT'])) { $strSql .= "AND "; if (strtoupper($DB->type) == "MYSQL") $strSql .= "CE.DT_TO>=FROM_UNIXTIME('".MkDateTime(FmtDate($arFilter['FROM_LIMIT'],"D.M.Y"),"d.m.Y")."')"; elseif(strtoupper($DB->type) == "MSSQL") $strSql .= "CE.DT_TO>=".$DB->CharToDateFunction($arFilter['FROM_LIMIT'], "SHORT"); elseif(strtoupper($DB->type) == "ORACLE") $strSql .= "CE.DT_TO>=TO_DATE('".FmtDate($arFilter['FROM_LIMIT'], "D.M.Y")." 00:00:00','dd.mm.yyyy hh24:mi:ss')"; } if($arFilter['TO_LIMIT']) { $strSql .= "AND "; if (strtoupper($DB->type) == "MYSQL") $strSql .= "CE.DT_FROM<=FROM_UNIXTIME('".MkDateTime(FmtDate($arFilter['TO_LIMIT'],"D.M.Y")." 23:59:59","d.m.Y H:i:s")."')"; elseif(strtoupper($DB->type) == "MSSQL") $strSql .= "CE.DT_FROM<=dateadd(day, 1, ".$DB->CharToDateFunction($arFilter['TO_LIMIT'], "SHORT").")"; elseif(strtoupper($DB->type) == "ORACLE") $strSql .= "CE.DT_FROM<=TO_DATE('".FmtDate($arFilter['TO_LIMIT'], "D.M.Y")." 23:59:59','dd.mm.yyyy hh24:mi:ss')"; } $res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); $arEvents2 = array(); while($event = $res->Fetch()) { $event = self::PreHandleEvent($event); if ($event['CAL_TYPE'] == 'user' && $event['IS_MEETING'] && $event['OWNER_ID'] == $event['USER_ID']) continue; if (self::CheckRecurcion($event)) self::ParseRecursion($arEvents2, $event, array( 'fromLimit' => $arFilter["FROM_LIMIT"], 'toLimit' => $arFilter["TO_LIMIT"], )); else self::HandleEvent($arEvents2, $event); } $arEvents = array_merge($arEvents, $arEvents2); $bSocNet = CModule::IncludeModule("socialnetwork"); $result = array(); $settings = CCalendar::GetSettings(array('request' => false)); foreach($arEvents as $event) { $userId = isset($event['USER_ID']) ? $event['USER_ID'] : $event['OWNER_ID']; if ($users !== false && !in_array($userId, $arUsers)) continue; if ($bSocNet && !CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $userId, "calendar")) continue; if ((!$event['CAL_TYPE'] != 'user' || $curUserId != $event['OWNER_ID']) && $curUserId != $event['CREATED_BY'] && !isset($arUserMeeting[$event['ID']])) { $sectId = $event['SECT_ID']; if (!$event['ACCESSIBILITY']) $event['ACCESSIBILITY'] = 'busy'; $private = $event['PRIVATE_EVENT'] && $event['CAL_TYPE'] == 'user'; $bManager = false; if (!$private && CCalendar::IsIntranetEnabled() && CModule::IncludeModule('intranet') && $event['CAL_TYPE'] == 'user' && $settings['dep_manager_sub']) $bManager = in_array($curUserId, CCalendar::GetUserManagers($event['OWNER_ID'], true)); if ($private || (!CCalendarSect::CanDo('calendar_view_full', $sectId) && !$bManager)) { if ($private) { $event['NAME'] = '['.GetMessage('EC_ACCESSIBILITY_'.strtoupper($event['ACCESSIBILITY'])).']'; } else { if (!CCalendarSect::CanDo('calendar_view_title', $sectId)) $event['NAME'] = '['.GetMessage('EC_ACCESSIBILITY_'.strtoupper($event['ACCESSIBILITY'])).']'; else $event['NAME'] = $event['NAME'].' ['.GetMessage('EC_ACCESSIBILITY_'.strtoupper($event['ACCESSIBILITY'])).']'; } } } $result[] = array( 'ID' => $event['ID'], 'NAME' => $event['NAME'], 'DATE_FROM' => $event['DT_FROM'], 'DATE_TO' => $event['DT_TO'], 'DT_FROM_TS' => $event['DT_FROM_TS'], 'DT_TO_TS' => $event['DT_TO_TS'], 'CREATED_BY' => $userId, 'DETAIL_TEXT' => '', 'USER_ID' => $userId ); } // Sort by DT_FROM_TS usort($result, array('CCalendar', '_NearestSort')); return $result; }
public static function ReturnICal($Params) { $sectId = $Params['sectId']; $userId = intVal($Params['userId']); $sign = $Params['sign']; $type = strtolower($Params['type']); $ownerId = intVal($Params['ownerId']); $bCache = false; $GLOBALS['APPLICATION']->RestartBuffer(); if (!self::CheckSign($sign, $userId, $sectId)) { return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED')); } $arSections = CCalendarSect::GetList(array('arFilter' => array('ID' => $sectId), 'checkPermissions' => false)); if ($arSections && $arSections[0] && $arSections[0]['EXPORT'] && $arSections[0]['EXPORT']['ALLOW']) { $arSection = $arSections[0]; $arEvents = CCalendarEvent::GetList(array('arFilter' => array('SECTION' => $arSection['ID']), 'getUserfields' => false, 'parseRecursion' => false, 'fetchAttendees' => false, 'fetchMeetings' => true, 'userId' => $userId)); $iCalEvents = self::FormatICal($arSection, $arEvents); } else { return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED')); } self::ShowICalHeaders(); echo $iCalEvents; exit; }
public static function CanView($eventId, $userId) { CModule::IncludeModule("calendar"); $Event = CCalendarEvent::GetList( array( 'arFilter' => array( "ID" => $eventId, ), 'parseRecursion' => false, 'fetchAttendees' => true, 'checkPermissions' => true, 'userId' => $userId, ) ); if ($Event && is_array($Event[0])) { // Event partly accessible if (!isset($Event[0]['DESCRIPTION'], $Event[0]['IS_MEETING'], $Event[0]['LOCATION'])) return false; return true; } return false; }
$arFields['ATTENDEES'][] = $ownerId; } $arFields['MEETING_HOST'] = $ownerId; $arFields['MEETING'] = array('HOST_NAME' => CCalendar::GetUserName($ownerId), 'TEXT' => '', 'OPEN' => false, 'NOTIFY' => true, 'REINVITE' => true); } $newId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true, 'autoCreateSection' => true)); } elseif ($_REQUEST['app_calendar_action'] == 'drop_event' && check_bitrix_sessid()) { $res = CCalendar::DeleteEvent(intVal($_POST['event_id'])); } die; } $calType = 'user'; $ownerId = $userId; if ($arResult['NEW']) { } else { $Event = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "OWNER_ID" => $userId, "DELETED" => "N"), 'parseRecursion' => false, 'fetchAttendees' => true, 'fetchMeetings' => true, 'checkPermissions' => true, 'setDefaultLimit' => false)); if ($Event && is_array($Event[0])) { $Event = $Event[0]; if ($Event['IS_MEETING']) { foreach ($Event['~ATTENDEES'] as $attendee) { $attendee['DISPLAY_NAME'] = CCalendar::GetUserName($attendee); $arAttendees[] = $attendee; } unset($Event['~ATTENDEES']); $arResult['ATTENDEES'] = $arAttendees; } $Event['~LOCATION'] = $Event['LOCATION'] !== '' ? CCalendar::GetTextLocation($Event["LOCATION"]) : ''; if ($Event['RRULE'] !== '') { $Event['RRULE'] = CCalendarEvent::ParseRRULE($Event['RRULE']); if (is_array($Event['RRULE']) && !isset($Event['RRULE']['UNTIL'])) { $Event['RRULE']['UNTIL'] = $Event['DT_TO_TS'];
if (!isset($arParams["CALENDAR_TYPE"])) { $arParams["CALENDAR_TYPE"] = 'user'; } if (!CModule::IncludeModule("calendar") || !class_exists("CCalendar")) { return ShowError(GetMessage("EC_CALENDAR_MODULE_NOT_INSTALLED")); } $arParams['EVENT_ID'] = intval($arParams['EVENT_ID']); $arResult['ID'] = 'livefeed' . $arParams['EVENT_ID']; $arResult['EVENT'] = false; $arParams['CUR_USER'] = $USER->GetId(); $Events = CCalendarEvent::GetList(array('arFilter' => array("ID" => $arParams['EVENT_ID'], "DELETED" => false), 'parseRecursion' => false, 'fetchAttendees' => true, 'checkPermissions' => true, 'setDefaultLimit' => false)); if ($Events && is_array($Events[0])) { $arResult['EVENT'] = $Events[0]; } if (!$arResult['EVENT']) { $Events = CCalendarEvent::GetList(array('arFilter' => array("ID" => $arParams['EVENT_ID'], "DELETED" => false), 'parseRecursion' => false, 'checkPermissions' => false, 'setDefaultLimit' => false)); // Clean damaged event from livefeed if (!$Events || !is_array($Events[0])) { CCalendarLiveFeed::OnDeleteCalendarEventEntry($arParams['EVENT_ID']); } return false; } if ($arResult['EVENT']['LOCATION'] !== '') { $arResult['EVENT']['LOCATION'] = CCalendar::GetTextLocation($arResult['EVENT']["LOCATION"]); } global $USER_FIELD_MANAGER; $UF = CCalendarEvent::GetEventUserFields($arResult['EVENT']); $arResult['UF_CRM_CAL_EVENT'] = $UF['UF_CRM_CAL_EVENT']; if (empty($arResult['UF_CRM_CAL_EVENT']['VALUE'])) { $arResult['UF_CRM_CAL_EVENT'] = false; }
function InstallService($serviceID, $serviceStage) { $wizard =& $this->GetWizard(); if (CModule::IncludeModule("iblock")) { $type = substr($serviceID, 0, -1); if ($type == "iblockElement") { $dbItem = CIBlockElement::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, false, array("ID")); while ($arItem = $dbItem->Fetch()) { CIBlockElement::Delete($arItem["ID"]); } } elseif ($type == "iblockSectionElement") { $dbItem = CIBlockElement::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, false, array("ID")); while ($arItem = $dbItem->Fetch()) { CIBlockElement::Delete($arItem["ID"]); } $dbItem = CIBlockSection::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, array("ID")); while ($arItem = $dbItem->Fetch()) { CIBlockSection::Delete($arItem["ID"]); } } elseif ($serviceID == "iblockDepartmentsElement") { $dbItem = CIBlockSection::GetList(array(), array("=IBLOCK_CODE" => "departments")); while ($arItem = $dbItem->Fetch()) { if ($arItem["DEPTH_LEVEL"] > 2) { CIBlockSection::Delete($arItem["ID"]); } } } elseif ($serviceID == "tasks") { if (CModule::IncludeModule("tasks")) { $dbItem = CTasks::GetList(array(), array("SITE_ID" => $wizard->GetVar("siteID"))); while ($arItem = $dbItem->Fetch()) { CTasks::Delete($arItem["ID"]); } } } elseif ($serviceID == "calendar") { if (CModule::IncludeModule("calendar")) { $dbItem = CCalendarEvent::GetList(); foreach ($dbItem as $arItem) { CCalendarEvent::Delete(array("id" => $arItem["ID"])); } } } elseif ($serviceID == "meeting") { if (CModule::IncludeModule("meeting")) { $dbItem = CMeeting::GetList(array(), array()); while ($arItem = $dbItem->Fetch()) { if ($arItem["ID"]) { CMeeting::Delete($arItem["ID"]); } } } } elseif ($serviceID == "user") { if ($serviceStage == "user") { $dbUser = CUser::GetList($by = "ID", $order = "DESC", array(">ID" => 1)); while ($arUser = $dbUser->Fetch()) { CUser::Delete($arUser["ID"]); } } } elseif ($serviceID == "crm") { if ($serviceStage == "crm") { if (CModule::IncludeModule('crm')) { $CCrmLead = new CCrmLead(); $resLead = CCrmLead::GetList(array(), array(), array(), false); while ($rowLead = $resLead->Fetch()) { $CCrmLead->Delete($rowLead["ID"]); } $CCrmContact = new CCrmContact(); $resContact = CCrmContact::GetList(array(), array(), array(), false); while ($rowContact = $resContact->Fetch()) { $CCrmContact->Delete($rowContact["ID"]); } $CCrmCompany = new CCrmCompany(); $resCompany = CCrmCompany::GetList(array(), array(), array(), false); while ($rowCompany = $resCompany->Fetch()) { $CCrmCompany->Delete($rowCompany["ID"]); } $CCrmDeal = new CCrmDeal(); $resDeal = CCrmDeal::GetList(array(), array(), array(), false); while ($rowDeal = $resDeal->Fetch()) { $CCrmDeal->Delete($rowDeal["ID"]); } } } } elseif ($serviceID == "cache") { require_once $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/classes/general/cache_html.php"; if ($serviceStage == "cache1") { BXClearCache(true); } elseif ($serviceStage == "cache2") { $GLOBALS["CACHE_MANAGER"]->CleanAll(); } elseif ($serviceStage == "cache3") { $GLOBALS["stackCacheManager"]->CleanAll(); } elseif ($serviceStage == "cache4") { CHTMLPagesCache::CleanAll(); } COption::SetOptionString("main", "wizard_clear_exec", "Y", false, $wizard->GetVar("siteID")); } } }
public function GetEvents($date) { $arEvents = array(); if (CBXFeatures::IsFeatureEnabled('Calendar')) { $ts = CTimeMan::RemoveHoursTS(MakeTimeStamp($date)); if ($ts > 0) { $calendar2 = COption::GetOptionString("intranet", "calendar_2", "N") == "Y" && CModule::IncludeModule('calendar'); if ($calendar2) { $arFilter = array('arFilter' => array("OWNER_ID" => $this->USER_ID, "FROM_LIMIT" => ConvertTimeStamp($ts, 'FULL'), "TO_LIMIT" => ConvertTimeStamp($ts + 86399, 'FULL')), 'parseRecursion' => true, 'userId' => $this->USER_ID, 'skipDeclined' => true, 'fetchAttendees' => false, 'fetchMeetings' => true); $arNewEvents = CCalendarEvent::GetList($arFilter); if (count($arNewEvents) > 0) { foreach ($arNewEvents as $arEvent) { if ($arEvent['RRULE']) { $ts_from = MakeTimeStamp($arEvent['DT_FROM']); $ts_to = MakeTimeStamp($arEvent['DT_TO']); if ($ts_to < $ts || $ts_from > $ts + 86399) { continue; } } $arEvents[] = array('ID' => $arEvent['ID'], 'OWNER_ID' => $this->USER_ID, 'CREATED_BY' => $arEvent['CREATED_BY'], 'NAME' => $arEvent['NAME'], 'DETAIL_TEXT' => $arEvent['DESCRIPTION'], 'DATE_FROM' => $arEvent['DT_FROM'], 'DATE_TO' => $arEvent['DT_TO'], 'IMPORTANCE' => $arEvent['IMPORTANCE'], 'ACCESSIBILITY' => $arEvent['ACCESSIBILITY']); } } } else { $arEvents = CEventCalendar::GetNearestEventsList(array('userId' => $this->USER_ID, 'bCurUserList' => true, 'fromLimit' => ConvertTimeStamp($ts, 'FULL'), 'toLimit' => ConvertTimeStamp($ts + 86399, 'FULL'), 'iblockId' => COption::GetOptionInt('intranet', 'iblock_calendar'))); foreach ($arEvents as $key => $event) { if ($event['STATUS'] === 'N') { unset($arEvents[$key]); } } } return array_values($arEvents); } } return false; }