Beispiel #1
0
 function SaveCalendar($arParams)
 {
     $iblockId = isset($arParams['iblockId']) ? $arParams['iblockId'] : $this->iblockId;
     $ownerId = isset($arParams['ownerId']) ? $arParams['ownerId'] : $this->ownerId;
     $ownerType = isset($arParams['ownerType']) ? $arParams['ownerType'] : $this->ownerType;
     $sectionId = isset($arParams['sectionId']) ? $arParams['sectionId'] : $this->sectionId;
     $arFields = $arParams['arFields'];
     global $DB;
     if ($sectionId === 'none') {
         $sectionId = $this->CreateSectionForOwner($ownerId, $ownerType, $iblockId);
         // Creating section for owner
         if ($sectionId === false) {
             return false;
         } else {
             $this->UpdateSectionId($sectionId);
         }
         $this->newSectionId = $sectionId;
     }
     $ID = $arFields['ID'];
     $DB->StartTransaction();
     $bs = new CIBlockSection();
     if ($ownerType != 'USER' && $ownerType != 'GROUP') {
         $ownerType = '';
     }
     $key_color = "UF_" . $ownerType . "_CAL_COL";
     $key_export = "UF_" . $ownerType . "_CAL_EXP";
     $key_status = "UF_" . $ownerType . "_CAL_STATUS";
     $EXPORT = $arFields['EXPORT'] ? $arFields['EXPORT_SET'] : '';
     $arFields = array("ACTIVE" => "Y", "IBLOCK_SECTION_ID" => $sectionId, "IBLOCK_ID" => $iblockId, "NAME" => $arFields['NAME'], "DESCRIPTION" => $arFields['DESCRIPTION'], $key_color => $arFields['COLOR'], $key_export => $EXPORT, $key_status => $arFields['PRIVATE_STATUS'], 'IS_EXCHANGE' => $arFields['IS_EXCHANGE']);
     $GLOBALS[$key_color] = $COLOR;
     $GLOBALS[$key_export] = $EXPORT;
     $GLOBALS[$key_status] = $arFields['PRIVATE_STATUS'];
     $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $iblockId . "_SECTION", $arFields);
     // Exchange
     if (CEventCalendar::IsExchangeEnabled() && $ownerType == 'USER') {
         $exchRes = true;
         if (isset($ID) && $ID > 0) {
             $calendarXmlId = CECCalendar::GetExchangeXmlId($iblockId, $ID, $ownerType);
             if (strlen($calendarXmlId) > 0 && $calendarXmlId !== 0) {
                 $calendarModLabel = CECCalendar::GetExchModLabel($iblockId, $ID);
                 $exchRes = CDavExchangeCalendar::DoUpdateCalendar($ownerId, $calendarXmlId, $calendarModLabel, $arFields);
             }
         } else {
             if ($arFields['IS_EXCHANGE']) {
                 $exchRes = CDavExchangeCalendar::DoAddCalendar($ownerId, $arFields);
             }
         }
         unset($arFields['IS_EXCHANGE']);
         if ($exchRes !== true) {
             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['UF_BXDAVEX_EXCH'] = $exchRes['XML_ID'];
             $arFields['UF_BXDAVEX_EXCH_LBL'] = $exchRes['MODIFICATION_LABEL'];
         }
     }
     if ($ownerType == 'GROUP' && $ownerId > 0) {
         $arFields['SOCNET_GROUP_ID'] = $ownerId;
     }
     if (isset($ID) && $ID > 0) {
         $res = $bs->Update($ID, $arFields);
     } else {
         $ID = $bs->Add($arFields);
         $res = $ID > 0;
         if ($res) {
             //This sets appropriate owner if section created by owner of the meeting
             //and this calendar belongs to guest which is not current user
             if ($ownerType == 'USER' && $ownerId > 0) {
                 $DB->Query("UPDATE b_iblock_section SET CREATED_BY = " . intval($ownerId) . " WHERE ID = " . intval($ID));
             }
         }
     }
     if (!$res) {
         $DB->Rollback();
         return false;
     }
     $DB->Commit();
     return $ID;
 }