Exemplo n.º 1
0
 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 ******************************/
 }
Exemplo n.º 2
0
 public static function GetGrNameByUserID($userid)
 {
     $res = '';
     $rsUser = CUser::GetByID($userid);
     $arUser = $rsUser->Fetch();
     $resID = $arUser['UF_REGION_NUMERATOR'];
     $resList = CIBLockElement::GetByID($resID);
     if ($arRes = $resList->GetNext()) {
         $res = $arRes['NAME'];
     }
     return $res;
 }
Exemplo n.º 3
0
 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));
     }
 }
Exemplo n.º 4
0
 }
 // set starting filter value
 $arFilter = array("IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"], "IBLOCK_ID" => $arParams["IBLOCK_ID"], "SHOW_NEW" => "Y");
 // check type of user association to iblock elements and add user association to filter
 //echo "<pre>"; print_r($arParams); echo "</pre>";
 if ($arParams["ELEMENT_ASSOC"] == "PROPERTY_ID" && intval($arParams["ELEMENT_ASSOC_PROPERTY"]) > 0 && in_array($arParams["ELEMENT_ASSOC_PROPERTY"], $arPropertyIDs)) {
     $arFilter["PROPERTY_" . $arParams["ELEMENT_ASSOC_PROPERTY"]] = $USER->GetID();
 } else {
     $arFilter["CREATED_BY"] = $USER->GetID();
 }
 //echo "<pre>"; print_r($arFilter); echo "</pre>";
 // deleteting element
 if (check_bitrix_sessid() && $_REQUEST["delete"] == "Y" && $arResult["CAN_DELETE"]) {
     $arParams["ID"] = intval($_REQUEST["CODE"]);
     // try to get element with id, for user and for iblock
     $rsElement = CIBLockElement::GetList(array(), array_merge($arFilter, array("ID" => $arParams["ID"])));
     if ($arElement = $rsElement->GetNext()) {
         // delete one
         $DB->StartTransaction();
         if (!CIBlockElement::Delete($arElement["ID"])) {
             $DB->Rollback();
         } else {
             $DB->Commit();
         }
     }
 }
 if ($bWorkflowIncluded) {
     $rsWFStatus = CWorkflowStatus::GetList($by = "c_sort", $order = "asc", array("ACTIVE" => "Y"), $is_filtered);
     $arResult["WF_STATUS"] = array();
     while ($arStatus = $rsWFStatus->GetNext()) {
         $arResult["WF_STATUS"][$arStatus["ID"]] = $arStatus["TITLE"];
Exemplo n.º 5
0
	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));
	}
Exemplo n.º 6
0
 public function GetElement($types, $MS)
 {
     $strXML = "";
     $arSort = array("ID" => "ASC");
     $arResult["OFFER"] = array();
     if (self::CheckArray($this->IBLOCK_ID)) {
         foreach ($this->IBLOCK_ID as $ibl) {
             $rsElements = CIBlockElement::Getlist($arSort, $this->arFilter[$ibl], false, false, $this->arSelect);
             if ($this->DETAIL_PAGE_URL) {
                 $rsElements->SetUrlTemplates($this->DETAIL_PAGE_URL);
             }
             while ($arOffer = $rsElements->GetNext()) {
                 $flag = 0;
                 if ($this->USE_SKU && $this->sku_IBLOCK_ID[$ibl] > 0) {
                     if (is_array($this->arSKU_Filter[$ibl]) && sizeof($this->arSKU_Filter[$ibl]) > 0) {
                         $skuFILTER = $this->arSKU_Filter[$ibl];
                         $skuFILTER["IBLOCK_ID"] = $this->sku_IBLOCK_ID[$ibl];
                         $skuFILTER[CGMExport::GetProp($this->sku_PROPERTY[$ibl])] = $arOffer["ID"];
                         $skuFILTER["ACTIVE"] = "Y";
                     } else {
                         $skuFILTER["IBLOCK_ID"] = $this->sku_IBLOCK_ID[$ibl];
                         $skuFILTER["ACTIVE"] = "Y";
                         $skuFILTER[CGMExport::GetProp($this->sku_PROPERTY[$ibl])] = $arOffer["ID"];
                     }
                     $arOfferInOb = CIBLockElement::GetList($arSort, $skuFILTER, false, false, $this->arSelect);
                     if ($this->DETAIL_PAGE_URL) {
                         $arOfferInOb->SetUrlTemplates($this->DETAIL_PAGE_URL);
                     }
                     while ($arOfferIn = $arOfferInOb->GetNext()) {
                         $flag = 1;
                         $arOfferIn1["g:availability"] = "in stock";
                         $arOfferIn1["g:id"] = $arOfferIn["ID"];
                         $arOfferIn1["g:condition"] = $this->CONDITIONS;
                         $arOfferIn1["g:item_group_id"] = $arOffer["ID"];
                         switch ($this->NAMESCHEMA) {
                             case "NAME_OFFER":
                                 $arOfferIn1["title"] = text2xml($arOffer["NAME"], true, true, $this->ENCODING);
                                 break;
                             case "NAME_OFFER_SKU":
                                 $arOfferIn1["title"] = text2xml($arOffer["NAME"] . "/" . $arOfferIn["NAME"], true, true, $this->ENCODING);
                                 break;
                             default:
                                 $arOfferIn1["title"] = text2xml($arOfferIn["NAME"], true, true, $this->ENCODING);
                                 break;
                         }
                         $arOfferIn1["g:price"] = $this->yandex_GetPrice(array("IBLOCK_ID" => $this->sku_IBLOCK_ID[$ibl], "ID" => $arOfferIn["ID"]));
                         if ($arOfferIn1["g:price"] > 0) {
                             $arOfferIn1["g:price"] .= " " . $this->baseCur;
                         }
                         $tr = CCatalogProduct::GetByID($arOfferIn["ID"]);
                         if ($tr["QUANTITY_TRACE"] == "N") {
                             $arOfferIn1["g:availability"] = "in stock";
                         } else {
                             if ($tr["QUANTITY"] > 0) {
                                 $arOfferIn1["g:availability"] = "in stock";
                             } else {
                                 if ($this->FORORDER) {
                                     $arOfferIn1["g:availability"] = "preorder";
                                 } else {
                                     $arOfferIn1["g:availability"] = "out of stock";
                                 }
                             }
                         }
                         $arOfferIn1["g:product_type"] = str_replace(">", "&gt;", $this->GOOGLE_CATEGORY[$arOffer["IBLOCK_SECTION_ID"]]["THIS"]);
                         $arOfferIn1["g:google_product_category"] = str_replace(">", "&gt;", $this->GOOGLE_CATEGORY[$arOffer["IBLOCK_SECTION_ID"] ? $arOffer["IBLOCK_SECTION_ID"] : $arOffer["IBLOCK_ID"]]["GOOGLE"]);
                         if ($arOffer["DETAIL_PAGE_URL"]) {
                             $arOfferIn1["g:link_href"] = "http://" . $this->DOMAIN_NAME . $arOffer["DETAIL_PAGE_URL"] . "#" . $arOfferIn["ID"];
                         } else {
                             $arOfferIn1["g:link_href"] = "http://" . $this->DOMAIN_NAME . $arOffer["DETAIL_PAGE_URL"];
                         }
                         if ($arOfferIn["PREVIEW_PICTURE"]) {
                             $db_file = CFile::GetByID($arOfferIn["PREVIEW_PICTURE"]);
                             if ($ar_file = $db_file->Fetch()) {
                                 $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                             }
                         }
                         if ($arOfferIn["DETAIL_PICTURE"]) {
                             $db_file = CFile::GetByID($arOfferIn["DETAIL_PICTURE"]);
                             if ($ar_file = $db_file->Fetch()) {
                                 $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                             }
                         }
                         if ($this->GetPropInData("g:image_link", $this->XML_DATA)) {
                             $ph = CIBlockElement::GetProperty($this->sku_IBLOCK_ID, $arOfferIn["ID"], array("sort" => "asc"), array("ID" => $this->GetPropInData("g:image_link", $this->XML_DATA)));
                             while ($ob = $ph->GetNext()) {
                                 $arFile = CFile::GetFileArray($ob["VALUE"]);
                                 if (!empty($arFile)) {
                                     if (strpos($arFile["SRC"], "http") === false) {
                                         $pic = "http://" . $this->DOMAIN_NAME . implode("/", array_map("rawurlencode", explode("/", $arFile["SRC"])));
                                     } else {
                                         $ar = explode("http://", $arFile["SRC"]);
                                         $pic = "http://" . implode("/", array_map("rawurlencode", explode("/", $ar[1])));
                                     }
                                     $arOfferIn1["g:image_link"][] = $pic;
                                 }
                             }
                         }
                         if (!$arOfferIn["g:image_link"]) {
                             if ($arOffer["PREVIEW_PICTURE"]) {
                                 $db_file = CFile::GetByID($arOffer["PREVIEW_PICTURE"]);
                                 if ($ar_file = $db_file->Fetch()) {
                                     $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                                 }
                             }
                             if ($arOffer["DETAIL_PICTURE"]) {
                                 $db_file = CFile::GetByID($arOffer["DETAIL_PICTURE"]);
                                 if ($ar_file = $db_file->Fetch()) {
                                     $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                                 }
                             }
                             if ($this->GetPropInData("g:image_link", $this->XML_DATA)) {
                                 $ph = CIBlockElement::GetProperty($this->IBLOCK_ID, $arOffer["ID"], array("value_id" => "asc"), array("ID" => $this->GetPropInData("g:image_link", $this->XML_DATA)))->Fetch();
                                 $db_file = CFile::GetByID($ph["VALUE"]);
                                 if ($ar_file = $db_file->Fetch()) {
                                     $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                                 }
                             }
                         }
                         if ($arOfferIn["PREVIEW_TEXT"]) {
                             $arOfferIn["PREVIEW_TEXT"] = text2xml($arOfferIn["PREVIEW_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferIn["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferIn["~PREVIEW_TEXT"]), true, true, $this->ENCODING);
                         }
                         if ($arOfferIn["DETAIL_TEXT"]) {
                             $arOfferIn["DETAIL_TEXT"] = text2xml($arOfferIn["DETAIL_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferIn["~DETAIL_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferIn["~DETAIL_TEXT"]), true, true, $this->ENCODING);
                         }
                         $arOfferIn1["description"] = strlen($arOfferIn["PREVIEW_TEXT"]) > strlen($arOfferIn["DETAIL_TEXT"]) ? $arOfferIn["PREVIEW_TEXT"] : $arOfferIn["DETAIL_TEXT"];
                         if ($this->GetPropInData("description", $this->XML_DATA)) {
                             $ph = CIBlockElement::GetProperty($this->sku_IBLOCK_ID, $arOfferIn["ID"], array("value_id" => "asc"), array("ID" => $this->GetPropInData("description", $this->XML_DATA)))->Fetch();
                             $arOfferIn1["description"] = text2xml($ph["VALUE"], true, true, $this->ENCODING);
                         }
                         if (!$arOfferIn1["description"]) {
                             if ($arOffer["PREVIEW_TEXT"]) {
                                 $arOffer["PREVIEW_TEXT"] = text2xml($arOffer["PREVIEW_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~PREVIEW_TEXT"]), true, true, $this->ENCODING);
                             }
                             if ($arOffer["DETAIL_TEXT"]) {
                                 $arOffer["DETAIL_TEXT"] = text2xml($arOffer["DETAIL_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~DETAIL_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~DETAIL_TEXT"]), true, true, $this->ENCODING);
                             }
                             $arOfferIn1["description"] = strlen($arOffer["PREVIEW_TEXT"]) > strlen($arOffer["DETAIL_TEXT"]) ? $arOffer["PREVIEW_TEXT"] : $arOffer["DETAIL_TEXT"];
                         }
                         $tmpmas = $this->GetXMLData($arOfferIn);
                         if (is_array($tmpmas) && sizeof($tmpmas) > 0) {
                             foreach ($tmpmas as $code => $xml) {
                                 $arOfferIn1[$xml["PARAM"]][] = $xml["VALUE"];
                             }
                         }
                         if (intval($arOfferIn1["g:price"]) <= 0) {
                             continue;
                         }
                         foreach ($arOfferIn1 as $id => $val) {
                             if (is_array($val) && sizeof($val) > 0) {
                                 $arOfferIn1[$id] = array_filter(array_unique($val));
                                 if (sizeof($arOfferIn1[$id]) == 1) {
                                     $arOfferIn1[$id] = array_shift($arOfferIn1[$id]);
                                 }
                             }
                         }
                         $strXML .= $this->BuildXml($arOfferIn1, $types, $MS);
                         unset($arOfferIn1);
                     }
                     if ($flag == 1) {
                         continue;
                     }
                 }
                 $arOffer1["g:availability"] = true;
                 $arOffer1["g:id"] = $arOffer["ID"];
                 $arOffer1["g:condition"] = $this->CONDITIONS;
                 $arOffer1["title"] = text2xml($arOffer["NAME"], true, true, $this->ENCODING);
                 if (!$this->isCat) {
                     if ($this->GetPropInData("quantity", $this->XML_DATA)) {
                         $av = CIBlockElement::GetProperty($arOffer["IBLOCK_ID"], $arOffer["ID"], array("sort" => "asc"), array("ID" => $this->GetPropInData("quantity", $this->XML_DATA)))->Fetch();
                         if (IntVal($av["VALUE"]) > 0) {
                             $arOffer1["g:availability"] = "in stock";
                         } else {
                             if ($this->FORORDER) {
                                 $arOffer1["g:availability"] = "preorder";
                             } else {
                                 $arOffer1["g:availability"] = "out of stock";
                             }
                         }
                     }
                 }
                 $arOffer1["g:price"] = $this->yandex_GetPrice(array("IBLOCK_ID" => $ibl, "ID" => $arOffer['ID']));
                 if ($arOffer1["g:price"] > 0) {
                     $arOffer1["g:price"] .= " " . $this->baseCur;
                 }
                 if ($this->isCat) {
                     $tr = CCatalogProduct::GetByID($arOffer["ID"]);
                     if ($tr["QUANTITY_TRACE"] == "N") {
                         $arOffer1["g:availability"] = "in stock";
                     } else {
                         if ($tr["QUANTITY"] > 0) {
                             $arOffer1["g:availability"] = "in stock";
                         } else {
                             if ($this->FORORDER) {
                                 $arOffer1["g:availability"] = "preorder";
                             } else {
                                 $arOffer1["g:availability"] = "out of stock";
                             }
                         }
                     }
                 }
                 $arOffer1["g:product_type"] = str_replace(">", "&gt;", $this->GOOGLE_CATEGORY[$arOffer["IBLOCK_SECTION_ID"]]["THIS"]);
                 $arOffer1["g:google_product_category"] = str_replace(">", "&gt;", $this->GOOGLE_CATEGORY[$arOffer["IBLOCK_SECTION_ID"] ? $arOffer["IBLOCK_SECTION_ID"] : $arOffer["IBLOCK_ID"]]["GOOGLE"]);
                 if ($arOffer["DETAIL_PAGE_URL"]) {
                     $arOffer1["g:link_href"] = "http://" . $this->DOMAIN_NAME . $arOffer["DETAIL_PAGE_URL"];
                 }
                 if ($arOffer["PREVIEW_PICTURE"]) {
                     $db_file = CFile::GetByID($arOffer["PREVIEW_PICTURE"]);
                     if ($ar_file = $db_file->Fetch()) {
                         $arOffer1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                     }
                 }
                 if ($arOffer["DETAIL_PICTURE"]) {
                     $db_file = CFile::GetByID($arOffer["DETAIL_PICTURE"]);
                     if ($ar_file = $db_file->Fetch()) {
                         $arOffer1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                     }
                 }
                 if ($this->GetPropInData("g:image_link", $this->XML_DATA)) {
                     $ph = CIBlockElement::GetProperty($arOffer['IBLOCK_ID'], $arOffer["ID"], array("sort" => "asc"), array("ID" => $this->GetPropInData("g:image_link", $this->XML_DATA)));
                     while ($ob = $ph->GetNext()) {
                         $arFile = CFile::GetFileArray($ob["VALUE"]);
                         if (!empty($arFile)) {
                             if (strpos($arFile["SRC"], "http") === false) {
                                 $pic = "http://" . $this->DOMAIN_NAME . implode("/", array_map("rawurlencode", explode("/", $arFile["SRC"])));
                             } else {
                                 $ar = explode("http://", $arFile["SRC"]);
                                 $pic = "http://" . implode("/", array_map("rawurlencode", explode("/", $ar[1])));
                             }
                             $arOffer1["g:image_link"][] = $pic;
                         }
                     }
                 }
                 if ($arOffer["PREVIEW_TEXT"]) {
                     $arOffer["PREVIEW_TEXT"] = text2xml($arOffer["PREVIEW_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~PREVIEW_TEXT"]), true, true, $this->ENCODING);
                 }
                 if ($arOffer["DETAIL_TEXT"]) {
                     $arOffer["DETAIL_TEXT"] = text2xml($arOffer["DETAIL_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~DETAIL_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~DETAIL_TEXT"]), true, true, $this->ENCODING);
                 }
                 $arOffer1["description"] = strlen($arOffer["PREVIEW_TEXT"]) > strlen($arOffer["DETAIL_TEXT"]) ? $arOffer["PREVIEW_TEXT"] : $arOffer["DETAIL_TEXT"];
                 if ($this->GetPropInData("description", $this->XML_DATA)) {
                     $ph = CIBlockElement::GetProperty($arOffer, $arOffer["ID"], array("value_id" => "asc"), array("ID" => $this->GetPropInData("description", $this->XML_DATA)))->Fetch();
                     $arOffer1["description"] = text2xml($ph["VALUE"], true, true, $this->ENCODING);
                 }
                 $tmpmas = $this->GetXMLData($arOffer);
                 if (is_array($tmpmas) && sizeof($tmpmas) > 0) {
                     foreach ($tmpmas as $code => $xml) {
                         $arOffer1[$xml["PARAM"]][$code] = $xml["VALUE"];
                     }
                 }
                 if (intval($arOffer1["g:price"]) <= 0) {
                     continue;
                 }
                 $strXML .= $this->BuildXml($arOffer1, $types, $MS);
                 unset($arOffer1);
             }
         }
     }
     return $strXML;
 }