Exemplo n.º 1
0
 static function GroupERights($iblockID)
 {
     if (CIBlock::GetArrayByID($iblockID, "RIGHTS_MODE") === "E") {
         return;
     }
     $arGroups = self::GetGroups($iblockID);
     foreach ($arGroups as $groupID => $group) {
         foreach (self::$ops as $op => $opTrans) {
             $arGroups[$groupID]["Operations"][$op] = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $groupID, 'files', $op);
         }
     }
     $arTasks = CWebDavIblock::GetTasks();
     // set e rights
     $arFields = array('RIGHTS_MODE' => 'E', 'GROUP_ID' => array());
     $ib = new CIBlock();
     $res = $ib->Update($iblockID, $arFields);
     $ibr = new CIBlockRights($iblockID);
     $rights = array();
     $rights['n0'] = array('GROUP_CODE' => 'G1', 'DO_CLEAN' => 'Y', 'TASK_ID' => $arTasks['X']);
     // admins
     $rights['n1'] = array('GROUP_CODE' => 'G2', 'DO_CLEAN' => 'Y', 'TASK_ID' => $arTasks['D']);
     // nobody
     $ibr->SetRights($rights);
     foreach ($arGroups as $groupID => $group) {
         $sectionID = $group['SECTION'];
         $ibrs = new CIBlockSectionRights($iblockID, $sectionID);
         $rights = array();
         $i = 0;
         foreach ($group["Operations"] as $op => $subj) {
             //			  'Operations' =>
             //				array
             //				  'view' => string 'A' (length=1)
             //				  'write_limited' => string 'Z' (length=1)
             //				  'bizproc' => null
             //				  'write' => string 'Z' (length=1)
             //
             //			A>Только владелец группы
             //			E>Владелец группы и модераторы группы
             //			K>Все члены группы
             //			L>Авторизованные пользователи
             //			N>Все посетители
             if ($subj) {
                 if ($subj == "N") {
                     $sSubj = "G2";
                 } elseif ($subj == "L") {
                     $sSubj = "AU";
                 } else {
                     $sSubj = "SG{$groupID}_{$subj}";
                 }
                 $rights[$sSubj] = $arTasks[self::$ops[$op]];
                 if (self::$ops[$op] == 'E') {
                     $rights["CR"] = $arTasks['W'];
                 }
             }
         }
         $rights["SG{$groupID}_A"] = $arTasks["X"];
         // admin of group
         $arRights = array();
         $i = 0;
         foreach ($rights as $subj => $task) {
             $arRights['n' . $i++] = array('GROUP_CODE' => $subj, 'TASK_ID' => $task, 'DO_CLEAN' => 'NOT');
         }
         $ibrs->SetRights($arRights);
     }
 }
Exemplo n.º 2
0
 function Update($ID, $arFields, $bResort = true, $bUpdateSearch = true, $bResizePictures = false)
 {
     global $USER, $DB, $APPLICATION;
     $ID = intval($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"]["tmp_name"] = CTempFile::GetFileName(basename($arFields["PICTURE"]["tmp_name"]));
                 CheckDirPath($arFields["PICTURE"]["tmp_name"]);
                 copy($arFields["DETAIL_PICTURE"]["tmp_name"], $arFields["PICTURE"]["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"]["tmp_name"] = CTempFile::GetFileName(basename($arFields["PICTURE"]["tmp_name"]));
                 CheckDirPath($arFields["PICTURE"]["tmp_name"]);
                 copy($arFields["DETAIL_PICTURE"]["tmp_name"], $arFields["PICTURE"]["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"]["tmp_name"] = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"]));
                 CheckDirPath($arFields["DETAIL_PICTURE"]["tmp_name"]);
                 copy($arFields["PICTURE"]["tmp_name"], $arFields["DETAIL_PICTURE"]["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"]["tmp_name"] = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"]));
                 CheckDirPath($arFields["DETAIL_PICTURE"]["tmp_name"]);
                 copy($arFields["PICTURE"]["tmp_name"], $arFields["DETAIL_PICTURE"]["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"]));
         }
     }
     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";
         }
     }
     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";
         }
     }
     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);
                     }
                 }
             }
         }
         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"]);
             }
         }
         $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);
             foreach ($arFields["SECTION_PROPERTY"] as $PROPERTY_ID => $arLink) {
                 CIBlockSectionPropertyLink::Add($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;
             $db_events = GetModuleEvents("main", "OnBeforeEventLog");
             $arEvent = $db_events->Fetch();
             if (!$arEvent || ExecuteModuleEventEx($arEvent, 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;
     $events = GetModuleEvents("iblock", "OnAfterIBlockSectionUpdate");
     while ($arEvent = $events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array(&$arFields));
     }
     if (defined("BX_COMP_MANAGED_CACHE")) {
         $GLOBALS["CACHE_MANAGER"]->ClearByTag("iblock_id_" . $arIBlock["ID"]);
     }
     return $Result;
 }