Esempio n. 1
0
    function SaveEvent($arParams)
    {
        global $DB;
        $iblockId = $arParams['iblockId'];
        $ownerType = $arParams['ownerType'];
        $ownerId = $arParams['ownerId'];
        $bCheckPermissions = $arParams["bCheckPermissions"] !== false;
        $calendarId = intVal($arParams['calendarId']);
        $sectionId = $arParams['sectionId'];
        $fullUrl = $arParams['fullUrl'];
        $userId = $arParams['userId'];
        $bIsInvitingEvent = $arParams['isMeeting'] && intval($arParams['prop']['PARENT']) > 0;
        $bExchange = CEventCalendar::IsExchangeEnabled() && $ownerType == 'USER';
        $bCalDav = CEventCalendar::IsCalDAVEnabled() && $ownerType == 'USER';
        if (!$bIsInvitingEvent) {
            // *** ADD MEETING ROOM ***
            $loc_old = CEventCalendar::ParseLocation($arParams['location']['old']);
            $loc_new = CEventCalendar::ParseLocation($arParams['location']['new']);
            if ($loc_old['mrid'] !== false && $loc_old['mrevid'] !== false && ($loc_old['mrid'] !== $loc_new['mrid'] || $arParams['location'])) {
                if ($loc_old['mrid'] == $arParams['VMiblockId']) {
                    CEventCalendar::ReleaseVR(array('mrevid' => $loc_old['mrevid'], 'mrid' => $loc_old['mrid'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting']));
                } else {
                    CEventCalendar::ReleaseMR(array('mrevid' => $loc_old['mrevid'], 'mrid' => $loc_old['mrid'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting']));
                }
            }
            if ($loc_new['mrid'] !== false) {
                if ($loc_new['mrid'] == $arParams['VMiblockId']) {
                    $mrevid = CEventCalendar::ReserveVR(array('mrid' => $loc_new['mrid'], 'dateFrom' => $arParams['dateFrom'], 'dateTo' => $arParams['dateTo'], 'name' => $arParams['name'], 'description' => GetMessage('EC_RESERVE_FOR_EVENT') . ': ' . $arParams['name'], 'persons' => count($arParams['guests']), 'members' => $arParams['guests'], 'regularity' => $arParams['prop']['PERIOD_TYPE'], 'regularity_count' => $arParams['prop']['PERIOD_COUNT'], 'regularity_length' => $arParams['prop']['EVENT_LENGTH'], 'regularity_additional' => $arParams['prop']['PERIOD_ADDITIONAL'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting']));
                } else {
                    $mrevid = CEventCalendar::ReserveMR(array('mrid' => $loc_new['mrid'], 'dateFrom' => $arParams['dateFrom'], 'dateTo' => $arParams['dateTo'], 'name' => $arParams['name'], 'description' => GetMessage('EC_RESERVE_FOR_EVENT') . ': ' . $arParams['name'], 'persons' => $arParams['isMeeting'] && count($arParams['guests']) > 0 ? count($arParams['guests']) : 1, 'regularity' => $arParams['prop']['PERIOD_TYPE'], 'regularity_count' => $arParams['prop']['PERIOD_COUNT'], 'regularity_length' => $arParams['prop']['EVENT_LENGTH'], 'regularity_additional' => $arParams['prop']['PERIOD_ADDITIONAL'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting']));
                }
                if ($mrevid && $mrevid != 'reserved' && $mrevid != 'expire' && $mrevid > 0) {
                    $loc_new = 'ECMR_' . $loc_new['mrid'] . '_' . $mrevid;
                    $arParams["prop"]['LOCATION'] = $loc_new;
                } else {
                    $arParams["prop"]['LOCATION'] = '';
                    if ($mrevid == 'reserved') {
                        $loc_new = 'bxec_error_reserved';
                    } elseif ($mrevid == 'expire') {
                        $loc_new = 'bxec_error_expire';
                    } else {
                        $loc_new = 'bxec_error';
                    }
                }
            } else {
                $loc_new = $loc_new['str'];
                $arParams["prop"]['LOCATION'] = $loc_new;
            }
        }
        //$bSocNetLog = (!isset($arParams['bSocNetLog']) || $arParams['bSocNetLog'] != false) && !$arParams["prop"]["PRIVATE"];
        //if(cmodule::includemodule('security'))
        if (CModule::IncludeModule("security")) {
            $filter = new CSecurityFilter();
            $arParams['desc'] = $filter->TestXSS($arParams['desc'], 'replace');
        } else {
            $arParams['desc'] = htmlspecialcharsex($arParams['desc']);
        }
        if ($calendarId > 0) {
            //cheking permissions and correct nesting
            //if (!CEventCalendar::CheckCalendar(array('iblockId' => $iblockId, 'ownerId' => $ownerId, 'ownerType' => $ownerType, 'calendarId' => $calendarId, 'sectionId' => $sectionId)))
            //	return CEventCalendar::ThrowError(GetMessage('EC_CALENDAR_CREATE_ERROR').' '.GetMessage('EC_CAL_INCORRECT_ERROR'));
        } else {
            // Creating default calendar section for owner
            $bDisplayCalendar = !$arParams["notDisplayCalendar"];
            // Output js with calendar description
            $newSectionId = 'none';
            // by reference
            $calendarId = CECCalendar::CreateDefault(array('ownerType' => $ownerType, 'ownerId' => $ownerId, 'iblockId' => $iblockId, 'sectionId' => $sectionId), $bDisplayCalendar, $newSectionId);
            if (!$calendarId) {
                return CEventCalendar::ThrowError('2' . GetMessage('EC_CALENDAR_CREATE_ERROR'));
            }
            if ($newSectionId != 'none') {
                $arParams['sectionId'] = $newSectionId;
            }
        }
        $arParams['calendarId'] = $calendarId;
        if ($bIsInvitingEvent && !isset($arParams["CONFIRMED"]) && isset($arParams["status"])) {
            $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, $arParams["status"]);
        } else {
            if ($arParams["CONFIRMED"] == "Q") {
                $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, "Q");
            } elseif ($arParams["CONFIRMED"] == "Y") {
                $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, "Y");
            } else {
                unset($arParams["prop"]["CONFIRMED"]);
            }
        }
        if (isset($arParams["remind"])) {
            if ($arParams["remind"] !== false) {
                $arParams["prop"]["REMIND_SETTINGS"] = $arParams["remind"]['count'] . '_' . $arParams["remind"]['type'];
            } else {
                if (!$arParams['bNew']) {
                    $arParams["prop"]["REMIND_SETTINGS"] = '';
                }
            }
        }
        if (!isset($arParams['prop']['VERSION'])) {
            if (!$arParams['bNew']) {
                $dbProp = CIBlockElement::GetProperty($iblockId, $arParams['id'], 'sort', 'asc', array('CODE' => 'VERSION'));
                if ($arProp = $dbProp->Fetch()) {
                    $arParams['prop']['VERSION'] = intval($arProp['VALUE']);
                }
            }
            if ($arParams['prop']['VERSION'] <= 0) {
                $arParams['prop']['VERSION'] = 1;
            }
            $arParams['prop']['VERSION']++;
        }
        if ($arParams['isMeeting']) {
            $arParams['prop']['IS_MEETING'] = 'Y';
        }
        if (!$bIsInvitingEvent) {
            $arParams['prop']['HOST_IS_ABSENT'] = $arParams['isMeeting'] && !in_array($userId, $arParams['guests']) ? 'Y' : 'N';
            if ($arParams['isMeeting'] && strlen($arParams['meetingText'])) {
                $arParams['prop']['MEETING_TEXT'] = array('VALUE' => array("TYPE" => 'text', "TEXT" => $arParams['meetingText']));
            }
        }
        $arFields = array("ACTIVE" => "Y", "IBLOCK_SECTION" => $calendarId, "IBLOCK_ID" => $iblockId, "NAME" => $arParams['name'], "ACTIVE_FROM" => $arParams['dateFrom'], "ACTIVE_TO" => $arParams['dateTo'], "DETAIL_TEXT" => $arParams['desc'], "DETAIL_TEXT_TYPE" => 'html', "MODIFIED_BY" => $GLOBALS['USER']->GetID(), "PROPERTY_VALUES" => $arParams['prop']);
        if ($ownerType == 'GROUP' && $ownerId > 0) {
            $arFields['SOCNET_GROUP_ID'] = $ownerId;
        }
        if ($bExchange || $bCalDav) {
            foreach ($arFields["PROPERTY_VALUES"] as $prKey => $prVal) {
                $arFields["PROPERTY_" . $prKey] = $prVal;
            }
        }
        // If it's EXCHANGE - we try to save event to exchange
        if ($bExchange) {
            $calendarXmlId = CECCalendar::GetExchangeXmlId($iblockId, $calendarId);
            if (strlen($calendarXmlId) > 0 && $calendarXmlId !== 0) {
                if ($arParams['bNew']) {
                    $exchRes = CDavExchangeCalendar::DoAddItem($ownerId, $calendarXmlId, $arFields);
                } else {
                    $eventModLabel = CECEvent::GetExchModLabel($iblockId, $arParams['id']);
                    $eventXmlId = CECEvent::GetExchangeXmlId($iblockId, $arParams['id']);
                    $exchRes = CDavExchangeCalendar::DoUpdateItem($ownerId, $eventXmlId, $eventModLabel, $arFields);
                }
                if (!is_array($exchRes) || !array_key_exists("XML_ID", $exchRes)) {
                    return CEventCalendar::ThrowError(CEventCalendar::CollectExchangeErros($exchRes));
                }
                // It's ok, we successfuly save event to exchange calendar - and save it to DB
                $arFields['XML_ID'] = $exchRes['XML_ID'];
                $arFields['PROPERTY_VALUES']['BXDAVEX_LABEL'] = $exchRes['MODIFICATION_LABEL'];
            }
        }
        if ($bCalDav) {
            $connectionId = CECCalendar::GetCalDAVConnectionId($iblockId, $calendarId);
            if ($connectionId > 0) {
                $calendarCalDAVXmlId = CECCalendar::GetCalDAVXmlId($iblockId, $calendarId);
                if ($arParams['bNew']) {
                    $DAVRes = CDavGroupdavClientCalendar::DoAddItem($connectionId, $calendarCalDAVXmlId, $arFields);
                } else {
                    $eventCalDAVModLabel = CECEvent::GetCalDAVModLabel($iblockId, $arParams['id']);
                    $eventXmlId = CECEvent::GetExchangeXmlId($iblockId, $arParams['id']);
                    $DAVRes = CDavGroupdavClientCalendar::DoUpdateItem($connectionId, $calendarCalDAVXmlId, $eventXmlId, $eventCalDAVModLabel, $arFields);
                }
                if (!is_array($DAVRes) || !array_key_exists("XML_ID", $DAVRes)) {
                    return CEventCalendar::ThrowError(CEventCalendar::CollectCalDAVErros($DAVRes));
                }
                // // It's ok, we successfuly save event to caldav calendar - and save it to DB
                $arFields['XML_ID'] = $DAVRes['XML_ID'];
                $arFields['PROPERTY_VALUES']['BXDAVCD_LABEL'] = $DAVRes['MODIFICATION_LABEL'];
            }
        }
        $bs = new CIBlockElement();
        $res = false;
        if (!$arParams['bNew']) {
            $ID = $arParams['id'];
            if ($ID > 0) {
                $res = $bs->Update($ID, $arFields, false);
            }
        } else {
            //This sets appropriate owner if event created by owner of the meeting and this calendar belongs to guest which is not current user
            if ($ownerType == 'USER' && $ownerId > 0 && $userId != $ownerId) {
                $arFields['CREATED_BY'] = $ownerId;
            }
            $ID = $bs->Add($arFields, false);
            $res = $ID > 0;
        }
        if ($arParams['isMeeting'] && !$bIsInvitingEvent) {
            $this->CheckParentProperty($arParams['userIblockId'], $iblockId);
            $arGuestConfirm = $this->InviteGuests($ID, $arFields, $arParams['guests'], $arParams);
        }
        if (!$res) {
            return CEventCalendar::ThrowError('4' . $bs->LAST_ERROR);
        } else {
            CIBlockElement::RecalcSections($ID);
        }
        if (!$bPeriodic && !$arParams["notDisplayCalendar"]) {
            if ($arParams['bNew']) {
                ?>
<script>window._bx_new_event = {ID: <?php 
                echo $ID;
                ?>
, IBLOCK_ID: '<?php 
                echo $iblockId;
                ?>
', LOC: '<?php 
                echo CUtil::JSEscape($loc_new);
                ?>
', arGuestConfirm: <?php 
                echo CUtil::PhpToJSObject($arGuestConfirm);
                ?>
};</script><?php 
            } else {
                ?>
<script>window._bx_existent_event = {ID: <?php 
                echo intVal($ID);
                ?>
, NAME : '<?php 
                echo CUtil::JSEscape($arParams['name']);
                ?>
', DETAIL_TEXT: '<?php 
                echo CUtil::JSEscape($arParams['desc']);
                ?>
', DATE_FROM : '<?php 
                echo $arParams['dateFrom'];
                ?>
', DATE_TO : '<?php 
                echo $arParams['dateTo'];
                ?>
', LOC: '<?php 
                echo CUtil::JSEscape($loc_new);
                ?>
', arGuestConfirm: <?php 
                echo CUtil::PhpToJSObject($arGuestConfirm);
                ?>
};</script>
<?php 
            }
        }
        $this->ClearCache($this->cachePath . 'events/' . $iblockId . '/');
        if ($bSocNetLog && $ownerType) {
            CEventCalendar::SocNetLog(array('iblockId' => $iblockId, 'ownerType' => $ownerType, 'ownerId' => $ownerId, 'target' => $arParams['bNew'] ? 'add_event' : 'edit_event', 'id' => $ID, 'name' => $arParams['name'], 'desc' => $arParams['desc'], 'from' => $arParams['dateFrom'], 'to' => $arParams['dateTo'], 'calendarId' => $calendarId, 'accessibility' => $arParams["prop"]["ACCESSIBILITY"], 'importance' => $arParams["prop"]["IMPORTANCE"], 'pathToGroupCalendar' => $arParams["pathToGroupCalendar"], 'pathToUserCalendar' => $arParams["pathToUserCalendar"]));
        }
        if (array_key_exists("remind", $arParams)) {
            CECEvent::AddReminder(array('iblockId' => $iblockId, 'ownerType' => $ownerType, 'ownerId' => $ownerId, 'userId' => $userId, 'fullUrl' => $fullUrl, 'id' => $ID, 'dateFrom' => $arParams['dateFrom'], 'remind' => $arParams["remind"], 'bNew' => $arParams['bNew']));
        }
        return $ID;
    }
Esempio n. 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) {
             $bCalDav = CCalendar::IsCalDAVEnabled() && $oCurEvent['CAL_TYPE'] == 'user' && strlen($oCurEvent['CAL_DAV_LABEL']) > 0;
             $bExchangeEnabled = CCalendar::IsExchangeEnabled() && $oCurEvent['CAL_TYPE'] == 'user';
             if ($bExchangeEnabled || $bCalDav) {
                 $res = CCalendar::DoDeleteToDav(array('bCalDav' => $bCalDav, 'bExchangeEnabled' => $bExchangeEnabled, 'sectionId' => $oCurEvent['SECT_ID']), $oCurEvent);
                 if ($res !== true) {
                     return CCalendar::ThrowError($res);
                 }
             }
         }
     }
     $fromTs = CCalendar::Timestamp($arFields['DT_FROM']);
     $toTs = CCalendar::Timestamp($arFields['DT_TO']);
     if (!isset($arFields['DT_FROM_TS'])) {
         $arFields['DT_FROM_TS'] = $fromTs;
     }
     if (!isset($arFields['DT_TO_TS'])) {
         $arFields['DT_TO_TS'] = $toTs;
     }
     $arDavFields = $arFields;
     CCalendarEvent::CheckFields($arDavFields);
     if ($arDavFields['RRULE'] != '') {
         $arDavFields['RRULE'] = $arFields['RRULE'];
     }
     $arDavFields['DETAIL_TEXT'] = $arDavFields['DESCRIPTION'];
     $arDavFields['DETAIL_TEXT_TYPE'] = 'text';
     $arDavFields['ACTIVE_FROM'] = $arDavFields['DT_FROM'];
     $arDavFields['ACTIVE_TO'] = $arDavFields['DT_TO'];
     $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'];
     }
     // RRULE
     $arDavFields['PROPERTY_PERIOD_TYPE'] = 'NONE';
     if (is_array($arFields['RRULE']) && isset($arFields['RRULE']['FREQ']) && in_array($arFields['RRULE']['FREQ'], array('HOURLY', 'DAILY', 'MONTHLY', 'YEARLY', 'WEEKLY'))) {
         $arDavFields['PROPERTY_PERIOD_TYPE'] = $arFields['RRULE']['FREQ'];
         // Interval
         $arDavFields['PROPERTY_PERIOD_COUNT'] = isset($arFields['RRULE']['INTERVAL']) && intVal($arFields['RRULE']['INTERVAL']) > 1 ? intVal($arFields['RRULE']['INTERVAL']) : 1;
         if ($arFields['RRULE']['FREQ'] == 'WEEKLY' && isset($arFields['RRULE']['BYDAY'])) {
             //PROPERTY_PERIOD_ADDITIONAL
             $BYDAYS = array();
             $days = array('SU' => 0, 'MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6);
             $bydays = explode(',', $arFields['RRULE']['BYDAY']);
             foreach ($bydays as $day) {
                 $BYDAYS[] = $days[$day];
             }
             $arDavFields['PROPERTY_PERIOD_ADDITIONAL'] = implode(',', $BYDAYS);
         }
         $h24 = 60 * 60 * 24;
         if ($fromTs == $toTs) {
             $arDavFields['PROPERTY_EVENT_LENGTH'] = $h24;
         } else {
             $arDavFields['PROPERTY_EVENT_LENGTH'] = intVal($toTs - $fromTs);
             if ($arDavFields['PROPERTY_EVENT_LENGTH'] % $h24 == 0) {
                 // We have dates without times
                 $arDavFields['PROPERTY_EVENT_LENGTH'] += $h24;
             }
         }
         // Until date
         if (isset($arFields['RRULE']['UNTIL'])) {
             $periodTs = $arFields['RRULE']['UNTIL'];
         } else {
             $periodTs = CCalendar::GetMaxTimestamp();
         }
         $arDavFields['ACTIVE_TO'] = CCalendar::Date($periodTs);
     }
     // **** 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'];
         // 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;
 }
Esempio n. 3
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;
 }