function InstallEvents() { global $DB; $arCurPhpVer = Explode(".", PhpVersion()); if (IntVal($arCurPhpVer[0]) < 5) return true; $sIn = "'CALENDAR_INVITATION'"; $rs = $DB->Query("SELECT count(*) C FROM b_event_type WHERE EVENT_NAME IN (".$sIn.") ", false, "File: ".__FILE__."<br>Line: ".__LINE__); $ar = $rs->Fetch(); if($ar["C"] <= 0) include($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/calendar/install/events.php"); if (!IsModuleInstalled('intranet')) { COption::SetOptionString("intranet", "calendar_2", "Y"); CModule::IncludeModule('calendar'); CCalendar::ClearCache(); CCalendar::CacheTime(0); $arTypes = CCalendarType::GetList(); if (!$arTypes || !count($arTypes)) { CCalendarType::Edit(array( 'NEW' => true, 'arFields' => array( 'XML_ID' => 'events', 'NAME' => GetMessage('CAL_DEFAULT_TYPE'), 'ACCESS' => array( 'G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_view') ) ) )); } } return true; }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule("calendar") || WIZARD_IS_RERUN) { return; } COption::SetOptionString("intranet", "calendar_2", "Y"); // company calendar calendar type CCalendarType::Edit(array('NEW' => true, 'arFields' => array('XML_ID' => 'company_calendar', 'NAME' => GetMessage('CAL_TYPE_COMPANY_NAME'), 'DESCRIPTION' => '', 'ACCESS' => array('G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_view'))))); // Sections $sectId0 = CCalendar::SaveSection(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'ID' => 0, 'NAME' => GetMessage("CAL_COMPANY_SECT_0"), 'DESCRIPTION' => GetMessage("CAL_COMPANY_SECT_DESC_0"), 'COLOR' => '#855CC5', 'TEXT_COLOR' => '', 'OWNER_ID' => '', 'EXPORT' => array('ALLOW' => true, 'SET' => '3_9'), 'ACCESS' => array(), 'IS_EXCHANGE' => false))); $sectId1 = CCalendar::SaveSection(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'ID' => 0, 'NAME' => GetMessage("CAL_COMPANY_SECT_1"), 'DESCRIPTION' => GetMessage("CAL_COMPANY_SECT_DESC_1"), 'COLOR' => '#7DDEC2', 'TEXT_COLOR' => '', 'OWNER_ID' => '', 'EXPORT' => array('ALLOW' => true, 'SET' => '3_9'), 'ACCESS' => array(), 'IS_EXCHANGE' => false))); $sectId2 = CCalendar::SaveSection(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'ID' => 0, 'NAME' => GetMessage("CAL_COMPANY_SECT_2"), 'DESCRIPTION' => GetMessage("CAL_COMPANY_SECT_DESC_2"), 'COLOR' => '#F6EA68', 'TEXT_COLOR' => '', 'OWNER_ID' => '', 'EXPORT' => array('ALLOW' => true, 'SET' => '3_9'), 'ACCESS' => array(), 'IS_EXCHANGE' => false))); // Events for company_calendar CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_0"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_0"), 'DT_FROM' => GetTime(mktime(9, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(16, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'UNTIL' => GetTime(mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1), "SHORT"), 'BYDAY' => 'TU'), 'SECTIONS' => $sectId0), 'userId' => 1)); CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_1"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_1"), 'DT_FROM' => GetTime(mktime(0, 0, 0, date("m"), date("d") + 2, date("Y")), "SHORT"), 'DT_TO' => GetTime(mktime(0, 0, 0, date("m"), date("d") + 2, date("Y")), "SHORT"), 'RRULE' => array('FREQ' => 'MONTHLY', 'INTERVAL' => 1, 'UNTIL' => GetTime(mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1), "SHORT")), 'SECTIONS' => $sectId0), 'userId' => 1)); CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_2"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_2"), 'DT_FROM' => GetTime(mktime(10, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(12, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'BYDAY' => 'MO'), 'SECTIONS' => $sectId1), 'userId' => 1)); CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_3"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_3"), 'DT_FROM' => GetTime(mktime(9, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(18, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'BYDAY' => 'TU'), 'SECTIONS' => $sectId2), 'userId' => 1)); CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_4"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_4"), 'DT_FROM' => GetTime(mktime(12, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(17, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'BYDAY' => 'FR'), 'SECTIONS' => $sectId2), 'userId' => 1)); CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 1, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_5"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_5"), 'DT_FROM' => GetTime(mktime(16, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(21, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'BYDAY' => 'SA'), 'SECTIONS' => $sectId1), 'userId' => 1)); // User's calendar type CCalendarType::Edit(array('NEW' => true, 'arFields' => array('XML_ID' => 'user', 'NAME' => GetMessage('CAL_TYPE_USER_NAME'), 'DESCRIPTION' => '', 'ACCESS' => array('G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_edit'))))); // Group's calendar type CCalendarType::Edit(array('NEW' => true, 'arFields' => array('XML_ID' => 'group', 'NAME' => GetMessage('CAL_TYPE_GROUP_NAME'), 'DESCRIPTION' => '', 'ACCESS' => array('G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_edit'))))); $id = CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'user', 'OWNER_ID' => 1, 'NAME' => GetMessage("W_IB_CALENDAR_EMP_ABS"), 'DT_FROM' => GetTime(mktime(12, 0, 0, date("m"), date("d") + 1, date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(14, 0, 0, date("m"), date("d") + 1, date("Y")), "FULL"), 'DESCRIPTION' => ''), 'userId' => 1, 'autoDetectSection' => true, 'autoCreateSection' => true));
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 static function GetDefaultAccess($type, $ownerId) { if (CCalendar::IsIntranetEnabled()) { $access = array('G2' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view_time')); } else { $access = array('G2' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view')); } if ($type == 'user') { } elseif ($type == 'group' && $ownerId > 0) { $access['SG' . $ownerId . '_A'] = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_access'); $access['SG' . $ownerId . '_E'] = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit'); $access['SG' . $ownerId . '_K'] = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit'); } else { } // Creator of the section $access['U' . CCalendar::GetUserId()] = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_access'); $arAccessCodes = array(); foreach ($access as $code => $o) { $arAccessCodes[] = $code; } CCalendar::PushAccessNames($arAccessCodes); return $access; }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule("calendar")) { return; } COption::SetOptionString("intranet", "calendar_2", "Y"); if (WIZARD_FIRST_INSTAL != 'Y') { // calendar type $arTypes = CCalendarType::GetList(array("arFilter" => array("XML_ID" => 'events_info'))); if (!$arTypes || count($arTypes) <= 0) { CCalendarType::Edit(array('NEW' => true, 'arFields' => array('XML_ID' => 'events_info', 'NAME' => GetMessage('CAL_DEFAULT_TYPE'), 'ACCESS' => array('G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_view'))))); } // Sections $sectId0 = CCalendar::SaveSection(array('arFields' => array('CAL_TYPE' => 'events_info', 'ID' => 0, 'NAME' => GetMessage("CAL_TYPE_COMPANY_NAME"), 'DESCRIPTION' => "", 'COLOR' => '#855CC5', 'TEXT_COLOR' => '', 'OWNER_ID' => '', 'EXPORT' => array('ALLOW' => true, 'SET' => '3_9'), 'ACCESS' => array(), 'IS_EXCHANGE' => false))); // Events for company_calendar CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'events_info', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_EVENT_1_NAME"), 'DESCRIPTION' => "", 'DT_FROM' => GetTime(mktime(0, 0, 0, date("m"), date("d") + 4, date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(0, 0, 0, date("m"), date("d") + 4, date("Y")), "FULL"), 'RRULE' => array(), 'SECTIONS' => $sectId0), 'userId' => 1)); CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'events', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_EVENT_2_NAME"), 'DESCRIPTION' => "", 'COLOR' => '#FFFF80', 'DT_FROM' => GetTime(mktime(0, 0, 0, date("m"), date("d"), date("Y")), "SHORT"), 'DT_TO' => GetTime(mktime(0, 0, 0, date("m"), date("d"), date("Y")), "SHORT"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 3, 'BYDAY' => 'SA'), 'SECTIONS' => $sectId0), 'userId' => 1)); }