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); }