function SetPropertyValues($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $PROPERTY_CODE = false) { global $DB; $ELEMENT_ID = intVal($ELEMENT_ID); if (!is_array($PROPERTY_VALUES)) { $PROPERTY_VALUES = array($PROPERTY_VALUES); } $arFilter = array("IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "N"); if ($PROPERTY_CODE !== false) { if (IntVal($PROPERTY_CODE) > 0) { $arFilter["ID"] = IntVal($PROPERTY_CODE); } else { $arFilter["CODE"] = $PROPERTY_CODE; } } else { $arFilter["ACTIVE"] = "Y"; } $uniq_flt = md5(serialize($arFilter)); global $BX_IBLOCK_PROP_CACHE; if (!is_set($BX_IBLOCK_PROP_CACHE, $IBLOCK_ID)) { $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID] = array(); } if (is_set($BX_IBLOCK_PROP_CACHE[$IBLOCK_ID], $uniq_flt)) { $ar_prop =& $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt]; } else { $db_prop = CIBlockProperty::GetList(array(), $arFilter); $ar_prop = array(); while ($prop = $db_prop->Fetch()) { $ar_prop[] = $prop; } $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt] =& $ar_prop; } Reset($ar_prop); $bRecalcSections = false; $arPROP_ID = array_keys($PROPERTY_VALUES); $cacheValues = false; if (count($ar_prop) > 1) { $cacheValues = array(); $strSql = "SELECT ep.ID, ep.VALUE, ep.IBLOCK_PROPERTY_ID " . "FROM b_iblock_element_property ep, b_iblock_property p " . "WHERE ep.IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\tAND ep.IBLOCK_PROPERTY_ID = p.ID " . "\tAND p.PROPERTY_TYPE <> 'L' " . "\tAND p.PROPERTY_TYPE <> 'G' "; $db_res = $DB->Query($strSql); while ($res = $db_res->Fetch()) { if (!isset($cacheValues[$res["IBLOCK_PROPERTY_ID"]])) { $cacheValues[$res["IBLOCK_PROPERTY_ID"]] = array(); } $cacheValues[$res["IBLOCK_PROPERTY_ID"]][] = $res; } } $ids = "0"; foreach ($ar_prop as $prop) { if ($PROPERTY_CODE) { $PROP = $PROPERTY_VALUES; } else { if (strlen($prop["CODE"]) > 0 && in_array($prop["CODE"], $arPROP_ID, TRUE)) { $PROP = $PROPERTY_VALUES[$prop["CODE"]]; } else { $PROP = $PROPERTY_VALUES[$prop["ID"]]; } } if ($prop["PROPERTY_TYPE"] == "F") { if (!is_array($PROP) || is_array($PROP) && (is_set($PROP, "tmp_name") || is_set($PROP, "del")) || count($PROP) == 2 && is_set($PROP, "VALUE") && is_set($PROP, "DESCRIPTION")) { $PROP = array($PROP); } } elseif (!is_array($PROP) || count($PROP) == 2 && is_set($PROP, "VALUE") && is_set($PROP, "DESCRIPTION")) { $PROP = array($PROP); } if ($prop["USER_TYPE"] != "") { $arUserType = CIBlockProperty::GetUserType($prop["USER_TYPE"]); if (array_key_exists("ConvertToDB", $arUserType)) { foreach ($PROP as $key => $value) { if (!is_array($value)) { $value = array("VALUE" => $value); } elseif (!array_key_exists("VALUE", $value)) { $value = array("VALUE" => $value); } $PROP[$key] = call_user_func_array($arUserType["ConvertToDB"], array($prop, $value)); } } } if ($prop["VERSION"] == 2) { if ($prop["MULTIPLE"] == "Y") { $strTable = "b_iblock_element_prop_m" . $prop["IBLOCK_ID"]; } else { $strTable = "b_iblock_element_prop_s" . $prop["IBLOCK_ID"]; } } else { $strTable = "b_iblock_element_property"; } if ($prop["PROPERTY_TYPE"] == "L") { $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID), false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $ids = "0"; foreach ($PROP as $key => $value) { if (is_array($value)) { $value = $value["VALUE"]; } if (IntVal($value) <= 0) { continue; } $ids .= "," . IntVal($value); if ($prop["MULTIPLE"] != "Y") { break; } } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $strSql = "\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . " E\n\t\t\t\t\t\t\t,b_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tE.PROPERTY_" . $prop["ID"] . "=PEN.ID\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tE.IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\tAND P.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND P.ID=PEN.PROPERTY_ID\n\t\t\t\t\t\t\tAND PEN.ID IN (" . $ids . ")\n\t\t\t\t\t"; } else { $strSql = "\n\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_ENUM)\n\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, PEN.ID, PEN.ID\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tP.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND P.ID=PEN.PROPERTY_ID\n\t\t\t\t\t\t\tAND PEN.ID IN (" . $ids . ")\n\t\t\t\t\t"; } $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } elseif ($prop["PROPERTY_TYPE"] == "G") { $bRecalcSections = true; $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID), false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $DB->Query("DELETE FROM b_iblock_section_element WHERE ADDITIONAL_PROPERTY_ID=" . $prop["ID"] . " AND IBLOCK_ELEMENT_ID=" . $ELEMENT_ID, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ids = "0"; foreach ($PROP as $key => $value) { if (is_array($value)) { $value = $value["VALUE"]; } if (IntVal($value) <= 0) { continue; } $ids .= "," . IntVal($value); if ($prop["MULTIPLE"] != "Y") { break; } } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $strSql = "\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . " E\n\t\t\t\t\t\t\t,b_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tE.PROPERTY_" . $prop["ID"] . "=S.ID\n\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=null\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tE.IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\tAND P.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\tAND S.ID IN (" . $ids . ")\n\t\t\t\t\t"; } else { $strSql = "\n\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM)\n\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, S.ID, S.ID\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tP.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\tAND S.ID IN (" . $ids . ")\n\t\t\t\t\t"; } $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $DB->Query("INSERT INTO b_iblock_section_element(IBLOCK_ELEMENT_ID, IBLOCK_SECTION_ID, ADDITIONAL_PROPERTY_ID) " . "SELECT " . $ELEMENT_ID . ", S.ID, P.ID " . "FROM b_iblock_property P, b_iblock_section S " . "WHERE P.ID=" . $prop["ID"] . " " . "\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID " . "\tAND S.ID IN (" . $ids . ") ", false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } else { $ids = "0"; $arV = array(); if ($cacheValues === false || $prop["VERSION"] == 2) { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $strSql = "\n\t\t\t\t\t\t\tSELECT\tconcat(IBLOCK_ELEMENT_ID,':','" . $prop["ID"] . "') ID, PROPERTY_" . $prop["ID"] . " VALUE\n\t\t\t\t\t\t\tFROM\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID; } else { $strSql = "\n\t\t\t\t\t\t\tSELECT\tID, VALUE\n\t\t\t\t\t\t\tFROM\t" . $strTable . "\n\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID=" . $prop["ID"]; } $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($res = $db_res->Fetch()) { $arV[] = $res; } } elseif (is_set($cacheValues, $prop["ID"])) { $arV = $cacheValues[$prop["ID"]]; } $arWas = array(); foreach ($arV as $res) { $val = $PROP[$res["ID"]]; if (is_array($val) && !is_set($val, "tmp_name") && !is_set($val, "del")) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if ($prop["PROPERTY_TYPE"] == "E") { if (in_array($val, $arWas)) { $val = ""; } else { $arWas[] = $val; } } if ($prop["PROPERTY_TYPE"] == "S" || $prop["PROPERTY_TYPE"] == "N" || $prop["PROPERTY_TYPE"] == "E") { if (strlen($val) <= 0) { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID; } else { $strSql = "DELETE FROM " . $strTable . " WHERE ID=" . $res["ID"]; } $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } else { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { if ($prop["PROPERTY_TYPE"] == "N") { $val = CIBlock::roundDB($val); } $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "='" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=" . ($val_desc !== false ? "'" . $DB->ForSQL($val_desc, 255) . "'" : "null") . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID; } else { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET \tVALUE='" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t\t,VALUE_NUM=" . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"]; } $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } } elseif ($prop["PROPERTY_TYPE"] == "F") { if (is_array($val)) { if (strlen($val["del"]) > 0) { $val = "NULL"; } else { $val["MODULE_ID"] = "iblock"; if ($val_desc !== false) { $val["description"] = $val_desc; } if ($val_desc !== false && strlen($val["name"]) <= 0) { //update description only if ($res["VALUE"] > 0) { CFile::UpdateDesc($res["VALUE"], $val_desc); } $val = false; } else { //register new file $val = CFile::SaveFile($val, "iblock"); } } } if ($val == "NULL") { CIBLockElement::DeleteFile($res["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $prop["IBLOCK_ID"]); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID; } else { $strSql = "DELETE FROM " . $strTable . " WHERE ID=" . $res["ID"]; } $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } elseif (IntVal($val) > 0) { if (intval($val) != $res["VALUE"]) { CIBLockElement::DeleteFile($res["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $prop["IBLOCK_ID"]); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION_" . $prop["ID"] . "='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID; } else { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET \tVALUE='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t\t,VALUE_NUM='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"]; } $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } elseif ($val_desc !== false) { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET DESCRIPTION_" . $prop["ID"] . "='" . $DB->ForSql($val_desc, 255) . "'\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"; } else { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"] . "\n\t\t\t\t\t\t\t\t"; } $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } } $ids .= "," . $res["ID"]; unset($PROP[$res["ID"]]); } //foreach($arV as $res) foreach ($PROP as $key => $val) { if (is_array($val) && !is_set($val, "tmp_name")) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if ($prop["PROPERTY_TYPE"] == "F") { if (is_array($val)) { $val["MODULE_ID"] = "iblock"; if ($val_desc !== false) { $val["description"] = $val_desc; } $val = CFile::SaveFile($val, "iblock"); } if (intval($val) <= 0) { $val = false; } elseif ($prop["MULTIPLE"] != "Y" && strlen($val) > 0) { $strSql = "\n\t\t\t\t\t\t\t\tSELECT VALUE\n\t\t\t\t\t\t\t\tFROM b_iblock_element_property\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID=" . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t\t"; if ($prop["VERSION"] == 2) { if ($prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\t\t\t\t\tSELECT PROPERTY_" . $prop["ID"] . " VALUE\n\t\t\t\t\t\t\t\t\t\tFROM b_iblock_element_prop_m" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID=" . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t\t\t\t"; } else { $strSql = "\n\t\t\t\t\t\t\t\t\t\tSELECT PROPERTY_" . $prop["ID"] . " VALUE\n\t\t\t\t\t\t\t\t\t\tFROM b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t\t"; } } $pfres = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($pfar = $pfres->Fetch()) { CIBLockElement::DeleteFile($pfar["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $prop["IBLOCK_ID"]); } $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID), false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } } elseif ($prop["PROPERTY_TYPE"] == "E") { if (in_array($val, $arWas)) { $val = ""; } else { $arWas[] = $val; } } if (strlen($val) > 0) { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $strSql = "\n\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . " = '" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=" . ($val_desc !== false ? "'" . $DB->ForSQL($val_desc, 255) . "'" : "null") . "\n\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID; } else { $strSql = "\n\t\t\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM" . ($val_desc !== false ? ", DESCRIPTION" : "") . ")\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\t" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t\t,P.ID\n\t\t\t\t\t\t\t\t\t,'" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t," . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ", '" . $DB->ForSQL($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\tFROM\tb_iblock_property P\n\t\t\t\t\t\t\t\tWHERE\tID=" . IntVal($prop["ID"]); } $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $strSql = "\n\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } if ($prop["MULTIPLE"] != "Y") { break; } } $ids .= "," . $prop["ID"]; } //foreach($PROP as $key=>$value) } //if($prop["PROPERTY_TYPE"]=="L") } if ($bRecalcSections) { CIBlockElement::RecalcSections($ELEMENT_ID); } /****************************** QUOTA ******************************/ $_SESSION["SESS_RECOUNT_DB"] = "Y"; /****************************** QUOTA ******************************/ }
function SetElementSection($ID, $arSections, $bNew = false, $bRightsIBlock = 0, $sectionId = null) { global $DB; $ID = intval($ID); $min_old_id = null; $min_new_id = null; $arToDelete = array(); $arToInsert = array(); if (is_array($arSections)) { foreach ($arSections as $section_id) { $section_id = intval($section_id); if ($section_id > 0) { if (!isset($min_new_id) || $section_id < $min_new_id) { $min_new_id = $section_id; } $arToInsert[$section_id] = $section_id; } } } else { $section_id = intval($arSections); if ($section_id > 0) { $arToInsert[$section_id] = $section_id; $min_new_id = $section_id; } } $arOldParents = array(); $arNewParents = $arToInsert; $bParentsChanged = false; //Read database if (!$bNew) { $rs = $DB->Query("\n\t\t\t\tSELECT * FROM b_iblock_section_element\n\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ID . "\n\t\t\t\tAND ADDITIONAL_PROPERTY_ID IS NULL\n\t\t\t", false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($ar = $rs->Fetch()) { $section_id = intval($ar["IBLOCK_SECTION_ID"]); $arOldParents[] = $section_id; if (!isset($min_old_id) || $section_id < $min_old_id) { $min_old_id = $section_id; } if (isset($arToInsert[$section_id])) { unset($arToInsert[$section_id]); //This already in DB } else { $arToDelete[] = $section_id; } } if (!empty($arToDelete)) { $bParentsChanged = true; $DB->Query($s = "\n\t\t\t\t\tDELETE FROM b_iblock_section_element\n\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ID . "\n\t\t\t\t\tAND ADDITIONAL_PROPERTY_ID IS NULL\n\t\t\t\t\tAND IBLOCK_SECTION_ID in (" . implode(", ", $arToDelete) . ")\n\t\t\t\t", false, "File: " . __FILE__ . "<br>Line: " . __LINE__); //And this should be deleted } } if (!empty($arToInsert)) { $bParentsChanged = true; $DB->Query("\n\t\t\t\tINSERT INTO b_iblock_section_element(IBLOCK_SECTION_ID, IBLOCK_ELEMENT_ID)\n\t\t\t\tSELECT S.ID, E.ID\n\t\t\t\tFROM b_iblock_section S, b_iblock_element E\n\t\t\t\tWHERE S.IBLOCK_ID = E.IBLOCK_ID\n\t\t\t\tAND S.ID IN (" . implode(", ", $arToInsert) . ")\n\t\t\t\tAND E.ID = " . $ID . "\n\t\t\t"); } if ($bParentsChanged && $bRightsIBlock) { $obElementRights = new CIBlockElementRights($bRightsIBlock, $ID); if (empty($arOldParents)) { $arOldParents[] = 0; } if (empty($arNewParents)) { $arNewParents[] = 0; } $obElementRights->ChangeParents($arOldParents, $arNewParents); } if ($sectionId !== null || $min_old_id !== $min_new_id) { CIBlockElement::RecalcSections($ID, $sectionId); } return !empty($arToDelete) || !empty($arToInsert); }
$_REQUEST["PUBLIC_ELEMENT"] = $_REQUEST["PUBLIC_ELEMENT"] == "Y" ? "Y" : "N"; $_REQUEST["APPROVE_ELEMENT"] = $_REQUEST["APPROVE_ELEMENT"] == "Y" ? "Y" : "N"; if ($arParams["BEHAVIOUR"] == "USER") { if (is_set($arResult["ELEMENT"]["PROPERTIES"], "PUBLIC_ELEMENT") && $arResult["ELEMENT"]["PROPERTIES"]["PUBLIC_ELEMENT"]["VALUE"] != $_REQUEST["PUBLIC_ELEMENT"]) { CIBlockElement::SetPropertyValues($arParams["ELEMENT_ID"], $arParams["IBLOCK_ID"], $_REQUEST["PUBLIC_ELEMENT"], "PUBLIC_ELEMENT"); if ($arParams["ABS_PERMISSION"] < "U" && $_REQUEST["PUBLIC_ELEMENT"] == "Y") { CIBlockElement::SetPropertyValues($arParams["ELEMENT_ID"], $arParams["IBLOCK_ID"], 'X', "APPROVE_ELEMENT"); } } if ($arParams["ABS_PERMISSION"] >= "U" && is_set($arResult["ELEMENT"]["PROPERTIES"], "APPROVE_ELEMENT") && $arResult["ELEMENT"]["PROPERTIES"]["APPROVE_ELEMENT"]["VALUE"] != $_REQUEST["APPROVE_ELEMENT"]) { CIBlockElement::SetPropertyValues($arParams["ELEMENT_ID"], $arParams["IBLOCK_ID"], $_REQUEST["APPROVE_ELEMENT"], "APPROVE_ELEMENT"); } } if ($arParams["SECTION_ID"] != $_REQUEST["TO_SECTION_ID"]) { CIBlockElement::RecalcSections($arParams["SECTION_ID"]); CIBlockElement::RecalcSections($_REQUEST["TO_SECTION_ID"]); } if ($arParams["AJAX_CALL"] != "Y") { } elseif ($arParams["SECTION_ID"] != $_REQUEST["TO_SECTION_ID"]) { $result = array("url" => CComponentEngine::MakePathFromTemplate($arParams["~DETAIL_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $_REQUEST["TO_SECTION_ID"], "ELEMENT_ID" => $arResult["ELEMENT"]["ID"]))); } else { $arSelect = array("ID", "NAME", "DETAIL_TEXT", "DETAIL_TEXT_TYPE", "TAGS", "DATE_CREATE", "CREATED_BY"); $db_res = CIBlockElement::GetList(array(), array("ID" => $arParams["ELEMENT_ID"]), false, false, $arSelect); if ($db_res && ($res = $db_res->GetNext())) { $result = array("TAGS" => $res["TAGS"], "TITLE" => $res["NAME"], "DESCRIPTION" => $res["DETAIL_TEXT"], "DATE" => $res["DATE_CREATE"]); } else { $result = array("TAGS" => htmlspecialcharsEx($_REQUEST["TAGS"]), "TITLE" => htmlspecialcharsEx($_REQUEST["TITLE"]), "DESCRIPTION" => htmlspecialcharsEx($_REQUEST["DESCRIPTION"]), "DATE" => htmlspecialcharsEx($_REQUEST["DATE_CREATE"])); } } $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~DETAIL_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $_REQUEST["TO_SECTION_ID"], "ELEMENT_ID" => $arResult["ELEMENT"]["ID"])); }
function SetPropertyValues($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $PROPERTY_CODE = false) { global $DB; global $BX_IBLOCK_PROP_CACHE; $ELEMENT_ID = (int) $ELEMENT_ID; $IBLOCK_ID = (int) $IBLOCK_ID; if (!is_array($PROPERTY_VALUES)) { $PROPERTY_VALUES = array($PROPERTY_VALUES); } $uniq_flt = $IBLOCK_ID; $arFilter = array("IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "N"); if ($PROPERTY_CODE === false) { $arFilter["ACTIVE"] = "Y"; $uniq_flt .= "|ACTIVE:" . $arFilter["ACTIVE"]; } elseif ((int) $PROPERTY_CODE > 0) { $arFilter["ID"] = (int) $PROPERTY_CODE; $uniq_flt .= "|ID:" . $arFilter["ID"]; } else { $arFilter["CODE"] = $PROPERTY_CODE; $uniq_flt .= "|CODE:" . $arFilter["CODE"]; } if (!isset($BX_IBLOCK_PROP_CACHE[$IBLOCK_ID])) { $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID] = array(); } if (!isset($BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt])) { $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt] = array(); $db_prop = CIBlockProperty::GetList(array(), $arFilter); while ($prop = $db_prop->Fetch()) { $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt][$prop["ID"]] = $prop; } unset($prop); unset($db_prop); } $ar_prop =& $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt]; reset($ar_prop); $bRecalcSections = false; //Read current property values from database $arDBProps = array(); if (CIBLock::GetArrayByID($IBLOCK_ID, "VERSION") == 2) { $rs = $DB->Query("\n\t\t\t\tselect *\n\t\t\t\tfrom b_iblock_element_prop_m" . $IBLOCK_ID . "\n\t\t\t\twhere IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\torder by ID asc\n\t\t\t"); while ($ar = $rs->Fetch()) { $property_id = $ar["IBLOCK_PROPERTY_ID"]; if (!isset($arDBProps[$property_id])) { $arDBProps[$property_id] = array(); } $arDBProps[$property_id][$ar["ID"]] = $ar; } unset($ar); unset($rs); $rs = $DB->Query("\n\t\t\t\tselect *\n\t\t\t\tfrom b_iblock_element_prop_s" . $IBLOCK_ID . "\n\t\t\t\twhere IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t"); if ($ar = $rs->Fetch()) { foreach ($ar_prop as $property) { $property_id = $property["ID"]; if ($property["MULTIPLE"] == "N" && isset($ar["PROPERTY_" . $property_id]) && strlen($ar["PROPERTY_" . $property_id])) { if (!isset($arDBProps[$property_id])) { $arDBProps[$property_id] = array(); } $arDBProps[$property_id][$ELEMENT_ID . ":" . $property_id] = array("ID" => $ELEMENT_ID . ":" . $property_id, "IBLOCK_PROPERTY_ID" => $property_id, "VALUE" => $ar["PROPERTY_" . $property_id], "DESCRIPTION" => $ar["DESCRIPTION_" . $property_id]); } } if (isset($property)) { unset($property); } } unset($ar); unset($rs); } else { $rs = $DB->Query("\n\t\t\t\tselect *\n\t\t\t\tfrom b_iblock_element_property\n\t\t\t\twhere IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\torder by ID asc\n\t\t\t"); while ($ar = $rs->Fetch()) { $property_id = $ar["IBLOCK_PROPERTY_ID"]; if (!isset($arDBProps[$property_id])) { $arDBProps[$property_id] = array(); } $arDBProps[$property_id][$ar["ID"]] = $ar; } unset($ar); unset($rs); } foreach (GetModuleEvents("iblock", "OnIBlockElementSetPropertyValues", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $PROPERTY_CODE, $ar_prop, $arDBProps)); } if (isset($arEvent)) { unset($arEvent); } $arFilesToDelete = array(); $arV2ClearCache = array(); foreach ($ar_prop as $prop) { if ($PROPERTY_CODE) { $PROP = $PROPERTY_VALUES; } else { if (strlen($prop["CODE"]) > 0 && array_key_exists($prop["CODE"], $PROPERTY_VALUES)) { $PROP = $PROPERTY_VALUES[$prop["CODE"]]; } else { $PROP = $PROPERTY_VALUES[$prop["ID"]]; } } if (!is_array($PROP) || $prop["PROPERTY_TYPE"] == "F" && (array_key_exists("tmp_name", $PROP) || array_key_exists("del", $PROP)) || count($PROP) == 2 && array_key_exists("VALUE", $PROP) && array_key_exists("DESCRIPTION", $PROP)) { $PROP = array($PROP); } if ($prop["USER_TYPE"] != "") { $arUserType = CIBlockProperty::GetUserType($prop["USER_TYPE"]); if (array_key_exists("ConvertToDB", $arUserType)) { foreach ($PROP as $key => $value) { if (!is_array($value) || !array_key_exists("VALUE", $value)) { $value = array("VALUE" => $value); } $prop["ELEMENT_ID"] = $ELEMENT_ID; $PROP[$key] = call_user_func_array($arUserType["ConvertToDB"], array($prop, $value)); } } } if ($prop["VERSION"] == 2) { if ($prop["MULTIPLE"] == "Y") { $strTable = "b_iblock_element_prop_m" . $prop["IBLOCK_ID"]; } else { $strTable = "b_iblock_element_prop_s" . $prop["IBLOCK_ID"]; } } else { $strTable = "b_iblock_element_property"; } if ($prop["PROPERTY_TYPE"] == "L") { $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID)); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } $ids = "0"; foreach ($PROP as $key => $value) { if (is_array($value)) { $value = intval($value["VALUE"]); } else { $value = intval($value); } if ($value <= 0) { continue; } $ids .= "," . $value; if ($prop["MULTIPLE"] != "Y") { break; } } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query("\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . " E\n\t\t\t\t\t\t\t,b_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tE.PROPERTY_" . $prop["ID"] . " = PEN.ID\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tE.IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t\t\t\tAND P.ID = " . $prop["ID"] . "\n\t\t\t\t\t\t\tAND P.ID = PEN.PROPERTY_ID\n\t\t\t\t\t\t\tAND PEN.ID IN (" . $ids . ")\n\t\t\t\t\t"); } else { $DB->Query("\n\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_ENUM)\n\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, PEN.ID, PEN.ID\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tP.ID = " . $prop["ID"] . "\n\t\t\t\t\t\t\tAND P.ID = PEN.PROPERTY_ID\n\t\t\t\t\t\t\tAND PEN.ID IN (" . $ids . ")\n\t\t\t\t\t"); } } elseif ($prop["PROPERTY_TYPE"] == "G") { $bRecalcSections = true; $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID)); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } $DB->Query("\n\t\t\t\t\tDELETE FROM b_iblock_section_element\n\t\t\t\t\tWHERE ADDITIONAL_PROPERTY_ID = " . $prop["ID"] . "\n\t\t\t\t\tAND IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t"); $ids = "0"; foreach ($PROP as $key => $value) { if (is_array($value)) { $value = intval($value["VALUE"]); } else { $value = intval($value); } if ($value <= 0) { continue; } $ids .= "," . $value; if ($prop["MULTIPLE"] != "Y") { break; } } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query("\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . " E\n\t\t\t\t\t\t\t,b_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tE.PROPERTY_" . $prop["ID"] . " = S.ID\n\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tE.IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t\t\t\tAND P.ID = " . $prop["ID"] . "\n\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\tP.LINK_IBLOCK_ID IS NULL\n\t\t\t\t\t\t\t\tOR P.LINK_IBLOCK_ID = 0\n\t\t\t\t\t\t\t\tOR S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tAND S.ID IN (" . $ids . ")\n\t\t\t\t\t"); } else { $DB->Query("\n\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM)\n\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, S.ID, S.ID\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tP.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\tP.LINK_IBLOCK_ID IS NULL\n\t\t\t\t\t\t\t\tOR P.LINK_IBLOCK_ID = 0\n\t\t\t\t\t\t\t\tOR S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tAND S.ID IN (" . $ids . ")\n\t\t\t\t\t"); } $DB->Query("\n\t\t\t\t\tINSERT INTO b_iblock_section_element\n\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_SECTION_ID, ADDITIONAL_PROPERTY_ID)\n\t\t\t\t\tSELECT " . $ELEMENT_ID . ", S.ID, P.ID\n\t\t\t\t\tFROM\n\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tP.ID = " . $prop["ID"] . "\n\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\tP.LINK_IBLOCK_ID IS NULL\n\t\t\t\t\t\t\tOR P.LINK_IBLOCK_ID = 0\n\t\t\t\t\t\t\tOR S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND S.ID IN (" . $ids . ")\n\t\t\t\t"); } elseif ($prop["PROPERTY_TYPE"] == "E") { $arWas = array(); if ($arDBProps[$prop["ID"]]) { foreach ($arDBProps[$prop["ID"]] as $res) { $val = $PROP[$res["ID"]]; if (is_array($val)) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (isset($arWas[$val])) { $val = ""; } else { $arWas[$val] = true; } if (strlen($val) <= 0) { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query($s = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . " = null\n\t\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"); } else { $DB->Query($s = "\n\t\t\t\t\t\t\t\t\tDELETE FROM " . $strTable . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"] . "\n\t\t\t\t\t\t\t\t"); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } } elseif ($res["VALUE"] !== $val || $res["DESCRIPTION"] . '' !== $val_desc . '') { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query("\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . " = '" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc) . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"); } else { $DB->Query("\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET VALUE = '" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t\t,VALUE_NUM = " . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION = '" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"] . "\n\t\t\t\t\t\t\t\t"); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } } unset($PROP[$res["ID"]]); } //foreach($arDBProps[$prop["ID"]] as $res) } foreach ($PROP as $val) { if (is_array($val)) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (isset($arWas[$val])) { $val = ""; } else { $arWas[$val] = true; } if (strlen($val) <= 0) { continue; } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query("\n\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . " = '" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc) . "\n\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t"); } else { $DB->Query("\n\t\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM" . ($val_desc !== false ? ", DESCRIPTION" : "") . ")\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t,P.ID\n\t\t\t\t\t\t\t\t,'" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t," . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ", '" . $DB->ForSQL($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tID = " . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t"); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } if ($prop["MULTIPLE"] != "Y") { break; } } //foreach($PROP as $value) } elseif ($prop["PROPERTY_TYPE"] == "F") { //We'll be adding values from the database into the head //for multiple values and into tje tail for single //these values were not passed into API call. if ($prop["MULTIPLE"] == "Y") { $orderedPROP = array_reverse($PROP, true); } else { $orderedPROP = $PROP; } if ($arDBProps[$prop["ID"]]) { //Go from high ID to low foreach (array_reverse($arDBProps[$prop["ID"]], true) as $res) { //Preserve description from database if (strlen($res["DESCRIPTION"])) { $description = $res["DESCRIPTION"]; } else { $description = false; } if (!array_key_exists($res["ID"], $orderedPROP)) { $orderedPROP[$res["ID"]] = array("VALUE" => $res["VALUE"], "DESCRIPTION" => $description); } else { $val = $orderedPROP[$res["ID"]]; if (is_array($val) && !array_key_exists("tmp_name", $val) && !array_key_exists("del", $val)) { $val = $val["VALUE"]; } //Check if no new file and no delete command if (!strlen($val["tmp_name"]) && !strlen($val["del"])) { //But save description from incoming value if (array_key_exists("description", $val)) { $description = trim($val["description"]); } $orderedPROP[$res["ID"]] = array("VALUE" => $res["VALUE"], "DESCRIPTION" => $description); } } } } //Restore original order if ($prop["MULTIPLE"] == "Y") { $orderedPROP = array_reverse($orderedPROP, true); } $preserveID = array(); //Now delete from database all marked for deletion records if ($arDBProps[$prop["ID"]]) { foreach ($arDBProps[$prop["ID"]] as $res) { $val = $orderedPROP[$res["ID"]]; if (is_array($val) && !array_key_exists("tmp_name", $val) && !array_key_exists("del", $val)) { $val = $val["VALUE"]; } if (is_array($val) && strlen($val["del"])) { unset($orderedPROP[$res["ID"]]); $arFilesToDelete[$res["VALUE"]] = array("FILE_ID" => $res["VALUE"], "ELEMENT_ID" => $ELEMENT_ID, "IBLOCK_ID" => $prop["IBLOCK_ID"]); } elseif ($prop["MULTIPLE"] != "Y") { //Delete all stored in database for replacement. $arFilesToDelete[$res["VALUE"]] = array("FILE_ID" => $res["VALUE"], "ELEMENT_ID" => $ELEMENT_ID, "IBLOCK_ID" => $prop["IBLOCK_ID"]); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query("\n\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . " = null\n\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) . "\n\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t\t\t\t"); } else { $DB->Query("DELETE FROM " . $strTable . " WHERE ID = " . $res["ID"]); $preserveID[$res["ID"]] = $res["ID"]; } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } } //foreach($arDBProps[$prop["ID"]] as $res) } //Check if we have to save property values id's if ($preserveID) { //Find tail mark where all added files started $tailStart = null; foreach (array_reverse($orderedPROP, true) as $propertyValueId => $val) { if (intval($propertyValueId) > 0) { break; } $tailStart = $propertyValueId; } $prevId = 0; foreach ($orderedPROP as $propertyValueId => $val) { if ($propertyValueId === $tailStart) { break; } if (intval($propertyValueId) < $prevId) { $preserveID = array(); break; } $prevId = $propertyValueId; } } //Write new values into database in specified order foreach ($orderedPROP as $propertyValueId => $val) { if (is_array($val) && !array_key_exists("tmp_name", $val)) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (is_array($val)) { $val["MODULE_ID"] = "iblock"; if ($val_desc !== false) { $val["description"] = $val_desc; } $val = CFile::SaveFile($val, "iblock"); } elseif ($val > 0 && $val_desc !== false) { CFile::UpdateDesc($val, $val_desc); } if (intval($val) <= 0) { continue; } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query($s = "\n\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . " = '" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc) . "\n\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t"); } elseif (array_key_exists($propertyValueId, $preserveID)) { $DB->Query("\n\t\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t\t(ID, IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM" . ($val_desc !== false ? ", DESCRIPTION" : "") . ")\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t" . $preserveID[$propertyValueId] . "\n\t\t\t\t\t\t\t\t," . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t,P.ID\n\t\t\t\t\t\t\t\t,'" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t," . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ", '" . $DB->ForSQL($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tID = " . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t"); } else { $DB->Query("\n\t\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM" . ($val_desc !== false ? ", DESCRIPTION" : "") . ")\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t,P.ID\n\t\t\t\t\t\t\t\t,'" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t," . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ", '" . $DB->ForSQL($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tID = " . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t"); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } if ($prop["MULTIPLE"] != "Y") { break; } } //foreach($PROP as $value) } else { if ($arDBProps[$prop["ID"]]) { foreach ($arDBProps[$prop["ID"]] as $res) { $val = $PROP[$res["ID"]]; if (is_array($val)) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (strlen($val) <= 0) { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query("\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . " = null\n\t\t\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"); } else { $DB->Query("DELETE FROM " . $strTable . " WHERE ID=" . $res["ID"]); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } } else { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { if ($prop["PROPERTY_TYPE"] == "N") { $val = CIBlock::roundDB($val); } $DB->Query("\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "='" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc) . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t"); } else { $DB->Query("\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET \tVALUE='" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t\t,VALUE_NUM=" . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"] . "\n\t\t\t\t\t\t\t\t"); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } } unset($PROP[$res["ID"]]); } //foreach ($arDBProps[$prop["ID"]] as $res) } foreach ($PROP as $val) { if (is_array($val) && !is_set($val, "tmp_name")) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (strlen($val) <= 0) { continue; } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { if ($prop["PROPERTY_TYPE"] == "N") { $val = CIBlock::roundDB($val); } $DB->Query("\n\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . " = '" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc) . "\n\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t"); } else { $DB->Query("\n\t\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM" . ($val_desc !== false ? ", DESCRIPTION" : "") . ")\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t,P.ID\n\t\t\t\t\t\t\t\t,'" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t," . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ", '" . $DB->ForSQL($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tID = " . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t"); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]); } if ($prop["MULTIPLE"] != "Y") { break; } } //foreach($PROP as $value) } //if($prop["PROPERTY_TYPE"]=="F") } if ($arV2ClearCache) { $DB->Query("\n\t\t\t\tUPDATE b_iblock_element_prop_s" . $IBLOCK_ID . "\n\t\t\t\tSET " . implode(",", $arV2ClearCache) . "\n\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t"); } foreach ($arFilesToDelete as $deleteTask) { CIBLockElement::DeleteFile($deleteTask["FILE_ID"], false, "PROPERTY", $deleteTask["ELEMENT_ID"], $deleteTask["IBLOCK_ID"]); } if ($bRecalcSections) { CIBlockElement::RecalcSections($ELEMENT_ID); } /****************************** QUOTA ******************************/ $_SESSION["SESS_RECOUNT_DB"] = "Y"; /****************************** QUOTA ******************************/ foreach (GetModuleEvents("iblock", "OnAfterIBlockElementSetPropertyValues", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $PROPERTY_CODE)); } }
} $boolFlagClear = CIBlockOffersTmp::Delete($str_TMP_ID); $boolFlagClearAll = CIBlockOffersTmp::DeleteOldID($IBLOCK_ID); } } } if (!$res) { $strWarning .= $bs->LAST_ERROR."<br>"; } else { $ipropValues = new \Bitrix\Iblock\InheritedProperty\ElementValues($IBLOCK_ID, $ID); $ipropValues->clearValues(); CIBlockElement::RecalcSections($ID); } if ('' == $strWarning && $bCatalog) { $arCatalogItem = array( 'IBLOCK_ID' => $IBLOCK_ID, 'SECTION_ID' => $MENU_SECTION_ID, 'ID' => $ID, 'PRODUCT_ID' => CIBlockElement::GetRealElement($ID) ); if ($arShowTabs['catalog']) { include($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/catalog/admin/templates/product_edit_action.php"); } elseif ($arShowTabs['sku'])
function handleFile($hash, $photo, &$package, &$upload, &$error) { if (!CModule::IncludeModule("iblock")) { return false; } global $USER; $arParams = $this->arParams; if (!($upload["SECTION_ID"] > 0)) { if ($this->post["photo_album_id"] > 0) { $upload["SECTION_ID"] = $this->post["photo_album_id"]; } else { $upload["NEW_SECTION_ID"] = $upload["SECTION_ID"] = self::createAlbum($this->arParams, $this->arResult, $this->post["new_album_name"]); } $this->arParams["SECTION_ID"] = $upload["SECTION_ID"]; $upload["redirectUrl"] = CComponentEngine::MakePathFromTemplate($this->arParams["~SECTION_URL"], array("USER_ALIAS" => $this->arParams["USER_ALIAS"], "SECTION_ID" => $this->arParams["SECTION_ID"])); self::adjustIBlock($this->arParams); } if (!($upload["SECTION_ID"] > 0)) { $error = "Album is not created or does not exist."; return false; } $arParams["bxu"]->checkCanvases($hash, $photo, $arParams['converters'], $this->arWatermark); // Props $_REQUEST["Public"] = $_REQUEST["Public"] == "N" ? "N" : "Y"; $Prop = array("REAL_PICTURE" => array("n0" => $photo["files"]["default"]), "PUBLIC_ELEMENT" => array("n0" => $_REQUEST["Public"]), "APPROVE_ELEMENT" => array("n0" => ($arParams["ABS_PERMISSION"] >= "U" || $arParams["APPROVE_BY_DEFAULT"] == "Y") && $_REQUEST["Public"] == "Y" ? "Y" : "X")); foreach ($arParams['converters'] as $val) { if ($val['code'] != "default" && $val['code'] != "thumbnail") { $Prop[strtoupper($val['code'])] = array("n0" => $photo["files"][$val['code']]); } } // Real photo $arFields = array("ACTIVE" => $arParams["MODERATION"] == "Y" && $arParams["ABS_PERMISSION"] < "U" ? "N" : "Y", "MODIFIED_BY" => $USER->GetID(), "IBLOCK_SECTION" => $upload['SECTION_ID'], "IBLOCK_ID" => $arParams["IBLOCK_ID"], "NAME" => $photo['name'], "CODE" => $photo['name'], "TAGS" => $photo['tags'], "DETAIL_TEXT" => $photo['description'], "DETAIL_TEXT_TYPE" => "text", "PREVIEW_PICTURE" => $photo["files"]["thumbnail"], "PREVIEW_TEXT" => $photo['description'], "PREVIEW_TEXT_TYPE" => "text", "PROPERTY_VALUES" => $Prop); $bs = new CIBlockElement(); $ID = $bs->Add($arFields); if ($ID <= 0) { $error = $bs->LAST_ERROR; return false; } $arFields['ID'] = $ID; $_SESSION['arUploadedPhotos'][] = $ID; CIBlockElement::RecalcSections($ID); $arParams['SECTION_ID'] = $upload['SECTION_ID']; $arResult = $this->arResult; foreach (GetModuleEvents("photogallery", "OnAfterUpload", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arFields, $arParams, $arResult)); } // Add thumbnail only for new album if ($upload["NEW_SECTION_ID"] > 0 && !array_key_exists('NEW_SECTION_PICTURE', $upload)) { $File = $photo["files"]["default"]; // Big picture $File['~tmp_name'] = $File['tmp_name']; $File['tmp_name'] .= "_album_cover.tmp"; if (CFile::ResizeImageFile($File['tmp_name'], $File['tmp_name_1'], array('width' => $arParams["ALBUM_PHOTO_THUMBS"]["SIZE"], 'height' => $arParams["ALBUM_PHOTO_THUMBS"]["SIZE"]), BX_RESIZE_IMAGE_PROPORTIONAL)) { $bs = new CIBlockSection(); if ($bs->Update($upload["SECTION_ID"], array("PICTURE" => $File), false, false)) { $upload['NEW_SECTION_PICTURE'] = true; } } } return $ID; }
function SaveEvent($arParams) { global $DB; $iblockId = $arParams['iblockId']; $ownerType = $arParams['ownerType']; $ownerId = $arParams['ownerId']; $bCheckPermissions = $arParams["bCheckPermissions"] !== false; $calendarId = intVal($arParams['calendarId']); $sectionId = $arParams['sectionId']; $fullUrl = $arParams['fullUrl']; $userId = $arParams['userId']; $bIsInvitingEvent = $arParams['isMeeting'] && intval($arParams['prop']['PARENT']) > 0; $bExchange = CEventCalendar::IsExchangeEnabled() && $ownerType == 'USER'; $bCalDav = CEventCalendar::IsCalDAVEnabled() && $ownerType == 'USER'; if (!$bIsInvitingEvent) { // *** ADD MEETING ROOM *** $loc_old = CEventCalendar::ParseLocation($arParams['location']['old']); $loc_new = CEventCalendar::ParseLocation($arParams['location']['new']); if ($loc_old['mrid'] !== false && $loc_old['mrevid'] !== false && ($loc_old['mrid'] !== $loc_new['mrid'] || $arParams['location'])) { if ($loc_old['mrid'] == $arParams['VMiblockId']) { CEventCalendar::ReleaseVR(array('mrevid' => $loc_old['mrevid'], 'mrid' => $loc_old['mrid'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting'])); } else { CEventCalendar::ReleaseMR(array('mrevid' => $loc_old['mrevid'], 'mrid' => $loc_old['mrid'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting'])); } } if ($loc_new['mrid'] !== false) { if ($loc_new['mrid'] == $arParams['VMiblockId']) { $mrevid = CEventCalendar::ReserveVR(array('mrid' => $loc_new['mrid'], 'dateFrom' => $arParams['dateFrom'], 'dateTo' => $arParams['dateTo'], 'name' => $arParams['name'], 'description' => GetMessage('EC_RESERVE_FOR_EVENT') . ': ' . $arParams['name'], 'persons' => count($arParams['guests']), 'members' => $arParams['guests'], 'regularity' => $arParams['prop']['PERIOD_TYPE'], 'regularity_count' => $arParams['prop']['PERIOD_COUNT'], 'regularity_length' => $arParams['prop']['EVENT_LENGTH'], 'regularity_additional' => $arParams['prop']['PERIOD_ADDITIONAL'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting'])); } else { $mrevid = CEventCalendar::ReserveMR(array('mrid' => $loc_new['mrid'], 'dateFrom' => $arParams['dateFrom'], 'dateTo' => $arParams['dateTo'], 'name' => $arParams['name'], 'description' => GetMessage('EC_RESERVE_FOR_EVENT') . ': ' . $arParams['name'], 'persons' => $arParams['isMeeting'] && count($arParams['guests']) > 0 ? count($arParams['guests']) : 1, 'regularity' => $arParams['prop']['PERIOD_TYPE'], 'regularity_count' => $arParams['prop']['PERIOD_COUNT'], 'regularity_length' => $arParams['prop']['EVENT_LENGTH'], 'regularity_additional' => $arParams['prop']['PERIOD_ADDITIONAL'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting'])); } if ($mrevid && $mrevid != 'reserved' && $mrevid != 'expire' && $mrevid > 0) { $loc_new = 'ECMR_' . $loc_new['mrid'] . '_' . $mrevid; $arParams["prop"]['LOCATION'] = $loc_new; } else { $arParams["prop"]['LOCATION'] = ''; if ($mrevid == 'reserved') { $loc_new = 'bxec_error_reserved'; } elseif ($mrevid == 'expire') { $loc_new = 'bxec_error_expire'; } else { $loc_new = 'bxec_error'; } } } else { $loc_new = $loc_new['str']; $arParams["prop"]['LOCATION'] = $loc_new; } } //$bSocNetLog = (!isset($arParams['bSocNetLog']) || $arParams['bSocNetLog'] != false) && !$arParams["prop"]["PRIVATE"]; //if(cmodule::includemodule('security')) if (CModule::IncludeModule("security")) { $filter = new CSecurityFilter(); $arParams['desc'] = $filter->TestXSS($arParams['desc'], 'replace'); } else { $arParams['desc'] = htmlspecialcharsex($arParams['desc']); } if ($calendarId > 0) { //cheking permissions and correct nesting //if (!CEventCalendar::CheckCalendar(array('iblockId' => $iblockId, 'ownerId' => $ownerId, 'ownerType' => $ownerType, 'calendarId' => $calendarId, 'sectionId' => $sectionId))) // return CEventCalendar::ThrowError(GetMessage('EC_CALENDAR_CREATE_ERROR').' '.GetMessage('EC_CAL_INCORRECT_ERROR')); } else { // Creating default calendar section for owner $bDisplayCalendar = !$arParams["notDisplayCalendar"]; // Output js with calendar description $newSectionId = 'none'; // by reference $calendarId = CECCalendar::CreateDefault(array('ownerType' => $ownerType, 'ownerId' => $ownerId, 'iblockId' => $iblockId, 'sectionId' => $sectionId), $bDisplayCalendar, $newSectionId); if (!$calendarId) { return CEventCalendar::ThrowError('2' . GetMessage('EC_CALENDAR_CREATE_ERROR')); } if ($newSectionId != 'none') { $arParams['sectionId'] = $newSectionId; } } $arParams['calendarId'] = $calendarId; if ($bIsInvitingEvent && !isset($arParams["CONFIRMED"]) && isset($arParams["status"])) { $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, $arParams["status"]); } else { if ($arParams["CONFIRMED"] == "Q") { $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, "Q"); } elseif ($arParams["CONFIRMED"] == "Y") { $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, "Y"); } else { unset($arParams["prop"]["CONFIRMED"]); } } if (isset($arParams["remind"])) { if ($arParams["remind"] !== false) { $arParams["prop"]["REMIND_SETTINGS"] = $arParams["remind"]['count'] . '_' . $arParams["remind"]['type']; } else { if (!$arParams['bNew']) { $arParams["prop"]["REMIND_SETTINGS"] = ''; } } } if (!isset($arParams['prop']['VERSION'])) { if (!$arParams['bNew']) { $dbProp = CIBlockElement::GetProperty($iblockId, $arParams['id'], 'sort', 'asc', array('CODE' => 'VERSION')); if ($arProp = $dbProp->Fetch()) { $arParams['prop']['VERSION'] = intval($arProp['VALUE']); } } if ($arParams['prop']['VERSION'] <= 0) { $arParams['prop']['VERSION'] = 1; } $arParams['prop']['VERSION']++; } if ($arParams['isMeeting']) { $arParams['prop']['IS_MEETING'] = 'Y'; } if (!$bIsInvitingEvent) { $arParams['prop']['HOST_IS_ABSENT'] = $arParams['isMeeting'] && !in_array($userId, $arParams['guests']) ? 'Y' : 'N'; if ($arParams['isMeeting'] && strlen($arParams['meetingText'])) { $arParams['prop']['MEETING_TEXT'] = array('VALUE' => array("TYPE" => 'text', "TEXT" => $arParams['meetingText'])); } } $arFields = array("ACTIVE" => "Y", "IBLOCK_SECTION" => $calendarId, "IBLOCK_ID" => $iblockId, "NAME" => $arParams['name'], "ACTIVE_FROM" => $arParams['dateFrom'], "ACTIVE_TO" => $arParams['dateTo'], "DETAIL_TEXT" => $arParams['desc'], "DETAIL_TEXT_TYPE" => 'html', "MODIFIED_BY" => $GLOBALS['USER']->GetID(), "PROPERTY_VALUES" => $arParams['prop']); if ($ownerType == 'GROUP' && $ownerId > 0) { $arFields['SOCNET_GROUP_ID'] = $ownerId; } if ($bExchange || $bCalDav) { foreach ($arFields["PROPERTY_VALUES"] as $prKey => $prVal) { $arFields["PROPERTY_" . $prKey] = $prVal; } } // If it's EXCHANGE - we try to save event to exchange if ($bExchange) { $calendarXmlId = CECCalendar::GetExchangeXmlId($iblockId, $calendarId); if (strlen($calendarXmlId) > 0 && $calendarXmlId !== 0) { if ($arParams['bNew']) { $exchRes = CDavExchangeCalendar::DoAddItem($ownerId, $calendarXmlId, $arFields); } else { $eventModLabel = CECEvent::GetExchModLabel($iblockId, $arParams['id']); $eventXmlId = CECEvent::GetExchangeXmlId($iblockId, $arParams['id']); $exchRes = CDavExchangeCalendar::DoUpdateItem($ownerId, $eventXmlId, $eventModLabel, $arFields); } if (!is_array($exchRes) || !array_key_exists("XML_ID", $exchRes)) { return CEventCalendar::ThrowError(CEventCalendar::CollectExchangeErros($exchRes)); } // It's ok, we successfuly save event to exchange calendar - and save it to DB $arFields['XML_ID'] = $exchRes['XML_ID']; $arFields['PROPERTY_VALUES']['BXDAVEX_LABEL'] = $exchRes['MODIFICATION_LABEL']; } } if ($bCalDav) { $connectionId = CECCalendar::GetCalDAVConnectionId($iblockId, $calendarId); if ($connectionId > 0) { $calendarCalDAVXmlId = CECCalendar::GetCalDAVXmlId($iblockId, $calendarId); if ($arParams['bNew']) { $DAVRes = CDavGroupdavClientCalendar::DoAddItem($connectionId, $calendarCalDAVXmlId, $arFields); } else { $eventCalDAVModLabel = CECEvent::GetCalDAVModLabel($iblockId, $arParams['id']); $eventXmlId = CECEvent::GetExchangeXmlId($iblockId, $arParams['id']); $DAVRes = CDavGroupdavClientCalendar::DoUpdateItem($connectionId, $calendarCalDAVXmlId, $eventXmlId, $eventCalDAVModLabel, $arFields); } if (!is_array($DAVRes) || !array_key_exists("XML_ID", $DAVRes)) { return CEventCalendar::ThrowError(CEventCalendar::CollectCalDAVErros($DAVRes)); } // // It's ok, we successfuly save event to caldav calendar - and save it to DB $arFields['XML_ID'] = $DAVRes['XML_ID']; $arFields['PROPERTY_VALUES']['BXDAVCD_LABEL'] = $DAVRes['MODIFICATION_LABEL']; } } $bs = new CIBlockElement(); $res = false; if (!$arParams['bNew']) { $ID = $arParams['id']; if ($ID > 0) { $res = $bs->Update($ID, $arFields, false); } } else { //This sets appropriate owner if event created by owner of the meeting and this calendar belongs to guest which is not current user if ($ownerType == 'USER' && $ownerId > 0 && $userId != $ownerId) { $arFields['CREATED_BY'] = $ownerId; } $ID = $bs->Add($arFields, false); $res = $ID > 0; } if ($arParams['isMeeting'] && !$bIsInvitingEvent) { $this->CheckParentProperty($arParams['userIblockId'], $iblockId); $arGuestConfirm = $this->InviteGuests($ID, $arFields, $arParams['guests'], $arParams); } if (!$res) { return CEventCalendar::ThrowError('4' . $bs->LAST_ERROR); } else { CIBlockElement::RecalcSections($ID); } if (!$bPeriodic && !$arParams["notDisplayCalendar"]) { if ($arParams['bNew']) { ?> <script>window._bx_new_event = {ID: <?php echo $ID; ?> , IBLOCK_ID: '<?php echo $iblockId; ?> ', LOC: '<?php echo CUtil::JSEscape($loc_new); ?> ', arGuestConfirm: <?php echo CUtil::PhpToJSObject($arGuestConfirm); ?> };</script><?php } else { ?> <script>window._bx_existent_event = {ID: <?php echo intVal($ID); ?> , NAME : '<?php echo CUtil::JSEscape($arParams['name']); ?> ', DETAIL_TEXT: '<?php echo CUtil::JSEscape($arParams['desc']); ?> ', DATE_FROM : '<?php echo $arParams['dateFrom']; ?> ', DATE_TO : '<?php echo $arParams['dateTo']; ?> ', LOC: '<?php echo CUtil::JSEscape($loc_new); ?> ', arGuestConfirm: <?php echo CUtil::PhpToJSObject($arGuestConfirm); ?> };</script> <?php } } $this->ClearCache($this->cachePath . 'events/' . $iblockId . '/'); if ($bSocNetLog && $ownerType) { CEventCalendar::SocNetLog(array('iblockId' => $iblockId, 'ownerType' => $ownerType, 'ownerId' => $ownerId, 'target' => $arParams['bNew'] ? 'add_event' : 'edit_event', 'id' => $ID, 'name' => $arParams['name'], 'desc' => $arParams['desc'], 'from' => $arParams['dateFrom'], 'to' => $arParams['dateTo'], 'calendarId' => $calendarId, 'accessibility' => $arParams["prop"]["ACCESSIBILITY"], 'importance' => $arParams["prop"]["IMPORTANCE"], 'pathToGroupCalendar' => $arParams["pathToGroupCalendar"], 'pathToUserCalendar' => $arParams["pathToUserCalendar"])); } if (array_key_exists("remind", $arParams)) { CECEvent::AddReminder(array('iblockId' => $iblockId, 'ownerType' => $ownerType, 'ownerId' => $ownerId, 'userId' => $userId, 'fullUrl' => $fullUrl, 'id' => $ID, 'dateFrom' => $arParams['dateFrom'], 'remind' => $arParams["remind"], 'bNew' => $arParams['bNew'])); } return $ID; }
function handleFile($Info, $arFiles, $Params) { CModule::IncludeModule("iblock"); global $USER; $arParams = $Params['arParams']; $savedData = CImageUploader::GetSavedData(); $arErrors = array(); // Check file sizes and types (types only for mass uploaders) foreach ($arFiles as $file) { if ($file['size'] > 0 && $arParams["UPLOAD_MAX_FILE_SIZE"] > 0 && $file['size'] > $arParams["UPLOAD_MAX_FILE_SIZE"]) { $arErrors[] = array("file" => $file['name'], "id" => "BXPH_FUNC_HANDLE_2_LARGE_SIZE", "text" => GetMessage('P_WM_IMG_ERROR04')); } if ($file['type'] && strpos(strtolower($file['type']), 'image') === false) { $arErrors[] = array("file" => $file['name'], "id" => "BXPH_FUNC_HANDLE_2_TYPE", "text" => GetMessage('P_WM_IMG_ERROR02')); } } if (count($arErrors) > 0) { // Exit if we have any errors return CImageUploader::SaveError($arErrors); } // Handle watermark for Flash-uploader if ($arParams["UPLOADER_TYPE"] == 'flash') { $arWatermark = false; if ($arParams['WATERMARK_RULES'] == 'ALL') { $arWatermark = array('type' => strtolower($arParams['WATERMARK_TYPE']), 'position' => $arParams['WATERMARK_POSITION']); if ($arParams['WATERMARK_TYPE'] == 'TEXT') { $arWatermark['coefficient'] = $arParams['WATERMARK_SIZE']; $arWatermark['text'] = trim($arParams['WATERMARK_TEXT']); $arWatermark['font'] = trim($arParams['PATH_TO_FONT']); $arWatermark['color'] = trim($arParams['WATERMARK_COLOR']); $arWatermark['use_copyright'] = "N"; } else { $arWatermark['file'] = $arParams['WATERMARK_FILE']; $arWatermark['alpha_level'] = $arParams['WATERMARK_TRANSPARENCY']; $arWatermark['size'] = 'real'; $arWatermark['fill'] = $arParams['WATERMARK_FILE_ORDER'] == 'usual' ? 'exact' : $arParams['WATERMARK_FILE_ORDER']; } } elseif ($Params['packageFields']['photo_watermark_use'] == 'Y') { $arWatermark = array('type' => $Params['packageFields']['photo_watermark_type'], 'text' => $Params['packageFields']['photo_watermark_text'], 'font' => $arParams['PATH_TO_FONT'], 'position' => $Params['packageFields']['photo_watermark_position'], 'color' => $Params['packageFields']['photo_watermark_color'], 'size' => $Params['packageFields']['photo_watermark_size'], 'fill' => 'resize', 'file' => $_SERVER["DOCUMENT_ROOT"] . $Params['packageFields']['photo_watermark_path'], 'alpha_level' => $Params['packageFields']['photo_watermark_opacity'], 'use_copyright' => $Params['packageFields']["photo_watermark_copyright"] == "Y" ? "Y" : "N"); } if ($arWatermark) { // Add watermark here foreach ($arFiles as $i => $file) { if ($i == 1) { // It's thumbnail skip it continue; } $size = CFile::GetImageSize($file['tmp_name']); $type = $size[2]; $sourceImage = CFile::CreateImage($file['tmp_name'], $type); if ($sourceImage) { $res = CFile::Watermark($sourceImage, $arWatermark); if (file_exists($file['tmp_name'])) { unlink($file['tmp_name']); } switch ($type) { case IMAGETYPE_GIF: imagegif($sourceImage, $file['tmp_name']); break; case IMAGETYPE_PNG: imagealphablending($sourceImage, false); imagesavealpha($sourceImage, true); imagepng($sourceImage, $file['tmp_name']); break; default: if ($arSourceFileSizeTmp[2] == IMAGETYPE_BMP) { $file['tmp_name'] .= ".jpg"; } imagejpeg($sourceImage, $file['tmp_name'], 100); break; } if ($sourceImage) { imagedestroy($sourceImage); } } } } } // Props $Prop = array(); // Additional image copyies $ind = -1; foreach ($arParams['converters'] as $key => $val) { $ind++; if ($val['code'] == "real_picture" || $val['code'] == "thumbnail") { continue; } $Prop[strtoupper($val['code'])] = array("n0" => $arFiles[$ind]); } $_REQUEST["Public"] = $_REQUEST["Public"] == "N" ? "N" : "Y"; $Prop["PUBLIC_ELEMENT"] = array("n0" => $_REQUEST["Public"]); $Prop["APPROVE_ELEMENT"] = array("n0" => ($arParams["ABS_PERMISSION"] >= "U" || $arParams["APPROVE_BY_DEFAULT"] == "Y") && $_REQUEST["Public"] == "Y" ? "Y" : "X"); // Real photo $Prop["REAL_PICTURE"] = array("n0" => $arFiles[0]); $arFields = array("ACTIVE" => $arParams["MODERATION"] == "Y" && $arParams["ABS_PERMISSION"] < "U" ? "N" : "Y", "MODIFIED_BY" => $USER->GetID(), "IBLOCK_SECTION" => $savedData['SECTION_ID'], "IBLOCK_ID" => $arParams["IBLOCK_ID"], "NAME" => $Info['name'], "CODE" => $Info['name'], "TAGS" => $Info['tags'], "DETAIL_TEXT" => $Info['description'], "DETAIL_TEXT_TYPE" => "text", "PREVIEW_PICTURE" => $arFiles[1], "PREVIEW_TEXT" => $Info['description'], "PREVIEW_TEXT_TYPE" => "text", "PROPERTY_VALUES" => $Prop); //$arFields["NAME"] = (!empty($arFields["NAME"]) ? $arFields["NAME"] : $File["REAL_PICTURE"]["name"]); //$arFields["DATE_CREATE"] = (intVal($arRealFile["ExifTimeStamp"]) > 0 ? // ConvertTimeStamp($arRealFile["ExifTimeStamp"], "FULL") : $arFields["DATE_CREATE"]); $bs = new CIBlockElement(); $ID = $bs->Add($arFields); if ($ID <= 0) { $strError = $bs->LAST_ERROR; $arErrors = array(); $arTmp = explode("<br>", $strError); foreach ($arTmp as $er) { if (trim($er) != '' && !in_array($er, $arErrors)) { $arErrors[] = array("id" => "BXPH_FUNC_002", "text" => $er); } } CImageUploader::SaveError($arErrors); } else { $arFields['ID'] = $ID; $_SESSION['arUploadedPhotos'][] = $ID; CIBlockElement::RecalcSections($ID); $arParams['SECTION_ID'] = $savedData['SECTION_ID']; $arResult = $Params['~arResult']; $events = GetModuleEvents("photogallery", "OnAfterUpload"); while ($arEvent = $events->Fetch()) { ExecuteModuleEventEx($arEvent, array(&$arFields, $arParams, $arResult)); } // Add thumbnail only for new album if ($savedData['NEW_SECTION_NAME'] && !$savedData['NEW_SECTION_PICTURE']) { $File = $arFiles[0]; // Big picture $File['tmp_name_1'] = $File['tmp_name']; $File['tmp_name'] = substr($File['tmp_name'], 0, strrpos($File['tmp_name'], ".")) . "_album_cover.tmp"; if (CFile::ResizeImageFile($File['tmp_name_1'], $File['tmp_name'], array('width' => $arParams["ALBUM_PHOTO_THUMBS"]["SIZE"], 'height' => $arParams["ALBUM_PHOTO_THUMBS"]["SIZE"]), BX_RESIZE_IMAGE_PROPORTIONAL_ALT)) { $bs = new CIBlockSection(); if ($bs->Update($savedData["SECTION_ID"], array("PICTURE" => $File), false, false)) { $savedData['NEW_SECTION_PICTURE'] = true; CImageUploader::SetSavedData($savedData); } } } } return $ID; }
function SetPropertyValues($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $PROPERTY_CODE = false) { global $DB; global $BX_IBLOCK_PROP_CACHE; $ELEMENT_ID = intVal($ELEMENT_ID); $IBLOCK_ID = intval($IBLOCK_ID); if (!is_array($PROPERTY_VALUES)) $PROPERTY_VALUES = array($PROPERTY_VALUES); $uniq_flt = $IBLOCK_ID; $arFilter = array( "IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "N", ); if ($PROPERTY_CODE === false) { $arFilter["ACTIVE"] = "Y"; $uniq_flt .= "|ACTIVE:".$arFilter["ACTIVE"]; } elseif(intval($PROPERTY_CODE) > 0) { $arFilter["ID"] = intval($PROPERTY_CODE); $uniq_flt .= "|ID:".$arFilter["ID"]; } else { $arFilter["CODE"] = $PROPERTY_CODE; $uniq_flt .= "|CODE:".$arFilter["CODE"]; } if (!isset($BX_IBLOCK_PROP_CACHE[$IBLOCK_ID])) $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID] = array(); if (!isset($BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt])) { $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt] = array(); $db_prop = CIBlockProperty::GetList(array(), $arFilter); while($prop = $db_prop->Fetch()) { $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt][] = $prop; } } $ar_prop = &$BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt]; reset($ar_prop); $bRecalcSections = false; //Read current property values from database $arDBProps = array(); if (CIBLock::GetArrayByID($IBLOCK_ID, "VERSION") == 2) { $rs = $DB->Query(" select * from b_iblock_element_prop_m".$IBLOCK_ID." where IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." order by ID asc "); while ($ar = $rs->Fetch()) { $property_id = $ar["IBLOCK_PROPERTY_ID"]; if (!isset($arDBProps[$property_id])) $arDBProps[$property_id] = array(); $arDBProps[$property_id][$ar["ID"]] = $ar; } $rs = $DB->Query(" select * from b_iblock_element_prop_s".$IBLOCK_ID." where IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." "); if ($ar = $rs->Fetch()) { foreach($ar_prop as $property) { $property_id = $property["ID"]; if( $property["MULTIPLE"] == "N" && isset($ar["PROPERTY_".$property_id]) && strlen($ar["PROPERTY_".$property_id]) ) { if (!isset($arDBProps[$property_id])) $arDBProps[$property_id] = array(); $arDBProps[$property_id][$pr["ID"]] = array( "ID" => $ELEMENT_ID.":".$property_id, "IBLOCK_PROPERTY_ID" => $property_id, "VALUE" => $ar["PROPERTY_".$property_id], "DESCRIPTION" => $ar["DESCRIPTION_".$property_id], ); } } } } else { $rs = $DB->Query(" select * from b_iblock_element_property where IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." order by ID asc "); while ($ar = $rs->Fetch()) { $property_id = $ar["IBLOCK_PROPERTY_ID"]; if (!isset($arDBProps[$property_id])) $arDBProps[$property_id] = array(); $arDBProps[$property_id][$ar["ID"]] = $ar; } } $arFilesToDelete = array(); $arV2ClearCache = array(); foreach ($ar_prop as $prop) { if ($PROPERTY_CODE) { $PROP = $PROPERTY_VALUES; } else { if (strlen($prop["CODE"]) > 0 && array_key_exists($prop["CODE"], $PROPERTY_VALUES)) $PROP = $PROPERTY_VALUES[$prop["CODE"]]; else $PROP = $PROPERTY_VALUES[$prop["ID"]]; } if ( !is_array($PROP) || ( $prop["PROPERTY_TYPE"] == "F" && ( array_key_exists("tmp_name", $PROP) || array_key_exists("del", $PROP) ) ) || ( count($PROP) == 2 && array_key_exists("VALUE", $PROP) && array_key_exists("DESCRIPTION", $PROP) ) ) { $PROP = array($PROP); } if ($prop["USER_TYPE"] != "") { $arUserType = CIBlockProperty::GetUserType($prop["USER_TYPE"]); if (array_key_exists("ConvertToDB", $arUserType)) { foreach ($PROP as $key => $value) { if( !is_array($value) || !array_key_exists("VALUE", $value) ) { $value = array("VALUE"=>$value); } $PROP[$key] = call_user_func_array($arUserType["ConvertToDB"], array($prop, $value)); } } } if ($prop["VERSION"] == 2) { if ($prop["MULTIPLE"] == "Y") $strTable = "b_iblock_element_prop_m".$prop["IBLOCK_ID"]; else $strTable = "b_iblock_element_prop_s".$prop["IBLOCK_ID"]; } else { $strTable = "b_iblock_element_property"; } if ($prop["PROPERTY_TYPE"] == "L") { $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID)); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } $ids = "0"; foreach ($PROP as $key => $value) { if (is_array($value)) $value = intval($value["VALUE"]); else $value = intval($value); if ($value <= 0) continue; $ids .= ",".$value; if ($prop["MULTIPLE"] != "Y") break; } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query(" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." E ,b_iblock_property P ,b_iblock_property_enum PEN SET E.PROPERTY_".$prop["ID"]." = PEN.ID WHERE E.IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." AND P.ID = ".$prop["ID"]." AND P.ID = PEN.PROPERTY_ID AND PEN.ID IN (".$ids.") "); } else { $DB->Query(" INSERT INTO ".$strTable." (IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_ENUM) SELECT ".$ELEMENT_ID.", P.ID, PEN.ID, PEN.ID FROM b_iblock_property P ,b_iblock_property_enum PEN WHERE P.ID = ".$prop["ID"]." AND P.ID = PEN.PROPERTY_ID AND PEN.ID IN (".$ids.") "); } } elseif ($prop["PROPERTY_TYPE"] == "G") { $bRecalcSections = true; $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID)); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } $DB->Query(" DELETE FROM b_iblock_section_element WHERE ADDITIONAL_PROPERTY_ID = ".$prop["ID"]." AND IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." "); $ids = "0"; foreach ($PROP as $key => $value) { if (is_array($value)) $value = intval($value["VALUE"]); else $value = intval($value); if ($value <= 0) continue; $ids .= ",".$value; if ($prop["MULTIPLE"] != "Y") break; } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query(" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." E ,b_iblock_property P ,b_iblock_section S SET E.PROPERTY_".$prop["ID"]." = S.ID ".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"])." WHERE E.IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." AND P.ID = ".$prop["ID"]." AND ( P.LINK_IBLOCK_ID IS NULL OR P.LINK_IBLOCK_ID = 0 OR S.IBLOCK_ID = P.LINK_IBLOCK_ID ) AND S.ID IN (".$ids.") "); } else { $DB->Query(" INSERT INTO ".$strTable." (IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM) SELECT ".$ELEMENT_ID.", P.ID, S.ID, S.ID FROM b_iblock_property P ,b_iblock_section S WHERE P.ID=".$prop["ID"]." AND ( P.LINK_IBLOCK_ID IS NULL OR P.LINK_IBLOCK_ID = 0 OR S.IBLOCK_ID = P.LINK_IBLOCK_ID ) AND S.ID IN (".$ids.") "); } $DB->Query(" INSERT INTO b_iblock_section_element (IBLOCK_ELEMENT_ID, IBLOCK_SECTION_ID, ADDITIONAL_PROPERTY_ID) SELECT ".$ELEMENT_ID.", S.ID, P.ID FROM b_iblock_property P ,b_iblock_section S WHERE P.ID = ".$prop["ID"]." AND ( P.LINK_IBLOCK_ID IS NULL OR P.LINK_IBLOCK_ID = 0 OR S.IBLOCK_ID = P.LINK_IBLOCK_ID ) AND S.ID IN (".$ids.") "); } elseif ($prop["PROPERTY_TYPE"] == "E") { $arWas = array(); if ($arDBProps[$prop["ID"]]) { foreach($arDBProps[$prop["ID"]] as $res) { $val = $PROP[$res["ID"]]; if (is_array($val)) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (isset($arWas[$val])) $val = ""; else $arWas[$val] = true; if (strlen($val) <= 0) //Delete property value { $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID)); if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } } elseif ($res["VALUE"] !== $val) //Update property value { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query(" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." SET PROPERTY_".$prop["ID"]." = '".$DB->ForSql($val)."' ".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc)." WHERE IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." "); } else { $DB->Query(" UPDATE ".$strTable." SET VALUE = '".$DB->ForSql($val)."' ,VALUE_NUM = ".CIBlock::roundDB($val)." ".($val_desc!==false ? ",DESCRIPTION = '".$DB->ForSql($val_desc, 255)."'" : "")." WHERE ID=".$res["ID"]." "); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } } unset($PROP[$res["ID"]]); } //foreach($arDBProps[$prop["ID"]] as $res) } foreach ($PROP as $val) { if (is_array($val)) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (isset($arWas[$val])) $val = ""; else $arWas[$val] = true; if (strlen($val) <= 0) continue; if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query(" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." SET PROPERTY_".$prop["ID"]." = '".$DB->ForSql($val)."' ".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc)." WHERE IBLOCK_ELEMENT_ID=".$ELEMENT_ID." "); } else { $DB->Query(" INSERT INTO ".$strTable." (IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM".($val_desc!==false?", DESCRIPTION":"").") SELECT ".$ELEMENT_ID." ,P.ID ,'".$DB->ForSql($val)."' ,".CIBlock::roundDB($val)." ".($val_desc!==false?", '".$DB->ForSQL($val_desc, 255)."'":"")." FROM b_iblock_property P WHERE ID = ".IntVal($prop["ID"])." "); } if($prop["VERSION"]==2 && $prop["MULTIPLE"]=="Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } if ($prop["MULTIPLE"] != "Y") break; } //foreach($PROP as $value) } elseif ($prop["PROPERTY_TYPE"] == "F") { //We'll be adding values from the database into the tail //this values was not passed into API call. $orderedPROP = array_reverse($PROP, true); if ($arDBProps[$prop["ID"]]) { //Go from high ID to low foreach (array_reverse($arDBProps[$prop["ID"]], true) as $res) { //Preserve description from database if (strlen($res["DESCRIPTION"])) $description = $res["DESCRIPTION"]; else $description = false; if (!array_key_exists($res["ID"], $orderedPROP)) { $orderedPROP[$res["ID"]] = array( "VALUE" => $res["VALUE"], "DESCRIPTION" => $description, ); } else { $val = $orderedPROP[$res["ID"]]; if ( is_array($val) && !array_key_exists("tmp_name", $val) && !array_key_exists("del", $val) ) $val = $val["VALUE"]; //Check if no new file and no delete command if ( !strlen($val["tmp_name"]) && !strlen($val["del"]) ) //Overwrite with database value { //But save description from incoming value if (array_key_exists("description", $val)) $description = trim($val["description"]); $orderedPROP[$res["ID"]] = array( "VALUE" => $res["VALUE"], "DESCRIPTION" => $description, ); } } } } //Reverse the array and now lower ID is in the beginning $orderedPROP = array_reverse($orderedPROP, true); //Now delete from database all marked for deletion records if ($arDBProps[$prop["ID"]]) { foreach ($arDBProps[$prop["ID"]] as $res) { $val = $orderedPROP[$res["ID"]]; if ( is_array($val) && !array_key_exists("tmp_name", $val) && !array_key_exists("del", $val) ) { $val = $val["VALUE"]; } if (is_array($val) && strlen($val["del"])) { unset($orderedPROP[$res["ID"]]); $arFilesToDelete[] = array( "FILE_ID" => $res["VALUE"], "ELEMENT_ID" => $ELEMENT_ID, "IBLOCK_ID" => $prop["IBLOCK_ID"], ); } elseif ($prop["MULTIPLE"] != "Y") { //Delete all stored in database for replacement. $arFilesToDelete[] = array( "FILE_ID" => $res["VALUE"], "ELEMENT_ID" => $ELEMENT_ID, "IBLOCK_ID" => $prop["IBLOCK_ID"], ); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query(" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." SET PROPERTY_".$prop["ID"]." = null ".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"])." WHERE IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." "); } else { $DB->Query("DELETE FROM ".$strTable." WHERE ID = ".$res["ID"]); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } } //foreach($arDBProps[$prop["ID"]] as $res) } //Write new values into database in specified order foreach ($orderedPROP as $val) { if( is_array($val) && !array_key_exists("tmp_name", $val) ) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (is_array($val)) { $val["MODULE_ID"] = "iblock"; if ($val_desc !== false) $val["description"] = $val_desc; $val = CFile::SaveFile($val, "iblock"); } elseif ( $val > 0 && $val_desc !== false ) { CFile::UpdateDesc($val, $val_desc); } if (intval($val) <= 0) continue; if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query($s=" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." SET PROPERTY_".$prop["ID"]." = '".$DB->ForSql($val)."' ".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc)." WHERE IBLOCK_ELEMENT_ID=".$ELEMENT_ID." "); } else { $DB->Query(" INSERT INTO ".$strTable." (IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM".($val_desc!==false?", DESCRIPTION":"").") SELECT ".$ELEMENT_ID." ,P.ID ,'".$DB->ForSql($val)."' ,".CIBlock::roundDB($val)." ".($val_desc!==false?", '".$DB->ForSQL($val_desc, 255)."'":"")." FROM b_iblock_property P WHERE ID = ".IntVal($prop["ID"])." "); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } if ($prop["MULTIPLE"] != "Y") break; } //foreach($PROP as $value) } else //if($prop["PROPERTY_TYPE"] == "S" || $prop["PROPERTY_TYPE"] == "N") { if ($arDBProps[$prop["ID"]]) { foreach ($arDBProps[$prop["ID"]] as $res) { $val = $PROP[$res["ID"]]; if (is_array($val)) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (strlen($val) <= 0) { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query(" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." SET PROPERTY_".$prop["ID"]." = null ".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"])." WHERE IBLOCK_ELEMENT_ID=".$ELEMENT_ID." "); } else { $DB->Query("DELETE FROM ".$strTable." WHERE ID=".$res["ID"]); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } } else { if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { if($prop["PROPERTY_TYPE"]=="N") $val = CIBlock::roundDB($val); $DB->Query(" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." SET PROPERTY_".$prop["ID"]."='".$DB->ForSql($val)."' ".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc)." WHERE IBLOCK_ELEMENT_ID=".$ELEMENT_ID." "); } else { $DB->Query(" UPDATE ".$strTable." SET VALUE='".$DB->ForSql($val)."' ,VALUE_NUM=".CIBlock::roundDB($val)." ".($val_desc!==false ? ",DESCRIPTION='".$DB->ForSql($val_desc, 255)."'" : "")." WHERE ID=".$res["ID"]." "); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } } unset($PROP[$res["ID"]]); } //foreach ($arDBProps[$prop["ID"]] as $res) } foreach($PROP as $val) { if(is_array($val) && !is_set($val, "tmp_name")) { $val_desc = $val["DESCRIPTION"]; $val = $val["VALUE"]; } else { $val_desc = false; } if (strlen($val) <= 0) continue; if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") { $DB->Query(" UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]." SET PROPERTY_".$prop["ID"]." = '".$DB->ForSql($val)."' ".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc)." WHERE IBLOCK_ELEMENT_ID=".$ELEMENT_ID." "); } else { $DB->Query(" INSERT INTO ".$strTable." (IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM".($val_desc!==false?", DESCRIPTION":"").") SELECT ".$ELEMENT_ID." ,P.ID ,'".$DB->ForSql($val)."' ,".CIBlock::roundDB($val)." ".($val_desc!==false?", '".$DB->ForSQL($val_desc, 255)."'":"")." FROM b_iblock_property P WHERE ID = ".IntVal($prop["ID"])." "); } if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") { $arV2ClearCache[$prop["ID"]] = "PROPERTY_".$prop["ID"]." = NULL" .self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) ; } if ($prop["MULTIPLE"] != "Y") break; } //foreach($PROP as $value) } //if($prop["PROPERTY_TYPE"]=="F") } if ($arV2ClearCache) { $DB->Query(" UPDATE b_iblock_element_prop_s".$IBLOCK_ID." SET ".implode(",", $arV2ClearCache)." WHERE IBLOCK_ELEMENT_ID = ".$ELEMENT_ID." "); } foreach ($arFilesToDelete as $deleteTask) { CIBLockElement::DeleteFile( $deleteTask["FILE_ID"], false, "PROPERTY", $deleteTask["ELEMENT_ID"], $deleteTask["IBLOCK_ID"] ); } if($bRecalcSections) CIBlockElement::RecalcSections($ELEMENT_ID); /****************************** QUOTA ******************************/ $_SESSION["SESS_RECOUNT_DB"] = "Y"; /****************************** QUOTA ******************************/ foreach (GetModuleEvents("iblock", "OnAfterIBlockElementSetPropertyValues", true) as $arEvent) ExecuteModuleEventEx($arEvent, array($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $PROPERTY_CODE)); }
/** * Метод изменяет свойства (поля) указанного документа на указанные значения. * * @param string $documentId - код документа. * @param array $arFields - массив новых значений свойств документа в виде array(код_свойства => значение, ...). Коды свойств соответствуют кодам свойств, возвращаемым методом GetDocumentFields. */ public function UpdateDocument($documentId, $arFields) { $documentId = intval($documentId); if ($documentId <= 0) { throw new CBPArgumentNullException("documentId"); } CIBlockElement::WF_CleanUpHistoryCopies($documentId, 0); $db = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y"), false, false, array("ID", "IBLOCK_ID")); $ar = $db->Fetch(); if (!$ar) { throw new Exception("Task is not found"); } $arFields["PROPERTY_VALUES"] = array(); $arKeys = array_keys($arFields); foreach ($arKeys as $key) { if (substr($key, 0, strlen("PROPERTY_")) == "PROPERTY_") { $arFields["PROPERTY_VALUES"][substr($key, strlen("PROPERTY_"))] = $arFields[$key]; } } $iblockElementObject = new CIBlockElement(); if (count($arFields["PROPERTY_VALUES"]) > 0) { $iblockElementObject->SetPropertyValuesEx($documentId, $ar["IBLOCK_ID"], $arFields["PROPERTY_VALUES"]); } unset($arFields["PROPERTY_VALUES"]); $res = $iblockElementObject->Update($documentId, $arFields); if (!$res) { throw new Exception($iblockElement->LAST_ERROR); } CIBlockElement::RecalcSections($documentId); }