protected static function plannerActionShow($arParams)
 {
     global $DB, $USER;
     $res = false;
     if ($arParams['ID'] > 0) {
         $event = self::getEvent(array('ID' => $arParams['ID'], 'SITE_ID' => $arParams['SITE_ID']));
         if ($event) {
             $today = ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT');
             $now = time();
             $res = array('ID' => $event['ID'], 'NAME' => $event['NAME'], 'DESCRIPTION' => CCalendarEvent::ParseText($event['DETAIL_TEXT'], $event['ID'], $event['UF_WEBDAV_CAL_EVENT']), 'URL' => '/company/personal/user/' . $USER->GetID() . '/calendar/?EVENT_ID=' . $event['ID'], 'DATE_FROM' => MakeTimeStamp($event['DATE_FROM']), 'DATE_TO' => MakeTimeStamp($event['DATE_TO']), 'STATUS' => $event['STATUS']);
             $res['DATE_FROM_TODAY'] = ConvertTimeStamp(MakeTimeStamp($res['DATE_FROM']), 'SHORT') == $today;
             $res['DATE_TO_TODAY'] = ConvertTimeStamp(MakeTimeStamp($res['DATE_TO']), 'SHORT') == $today;
             if ($res['DATE_FROM_TODAY']) {
                 if (IsAmPmMode()) {
                     $res['DATE_F'] = FormatDate("today g:i a", $res['DATE_FROM']);
                     $res['DATE_T'] = FormatDate("g:i a", $res['DATE_TO']);
                 } else {
                     $res['DATE_F'] = FormatDate("today H:i", $res['DATE_FROM']);
                     $res['DATE_T'] = FormatDate("H:i", $res['DATE_TO']);
                 }
                 if ($res['DATE_TO_TODAY']) {
                     $res['DATE_F'] .= ' - ' . $res['DATE_T'];
                 }
                 if ($res['DATE_FROM'] > $now) {
                     $res['DATE_F_TO'] = GetMessage('TM_IN') . ' ' . FormatDate('Hdiff', time() * 2 - ($res['DATE_FROM'] - CTimeZone::GetOffset()));
                 }
             } else {
                 if ($res['DATE_TO_TODAY']) {
                     $res['DATE_F'] = FormatDate(str_replace(array('#today#', '#time#'), array('today', 'H:i'), GetMessage('TM_TILL')), $res['DATE_TO']);
                 } else {
                     $fmt = preg_replace('/:s$/', '', $DB->DateFormatToPHP(CSite::GetDateFormat("FULL")));
                     $res['DATE_F'] = FormatDate($fmt, $res['DATE_FROM']);
                     $res['DATE_F_TO'] = FormatDate($fmt, $res['DATE_TO']);
                 }
             }
             if ($event['IS_MEETING'] == 'Y') {
                 $arGuests = array('Y' => array(), 'N' => array(), 'Q' => array());
                 foreach ($event['GUESTS'] as $key => $guest) {
                     $guest['url'] = str_replace(array('#ID#', '#USER_ID#'), $guest['id'], COption::GetOptionString('intranet', 'path_user', '/company/personal/user/#USER_ID#/', $arParams['SITE_ID']));
                     if ($guest['bHost']) {
                         $res['HOST'] = $guest;
                     } else {
                         $arGuests[$guest['status']][] = $guest;
                     }
                 }
                 $res['GUESTS'] = array_merge($arGuests['Y'], $arGuests['N'], $arGuests['Q']);
             }
             if (strlen($res['DESCRIPTION']) > 150) {
                 $res['DESCRIPTION'] = CUtil::closetags(substr($res['DESCRIPTION'], 0, 150)) . '...';
             }
             $res = array('EVENT' => $res);
         }
     } else {
         $res = array('error' => 'event not found');
     }
     return $res;
 }
示例#2
0
 public static function DoSaveToDav($Params = array(), &$arFields, $oCurEvent = false)
 {
     $sectionId = $Params['sectionId'];
     $bExchange = $Params['bExchange'];
     $bCalDav = $Params['bCalDav'];
     if (isset($oCurEvent['DAV_XML_ID'])) {
         $arFields['DAV_XML_ID'] = $oCurEvent['DAV_XML_ID'];
     }
     if (isset($oCurEvent['DAV_EXCH_LABEL'])) {
         $arFields['DAV_EXCH_LABEL'] = $oCurEvent['DAV_EXCH_LABEL'];
     }
     if (isset($oCurEvent['CAL_DAV_LABEL'])) {
         $arFields['CAL_DAV_LABEL'] = $oCurEvent['CAL_DAV_LABEL'];
     }
     $oSect = CCalendarSect::GetById($sectionId);
     if ($oCurEvent) {
         if ($oCurEvent['SECT_ID'] != $sectionId) {
             $bCalDavCur = CCalendar::IsCalDAVEnabled() && $oCurEvent['CAL_TYPE'] == 'user' && strlen($oCurEvent['CAL_DAV_LABEL']) > 0;
             $bExchangeEnabledCur = CCalendar::IsExchangeEnabled() && $oCurEvent['CAL_TYPE'] == 'user';
             if ($bExchangeEnabledCur || $bCalDavCur) {
                 $res = CCalendar::DoDeleteToDav(array('bCalDav' => $bCalDavCur, 'bExchangeEnabled' => $bExchangeEnabledCur, 'sectionId' => $oCurEvent['SECT_ID']), $oCurEvent);
                 if ($oCurEvent['DAV_EXCH_LABEL']) {
                     $oCurEvent['DAV_EXCH_LABEL'] = '';
                 }
                 if ($res !== true) {
                     return CCalendar::ThrowError($res);
                 }
             }
         }
     }
     $arDavFields = $arFields;
     CCalendarEvent::CheckFields($arDavFields);
     if ($arDavFields['RRULE'] != '') {
         $arDavFields['RRULE'] = $arFields['RRULE'];
     }
     $arDavFields['PROPERTY_LOCATION'] = $arDavFields['LOCATION']['NEW'];
     if ($arDavFields['PROPERTY_LOCATION'] !== '') {
         $arDavFields['PROPERTY_LOCATION'] = CCalendar::GetTextLocation($arDavFields['PROPERTY_LOCATION']);
     }
     $arDavFields['PROPERTY_IMPORTANCE'] = $arDavFields['IMPORTANCE'];
     $arDavFields['REMIND_SETTINGS'] = '';
     if ($arFields['REMIND'] && is_array($arFields['REMIND']) && is_array($arFields['REMIND'][0])) {
         $arDavFields['REMIND_SETTINGS'] = floatVal($arFields['REMIND'][0]['count']) . '_' . $arFields['REMIND'][0]['type'];
     }
     // **** Synchronize with CalDav ****
     if ($bCalDav && $oSect['CAL_DAV_CON'] > 0) {
         // New event or move existent event to DAV calendar
         if ($arFields['ID'] <= 0 || $oCurEvent && !$oCurEvent['CAL_DAV_LABEL']) {
             $DAVRes = CDavGroupdavClientCalendar::DoAddItem($oSect['CAL_DAV_CON'], $oSect['CAL_DAV_CAL'], $arDavFields);
         } else {
             // Edit existent event
             $DAVRes = CDavGroupdavClientCalendar::DoUpdateItem($oSect['CAL_DAV_CON'], $oSect['CAL_DAV_CAL'], $oCurEvent['DAV_XML_ID'], $oCurEvent['CAL_DAV_LABEL'], $arDavFields);
         }
         if (!is_array($DAVRes) || !array_key_exists("XML_ID", $DAVRes)) {
             return CCalendar::CollectCalDAVErros($DAVRes);
         }
         // // It's ok, we successfuly save event to caldav calendar - and save it to DB
         $arFields['DAV_XML_ID'] = $DAVRes['XML_ID'];
         $arFields['CAL_DAV_LABEL'] = $DAVRes['MODIFICATION_LABEL'];
     } elseif ($bExchange && $oSect['IS_EXCHANGE'] && strlen($oSect['DAV_EXCH_CAL']) > 0 && $oSect['DAV_EXCH_CAL'] !== 0) {
         $ownerId = $arFields['OWNER_ID'];
         $fromTo = CCalendarEvent::GetEventFromToForUser($arDavFields, $ownerId);
         $arDavFields["DATE_FROM"] = $fromTo['DATE_FROM'];
         $arDavFields["DATE_TO"] = $fromTo['DATE_TO'];
         // Convert BBcode to HTML for exchange
         $arDavFields["DESCRIPTION"] = CCalendarEvent::ParseText($arDavFields['DESCRIPTION']);
         // New event  or move existent event to Exchange calendar
         if ($arFields['ID'] <= 0 || $oCurEvent && !$oCurEvent['DAV_EXCH_LABEL']) {
             $exchRes = CDavExchangeCalendar::DoAddItem($ownerId, $oSect['DAV_EXCH_CAL'], $arDavFields);
         } else {
             $exchRes = CDavExchangeCalendar::DoUpdateItem($ownerId, $oCurEvent['DAV_XML_ID'], $oCurEvent['DAV_EXCH_LABEL'], $arDavFields);
         }
         if (!is_array($exchRes) || !array_key_exists("XML_ID", $exchRes)) {
             return CCalendar::CollectExchangeErrors($exchRes);
         }
         // It's ok, we successfuly save event to exchange calendar - and save it to DB
         $arFields['DAV_XML_ID'] = $exchRes['XML_ID'];
         $arFields['DAV_EXCH_LABEL'] = $exchRes['MODIFICATION_LABEL'];
     }
     return true;
 }