} if (isset($_POST["LIST_DEF"]) && is_array($_POST["LIST_DEF"])) { foreach ($arField["LIST"] as $i => $arEnum) { $arField["LIST"][$i]["DEF"] = "N"; } foreach ($_POST["LIST_DEF"] as $def) { $def = intval($def); if ($def > 0 && isset($arField["LIST"][$def])) { $arField["LIST"][$def]["DEF"] = "Y"; } } } if (!$strError) { if ($arResult["FIELD_ID"]) { unset($arField["TYPE"]); $arResult["FIELD_ID"] = $obList->UpdateField($arResult["FIELD_ID"], $arField); } else { $arResult["FIELD_ID"] = $obList->AddField($arField); } //Clear components cache $CACHE_MANAGER->ClearByTag("lists_list_" . $arIBlock["ID"]); $tab_name = $arResult["FORM_ID"] . "_active_tab"; //And go to proper page if (isset($_POST["save"])) { LocalRedirect($arResult["~LIST_FIELDS_URL"]); } elseif ($arResult["FIELD_ID"]) { LocalRedirect(CHTTP::urlAddParams(str_replace(array("#list_id#", "#field_id#", "#group_id#"), array($arResult["IBLOCK_ID"], $arResult["FIELD_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_FIELD_EDIT_URL"]), array($tab_name => $_POST[$tab_name]), array("skip_empty" => true, "encode" => true))); } else { LocalRedirect($arResult["~LIST_FIELDS_URL"]); } } else {
$arResult["~LIST_FIELD_EDIT_URL"] = str_replace(array("#list_id#", "#field_id#", "#group_id#"), array($arResult["IBLOCK_ID"], "0", $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_FIELD_EDIT_URL"]); $arResult["LIST_FIELD_EDIT_URL"] = htmlspecialcharsbx($arResult["~LIST_FIELD_EDIT_URL"]); //Form submitted if ($_SERVER["REQUEST_METHOD"] == "POST" && check_bitrix_sessid() && isset($_POST["action_button_" . $arResult["GRID_ID"]])) { $obList = new CList($arIBlock["ID"]); if ($_POST["action_button_" . $arResult["GRID_ID"]] == "delete" && isset($_POST["ID"]) && is_array($_POST["ID"])) { foreach ($_POST["ID"] as $ID) { $obList->DeleteField($ID); } //Clear components cache $CACHE_MANAGER->ClearByTag("lists_list_" . $arResult["IBLOCK_ID"]); } if ($_POST["action_button_" . $arResult["GRID_ID"]] == "edit" && isset($_POST["FIELDS"]) && is_array($_POST["FIELDS"])) { foreach ($_POST["FIELDS"] as $ID => $tmp) { $arField = array("SORT" => $_POST["FIELDS"][$ID]["SORT"], "NAME" => $_POST["FIELDS"][$ID]["NAME"], "IS_REQUIRED" => $_POST["FIELDS"][$ID]["IS_REQUIRED"], "MULTIPLE" => $_POST["FIELDS"][$ID]["MULTIPLE"]); $obList->UpdateField($ID, $arField); } //Clear components cache $CACHE_MANAGER->ClearByTag("lists_list_" . $arResult["IBLOCK_ID"]); } if (!isset($_POST["AJAX_CALL"])) { LocalRedirect($arResult["LIST_FIELDS_URL"]); } } global $CACHE_MANAGER; if ($this->StartResultCache(false)) { $CACHE_MANAGER->StartTagCache($this->GetCachePath()); $CACHE_MANAGER->RegisterTag("lists_list_" . $arIBlock["ID"]); $obList = new CList($arIBlock["ID"]); $arResult["TYPES"] = $obList->GetAllTypes(); $arFields = $obList->GetFields();
private static function createIBlock($iblockType, $iblock, $pictureType, $picture, $siteId = null) { if (is_null($siteId)) { $siteId = \CSite::GetDefSite(); } $db = \CIBlock::GetList(array(), array("IBLOCK_TYPE_ID" => $iblockType, "CODE" => $iblock["CODE"], "CHECK_PERMISSIONS" => "N", "SITE_ID" => $siteId)); if ($res = $db->Fetch()) { return $res["ID"]; } $fields = array("NAME" => $iblock["NAME"], "DESCRIPTION" => $iblock["DESCRIPTION"], "IBLOCK_TYPE_ID" => $iblockType, "SORT" => $iblock["SORT"], "CODE" => $iblock["CODE"], "WORKFLOW" => "N", "ELEMENTS_NAME" => $iblock["ELEMENTS_NAME"], "ELEMENT_NAME" => $iblock["ELEMENT_NAME"], "ELEMENT_ADD" => $iblock["ELEMENT_ADD"], "ELEMENT_EDIT" => $iblock["ELEMENT_EDIT"], "ELEMENT_DELETE" => $iblock["ELEMENT_DELETE"], "SECTIONS_NAME" => $iblock["SECTIONS_NAME"], "SECTION_NAME" => $iblock["SECTION_NAME"], "SECTION_ADD" => $iblock["SECTION_ADD"], "SECTION_EDIT" => $iblock["SECTION_EDIT"], "SECTION_DELETE" => $iblock["SECTION_DELETE"], "BIZPROC" => "Y", "SITE_ID" => array($siteId), "RIGHTS_MODE" => "E"); if ($iblock["SOCNET_GROUP_ID"]) { $fields["SOCNET_GROUP_ID"] = $iblock["SOCNET_GROUP_ID"]; } static $exts = array("image/jpeg" => "jpg", "image/png" => "png", "image/gif" => "gif"); if (!empty($picture) && isset($exts[$pictureType])) { $fn = \CTempFile::GetFileName(); Main\IO\Directory::createDirectory($fn); $fn .= md5(mt_rand()) . "." . $exts[$pictureType]; $f = fopen($fn, "wb"); fwrite($f, $picture); fclose($f); $fields["PICTURE"] = \CFile::MakeFileArray($fn); } $ob = new \CIBlock(); $res = $ob->Add($fields); if ($res) { self::createIBlockRights($res); $list = new \CList($res); if (isset($iblock["~NAME_FIELD"])) { $list->UpdateField("NAME", $iblock["~NAME_FIELD"]); } $list->Save(); \CLists::setLiveFeed(1, $res); return $res; } return 0; }