/**
  * @param $data
  * @param null $dbVersion
  * @throws \Exception
  * @return ApplyResult
  */
 public function applySnapshot($data, $dbVersion = null)
 {
     $data = $this->handleNullValues($data);
     $sec = new \CIBlockSection();
     $res = new ApplyResult();
     $extId = $data['ID'];
     if ($dbVersion) {
         $data['IBLOCK_ID'] = $this->getReferenceController()->getCurrentIdByOtherVersion($data['IBLOCK_ID'], ReferenceController::GROUP_IBLOCK, $dbVersion);
         $data['IBLOCK_SECTION_ID'] && ($data['IBLOCK_SECTION_ID'] = $this->getCurrentVersionId($data['IBLOCK_SECTION_ID'], $dbVersion));
         $id = $this->getCurrentVersionId($extId, $dbVersion);
     } else {
         $id = $extId;
     }
     if (!$dbVersion && !SectionTable::getList(array('filter' => array('=ID' => $id)))->fetch()) {
         $addRes = SectionTable::add(array('ID' => $id, 'IBLOCK_ID' => $data['IBLOCK_ID'], 'TIMESTAMP_X' => new DateTime(), 'NAME' => $data['NAME'], 'DESCRIPTION_TYPE' => $data['DESCRIPTION_TYPE']));
         if (!$addRes->isSuccess()) {
             throw new \Exception('Не удалось возобновить секцию(раздел) текущей версии. ' . implode(', ', $addRes->getErrorMessages()) . "\n" . var_export($data, true));
         }
     }
     unset($data['CREATED_BY'], $data['MODIFIED_BY']);
     if ($id && ($currentData = SectionTable::getById($id)->fetch())) {
         $data['PICTURE'] = $currentData['PICTURE'];
         $data['DETAIL_PICTURE'] = $currentData['DETAIL_PICTURE'];
         $res->setSuccess((bool) $sec->Update($id, $data));
     } else {
         unset($data['PICTURE'], $data['DETAIL_PICTURE']);
         $res->setSuccess((bool) ($id = $sec->Add($data)));
         $this->registerCurrentVersionId($id, $this->getReferenceValue($extId, $dbVersion));
     }
     $res->setId($id);
     $res->setMessage($sec->LAST_ERROR);
     return $res;
 }
Exemplo n.º 2
0
 public static function Add(&$arFields)
 {
     if (!CModule::IncludeModule('iblock')) {
         return false;
     }
     if (!(isset($arFields['NAME']) && is_string($arFields['NAME']) && $arFields['NAME'] !== '')) {
         self::$LAST_ERROR_CODE = self::ERR_SECTION_NAME_EMPTY;
         self::$LAST_ERROR = GetMessage('CRM_PRODUCT_SECTION_ERR_SECTION_NAME_EMPTY');
         return false;
     }
     $catalogID = isset($arFields['CATALOG_ID']) ? intval($arFields['CATALOG_ID']) : 0;
     if (!($catalogID > 0 && CCrmCatalog::Exists($catalogID))) {
         $catalogID = CCrmCatalog::EnsureDefaultExists();
     }
     $arFields['CATALOG_ID'] = $catalogID;
     $sectionFields = CCrmProductSectionDbResult::MapKeys($arFields);
     $sectionFields['CHECK_PERMISSIONS'] = 'N';
     $section = new CIBlockSection();
     $result = $section->Add($sectionFields);
     if (!(is_int($result) && $result > 0)) {
         self::$LAST_ERROR_CODE = self::ERR_IBLOCK_SECTION_ADD;
         self::$LAST_ERROR = $section->LAST_ERROR;
     }
     return $result;
 }
Exemplo n.º 3
0
 static function createSection($name, $code, $parent_id = false)
 {
     $bs = new CIBlockSection();
     $arFields = array("ACTIVE" => "Y", "CODE" => $code, "IBLOCK_SECTION_ID" => $parent_id, "IBLOCK_ID" => self::$IBLOCK_ID, "NAME" => $name, "SORT" => 500, "PICTURE" => "", "DESCRIPTION" => "", "DESCRIPTION_TYPE" => "html");
     $result_id = $bs->Add($arFields);
     return $result_id;
 }
 function AddCategory($NAME, $PARENT_ID)
 {
     $iblock_permission = CIBlock::GetPermission(IBLOCK_ID);
     if ($iblock_permission < "W") {
         $GLOBALS["USER"]->RequiredHTTPAuthBasic();
         return new CSOAPFault('Server Error', 'Unable to authorize user.');
     }
     $code = self::translit($NAME);
     $i = 1;
     while (true) {
         $res = CIBlockSection::Getlist(array(), array("CODE" => $code), false, array("CODE"));
         if ($res->Fetch()) {
             $code = self::translit($NAME) . $i;
         } else {
             break;
         }
         $i++;
     }
     $arFields = array("ACTIVE" => "Y", "NAME" => $NAME, "IBLOCK_SECTION_ID" => $PARENT_ID, "IBLOCK_ID" => IBLOCK_ID, "CODE" => $code);
     $ib_section = new CIBlockSection();
     $result = $ib_section->Add($arFields);
     if ($result > 0) {
         CIBlockSection::ReSort();
         return $result;
     }
     return new CSOAPFault('Server Error', 'Error: ' . $ib_section->LAST_ERROR);
 }
Exemplo n.º 5
0
 static function onBeforeElementAddHandler($arFields)
 {
     $IBLOCK_ID = Config\Option::get("citfact.replaceurl", "IBLOCK_ID", "");
     $SECTION_ID = Config\Option::get("citfact.replaceurl", "SECTION_BREND_ID", "BRENDI");
     $CODE_PROP = Config\Option::get("citfact.replaceurl", "PROPERTY_CODE_BRENDI", "BRENDI");
     if ($IBLOCK_ID == $arFields["IBLOCK_ID"]) {
         $propertyBrand = \CIBlockProperty::GetByID($CODE_PROP, $arFields["IBLOCK_ID"]);
         if ($arResultProperty = $propertyBrand->GetNext()) {
             $propertyBrandValue = \CIBlockPropertyEnum::GetByID($arFields["PROPERTY_VALUES"][$arResultProperty["ID"]][0]["VALUE"]);
         }
         $rqParentSection = \CIBlockSection::GetByID($SECTION_ID);
         if ($arParentSection = $rqParentSection->GetNext()) {
             $arFilter = array('IBLOCK_ID' => $arParentSection['IBLOCK_ID'], '>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'], '<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'], '>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']);
             // выберет потомков без учета активности
             $rqSectChild = \CIBlockSection::GetList(array('left_margin' => 'asc'), $arFilter);
             while ($arSectChild = $rqSectChild->GetNext()) {
                 $arSections[$arSectChild["NAME"]] = $arSectChild["ID"];
             }
         }
         if (array_key_exists($propertyBrandValue["VALUE"], $arSections)) {
             $arFields["IBLOCK_SECTION"][] = $arSections[$propertyBrandValue["VALUE"]];
         } else {
             $arParams = array("replace_space" => "-", "replace_other" => "-");
             $trans = \Cutil::translit($propertyBrandValue["VALUE"], "ru", $arParams);
             $bs = new \CIBlockSection();
             $arFieldsNewSection = array("ACTIVE" => "Y", "IBLOCK_SECTION_ID" => $SECTION_ID, "IBLOCK_ID" => $IBLOCK_ID, "NAME" => $propertyBrandValue["VALUE"], "CODE" => $trans);
             $resultAdd = $bs->Add($arFieldsNewSection);
             $arFields["IBLOCK_SECTION"][] = $resultAdd;
         }
     }
     return true;
 }
Exemplo n.º 6
0
 function __wd_get_root_section($IBLOCK_ID, $object, $object_id)
 {
     $result = CIBlockWebdavSocnet::GetSectionID($IBLOCK_ID, $object, $object_id);
     if (intval($result) > 0) {
         return $result;
     } else {
         __wd_check_uf_use_bp_property($arParams["IBLOCK_ID"]);
         $arFields = array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y", "SOCNET_GROUP_ID" => false, "IBLOCK_SECTION_ID" => 0, "UF_USE_BP" => "N");
         if ($object == "user") {
             $dbUser = CUser::GetByID($object_id);
             $arUser = $dbUser->Fetch();
             $arFields["NAME"] = trim($arUser['LAST_NAME'] . " " . $arUser['FIRST_NAME']);
             $arFields["NAME"] = trim(!empty($arFields["NAME"]) ? $arFields["NAME"] : $arUser['LOGIN']);
             $arFields['CREATED_BY'] = $arUser['ID'];
             $arFields['MODIFIED_BY'] = $arUser['ID'];
             if (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E") {
                 $arTasks = CWebDavIblock::GetTasks();
                 $arFields['RIGHTS'] = array('n0' => array('GROUP_CODE' => 'U' . $object_id, 'TASK_ID' => $arTasks['X']));
             }
         } else {
             /*		$res = CSocNetGroup::GetByID($arResult["VARIABLES"]["group_id"]);
             				if (!$res)
             				{
             					$arParams["ERROR_MESSAGE"] = GetMessage("SONET_GROUP_NOT_EXISTS");
             					return 0;
             				} */
             $arFields["SOCNET_GROUP_ID"] = $object_id;
             //$arGroup = CSocNetGroup::GetByID($object_id);
             $arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $object_id;
             $dbGroup = CSocNetGroup::GetList(array(), array("ID" => (int) $object_id), false, false, array("ID", "SITE_ID", "NAME"));
             if ($arGroup = $dbGroup->Fetch()) {
                 $arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $arGroup["NAME"];
             }
             if (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E") {
                 $arTasks = CWebDavIblock::GetTasks();
                 $arFields['RIGHTS'] = array('n0' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_A', 'TASK_ID' => $arTasks['X']), 'n1' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_E', 'TASK_ID' => $arTasks['W']), 'n2' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_K', 'TASK_ID' => $arTasks['W']));
             }
         }
         if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk')) {
             \Bitrix\Disk\Driver::getInstance()->addGroupStorage($arFields["SOCNET_GROUP_ID"]);
         }
         $GLOBALS["UF_USE_BP"] = $arFields["UF_USE_BP"];
         $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $IBLOCK_ID . "_SECTION", $arFields);
         $bs = new CIBlockSection();
         $sectionID = $bs->Add($arFields);
         if (!$sectionID) {
             $arParams["ERROR_MESSAGE"] = $bs->LAST_ERROR;
             return 0;
         }
         WDClearComponentCache(array("webdav.element.edit", "webdav.element.hist", "webdav.element.upload", "webdav.element.view", "webdav.menu", "webdav.section.edit", "webdav.section.list"));
         return true;
         /*
         	if ($ob->workflow == 'bizproc')
         	{
         		__wd_create_default_bp_user_and_groups($arBizProcParameters);
         	}
         */
     }
 }
 public function testAdd()
 {
     $this->_injectDutyCollector();
     $ibType = \CIBlockType::GetList()->Fetch();
     $ib = new \CIBlock();
     $ibId = $ib->Add(array('IBLOCK_TYPE_ID' => $ibType['ID'], 'NAME' => 'New Iblock', 'SITE_ID' => 's1'));
     $this->assertNotEmpty($ibId, $this->errorMessage('not create iblock id', array(':lastError' => $ib->LAST_ERROR)));
     $prop = new \CIBlockProperty();
     $propId = $prop->Add(array('IBLOCK_ID' => $ibId, 'CODE' => 'propCode', 'NAME' => 'Property NAME'));
     $this->assertNotEmpty($propId, $this->errorMessage('not create property iblock id', array(':lastError' => $ib->LAST_ERROR)));
     $sec = new \CIBlockSection();
     $secId = $sec->Add(array('IBLOCK_ID' => $ibId, 'NAME' => 'Iblock Section'));
     $this->assertNotEmpty($secId, $this->errorMessage('not create section iblock id', array(':lastError' => $ib->LAST_ERROR)));
     // ¬ итоге должны получитс¤
     // данные по добавлению »Ѕ
     $this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockHandler::className()));
     // данные по добавлению свойства
     $this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockPropertyHandler::className()));
     // данные по добавлению секции
     $this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockSectionHandler::className()));
     $refFixes = $this->_getCollectorFixes('reference');
     // фиксаци¤ изменений
     Module::getInstance()->commitDutyChanges();
     // добавлены записи журнала обновлений (в базу)
     /** @var $logRecords AppliedChangesLogModel[] */
     $logRecords = AppliedChangesLogModel::find(array('order' => array('id' => 'desc'), 'limit' => 10));
     $this->assertTrue(count($logRecords) > 3);
     $iterationsCount = 0;
     foreach ($logRecords as $logRecord) {
         if ($logRecord->processName == Module::SPECIAL_PROCESS_FIX_REFERENCE) {
             continue;
         }
         if ($logRecord->processName != AddProcess::className()) {
             $this->throwError($this->errorMessage('last log records need been update process'), $logRecord->processName);
         }
         if (++$iterationsCount > 3) {
             break;
         }
         $data = $logRecord->updateData;
         switch ($logRecord->subjectName) {
             case IblockHandler::className():
                 (!$data['iblock'] || $data['iblock']['ID'] != $ibId) && $this->throwError($this->errorMessage('iblock not registered after update', array(':actual' => $data['iblock']['ID'], ':need' => $ibId)));
                 break;
             case IblockPropertyHandler::className():
                 $data['ID'] != $propId && $this->throwError($this->errorMessage('property iblock not registered after update', array(':original' => $propId, ':actual' => $data['ID'])));
                 break;
             case IblockSectionHandler::className():
                 $data['ID'] != $secId && $this->throwError($this->errorMessage('section iblock not registered after update', array(':original' => $secId, ':actual' => $data['ID'])));
                 break;
         }
     }
     // добавлены три вида ссылок в фиксаци¤х
     $this->assertEquals(3, count($refFixes), $this->errorMessage('links expected count', array(':count' => 3)));
     $this->_iblockId = $ibId;
     $this->_propertyId = $propId;
     $this->_sectionId = $secId;
 }
 function executeUp()
 {
     CModule::IncludeModule('iblock');
     $obj_ib_section = new CIBlockSection();
     $r = $obj_ib_section->Add(array('NAME' => 'new section here', 'CODE' => 'new_section_here', 'ACTIVE' => 'N', 'IBLOCK_ID' => self::IBLOCK_ID));
     if (!$r) {
         throw new \Exception('Err adding section:' . $obj_ib_section->LAST_ERROR);
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  * @param array $params
  */
 protected function IblockSectionCreate(array $params)
 {
     $bs = new \CIBlockSection();
     $res = $bs->Add($params);
     if (!$res) {
         throw new \Exception($bs->LAST_ERROR);
     } else {
         return $res;
     }
 }
Exemplo n.º 10
0
 private static function EnsureProductSection($externalID, $catalogID, $arFields)
 {
     $section = new CIBlockSection();
     $rsSections = $section->GetList(array(), array('XML_ID' => $externalID, 'IBLOCK_ID' => $catalogID), false, array('ID'));
     $arSection = $rsSections->Fetch();
     if (is_array($arSection)) {
         return intval($arSection['ID']);
     }
     $sectionID = $section->Add(array('IBLOCK_ID' => $catalogID, 'ACTIVE' => 'Y', 'NAME' => $arFields['NAME'], 'IBLOCK_SECTION_ID' => 0, 'CHECK_PERMISSIONS' => 'N', 'XML_ID' => $externalID));
     return $sectionID;
 }
Exemplo n.º 11
0
 public function addSection($iblockId, $fields = array())
 {
     $default = array("ACTIVE" => "Y", "IBLOCK_SECTION_ID" => false, "NAME" => 'section', "CODE" => '', "SORT" => 100, "PICTURE" => false, "DESCRIPTION" => '', "DESCRIPTION_TYPE" => 'text');
     $fields = array_merge($default, $fields);
     $fields["IBLOCK_ID"] = $iblockId;
     $ib = new \CIBlockSection();
     $id = $ib->Add($fields);
     if ($id) {
         return $id;
     }
     $this->throwException(__METHOD__, $ib->LAST_ERROR);
 }
Exemplo n.º 12
0
function addSectionReview($NAME, $CODE, $IBLOCK_ID)
{
    CModule::IncludeModule('iblock');
    $bs = new CIBlockSection();
    $arFields = array("ACTIVE" => 'Y', "IBLOCK_ID" => $IBLOCK_ID, "NAME" => $NAME, "CODE" => $CODE);
    $ID = $bs->Add($arFields);
    $res = $ID > 0;
    if (!$res) {
        echo $bs->LAST_ERROR;
    }
    return $ID;
}
Exemplo n.º 13
0
 /**
  * Creates new section in iblock
  * @param $arParams
  * @param $arResult
  * @param $name
  * @return bool|int
  */
 public static function createAlbum($arParams, $arResult, &$name)
 {
     if (!CModule::IncludeModule("iblock")) {
         return false;
     }
     $name = trim($name);
     $name = strlen($name) > 0 ? $name : GetMessage("P_NEW_ALBUM");
     $name = strlen($name) > 0 ? $name : "New album";
     $arFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $arParams["IBLOCK_ID"], "IBLOCK_SECTION_ID" => $arParams["BEHAVIOUR"] == "USER" ? $arResult["GALLERY"]["ID"] : 0, "DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "UF_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "NAME" => $name);
     $GLOBALS["UF_DATE"] = $arFields["UF_DATE"];
     $bs = new CIBlockSection();
     $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", $arFields);
     $ID = $bs->Add($arFields);
     if ($ID > 0) {
         CIBlockSection::ReSort($arParams["IBLOCK_ID"]);
         $arPropertiesNeed = array();
         // Array of properties to create
         foreach ($arParams['converters'] as $val) {
             if ($val['code'] == "real_picture" || $val['code'] == "thumbnail") {
                 continue;
             }
             $db_res = CIBlock::GetProperties($arParams["IBLOCK_ID"], array(), array("CODE" => $val['code']));
             if (!($db_res && ($res = $db_res->Fetch()))) {
                 $arPropertiesNeed[] = $val['code'];
             }
         }
         if (count($arPropertiesNeed) > 0) {
             $obProperty = new CIBlockProperty();
             foreach ($arPropertiesNeed as $key) {
                 $res = $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "F", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_" . strToUpper($key))) > 0 ? GetMessage("P_" . strToUpper($key)) : strToUpper($key), "CODE" => strToUpper($key), "FILE_TYPE" => "jpg, gif, bmp, png, jpeg"));
             }
         }
         // Check Public property
         $arPropertiesNeed = array();
         foreach (array("PUBLIC_ELEMENT", "APPROVE_ELEMENT") as $key) {
             $db_res = CIBlock::GetProperties($arParams["IBLOCK_ID"], array(), array("CODE" => $key));
             if (!$db_res || !($res = $db_res->Fetch())) {
                 $arPropertiesNeed[] = $key;
             }
         }
         if (count($arPropertiesNeed) > 0) {
             $obProperty = new CIBlockProperty();
             foreach ($arPropertiesNeed as $key) {
                 $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "S", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_" . $key)) > 0 ? GetMessage("P_" . $key) : $key, "DEFAULT_VALUE" => "N", "CODE" => $key));
             }
         }
     }
     return $ID > 0 ? $ID : false;
 }
Exemplo n.º 14
0
function AddDepartment($SITE_ID, $arFields)
{
    if (CModule::IncludeModule('iblock')) {
        global $iblockID;
        $arNewFields = array("NAME" => $arFields["NAME"], "IBLOCK_SECTION_ID" => $arFields["IBLOCK_SECTION_ID"], "UF_HEAD" => $arFields["UF_HEAD"], "IBLOCK_ID" => $iblockID);
        $section = new CIBlockSection();
        $ID = $section->Add($arNewFields);
    }
    if (!$ID) {
        $arErrors = preg_split("/<br>/", $section->LAST_ERROR);
        return $arErrors;
    } else {
        return $ID;
    }
}
Exemplo n.º 15
0
 public static function departmentAdd($params)
 {
     if (self::canEdit()) {
         CModule::IncludeModule('iblock');
         $params = array_change_key_case($params, CASE_UPPER);
         $arFields = array('IBLOCK_ID' => self::getDeptIblock(), 'NAME' => $params['NAME'], 'SORT' => $params['SORT'], 'IBLOCK_SECTION_ID' => $params['PARENT'], 'UF_HEAD' => $params['UF_HEAD']);
         $ob = new CIBlockSection();
         $section = $ob->Add($arFields);
         if ($section > 0) {
             return $section;
         } else {
             throw new Exception($ob->LAST_ERROR);
         }
     } else {
         throw new Exception('Access denied!');
     }
 }
Exemplo n.º 16
0
 /**
  * <p>Метод инициализирует интеграцию.</p>
  *
  *
  *
  *
  * @param int $SOCNET_GROUP_ID  Идентификатор рабочей группы соц. сети
  *
  *
  *
  * @param int $IBLOCK_ID  Идентификатор инфо.блока
  *
  *
  *
  * @return bool 
  *
  *
  * <h4>Example</h4> 
  * <pre>
  * &lt;?<br>// Инициализируем интеграцию<br>$SOCNET_GROUP_ID = 14;<br>$IBLOCK_ID = 3;<br><br>if (!CWikiSocnet::Init($SOCNET_GROUP_ID, $IBLOCK_ID))<br>	echo 'Ошибка. Не удалось инициализировать интеграцию.';<br>?&gt;
  * </pre>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/wiki/classes/cwikisocnet/Init.php
  * @author Bitrix
  */
 static function Init($SOCNET_GROUP_ID, $IBLOCK_ID)
 {
     if (self::$bInit) {
         return self::$bInit;
     }
     if (!self::IsEnabledSocnet()) {
         return false;
     }
     self::$iSocNetId = $SOCNET_GROUP_ID;
     // detect work group
     $arFilter = array();
     $arFilter['IBLOCK_ID'] = $IBLOCK_ID;
     $arFilter['SOCNET_GROUP_ID'] = self::$iSocNetId;
     $arFilter['CHECK_PERMISSIONS'] = 'N';
     $rsSection = CIBlockSection::GetList(array($by => $order), $arFilter, true);
     $obSection = $rsSection->GetNextElement();
     if ($obSection !== false) {
         $arResult = $obSection->GetFields();
         self::$iCatId = $arResult['ID'];
         self::$iCatLeftBorder = $arResult['LEFT_MARGIN'];
         self::$iCatRightBorder = $arResult['RIGHT_MARGIN'];
     } else {
         $arWorkGroup = CSocNetGroup::GetById(self::$iSocNetId);
         $arFields = array('ACTIVE' => 'Y', 'IBLOCK_ID' => $IBLOCK_ID, 'SOCNET_GROUP_ID' => self::$iSocNetId, 'CHECK_PERMISSIONS' => 'N', 'NAME' => $arWorkGroup['NAME']);
         $CIB_S = new CIBlockSection();
         self::$iCatId = $CIB_S->Add($arFields);
         if (self::$iCatId == false) {
             self::$bInit = false;
             return false;
         }
         $rsSection = CIBlockSection::GetList(array($by => $order), $arFilter, true);
         $obSection = $rsSection->GetNextElement();
         if ($obSection == false) {
             self::$bInit = false;
             return false;
         }
         $arResult = $obSection->GetFields();
         self::$iCatLeftBorder = $arResult['LEFT_MARGIN'];
         self::$iCatRightBorder = $arResult['RIGHT_MARGIN'];
     }
     self::$bInit = CSocNetFeatures::IsActiveFeature(SONET_ENTITY_GROUP, self::$iSocNetId, 'wiki');
     return self::$bInit;
 }
Exemplo n.º 17
0
             }
             if (!$bFilePres) {
                 unset($arGroupsTmp[$i]["DETAIL_PICTURE"]);
             }
         }
         $res = CIBlockSection::GetList(array(), $arFilter, false, array('ID'));
         if ($arr = $res->Fetch()) {
             $LAST_GROUP_CODE = $arr["ID"];
             $res = $bs->Update($LAST_GROUP_CODE, $arGroupsTmp[$i], true, true, 'Y' === $IMAGE_RESIZE);
             if (!$res) {
                 $strErrorR .= GetMessage("CATI_LINE_NO") . " " . $line_num . ". " . GetMessage("CATI_ERR_UPDATE_SECT") . " " . $bs->LAST_ERROR . "<br>";
             }
         } else {
             $arGroupsTmp[$i]["IBLOCK_ID"] = $IBLOCK_ID;
             $arGroupsTmp[$i]["ACTIVE"] = isset($arGroupsTmp[$i]["ACTIVE"]) && 'N' === $arGroupsTmp[$i]["ACTIVE"] ? 'N' : 'Y';
             $LAST_GROUP_CODE = $bs->Add($arGroupsTmp[$i], true, true, 'Y' === $IMAGE_RESIZE);
             if (!$LAST_GROUP_CODE) {
                 $strErrorR .= GetMessage("CATI_LINE_NO") . " " . $line_num . ". " . GetMessage("CATI_ERR_ADD_SECT") . " " . $bs->LAST_ERROR . "<br>";
             }
         }
         if ('' === $strErrorR) {
             $arSectionCache[$sectionIndex] = $LAST_GROUP_CODE;
         }
     } else {
         $LAST_GROUP_CODE = $arSectionCache[$sectionIndex];
     }
 }
 if ('' === $strErrorR) {
     $arLoadProductArray = array("MODIFIED_BY" => $currentUserID, "IBLOCK_ID" => $IBLOCK_ID, "TMP_ID" => $tmpid);
     foreach ($arAvailProdFields_names as $key => $value) {
         $ind = -1;
Exemplo n.º 18
0
 function ImportSection($xml_tree_id, $IBLOCK_ID, $parent_section_id)
 {
     /** @var CUserTypeManager $USER_FIELD_MANAGER */
     global $USER_FIELD_MANAGER;
     /** @var CDatabase $DB */
     global $DB;
     static $arUserFields;
     if ($parent_section_id === false) {
         $arUserFields = array();
         foreach ($USER_FIELD_MANAGER->GetUserFields("IBLOCK_" . $IBLOCK_ID . "_SECTION") as $FIELD_ID => $arField) {
             if (strlen($arField["XML_ID"]) <= 0) {
                 $arUserFields[$FIELD_ID] = $arField;
             } else {
                 $arUserFields[$arField["XML_ID"]] = $arField;
             }
         }
     }
     $this->next_step["section_sort"] += 10;
     $arSection = array("IBLOCK_SECTION_ID" => $parent_section_id, "ACTIVE" => "Y");
     $rsS = $this->_xml_file->GetList(array("ID" => "asc"), array("PARENT_ID" => $xml_tree_id));
     $XML_SECTIONS_PARENT = false;
     $XML_PROPERTIES_PARENT = false;
     $XML_SECTION_PROPERTIES = false;
     $deletedStatus = false;
     while ($arS = $rsS->Fetch()) {
         if (isset($arS["VALUE_CLOB"])) {
             $arS["VALUE"] = $arS["VALUE_CLOB"];
         }
         if ($arS["NAME"] == $this->mess["IBLOCK_XML2_ID"]) {
             $arSection["XML_ID"] = $arS["VALUE"];
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_NAME"]) {
             $arSection["NAME"] = $arS["VALUE"];
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_DESCRIPTION"]) {
             $arSection["DESCRIPTION"] = $arS["VALUE"];
             $arSection["DESCRIPTION_TYPE"] = "html";
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_GROUPS"]) {
             $XML_SECTIONS_PARENT = $arS["ID"];
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_PROPERTIES_VALUES"]) {
             $XML_PROPERTIES_PARENT = $arS["ID"];
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_BX_SORT"]) {
             $arSection["SORT"] = intval($arS["VALUE"]);
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_BX_CODE"]) {
             $arSection["CODE"] = $arS["VALUE"];
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_BX_PICTURE"]) {
             if (strlen($arS["VALUE"]) > 0) {
                 $arSection["PICTURE"] = $this->MakeFileArray($arS["VALUE"]);
             } else {
                 $arSection["PICTURE"] = $this->MakeFileArray($this->_xml_file->GetAllChildrenArray($arS["ID"]));
             }
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_BX_DETAIL_PICTURE"]) {
             if (strlen($arS["VALUE"]) > 0) {
                 $arSection["DETAIL_PICTURE"] = $this->MakeFileArray($arS["VALUE"]);
             } else {
                 $arSection["DETAIL_PICTURE"] = $this->MakeFileArray($this->_xml_file->GetAllChildrenArray($arS["ID"]));
             }
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_BX_ACTIVE"]) {
             $arSection["ACTIVE"] = $arS["VALUE"] == "true" || intval($arS["VALUE"]) ? "Y" : "N";
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_SECTION_PROPERTIES"]) {
             $XML_SECTION_PROPERTIES = $arS["ID"];
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_STATUS"]) {
             $deletedStatus = $arS["VALUE"] === $this->mess["IBLOCK_XML2_DELETED"];
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_INHERITED_TEMPLATES"]) {
             $arSection["IPROPERTY_TEMPLATES"] = array();
             $arTemplates = $this->_xml_file->GetAllChildrenArray($arS["ID"]);
             foreach ($arTemplates as $TEMPLATE) {
                 $id = $TEMPLATE[$this->mess["IBLOCK_XML2_ID"]];
                 $template = $TEMPLATE[$this->mess["IBLOCK_XML2_VALUE"]];
                 if (strlen($id) > 0 && strlen($template) > 0) {
                     $arSection["IPROPERTY_TEMPLATES"][$id] = $template;
                 }
             }
         } elseif ($arS["NAME"] == $this->mess["IBLOCK_XML2_DELETE_MARK"]) {
             $arSection["ACTIVE"] = $arS["VALUE"] == "true" || intval($arS["VALUE"]) ? "N" : "Y";
         }
     }
     if ($deletedStatus) {
         $obSection = new CIBlockSection();
         $rsSection = $obSection->GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "XML_ID" => $arSection["XML_ID"]), false, array("ID"));
         if ($arDBSection = $rsSection->Fetch()) {
             $obSection->Update($arDBSection["ID"], array("ACTIVE" => "N"));
             $this->_xml_file->Add(array("PARENT_ID" => 0, "LEFT_MARGIN" => $arDBSection["ID"]));
         }
         return true;
     }
     if ($XML_PROPERTIES_PARENT) {
         $rs = $this->_xml_file->GetList(array("ID" => "asc"), array("PARENT_ID" => $XML_PROPERTIES_PARENT), array("ID"));
         while ($ar = $rs->Fetch()) {
             $arXMLProp = $this->_xml_file->GetAllChildrenArray($ar["ID"]);
             if (array_key_exists($this->mess["IBLOCK_XML2_ID"], $arXMLProp) && array_key_exists($arXMLProp[$this->mess["IBLOCK_XML2_ID"]], $arUserFields)) {
                 $arUserField = $arUserFields[$arXMLProp[$this->mess["IBLOCK_XML2_ID"]]];
                 unset($arXMLProp[$this->mess["IBLOCK_XML2_ID"]]);
                 $arProp = array();
                 $i = 0;
                 foreach ($arXMLProp as $value) {
                     if ($arUserField["USER_TYPE"]["BASE_TYPE"] === "file") {
                         $arProp["n" . $i++] = $this->MakeFileArray($value);
                     } elseif ($arUserField["USER_TYPE"]["BASE_TYPE"] === "enum") {
                         $arProp["n" . $i++] = $this->GetSectionEnumByXML_ID($arUserField["ID"], $value);
                     } else {
                         $arProp["n" . $i++] = $value;
                     }
                 }
                 if ($arUserField["MULTIPLE"] == "N") {
                     $arSection[$arUserField["FIELD_NAME"]] = array_pop($arProp);
                 } else {
                     $arSection[$arUserField["FIELD_NAME"]] = $arProp;
                 }
             }
         }
     }
     $obSection = new CIBlockSection();
     $rsSection = $obSection->GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "XML_ID" => $arSection["XML_ID"]), false);
     if ($arDBSection = $rsSection->Fetch()) {
         if (!array_key_exists("CODE", $arSection) && is_array($this->translit_on_update)) {
             $arSection["CODE"] = CUtil::translit($arSection["NAME"], LANGUAGE_ID, $this->translit_on_update);
             //Check if name was not changed in a way to update CODE
             if (substr($arDBSection["CODE"], 0, strlen($arSection["CODE"])) === $arSection["CODE"]) {
                 unset($arSection["CODE"]);
             } else {
                 $arSection["CODE"] = $this->CheckSectionCode($IBLOCK_ID, $arSection["CODE"]);
             }
         }
         $bChanged = false;
         foreach ($arSection as $key => $value) {
             if (is_array($arDBSection[$key]) || $arDBSection[$key] != $value) {
                 $bChanged = true;
                 break;
             }
         }
         if ($bChanged) {
             foreach ($arUserFields as $arField1) {
                 if ($arField1["USER_TYPE"]["BASE_TYPE"] == "file") {
                     $sectionUF = $USER_FIELD_MANAGER->GetUserFields("IBLOCK_" . $IBLOCK_ID . "_SECTION", $arDBSection["ID"]);
                     foreach ($sectionUF as $arField2) {
                         if ($arField2["USER_TYPE"]["BASE_TYPE"] == "file" && isset($arSection[$arField2["FIELD_NAME"]])) {
                             if ($arField2["MULTIPLE"] == "Y" && is_array($arField2["VALUE"])) {
                                 foreach ($arField2["VALUE"] as $old_file_id) {
                                     $arSection[$arField2["FIELD_NAME"]][] = array("del" => true, "old_id" => $old_file_id);
                                 }
                             } elseif ($arField2["MULTIPLE"] == "N" && $arField2["VALUE"] > 0) {
                                 $arSection[$arField2["FIELD_NAME"]]["old_id"] = $arField2["VALUE"];
                             }
                         }
                     }
                     break;
                 }
             }
             $res = $obSection->Update($arDBSection["ID"], $arSection);
             if (!$res) {
                 $this->LAST_ERROR = $obSection->LAST_ERROR;
                 return $this->LAST_ERROR;
             }
         } else {
             $DB->Query("UPDATE b_iblock_section SET TIMESTAMP_X = " . $DB->CurrentTimeFunction() . " WHERE ID=" . $arDBSection["ID"]);
         }
         $arSection["ID"] = $arDBSection["ID"];
     } else {
         if (!array_key_exists("CODE", $arSection) && is_array($this->translit_on_add)) {
             $arSection["CODE"] = $this->CheckSectionCode($IBLOCK_ID, CUtil::translit($arSection["NAME"], LANGUAGE_ID, $this->translit_on_add));
         }
         $arSection["IBLOCK_ID"] = $IBLOCK_ID;
         if (!isset($arSection["SORT"])) {
             $arSection["SORT"] = $this->next_step["section_sort"];
         }
         $arSection["ID"] = $obSection->Add($arSection);
         if (!$arSection["ID"]) {
             $this->LAST_ERROR = $obSection->LAST_ERROR;
             return $this->LAST_ERROR;
         }
     }
     if ($XML_SECTION_PROPERTIES) {
         $this->ImportSectionProperties($XML_SECTION_PROPERTIES, $IBLOCK_ID, $arSection["ID"]);
     }
     if ($arSection["ID"]) {
         $this->_xml_file->Add(array("PARENT_ID" => 0, "LEFT_MARGIN" => $arSection["ID"]));
     }
     if ($XML_SECTIONS_PARENT) {
         $rs = $this->_xml_file->GetList(array("ID" => "asc"), array("PARENT_ID" => $XML_SECTIONS_PARENT), array("ID"));
         while ($ar = $rs->Fetch()) {
             $result = $this->ImportSection($ar["ID"], $IBLOCK_ID, $arSection["ID"]);
             if ($result !== true) {
                 return $result;
             }
         }
     }
     return true;
 }
Exemplo n.º 19
0
             $errorString .= $iblock->LAST_ERROR;
         }
         if ($iblockID > 0) {
             $arCars = array(array("NAME" => "MERCEDES-BENZ", "CHILDREN_TMP" => array(array("NAME" => "MERCEDES-BENZ 190"), array("NAME" => "MERCEDES-BENZ 300"), array("NAME" => "MERCEDES-BENZ A-KLASSE"), array("NAME" => "MERCEDES-BENZ C-KLASSE"))), array("NAME" => "VOLKSWAGEN", "CHILDREN_TMP" => array(array("NAME" => "VOLKSWAGEN GOLF"), array("NAME" => "VOLKSWAGEN PASSAT"), array("NAME" => "VOLKSWAGEN POLO"), array("NAME" => "VOLKSWAGEN TIGUAN"))), array("NAME" => "RENAULT", "CHILDREN_TMP" => array(array("NAME" => "RENAULT CLIO"), array("NAME" => "RENAULT LOGAN"), array("NAME" => "RENAULT MEGANE"))), array("NAME" => "TOYOTA", "CHILDREN_TMP" => array(array("NAME" => "TOYOTA AVENSIS"), array("NAME" => "TOYOTA CAMRY"), array("NAME" => "TOYOTA CELICA"), array("NAME" => "TOYOTA COROLLA"), array("NAME" => "TOYOTA YARIS"))), array("NAME" => "OPEL", "CHILDREN_TMP" => array(array("NAME" => "OPEL ASCONA"), array("NAME" => "OPEL CORSA"), array("NAME" => "OPEL KADETT"), array("NAME" => "OPEL OMEGA"))), array("NAME" => "NISSAN", "CHILDREN_TMP" => array(array("NAME" => "NISSAN ALMERA"), array("NAME" => "NISSAN MICRA"), array("NAME" => "NISSAN PATROL"))), array("NAME" => "FORD", "CHILDREN_TMP" => array(array("NAME" => "FORD C-MAX"), array("NAME" => "FORD ESCORT"), array("NAME" => "FORD FIESTA"), array("NAME" => "FORD FOCUS"))), array("NAME" => "MITSUBISHI", "CHILDREN_TMP" => array(array("NAME" => "MITSUBISHI GALANT"), array("NAME" => "MITSUBISHI PAJERO"))), array("NAME" => "BMW", "CHILDREN_TMP" => array(array("NAME" => "BMW M"), array("NAME" => "BMW X"))), array("NAME" => "AUDI", "CHILDREN_TMP" => array(array("NAME" => "AUDI A4"), array("NAME" => "AUDI A5"), array("NAME" => "AUDI A6"))), array("NAME" => "FIAT", "CHILDREN_TMP" => array(array("NAME" => "FIAT BRAVO"), array("NAME" => "FIAT 900 T/E"))));
             foreach ($arCars as $arCar) {
                 $arFields = array("IBLOCK_ID" => $iblockID, "IBLOCK_SECTION_ID" => 0, "ACTIVE" => "Y", "NAME" => $arCar["NAME"]);
                 $iblockSection = new CIBlockSection();
                 $iblockSectionID = $iblockSection->Add($arFields, true, false);
                 if ($iblockSectionID <= 0) {
                     $errorString .= $iblockSection->LAST_ERROR;
                 } else {
                     if (array_key_exists("CHILDREN_TMP", $arCar) && Count($arCar["CHILDREN_TMP"]) > 0) {
                         foreach ($arCar["CHILDREN_TMP"] as $arChildCar) {
                             $arFields = array("IBLOCK_ID" => $iblockID, "IBLOCK_SECTION_ID" => $iblockSectionID, "ACTIVE" => "Y", "NAME" => $arChildCar["NAME"]);
                             $iblockSection = new CIBlockSection();
                             $iblockChildSectionID = $iblockSection->Add($arFields, true, false);
                             if ($iblockChildSectionID <= 0) {
                                 $errorString .= $iblockSection->LAST_ERROR;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 $iblockID = IntVal($iblockID);
 if (StrLen($iblockTypeID) > 0 && $iblockID > 0) {
     $dbUserField = CUserTypeEntity::GetList(array(), array("ENTITY_ID" => "USER", "FIELD_NAME" => "UF_USER_CAR_DEMO"));
     if ($arUserField = $dbUserField->Fetch()) {
     } else {
Exemplo n.º 20
0
             }
         }
     }
     if (empty($arFields["IBLOCK_SECTION_ID"])) {
         $arFields["IBLOCK_SECTION_ID"] = $arResult["GALLERY"]["ID"];
     }
 } elseif (intVal($_REQUEST["IBLOCK_SECTION_ID"]) > 0) {
     $arFields["IBLOCK_SECTION_ID"] = $_REQUEST["IBLOCK_SECTION_ID"];
 }
 if (!empty($_REQUEST["PASSWORD"])) {
     $arFields["UF_PASSWORD"] = md5($_REQUEST["PASSWORD"]);
     $GLOBALS["UF_PASSWORD"] = md5($_REQUEST["PASSWORD"]);
 }
 $bs = new CIBlockSection();
 $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", $arFields);
 $ID = $bs->Add($arFields);
 if ($ID > 0) {
     $rsSection = CIBlockSection::GetList(array(), array("ID" => $ID), false);
     $arResultSection = $rsSection->GetNext();
     $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~SECTION_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $ID));
     $arResultFields = array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "DATE" => PhotoDateFormat($arParams["DATE_TIME_FORMAT"], MakeTimeStamp($_REQUEST["UF_DATE"], CSite::GetDateFormat())), "NAME" => $arResultSection["NAME"], "DESCRIPTION" => $arResultSection["DESCRIPTION"], "PASSWORD" => $arResultSection["UF_PASSWORD"], "ID" => $ID, "error" => "", "url" => $arResult["URL"]);
 } elseif ($bs->LAST_ERROR) {
     $strWarning .= $bs->LAST_ERROR;
     $bVarsFromForm = true;
 } else {
     $err = $GLOBALS['APPLICATION']->GetException();
     if ($err) {
         $strWarning .= $err->GetString();
     }
     $bVarsFromForm = true;
 }
Exemplo n.º 21
0
 protected static function groupSectionCreate($groupId)
 {
     $groupLib = CWebDavIblock::LibOptions('group_files', false, SITE_ID);
     if (!$groupLib || !isset($groupLib['id']) || !($iblockId = intval($groupLib['id']))) {
         return false;
     }
     $result = CIBlockWebdavSocnet::GetSectionID($iblockId, 'group', $groupId);
     if (intval($result) > 0) {
         return $result;
     }
     $dbRes = CUserTypeEntity::GetList(array($by => $order), array("ENTITY_ID" => "IBLOCK_" . $iblockId . "_SECTION", "FIELD_NAME" => "UF_USE_BP"));
     if (!$dbRes || !($res = $dbRes->GetNext())) {
         $arFields = array("ENTITY_ID" => "IBLOCK_" . $iblockId . "_SECTION", "FIELD_NAME" => "UF_USE_BP", "USER_TYPE_ID" => "string", "MULTIPLE" => "N", "MANDATORY" => "N", "SETTINGS" => array("DEFAULT_VALUE" => "Y"));
         $arFieldName = array();
         $rsLanguage = CLanguage::GetList($by, $order, array());
         while ($arLanguage = $rsLanguage->Fetch()) {
             $dir = str_replace(array("\\", "//"), "/", dirname(__FILE__));
             $dirs = explode("/", $dir);
             array_pop($dirs);
             $file = trim(implode("/", $dirs) . "/lang/" . $arLanguage["LID"] . "/include/webdav_settings.php");
             $tmp_mess = __IncludeLang($file, true);
             $arFieldName[$arLanguage["LID"]] = empty($tmp_mess["SONET_UF_USE_BP"]) ? "Use Business Process" : $tmp_mess["SONET_UF_USE_BP"];
         }
         $arFields["EDIT_FORM_LABEL"] = $arFieldName;
         $obUserField = new CUserTypeEntity();
         $obUserField->Add($arFields);
         $GLOBALS["USER_FIELD_MANAGER"]->arFieldsCache = array();
     }
     $arFields = array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "SOCNET_GROUP_ID" => false, "IBLOCK_SECTION_ID" => 0, "UF_USE_BP" => "N");
     $arFields["SOCNET_GROUP_ID"] = $groupId;
     $arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $groupId;
     $dbGroup = CSocNetGroup::GetList(array(), array("ID" => (int) $groupId), false, false, array("ID", "SITE_ID", "NAME"));
     if ($arGroup = $dbGroup->Fetch()) {
         $arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $arGroup["NAME"];
     }
     if (CIBlock::GetarrayByID($iblockId, "RIGHTS_MODE") === "E") {
         $arTasks = CWebDavIblock::GetTasks();
         $arFields['RIGHTS'] = array('n0' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_A', 'TASK_ID' => $arTasks['X']), 'n1' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_E', 'TASK_ID' => $arTasks['W']), 'n2' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_K', 'TASK_ID' => $arTasks['W']));
     }
     $GLOBALS["UF_USE_BP"] = $arFields["UF_USE_BP"];
     $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $iblockId . "_SECTION", $arFields);
     $bs = new CIBlockSection();
     $sectionId = $bs->Add($arFields);
     if (!$sectionId) {
         return false;
     }
     return $sectionId;
 }
Exemplo n.º 22
0
 protected function addSection($arSection)
 {
     //TODO: Сделать рефакторинг этого метода
     $iNewSectionId = 0;
     $iIblockId = 0;
     $sIblockTypeId = $arSection['IBLOCK_TYPE_ID'];
     if (strlen($arSection['CODE']) > 0) {
         $arFilter = array('IBLOCK_ID' => $arSection['IBLOCK_ID'], 'CODE' => $arSection['CODE'], 'IBLOCK_TYPE_ID' => $sIblockTypeId);
         $db_list = \CIBlockSection::GetList(array(), $arFilter, true);
         if ($arRes = $db_list->GetNext()) {
             $iNewSectionId = $arRes['ID'];
             //такой раздел уже есть
             $iIblockId = $arRes['IBLOCK_ID'];
         }
     }
     if ($iNewSectionId == 0) {
         $bs = new \CIBlockSection();
         if (is_array($arSection['PICTURE'])) {
             $arSection['PICTURE'] = $this->prepareFile($arSection['PICTURE']);
         }
         if ($iNewSectionId = $bs->Add($arSection)) {
             $this->addMessage('Новый раздел ' . $iNewSectionId . ' добавлен.', true);
             $iIblockId = $arSection['IBLOCK_ID'];
         }
         unset($bs);
     }
     if (intval($iNewSectionId) > 0 && intval($iIblockId) > 0) {
         //добавляем элементы раздела
         if (count($arSection['ELEMENTS']) > 0) {
             foreach ($arSection['ELEMENTS'] as $arElement) {
                 $arElement["IBLOCK_SECTION_ID"] = $iNewSectionId;
                 $arElement["IBLOCK_ID"] = $iIblockId;
                 $this->addElement($arElement);
             }
         }
         //добавляем подразделы
         if (count($arSection['SECTIONS']) > 0) {
             foreach ($arSection['SECTIONS'] as $arSection) {
                 $arSection["IBLOCK_SECTION_ID"] = $iNewSectionId;
                 $arSection["IBLOCK_ID"] = $iIblockId;
                 $arSection['IBLOCK_TYPE_ID'] = $sIblockTypeId;
                 $this->addSection($arSection);
             }
         }
     }
     return $iNewSectionId;
 }
Exemplo n.º 23
0
 }
 if (is_array($_POST["IPROPERTY_TEMPLATES"])) {
     $SECTION_PICTURE_FILE_NAME = \Bitrix\Iblock\Template\Helper::convertArrayToModifiers($_POST["IPROPERTY_TEMPLATES"]["SECTION_PICTURE_FILE_NAME"]);
     $SECTION_DETAIL_PICTURE_FILE_NAME = \Bitrix\Iblock\Template\Helper::convertArrayToModifiers($_POST["IPROPERTY_TEMPLATES"]["SECTION_DETAIL_PICTURE_FILE_NAME"]);
     $ELEMENT_PREVIEW_PICTURE_FILE_NAME = \Bitrix\Iblock\Template\Helper::convertArrayToModifiers($_POST["IPROPERTY_TEMPLATES"]["ELEMENT_PREVIEW_PICTURE_FILE_NAME"]);
     $ELEMENT_DETAIL_PICTURE_FILE_NAME = \Bitrix\Iblock\Template\Helper::convertArrayToModifiers($_POST["IPROPERTY_TEMPLATES"]["ELEMENT_DETAIL_PICTURE_FILE_NAME"]);
     $arFields["IPROPERTY_TEMPLATES"] = array("SECTION_META_TITLE" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_META_TITLE"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["SECTION_META_TITLE"]["TEMPLATE"] : "", "SECTION_META_KEYWORDS" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_META_KEYWORDS"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["SECTION_META_KEYWORDS"]["TEMPLATE"] : "", "SECTION_META_DESCRIPTION" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_META_DESCRIPTION"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["SECTION_META_DESCRIPTION"]["TEMPLATE"] : "", "SECTION_PAGE_TITLE" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_PAGE_TITLE"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["SECTION_PAGE_TITLE"]["TEMPLATE"] : "", "ELEMENT_META_TITLE" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_META_TITLE"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_META_TITLE"]["TEMPLATE"] : "", "ELEMENT_META_KEYWORDS" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_META_KEYWORDS"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_META_KEYWORDS"]["TEMPLATE"] : "", "ELEMENT_META_DESCRIPTION" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_META_DESCRIPTION"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_META_DESCRIPTION"]["TEMPLATE"] : "", "ELEMENT_PAGE_TITLE" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_PAGE_TITLE"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_PAGE_TITLE"]["TEMPLATE"] : "", "SECTION_PICTURE_FILE_ALT" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_PICTURE_FILE_ALT"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["SECTION_PICTURE_FILE_ALT"]["TEMPLATE"] : "", "SECTION_PICTURE_FILE_TITLE" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_PICTURE_FILE_TITLE"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["SECTION_PICTURE_FILE_TITLE"]["TEMPLATE"] : "", "SECTION_PICTURE_FILE_NAME" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_PICTURE_FILE_NAME"]["INHERITED"] === "N" ? $SECTION_PICTURE_FILE_NAME : "", "SECTION_DETAIL_PICTURE_FILE_ALT" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_DETAIL_PICTURE_FILE_ALT"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["SECTION_DETAIL_PICTURE_FILE_ALT"]["TEMPLATE"] : "", "SECTION_DETAIL_PICTURE_FILE_TITLE" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_DETAIL_PICTURE_FILE_TITLE"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["SECTION_DETAIL_PICTURE_FILE_TITLE"]["TEMPLATE"] : "", "SECTION_DETAIL_PICTURE_FILE_NAME" => $_POST["IPROPERTY_TEMPLATES"]["SECTION_DETAIL_PICTURE_FILE_NAME"]["INHERITED"] === "N" ? $SECTION_DETAIL_PICTURE_FILE_NAME : "", "ELEMENT_PREVIEW_PICTURE_FILE_ALT" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_PREVIEW_PICTURE_FILE_ALT"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_PREVIEW_PICTURE_FILE_ALT"]["TEMPLATE"] : "", "ELEMENT_PREVIEW_PICTURE_FILE_TITLE" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_PREVIEW_PICTURE_FILE_TITLE"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_PREVIEW_PICTURE_FILE_TITLE"]["TEMPLATE"] : "", "ELEMENT_PREVIEW_PICTURE_FILE_NAME" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_PREVIEW_PICTURE_FILE_NAME"]["INHERITED"] === "N" ? $ELEMENT_PREVIEW_PICTURE_FILE_NAME : "", "ELEMENT_DETAIL_PICTURE_FILE_ALT" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_DETAIL_PICTURE_FILE_ALT"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_DETAIL_PICTURE_FILE_ALT"]["TEMPLATE"] : "", "ELEMENT_DETAIL_PICTURE_FILE_TITLE" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_DETAIL_PICTURE_FILE_TITLE"]["INHERITED"] === "N" ? $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_DETAIL_PICTURE_FILE_TITLE"]["TEMPLATE"] : "", "ELEMENT_DETAIL_PICTURE_FILE_NAME" => $_POST["IPROPERTY_TEMPLATES"]["ELEMENT_DETAIL_PICTURE_FILE_NAME"]["INHERITED"] === "N" ? $ELEMENT_DETAIL_PICTURE_FILE_NAME : "");
 }
 $USER_FIELD_MANAGER->EditFormAddFields("IBLOCK_" . $IBLOCK_ID . "_SECTION", $arFields);
 if (COption::GetOptionString("iblock", "show_xml_id", "N") == "Y" && is_set($_POST, "XML_ID")) {
     $arFields["XML_ID"] = $_POST["XML_ID"];
 }
 if ($ID > 0) {
     $res = $bs->Update($ID, $arFields, true, true, true);
 } else {
     $ID = $bs->Add($arFields, true, true, true);
     $res = $ID > 0;
 }
 if (!$res) {
     $strWarning .= $bs->LAST_ERROR;
     $bVarsFromForm = true;
     $DB->Rollback();
     if ($e = $APPLICATION->GetException()) {
         $message = new CAdminMessage(GetMessage("admin_lib_error"), $e);
     }
 } else {
     if ($_POST["IPROPERTY_CLEAR_VALUES"] === "Y") {
         $ipropValues = new \Bitrix\Iblock\InheritedProperty\SectionValues($IBLOCK_ID, $ID);
         $ipropValues->clearValues();
     }
     $DB->Commit();
Exemplo n.º 24
0
         $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", $arr);
         foreach ($arResult["GALLERIES"] as $res) {
             $res = $bs->Update($res["ID"], $arr, false, false);
         }
     }
     $arFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $arParams["IBLOCK_ID"], "NAME" => $_REQUEST["NAME"], "CODE" => $_REQUEST["CODE"], "SOCNET_GROUP_ID" => $arParams["SOCNET_GROUP_ID"] > 0 ? $arParams["SOCNET_GROUP_ID"] : false, "DESCRIPTION" => $_REQUEST["DESCRIPTION"], "UF_DEFAULT" => $_REQUEST["ACTIVE"]);
     if (!empty($arFiles)) {
         $arFields["PICTURE"] = $arFiles["PICTURE"];
     }
     if ($bs->CheckFields($arFields)) {
         if (!empty($arFiles)) {
             $arFields["DETAIL_PICTURE"] = $arFiles["DETAIL_PICTURE"];
         }
         $GLOBALS["UF_DEFAULT"] = $arFields["UF_DEFAULT"];
         $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", $arFields);
         $res = $bs->Add($arFields);
     } else {
         $res = false;
     }
 }
 if (!empty($arFiles)) {
     @unlink($arFiles["PICTURE"]["tmp_name"]);
     @unlink($arFiles["DETAIL_PICTURE"]["tmp_name"]);
 }
 if ($res <= 0) {
     $arError = array("code" => "SECTION_NOT_ADD", "title" => $bs->LAST_ERROR);
 } else {
     $ID = $ID > 0 ? $ID : $res;
     if ($arParams["ACTION"] == "CREATE" && $arResult["GALLERIES"] >= 1 || $arResult["GALLERIES"] > 1 || $arParams["ABS_PERMISSION"] >= "W") {
         $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["GALLERIES_URL"], array("USER_ID" => $arParams["USER_ID"]));
     } else {
Exemplo n.º 25
0
 private function InstallIblockSection()
 {
     $arSections = $this->arResult["INSTALLATION"]["IBLOCK_SECTION_ID"] = array();
     $arSections["MAIN_1"] = array("ACTIVE" => "Y", "IBLOCK_ID" => $this->arResult["INSTALLATION"]["IBLOCK_ID"], "NAME" => GetMessage("IDEA_CATEGORY_MAIN_1_NAME"), "CODE" => "company");
     $arSections["MAIN_1_SUB_1"] = array("ACTIVE" => "Y", "IBLOCK_ID" => $this->arResult["INSTALLATION"]["IBLOCK_ID"], "IBLOCK_SECTION_ID" => "MAIN_1", "NAME" => GetMessage("IDEA_CATEGORY_MAIN_1_SUB_1_NAME"), "CODE" => "inside");
     $arSections["MAIN_1_SUB_2"] = array("ACTIVE" => "Y", "IBLOCK_ID" => $this->arResult["INSTALLATION"]["IBLOCK_ID"], "IBLOCK_SECTION_ID" => "MAIN_1", "NAME" => GetMessage("IDEA_CATEGORY_MAIN_1_SUB_2_NAME"), "CODE" => "outside");
     $arSections["MAIN_2"] = array("ACTIVE" => "Y", "IBLOCK_ID" => $this->arResult["INSTALLATION"]["IBLOCK_ID"], "NAME" => GetMessage("IDEA_CATEGORY_MAIN_2_NAME"), "CODE" => "our_events");
     $IBS = new CIBlockSection();
     foreach ($arSections as $key => $arSection) {
         if (array_key_exists("IBLOCK_SECTION_ID", $arSection) && array_key_exists($arSection["IBLOCK_SECTION_ID"], $this->arResult["INSTALLATION"]["IBLOCK_SECTION_ID"])) {
             $arSection["IBLOCK_SECTION_ID"] = $this->arResult["INSTALLATION"]["IBLOCK_SECTION_ID"][$arSection["IBLOCK_SECTION_ID"]];
         }
         $this->arResult["INSTALLATION"]["IBLOCK_SECTION_ID"][$key] = $IBS->Add($arSection);
     }
 }
Exemplo n.º 26
0
    function Edit($arParams, &$newSectionId, $bDisplay = true)
    {
        global $DB;
        $iblockId = $arParams['iblockId'];
        $ownerId = $arParams['ownerId'];
        $ownerType = $arParams['ownerType'];
        $sectionId = $arParams['sectionId'];
        $arFields = $arParams['arFields'];
        if ($sectionId === 'none') {
            $sectionId = CEventCalendar::CreateSectionForOwner($ownerId, $ownerType, $iblockId);
            // Creating section for owner
            if ($sectionId === false) {
                return false;
            }
            if ($bDisplay) {
                ?>
<script>window._bx_section_id = <?php 
                echo intVal($sectionId);
                ?>
;</script><?php 
            }
            $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']);
        $GLOBALS[$key_color] = $COLOR;
        $GLOBALS[$key_export] = $EXPORT;
        $GLOBALS[$key_status] = $arFields['PRIVATE_STATUS'];
        $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $iblockId . "_SECTION", $arFields);
        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;
    }
Exemplo n.º 27
0
function GetAlbumId($Params)
{
    $arParams = $Params['arParams'];
    $sectionId = false;
    $savedData = CImageUploader::GetSavedData();
    $arResult = $Params['~arResult'];
    if ($savedData['SECTION_ID'] <= 0) {
        // Upload photos to existing album
        if ($Params['id'] !== 'new' && intVal($Params['id']) > 0) {
            $sectionId = intVal($Params['id']);
        } else {
            if ($Params['id'] == 'new') {
                $Params['name'] = trim($Params['name']);
                if (empty($Params['name'])) {
                    $Params['name'] = strLen(GetMessage("P_NEW_ALBUM")) > 0 ? GetMessage("P_NEW_ALBUM") : "New album";
                }
                $arFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $arParams["IBLOCK_ID"], "IBLOCK_SECTION_ID" => $arParams["BEHAVIOUR"] == "USER" ? $arResult["GALLERY"]["ID"] : 0, "DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "UF_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "NAME" => $Params['name']);
                $GLOBALS["UF_DATE"] = $arFields["UF_DATE"];
                $bs = new CIBlockSection();
                $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", $arFields);
                $ID = $bs->Add($arFields);
                if ($ID > 0) {
                    CIBlockSection::ReSort($arParams["IBLOCK_ID"]);
                    $sectionId = intVal($ID);
                    $arFilter = array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "CODE" => $arParams["USER_ALIAS"], "SECTION_ID" => 0);
                    //$db_res = CIBlockSection::GetList(array(), $arFilter, false, array("ID", "NAME", "CREATED_BY", "RIGHT_MARGIN", "LEFT_MARGIN", "CODE", "UF_GALLERY_SIZE"));
                    //$arResult["GALLERY"] = $db_res->Fetch();
                    $savedData['NEW_SECTION_NAME'] = $Params['name'];
                    $savedData['NEW_SECTION_PICTURE'] = "";
                } else {
                    CImageUploader::SaveError(array(array("id" => "BXPH_FUNC_001", "text" => $bs->LAST_ERROR)));
                }
            }
        }
    }
    $savedData["SECTION_ID"] = $sectionId;
    CImageUploader::SetSavedData($savedData);
    return $sectionId;
}
Exemplo n.º 28
0
 function GetDepartmentIdForADUser($department, $managerDN, $username, &$cache = FALSE, $iblockId = FALSE, $names = FALSE)
 {
     global $USER_FIELD_MANAGER;
     // check for loops in manager structure, if loop is found - quit
     // should be done before cache lookup
     if ($names && isset($names[$username])) {
         return false;
     }
     // if department id for this user is already stored in cache
     if ($cache) {
         $departmentCached = $cache[$username];
         // if user was not set as head earlier, then do not get his id from cache
         if ($departmentCached) {
             return $departmentCached;
         }
     }
     // if it is a first call in recursive chain
     if (!$iblockId) {
         // check module inclusions
         if (!IsModuleInstalled('intranet') || !CModule::IncludeModule('iblock')) {
             return false;
         }
         // get structure's iblock id
         $iblockId = COption::GetOptionInt("intranet", "iblock_structure", false, false);
         if (!$iblockId) {
             return false;
         }
         $names = array();
     }
     // save current username as already visited
     $names[$username] = true;
     $arManagerDep = null;
     $mgrDepartment = null;
     // if there's a manager - query it
     if ($managerDN) {
         preg_match('/^(CN=.*?)(\\,){1}([^\\,])*(=){1}/i', $managerDN, $matches);
         //Extract "CN=User Name" from full name
         $user = isset($matches[1]) ? str_replace('\\', '', $matches[1]) : "";
         $userArr = $this->GetUserArray($user);
         if (count($userArr) > 0) {
             // contents of userArr are already in local encoding, no need for conversion here
             $mgrDepartment = $userArr[0][$this->arFields['USER_DEPARTMENT_ATTR']];
             if ($mgrDepartment && trim($mgrDepartment) != '') {
                 // if manager's department name is set - then get it's id
                 $mgrManagerDN = $userArr[0][$this->arFields['USER_MANAGER_ATTR']];
                 $mgrUserName = $userArr[0][$this->arFields['USER_ID_ATTR']];
                 $arManagerDep = $this->GetDepartmentIdForADUser($mgrDepartment, $mgrManagerDN, $mgrUserName, $cache, $iblockId, $names);
                 // fill in cache
                 if ($cache && $arManagerDep) {
                     $cache[$mgrUserName] = $arManagerDep;
                 }
             }
         }
     }
     // prepare result and create department (if needed)
     $arResult = array('IS_HEAD' => true);
     // by default, thinking of user as a head of the department
     if ($arManagerDep) {
         // if got manager's data correctly
         if ($department && trim($department) != '' && $mgrDepartment != $department) {
             // if our department is set && differs from manager's, set manager's as parent
             $parentSectionId = $arManagerDep['ID'];
         } else {
             // - if user has no department, but somehow have manager - then he is assumed to be in manager's department
             // - if user has same department name as manager - then he is not head
             // here we can return manager's department id immediately
             $arResult = $arManagerDep;
             $arResult['IS_HEAD'] = false;
             return $arResult;
         }
     } else {
         // if there's no manager's data
         if ($department && trim($department) != '') {
             $parentSectionId = $this->arFields['ROOT_DEPARTMENT'];
         } else {
             // if have no manager's department and no own department:
             // - use default as our department and root as parent section if default is set
             // - or just root if default has empty value
             // - or return false, if setting of default department is turned off
             if ($this->arFields['STRUCT_HAVE_DEFAULT'] && $this->arFields['STRUCT_HAVE_DEFAULT'] == "Y") {
                 // if can use default department
                 $department = $this->arFields['DEFAULT_DEPARTMENT_NAME'];
                 if ($department && trim($department) != '') {
                     // if department is not empty
                     $parentSectionId = $this->arFields['ROOT_DEPARTMENT'];
                 } else {
                     // if it is empty - return parent
                     return array('ID' => $this->arFields['ROOT_DEPARTMENT']);
                 }
             } else {
                 // if have no department in AD and no default - then do not set a department
                 return false;
             }
         }
     }
     // 3. if there's no department set for this user, this means there was no default department name (which substituted in *) - then there's no need to set department id for this user at all
     if (!$department || trim($department) == '') {
         return false;
     }
     // 4. detect this user's department ID, using parent id and department name string, which we certainly have now (these 2 parameters are required to get an ID)
     // see if this department already exists
     $bs = new CIBlockSection();
     $dbExistingSections = GetIBlockSectionList($iblockId, $parentSectionId >= 0 ? $parentSectionId : false, $arOrder = array("left_margin" => "asc"), $cnt = 0, $arFilter = array('NAME' => $department));
     $departmentId = false;
     if ($arItem = $dbExistingSections->GetNext()) {
         $departmentId = $arItem['ID'];
     }
     if (!$departmentId) {
         //create new department
         $arNewSectFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $iblockId, "NAME" => $department);
         if ($parentSectionId >= 0) {
             $arNewSectFields["IBLOCK_SECTION_ID"] = $parentSectionId;
         }
         // and get it's Id
         $departmentId = $bs->Add($arNewSectFields);
     }
     $arElement = $USER_FIELD_MANAGER->GetUserFields('IBLOCK_' . $iblockId . '_SECTION', $departmentId);
     // if the head of the department is already set, do not change it
     if (!empty($arElement['UF_HEAD']['VALUE'])) {
         $arResult['IS_HEAD'] = false;
     }
     $arResult['ID'] = $departmentId;
     return $arResult;
 }
Exemplo n.º 29
0
 function __GetIBlockSectionID(&$arFields)
 {
     $sectionID = 0;
     $i = 0;
     while (true) {
         $i++;
         $csvSectionCode = "IBLOCK_SECTION_NAME_" . $i;
         if (!array_key_exists($csvSectionCode, $arFields)) {
             break;
         }
         $sectionName = trim($arFields[$csvSectionCode]);
         if (strlen($sectionName) < 1) {
             break;
         }
         $cacheID = md5($csvSectionCode . "_" . $sectionName . "_" . $sectionID);
         if (array_key_exists($cacheID, $this->arSectionCache)) {
             $sectionID = $this->arSectionCache[$cacheID];
             continue;
         }
         $dbSection = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $this->attachIBlockID, "NAME" => $sectionName, "SECTION_ID" => $sectionID));
         if ($arGroup = $dbSection->Fetch()) {
             $sectionID = $arGroup["ID"];
             $this->arSectionCache[$cacheID] = $sectionID;
             continue;
         }
         $iblockSection = new CIBlockSection();
         $arSectionFields = array("ACTIVE" => "Y", "IBLOCK_SECTION_ID" => $sectionID, "IBLOCK_ID" => $this->attachIBlockID, "NAME" => $sectionName);
         $sectionID = (int) $iblockSection->Add($arSectionFields);
         if ($sectionID > 1) {
             $this->arSectionCache[$cacheID] = $sectionID;
         } else {
             return 0;
         }
     }
     return $sectionID;
 }
Exemplo n.º 30
0
    public static function OnBeforePrologHandler()
    {
        global $USER_FIELD_MANAGER;
        if (isset($_REQUEST['action_button']) && !isset($_REQUEST['action'])) {
            $_REQUEST['action'] = $_REQUEST['action_button'];
        }
        if (!isset($_REQUEST['action'])) {
            return;
        }
        $BID = isset($_REQUEST['ID']) ? (int) $_REQUEST['ID'] : 0;
        if ($_REQUEST['action'] == 'asd_prop_export' && $BID > 0 && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($BID)) {
            $strPath = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/tmp/asd.iblock/';
            $strName = 'asd_props_export_' . $BID . '_' . md5(LICENSE_KEY) . '.xml';
            CheckDirPath($strPath);
            if ($hdlOutput = fopen($strPath . $strName, 'wb')) {
                fwrite($hdlOutput, '<?xml version="1.0" encoding="' . SITE_CHARSET . '"?>' . "\n");
                fwrite($hdlOutput, '<asd_iblock_props>' . "\n");
                fwrite($hdlOutput, CASDiblockTools::ExportPropsToXML($BID, $_REQUEST['p']));
                if ($_REQUEST['forms'] == 'Y') {
                    fwrite($hdlOutput, CASDiblockTools::ExportSettingsToXML($BID, array('forms')));
                }
                fwrite($hdlOutput, '</asd_iblock_props>' . "\n");
                fclose($hdlOutput);
            }
            ?>
<script type="text/javascript">
				top.BX.closeWait(); top.BX.WindowManager.Get().AllowClose(); top.BX.WindowManager.Get().Close();
				window.location.href = '/bitrix/tools/asd.iblock/props_export.php?ID=<?php 
            echo $BID;
            ?>
';
			</script><?php 
            die;
        }
        if ($_REQUEST['action'] == 'asd_prop_import' && $BID > 0 && !$_FILES['xml_file']['error'] && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($BID)) {
            CASDiblockTools::ImportPropsFromXML($BID, $_FILES['xml_file']['tmp_name'], $arOldNewID);
            CASDiblockTools::ImportFormsFromXML($BID, $_FILES['xml_file']['tmp_name'], $arOldNewID);
            LocalRedirect('/bitrix/admin/iblock_edit.php?type=' . $_REQUEST['type'] . '&tabControl_active_tab=edit2&lang=' . LANGUAGE_ID . '&ID=' . $BID . '&admin=Y');
        }
        $IBLOCK_ID = 0;
        if (isset($_REQUEST['IBLOCK_ID'])) {
            $IBLOCK_ID = (int) $_REQUEST['IBLOCK_ID'];
            if ($IBLOCK_ID < 0) {
                $IBLOCK_ID = 0;
            }
        }
        if ($_REQUEST['action'] == 'asd_reverse' && $IBLOCK_ID > 0 && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($IBLOCK_ID)) {
            $LIST_MODE = CIBlock::GetArrayByID($IBLOCK_ID, 'LIST_MODE');
            if (!strlen($LIST_MODE)) {
                $LIST_MODE = COption::GetOptionString('iblock', 'combined_list_mode', 'N') == 'Y' ? 'C' : 'S';
            }
            $LIST_MODE = $LIST_MODE == 'C' ? 'S' : 'C';
            $ib = new CIBlock();
            $ib->Update($IBLOCK_ID, array('LIST_MODE' => $LIST_MODE));
            LocalRedirect('/bitrix/admin/' . ($LIST_MODE == 'S' ? 'iblock_element_admin' : 'iblock_list_admin') . '.php?IBLOCK_ID=' . $IBLOCK_ID . '&type=' . htmlspecialcharsbx($_REQUEST['type']) . '&find_section_section=' . intval($_REQUEST['find_section_section']) . '&lang=' . LANGUAGE_ID);
        }
        $strCurPage = $GLOBALS['APPLICATION']->GetCurPage();
        $bElemPage = $strCurPage == '/bitrix/admin/iblock_element_admin.php' || $strCurPage == '/bitrix/admin/cat_product_admin.php';
        $bSectPage = $strCurPage == '/bitrix/admin/iblock_section_admin.php' || $strCurPage == '/bitrix/admin/cat_section_admin.php';
        $bMixPage = $strCurPage == '/bitrix/admin/iblock_list_admin.php';
        $bRightPage = $bElemPage || $bSectPage || $bMixPage;
        $successRedirect = false;
        if ($bRightPage && $_REQUEST['action'] == 'asd_copy_in_list' && strlen($_REQUEST['ID']) > 0) {
            $bDoAction = true;
            $_REQUEST['action'] = 'asd_copy';
            $_REQUEST['asd_ib_dest'] = $IBLOCK_ID;
            $_REQUEST['ID'] = array($_REQUEST['ID']);
        } else {
            $bDoAction = false;
        }
        if ($bRightPage && check_bitrix_sessid() && !empty($_REQUEST['ID']) && ($_SERVER['REQUEST_METHOD'] == 'POST' || $bDoAction) && CModule::IncludeModule('iblock') && ($_REQUEST['action'] == 'asd_copy' || $_REQUEST['action'] == 'asd_move') && isset($_REQUEST['asd_ib_dest']) && (int) $_REQUEST['asd_ib_dest'] > 0 && CASDIblockRights::IsIBlockDisplay($_REQUEST['asd_ib_dest'])) {
            $intSrcIBlockID = $IBLOCK_ID;
            $intDestIBlockID = (int) $_REQUEST['asd_ib_dest'];
            $intSetSectID = 0;
            if (isset($_REQUEST['asd_sect_dest'])) {
                $intSetSectID = (int) $_REQUEST['asd_sect_dest'];
                if ($intSetSectID < 0) {
                    $intSetSectID = 0;
                }
            }
            $boolCreateElement = false;
            $boolCreateSection = false;
            if ($bElemPage || $bMixPage) {
                $boolCreateElement = CASDIblockRights::IsSectionElementCreate($intDestIBlockID, $intSetSectID);
            }
            if ($bSectPage || $bMixPage) {
                $boolCreateSection = CASDIblockRights::IsSectionSectionCreate($intDestIBlockID, $intSetSectID);
            }
            if ($boolCreateElement || $boolCreateSection) {
                $arPropListCache = array();
                $arOldPropListCache = array();
                $arNamePropListCache = array();
                $arOldNamePropListCache = array();
                $boolUFListCache = false;
                $arUFListCache = array();
                $arOldUFListCache = array();
                $arUFEnumCache = array();
                $arOldUFEnumCache = array();
                $arUFNameEnumCache = array();
                $arOldUFNameEnumCache = array();
                $arDestIBlock = CIBlock::GetArrayByID($intDestIBlockID);
                $arDestIBFields = $arDestIBlock['FIELDS'];
                $boolCodeUnique = false;
                if ($arDestIBFields['CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') {
                    $boolCodeUnique = $intSrcIBlockID == $intDestIBlockID;
                }
                $boolSectCodeUnique = false;
                if ($arDestIBFields['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') {
                    $boolSectCodeUnique = $intSrcIBlockID == $intDestIBlockID;
                }
                $boolCatalog = CModule::IncludeModule('catalog');
                $boolCopyCatalog = false;
                $boolNewCatalog = false;
                if ($boolCatalog) {
                    $boolCopyCatalog = is_array(CCatalog::GetByID($intDestIBlockID));
                    $boolNewCatalog = $boolCopyCatalog;
                    if ($boolCopyCatalog) {
                        $boolCopyCatalog = is_array(CCatalog::GetByID($intSrcIBlockID));
                    }
                }
                $el = new CIBlockElement();
                $sc = new CIBlockSection();
                $obEnum = new CUserFieldEnum();
                foreach ($_REQUEST['ID'] as $eID) {
                    $boolCopyElem = false;
                    $boolCopySect = false;
                    if ($bMixPage) {
                        if (substr($eID, 0, 1) != 'E') {
                            $boolCopySect = true;
                        } else {
                            $boolCopyElem = true;
                        }
                        $ID = (int) substr($eID, 1);
                    } else {
                        $boolCopyElem = $bElemPage;
                        $boolCopySect = $bSectPage;
                        $ID = (int) $eID;
                    }
                    if ($boolCreateElement && $boolCopyElem) {
                        if ($obSrc = CIBlockElement::GetByID($ID)->GetNextElement()) {
                            $arSrc = $obSrc->GetFields();
                            $arSrcPr = $obSrc->GetProperties(false, array('EMPTY' => 'N'));
                            $arSrc['PREVIEW_PICTURE'] = (int) $arSrc['PREVIEW_PICTURE'];
                            if ($arSrc['PREVIEW_PICTURE'] > 0) {
                                $arSrc['PREVIEW_PICTURE'] = CFile::MakeFileArray($arSrc['PREVIEW_PICTURE']);
                                if (empty($arSrc['PREVIEW_PICTURE'])) {
                                    $arSrc['PREVIEW_PICTURE'] = false;
                                } else {
                                    $arSrc['PREVIEW_PICTURE']['COPY_FILE'] = 'Y';
                                }
                            } else {
                                $arSrc['PREVIEW_PICTURE'] = false;
                            }
                            $arSrc['DETAIL_PICTURE'] = (int) $arSrc['DETAIL_PICTURE'];
                            if ($arSrc['DETAIL_PICTURE'] > 0) {
                                $arSrc['DETAIL_PICTURE'] = CFile::MakeFileArray($arSrc['DETAIL_PICTURE']);
                                if (empty($arSrc['DETAIL_PICTURE'])) {
                                    $arSrc['DETAIL_PICTURE'] = false;
                                } else {
                                    $arSrc['DETAIL_PICTURE']['COPY_FILE'] = 'Y';
                                }
                            } else {
                                $arSrc['DETAIL_PICTURE'] = false;
                            }
                            $arSrc = array('IBLOCK_ID' => $intDestIBlockID, 'ACTIVE' => $arSrc['ACTIVE'], 'ACTIVE_FROM' => $arSrc['ACTIVE_FROM'], 'ACTIVE_TO' => $arSrc['ACTIVE_TO'], 'SORT' => $arSrc['SORT'], 'NAME' => $arSrc['~NAME'], 'PREVIEW_PICTURE' => $arSrc['PREVIEW_PICTURE'], 'PREVIEW_TEXT' => $arSrc['~PREVIEW_TEXT'], 'PREVIEW_TEXT_TYPE' => $arSrc['PREVIEW_TEXT_TYPE'], 'DETAIL_TEXT' => $arSrc['~DETAIL_TEXT'], 'DETAIL_TEXT_TYPE' => $arSrc['DETAIL_TEXT_TYPE'], 'DETAIL_PICTURE' => $arSrc['DETAIL_PICTURE'], 'WF_STATUS_ID' => $arSrc['WF_STATUS_ID'], 'CODE' => $arSrc['~CODE'], 'TAGS' => $arSrc['~TAGS'], 'XML_ID' => $arSrc['~XML_ID'], 'PROPERTY_VALUES' => array());
                            if ($arDestIBFields['CODE']['IS_REQUIRED'] == 'Y') {
                                if (!strlen($arSrc['CODE'])) {
                                    $arSrc['CODE'] = mt_rand(100000, 1000000);
                                }
                            }
                            if ($arDestIBFields['CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') {
                                $boolElCodeUnique = $boolCodeUnique;
                                if (!$boolCodeUnique) {
                                    $rsCheckItems = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, '=CODE' => $arSrc['CODE'], 'CHECK_PERMISSIONS' => 'N'), false, array('nTopCount' => 1), array('ID', 'IBLOCK_ID'));
                                    if ($arCheck = $rsCheckItems->Fetch()) {
                                        $boolElCodeUnique = true;
                                    }
                                }
                                if ($boolElCodeUnique) {
                                    $arSrc['CODE'] .= mt_rand(100, 10000);
                                }
                            }
                            if ($intSetSectID > 0) {
                                $arSrc['IBLOCK_SECTION_ID'] = $intSetSectID;
                            } elseif ($intSrcIBlockID == $intDestIBlockID) {
                                $arSectionList = array();
                                $rsSections = CIBlockElement::GetElementGroups($ID, true);
                                while ($arSection = $rsSections->Fetch()) {
                                    $arSectionList[] = $arSection['ID'];
                                }
                                $arSrc['IBLOCK_SECTION'] = $arSectionList;
                            }
                            if ($intSrcIBlockID != $intDestIBlockID) {
                                if (empty($arPropListCache)) {
                                    $rsProps = CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, 'PROPERTY_TYPE' => 'L', 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'));
                                    while ($arProp = $rsProps->Fetch()) {
                                        $arValueList = array();
                                        $arNameList = array();
                                        $rsValues = CIBlockProperty::GetPropertyEnum($arProp['ID']);
                                        while ($arValue = $rsValues->Fetch()) {
                                            $arValueList[$arValue['XML_ID']] = $arValue['ID'];
                                            $arNameList[$arValue['ID']] = trim($arValue['VALUE']);
                                        }
                                        if (!empty($arValueList)) {
                                            $arPropListCache[$arProp['CODE']] = $arValueList;
                                        }
                                        if (!empty($arNameList)) {
                                            $arNamePropListCache[$arProp['CODE']] = $arNameList;
                                        }
                                    }
                                }
                                if (empty($arOldPropListCache)) {
                                    $rsProps = CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $intSrcIBlockID, 'PROPERTY_TYPE' => 'L', 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'));
                                    while ($arProp = $rsProps->Fetch()) {
                                        $arValueList = array();
                                        $arNameList = array();
                                        $rsValues = CIBlockProperty::GetPropertyEnum($arProp['ID']);
                                        while ($arValue = $rsValues->Fetch()) {
                                            $arValueList[$arValue['ID']] = $arValue['XML_ID'];
                                            $arNameList[$arValue['ID']] = trim($arValue['VALUE']);
                                        }
                                        if (!empty($arValueList)) {
                                            $arOldPropListCache[$arProp['CODE']] = $arValueList;
                                        }
                                        if (!empty($arNameList)) {
                                            $arOldNamePropListCache[$arProp['CODE']] = $arNameList;
                                        }
                                    }
                                }
                            }
                            foreach ($arSrcPr as &$arProp) {
                                if ($arProp['USER_TYPE'] == 'HTML') {
                                    if (is_array($arProp['~VALUE'])) {
                                        if ($arProp['MULTIPLE'] == 'N') {
                                            $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array('VALUE' => array('TEXT' => $arProp['~VALUE']['TEXT'], 'TYPE' => $arProp['~VALUE']['TYPE']));
                                            if ($arProp['WITH_DESCRIPTION'] == 'Y') {
                                                $arSrc['PROPERTY_VALUES'][$arProp['CODE']]['DESCRIPTION'] = $arProp['~DESCRIPTION'];
                                            }
                                        } else {
                                            if (!empty($arProp['~VALUE'])) {
                                                $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array();
                                                foreach ($arProp['~VALUE'] as $propValueKey => $propValue) {
                                                    $oneNewValue = array('VALUE' => array('TEXT' => $propValue['TEXT'], 'TYPE' => $propValue['TYPE']));
                                                    if ($arProp['WITH_DESCRIPTION'] == 'Y') {
                                                        $oneNewValue['DESCRIPTION'] = $arProp['~DESCRIPTION'][$propValueKey];
                                                    }
                                                    $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $oneNewValue;
                                                    unset($oneNewValue);
                                                }
                                                unset($propValue, $propValueKey);
                                            }
                                        }
                                    }
                                } elseif ($arProp['PROPERTY_TYPE'] == 'F') {
                                    if (is_array($arProp['VALUE'])) {
                                        $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array();
                                        foreach ($arProp['VALUE'] as $propValueKey => $file) {
                                            if ($file > 0) {
                                                $tmpValue = CFile::MakeFileArray($file);
                                                if (!is_array($tmpValue)) {
                                                    continue;
                                                }
                                                if ($arProp['WITH_DESCRIPTION'] == 'Y') {
                                                    $tmpValue = array('VALUE' => $tmpValue, 'DESCRIPTION' => $arProp['~DESCRIPTION'][$propValueKey]);
                                                }
                                                $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $tmpValue;
                                            }
                                        }
                                    } elseif ($arProp['VALUE'] > 0) {
                                        $tmpValue = CFile::MakeFileArray($arProp['VALUE']);
                                        if (is_array($tmpValue)) {
                                            if ($arProp['WITH_DESCRIPTION'] == 'Y') {
                                                $tmpValue = array('VALUE' => $tmpValue, 'DESCRIPTION' => $arProp['~DESCRIPTION']);
                                            }
                                            $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $tmpValue;
                                        }
                                    }
                                } elseif ($arProp['PROPERTY_TYPE'] == 'L') {
                                    if (!empty($arProp['VALUE_ENUM_ID'])) {
                                        if ($intSrcIBlockID == $arSrc['IBLOCK_ID']) {
                                            $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['VALUE_ENUM_ID'];
                                        } else {
                                            if (isset($arPropListCache[$arProp['CODE']]) && isset($arOldPropListCache[$arProp['CODE']])) {
                                                if (is_array($arProp['VALUE_ENUM_ID'])) {
                                                    $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array();
                                                    foreach ($arProp['VALUE_ENUM_ID'] as &$intValueID) {
                                                        $strValueXmlID = $arOldPropListCache[$arProp['CODE']][$intValueID];
                                                        if (isset($arPropListCache[$arProp['CODE']][$strValueXmlID])) {
                                                            $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $arPropListCache[$arProp['CODE']][$strValueXmlID];
                                                        } else {
                                                            $strValueName = $arOldNamePropListCache[$arProp['CODE']][$intValueID];
                                                            $intValueKey = array_search($strValueName, $arNamePropListCache[$arProp['CODE']]);
                                                            if ($intValueKey !== false) {
                                                                $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $intValueKey;
                                                            }
                                                        }
                                                    }
                                                    if (isset($intValueID)) {
                                                        unset($intValueID);
                                                    }
                                                    if (empty($arSrc['PROPERTY_VALUES'][$arProp['CODE']])) {
                                                        unset($arSrc['PROPERTY_VALUES'][$arProp['CODE']]);
                                                    }
                                                } else {
                                                    $strValueXmlID = $arOldPropListCache[$arProp['CODE']][$arProp['VALUE_ENUM_ID']];
                                                    if (isset($arPropListCache[$arProp['CODE']][$strValueXmlID])) {
                                                        $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arPropListCache[$arProp['CODE']][$strValueXmlID];
                                                    } else {
                                                        $strValueName = $arOldNamePropListCache[$arProp['CODE']][$arProp['VALUE_ENUM_ID']];
                                                        $intValueKey = array_search($strValueName, $arNamePropListCache[$arProp['CODE']]);
                                                        if ($intValueKey !== false) {
                                                            $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $intValueKey;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } elseif ($arProp['PROPERTY_TYPE'] == 'S' || $arProp['PROPERTY_TYPE'] == 'N') {
                                    if ($arProp['MULTIPLE'] == 'Y') {
                                        if (is_array($arProp['~VALUE'])) {
                                            if ($arProp['WITH_DESCRIPTION'] == 'Y') {
                                                $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array();
                                                foreach ($arProp['~VALUE'] as $propValueKey => $propValue) {
                                                    $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = array('VALUE' => $propValue, 'DESCRIPTION' => $arProp['~DESCRIPTION'][$propValueKey]);
                                                }
                                                unset($propValue, $propValueKey);
                                            } else {
                                                $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['~VALUE'];
                                            }
                                        }
                                    } else {
                                        $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['WITH_DESCRIPTION'] == 'Y' ? array('VALUE' => $arProp['~VALUE'], 'DESCRIPTION' => $arProp['~DESCRIPTION']) : $arProp['~VALUE'];
                                    }
                                } else {
                                    $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['~VALUE'];
                                }
                            }
                            if (isset($arProp)) {
                                unset($arProp);
                            }
                            AddMessage2Log($arSrc['PROPERTY_VALUES']);
                            $intNewID = $el->Add($arSrc, true, true, true);
                            if ($intNewID) {
                                if ($boolCatalog && $boolCopyCatalog) {
                                    $priceRes = CPrice::GetListEx(array(), array('PRODUCT_ID' => $ID), false, false, array('PRODUCT_ID', 'EXTRA_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO'));
                                    while ($arPrice = $priceRes->Fetch()) {
                                        $arPrice['PRODUCT_ID'] = $intNewID;
                                        CPrice::Add($arPrice);
                                    }
                                }
                                if ($boolCatalog && $boolNewCatalog) {
                                    $arProduct = array('ID' => $intNewID);
                                    if ($boolCopyCatalog) {
                                        $productRes = CCatalogProduct::GetList(array(), array('ID' => $ID), false, false, array('QUANTITY', 'QUANTITY_TRACE_ORIG', 'CAN_BUY_ZERO_ORIG', 'NEGATIVE_AMOUNT_TRACE_ORIG', 'SUBSCRIBE_ORIG', 'WEIGHT', 'PRICE_TYPE', 'RECUR_SCHEME_TYPE', 'RECUR_SCHEME_LENGTH', 'TRIAL_PRICE_ID', 'WITHOUT_ORDER', 'SELECT_BEST_PRICE', 'VAT_ID', 'VAT_INCLUDED', 'WIDTH', 'LENGTH', 'HEIGHT', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY', 'MEASURE'));
                                        if ($arCurProduct = $productRes->Fetch()) {
                                            $arProduct = $arCurProduct;
                                            $arProduct['ID'] = $intNewID;
                                            $arProduct['QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE_ORIG'];
                                            $arProduct['CAN_BUY_ZERO'] = $arProduct['CAN_BUY_ZERO_ORIG'];
                                            $arProduct['NEGATIVE_AMOUNT_TRACE'] = $arProduct['NEGATIVE_AMOUNT_TRACE_ORIG'];
                                            if (isset($arProduct['SUBSCRIBE_ORIG'])) {
                                                $arProduct['SUBSCRIBE'] = $arProduct['SUBSCRIBE_ORIG'];
                                            }
                                            foreach ($arProduct as $productKey => $productValue) {
                                                if ($productValue === null) {
                                                    unset($arProduct[$productKey]);
                                                }
                                            }
                                        }
                                    }
                                    CCatalogProduct::Add($arProduct, false);
                                }
                                if ($_REQUEST['action'] == 'asd_move') {
                                    if (CASDIblockRights::IsElementDelete($intSrcIBlockID, $ID)) {
                                        $el->Delete($ID);
                                    } else {
                                        CASDiblock::$error .= '[' . $ID . '] ' . GetMessage('ASD_ACTION_ERR_DELETE_ELEMENT_RIGHTS') . "\n";
                                    }
                                }
                            } else {
                                CASDiblock::$error .= '[' . $ID . '] ' . $el->LAST_ERROR . "\n";
                            }
                        }
                    }
                    if ($boolCreateSection && $boolCopySect) {
                        if ($_REQUEST['action'] == 'asd_move') {
                            continue;
                        }
                        $rsSections = CIBlockSection::GetList(array(), array('ID' => $ID, 'IBLOCK_ID' => $intSrcIBlockID), false, array('ID', 'NAME', 'XML_ID', 'CODE', 'IBLOCK_SECTION_ID', 'IBLOCK_ID', 'ACTIVE', 'SORT', 'PICTURE', 'DESCRIPTION', 'DESCRIPTION_TYPE', 'DETAIL_PICTURE', 'SOCNET_GROUP_ID', 'UF_*'));
                        if ($arSrcSect = $rsSections->Fetch()) {
                            $arDestSect = $arSrcSect;
                            unset($arDestSect['ID']);
                            $arDestSect['IBLOCK_ID'] = $intDestIBlockID;
                            if ($arDestIBFields['SECTION_CODE']['IS_REQUIRED'] == 'Y') {
                                if (!strlen($arDestSect['CODE'])) {
                                    $arDestSect['CODE'] = mt_rand(100000, 1000000);
                                }
                            }
                            if ($arDestIBFields['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') {
                                $boolScCodeUnique = $boolSectCodeUnique;
                                if (!$boolSectCodeUnique) {
                                    $rsCheckItems = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, '=CODE' => $arSrc['CODE'], 'CHECK_PERMISSIONS' => 'N'), false, array('nTopCount' => 1), array('ID', 'IBLOCK_ID'));
                                    if ($arCheck = $rsCheckItems->Fetch()) {
                                        $boolScCodeUnique = true;
                                    }
                                }
                                if ($boolScCodeUnique) {
                                    $arDestSect['CODE'] .= mt_rand(100, 10000);
                                }
                            }
                            if ($intSetSectID > 0) {
                                $arDestSect['IBLOCK_SECTION_ID'] = $intSetSectID;
                            } elseif ($intSrcIBlockID != $intDestIBlockID) {
                                $arDestSect['IBLOCK_SECTION_ID'] = 0;
                            }
                            $arDestSect['PICTURE'] = (int) $arDestSect['PICTURE'];
                            if ($arDestSect['PICTURE'] > 0) {
                                $arDestSect['PICTURE'] = CFile::MakeFileArray($arDestSect['PICTURE']);
                                if (empty($arDestSect['PICTURE'])) {
                                    $arDestSect['PICTURE'] = false;
                                } else {
                                    $arDestSect['PICTURE']['COPY_FILE'] = 'Y';
                                }
                            } else {
                                $arDestSect['PICTURE'] = false;
                            }
                            $arDestSect['DETAIL_PICTURE'] = (int) $arDestSect['DETAIL_PICTURE'];
                            if ($arDestSect['DETAIL_PICTURE'] > 0) {
                                $arDestSect['DETAIL_PICTURE'] = CFile::MakeFileArray($arDestSect['DETAIL_PICTURE']);
                                if (empty($arDestSect['DETAIL_PICTURE'])) {
                                    $arDestSect['DETAIL_PICTURE'] = false;
                                } else {
                                    $arDestSect['DETAIL_PICTURE']['COPY_FILE'] = 'Y';
                                }
                            } else {
                                $arDestSect['DETAIL_PICTURE'] = false;
                            }
                            if (!$boolUFListCache) {
                                $boolUFListCache = true;
                                $arUFListCache = $USER_FIELD_MANAGER->GetUserFields('IBLOCK_' . $intDestIBlockID . '_SECTION');
                                if (!empty($arUFListCache)) {
                                    if ($intSrcIBlockID != $intDestIBlockID) {
                                        $arOldUFListCache = $USER_FIELD_MANAGER->GetUserFields('IBLOCK_' . $intSrcIBlockID . '_SECTION');
                                        if (empty($arOldUFListCache)) {
                                            $arUFListCache = array();
                                        }
                                    } else {
                                        $arOldUFListCache = $arUFListCache;
                                    }
                                }
                                if (!empty($arUFListCache)) {
                                    if ($intSrcIBlockID != $intDestIBlockID) {
                                        foreach ($arUFListCache as &$arOneUserField) {
                                            if ('enum' == $arOneUserField['USER_TYPE']['BASE_TYPE']) {
                                                $arUFEnumCache[$arOneUserField['FIELD_NAME']] = array();
                                                $arUFNameEnumCache[$arOneUserField['FIELD_NAME']] = array();
                                                $rsEnum = $obEnum->GetList(array(), array('USER_FIELD_ID' => $arOneUserField['ID']));
                                                while ($arEnum = $rsEnum->Fetch()) {
                                                    $arUFEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['XML_ID']] = $arEnum['ID'];
                                                    $arUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = trim($arEnum['VALUE']);
                                                }
                                            }
                                        }
                                        if (isset($arOneUserField)) {
                                            unset($arOneUserField);
                                        }
                                        foreach ($arOldUFListCache as &$arOneUserField) {
                                            if ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'enum') {
                                                $arOldUFEnumCache[$arOneUserField['FIELD_NAME']] = array();
                                                $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']] = array();
                                                $rsEnum = $obEnum->GetList(array(), array('USER_FIELD_ID' => $arOneUserField['ID']));
                                                while ($arEnum = $rsEnum->Fetch()) {
                                                    $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = $arEnum['XML_ID'];
                                                    $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = trim($arEnum['VALUE']);
                                                }
                                            }
                                        }
                                        if (isset($arOneUserField)) {
                                            unset($arOneUserField);
                                        }
                                    }
                                }
                            }
                            if (!empty($arUFListCache)) {
                                foreach ($arUFListCache as &$arOneUserField) {
                                    if (!isset($arDestSect[$arOneUserField['FIELD_NAME']])) {
                                        continue;
                                    }
                                    if ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'file') {
                                        if (!empty($arDestSect[$arOneUserField['FIELD_NAME']])) {
                                            if (is_array($arDestSect[$arOneUserField['FIELD_NAME']])) {
                                                $arNewFileList = array();
                                                foreach ($arDestSect[$arOneUserField['FIELD_NAME']] as &$intFileID) {
                                                    $arNewFile = false;
                                                    $intFileID = (int) $intFileID;
                                                    if ($intFileID > 0) {
                                                        $arNewFile = CFile::MakeFileArray($intFileID);
                                                    }
                                                    if (!empty($arNewFile)) {
                                                        $arNewFileList[] = $arNewFile;
                                                    }
                                                }
                                                if (isset($intFileID)) {
                                                    unset($intFileID);
                                                }
                                                $arDestSect[$arOneUserField['FIELD_NAME']] = !empty($arNewFileList) ? $arNewFileList : false;
                                            } else {
                                                $arNewFile = false;
                                                $intFileID = (int) $arDestSect[$arOneUserField['FIELD_NAME']];
                                                if ($intFileID > 0) {
                                                    $arNewFile = CFile::MakeFileArray($intFileID);
                                                }
                                                $arDestSect[$arOneUserField['FIELD_NAME']] = !empty($arNewFile) ? $arNewFile : false;
                                            }
                                        } else {
                                            $arDestSect[$arOneUserField['FIELD_NAME']] = false;
                                        }
                                    } elseif ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'enum') {
                                        if (!empty($arDestSect[$arOneUserField['FIELD_NAME']])) {
                                            if ($intSrcIBlockID != $intDestIBlockID) {
                                                if (array_key_exists($arOneUserField['FIELD_NAME'], $arUFEnumCache) && array_key_exists($arOneUserField['FIELD_NAME'], $arOldUFEnumCache)) {
                                                    if (is_array($arDestSect[$arOneUserField['FIELD_NAME']])) {
                                                        $arNewEnumList = array();
                                                        foreach ($arDestSect[$arOneUserField['FIELD_NAME']] as &$intValueID) {
                                                            $strValueXmlID = $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$intValueID];
                                                            if (array_key_exists($strValueXmlID, $arUFEnumCache[$arOneUserField['FIELD_NAME']])) {
                                                                $arNewEnumList[] = $arUFEnumCache[$arOneUserField['FIELD_NAME']][$strValueXmlID];
                                                            } else {
                                                                $strValueName = $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$intValueID];
                                                                $intValueKey = array_search($strValueName, $arUFNameEnumCache[$arOneUserField['FIELD_NAME']]);
                                                                if ($intValueKey !== false) {
                                                                    $arNewEnumList[] = $intValueKey;
                                                                }
                                                            }
                                                        }
                                                        if (isset($intValueID)) {
                                                            unset($intValueID);
                                                        }
                                                        if (!empty($arNewEnumList)) {
                                                            $arDestSect[$arOneUserField['FIELD_NAME']] = $arNewEnumList;
                                                        }
                                                    } else {
                                                        $strValueXmlID = $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$arDestSect[$arOneUserField['FIELD_NAME']]];
                                                        if (array_key_exists($strValueXmlID, $arUFEnumCache[$arOneUserField['FIELD_NAME']])) {
                                                            $arDestSect[$arOneUserField['FIELD_NAME']] = $arUFEnumCache[$arOneUserField['FIELD_NAME']][$strValueXmlID];
                                                        } else {
                                                            $strValueName = $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arDestSect[$arOneUserField['FIELD_NAME']]];
                                                            $intValueKey = array_search($strValueName, $arUFNameEnumCache[$arOneUserField['FIELD_NAME']]);
                                                            if ($intValueKey !== false) {
                                                                $arDestSect[$arOneUserField['FIELD_NAME']] = $intValueKey;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            $arDestSect[$arOneUserField['FIELD_NAME']] = false;
                                        }
                                    }
                                }
                                if (isset($arOneUserField)) {
                                    unset($arOneUserField);
                                }
                            }
                            $intNewID = $sc->Add($arDestSect);
                            if (!$intNewID) {
                                CASDiblock::$error .= '[' . $ID . '] ' . $sc->LAST_ERROR . "\n";
                            }
                        }
                    }
                }
                $successRedirect = true;
            }
            unset($_REQUEST['action']);
            if (isset($_REQUEST['action_button'])) {
                unset($_REQUEST['action_button']);
            }
            if ($successRedirect) {
                LocalRedirect($GLOBALS['APPLICATION']->GetCurPageParam('', array('action', 'action_button', 'asd_ib_dest', 'asd_sect_dest', 'ID')));
            }
        }
        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'asd_remove' && $IBLOCK_ID > 0 && isset($_REQUEST['find_section_section']) && check_bitrix_sessid() && CASDIblockRights::IsIBlockDisplay($IBLOCK_ID)) {
            $intSectionID = (int) $_REQUEST['find_section_section'];
            if ($intSectionID > 0) {
                $strCurPage = $GLOBALS['APPLICATION']->GetCurPage();
                $bElemPage = $strCurPage == '/bitrix/admin/iblock_element_admin.php' || $strCurPage == '/bitrix/admin/cat_product_admin.php';
                $bMixPage = $strCurPage == '/bitrix/admin/iblock_list_admin.php';
                if ($bElemPage || $bMixPage) {
                    foreach ($_REQUEST['ID'] as $eID) {
                        if ($bMixPage) {
                            if (substr($eID, 0, 1) != 'E') {
                                continue;
                            }
                            $ID = (int) substr($eID, 1);
                        } else {
                            $ID = (int) $eID;
                        }
                        if ($ID <= 0) {
                            continue;
                        }
                        if (CASDIblockRights::IsElementEdit($IBLOCK_ID, $ID)) {
                            $arSectionList = array();
                            $rsSections = CIBlockElement::GetElementGroups($ID, true);
                            while ($arSection = $rsSections->Fetch()) {
                                $arSection['ID'] = (int) $arSection['ID'];
                                if ($arSection['ID'] != $intSectionID) {
                                    $arSectionList[] = $arSection['ID'];
                                }
                            }
                            CIBlockElement::SetElementSection($ID, $arSectionList, false);
                            $successRedirect = true;
                        }
                    }
                }
            }
            unset($_REQUEST['action']);
            if (isset($_REQUEST['action_button'])) {
                unset($_REQUEST['action_button']);
            }
            if ($successRedirect) {
                LocalRedirect($GLOBALS['APPLICATION']->GetCurPageParam('', array('action', 'action_button')));
            }
        }
    }