function CheckFields(&$arFields, $ID = false, $bCheckDiskQuota = true) { global $DB, $APPLICATION, $USER; $this->LAST_ERROR = ""; $APPLICATION->ResetException(); if ($ID === false) { $db_events = GetModuleEvents("iblock", "OnStartIBlockElementAdd", true); } else { $arFields["ID"] = $ID; $db_events = GetModuleEvents("iblock", "OnStartIBlockElementUpdate", true); } foreach ($db_events as $arEvent) { $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields)); if ($bEventRes === false) { break; } } if (($ID === false || is_set($arFields, "NAME")) && strlen($arFields["NAME"]) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ELEMENT_NAME") . "<br>"; } if (isset($arFields["ACTIVE_FROM"]) && $arFields["ACTIVE_FROM"] != '' && !$DB->IsDate($arFields["ACTIVE_FROM"], false, LANG, "FULL")) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_FROM") . "<br>"; } if (isset($arFields["ACTIVE_TO"]) && $arFields["ACTIVE_TO"] != '' && !$DB->IsDate($arFields["ACTIVE_TO"], false, LANG, "FULL")) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_TO") . "<br>"; } if (is_set($arFields, "PREVIEW_PICTURE")) { if (is_array($arFields["PREVIEW_PICTURE"]) && array_key_exists("bucket", $arFields["PREVIEW_PICTURE"]) && is_object($arFields["PREVIEW_PICTURE"]["bucket"])) { //This is trusted image from xml import } elseif (is_array($arFields["PREVIEW_PICTURE"])) { $error = CFile::CheckImageFile($arFields["PREVIEW_PICTURE"]); if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } elseif (($error = CFile::checkForDb($arFields, "PREVIEW_PICTURE")) !== "") { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE") . "<br>" . $error . "<br>"; } } elseif (intval($arFields["PREVIEW_PICTURE"]) > 0) { if (intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0 || CIBlockElement::DeleteFile($arFields["PREVIEW_PICTURE"], $ID, "PREVIEW", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE") . "<br>"; } } } if (is_set($arFields, "DETAIL_PICTURE")) { if (is_array($arFields["DETAIL_PICTURE"]) && array_key_exists("bucket", $arFields["DETAIL_PICTURE"]) && is_object($arFields["DETAIL_PICTURE"]["bucket"])) { //This is trusted image from xml import } elseif (is_array($arFields["DETAIL_PICTURE"])) { $error = CFile::CheckImageFile($arFields["DETAIL_PICTURE"]); if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } elseif (($error = CFile::checkForDb($arFields, "DETAIL_PICTURE")) !== "") { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE") . "<br>" . $error . "<br>"; } } elseif (intval($arFields["DETAIL_PICTURE"]) > 0) { if (intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0 || CIBlockElement::DeleteFile($arFields["DETAIL_PICTURE"], $ID, "DETAIL", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE") . "<br>"; } } } if (array_key_exists("TAGS", $arFields) && CModule::IncludeModule('search')) { $arFields["TAGS"] = implode(", ", tags_prepare($arFields["TAGS"])); } if ($ID === false && !is_set($arFields, "IBLOCK_ID")) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>"; } if ($ID !== false && is_set($arFields, "XML_ID") && strlen($arFields["XML_ID"]) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_EXTERNAL_CODE") . "<br>"; } //Find out IBLOCK_ID from fields or from element $IBLOCK_ID = intval($arFields["IBLOCK_ID"]); if ($IBLOCK_ID <= 0) { $IBLOCK_ID = 0; $res = $DB->Query("SELECT IBLOCK_ID FROM b_iblock_element WHERE ID=" . IntVal($ID)); if ($ar = $res->Fetch()) { $IBLOCK_ID = (int) $ar["IBLOCK_ID"]; } } //Read iblock metadata static $IBLOCK_CACHE = array(); if (!isset($IBLOCK_CACHE[$IBLOCK_ID])) { if ($IBLOCK_ID > 0) { $IBLOCK_CACHE[$IBLOCK_ID] = CIBlock::GetArrayByID($IBLOCK_ID); } else { $IBLOCK_CACHE[$IBLOCK_ID] = false; } } if ($IBLOCK_CACHE[$IBLOCK_ID]) { $arFields["IBLOCK_ID"] = $IBLOCK_ID; } else { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>"; } if (is_set($arFields, 'IBLOCK_SECTION') && !empty($arFields['IBLOCK_SECTION'])) { if (!is_array($arFields['IBLOCK_SECTION'])) { $arFields['IBLOCK_SECTION'] = array($arFields['IBLOCK_SECTION']); } $arFields['IBLOCK_SECTION'] = array_filter($arFields['IBLOCK_SECTION']); } if ($IBLOCK_CACHE[$IBLOCK_ID]) { $ar = $IBLOCK_CACHE[$IBLOCK_ID]["FIELDS"]; if (is_array($ar)) { $WF_PARENT_ELEMENT_ID = isset($arFields["WF_PARENT_ELEMENT_ID"]) ? intval($arFields["WF_PARENT_ELEMENT_ID"]) : 0; if (($WF_PARENT_ELEMENT_ID == 0 || $WF_PARENT_ELEMENT_ID == intval($ID)) && array_key_exists("CODE", $arFields) && strlen($arFields["CODE"]) > 0 && is_array($ar["CODE"]["DEFAULT_VALUE"]) && $ar["CODE"]["DEFAULT_VALUE"]["UNIQUE"] == "Y") { $res = $DB->Query("\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_iblock_element\n\t\t\t\t\t\tWHERE IBLOCK_ID = " . $IBLOCK_ID . "\n\t\t\t\t\t\tAND CODE = '" . $DB->ForSQL($arFields["CODE"]) . "'\n\t\t\t\t\t\tAND WF_PARENT_ELEMENT_ID IS NULL\n\t\t\t\t\t\tAND ID <> " . intval($ID)); if ($res->Fetch()) { $this->LAST_ERROR .= GetMessage("IBLOCK_DUP_ELEMENT_CODE") . "<br>"; } } $arOldElement = false; foreach ($ar as $FIELD_ID => $field) { if (preg_match("/^(SECTION_|LOG_)/", $FIELD_ID)) { continue; } if ($field["IS_REQUIRED"] === "Y") { switch ($FIELD_ID) { case "NAME": case "ACTIVE": case "PREVIEW_TEXT_TYPE": case "DETAIL_TEXT_TYPE": case "SORT": //We should never check for this fields break; case "IBLOCK_SECTION": if ($ID === false || array_key_exists($FIELD_ID, $arFields)) { $sum = 0; if (is_array($arFields[$FIELD_ID])) { foreach ($arFields[$FIELD_ID] as $k => $v) { if (intval($v) > 0) { $sum += intval($v); } } } else { $sum = intval($arFields[$FIELD_ID]); } if ($sum <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } break; case "PREVIEW_PICTURE": case "DETAIL_PICTURE": if ($ID !== false && !$arOldElement) { $rs = $DB->Query("SELECT PREVIEW_PICTURE, DETAIL_PICTURE from b_iblock_element WHERE ID = " . intval($ID)); $arOldElement = $rs->Fetch(); } if ($arOldElement && $arOldElement[$FIELD_ID] > 0) { //There was an picture so just check that it is not deleted if (array_key_exists($FIELD_ID, $arFields) && is_array($arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["del"] === "Y") { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } else { //There was NO picture so it MUST be present if (!array_key_exists($FIELD_ID, $arFields)) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } elseif (is_array($arFields[$FIELD_ID])) { if ($arFields[$FIELD_ID]["del"] === "Y" || array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0 || $arFields[$FIELD_ID]["size"] <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } else { if (intval($arFields[$FIELD_ID]) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } } break; default: if ($ID === false || array_key_exists($FIELD_ID, $arFields)) { if (is_array($arFields[$FIELD_ID])) { $val = implode("", $arFields[$FIELD_ID]); } else { $val = $arFields[$FIELD_ID]; } if (strlen($val) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } break; } } } } } if (array_key_exists("PROPERTY_VALUES", $arFields) && is_array($arFields["PROPERTY_VALUES"])) { //First "normalize" properties to form: //$arFields["PROPERTY_VALUES"][<PROPERTY_ID>][<PROPERTY_VALUE_ID>] => $value $arProperties = array(); foreach ($arFields["PROPERTY_VALUES"] as $key => $property_values) { $arProperties[$key] = array(); if (is_array($property_values)) { if (array_key_exists("VALUE", $property_values)) { $arProperties[$key][] = $property_values["VALUE"]; } elseif (array_key_exists("tmp_name", $property_values)) { $arProperties[$key][] = $property_values; } else { foreach ($property_values as $key2 => $property_value) { if (is_array($property_value) && array_key_exists("VALUE", $property_value)) { //each of these may be "complex" $arProperties[$key][] = $property_value["VALUE"]; } else { //or simple $arProperties[$key][] = $property_value; } } } } else { $arProperties[$key][] = $property_values; } } foreach ($arProperties as $key => $property_values) { $arProperty = CIBlockProperty::GetPropertyArray($key, $IBLOCK_ID); if ($arProperty["USER_TYPE"] != "") { $arUserType = CIBlockProperty::GetUserType($arProperty["USER_TYPE"]); } else { $arUserType = array(); } if (array_key_exists("CheckFields", $arUserType)) { foreach ($property_values as $key2 => $property_value) { $arError = call_user_func_array($arUserType["CheckFields"], array($arProperty, array("VALUE" => $property_value))); if (is_array($arError)) { foreach ($arError as $err_mess) { $this->LAST_ERROR .= $err_mess . "<br>"; } } } } //Files check $bError = false; if ($arProperty["IS_REQUIRED"] == "Y" && $arProperty['PROPERTY_TYPE'] == 'F') { //New element if ($ID === false) { $bError = true; foreach ($property_values as $key2 => $property_value) { if (is_array($property_value) && array_key_exists("tmp_name", $property_value) && array_key_exists("size", $property_value)) { if ($property_value['size'] > 0) { $bError = false; break; } } elseif (intval($property_value) > 0) { //This is history copy of the file $bError = false; break; } } } else { $dbProperty = CIBlockElement::GetProperty($arProperty["IBLOCK_ID"], $ID, "sort", "asc", array("ID" => $arProperty["ORIG_ID"], "EMPTY" => "N")); $bCount = 0; while ($a = $dbProperty->Fetch()) { if ($a["VALUE"] > 0) { $bCount++; } } foreach ($property_values as $key2 => $property_value) { if (is_array($property_value)) { if ($property_value['size'] > 0) { $bCount++; break; } elseif ($property_value['del'] == 'Y') { $bCount--; } } elseif (intval($property_value) > 0) { //This is history copy of the file $bCount++; break; } } $bError = $bCount <= 0; } } if ($arProperty["IS_REQUIRED"] == "Y" && $arProperty['PROPERTY_TYPE'] != 'F') { $len = 0; foreach ($property_values as $key2 => $property_value) { if (array_key_exists("GetLength", $arUserType)) { $len += call_user_func_array($arUserType["GetLength"], array($arProperty, array("VALUE" => $property_value))); } else { $len += strlen($property_value); } if ($len > 0) { break; } } $bError = $len <= 0; } if ($bError) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_PROPERTY", array("#PROPERTY#" => $arProperty["NAME"])) . "<br>"; } // check file properties for correctness if ($arProperty['PROPERTY_TYPE'] == 'F') { $bImageOnly = False; $arImageExtentions = explode(",", strtoupper(CFile::GetImageExtensions())); if (strlen($arProperty["FILE_TYPE"])) { $bImageOnly = True; $arAvailTypes = explode(",", strtoupper($arProperty["FILE_TYPE"])); foreach ($arAvailTypes as $avail_type) { if (!in_array(trim($avail_type), $arImageExtentions)) { $bImageOnly = False; break; } } } foreach ($property_values as $key2 => $property_value) { if (!is_array($property_value) && intval($property_value) > 0 && intval($arFields["WF_PARENT_ELEMENT_ID"]) > 0) { if (CIBlockElement::DeleteFile($property_value, $ID, "PROPERTY", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_FILE_PROPERTY") . "<br>"; } } elseif (is_array($property_value)) { if (is_object($property_value["bucket"])) { //This is trusted image from xml import $error = ""; } else { if ($bImageOnly) { $error = CFile::CheckImageFile($property_value); } else { $error = CFile::CheckFile($property_value, 0, false, $arProperty["FILE_TYPE"]); } } //For user without edit php permissions //we allow only pictures upload if (!is_object($USER) || !$USER->IsAdmin()) { if (HasScriptExtension($property_value["name"])) { $error = GetMessage("FILE_BAD_TYPE") . " (" . $property_value["name"] . ")."; } } if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } } } } } } $APPLICATION->ResetException(); if ($ID === false) { $db_events = GetModuleEvents("iblock", "OnBeforeIBlockElementAdd", true); } else { $arFields["ID"] = $ID; $db_events = GetModuleEvents("iblock", "OnBeforeIBlockElementUpdate", true); } foreach ($db_events as $arEvent) { $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields)); if ($bEventRes === false) { if ($err = $APPLICATION->GetException()) { $this->LAST_ERROR .= $err->GetString() . "<br>"; } else { $APPLICATION->ThrowException("Unknown error"); $this->LAST_ERROR .= "Unknown error.<br>"; } break; } } /****************************** QUOTA ******************************/ if ($bCheckDiskQuota && empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) { $quota = new CDiskQuota(); if (!$quota->checkDiskQuota($arFields)) { $this->LAST_ERROR = $quota->LAST_ERROR; } } /****************************** QUOTA ******************************/ if (!empty($this->LAST_ERROR)) { return false; } return true; }
function GetSectionElementsCount($ID, $arFilter = array()) { global $DB, $USER; $arJoinProps = array(); $bJoinFlatProp = false; $arSqlSearch = array(); if (array_key_exists("PROPERTY", $arFilter)) { $val = $arFilter["PROPERTY"]; foreach ($val as $propID => $propVAL) { $res = CIBlock::MkOperationFilter($propID); $propID = $res["FIELD"]; $cOperationType = $res["OPERATION"]; if ($db_prop = CIBlockProperty::GetPropertyArray($propID, CIBlock::_MergeIBArrays($arFilter["IBLOCK_ID"], $arFilter["IBLOCK_CODE"]))) { $bSave = false; if (array_key_exists($db_prop["ID"], $arJoinProps)) { $iPropCnt = $arJoinProps[$db_prop["ID"]]; } elseif ($db_prop["VERSION"] != 2 || $db_prop["MULTIPLE"] == "Y") { $bSave = true; $iPropCnt = count($arJoinProps); } if (!is_array($propVAL)) { $propVAL = array($propVAL); } if ($db_prop["PROPERTY_TYPE"] == "N" || $db_prop["PROPERTY_TYPE"] == "G" || $db_prop["PROPERTY_TYPE"] == "E") { if ($db_prop["VERSION"] == 2 && $db_prop["MULTIPLE"] == "N") { $r = CIBlock::FilterCreate("FPS.PROPERTY_" . $db_prop["ORIG_ID"], $propVAL, "number", $cOperationType); $bJoinFlatProp = $db_prop["IBLOCK_ID"]; } else { $r = CIBlock::FilterCreate("FPV" . $iPropCnt . ".VALUE_NUM", $propVAL, "number", $cOperationType); } } else { if ($db_prop["VERSION"] == 2 && $db_prop["MULTIPLE"] == "N") { $r = CIBlock::FilterCreate("FPS.PROPERTY_" . $db_prop["ORIG_ID"], $propVAL, "string", $cOperationType); $bJoinFlatProp = $db_prop["IBLOCK_ID"]; } else { $r = CIBlock::FilterCreate("FPV" . $iPropCnt . ".VALUE", $propVAL, "string", $cOperationType); } } if (strlen($r) > 0) { if ($bSave) { $db_prop["iPropCnt"] = $iPropCnt; $arJoinProps[$db_prop["ID"]] = $db_prop; } $arSqlSearch[] = $r; } } } } $strSqlSearch = ""; foreach ($arSqlSearch as $r) { if (strlen($r) > 0) { $strSqlSearch .= "\n\t\t\t\tAND (" . $r . ") "; } } $strSqlSearchProp = ""; foreach ($arJoinProps as $propID => $db_prop) { if ($db_prop["VERSION"] == 2) { $strTable = "b_iblock_element_prop_m" . $db_prop["IBLOCK_ID"]; } else { $strTable = "b_iblock_element_property"; } $i = $db_prop["iPropCnt"]; $strSqlSearchProp .= "\n\t\t\t\tINNER JOIN b_iblock_property FP" . $i . " ON FP" . $i . ".IBLOCK_ID=BS.IBLOCK_ID AND\n\t\t\t\t" . (IntVal($propID) > 0 ? " FP" . $i . ".ID=" . IntVal($propID) . " " : " FP" . $i . ".CODE='" . $DB->ForSQL($propID, 200) . "' ") . "\n\t\t\t\tINNER JOIN " . $strTable . " FPV" . $i . " ON FP" . $i . ".ID=FPV" . $i . ".IBLOCK_PROPERTY_ID AND FPV" . $i . ".IBLOCK_ELEMENT_ID=BE.ID\n\t\t\t"; } if ($bJoinFlatProp) { $strSqlSearchProp .= "\n\t\t\t\tINNER JOIN b_iblock_element_prop_s" . $bJoinFlatProp . " FPS ON FPS.IBLOCK_ELEMENT_ID = BE.ID\n\t\t\t"; } $strHint = $DB->type == "MYSQL" ? "STRAIGHT_JOIN" : ""; $strSql = "\n\t\t\tSELECT " . $strHint . " COUNT(DISTINCT BE.ID) as CNT\n\t\t\tFROM b_iblock_section BS\n\t\t\t\tINNER JOIN b_iblock_section BSTEMP ON (BSTEMP.IBLOCK_ID=BS.IBLOCK_ID\n\t\t\t\t\tAND BSTEMP.LEFT_MARGIN >= BS.LEFT_MARGIN\n\t\t\t\t\tAND BSTEMP.RIGHT_MARGIN <= BS.RIGHT_MARGIN)\n\t\t\t\tINNER JOIN b_iblock_section_element BSE ON BSE.IBLOCK_SECTION_ID=BSTEMP.ID\n\t\t\t\tINNER JOIN b_iblock_element BE ON BE.ID=BSE.IBLOCK_ELEMENT_ID AND BE.IBLOCK_ID=BS.IBLOCK_ID\n\t\t\t" . $strSqlSearchProp . "\n\t\t\tWHERE BS.ID=" . IntVal($ID) . "\n\t\t\t\tAND ((BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL )\n\t\t\t\t" . ($arFilter["CNT_ALL"] == "Y" ? " OR BE.WF_NEW='Y' " : "") . ")\n\t\t\t\t" . ($arFilter["CNT_ACTIVE"] == "Y" ? " AND BE.ACTIVE='Y'\n\t\t\t\t\tAND (BE.ACTIVE_TO >= " . $DB->CurrentTimeFunction() . " OR BE.ACTIVE_TO IS NULL)\n\t\t\t\t\tAND (BE.ACTIVE_FROM <= " . $DB->CurrentTimeFunction() . " OR BE.ACTIVE_FROM IS NULL)" : "") . "\n\t\t\t\t" . $strSqlSearch; //echo "<pre>",htmlspecialcharsbx($strSql),"</pre>"; $res = $DB->Query($strSql); $res = $res->Fetch(); return $res["CNT"]; }
/** * @param $iblockId int * @param $fieldId int */ public static function CheckFieldId($iblock_id, $field_id) { if ($field_id === "DETAIL_PICTURE") { return true; } elseif ($field_id === "PREVIEW_PICTURE") { return true; } elseif ($field_id === "PICTURE") { return true; } elseif ($iblock_id <= 0) { return false; } elseif (!preg_match("/^PROPERTY_(.+)\$/", $field_id, $match)) { return false; } else { $db_prop = CIBlockProperty::GetPropertyArray($match[1], $iblock_id); if (is_array($db_prop) && $db_prop["PROPERTY_TYPE"] === "F") { return true; } } return false; }
protected function UpdateList($arFields, $arFilter = array()) { global $DB, $USER, $USER_FIELD_MANAGER; $strUpdate = $DB->PrepareUpdate("b_iblock_section", $arFields, "iblock", false, "BS"); if ($strUpdate == "") { return false; } if (isset($arFilter["IBLOCK_ID"]) && $arFilter["IBLOCK_ID"] > 0) { $obUserFieldsSql = new CUserTypeSQL(); $obUserFieldsSql->SetEntity("IBLOCK_" . $arFilter["IBLOCK_ID"] . "_SECTION", "BS.ID"); $obUserFieldsSql->SetFilter($arFilter); } else { foreach ($arFilter as $key => $val) { $res = CIBlock::MkOperationFilter($key); if (preg_match("/^UF_/", $res["FIELD"])) { trigger_error("arFilter parameter of the CIBlockSection::GetList contains user fields, but has no IBLOCK_ID field.", E_USER_WARNING); break; } } } $arJoinProps = array(); $bJoinFlatProp = false; $arSqlSearch = CIBlockSection::GetFilter($arFilter); $bCheckPermissions = !array_key_exists("CHECK_PERMISSIONS", $arFilter) || $arFilter["CHECK_PERMISSIONS"] !== "N"; $bIsAdmin = is_object($USER) && $USER->IsAdmin(); if ($bCheckPermissions && !$bIsAdmin) { $arSqlSearch[] = CIBlockSection::_check_rights_sql($arFilter["MIN_PERMISSION"]); } if (array_key_exists("PROPERTY", $arFilter)) { $val = $arFilter["PROPERTY"]; foreach ($val as $propID => $propVAL) { $res = CIBlock::MkOperationFilter($propID); $propID = $res["FIELD"]; $cOperationType = $res["OPERATION"]; if ($db_prop = CIBlockProperty::GetPropertyArray($propID, CIBlock::_MergeIBArrays($arFilter["IBLOCK_ID"], $arFilter["IBLOCK_CODE"]))) { $bSave = false; if (array_key_exists($db_prop["ID"], $arJoinProps)) { $iPropCnt = $arJoinProps[$db_prop["ID"]]; } elseif ($db_prop["VERSION"] != 2 || $db_prop["MULTIPLE"] == "Y") { $bSave = true; $iPropCnt = count($arJoinProps); } if (!is_array($propVAL)) { $propVAL = array($propVAL); } if ($db_prop["PROPERTY_TYPE"] == "N" || $db_prop["PROPERTY_TYPE"] == "G" || $db_prop["PROPERTY_TYPE"] == "E") { if ($db_prop["VERSION"] == 2 && $db_prop["MULTIPLE"] == "N") { $r = CIBlock::FilterCreate("FPS.PROPERTY_" . $db_prop["ORIG_ID"], $propVAL, "number", $cOperationType); $bJoinFlatProp = $db_prop["IBLOCK_ID"]; } else { $r = CIBlock::FilterCreate("FPV" . $iPropCnt . ".VALUE_NUM", $propVAL, "number", $cOperationType); } } else { if ($db_prop["VERSION"] == 2 && $db_prop["MULTIPLE"] == "N") { $r = CIBlock::FilterCreate("FPS.PROPERTY_" . $db_prop["ORIG_ID"], $propVAL, "string", $cOperationType); $bJoinFlatProp = $db_prop["IBLOCK_ID"]; } else { $r = CIBlock::FilterCreate("FPV" . $iPropCnt . ".VALUE", $propVAL, "string", $cOperationType); } } if (strlen($r) > 0) { if ($bSave) { $db_prop["iPropCnt"] = $iPropCnt; $arJoinProps[$db_prop["ID"]] = $db_prop; } $arSqlSearch[] = $r; } } } } $strSqlSearch = ""; foreach ($arSqlSearch as $r) { if (strlen($r) > 0) { $strSqlSearch .= "\n\t\t\t\tAND (" . $r . ") "; } } if (isset($obUserFieldsSql)) { $r = $obUserFieldsSql->GetFilter(); if (strlen($r) > 0) { $strSqlSearch .= "\n\t\t\t\tAND (" . $r . ") "; } } $strProp1 = ""; foreach ($arJoinProps as $propID => $db_prop) { if ($db_prop["VERSION"] == 2) { $strTable = "b_iblock_element_prop_m" . $db_prop["IBLOCK_ID"]; } else { $strTable = "b_iblock_element_property"; } $i = $db_prop["iPropCnt"]; $strProp1 .= "\n\t\t\t\tLEFT JOIN b_iblock_property FP" . $i . " ON FP" . $i . ".IBLOCK_ID=B.ID AND\n\t\t\t\t" . (IntVal($propID) > 0 ? " FP" . $i . ".ID=" . IntVal($propID) . " " : " FP" . $i . ".CODE='" . $DB->ForSQL($propID, 200) . "' ") . "\n\t\t\t\tLEFT JOIN " . $strTable . " FPV" . $i . " ON FP" . $i . ".ID=FPV" . $i . ".IBLOCK_PROPERTY_ID AND FPV" . $i . ".IBLOCK_ELEMENT_ID=BE.ID "; } if ($bJoinFlatProp) { $strProp1 .= "\n\t\t\t\tLEFT JOIN b_iblock_element_prop_s" . $bJoinFlatProp . " FPS ON FPS.IBLOCK_ELEMENT_ID = BE.ID\n\t\t\t"; } $strSql = "\n\t\t\tUPDATE\n\t\t\tb_iblock_section BS\n\t\t\t\tINNER JOIN b_iblock B ON BS.IBLOCK_ID = B.ID\n\t\t\t\t" . (isset($obUserFieldsSql) ? $obUserFieldsSql->GetJoin("BS.ID") : "") . "\n\t\t\t" . (strlen($strProp1) > 0 ? "\tINNER JOIN b_iblock_section BSTEMP ON BSTEMP.IBLOCK_ID = BS.IBLOCK_ID\n\t\t\t\t\tLEFT JOIN b_iblock_section_element BSE ON BSE.IBLOCK_SECTION_ID=BSTEMP.ID\n\t\t\t\t\tLEFT JOIN b_iblock_element BE ON (BSE.IBLOCK_ELEMENT_ID=BE.ID\n\t\t\t\t\t\tAND ((BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL )\n\t\t\t\t\t\tAND BE.IBLOCK_ID = BS.IBLOCK_ID\n\t\t\t\t" . ($arFilter["CNT_ALL"] == "Y" ? " OR BE.WF_NEW='Y' " : "") . ")\n\t\t\t\t" . ($arFilter["CNT_ACTIVE"] == "Y" ? " AND BE.ACTIVE='Y'\n\t\t\t\t\tAND (BE.ACTIVE_TO >= " . $DB->CurrentTimeFunction() . " OR BE.ACTIVE_TO IS NULL)\n\t\t\t\t\tAND (BE.ACTIVE_FROM <= " . $DB->CurrentTimeFunction() . " OR BE.ACTIVE_FROM IS NULL)" : "") . ")\n\t\t\t\t\t" . $strProp1 . " " : "") . "\n\t\t\tSET " . $strUpdate . "\n\t\t\tWHERE 1=1\n\t\t\t" . (strlen($strProp1) > 0 ? "\tAND BSTEMP.LEFT_MARGIN >= BS.LEFT_MARGIN\n\t\t\t\t\tAND BSTEMP.RIGHT_MARGIN <= BS.RIGHT_MARGIN " : "") . "\n\t\t\t" . $strSqlSearch . "\n\t\t"; return $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); }
public static function CheckFieldId($catalogID, $fieldID) { if ($fieldID === "DETAIL_PICTURE") { return true; } elseif ($fieldID === "PREVIEW_PICTURE") { return true; } elseif ($fieldID === "PICTURE") { return true; } elseif ($catalogID <= 0 || $catalogID !== CCrmCatalog::EnsureDefaultExists()) { return false; } elseif (!preg_match("/^PROPERTY_(.+)\$/", $fieldID, $match)) { return false; } else { $db_prop = CIBlockProperty::GetPropertyArray($match[1], $catalogID); if (is_array($db_prop) && $db_prop["PROPERTY_TYPE"] === "F") { return true; } } return false; }