예제 #1
0
 public static function SaveSection($Params)
 {
     $type = isset($Params['arFields']['CAL_TYPE']) ? $Params['arFields']['CAL_TYPE'] : self::$type;
     // Exchange
     if ($Params['bAffectToDav'] !== false && CCalendar::IsExchangeEnabled(self::$ownerId) && $type == 'user') {
         $exchRes = true;
         $ownerId = isset($Params['arFields']['OWNER_ID']) ? $Params['arFields']['OWNER_ID'] : self::$ownerId;
         if (isset($Params['arFields']['ID']) && $Params['arFields']['ID'] > 0) {
             // Fetch section
             $oSect = CCalendarSect::GetById($Params['arFields']['ID']);
             // For exchange we change only calendar name
             if ($oSect && $oSect['IS_EXCHANGE'] && $oSect['DAV_EXCH_CAL'] && $oSect["NAME"] != $Params['arFields']['NAME']) {
                 $exchRes = CDavExchangeCalendar::DoUpdateCalendar($ownerId, $oSect['DAV_EXCH_CAL'], $oSect['DAV_EXCH_MOD'], $Params['arFields']);
             }
         } elseif ($Params['arFields']['IS_EXCHANGE']) {
             $exchRes = CDavExchangeCalendar::DoAddCalendar($ownerId, $Params['arFields']);
         }
         if ($exchRes !== true) {
             if (!is_array($exchRes) || !array_key_exists("XML_ID", $exchRes)) {
                 return CCalendar::ThrowError(CCalendar::CollectExchangeErrors($exchRes));
             }
             // // It's ok, we successfuly save event to exchange calendar - and save it to DB
             $Params['arFields']['DAV_EXCH_CAL'] = $exchRes['XML_ID'];
             $Params['arFields']['DAV_EXCH_MOD'] = $exchRes['MODIFICATION_LABEL'];
         }
     }
     // Save here
     $ID = CCalendarSect::Edit($Params);
     CCalendar::ClearCache(array('section_list', 'event_list'));
     return $ID;
 }
예제 #2
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;
 }