function Update($ID, $arFields, $bResort = true, $bUpdateSearch = true, $bResizePictures = false) { global $USER, $DB, $APPLICATION; $ID = (int) $ID; $db_record = CIBlockSection::GetList(array(), array("ID" => $ID, "CHECK_PERMISSIONS" => "N")); if (!($db_record = $db_record->Fetch())) { return false; } if (is_set($arFields, "EXTERNAL_ID")) { $arFields["XML_ID"] = $arFields["EXTERNAL_ID"]; } unset($arFields["GLOBAL_ACTIVE"]); unset($arFields["DEPTH_LEVEL"]); unset($arFields["LEFT_MARGIN"]); unset($arFields["RIGHT_MARGIN"]); unset($arFields["IBLOCK_ID"]); unset($arFields["DATE_CREATE"]); unset($arFields["CREATED_BY"]); $arIBlock = CIBlock::GetArrayByID($db_record["IBLOCK_ID"]); if ($bResizePictures) { $arDef = $arIBlock["FIELDS"]["SECTION_PICTURE"]["DEFAULT_VALUE"]; if ($arDef["DELETE_WITH_DETAIL"] === "Y" && $arFields["DETAIL_PICTURE"]["del"] === "Y") { $arFields["PICTURE"]["del"] = "Y"; } if ($arDef["FROM_DETAIL"] === "Y" && ($arFields["PICTURE"]["size"] <= 0 || $arDef["UPDATE_WITH_DETAIL"] === "Y") && is_array($arFields["DETAIL_PICTURE"]) && $arFields["DETAIL_PICTURE"]["size"] > 0) { if ($arFields["PICTURE"]["del"] !== "Y" && $arDef["UPDATE_WITH_DETAIL"] !== "Y") { $arOldSection = $db_record; } else { $arOldSection = false; } if (!$arOldSection || !$arOldSection["PICTURE"]) { $arNewPreview = $arFields["DETAIL_PICTURE"]; $arNewPreview["COPY_FILE"] = "Y"; $arNewPreview["description"] = $arFields["PICTURE"]["description"]; $arFields["PICTURE"] = $arNewPreview; } } if (array_key_exists("PICTURE", $arFields) && is_array($arFields["PICTURE"]) && $arFields["PICTURE"]["size"] > 0 && $arDef["SCALE"] === "Y") { $arNewPicture = CIBlock::ResizePicture($arFields["PICTURE"], $arDef); if (is_array($arNewPicture)) { $arNewPicture["description"] = $arFields["PICTURE"]["description"]; $arFields["PICTURE"] = $arNewPicture; } elseif ($arDef["IGNORE_ERRORS"] !== "Y") { unset($arFields["PICTURE"]); $strWarning .= GetMessage("IBLOCK_FIELD_PREVIEW_PICTURE") . ": " . $arNewPicture . "<br>"; } } if (array_key_exists("PICTURE", $arFields) && is_array($arFields["PICTURE"]) && $arDef["USE_WATERMARK_FILE"] === "Y") { if (strlen($arFields["PICTURE"]["tmp_name"]) > 0 && ($arFields["PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"] || $arFields["PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["PICTURE"]["tmp_name"], $tmp_name); $arFields["PICTURE"]["copy"] = true; $arFields["PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_FILE_POSITION"], "type" => "file", "size" => "real", "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100), "file" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_FILE"]))); } if (array_key_exists("PICTURE", $arFields) && is_array($arFields["PICTURE"]) && $arDef["USE_WATERMARK_TEXT"] === "Y") { if (strlen($arFields["PICTURE"]["tmp_name"]) > 0 && ($arFields["PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"] || $arFields["PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["PICTURE"]["tmp_name"], $tmp_name); $arFields["PICTURE"]["copy"] = true; $arFields["PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_TEXT_POSITION"], "type" => "text", "coefficient" => $arDef["WATERMARK_TEXT_SIZE"], "text" => $arDef["WATERMARK_TEXT"], "font" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]), "color" => $arDef["WATERMARK_TEXT_COLOR"])); } $arDef = $arIBlock["FIELDS"]["SECTION_DETAIL_PICTURE"]["DEFAULT_VALUE"]; if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["SCALE"] === "Y") { $arNewPicture = CIBlock::ResizePicture($arFields["DETAIL_PICTURE"], $arDef); if (is_array($arNewPicture)) { $arNewPicture["description"] = $arFields["DETAIL_PICTURE"]["description"]; $arFields["DETAIL_PICTURE"] = $arNewPicture; } elseif ($arDef["IGNORE_ERRORS"] !== "Y") { unset($arFields["DETAIL_PICTURE"]); $strWarning .= GetMessage("IBLOCK_FIELD_DETAIL_PICTURE") . ": " . $arNewPicture . "<br>"; } } if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["USE_WATERMARK_FILE"] === "Y") { if (strlen($arFields["DETAIL_PICTURE"]["tmp_name"]) > 0 && ($arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PICTURE"]["tmp_name"] || $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name); $arFields["DETAIL_PICTURE"]["copy"] = true; $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_FILE_POSITION"], "type" => "file", "size" => "real", "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100), "file" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_FILE"]), "fill" => "resize")); } if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["USE_WATERMARK_TEXT"] === "Y") { if (strlen($arFields["DETAIL_PICTURE"]["tmp_name"]) > 0 && ($arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PICTURE"]["tmp_name"] || $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name); $arFields["DETAIL_PICTURE"]["copy"] = true; $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_TEXT_POSITION"], "type" => "text", "coefficient" => $arDef["WATERMARK_TEXT_SIZE"], "text" => $arDef["WATERMARK_TEXT"], "font" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]), "color" => $arDef["WATERMARK_TEXT_COLOR"])); } } $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\SectionTemplates($db_record["IBLOCK_ID"], $db_record["ID"]); if (is_set($arFields, "PICTURE")) { if (strlen($arFields["PICTURE"]["name"]) <= 0 && strlen($arFields["PICTURE"]["del"]) <= 0) { unset($arFields["PICTURE"]); } else { $arFields["PICTURE"]["old_file"] = $db_record["PICTURE"]; $arFields["PICTURE"]["MODULE_ID"] = "iblock"; $arFields["PICTURE"]["name"] = \Bitrix\Iblock\Template\Helper::makeFileName($ipropTemplates, "SECTION_PICTURE_FILE_NAME", array_merge($db_record, $arFields), $arFields["PICTURE"]); } } if (is_set($arFields, "DETAIL_PICTURE")) { if (strlen($arFields["DETAIL_PICTURE"]["name"]) <= 0 && strlen($arFields["DETAIL_PICTURE"]["del"]) <= 0) { unset($arFields["DETAIL_PICTURE"]); } else { $arFields["DETAIL_PICTURE"]["old_file"] = $db_record["DETAIL_PICTURE"]; $arFields["DETAIL_PICTURE"]["MODULE_ID"] = "iblock"; $arFields["DETAIL_PICTURE"]["name"] = \Bitrix\Iblock\Template\Helper::makeFileName($ipropTemplates, "SECTION_DETAIL_PICTURE_FILE_NAME", array_merge($db_record, $arFields), $arFields["DETAIL_PICTURE"]); } } if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") { $arFields["ACTIVE"] = "N"; } if (is_set($arFields, "DESCRIPTION_TYPE") && $arFields["DESCRIPTION_TYPE"] != "html") { $arFields["DESCRIPTION_TYPE"] = "text"; } if (isset($arFields["IBLOCK_SECTION_ID"])) { $arFields["IBLOCK_SECTION_ID"] = intval($arFields["IBLOCK_SECTION_ID"]); if ($arFields["IBLOCK_SECTION_ID"] <= 0) { $arFields["IBLOCK_SECTION_ID"] = false; } } $DESC_tmp = is_set($arFields, "DESCRIPTION") ? $arFields["DESCRIPTION"] : $db_record["DESCRIPTION"]; $DESC_TYPE_tmp = is_set($arFields, "DESCRIPTION_TYPE") ? $arFields["DESCRIPTION_TYPE"] : $db_record["DESCRIPTION_TYPE"]; $arFields["SEARCHABLE_CONTENT"] = ToUpper((is_set($arFields, "NAME") ? $arFields["NAME"] : $db_record["NAME"]) . "\r\n" . ($DESC_TYPE_tmp == "html" ? HTMLToTxt($DESC_tmp) : $DESC_tmp)); if (is_object($USER)) { if (!isset($arFields["MODIFIED_BY"]) || intval($arFields["MODIFIED_BY"]) <= 0) { $arFields["MODIFIED_BY"] = intval($USER->GetID()); } } if (!$this->CheckFields($arFields, $ID)) { $Result = false; $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR; } elseif (!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("IBLOCK_" . $db_record["IBLOCK_ID"] . "_SECTION", $ID, $arFields)) { $Result = false; $err = $APPLICATION->GetException(); if (is_object($err)) { $this->LAST_ERROR .= str_replace("<br><br>", "<br>", $err->GetString() . "<br>"); } $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR; } else { if (array_key_exists("PICTURE", $arFields)) { $SAVED_PICTURE = $arFields["PICTURE"]; CFile::SaveForDB($arFields, "PICTURE", "iblock"); } if (array_key_exists("DETAIL_PICTURE", $arFields)) { $SAVED_DETAIL_PICTURE = $arFields["DETAIL_PICTURE"]; CFile::SaveForDB($arFields, "DETAIL_PICTURE", "iblock"); } unset($arFields["ID"]); $strUpdate = $DB->PrepareUpdate("b_iblock_section", $arFields, "iblock"); if (array_key_exists("PICTURE", $arFields)) { $arFields["PICTURE"] = $SAVED_PICTURE; } if (array_key_exists("DETAIL_PICTURE", $arFields)) { $arFields["DETAIL_PICTURE"] = $SAVED_DETAIL_PICTURE; } CIBlock::_transaction_lock($db_record["IBLOCK_ID"]); if (strlen($strUpdate) > 0) { $strSql = "UPDATE b_iblock_section SET " . $strUpdate . " WHERE ID = " . $ID; $arBinds = array(); if (array_key_exists("DESCRIPTION", $arFields)) { $arBinds["DESCRIPTION"] = $arFields["DESCRIPTION"]; } if (array_key_exists("SEARCHABLE_CONTENT", $arFields)) { $arBinds["SEARCHABLE_CONTENT"] = $arFields["SEARCHABLE_CONTENT"]; } $DB->QueryBind($strSql, $arBinds); } if ($bResort) { //Move inside the tree if (isset($arFields["SORT"]) && $arFields["SORT"] != $db_record["SORT"] || isset($arFields["NAME"]) && $arFields["NAME"] != $db_record["NAME"] || isset($arFields["IBLOCK_SECTION_ID"]) && $arFields["IBLOCK_SECTION_ID"] != $db_record["IBLOCK_SECTION_ID"]) { //First "delete" from the tree $distance = intval($db_record["RIGHT_MARGIN"]) - intval($db_record["LEFT_MARGIN"]) + 1; $DB->Query("\n\t\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t\t,LEFT_MARGIN = -LEFT_MARGIN\n\t\t\t\t\t\t\t,RIGHT_MARGIN = -RIGHT_MARGIN\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tIBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tAND LEFT_MARGIN >= " . intval($db_record["LEFT_MARGIN"]) . "\n\t\t\t\t\t\t\tAND LEFT_MARGIN <= " . intval($db_record["RIGHT_MARGIN"]) . "\n\t\t\t\t\t"); $DB->Query("\n\t\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t\t,RIGHT_MARGIN = RIGHT_MARGIN - " . $distance . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tIBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tAND RIGHT_MARGIN > " . $db_record["RIGHT_MARGIN"] . "\n\t\t\t\t\t"); $DB->Query("\n\t\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t\t,LEFT_MARGIN = LEFT_MARGIN - " . $distance . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tIBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tAND LEFT_MARGIN > " . $db_record["LEFT_MARGIN"] . "\n\t\t\t\t\t"); //Next insert into the the tree almost as we do when inserting the new one $PARENT_ID = isset($arFields["IBLOCK_SECTION_ID"]) ? intval($arFields["IBLOCK_SECTION_ID"]) : intval($db_record["IBLOCK_SECTION_ID"]); $NAME = isset($arFields["NAME"]) ? $arFields["NAME"] : $db_record["NAME"]; $SORT = isset($arFields["SORT"]) ? intval($arFields["SORT"]) : intval($db_record["SORT"]); $arParents = array(); $strSql = "\n\t\t\t\t\t\tSELECT BS.ID, BS.ACTIVE, BS.GLOBAL_ACTIVE, BS.DEPTH_LEVEL, BS.LEFT_MARGIN, BS.RIGHT_MARGIN\n\t\t\t\t\t\tFROM b_iblock_section BS\n\t\t\t\t\t\tWHERE BS.IBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\tAND BS.ID in (" . intval($db_record["IBLOCK_SECTION_ID"]) . ", " . $PARENT_ID . ")\n\t\t\t\t\t"; $rsParents = $DB->Query($strSql); while ($arParent = $rsParents->Fetch()) { $arParents[$arParent["ID"]] = $arParent; } //Find rightmost child of the parent $strSql = "\n\t\t\t\t\t\tSELECT BS.ID, BS.RIGHT_MARGIN, BS.DEPTH_LEVEL\n\t\t\t\t\t\tFROM b_iblock_section BS\n\t\t\t\t\t\tWHERE BS.IBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\tAND " . ($PARENT_ID > 0 ? "BS.IBLOCK_SECTION_ID=" . $PARENT_ID : "BS.IBLOCK_SECTION_ID IS NULL") . "\n\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t(BS.SORT < " . $SORT . ")\n\t\t\t\t\t\t\tOR (BS.SORT = " . $SORT . " AND BS.NAME < '" . $DB->ForSQL($NAME) . "')\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND BS.ID <> " . $ID . "\n\t\t\t\t\t\tORDER BY BS.SORT DESC, BS.NAME DESC\n\t\t\t\t\t"; $rsChild = $DB->Query($strSql); if ($arChild = $rsChild->Fetch()) { //We found the left neighbour $arUpdate = array("LEFT_MARGIN" => intval($arChild["RIGHT_MARGIN"]) + 1, "DEPTH_LEVEL" => intval($arChild["DEPTH_LEVEL"])); } else { //If we have parent, when take its left_margin if (isset($arParents[$PARENT_ID]) && $arParents[$PARENT_ID]) { $arUpdate = array("LEFT_MARGIN" => intval($arParents[$PARENT_ID]["LEFT_MARGIN"]) + 1, "DEPTH_LEVEL" => intval($arParents[$PARENT_ID]["DEPTH_LEVEL"]) + 1); } else { //We are only one/leftmost section in the iblock. $arUpdate = array("LEFT_MARGIN" => 1, "DEPTH_LEVEL" => 1); } } $move_distance = intval($db_record["LEFT_MARGIN"]) - $arUpdate["LEFT_MARGIN"]; $DB->Query("\n\t\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t\t,LEFT_MARGIN = LEFT_MARGIN + " . $distance . "\n\t\t\t\t\t\t\t,RIGHT_MARGIN = RIGHT_MARGIN + " . $distance . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tIBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tAND LEFT_MARGIN >= " . $arUpdate["LEFT_MARGIN"] . "\n\t\t\t\t\t"); $DB->Query("\n\t\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t\t,LEFT_MARGIN = -LEFT_MARGIN - " . $move_distance . "\n\t\t\t\t\t\t\t,RIGHT_MARGIN = -RIGHT_MARGIN - " . $move_distance . "\n\t\t\t\t\t\t\t" . ($arUpdate["DEPTH_LEVEL"] != intval($db_record["DEPTH_LEVEL"]) ? ",DEPTH_LEVEL = DEPTH_LEVEL - " . ($db_record["DEPTH_LEVEL"] - $arUpdate["DEPTH_LEVEL"]) : "") . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tIBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tAND LEFT_MARGIN <= " . -intval($db_record["LEFT_MARGIN"]) . "\n\t\t\t\t\t\t\tAND LEFT_MARGIN >= " . -intval($db_record["RIGHT_MARGIN"]) . "\n\t\t\t\t\t"); if (isset($arParents[$PARENT_ID])) { $DB->Query("\n\t\t\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t\t\t,RIGHT_MARGIN = RIGHT_MARGIN + " . $distance . "\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tIBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\tAND LEFT_MARGIN <= " . $arParents[$PARENT_ID]["LEFT_MARGIN"] . "\n\t\t\t\t\t\t\t\tAND RIGHT_MARGIN >= " . $arParents[$PARENT_ID]["RIGHT_MARGIN"] . "\n\t\t\t\t\t\t"); } } //Check if parent was changed if (isset($arFields["IBLOCK_SECTION_ID"]) && $arFields["IBLOCK_SECTION_ID"] != $db_record["IBLOCK_SECTION_ID"]) { $rsSection = CIBlockSection::GetByID($ID); $arSection = $rsSection->Fetch(); $strSql = "\n\t\t\t\t\t\tSELECT ID, GLOBAL_ACTIVE\n\t\t\t\t\t\tFROM b_iblock_section\n\t\t\t\t\t\tWHERE IBLOCK_ID = " . $arSection["IBLOCK_ID"] . "\n\t\t\t\t\t\tAND ID = " . intval($arFields["IBLOCK_SECTION_ID"]) . "\n\t\t\t\t\t"; $rsParent = $DB->Query($strSql); $arParent = $rsParent->Fetch(); //If new parent is not globally active //or we are not active either //we must be not globally active too if ($arParent && $arParent["GLOBAL_ACTIVE"] == "N" || $arFields["ACTIVE"] == "N") { $DB->Query("\n\t\t\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t\t\t,GLOBAL_ACTIVE = 'N'\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tIBLOCK_ID = " . $arSection["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\tAND LEFT_MARGIN >= " . intval($arSection["LEFT_MARGIN"]) . "\n\t\t\t\t\t\t\t\tAND RIGHT_MARGIN <= " . intval($arSection["RIGHT_MARGIN"]) . "\n\t\t\t\t\t\t"); } elseif ($arSection["ACTIVE"] == "N" && $arFields["ACTIVE"] == "Y") { $this->RecalcGlobalActiveFlag($arSection); } elseif ((!$arParent || $arParent["GLOBAL_ACTIVE"] == "Y") && $arSection["GLOBAL_ACTIVE"] == "N" && ($arSection["ACTIVE"] == "Y" || $arFields["ACTIVE"] == "Y")) { $this->RecalcGlobalActiveFlag($arSection); } //Otherwise we may not to change anything } elseif (isset($arFields["ACTIVE"]) && $arFields["ACTIVE"] != $db_record["ACTIVE"]) { //Make all children globally inactive if ($arFields["ACTIVE"] == "N") { $DB->Query("\n\t\t\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t\t\t,GLOBAL_ACTIVE = 'N'\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tIBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\tAND LEFT_MARGIN >= " . intval($db_record["LEFT_MARGIN"]) . "\n\t\t\t\t\t\t\t\tAND RIGHT_MARGIN <= " . intval($db_record["RIGHT_MARGIN"]) . "\n\t\t\t\t\t\t"); } else { //Check for parent activity $strSql = "\n\t\t\t\t\t\t\tSELECT ID, GLOBAL_ACTIVE\n\t\t\t\t\t\t\tFROM b_iblock_section\n\t\t\t\t\t\t\tWHERE IBLOCK_ID = " . $db_record["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tAND ID = " . intval($db_record["IBLOCK_SECTION_ID"]) . "\n\t\t\t\t\t\t"; $rsParent = $DB->Query($strSql); $arParent = $rsParent->Fetch(); //Parent is active //and we changed //so need to recalc if (!$arParent || $arParent["GLOBAL_ACTIVE"] == "Y") { $this->RecalcGlobalActiveFlag($db_record); } } } } unset(self::$arSectionCodeCache[$ID]); self::$arSectionPathCache = array(); self::$arSectionNavChainCache = array(); if ($arIBlock["RIGHTS_MODE"] === "E") { $obSectionRights = new CIBlockSectionRights($arIBlock["ID"], $ID); //Check if parent changed with extended rights mode if (isset($arFields["IBLOCK_SECTION_ID"]) && $arFields["IBLOCK_SECTION_ID"] != $db_record["IBLOCK_SECTION_ID"]) { $obSectionRights->ChangeParents(array($db_record["IBLOCK_SECTION_ID"]), array($arFields["IBLOCK_SECTION_ID"])); } if (array_key_exists("RIGHTS", $arFields) && is_array($arFields["RIGHTS"])) { $obSectionRights->SetRights($arFields["RIGHTS"]); } } if (array_key_exists("IPROPERTY_TEMPLATES", $arFields)) { $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\SectionTemplates($arIBlock["ID"], $ID); $ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]); } $uf_updated = $GLOBALS["USER_FIELD_MANAGER"]->Update("IBLOCK_" . $db_record["IBLOCK_ID"] . "_SECTION", $ID, $arFields); if ($uf_updated) { $DB->Query("UPDATE b_iblock_section SET TIMESTAMP_X = " . $DB->CurrentTimeFunction() . " WHERE ID = " . $ID); } if (CIBlock::GetArrayByID($db_record["IBLOCK_ID"], "SECTION_PROPERTY") === "Y" && array_key_exists("SECTION_PROPERTY", $arFields) && is_array($arFields["SECTION_PROPERTY"])) { CIBlockSectionPropertyLink::DeleteBySection($ID, array_keys($arFields["SECTION_PROPERTY"])); foreach ($arFields["SECTION_PROPERTY"] as $PROPERTY_ID => $arLink) { CIBlockSectionPropertyLink::Set($ID, $PROPERTY_ID, $arLink); } } if ($bUpdateSearch) { CIBlockSection::UpdateSearch($ID); } if ($arIBlock["FIELDS"]["LOG_SECTION_EDIT"]["IS_REQUIRED"] == "Y") { $USER_ID = is_object($USER) ? intval($USER->GetID()) : 0; $arEvents = GetModuleEvents("main", "OnBeforeEventLog", true); if (empty($arEvents) || ExecuteModuleEventEx($arEvents[0], array($USER_ID)) === false) { $rsSection = CIBlockSection::GetList(array(), array("=ID" => $ID), false, array("LIST_PAGE_URL", "NAME", "CODE")); $arSection = $rsSection->GetNext(); $res = array("ID" => $ID, "CODE" => $arSection["CODE"], "NAME" => $arSection["NAME"], "SECTION_NAME" => $arIBlock["SECTION_NAME"], "USER_ID" => $USER_ID, "IBLOCK_PAGE_URL" => $arSection["LIST_PAGE_URL"]); CEventLog::Log("IBLOCK", "IBLOCK_SECTION_EDIT", "iblock", $arIBlock["ID"], serialize($res)); } } $Result = true; /*********** QUOTA ***************/ $_SESSION["SESS_RECOUNT_DB"] = "Y"; /*********** QUOTA ***************/ } $arFields["ID"] = $ID; $arFields["IBLOCK_ID"] = $db_record["IBLOCK_ID"]; $arFields["RESULT"] =& $Result; foreach (GetModuleEvents("iblock", "OnAfterIBlockSectionUpdate", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arFields)); } CIBlock::clearIblockTagCache($arIBlock['ID']); return $Result; }
/** * <p>Метод изменяет параметры свойства с кодом <i>ID</i>. Перед изменением параметров вызываются обработчики события <a href="http://dev.1c-bitrix.ru/api_help/iblock/events/onbeforeiblockpropertyupdate.php">OnBeforeIBlockPropertyUpdate</a> из которых можно отменить изменения или переопределить поля. А после изменения параметром вызывается событие <a href="http://dev.1c-bitrix.ru/api_help/iblock/events/onafteriblockpropertyupdate.php">OnAfterIBlockPropertyUpdate</a>. Метод динамичный.</p> * * * @param int $ID ID изменяемой записи. </htm * * @param array $arFields Массив Array("поле"=>"значение", ...). Содержит значения <a * href="http://dev.1c-bitrix.ru/api_help/iblock/fields.php#fproperty">всех полей</a> изменяемого * свойства. Кроме того, с помощью поля "VALUES", значением которого * должен быть массив вида Array(Array("VALUE"=>"значение", "DEF"=>"по * умолчанию (Y/N)", "SORT"=>"индекс сортировки"),...), можно установить * варианты выбора для свойств типа "список" (подробнее смотрите * метод <a href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockproperty/index.php">CIBlockProperty</a>::<a * href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockproperty/updateenum.php">UpdateEnum()</a>). * * @return bool * * <h4>Example</h4> * <pre> * <?<br>$arFields = Array(<br> "NAME" => "Цвет",<br> "ACTIVE" => "Y",<br> "SORT" => "100",<br> "CODE" => "color",<br> "PROPERTY_TYPE" => "L",<br> "IBLOCK_ID" => 11<br> );<br><br>$arFields["VALUES"][0] = Array(<br> "VALUE" => "Красный",<br> "DEF" => "N",<br> "SORT" => "100"<br>}<br><br>$arFields["VALUES"][1] = Array(<br> "VALUE" => "Желтый",<br> "DEF" => "N",<br> "SORT" => "200"<br>}<br><br>$arFields["VALUES"][2] = Array(<br> "VALUE" => "Зеленый",<br> "DEF" => "Y",<br> "SORT" => "300"<br>}<br><br>$ibp = new CIBlockProperty;<br>if(!$ibp->Update($ID, $arFields))<br> echo $ibp->LAST_ERROR;<br>? * * В случае обновления информации в пользовательском типе свойства для сохранения ключа USER_TYPE_SETTINGS необходимо указать еще ключ USER_TYPE с реальным значением. В противном случае ключ USER_TYPE_SETTINGS не обновится. Неверными будут следующие варианты: * * * $arFields = array( * 'PROPERTY_TYPE' => 'E', * 'USER_TYPE_SETTINGS' => array( * 'WIDTH' => '10', * 'HEIGHT' => '10', * ), * ); * $ibp = new CIBlockProperty(); * $ibp->Update($ID, $arFields)); * * $arFields = array( * 'PROPERTY_TYPE' => 'E', * 'USER_TYPE_SETTINGS' => array( * 'WIDTH' => '10', * 'HEIGHT' => '10', * ), * 'USER_TYPE' => '', * ); * $ibp = new CIBlockProperty(); * $ibp->Update($ID, $arFields)); * * $arFields = array( * 'PROPERTY_TYPE' => 'E', * 'USER_TYPE_SETTINGS' => array( * 'WIDTH' => '10', * 'HEIGHT' => '10', * ), * 'USER_TYPE' => 'xxx' * ); * $ibp = new CIBlockProperty(); * $ibp->Update($ID, $arFields)); * * //включить индексацию свойства для поиска * $arFields = Array( * 'SEARCHABLE'=>'Y' * ); * $ibp = new CIBlockProperty; * if(!$ibp->Update($prop['ID'], $arFields)) * echo $ibp->LAST_ERROR; * * * * // добавление свойства в умный фильтр: * $arFields = Array('SMART_FILTER' => 'Y', 'IBLOCK_ID' => 123); * $ibp = new CIBlockProperty(); * if(!$ibp->Update($prop['ID'], $arFields)) * echo $ibp->LAST_ERROR; * * //IBLOCK_ID в arFields указывать обязательно, иначе свойство не будет включено в умный фильтр, и при этом не выдаст ошибки. * //Чтобы исключить свойство из умного фильтра в arFileds заменить: 'SMART_FILTER'=>'N' * </pre> * * * <h4>See Also</h4> * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockproperty/add.php">CIBlockProperty::Add</a> * </li> <li><a href="http://dev.1c-bitrix.ru/api_help/iblock/fields.php#fproperty">Поля свойства</a></li> * <li><a * href="http://dev.1c-bitrix.ru/api_help/iblock/events/onbeforeiblockpropertyupdate.php">OnBeforeIBlockPropertyUpdate</a></li> * <li><a * href="http://dev.1c-bitrix.ru/api_help/iblock/events/onafteriblockpropertyupdate.php">OnAfterIBlockPropertyUpdate</a></li> * </ul> <br><p><b>Примечание:</b> если используются <b>Инфоблоки 2.0</b> и * изменяется базовый тип свойства, то все текущие значения свойств * у существующих элементов очищаются.</p> <br><a name="examples"></a> * * * @static * @link http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockproperty/update.php * @author Bitrix */ public function Update($ID, $arFields, $bCheckDescription = false) { global $DB; $ID = IntVal($ID); if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") { $arFields["ACTIVE"] = "N"; } if (is_set($arFields, "SEARCHABLE") && $arFields["SEARCHABLE"] != "Y") { $arFields["SEARCHABLE"] = "N"; } if (is_set($arFields, "FILTRABLE") && $arFields["FILTRABLE"] != "Y") { $arFields["FILTRABLE"] = "N"; } if (is_set($arFields, "MULTIPLE") && $arFields["MULTIPLE"] != "Y") { $arFields["MULTIPLE"] = "N"; } if (is_set($arFields, "LIST_TYPE") && $arFields["LIST_TYPE"] != "C") { $arFields["LIST_TYPE"] = "L"; } if (!$this->CheckFields($arFields, $ID)) { $Result = false; $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR; } elseif (!$this->_Update($ID, $arFields, $bCheckDescription)) { $Result = false; $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR; } else { if (isset($arFields["USER_TYPE"])) { $arUserType = CIBlockProperty::GetUserType($arFields["USER_TYPE"]); if (array_key_exists("ConvertToDB", $arUserType)) { $arValue = array("VALUE" => $arFields["DEFAULT_VALUE"]); $arValue = call_user_func_array($arUserType["ConvertToDB"], array($arFields, $arValue)); if (is_array($arValue) && isset($arValue["VALUE"]) && strlen($arValue["VALUE"])) { $arFields["DEFAULT_VALUE"] = $arValue["VALUE"]; } else { $arFields["DEFAULT_VALUE"] = false; } } if (array_key_exists("PrepareSettings", $arUserType)) { $arFieldsResult = call_user_func_array($arUserType["PrepareSettings"], array($arFields)); if (is_array($arFieldsResult) && array_key_exists('USER_TYPE_SETTINGS', $arFieldsResult)) { $arFields = array_merge($arFields, $arFieldsResult); $arFields["USER_TYPE_SETTINGS"] = serialize($arFields["USER_TYPE_SETTINGS"]); } else { $arFields["USER_TYPE_SETTINGS"] = serialize($arFieldsResult); } } else { $arFields["USER_TYPE_SETTINGS"] = false; } } unset($arFields["ID"]); unset($arFields["VERSION"]); unset($arFields["TIMESTAMP_X"]); $strUpdate = $DB->PrepareUpdate("b_iblock_property", $arFields); if (strlen($strUpdate) > 0) { $strSql = "UPDATE b_iblock_property SET " . $strUpdate . " WHERE ID=" . $ID; $DB->QueryBind($strSql, array("USER_TYPE_SETTINGS" => $arFields["USER_TYPE_SETTINGS"])); } if (is_set($arFields, "VALUES")) { $this->UpdateEnum($ID, $arFields["VALUES"]); } if (array_key_exists("IBLOCK_ID", $arFields) && CIBlock::GetArrayByID($arFields["IBLOCK_ID"], "SECTION_PROPERTY") === "Y") { if (!array_key_exists("SECTION_PROPERTY", $arFields) || $arFields["SECTION_PROPERTY"] !== "N") { $arLink = array("SMART_FILTER" => $arFields["SMART_FILTER"]); if (array_key_exists("DISPLAY_TYPE", $arFields)) { $arLink["DISPLAY_TYPE"] = $arFields["DISPLAY_TYPE"]; } if (array_key_exists("DISPLAY_EXPANDED", $arFields)) { $arLink["DISPLAY_EXPANDED"] = $arFields["DISPLAY_EXPANDED"]; } if (array_key_exists("FILTER_HINT", $arFields)) { $arLink["FILTER_HINT"] = $arFields["FILTER_HINT"]; } CIBlockSectionPropertyLink::Set(0, $ID, $arLink); } else { CIBlockSectionPropertyLink::Delete(0, $ID); } } global $BX_IBLOCK_PROP_CACHE; if (is_set($arFields, "IBLOCK_ID")) { unset($BX_IBLOCK_PROP_CACHE[$arFields["IBLOCK_ID"]]); } else { $BX_IBLOCK_PROP_CACHE = array(); } $Result = true; } $arFields["ID"] = $ID; $arFields["RESULT"] =& $Result; foreach (GetModuleEvents("iblock", "OnAfterIBlockPropertyUpdate", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arFields)); } return $Result; }
if (is_array($arCatalog)) { $props = CIBlockProperty::GetList(array(), array("IBLOCK_ID" => $arCatalog["IBLOCK_ID"], "CHECK_PERMISSIONS" => "N")); while($p = $props->Fetch()) { if( isset($_POST["SECTION_PROPERTY"]) && is_array($_POST["SECTION_PROPERTY"]) && array_key_exists($p["ID"], $_POST["SECTION_PROPERTY"]) && $_POST["SECTION_PROPERTY"][$p["ID"]]["SHOW"] === "Y" ) { CIBlockSectionPropertyLink::Set(0, $p["ID"], array( "SMART_FILTER" => $_POST["SECTION_PROPERTY"][$p["ID"]]["SMART_FILTER"], "DISPLAY_TYPE" => $_POST["SECTION_PROPERTY"][$p["ID"]]["DISPLAY_TYPE"], "DISPLAY_EXPANDED" => $_POST["SECTION_PROPERTY"][$p["ID"]]["DISPLAY_EXPANDED"], "IBLOCK_ID" => $IBLOCK_ID, )); } else { CIBlockSectionPropertyLink::Delete(0, $p["ID"]); } } } LocalRedirect("/bitrix/admin/cat_catalog_edit.php?lang=".LANGUAGE_ID."&IBLOCK_ID=".$IBLOCK_ID."&".$tabControl->ActiveTabParam()); } } ClearVars("str_");