Example #1
0
 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);
 }
    private static function BuildDialogs($Params)
    {
        require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/tools/clock.php";
        $id = $Params['id'];
        ?>
<div id="<?php 
        echo $id;
        ?>
_dialogs_cont" style="display: none;"><?php 
        if (!$Params['bReadOnly']) {
            self::DialogAddEventSimple($Params);
            self::DialogEditSection($Params);
            self::DialogExternalCalendars($Params);
        }
        self::DialogSettings($Params);
        //self::DialogViewEvent($Params);
        self::DialogExportCalendar($Params);
        self::DialogMobileCon($Params);
        if ($Params['bShowSuperpose']) {
            self::DialogSuperpose($Params);
        }
        if (!$Params['bReadOnly'] && $Params['bSocNet']) {
            CCalendarPlanner::BuildDialog($Params);
        }
        ?>
</div><?php 
    }