コード例 #1
0
ファイル: calendar.php プロジェクト: andy-profi/bxApiDocs
 public function Show($Params = array())
 {
     global $APPLICATION, $USER;
     $arType = false;
     foreach (self::$arTypes as $t) {
         if (self::$type == $t['XML_ID']) {
             $arType = $t;
         }
     }
     if (!$arType) {
         return $APPLICATION->ThrowException('[EC_WRONG_TYPE]' . GetMessage('EC_WRONG_TYPE'));
     }
     if (!CCalendarType::CanDo('calendar_type_view', self::$type)) {
         return $APPLICATION->ThrowException(GetMessage("EC_ACCESS_DENIED"));
     }
     $arStartupEvent = false;
     $showNewEventDialog = false;
     //Show new event dialog
     if (isset($_GET['EVENT_ID'])) {
         if ($_GET['EVENT_ID'] == 'NEW') {
             $showNewEventDialog = true;
         } elseif (substr($_GET['EVENT_ID'], 0, 4) == 'EDIT') {
             $arStartupEvent = self::GetStartUpEvent(intval(substr($_GET['EVENT_ID'], 4)));
             if ($arStartupEvent) {
                 $arStartupEvent['EDIT'] = true;
             }
             if ($arStartupEvent['DT_FROM']) {
                 $ts = self::Timestamp($arStartupEvent['DT_FROM']);
                 $init_month = date('m', $ts);
                 $init_year = date('Y', $ts);
             }
         } elseif ($arStartupEvent = self::GetStartUpEvent($_GET['EVENT_ID'])) {
             if ($arStartupEvent['DT_FROM']) {
                 $ts = self::Timestamp($arStartupEvent['DT_FROM']);
                 $init_month = date('m', $ts);
                 $init_year = date('Y', $ts);
             }
         }
     }
     if (!$init_month && !$init_year && strlen($Params["initDate"]) > 0 && strpos($Params["initDate"], '.') !== false) {
         $ts = self::Timestamp($Params["initDate"]);
         $init_month = date('m', $ts);
         $init_year = date('Y', $ts);
     }
     if (!isset($init_month)) {
         $init_month = date("m");
     }
     if (!isset($init_year)) {
         $init_year = date("Y");
     }
     $id = 'EC' . rand();
     $weekHolidays = array();
     if (isset(self::$settings['week_holidays'])) {
         $days = array('MO' => 0, 'TU' => 1, 'WE' => 2, 'TH' => 3, 'FR' => 4, 'SA' => 5, 'SU' => 6);
         foreach (self::$settings['week_holidays'] as $day) {
             $weekHolidays[] = $days[$day];
         }
     } else {
         $weekHolidays = array(5, 6);
     }
     $yearHolidays = array();
     if (isset(self::$settings['year_holidays'])) {
         foreach (explode(',', self::$settings['year_holidays']) as $date) {
             $date = trim($date);
             $ardate = explode('.', $date);
             if (count($ardate) == 2 && $ardate[0] && $ardate[1]) {
                 $yearHolidays[] = intVal($ardate[0]) . '.' . (intVal($ardate[1]) - 1);
             }
         }
     }
     $yearWorkdays = array();
     if (isset(self::$settings['year_workdays'])) {
         foreach (explode(',', self::$settings['year_workdays']) as $date) {
             $date = trim($date);
             $ardate = explode('.', $date);
             if (count($ardate) == 2 && $ardate[0] && $ardate[1]) {
                 $yearWorkdays[] = intVal($ardate[0]) . '.' . (intVal($ardate[1]) - 1);
             }
         }
     }
     $bShowBanner = self::IsPersonal() && self::$userSettings['showBanner'];
     $bExchange = CCalendar::IsExchangeEnabled() && self::$type == 'user';
     $bExchangeConnected = $bExchange && CDavExchangeCalendar::IsExchangeEnabledForUser(self::$ownerId);
     $bCalDAV = CCalendar::IsCalDAVEnabled() && self::$type == "user";
     $bWebservice = CCalendar::IsWebserviceEnabled();
     $bExtranet = CCalendar::IsExtranetEnabled();
     if (!self::$bIntranet && !$bExchange && !$bCalDAV) {
         $bShowBanner = false;
     }
     $dd = self::GetMeetingRoomList(array('RMiblockId' => self::$settings['rm_iblock_id'], 'pathToMR' => self::$pathesForSite['path_to_rm'], 'VMiblockId' => self::$settings['vr_iblock_id'], 'pathToVR' => self::$pathesForSite['path_to_vr']));
     $JSConfig = array('id' => $id, 'type' => self::$type, 'userId' => self::$userId, 'userName' => self::GetUserName(self::$userId), 'ownerId' => self::$ownerId, 'perm' => $arType['PERM'], 'permEx' => self::$perm, 'bTasks' => self::$bTasks, 'sectionControlsDOMId' => self::$SectionsControlsDOMId, 'week_holidays' => $weekHolidays, 'year_holidays' => $yearHolidays, 'year_workdays' => $yearWorkdays, 'week_start' => self::GetWeekStart(), 'week_days' => CCalendarSceleton::GetWeekDaysEx(self::GetWeekStart()), 'init_month' => $init_month, 'init_year' => $init_year, 'pathToUser' => self::$pathToUser, 'path' => self::$path, 'page' => self::$actionUrl, 'settings' => self::$settings, 'userSettings' => self::$userSettings, 'bShowBanner' => $bShowBanner, 'bAnonym' => self::$bAnonym, 'bIntranet' => self::$bIntranet, 'bWebservice' => $bWebservice, 'bExtranet' => $bExtranet, 'bSocNet' => self::$bSocNet, 'bExchange' => $bExchangeConnected, 'startupEvent' => $arStartupEvent, 'canAddToSuperpose' => self::$bCanAddToSuperpose, 'workTime' => array(self::$settings['work_time_start'], self::$settings['work_time_end']), 'meetingRooms' => self::GetMeetingRoomList(array('RMiblockId' => self::$settings['rm_iblock_id'], 'pathToMR' => self::$pathesForSite['path_to_rm'], 'VMiblockId' => self::$settings['vr_iblock_id'], 'pathToVR' => self::$pathesForSite['path_to_vr'])), 'allowResMeeting' => self::$allowReserveMeeting, 'allowVideoMeeting' => self::$allowVideoMeeting, 'plannerSettings' => CCalendarPlanner::GetUserOptions(), 'bAMPM' => self::$bAMPM, 'bWideDate' => self::$bWideDate, 'WDControllerCID' => 'UFWD' . $id);
     $lastSection = CUserOptions::GetOption("calendar", "last_section", false, self::$userId);
     if (isset($lastSection[self::$type . '_' . self::$ownerId])) {
         $JSConfig['lastSection'] = $lastSection[self::$type . '_' . self::$ownerId];
     }
     // Access permissons for type
     if (CCalendarType::CanDo('calendar_type_access', self::$type)) {
         $JSConfig['TYPE_ACCESS'] = $arType['ACCESS'];
     }
     if ($bCalDAV) {
         self::InitCalDavParams($JSConfig);
     }
     // If enabled superposed sections - fetch it
     $arAddSections = array();
     if (self::$bSuperpose) {
         $arAddSections = self::GetDisplayedSuperposed(self::$userId);
     }
     if (!is_array($arAddSections)) {
         $arAddSections = array();
     }
     $arSectionIds = array();
     $hiddenSections = CCalendarSect::Hidden(self::$userId);
     $arDisplayedSPSections = array();
     foreach ($arAddSections as $sect) {
         $arDisplayedSPSections[] = $sect;
     }
     self::$userMeetingSection = CCalendar::GetCurUserMeetingSection();
     //  **** GET SECTIONS ****
     $arSections = self::GetSectionList(array('ADDITIONAL_IDS' => $arDisplayedSPSections));
     $bReadOnly = !self::$perm['edit'] && !self::$perm['section_edit'];
     if (self::$type == 'user' && self::$ownerId != self::$userId) {
         $bReadOnly = true;
     }
     if (!$USER->IsAuthorized()) {
         $bReadOnly = true;
     }
     $bCreateDefault = true;
     if (self::$type == 'user') {
         $bCreateDefault = self::$ownerId == self::$userId;
     }
     $noEditAccessedCalendars = true;
     $additonalMeetingsId = array();
     foreach ($arSections as $i => $section) {
         $arSections[$i]['~IS_MEETING_FOR_OWNER'] = $section['CAL_TYPE'] == 'user' && $section['OWNER_ID'] != self::$userId && CCalendar::GetMeetingSection($section['OWNER_ID']) == $section['ID'];
         if (!in_array($section['ID'], $hiddenSections)) {
             $arSectionIds[] = $section['ID'];
             // It's superposed calendar of the other user and it's need to show user's meetings
             if ($arSections[$i]['~IS_MEETING_FOR_OWNER']) {
                 $additonalMeetingsId[] = array('ID' => $section['OWNER_ID'], 'SECTION_ID' => $section['ID']);
             }
         }
         // We check access only for main sections because we can't edit superposed section
         if ($arSections[$i]['CAL_TYPE'] == self::$type && $arSections[$i]['OWNER_ID'] == self::$ownerId) {
             if ($noEditAccessedCalendars && $section['PERM']['edit']) {
                 $noEditAccessedCalendars = false;
             }
             if ($bReadOnly && ($section['PERM']['edit'] || $section['PERM']['edit_section'])) {
                 $bReadOnly = false;
             }
         }
         if (self::$bSuperpose && in_array($section['ID'], $arAddSections)) {
             $arSections[$i]['SUPERPOSED'] = true;
         }
         if ($bCreateDefault && $section['CAL_TYPE'] == self::$type && $section['OWNER_ID'] == self::$ownerId) {
             $bCreateDefault = false;
         }
     }
     if ($noEditAccessedCalendars && !$bCreateDefault) {
         $bReadOnly = true;
     }
     if (self::$bSuperpose && $bReadOnly && count($arAddSections) <= 0) {
         self::$bSuperpose = false;
     }
     self::$bReadOnly = $bReadOnly;
     if (!$bReadOnly && $showNewEventDialog) {
         $JSConfig['showNewEventDialog'] = true;
         $JSConfig['bChooseMR'] = isset($_GET['CHOOSE_MR']) && $_GET['CHOOSE_MR'] == "Y";
     }
     if (!in_array($JSConfig['lastSection'], $arSectionIds)) {
         $JSConfig['lastSection'] = $arSectionIds[0];
     }
     //  **** GET EVENTS ****
     // NOTICE: Attendees for meetings selected inside this method and returns as array by link '$arAttendees'
     $arAttendees = array();
     // List of attendees for each event Array([ID] => Array(), ..,);
     $arEvents = self::GetEventList(array('type' => self::$type, 'section' => $arSectionIds, 'fromLimit' => self::Date(mktime(0, 0, 0, $init_month - 1, 20, $init_year), false), 'toLimit' => self::Date(mktime(0, 0, 0, $init_month + 1, 10, $init_year), false), 'additonalMeetingsId' => $additonalMeetingsId), $arAttendees);
     $arTaskIds = array();
     //  **** GET TASKS ****
     if (self::$bTasks && !in_array('tasks', $hiddenSections)) {
         $arTasks = self::GetTaskList(array('fromLimit' => self::Date(mktime(0, 0, 0, $init_month - 1, 20, $init_year), false), 'toLimit' => self::Date(mktime(0, 0, 0, $init_month + 1, 10, $init_year), false)), $arTaskIds);
         if (count($arTasks) > 0) {
             $arEvents = array_merge($arEvents, $arTasks);
         }
     }
     // We don't have any section
     if ($bCreateDefault) {
         $defCalendar = CCalendarSect::CreateDefault(array('type' => CCalendar::GetType(), 'ownerId' => CCalendar::GetOwnerId()));
         $arSectionIds[] = $defCalendar['ID'];
         $arSections[] = $defCalendar;
         self::$userMeetingSection = $defCalendar['ID'];
     }
     if (CCalendarType::CanDo('calendar_type_edit', self::$type)) {
         $JSConfig['new_section_access'] = CCalendarSect::GetDefaultAccess(self::$type, self::$ownerId);
     }
     if ($bReadOnly && (!count($arSections) || count($arSections) == 1 && !self::$bIntranet)) {
         $bShowSections = false;
     } else {
         $bShowSections = true;
     }
     $arColors = array('#CEE669', '#E6A469', '#98AEF6', '#7DDEC2', '#B592EC', '#D98E85', '#F6EA68', '#DDBFEB', '#FF8D89', '#FFCEFF', '#3ABF54', '#BF793A', '#1C1CD8', '#4BB798', '#855CC5', '#B25D52', '#FFBD26', '#C48297', '#E53D37', '#7DF5FF');
     // Build calendar base html and dialogs
     CCalendarSceleton::Build(array('id' => $id, 'type' => self::$type, 'ownerId' => self::$ownerId, 'bShowSections' => $bShowSections, 'bShowSuperpose' => self::$bSuperpose, 'bShowBanner' => $bShowBanner, 'bOutlook' => self::$bIntranet && self::$bWebservice, 'bExtranet' => $bExtranet, 'bReadOnly' => $bReadOnly, 'bShowTasks' => self::$bTasks, 'arTaskIds' => $arTaskIds, 'bSocNet' => self::$bSocNet, 'bIntranet' => self::$bIntranet, 'bCalDAV' => $bCalDAV, 'bExchange' => $bExchange, 'bExchangeConnected' => $bExchangeConnected, 'inPersonalCalendar' => self::IsPersonal(), 'colors' => $arColors, 'bAMPM' => self::$bAMPM));
     $JSConfig['arCalColors'] = $arColors;
     $JSConfig['events'] = $arEvents;
     $JSConfig['attendees'] = $arAttendees;
     $JSConfig['sections'] = $arSections;
     $JSConfig['sectionsIds'] = $arSectionIds;
     $JSConfig['hiddenSections'] = $hiddenSections;
     $JSConfig['readOnly'] = $bReadOnly;
     $JSConfig['accessNames'] = self::GetAccessNames();
     $JSConfig['bSuperpose'] = self::$bSuperpose;
     $JSConfig['additonalMeetingsId'] = $additonalMeetingsId;
     // Append Javascript files and CSS files, and some base configs
     CCalendarSceleton::InitJS($JSConfig);
 }
コード例 #2
0
 public static function Edit($Params = array())
 {
     global $DB, $CACHE_MANAGER;
     $arFields = $Params['arFields'];
     // Get current user id
     $userId = isset($Params['userId']) && intVal($Params['userId']) > 0 ? intVal($Params['userId']) : CCalendar::GetCurUserId();
     if (!$userId && isset($arFields['CREATED_BY'])) {
         $userId = intVal($arFields['CREATED_BY']);
     }
     $path = !empty($Params['path']) ? $Params['path'] : CCalendar::GetPath($arFields['CAL_TYPE'], $arFields['OWNER_ID'], true);
     if ($userId < 0) {
         return false;
     }
     if (!self::CheckFields($arFields)) {
         return false;
     }
     if ($arFields['CAL_TYPE'] == 'user') {
         $CACHE_MANAGER->ClearByTag('calendar_user_' . $arFields['OWNER_ID']);
     }
     $bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0;
     $arFields['TIMESTAMP_X'] = CCalendar::Date(mktime(), true, false);
     if ($bNew) {
         if (!isset($arFields['CREATED_BY'])) {
             $arFields['CREATED_BY'] = $userId;
         }
         if (!isset($arFields['DATE_CREATE'])) {
             $arFields['DATE_CREATE'] = $arFields['TIMESTAMP_X'];
         }
     }
     $attendees = is_array($arFields['ATTENDEES']) ? $arFields['ATTENDEES'] : array();
     if (!isset($arFields['OWNER_ID']) || !$arFields['OWNER_ID']) {
         $arFields['OWNER_ID'] = 0;
     }
     if (!isset($arFields['LOCATION']['OLD']) && !$bNew) {
         // Select meeting info about event
         if (isset($Params['currentEvent'])) {
             $oldEvent = $Params['currentEvent'];
         } else {
             $oldEvent = CCalendarEvent::GetById($arFields['ID']);
         }
         if ($oldEvent) {
             $arFields['LOCATION']['OLD'] = $oldEvent['LOCATION'];
         }
     }
     $offset = CCalendar::GetOffset();
     $arFields['LOCATION'] = CCalendar::SetLocation($arFields['LOCATION']['OLD'], $arFields['LOCATION']['NEW'], array('dateFrom' => CCalendar::Date($arFields['DT_FROM_TS'] + $offset), 'dateTo' => CCalendar::Date($arFields['DT_TO_TS'] + $offset), 'name' => $arFields['NAME'], 'persons' => count($attendees), 'attendees' => $attendees, 'bRecreateReserveMeetings' => $arFields['LOCATION']['RE_RESERVE'] !== 'N'));
     $bSendInvitations = false;
     if (!isset($arFields['IS_MEETING']) && isset($arFields['ATTENDEES']) && is_array($arFields['ATTENDEES']) && empty($arFields['ATTENDEES'])) {
         $arFields['IS_MEETING'] = false;
     }
     $attendeesCodes = array();
     if ($arFields['IS_MEETING'] && is_array($arFields['MEETING'])) {
         if (!empty($arFields['ATTENDEES_CODES'])) {
             $attendeesCodes = $arFields['ATTENDEES_CODES'];
             $arFields['ATTENDEES_CODES'] = implode(',', $arFields['ATTENDEES_CODES']);
         }
         // Organizer
         $bSendInvitations = $Params['bSendInvitations'] !== false;
         $arFields['~MEETING'] = array('HOST_NAME' => $arFields['MEETING']['HOST_NAME'], 'TEXT' => $arFields['MEETING']['TEXT'], 'OPEN' => $arFields['MEETING']['OPEN'], 'NOTIFY' => $arFields['MEETING']['NOTIFY'], 'REINVITE' => $arFields['MEETING']['REINVITE']);
         $arFields['MEETING'] = serialize($arFields['~MEETING']);
     }
     $arReminders = array();
     if ($arFields['REMIND'] && is_array($arFields['REMIND'])) {
         foreach ($arFields['REMIND'] as $remind) {
             if (in_array($remind['type'], array('min', 'hour', 'day'))) {
                 $arReminders[] = array('type' => $remind['type'], 'count' => floatVal($remind['count']));
             }
         }
     }
     $arFields['REMIND'] = count($arReminders) > 0 ? serialize($arReminders) : '';
     $AllFields = self::GetFields();
     $dbFields = array();
     foreach ($arFields as $field => $val) {
         if (isset($AllFields[$field]) && $field != "ID") {
             $dbFields[$field] = $arFields[$field];
         }
     }
     CTimeZone::Disable();
     if ($bNew) {
         $ID = CDatabase::Add("b_calendar_event", $dbFields, array('DESCRIPTION', 'MEETING', 'RDATE', 'EXDATE'));
     } else {
         $ID = $arFields['ID'];
         $strUpdate = $DB->PrepareUpdate("b_calendar_event", $dbFields);
         $strSql = "UPDATE b_calendar_event SET " . $strUpdate . " WHERE ID=" . IntVal($arFields['ID']);
         $DB->QueryBind($strSql, array('DESCRIPTION' => $arFields['DESCRIPTION'], 'MEETING' => $arFields['MEETING'], 'RDATE' => $arFields['RDATE'], 'EXDATE' => $arFields['EXDATE']));
     }
     CTimeZone::Enable();
     if ($bNew && !isset($dbFields['DAV_XML_ID'])) {
         $strSql = "UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array('DAV_XML_ID' => $ID)) . " WHERE ID=" . IntVal($ID);
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     // Clean links
     // Del link from table
     if (!$bNew) {
         $arAffectedSections = CCalendarEvent::GetCurrentSectionIds($ID);
         $DB->Query("DELETE FROM b_calendar_event_sect WHERE EVENT_ID=" . IntVal($ID), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     } else {
         $arAffectedSections = array();
     }
     $strSections = "0";
     foreach ($arFields['SECTIONS'] as $sect) {
         if (IntVal($sect) > 0) {
             $strSections .= "," . IntVal($sect);
             $arAffectedSections[] = IntVal($sect);
         }
     }
     if (count($arAffectedSections) > 0) {
         CCalendarSect::UpdateModificationLabel($arAffectedSections);
     }
     // We don't have any section for this event
     // and we have to create default one.
     if ($strSections == "0") {
         $defCalendar = CCalendarSect::CreateDefault(array('type' => CCalendar::GetType(), 'ownerId' => CCalendar::GetOwnerId()));
         $strSections .= "," . IntVal($defCalendar['ID']);
     }
     // Add links
     $strSql = "INSERT INTO b_calendar_event_sect(EVENT_ID, SECT_ID) " . "SELECT " . intVal($ID) . ", ID " . "FROM b_calendar_section " . "WHERE ID in (" . $strSections . ")";
     $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     $bPull = CModule::IncludeModule("pull");
     if ($arFields['IS_MEETING']) {
         if (isset($arFields['ATTENDEES'])) {
             self::InviteAttendees($ID, $arFields, $arFields['ATTENDEES'], is_array($Params['attendeesStatuses']) ? $Params['attendeesStatuses'] : array(), $bSendInvitations, $userId);
             if ($bPull) {
                 // TODO: CACHE IT!
                 $attendees = self::GetAttendees($ID);
                 $attendees = $attendees[$ID];
                 foreach ($attendees as $user) {
                     CPullStack::AddByUser($user['USER_ID'], array('module_id' => 'calendar', 'command' => 'event_update', 'params' => array('EVENT' => CCalendarEvent::OnPullPrepareArFields($arFields), 'ATTENDEES' => $attendees, 'NEW' => $bNew ? 'Y' : 'N')));
                 }
             }
         }
     } else {
         if ($bPull) {
             CPullStack::AddByUser($userId, array('module_id' => 'calendar', 'command' => 'event_update', 'params' => array('EVENT' => CCalendarEvent::OnPullPrepareArFields($arFields), 'ATTENDEES' => array(), 'NEW' => $bNew ? 'Y' : 'N')));
         }
     }
     // Clean old reminders and add new reminders
     self::UpdateReminders(array('id' => $ID, 'reminders' => $arReminders, 'arFields' => $arFields, 'userId' => $userId, 'path' => $path, 'bNew' => $bNew));
     if ($arFields['CAL_TYPE'] == 'user' && $arFields['IS_MEETING'] && !empty($attendeesCodes)) {
         CCalendarLiveFeed::OnEditCalendarEventEntry($ID, $arFields, $attendeesCodes);
     }
     CCalendar::ClearCache('event_list');
     return $ID;
 }
コード例 #3
0
 public static function CanDo($operation, $sectId = 0, $userId = false)
 {
     global $USER;
     if (!isset($USER) || !$sectId) {
         return false;
     }
     if ($USER->CanDoOperation('edit_php')) {
         return true;
     }
     if ((CCalendar::GetType() == 'group' || CCalendar::GetType() == 'user') && CCalendar::IsSocNet() && CCalendar::IsSocnetAdmin()) {
         return true;
     }
     $res = in_array($operation, self::GetOperations($sectId, $userId));
     self::$bClearOperationCache = false;
     return $res;
 }