private static function _init()
 {
     if (count(self::$types) == 0) {
         self::$types = array();
         //Element fields
         self::$types["NAME"] = new CListFieldType("NAME", GetMessage("LISTS_LIST_FIELD_NAME"), CListFieldType::IS_FIELD, CListFieldType::NOT_READONLY);
         self::$types["SORT"] = new CListFieldType("SORT", GetMessage("LISTS_LIST_FIELD_SORT"), CListFieldType::IS_FIELD, CListFieldType::NOT_READONLY);
         self::$types["ACTIVE_FROM"] = new CListFieldType("ACTIVE_FROM", GetMessage("LISTS_LIST_FIELD_ACTIVE_FROM"), CListFieldType::IS_FIELD, CListFieldType::NOT_READONLY);
         self::$types["ACTIVE_TO"] = new CListFieldType("ACTIVE_TO", GetMessage("LISTS_LIST_FIELD_ACTIVE_TO"), CListFieldType::IS_FIELD, CListFieldType::NOT_READONLY);
         self::$types["PREVIEW_PICTURE"] = new CListFieldType("PREVIEW_PICTURE", GetMessage("LISTS_LIST_FIELD_PREVIEW_PICTURE"), CListFieldType::IS_FIELD, CListFieldType::NOT_READONLY);
         self::$types["PREVIEW_TEXT"] = new CListFieldType("PREVIEW_TEXT", GetMessage("LISTS_LIST_FIELD_PREVIEW_TEXT"), CListFieldType::IS_FIELD, CListFieldType::NOT_READONLY);
         self::$types["DETAIL_PICTURE"] = new CListFieldType("DETAIL_PICTURE", GetMessage("LISTS_LIST_FIELD_DETAIL_PICTURE"), CListFieldType::IS_FIELD, CListFieldType::NOT_READONLY);
         self::$types["DETAIL_TEXT"] = new CListFieldType("DETAIL_TEXT", GetMessage("LISTS_LIST_FIELD_DETAIL_TEXT"), CListFieldType::IS_FIELD, CListFieldType::NOT_READONLY);
         self::$types["DATE_CREATE"] = new CListFieldType("DATE_CREATE", GetMessage("LISTS_LIST_FIELD_DATE_CREATE"), CListFieldType::IS_FIELD, CListFieldType::IS_READONLY);
         self::$types["CREATED_BY"] = new CListFieldType("CREATED_BY", GetMessage("LISTS_LIST_FIELD_CREATED_BY"), CListFieldType::IS_FIELD, CListFieldType::IS_READONLY);
         self::$types["TIMESTAMP_X"] = new CListFieldType("TIMESTAMP_X", GetMessage("LISTS_LIST_FIELD_TIMESTAMP_X"), CListFieldType::IS_FIELD, CListFieldType::IS_READONLY);
         self::$types["MODIFIED_BY"] = new CListFieldType("MODIFIED_BY", GetMessage("LISTS_LIST_FIELD_MODIFIED_BY"), CListFieldType::IS_FIELD, CListFieldType::IS_READONLY);
         //Property types
         self::$types["S"] = new CListFieldType("S", GetMessage("LISTS_LIST_FIELD_S"), CListFieldType::NOT_FIELD, CListFieldType::NOT_READONLY);
         self::$types["N"] = new CListFieldType("N", GetMessage("LISTS_LIST_FIELD_N"), CListFieldType::NOT_FIELD, CListFieldType::NOT_READONLY);
         self::$types["L"] = new CListFieldType("L", GetMessage("LISTS_LIST_FIELD_L"), CListFieldType::NOT_FIELD, CListFieldType::NOT_READONLY);
         self::$types["F"] = new CListFieldType("F", GetMessage("LISTS_LIST_FIELD_F"), CListFieldType::NOT_FIELD, CListFieldType::NOT_READONLY);
         self::$types["G"] = new CListFieldType("G", GetMessage("LISTS_LIST_FIELD_G"), CListFieldType::NOT_FIELD, CListFieldType::NOT_READONLY);
         self::$types["E"] = new CListFieldType("E", GetMessage("LISTS_LIST_FIELD_E"), CListFieldType::NOT_FIELD, CListFieldType::NOT_READONLY);
         //User types
         foreach (CIBlockProperty::GetUserType() as $ar) {
             if (array_key_exists("GetPublicEditHTML", $ar)) {
                 self::$types[$ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"]] = new CListFieldType($ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"], $ar["DESCRIPTION"], CListFieldType::NOT_FIELD, CListFieldType::NOT_READONLY);
             }
         }
     }
 }
Example #2
0
 function Fetch()
 {
     $res = parent::Fetch();
     if ($res && $res["USER_TYPE"] != "") {
         $arUserType = CIBlockProperty::GetUserType($res["USER_TYPE"]);
         if (array_key_exists("ConvertFromDB", $arUserType)) {
             if (array_key_exists("VALUE", $res)) {
                 $value = array("VALUE" => $res["VALUE"], "DESCRIPTION" => "");
                 $value = call_user_func_array($arUserType["ConvertFromDB"], array($res, $value));
                 $res["VALUE"] = $value["VALUE"];
             }
             if (array_key_exists("DEFAULT_VALUE", $res)) {
                 $value = array("VALUE" => $res["DEFAULT_VALUE"], "DESCRIPTION" => "");
                 $value = call_user_func_array($arUserType["ConvertFromDB"], array($res, $value));
                 $res["DEFAULT_VALUE"] = $value["VALUE"];
             }
         }
         if (strlen($res["USER_TYPE_SETTINGS"])) {
             $res["USER_TYPE_SETTINGS"] = unserialize($res["USER_TYPE_SETTINGS"]);
         }
     }
     return $res;
 }
 public static function GetPropsTypesByOperations($userType = false, $arOperations = array())
 {
     if (!is_array($arOperations)) {
         $arOperations = array(strval($arOperations));
     }
     $methodByOperation = array('view' => 'GetPublicViewHTML', 'edit' => 'GetPublicEditHTML', 'filter' => 'GetPublicFilterHTML', 'import' => 'GetPublicEditHTML', 'rest' => 'GetPublicEditHTML');
     $whiteListByOperation = array('view' => array(), 'edit' => array(), 'filter' => array(), 'import' => array('S:HTML', 'S:Date', 'S:DateTime', 'S:employee', 'N:Sequence'), 'rest' => array('S:HTML', 'S:Date', 'S:DateTime', 'S:employee', 'E:EList', 'N:Sequence'));
     $arUserTypeList = CIBlockProperty::GetUserType($userType);
     if (!empty($arOperations)) {
         foreach ($arUserTypeList as $key => $item) {
             $skipNumber = count($arOperations);
             $skipCount = 0;
             foreach ($arOperations as $operation) {
                 if (!isset($methodByOperation[$operation]) || !array_key_exists($methodByOperation[$operation], $item) || is_array($whiteListByOperation[$operation]) && count($whiteListByOperation[$operation]) > 0 && !in_array($item['PROPERTY_TYPE'] . ':' . $key, $whiteListByOperation[$operation], true)) {
                     $skipCount++;
                 }
             }
             if ($skipNumber <= $skipCount) {
                 unset($arUserTypeList[$key]);
             }
         }
     }
     return $arUserTypeList;
 }
Example #4
0
 public static function SetPropertyValuesEx($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $FLAGS = array())
 {
     //Check input parameters
     if (!is_array($PROPERTY_VALUES)) {
         return;
     }
     if (!is_array($FLAGS)) {
         $FLAGS = array();
     }
     //FLAGS - modify function behavior
     //NewElement - if present no db values select will be issued
     //DoNotValidateLists - if present list values do not validates against metadata tables
     global $DB;
     $ELEMENT_ID = intval($ELEMENT_ID);
     if ($ELEMENT_ID <= 0) {
         return;
     }
     $IBLOCK_ID = intval($IBLOCK_ID);
     if ($IBLOCK_ID <= 0) {
         $rs = $DB->Query("select IBLOCK_ID from b_iblock_element where ID=" . $ELEMENT_ID);
         if ($ar = $rs->Fetch()) {
             $IBLOCK_ID = $ar["IBLOCK_ID"];
         } else {
             return;
         }
     }
     //Get property metadata
     static $PROPS_CACHE = array();
     if (!array_key_exists($IBLOCK_ID, $PROPS_CACHE)) {
         $PROPS_CACHE[$IBLOCK_ID] = array(0 => array());
         $rs = CIBlockProperty::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "N", "ACTIVE" => "Y"));
         while ($ar = $rs->Fetch()) {
             $ar["ConvertToDB"] = false;
             if ($ar["USER_TYPE"] != "") {
                 $arUserType = CIBlockProperty::GetUserType($ar["USER_TYPE"]);
                 if (array_key_exists("ConvertToDB", $arUserType)) {
                     $ar["ConvertToDB"] = $arUserType["ConvertToDB"];
                 }
             }
             $PROPS_CACHE[$IBLOCK_ID][$ar["ID"]] = $ar;
             //For CODE2ID conversion
             $PROPS_CACHE[$IBLOCK_ID][0][$ar["CODE"]] = $ar["ID"];
             //VERSION
             $PROPS_CACHE[$IBLOCK_ID]["VERSION"] = $ar["VERSION"];
         }
     }
     //Unify properties values arProps[$property_id]=>array($id=>array("VALUE", "DESCRIPTION"),....)
     $arProps = array();
     foreach ($PROPERTY_VALUES as $key => $value) {
         //Code2ID
         if (array_key_exists($key, $PROPS_CACHE[$IBLOCK_ID][0])) {
             $key = $PROPS_CACHE[$IBLOCK_ID][0][$key];
         } else {
             $key = intval($key);
             if ($key <= 0 || !array_key_exists($key, $PROPS_CACHE[$IBLOCK_ID])) {
                 continue;
             }
         }
         if ($PROPS_CACHE[$IBLOCK_ID][$key]["PROPERTY_TYPE"] == "F") {
             if (is_array($value)) {
                 $ar = array_keys($value);
                 if (array_key_exists("tmp_name", $value) || array_key_exists("del", $value)) {
                     $uni_value = array(array("ID" => 0, "VALUE" => $value, "DESCRIPTION" => ""));
                 } elseif ($ar[0] === "VALUE" && $ar[1] === "DESCRIPTION") {
                     $uni_value = array(array("ID" => 0, "VALUE" => $value["VALUE"], "DESCRIPTION" => $value["DESCRIPTION"]));
                 } elseif (count($ar) === 1 && $ar[0] === "VALUE") {
                     $uni_value = array(array("ID" => 0, "VALUE" => $value["VALUE"], "DESCRIPTION" => ""));
                 } else {
                     $uni_value = array();
                     foreach ($value as $id => $val) {
                         if (is_array($val)) {
                             if (array_key_exists("tmp_name", $val) || array_key_exists("del", $val)) {
                                 $uni_value[] = array("ID" => $id, "VALUE" => $val, "DESCRIPTION" => "");
                             } else {
                                 $ar = array_keys($val);
                                 if ($ar[0] === "VALUE" && $ar[1] === "DESCRIPTION") {
                                     $uni_value[] = array("ID" => $id, "VALUE" => $val["VALUE"], "DESCRIPTION" => $val["DESCRIPTION"]);
                                 } elseif (count($ar) === 1 && $ar[0] === "VALUE") {
                                     $uni_value[] = array("ID" => $id, "VALUE" => $val["VALUE"], "DESCRIPTION" => "");
                                 }
                             }
                         }
                     }
                 }
             } else {
                 //There was no valid file array found so we'll skip this property
                 $uni_value = array();
             }
         } elseif (!is_array($value)) {
             $uni_value = array(array("VALUE" => $value, "DESCRIPTION" => ""));
         } else {
             $ar = array_keys($value);
             if (count($ar) === 2 && $ar[0] === "VALUE" && $ar[1] === "DESCRIPTION") {
                 $uni_value = array(array("VALUE" => $value["VALUE"], "DESCRIPTION" => $value["DESCRIPTION"]));
             } elseif (count($ar) === 1 && $ar[0] === "VALUE") {
                 $uni_value = array(array("VALUE" => $value["VALUE"], "DESCRIPTION" => ""));
             } else {
                 $uni_value = array();
                 foreach ($value as $id => $val) {
                     if (!is_array($val)) {
                         $uni_value[] = array("VALUE" => $val, "DESCRIPTION" => "");
                     } else {
                         $ar = array_keys($val);
                         if ($ar[0] === "VALUE" && $ar[1] === "DESCRIPTION") {
                             $uni_value[] = array("VALUE" => $val["VALUE"], "DESCRIPTION" => $val["DESCRIPTION"]);
                         } elseif (count($ar) === 1 && $ar[0] === "VALUE") {
                             $uni_value[] = array("VALUE" => $val["VALUE"], "DESCRIPTION" => "");
                         }
                     }
                 }
             }
         }
         $arValueCounters = array();
         foreach ($uni_value as $val) {
             if (!array_key_exists($key, $arProps)) {
                 $arProps[$key] = array();
                 $arValueCounters[$key] = 0;
             }
             if ($PROPS_CACHE[$IBLOCK_ID][$key]["ConvertToDB"] !== false) {
                 $arProperty = $PROPS_CACHE[$IBLOCK_ID][$key];
                 $arProperty["ELEMENT_ID"] = $ELEMENT_ID;
                 $val = call_user_func_array($PROPS_CACHE[$IBLOCK_ID][$key]["ConvertToDB"], array($arProperty, $val));
             }
             if (!is_array($val["VALUE"]) && strlen($val["VALUE"]) > 0 || is_array($val["VALUE"]) && count($val["VALUE"]) > 0) {
                 if ($arValueCounters[$key] == 0 || $PROPS_CACHE[$IBLOCK_ID][$key]["MULTIPLE"] == "Y") {
                     if (!is_array($val["VALUE"]) || !isset($val["VALUE"]["del"])) {
                         $arValueCounters[$key]++;
                     }
                     $arProps[$key][] = $val;
                 }
             }
         }
     }
     if (count($arProps) <= 0) {
         return;
     }
     //Read current property values from database
     $arDBProps = array();
     if (!array_key_exists("NewElement", $FLAGS)) {
         if ($PROPS_CACHE[$IBLOCK_ID]["VERSION"] == 1) {
             $rs = $DB->Query("\n\t\t\t\t\tselect *\n\t\t\t\t\tfrom b_iblock_element_property\n\t\t\t\t\twhere IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\tAND IBLOCK_PROPERTY_ID in (" . implode(", ", array_keys($arProps)) . ")\n\t\t\t\t");
             while ($ar = $rs->Fetch()) {
                 if (!array_key_exists($ar["IBLOCK_PROPERTY_ID"], $arDBProps)) {
                     $arDBProps[$ar["IBLOCK_PROPERTY_ID"]] = array();
                 }
                 $arDBProps[$ar["IBLOCK_PROPERTY_ID"]][$ar["ID"]] = $ar;
             }
         } else {
             $rs = $DB->Query("\n\t\t\t\t\tselect *\n\t\t\t\t\tfrom b_iblock_element_prop_m" . $IBLOCK_ID . "\n\t\t\t\t\twhere IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\tAND IBLOCK_PROPERTY_ID in (" . implode(", ", array_keys($arProps)) . ")\n\t\t\t\t");
             while ($ar = $rs->Fetch()) {
                 if (!array_key_exists($ar["IBLOCK_PROPERTY_ID"], $arDBProps)) {
                     $arDBProps[$ar["IBLOCK_PROPERTY_ID"]] = array();
                 }
                 $arDBProps[$ar["IBLOCK_PROPERTY_ID"]][$ar["ID"]] = $ar;
             }
             $rs = $DB->Query("\n\t\t\t\t\tselect *\n\t\t\t\t\tfrom b_iblock_element_prop_s" . $IBLOCK_ID . "\n\t\t\t\t\twhere IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t");
             if ($ar = $rs->Fetch()) {
                 foreach ($PROPS_CACHE[$IBLOCK_ID] as $property_id => $property) {
                     if (array_key_exists($property_id, $arProps) && array_key_exists("PROPERTY_" . $property_id, $ar) && $property["MULTIPLE"] == "N" && strlen($ar["PROPERTY_" . $property_id]) > 0) {
                         $pr = array("IBLOCK_PROPERTY_ID" => $property_id, "VALUE" => $ar["PROPERTY_" . $property_id], "DESCRIPTION" => $ar["DESCRIPTION_" . $property_id]);
                         if (!array_key_exists($pr["IBLOCK_PROPERTY_ID"], $arDBProps)) {
                             $arDBProps[$pr["IBLOCK_PROPERTY_ID"]] = array();
                         }
                         $arDBProps[$pr["IBLOCK_PROPERTY_ID"]][$ELEMENT_ID . ":" . $property_id] = $pr;
                     }
                 }
             }
         }
     }
     $arFilesToDelete = array();
     //Handle file properties
     foreach ($arProps as $property_id => $values) {
         if ($PROPS_CACHE[$IBLOCK_ID][$property_id]["PROPERTY_TYPE"] == "F") {
             foreach ($values as $i => $value) {
                 $val = $value["VALUE"];
                 if (strlen($val["del"]) > 0) {
                     $val = "NULL";
                 } else {
                     $val["MODULE_ID"] = "iblock";
                     unset($val["old_file"]);
                     if (strlen($value["DESCRIPTION"]) > 0) {
                         $val["description"] = $value["DESCRIPTION"];
                     }
                     $val = CFile::SaveFile($val, "iblock");
                 }
                 if ($val == "NULL") {
                     //Delete it! Actually it will not add an value
                     unset($arProps[$property_id][$i]);
                 } elseif (intval($val) > 0) {
                     $arProps[$property_id][$i]["VALUE"] = intval($val);
                     if (strlen($value["DESCRIPTION"]) <= 0) {
                         $arProps[$property_id][$i]["DESCRIPTION"] = $arDBProps[$property_id][$value["ID"]]["DESCRIPTION"];
                     }
                 } elseif (strlen($value["DESCRIPTION"]) > 0) {
                     $arProps[$property_id][$i]["VALUE"] = $arDBProps[$property_id][$value["ID"]]["VALUE"];
                     //Only needs to update description so CFile::Delete will not called
                     unset($arDBProps[$property_id][$value["ID"]]);
                 } else {
                     $arProps[$property_id][$i]["VALUE"] = $arDBProps[$property_id][$value["ID"]]["VALUE"];
                     //CFile::Delete will not called
                     unset($arDBProps[$property_id][$value["ID"]]);
                 }
             }
             if (array_key_exists($property_id, $arDBProps)) {
                 foreach ($arDBProps[$property_id] as $id => $value) {
                     $arFilesToDelete[] = array($value["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $IBLOCK_ID);
                 }
             }
         }
     }
     foreach ($arFilesToDelete as $ar) {
         call_user_func_array(array("CIBlockElement", "DeleteFile"), $ar);
     }
     //Now we'll try to find out properties which do not require any update
     if (!array_key_exists("NewElement", $FLAGS)) {
         foreach ($arProps as $property_id => $values) {
             if ($PROPS_CACHE[$IBLOCK_ID][$property_id]["PROPERTY_TYPE"] != "F") {
                 if (array_key_exists($property_id, $arDBProps)) {
                     $db_values = $arDBProps[$property_id];
                     if (count($values) == count($db_values)) {
                         $bEqual = true;
                         foreach ($values as $id => $value) {
                             $bDBFound = false;
                             foreach ($db_values as $db_id => $db_row) {
                                 if (strcmp($value["VALUE"], $db_row["VALUE"]) == 0 && strcmp($value["DESCRIPTION"], $db_row["DESCRIPTION"]) == 0) {
                                     unset($db_values[$db_id]);
                                     $bDBFound = true;
                                     break;
                                 }
                             }
                             if (!$bDBFound) {
                                 $bEqual = false;
                                 break;
                             }
                         }
                         if ($bEqual) {
                             unset($arProps[$property_id]);
                             unset($arDBProps[$property_id]);
                         }
                     }
                 } elseif (count($values) == 0) {
                     //Values was not found in database neither no values input was given
                     unset($arProps[$property_id]);
                 }
             }
         }
     }
     //Init "commands" arrays
     $ar2Delete = array("b_iblock_element_property" => array(), "b_iblock_element_prop_m" . $IBLOCK_ID => array(), "b_iblock_section_element" => array());
     $ar2Insert = array("values" => array("b_iblock_element_property" => array(), "b_iblock_element_prop_m" . $IBLOCK_ID => array()), "sqls" => array("b_iblock_element_property" => array(), "b_iblock_element_prop_m" . $IBLOCK_ID => array(), "b_iblock_section_element" => array()));
     $ar2Update = array();
     foreach ($arDBProps as $property_id => $values) {
         if ($PROPS_CACHE[$IBLOCK_ID][$property_id]["VERSION"] == 1) {
             $ar2Delete["b_iblock_element_property"][$property_id] = true;
         } elseif ($PROPS_CACHE[$IBLOCK_ID][$property_id]["MULTIPLE"] == "Y") {
             $ar2Delete["b_iblock_element_prop_m" . $IBLOCK_ID][$property_id] = true;
             $ar2Update["b_iblock_element_prop_s" . $IBLOCK_ID][$property_id] = false;
             //null
         } else {
             $ar2Update["b_iblock_element_prop_s" . $IBLOCK_ID][$property_id] = false;
             //null
         }
         if ($PROPS_CACHE[$IBLOCK_ID][$property_id]["PROPERTY_TYPE"] == "G") {
             $ar2Delete["b_iblock_section_element"][$property_id] = true;
         }
     }
     foreach ($arProps as $property_id => $values) {
         $db_prop = $PROPS_CACHE[$IBLOCK_ID][$property_id];
         if ($db_prop["PROPERTY_TYPE"] == "L" && !array_key_exists("DoNotValidateLists", $FLAGS)) {
             $arID = array();
             foreach ($values as $value) {
                 $value["VALUE"] = intval($value["VALUE"]);
                 if ($value["VALUE"] > 0) {
                     $arID[] = $value["VALUE"];
                 }
             }
             if (count($arID) > 0) {
                 if ($db_prop["VERSION"] == 1) {
                     $ar2Insert["sqls"]["b_iblock_element_property"][$property_id] = "\n\t\t\t\t\t\t\t\tINSERT INTO b_iblock_element_property\n\t\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_ENUM)\n\t\t\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, PEN.ID, PEN.ID\n\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tP.ID=" . $property_id . "\n\t\t\t\t\t\t\t\t\tAND P.ID=PEN.PROPERTY_ID\n\t\t\t\t\t\t\t\t\tAND PEN.ID IN (" . implode(", ", $arID) . ")\n\t\t\t\t\t\t";
                 } elseif ($db_prop["MULTIPLE"] == "Y") {
                     $ar2Insert["sqls"]["b_iblock_element_prop_m" . $IBLOCK_ID][$property_id] = "\n\t\t\t\t\t\t\t\tINSERT INTO b_iblock_element_prop_m" . $IBLOCK_ID . "\n\t\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_ENUM)\n\t\t\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, PEN.ID, PEN.ID\n\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tP.ID=" . $property_id . "\n\t\t\t\t\t\t\t\t\tAND P.ID=PEN.PROPERTY_ID\n\t\t\t\t\t\t\t\t\tAND PEN.ID IN (" . implode(", ", $arID) . ")\n\t\t\t\t\t\t";
                     $ar2Update["b_iblock_element_prop_s" . $IBLOCK_ID][$property_id] = false;
                     //null
                 } else {
                     $rs = $DB->Query("\n\t\t\t\t\t\t\t\tSELECT PEN.ID\n\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tP.ID=" . $property_id . "\n\t\t\t\t\t\t\t\t\tAND P.ID=PEN.PROPERTY_ID\n\t\t\t\t\t\t\t\t\tAND PEN.ID IN (" . implode(", ", $arID) . ")\n\t\t\t\t\t\t");
                     if ($ar = $rs->Fetch()) {
                         $ar2Update["b_iblock_element_prop_s" . $IBLOCK_ID][$property_id] = array("VALUE" => $ar["ID"], "DESCRIPTION" => "");
                     }
                 }
             }
             continue;
         }
         if ($db_prop["PROPERTY_TYPE"] == "G") {
             $arID = array();
             foreach ($values as $value) {
                 $value["VALUE"] = intval($value["VALUE"]);
                 if ($value["VALUE"] > 0) {
                     $arID[] = $value["VALUE"];
                 }
             }
             if (count($arID) > 0) {
                 if ($db_prop["VERSION"] == 1) {
                     $ar2Insert["sqls"]["b_iblock_element_property"][$property_id] = "\n\t\t\t\t\t\t\t\tINSERT INTO b_iblock_element_property\n\t\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM)\n\t\t\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, S.ID, S.ID\n\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tP.ID=" . $property_id . "\n\t\t\t\t\t\t\t\t\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\t\t\tAND S.ID IN (" . implode(", ", $arID) . ")\n\t\t\t\t\t\t";
                 } elseif ($db_prop["MULTIPLE"] == "Y") {
                     $ar2Insert["sqls"]["b_iblock_element_prop_m" . $IBLOCK_ID][$property_id] = "\n\t\t\t\t\t\t\t\tINSERT INTO b_iblock_element_prop_m" . $IBLOCK_ID . "\n\t\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM)\n\t\t\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, S.ID, S.ID\n\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tP.ID=" . $property_id . "\n\t\t\t\t\t\t\t\t\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\t\t\tAND S.ID IN (" . implode(", ", $arID) . ")\n\t\t\t\t\t\t";
                     $ar2Update["b_iblock_element_prop_s" . $IBLOCK_ID][$property_id] = false;
                     //null
                 } else {
                     $rs = $DB->Query("\n\t\t\t\t\t\t\t\tSELECT S.ID\n\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tP.ID=" . $property_id . "\n\t\t\t\t\t\t\t\t\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\t\t\tAND S.ID IN (" . implode(", ", $arID) . ")\n\t\t\t\t\t\t");
                     if ($ar = $rs->Fetch()) {
                         $ar2Update["b_iblock_element_prop_s" . $IBLOCK_ID][$property_id] = array("VALUE" => $ar["ID"], "DESCRIPTION" => "");
                     }
                 }
                 $ar2Insert["sqls"]["b_iblock_section_element"][$property_id] = "\n\t\t\t\t\t\tINSERT INTO b_iblock_section_element\n\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_SECTION_ID, ADDITIONAL_PROPERTY_ID)\n\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", S.ID, P.ID\n\t\t\t\t\t\tFROM b_iblock_property P, b_iblock_section S\n\t\t\t\t\t\tWHERE P.ID=" . $property_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 (" . implode(", ", $arID) . ")\n\t\t\t\t\t";
             }
             continue;
         }
         foreach ($values as $value) {
             if ($db_prop["VERSION"] == 1) {
                 $ar2Insert["values"]["b_iblock_element_property"][$property_id][] = $value;
             } elseif ($db_prop["MULTIPLE"] == "Y") {
                 $ar2Insert["values"]["b_iblock_element_prop_m" . $IBLOCK_ID][$property_id][] = $value;
                 $ar2Update["b_iblock_element_prop_s" . $IBLOCK_ID][$property_id] = false;
                 //null
             } else {
                 $ar2Update["b_iblock_element_prop_s" . $IBLOCK_ID][$property_id] = $value;
             }
         }
     }
     foreach ($ar2Delete as $table => $arID) {
         if (count($arID) > 0) {
             if ($table == "b_iblock_section_element") {
                 $DB->Query("\n\t\t\t\t\t\tdelete from " . $table . "\n\t\t\t\t\t\twhere IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t\t\tand  ADDITIONAL_PROPERTY_ID in (" . implode(", ", array_keys($arID)) . ")\n\t\t\t\t\t");
             } else {
                 $DB->Query("\n\t\t\t\t\t\tdelete from " . $table . "\n\t\t\t\t\t\twhere IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t\t\tand IBLOCK_PROPERTY_ID in (" . implode(", ", array_keys($arID)) . ")\n\t\t\t\t\t");
             }
         }
     }
     foreach ($ar2Insert["values"] as $table => $properties) {
         $strSqlPrefix = "\n\t\t\t\t\tinsert into " . $table . "\n\t\t\t\t\t(IBLOCK_PROPERTY_ID, IBLOCK_ELEMENT_ID, VALUE, VALUE_ENUM, VALUE_NUM, DESCRIPTION)\n\t\t\t\t\tvalues\n\t\t\t";
         $maxValuesLen = $DB->type == "MYSQL" ? 1024 : 0;
         $strSqlValues = "";
         foreach ($properties as $property_id => $values) {
             foreach ($values as $value) {
                 if (strlen($value["VALUE"]) > 0) {
                     $strSqlValues .= ",\n(" . $property_id . ", " . $ELEMENT_ID . ", " . "'" . $DB->ForSQL($value["VALUE"]) . "', " . intval($value["VALUE"]) . ", " . CIBlock::roundDB($value["VALUE"]) . ", " . (strlen($value["DESCRIPTION"]) ? "'" . $DB->ForSQL($value["DESCRIPTION"]) . "'" : "null") . " " . ")";
                 }
                 if (strlen($strSqlValues) > $maxValuesLen) {
                     $DB->Query($strSqlPrefix . substr($strSqlValues, 2));
                     $strSqlValues = "";
                 }
             }
         }
         if (strlen($strSqlValues) > 0) {
             $DB->Query($strSqlPrefix . substr($strSqlValues, 2));
             $strSqlValues = "";
         }
     }
     foreach ($ar2Insert["sqls"] as $table => $properties) {
         foreach ($properties as $property_id => $sql) {
             $DB->Query($sql);
         }
     }
     foreach ($ar2Update as $table => $properties) {
         $tableFields = $DB->GetTableFields($table);
         if (count($properties) > 0) {
             $arFields = array();
             foreach ($properties as $property_id => $value) {
                 if ($value === false || strlen($value["VALUE"]) <= 0) {
                     $arFields[] = "PROPERTY_" . $property_id . " = null";
                     if (isset($tableFields["DESCRIPTION_" . $property_id])) {
                         $arFields[] = "DESCRIPTION_" . $property_id . " = null";
                     }
                 } else {
                     $arFields[] = "PROPERTY_" . $property_id . " = '" . $DB->ForSQL($value["VALUE"]) . "'";
                     if (isset($tableFields["DESCRIPTION_" . $property_id])) {
                         if (strlen($value["DESCRIPTION"])) {
                             $arFields[] = "DESCRIPTION_" . $property_id . " = '" . $DB->ForSQL($value["DESCRIPTION"]) . "'";
                         } else {
                             $arFields[] = "DESCRIPTION_" . $property_id . " = null";
                         }
                     }
                 }
             }
             $DB->Query("\n\t\t\t\t\tupdate " . $table . "\n\t\t\t\t\tset " . implode(",\n", $arFields) . "\n\t\t\t\t\twhere IBLOCK_ELEMENT_ID = " . $ELEMENT_ID . "\n\t\t\t\t");
         }
     }
     /****************************** QUOTA ******************************/
     $_SESSION["SESS_RECOUNT_DB"] = "Y";
     /****************************** QUOTA ******************************/
     foreach (GetModuleEvents("iblock", "OnAfterIBlockElementSetPropertyValuesEx", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $FLAGS));
     }
 }
Example #5
0
 public static function GetTypesCreate()
 {
     if (!self::$arTypesCreateList) {
         self::$arTypesCreateList = array("S" => GetMessage("SP_LIST_FIELD_S"), "N" => GetMessage("SP_LIST_FIELD_N"), "L" => GetMessage("SP_LIST_FIELD_L"), "F" => GetMessage("SP_LIST_FIELD_F"), "G" => GetMessage("SP_LIST_FIELD_G"), "E" => GetMessage("SP_LIST_FIELD_E"));
         //User types
         foreach (CIBlockProperty::GetUserType() as $ar) {
             if (array_key_exists("GetPublicEditHTML", $ar)) {
                 self::$arTypesCreateList[$ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"]] = $ar["DESCRIPTION"];
             }
         }
     }
     return self::$arTypesCreateList;
 }
Example #6
0
	public static function GetDisplayValue($arItem, $arProperty, $event1)
	{
		static $installedStatictic = null;
		if (null === $installedStatictic)
		{
			$installedStatictic = \Freetrix\Main\ModuleManager::isModuleInstalled('statistic');
		}
		$arUserTypeFormat = false;
		if(isset($arProperty["USER_TYPE"]) && !empty($arProperty["USER_TYPE"]))
		{
			$arUserType = CIBlockProperty::GetUserType($arProperty["USER_TYPE"]);
			if(isset($arUserType["GetPublicViewHTML"]))
				$arUserTypeFormat = $arUserType["GetPublicViewHTML"];
		}

		static $CACHE = array("E"=>array(),"G"=>array());
		if($arUserTypeFormat)
		{
			if($arProperty["MULTIPLE"]=="N" || !is_array($arProperty["~VALUE"]))
				$arValues = array($arProperty["~VALUE"]);
			else
				$arValues = $arProperty["~VALUE"];
		}
		else
		{
			if(is_array($arProperty["VALUE"]))
				$arValues = $arProperty["VALUE"];
			else
				$arValues = array($arProperty["VALUE"]);
		}
		$arDisplayValue = array();
		$arFiles = array();
		$arLinkElements = array();
		$arLinkSections = array();
		foreach($arValues as $val)
		{
			if($arUserTypeFormat)
			{
				$arDisplayValue[] = call_user_func_array($arUserTypeFormat,
					array(
						$arProperty,
						array("VALUE" => $val),
						array(),
					));
			}
			elseif($arProperty["PROPERTY_TYPE"] == "E")
			{
				if(intval($val) > 0)
				{
					if(!isset($CACHE["E"][$val]))
					{
						//USED TO GET "LINKED" ELEMENTS
						$arLinkFilter = array (
							"ID" => $val,
							"ACTIVE" => "Y",
							"ACTIVE_DATE" => "Y",
							"CHECK_PERMISSIONS" => "Y",
						);
						$rsLink = CIBlockElement::GetList(
							array(),
							$arLinkFilter,
							false,
							false,
							array("ID","IBLOCK_ID","NAME","DETAIL_PAGE_URL", "PREVIEW_PICTURE", "DETAIL_PUCTURE")
						);
						$CACHE["E"][$val] = $rsLink->GetNext();
					}
					if(is_array($CACHE["E"][$val]))
					{
						$arDisplayValue[]='<a href="'.$CACHE["E"][$val]["DETAIL_PAGE_URL"].'">'.$CACHE["E"][$val]["NAME"].'</a>';
						$arLinkElements[$val] = $CACHE["E"][$val];
					}
				}
			}
			elseif($arProperty["PROPERTY_TYPE"] == "G")
			{
				if(intval($val) > 0)
				{
					if(!isset($CACHE["G"][$val]))
					{
						//USED TO GET SECTIONS NAMES
						$arSectionFilter = array (
							"ID" => $val,
						);
						$rsSection = CIBlockSection::GetList(
							array(),
							$arSectionFilter,
							false,
							array("ID", "IBLOCK_ID", "NAME", "SECTION_PAGE_URL", "PICTURE", "DETAIL_PICTURE")
						);
						$CACHE["G"][$val] = $rsSection->GetNext();
					}
					if(is_array($CACHE["G"][$val]))
					{
						$arDisplayValue[]='<a href="'.$CACHE["G"][$val]["SECTION_PAGE_URL"].'">'.$CACHE["G"][$val]["NAME"].'</a>';
						$arLinkSections[$val] = $CACHE["G"][$val];
					}
				}
			}
			elseif($arProperty["PROPERTY_TYPE"]=="L")
			{
				$arDisplayValue[] = $val;
			}
			elseif($arProperty["PROPERTY_TYPE"]=="F")
			{
				if($arFile = CFile::GetFileArray($val))
				{
					$arFiles[] = $arFile;
					if($installedStatictic)
						$arDisplayValue[] =  '<a href="'.htmlspecialcharsbx("/freetrix/redirect.php?event1=".urlencode($event1)."&event2=".urlencode($arFile["SRC"])."&event3=".urlencode($arFile["ORIGINAL_NAME"])."&goto=".urlencode($arFile["SRC"])).'">'.GetMessage('IBLOCK_DOWNLOAD').'</a>';
					else
						$arDisplayValue[] =  '<a href="'.htmlspecialcharsbx($arFile["SRC"]).'">'.GetMessage('IBLOCK_DOWNLOAD').'</a>';
				}
			}
			else
			{
				$trimmed = trim($val);
				if(strpos($trimmed, "http")===0)
				{
					if($installedStatictic)
						$arDisplayValue[] =  '<a href="'.htmlspecialcharsbx("/freetrix/redirect.php?event1=".urlencode($event1)."&event2=".urlencode($trimmed)."&event3=".urlencode($arItem["NAME"])."&goto=".urlencode($trimmed)).'">'.$trimmed.'</a>';
					else
						$arDisplayValue[] =  '<a href="'.htmlspecialcharsbx($trimmed).'">'.$trimmed.'</a>';
				}
				elseif(strpos($trimmed, "www")===0)
				{
					if($installedStatictic)
						$arDisplayValue[] =  '<a href="'.htmlspecialcharsbx("/freetrix/redirect.php?event1=".urlencode($event1)."&event2=".urlencode("http://".$trimmed)."&event3=".urlencode($arItem["NAME"])."&goto=".urlencode("http://".$trimmed)).'">'.$trimmed.'</a>';
					else
						$arDisplayValue[] =  '<a href="'.htmlspecialcharsbx("http://".$val).'">'.$val.'</a>';
				}
				else
					$arDisplayValue[] = $val;
			}
		}

		if(count($arDisplayValue)==1)
			$arProperty["DISPLAY_VALUE"] = $arDisplayValue[0];
		elseif(count($arDisplayValue)>1)
			$arProperty["DISPLAY_VALUE"] = $arDisplayValue;
		else
			$arProperty["DISPLAY_VALUE"] = false;

		if ($arProperty["PROPERTY_TYPE"]=="F")
		{
			if(count($arFiles)==1)
				$arProperty["FILE_VALUE"] = $arFiles[0];
			elseif(count($arFiles)>1)
				$arProperty["FILE_VALUE"] = $arFiles;
			else
				$arProperty["FILE_VALUE"] = false;
		}
		elseif ($arProperty['PROPERTY_TYPE'] == 'E')
		{
			$arProperty['LINK_ELEMENT_VALUE'] = (!empty($arLinkElements) ? $arLinkElements : false);
		}
		elseif ($arProperty['PROPERTY_TYPE'] == 'G')
		{
			$arProperty['LINK_SECTION_VALUE'] = (!empty($arLinkSections) ? $arLinkSections : false);
		}

		return $arProperty;
	}
Example #7
0
	public static function GetOfferProperties($offerID, $iblockID, $propertiesList, $skuTreeProps = '')
	{
		$iblockInfo = false;
		$result = array();

		$iblockID = intval($iblockID);
		$offerID = intval($offerID);
		if (0 >= $iblockID || 0 >= $offerID)
			return $result;

		$skuPropsList = array();
		if (!empty($skuTreeProps))
		{
			if (is_array($skuTreeProps))
			{
				$skuPropsList = $skuTreeProps;
			}
			else
			{
				$skuTreeProps = base64_decode((string)$skuTreeProps);
				if (false !== $skuTreeProps && CheckSerializedData($skuTreeProps))
				{
					$skuPropsList = unserialize($skuTreeProps);
					if (!is_array($skuPropsList))
					{
						$skuPropsList = array();
					}
				}
			}
		}

		if (!is_array($propertiesList))
		{
			$propertiesList = array();
		}
		if (!empty($skuPropsList))
		{
			$propertiesList = array_unique(array_merge($propertiesList, $skuPropsList));
		}
		if (empty($propertiesList))
			return $result;
		$propCodes = array_fill_keys($propertiesList, true);

		if (self::$catalogIncluded === null)
			self::$catalogIncluded = \Freetrix\Main\Loader::includeModule('catalog');
		if (self::$catalogIncluded)
		{
			$iblockInfo = CCatalogSKU::GetInfoByProductIBlock($iblockID);
		}
		if (empty($iblockInfo))
			return $result;

		$sortIndex = 1;
		$rsProps = CIBlockElement::GetProperty(
			$iblockInfo['IBLOCK_ID'],
			$offerID,
			array("sort"=>"asc", "enum_sort" => "asc", "value_id"=>"asc"),
			array("EMPTY"=>"N")
		);

		while ($oneProp = $rsProps->Fetch())
		{
			if (!isset($propCodes[$oneProp['CODE']]) && !isset($propCodes[$oneProp['ID']]))
				continue;
			$propID = (isset($propCodes[$oneProp['CODE']]) ? $oneProp['CODE'] : $oneProp['ID']);

			$userTypeProp = false;
			$userType = null;
			if (isset($oneProp['USER_TYPE']) && !empty($oneProp['USER_TYPE']))
			{
				$userTypeDescr = CIBlockProperty::GetUserType($oneProp['USER_TYPE']);
				if (isset($userTypeDescr['GetPublicViewHTML']))
				{
					$userTypeProp = true;
					$userType = $userTypeDescr['GetPublicViewHTML'];
				}
			}

			if ($userTypeProp)
			{
				$displayValue = (string)call_user_func_array($userType,
					array(
						$oneProp,
						array('VALUE' => $oneProp['VALUE']),
						array('MODE' => 'SIMPLE_TEXT')
					));
				$result[] = array(
					"NAME" => $oneProp["NAME"],
					"CODE" => $propID,
					"VALUE" => $displayValue,
					"SORT" => $sortIndex++,
				);
			}
			else
			{
				switch ($oneProp["PROPERTY_TYPE"])
				{
				case "S":
				case "N":
					$result[] = array(
						"NAME" => $oneProp["NAME"],
						"CODE" => $propID,
						"VALUE" => $oneProp["VALUE"],
						"SORT" => $sortIndex++,
					);
					break;
				case "G":
					$rsSection = CIBlockSection::GetList(
						array(),
						array("=ID"=>$oneProp["VALUE"]),
						false,
						array('ID', 'NAME')
					);
					if ($arSection = $rsSection->Fetch())
					{
						$result[] = array(
							"NAME" => $oneProp["NAME"],
							"CODE" => $propID,
							"VALUE" => $arSection["NAME"],
							"SORT" => $sortIndex++,
						);
					}
					break;
				case "E":
					$rsElement = CIBlockElement::GetList(
						array(),
						array("=ID"=>$oneProp["VALUE"]),
						false,
						false,
						array("ID", "NAME")
					);
					if ($arElement = $rsElement->Fetch())
					{
						$result[] = array(
							"NAME" => $oneProp["NAME"],
							"CODE" => $propID,
							"VALUE" => $arElement["NAME"],
							"SORT" => $sortIndex++,
						);
					}
					break;
				case "L":
					$result[] = array(
						"NAME" => $oneProp["NAME"],
						"CODE" => $propID,
						"VALUE" => $oneProp["VALUE_ENUM"],
						"SORT" => $sortIndex++,
					);
					break;
				}
			}
		}
		return $result;
	}
Example #8
0
 public function GetDocumentFieldTypes($documentType)
 {
     $iblockId = intval(substr($documentType, strlen("iblock_")));
     if ($iblockId <= 0) {
         throw new CBPArgumentOutOfRangeException("documentType", $documentType);
     }
     $arResult = array("string" => array("Name" => GetMessage("BPCGHLP_PROP_STRING"), "BaseType" => "string"), "text" => array("Name" => GetMessage("BPCGHLP_PROP_TEXT"), "BaseType" => "text"), "int" => array("Name" => GetMessage("BPCGHLP_PROP_INT"), "BaseType" => "int"), "double" => array("Name" => GetMessage("BPCGHLP_PROP_DOUBLE"), "BaseType" => "double"), "select" => array("Name" => GetMessage("BPCGHLP_PROP_SELECT"), "BaseType" => "select", "Complex" => true), "bool" => array("Name" => GetMessage("BPCGHLP_PROP_BOOL"), "BaseType" => "bool"), "date" => array("Name" => GetMessage("BPCGHLP_PROP_DATA"), "BaseType" => "date"), "datetime" => array("Name" => GetMessage("BPCGHLP_PROP_DATETIME"), "BaseType" => "datetime"), "user" => array("Name" => GetMessage("BPCGHLP_PROP_USER"), "BaseType" => "user"), "file" => array("Name" => GetMessage("BPCGHLP_PROP_FILE"), "BaseType" => "file"));
     foreach (CIBlockProperty::GetUserType() as $ar) {
         $t = $ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"];
         if (COption::GetOptionString("bizproc", "SkipNonPublicCustomTypes", "N") == "Y" && !array_key_exists("GetPublicEditHTML", $ar) || $t == "S:UserID" || $t == "S:DateTime") {
             continue;
         }
         $arResult[$t] = array("Name" => $ar["DESCRIPTION"], "BaseType" => "string");
         if ($t == "S:UserID") {
             $arResult[$t]["BaseType"] = "user";
         } elseif ($t == "S:employee" && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y") {
             $arResult[$t]["BaseType"] = "user";
         } elseif ($t == "S:DateTime") {
             $arResult[$t]["BaseType"] = "datetime";
         } elseif ($t == "E:EList") {
             $arResult[$t]["BaseType"] = "string";
             $arResult[$t]["Complex"] = true;
         } elseif (!array_key_exists("GetPublicEditHTML", $ar)) {
             continue;
         }
     }
     return $arResult;
 }
Example #9
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 ******************************/
 }
Example #10
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));
     }
 }
Example #11
0
 public function GetDocumentFieldTypes($documentType)
 {
     $v = substr($documentType, strlen("type_"));
     if (intval($v) . "!" != $v . "!") {
         throw new CBPArgumentOutOfRangeException("documentType", $documentType);
     }
     $iblockId = intval($v);
     $arResult = array("S" => array("Name" => GetMessage("BPVDX_STRING"), "BaseType" => "string"), "T" => array("Name" => GetMessage("BPVDX_TEXT"), "BaseType" => "text"), "N" => array("Name" => GetMessage("BPVDX_NUM"), "BaseType" => "double"), "L" => array("Name" => GetMessage("BPVDX_LIST"), "BaseType" => "select", "Complex" => true), "F" => array("Name" => GetMessage("BPVDX_FILE"), "BaseType" => "file"), "B" => array("Name" => GetMessage("BPVDX_YN"), "BaseType" => "bool"));
     foreach (CIBlockProperty::GetUserType() as $ar) {
         $t = $ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"];
         if (COption::GetOptionString("bizproc", "SkipNonPublicCustomTypes", "N") == "Y" && !array_key_exists("GetPublicEditHTML", $ar) && $t != "S:UserID" && $t != "S:DateTime") {
             continue;
         }
         $arResult[$t] = array("Name" => $ar["DESCRIPTION"], "BaseType" => "string");
         if ($t == "S:UserID") {
             $arResult[$t]["BaseType"] = "user";
         } elseif ($t == "S:employee" && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y") {
             $arResult[$t]["BaseType"] = "user";
         } elseif ($t == "S:DateTime") {
             $arResult[$t]["BaseType"] = "datetime";
         } elseif ($t == "E:EList") {
             $arResult[$t]["BaseType"] = "string";
             $arResult[$t]["Complex"] = true;
         } elseif (!array_key_exists("GetPublicEditHTML", $ar)) {
             continue;
         }
     }
     return $arResult;
 }
Example #12
0
 function setIBlock($IBLOCK_ID, $propertyID = array())
 {
     $this->VERSION = CIBlockElement::GetIBVersion($IBLOCK_ID);
     if (!empty($propertyID)) {
         Collection::normalizeArrayValuesByInt($propertyID);
     }
     $this->arProperties = array();
     if (!empty($propertyID) || empty($propertyID) && !isset(self::$propertiesCache[$IBLOCK_ID])) {
         $propertyIterator = PropertyTable::getList(array('select' => array('ID', 'IBLOCK_ID', 'NAME', 'ACTIVE', 'SORT', 'CODE', 'DEFAULT_VALUE', 'PROPERTY_TYPE', 'MULTIPLE', 'LINK_IBLOCK_ID', 'VERSION', 'USER_TYPE', 'USER_TYPE_SETTINGS'), 'filter' => empty($propertyID) ? array('IBLOCK_ID' => $IBLOCK_ID) : array('ID' => $propertyID, 'IBLOCK_ID' => $IBLOCK_ID), 'order' => array('ID' => 'ASC')));
         while ($property = $propertyIterator->fetch()) {
             if ($property['USER_TYPE']) {
                 $userType = CIBlockProperty::GetUserType($property['USER_TYPE']);
                 if (isset($userType["ConvertFromDB"])) {
                     if (array_key_exists("DEFAULT_VALUE", $property)) {
                         $value = array("VALUE" => $property["DEFAULT_VALUE"], "DESCRIPTION" => "");
                         $value = call_user_func_array($userType["ConvertFromDB"], array($property, $value));
                         $property["DEFAULT_VALUE"] = $value["VALUE"];
                     }
                 }
             }
             if ($property['USER_TYPE_SETTINGS'] !== '' || $property['USER_TYPE_SETTINGS'] !== null) {
                 $property['USER_TYPE_SETTINGS'] = unserialize($property['USER_TYPE_SETTINGS']);
             }
             $this->arProperties[$property['ID']] = $property;
         }
         unset($property, $propertyIterator);
         if (empty($propertyID)) {
             self::$propertiesCache[$IBLOCK_ID] = $this->arProperties;
         }
     } else {
         $this->arProperties = self::$propertiesCache[$IBLOCK_ID];
     }
 }
Example #13
0
 public function fillItemValues(&$resultItem, $arProperty, $flag = null)
 {
     static $cache = array();
     if (is_array($arProperty)) {
         if (isset($arProperty["PRICE"])) {
             return null;
         }
         $key = $arProperty["VALUE"];
         $PROPERTY_TYPE = $arProperty["PROPERTY_TYPE"];
         $PROPERTY_USER_TYPE = $arProperty["USER_TYPE"];
         $PROPERTY_ID = $arProperty["ID"];
     } else {
         $key = $arProperty;
         $PROPERTY_TYPE = $resultItem["PROPERTY_TYPE"];
         $PROPERTY_USER_TYPE = $resultItem["USER_TYPE"];
         $PROPERTY_ID = $resultItem["ID"];
         $arProperty = $resultItem;
     }
     if ($PROPERTY_TYPE == "F") {
         return null;
     } elseif ($PROPERTY_TYPE == "N") {
         $convertKey = (double) $key;
         if (strlen($key) <= 0) {
             return null;
         }
         if (!isset($resultItem["VALUES"]["MIN"]) || !array_key_exists("VALUE", $resultItem["VALUES"]["MIN"]) || doubleval($resultItem["VALUES"]["MIN"]["VALUE"]) > $convertKey) {
             $resultItem["VALUES"]["MIN"]["VALUE"] = preg_replace("/\\.0+\$/", "", $key);
         }
         if (!isset($resultItem["VALUES"]["MAX"]) || !array_key_exists("VALUE", $resultItem["VALUES"]["MAX"]) || doubleval($resultItem["VALUES"]["MAX"]["VALUE"]) < $convertKey) {
             $resultItem["VALUES"]["MAX"]["VALUE"] = preg_replace("/\\.0+\$/", "", $key);
         }
         return null;
     } elseif ($arProperty["DISPLAY_TYPE"] == "U") {
         $date = substr($key, 0, 10);
         if (!$date) {
             return null;
         }
         $timestamp = MakeTimeStamp($date, "YYYY-MM-DD");
         if (!$timestamp) {
             return null;
         }
         if (!isset($resultItem["VALUES"]["MIN"]) || !array_key_exists("VALUE", $resultItem["VALUES"]["MIN"]) || $resultItem["VALUES"]["MIN"]["VALUE"] > $timestamp) {
             $resultItem["VALUES"]["MIN"]["VALUE"] = $timestamp;
         }
         if (!isset($resultItem["VALUES"]["MAX"]) || !array_key_exists("VALUE", $resultItem["VALUES"]["MAX"]) || $resultItem["VALUES"]["MAX"]["VALUE"] < $timestamp) {
             $resultItem["VALUES"]["MAX"]["VALUE"] = $timestamp;
         }
         return null;
     } elseif ($PROPERTY_TYPE == "E" && $key <= 0) {
         return null;
     } elseif ($PROPERTY_TYPE == "G" && $key <= 0) {
         return null;
     } elseif (strlen($key) <= 0) {
         return null;
     }
     $arUserType = array();
     if ($PROPERTY_USER_TYPE != "") {
         $arUserType = CIBlockProperty::GetUserType($PROPERTY_USER_TYPE);
         if (isset($arUserType["GetExtendedValue"])) {
             $PROPERTY_TYPE = "Ux";
         } elseif (isset($arUserType["GetPublicViewHTML"])) {
             $PROPERTY_TYPE = "U";
         }
     }
     if ($PROPERTY_USER_TYPE === "DateTime") {
         $key = call_user_func_array($arUserType["GetPublicViewHTML"], array($arProperty, array("VALUE" => $key), array("MODE" => "SIMPLE_TEXT", "DATETIME_FORMAT" => "SHORT")));
         $PROPERTY_TYPE = "S";
     }
     $htmlKey = htmlspecialcharsbx($key);
     if (isset($resultItem["VALUES"][$htmlKey])) {
         return $htmlKey;
     }
     $file_id = null;
     $url_id = null;
     switch ($PROPERTY_TYPE) {
         case "L":
             $enum = CIBlockPropertyEnum::GetByID($key);
             if ($enum) {
                 $value = $enum["VALUE"];
                 $sort = $enum["SORT"];
                 $url_id = toLower($enum["XML_ID"]);
             } else {
                 return null;
             }
             break;
         case "E":
             if (!isset($cache[$PROPERTY_TYPE][$key])) {
                 $arLinkFilter = array("ID" => $key, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSIONS" => "Y");
                 $rsLink = CIBlockElement::GetList(array(), $arLinkFilter, false, false, array("ID", "IBLOCK_ID", "NAME", "SORT", "CODE"));
                 $cache[$PROPERTY_TYPE][$key] = $rsLink->Fetch();
             }
             $value = $cache[$PROPERTY_TYPE][$key]["NAME"];
             $sort = $cache[$PROPERTY_TYPE][$key]["SORT"];
             if ($cache[$PROPERTY_TYPE][$key]["CODE"]) {
                 $url_id = toLower($cache[$PROPERTY_TYPE][$key]["CODE"]);
             } else {
                 $url_id = toLower($value);
             }
             break;
         case "G":
             if (!isset($cache[$PROPERTY_TYPE][$key])) {
                 $arLinkFilter = array("ID" => $key, "GLOBAL_ACTIVE" => "Y", "CHECK_PERMISSIONS" => "Y");
                 $rsLink = CIBlockSection::GetList(array(), $arLinkFilter, false, array("ID", "IBLOCK_ID", "NAME", "LEFT_MARGIN", "DEPTH_LEVEL", "CODE"));
                 $cache[$PROPERTY_TYPE][$key] = $rsLink->Fetch();
                 $cache[$PROPERTY_TYPE][$key]['DEPTH_NAME'] = str_repeat(".", $cache[$PROPERTY_TYPE][$key]["DEPTH_LEVEL"]) . $cache[$PROPERTY_TYPE][$key]["NAME"];
             }
             $value = $cache[$PROPERTY_TYPE][$key]['DEPTH_NAME'];
             $sort = $cache[$PROPERTY_TYPE][$key]["LEFT_MARGIN"];
             if ($cache[$PROPERTY_TYPE][$key]["CODE"]) {
                 $url_id = toLower($cache[$PROPERTY_TYPE][$key]["CODE"]);
             } else {
                 $url_id = toLower($value);
             }
             break;
         case "U":
             if (!isset($cache[$PROPERTY_ID])) {
                 $cache[$PROPERTY_ID] = array();
             }
             if (!isset($cache[$PROPERTY_ID][$key])) {
                 $cache[$PROPERTY_ID][$key] = call_user_func_array($arUserType["GetPublicViewHTML"], array($arProperty, array("VALUE" => $key), array("MODE" => "SIMPLE_TEXT")));
             }
             $value = $cache[$PROPERTY_ID][$key];
             $sort = 0;
             $url_id = toLower($value);
             break;
         case "Ux":
             if (!isset($cache[$PROPERTY_ID])) {
                 $cache[$PROPERTY_ID] = array();
             }
             if (!isset($cache[$PROPERTY_ID][$key])) {
                 $cache[$PROPERTY_ID][$key] = call_user_func_array($arUserType["GetExtendedValue"], array($arProperty, array("VALUE" => $key)));
             }
             $value = $cache[$PROPERTY_ID][$key]['VALUE'];
             $file_id = $cache[$PROPERTY_ID][$key]['FILE_ID'];
             $sort = isset($cache[$PROPERTY_ID][$key]['SORT']) ? $cache[$PROPERTY_ID][$key]['SORT'] : 0;
             $url_id = toLower($cache[$PROPERTY_ID][$key]['UF_XML_ID']);
             break;
         default:
             $value = $key;
             $sort = 0;
             $url_id = toLower($value);
             break;
     }
     $keyCrc = abs(crc32($htmlKey));
     $safeValue = htmlspecialcharsex($value);
     $sort = (int) $sort;
     $filterPropertyID = $this->SAFE_FILTER_NAME . '_' . $PROPERTY_ID;
     $filterPropertyIDKey = $filterPropertyID . '_' . $keyCrc;
     $resultItem["VALUES"][$htmlKey] = array("CONTROL_ID" => $filterPropertyIDKey, "CONTROL_NAME" => $filterPropertyIDKey, "CONTROL_NAME_ALT" => $filterPropertyID, "HTML_VALUE_ALT" => $keyCrc, "HTML_VALUE" => "Y", "VALUE" => $safeValue, "SORT" => $sort, "UPPER" => ToUpper($safeValue), "FLAG" => $flag);
     if ($file_id) {
         $resultItem["VALUES"][$htmlKey]['FILE'] = CFile::GetFileArray($file_id);
     }
     if ($url_id) {
         $resultItem["VALUES"][$htmlKey]['URL_ID'] = $url_id;
     }
     return $htmlKey;
 }
Example #14
0
function __AddPropCellType($intOFPropID, $strPrefix, $arPropInfo)
{
    $strResult = '';
    ob_start();
    ?>
<select name="<?php 
    echo $strPrefix . $intOFPropID;
    ?>
_PROPERTY_TYPE" id="<?php 
    echo $strPrefix . $intOFPropID;
    ?>
_PROPERTY_TYPE" style="width:150px">
		<option value="S" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "S" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_S");
    ?>
</option>
		<option value="N" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "N" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_N");
    ?>
</option>
		<option value="L" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "L" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_L");
    ?>
</option>
		<option value="F" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "F" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_F");
    ?>
</option>
		<option value="G" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "G" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_G");
    ?>
</option>
		<option value="E" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "E" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_E");
    ?>
</option>
		<?php 
    foreach (CIBlockProperty::GetUserType() as $ar) {
        ?>
		<option value="<?php 
        echo htmlspecialcharsbx($ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"]);
        ?>
" <?php 
        if ($arPropInfo['PROPERTY_TYPE'] == $ar["PROPERTY_TYPE"] && $arPropInfo['USER_TYPE'] == $ar["USER_TYPE"]) {
            echo " selected";
        }
        ?>
><?php 
        echo htmlspecialcharsbx($ar["DESCRIPTION"]);
        ?>
</option>
		<?php 
    }
    ?>
	</select><?php 
    $strResult = ob_get_contents();
    ob_end_clean();
    return $strResult;
}
Example #15
0
                     $arUpdateValues["DETAIL_TEXT_TYPE"] = "text";
                 }
                 if ($propertyID == "PREVIEW_TEXT") {
                     $arUpdateValues["PREVIEW_TEXT_TYPE"] = "text";
                 }
                 $arUpdateValues[$propertyID] = $arProperties[$propertyID][0];
             }
         }
     }
 }
 // check required properties
 foreach ($arParams["PROPERTY_CODES_REQUIRED"] as $key => $propertyID) {
     $bError = false;
     $propertyValue = intval($propertyID) > 0 ? $arUpdatePropertyValues[$propertyID] : $arUpdateValues[$propertyID];
     if ($arResult["PROPERTY_LIST_FULL"][$propertyID]["USER_TYPE"] != "") {
         $arUserType = CIBlockProperty::GetUserType($arResult["PROPERTY_LIST_FULL"][$propertyID]["USER_TYPE"]);
     } else {
         $arUserType = array();
     }
     //Files check
     if ($arResult["PROPERTY_LIST_FULL"][$propertyID]['PROPERTY_TYPE'] == 'F') {
         //New element
         if ($arParams["ID"] <= 0) {
             $bError = true;
             if (is_array($propertyValue)) {
                 if (array_key_exists("tmp_name", $propertyValue) && array_key_exists("size", $propertyValue)) {
                     if ($propertyValue['size'] > 0) {
                         $bError = false;
                     }
                 } else {
                     foreach ($propertyValue as $arFile) {
Example #16
0
					<?echo htmlspecialcharsex($arProp["NAME"])?>
				</td>
				<td align="left"><?
					if($arProp['PROPERTY_TYPE'] == "S" && !$arProp['USER_TYPE'])
						echo GetMessage("IBLOCK_PROP_S");
					elseif($arProp['PROPERTY_TYPE'] == "N" && !$arProp['USER_TYPE'])
						echo GetMessage("IBLOCK_PROP_N");
					elseif($arProp['PROPERTY_TYPE'] == "L" && !$arProp['USER_TYPE'])
						echo GetMessage("IBLOCK_PROP_L");
					elseif($arProp['PROPERTY_TYPE'] == "F" && !$arProp['USER_TYPE'])
						echo GetMessage("IBLOCK_PROP_F");
					elseif($arProp['PROPERTY_TYPE'] == "G" && !$arProp['USER_TYPE'])
						echo GetMessage("IBLOCK_PROP_G");
					elseif($arProp['PROPERTY_TYPE'] == "E" && !$arProp['USER_TYPE'])
						echo GetMessage("IBLOCK_PROP_E");
					elseif($arProp['USER_TYPE'] && is_array($ar = CIBlockProperty::GetUserType($arProp['USER_TYPE'])))
						echo htmlspecialcharsex($ar["DESCRIPTION"]);
					else
						echo GetMessage("IBLOCK_PROP_S");
				?></td>
				<td style="text-align:center"><?
					echo '<input type="checkbox" value="Y" '.((is_array($arLink) && $arLink["INHERITED"] == "Y")? 'disabled="disabled"': '').' name="SECTION_PROPERTY['.$arProp['ID'].'][SMART_FILTER]" '.($arLink["SMART_FILTER"] == "Y"? 'checked="checked"': '').'>';
				?></td>
				<td align="left"><?
					if(!is_array($arLink) || $arLink["INHERITED"] == "N")
						echo '<a href="javascript:deleteSectionProperty('.$arProp['ID'].', \'select_SKU_SECTION_PROPERTY\', \'shadow_SKU_SECTION_PROPERTY\', \'table_SKU_SECTION_PROPERTY\')">'.GetMessage("CAT_CEDIT_PROP_TABLE_ACTION_DELETE").'</a>';
					else
						echo '&nbsp;';
				?></td>
			</tr>
			<?endwhile?>
 $dbrFProps = CIBlockProperty::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "FILTRABLE" => "Y", "!PROPERTY_TYPE" => "F", "CHECK_PERMISSIONS" => "N"));
 $arProps = $arPrices = array();
 while ($arProp = $dbrFProps->GetNext()) {
     $arProp["PROPERTY_USER_TYPE"] = !empty($arProp["USER_TYPE"]) ? CIBlockProperty::GetUserType($arProp["USER_TYPE"]) : array();
     $arProps[] = $arProp;
 }
 //filter sku props
 $arSKUProps = array();
 $arCatalog = CCatalogSKU::GetInfoByProductIBlock($iblockId);
 if (!empty($arCatalog)) {
     $dbrFProps = CIBlockProperty::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("IBLOCK_ID" => $arCatalog["IBLOCK_ID"], "ACTIVE" => "Y", "FILTRABLE" => "Y", "!PROPERTY_TYPE" => "F", "CHECK_PERMISSIONS" => "N"));
     while ($arProp = $dbrFProps->GetNext()) {
         if ($arCatalog['SKU_PROPERTY_ID'] == $arProp['ID']) {
             continue;
         }
         $arProp["PROPERTY_USER_TYPE"] = !empty($arProp["USER_TYPE"]) ? CIBlockProperty::GetUserType($arProp["USER_TYPE"]) : array();
         $arSKUProps[] = $arProp;
     }
 }
 $arFilter = array("IBLOCK_ID" => $iblockId, "SECTION_ID" => $_REQUEST['filter_section'], "ACTIVE" => $orderForm ? "Y" : $_REQUEST['filter_active'], "WF_PARENT_ELEMENT_ID" => false);
 if ('' != trim($_REQUEST['filter_product_name'])) {
     $arFilter["%NAME"] = $_REQUEST['filter_product_name'];
 }
 if ('' != trim($_REQUEST['filter_intext'])) {
     $arFilter["%SEARCHABLE_CONTENT"] = $_REQUEST['filter_intext'];
 }
 $arFilter["SHOW_NEW"] = "Y";
 if (!empty($arProps)) {
     foreach ($arProps as $arProp) {
         $value = ${"filter_el_property_" . $arProp["ID"]};
         if (array_key_exists("AddFilterFields", $arProp["PROPERTY_USER_TYPE"])) {
Example #18
0
 protected function getParams($product, $arIblock)
 {
     if (isset($arIblock['PROPERTY'])) {
         $arProperties = $arIblock['PROPERTY'];
     } else {
         $arProperties = array();
     }
     $arUserTypeFormat = array();
     foreach ($arProperties as $key => $arProperty) {
         $arUserTypeFormat[$arProperty["ID"]] = false;
         if (strlen($arProperty["USER_TYPE"])) {
             $arUserType = \CIBlockProperty::GetUserType($arProperty["USER_TYPE"]);
             if (array_key_exists("GetPublicViewHTML", $arUserType)) {
                 $arUserTypeFormat[$arProperty["ID"]] = $arUserType["GetPublicViewHTML"];
                 $arProperties[$key]['PROPERTY_TYPE'] = 'USER_TYPE';
             }
         }
     }
     $result = array();
     if (is_array($this->xmlData) && is_array($this->xmlData['XML_DATA']) && is_array($this->xmlData['XML_DATA']['PARAMS'])) {
         foreach ($this->xmlData['XML_DATA']['PARAMS'] as $key => $propId) {
             if ($propId) {
                 $result[] = $this->getValue($product, 'PARAM_' . $key, $propId, $arProperties, $arUserTypeFormat);
             }
         }
     }
     return $result;
 }
Example #19
0
function __AddPropCellType($intOFPropID, $strPrefix, $arPropInfo)
{
    static $arUserTypeList = null;
    if ($arUserTypeList === null) {
        $arUserTypeList = CIBlockProperty::GetUserType();
        \Bitrix\Main\Type\Collection::sortByColumn($arUserTypeList, array('DESCRIPTION' => SORT_STRING));
    }
    $boolUserPropExist = !empty($arUserTypeList);
    ob_start();
    ?>
<select name="<?php 
    echo $strPrefix . $intOFPropID;
    ?>
_PROPERTY_TYPE" id="<?php 
    echo $strPrefix . $intOFPropID;
    ?>
_PROPERTY_TYPE" style="width:150px"><?php 
    if ($boolUserPropExist) {
        ?>
<optgroup label="<?php 
        echo GetMessage('IB_E_PROP_BASE_TYPE_GROUP');
        ?>
"><?php 
    }
    ?>
	<option value="S" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "S" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_S");
    ?>
</option>
	<option value="N" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "N" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_N");
    ?>
</option>
	<option value="L" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "L" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_L");
    ?>
</option>
	<option value="F" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "F" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_F");
    ?>
</option>
	<option value="G" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "G" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_G");
    ?>
</option>
	<option value="E" <?php 
    if ($arPropInfo['PROPERTY_TYPE'] == "E" && !$arPropInfo['USER_TYPE']) {
        echo " selected";
    }
    ?>
><?php 
    echo GetMessage("IB_E_PROP_TYPE_E");
    ?>
</option>
	<?php 
    if ($boolUserPropExist) {
        ?>
</optgroup><optgroup label="<?php 
        echo GetMessage('IB_E_PROP_USER_TYPE_GROUP');
        ?>
"><?php 
    }
    foreach ($arUserTypeList as $ar) {
        ?>
<option value="<?php 
        echo htmlspecialcharsbx($ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"]);
        ?>
" <?php 
        if ($arPropInfo['PROPERTY_TYPE'] == $ar["PROPERTY_TYPE"] && $arPropInfo['USER_TYPE'] == $ar["USER_TYPE"]) {
            echo " selected";
        }
        ?>
><?php 
        echo htmlspecialcharsbx($ar["DESCRIPTION"]);
        ?>
</option>
		<?php 
    }
    if ($boolUserPropExist) {
        ?>
</optgroup><?php 
    }
    ?>
	</select><?php 
    $strResult = ob_get_contents();
    ob_end_clean();
    return $strResult;
}
Example #20
0
 public static function OnSearchReindex($NS = array(), $oCallback = NULL, $callback_method = "")
 {
     /** @global CUserTypeManager $USER_FIELD_MANAGER */
     global $USER_FIELD_MANAGER;
     /** $global CDatabase $DB */
     global $DB;
     $strNSJoin1 = "";
     $strNSFilter1 = "";
     $strNSFilter2 = "";
     $strNSFilter3 = "";
     $arResult = array();
     if ($NS["MODULE"] == "iblock" && strlen($NS["ID"]) > 0) {
         $arrTmp = explode(".", $NS["ID"]);
         $strNSFilter1 = " AND B.ID>=" . IntVal($arrTmp[0]) . " ";
         if (substr($arrTmp[1], 0, 1) != 'S') {
             $strNSFilter2 = " AND BE.ID>" . IntVal($arrTmp[1]) . " ";
         } else {
             $strNSFilter2 = false;
             $strNSFilter3 = " AND BS.ID>" . IntVal(substr($arrTmp[1], 1)) . " ";
         }
     }
     if ($NS["SITE_ID"] != "") {
         $strNSJoin1 .= " INNER JOIN b_iblock_site BS ON BS.IBLOCK_ID=B.ID ";
         $strNSFilter1 .= " AND BS.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "' ";
     }
     $strSql = "\n\t\t\tSELECT B.ID, B.IBLOCK_TYPE_ID, B.INDEX_ELEMENT, B.INDEX_SECTION, B.RIGHTS_MODE,\n\t\t\t\tB.IBLOCK_TYPE_ID, B.CODE as IBLOCK_CODE, B.XML_ID as IBLOCK_EXTERNAL_ID\n\t\t\tFROM b_iblock B\n\t\t\t" . $strNSJoin1 . "\n\t\t\tWHERE B.ACTIVE = 'Y'\n\t\t\t\tAND (B.INDEX_ELEMENT='Y' OR B.INDEX_SECTION='Y')\n\t\t\t\t" . $strNSFilter1 . "\n\t\t\tORDER BY B.ID\n\t\t";
     $dbrIBlock = $DB->Query($strSql);
     while ($arIBlock = $dbrIBlock->Fetch()) {
         $IBLOCK_ID = $arIBlock["ID"];
         $arGroups = array();
         $strSql = "SELECT GROUP_ID " . "FROM b_iblock_group " . "WHERE IBLOCK_ID= " . $IBLOCK_ID . " " . "\tAND PERMISSION>='R' " . "\tAND GROUP_ID>1 " . "ORDER BY GROUP_ID";
         $dbrIBlockGroup = $DB->Query($strSql);
         while ($arIBlockGroup = $dbrIBlockGroup->Fetch()) {
             $arGroups[] = $arIBlockGroup["GROUP_ID"];
             if ($arIBlockGroup["GROUP_ID"] == 2) {
                 break;
             }
         }
         $arSITE = array();
         $strSql = "SELECT SITE_ID " . "FROM b_iblock_site " . "WHERE IBLOCK_ID= " . $IBLOCK_ID;
         $dbrIBlockSite = $DB->Query($strSql);
         while ($arIBlockSite = $dbrIBlockSite->Fetch()) {
             $arSITE[] = $arIBlockSite["SITE_ID"];
         }
         if ($arIBlock["INDEX_ELEMENT"] == 'Y' && $strNSFilter2 !== false) {
             $strSql = "SELECT BE.ID, BE.NAME, BE.TAGS, " . "\t" . $DB->DateToCharFunction("BE.ACTIVE_FROM") . " as DATE_FROM, " . "\t" . $DB->DateToCharFunction("BE.ACTIVE_TO") . " as DATE_TO, " . "\t" . $DB->DateToCharFunction("BE.TIMESTAMP_X") . " as LAST_MODIFIED, " . "\tBE.PREVIEW_TEXT_TYPE, BE.PREVIEW_TEXT, " . "\tBE.DETAIL_TEXT_TYPE, BE.DETAIL_TEXT, " . "\tBE.XML_ID as EXTERNAL_ID, BE.CODE, " . "\tBE.IBLOCK_SECTION_ID " . "FROM b_iblock_element BE " . "WHERE BE.IBLOCK_ID=" . $IBLOCK_ID . " " . "\tAND BE.ACTIVE='Y' " . CIBlockElement::WF_GetSqlLimit("BE.", "N") . $strNSFilter2 . "ORDER BY BE.ID ";
             //For MySQL we have to solve client out of memory
             //problem by limiting the query
             if ($DB->type == "MYSQL") {
                 $limit = 1000;
                 $strSql .= " LIMIT " . $limit;
             } else {
                 $limit = false;
             }
             $dbrIBlockElement = $DB->Query($strSql);
             while ($arIBlockElement = $dbrIBlockElement->Fetch()) {
                 $DETAIL_URL = "=ID=" . $arIBlockElement["ID"] . "&EXTERNAL_ID=" . $arIBlockElement["EXTERNAL_ID"] . "&CODE=" . $arIBlockElement["CODE"] . "&IBLOCK_SECTION_ID=" . $arIBlockElement["IBLOCK_SECTION_ID"] . "&IBLOCK_TYPE_ID=" . $arIBlock["IBLOCK_TYPE_ID"] . "&IBLOCK_ID=" . $IBLOCK_ID . "&IBLOCK_CODE=" . $arIBlock["IBLOCK_CODE"] . "&IBLOCK_EXTERNAL_ID=" . $arIBlock["IBLOCK_EXTERNAL_ID"];
                 $BODY = ($arIBlockElement["PREVIEW_TEXT_TYPE"] == "html" ? CSearch::KillTags($arIBlockElement["PREVIEW_TEXT"]) : $arIBlockElement["PREVIEW_TEXT"]) . "\r\n" . ($arIBlockElement["DETAIL_TEXT_TYPE"] == "html" ? CSearch::KillTags($arIBlockElement["DETAIL_TEXT"]) : $arIBlockElement["DETAIL_TEXT"]);
                 $dbrProperties = CIBlockElement::GetProperty($IBLOCK_ID, $arIBlockElement["ID"], "sort", "asc", array("ACTIVE" => "Y", "SEARCHABLE" => "Y"));
                 while ($arProperties = $dbrProperties->Fetch()) {
                     $BODY .= "\r\n";
                     if (strlen($arProperties["USER_TYPE"]) > 0) {
                         $UserType = CIBlockProperty::GetUserType($arProperties["USER_TYPE"]);
                     } else {
                         $UserType = array();
                     }
                     if (array_key_exists("GetSearchContent", $UserType)) {
                         $BODY .= CSearch::KillTags(call_user_func_array($UserType["GetSearchContent"], array($arProperties['ID'], array("VALUE" => $arProperties["VALUE"]), array())));
                     } elseif (array_key_exists("GetPublicViewHTML", $UserType)) {
                         $BODY .= CSearch::KillTags(call_user_func_array($UserType["GetPublicViewHTML"], array($arProperties['ID'], array("VALUE" => $arProperties["VALUE"]), array())));
                     } elseif ($arProperties["PROPERTY_TYPE"] == 'L') {
                         $BODY .= $arProperties["VALUE_ENUM"];
                     } elseif ($arProperties["PROPERTY_TYPE"] == 'F') {
                         $arFile = CIBlockElement::__GetFileContent($arProperties["VALUE"]);
                         if (is_array($arFile)) {
                             $BODY .= $arFile["CONTENT"];
                             $arIBlockElement["TAGS"] .= "," . $arFile["PROPERTIES"][COption::GetOptionString("search", "page_tag_property")];
                         }
                     } else {
                         $BODY .= $arProperties["VALUE"];
                     }
                 }
                 if ($arIBlock["RIGHTS_MODE"] !== "E") {
                     $arPermissions = $arGroups;
                 } else {
                     $obElementRights = new CIBlockElementRights($IBLOCK_ID, $arIBlockElement["ID"]);
                     $arPermissions = $obElementRights->GetGroups(array("element_read"));
                 }
                 $Result = array("ID" => $arIBlockElement["ID"], "LAST_MODIFIED" => strlen($arIBlockElement["DATE_FROM"]) > 0 ? $arIBlockElement["DATE_FROM"] : $arIBlockElement["LAST_MODIFIED"], "TITLE" => $arIBlockElement["NAME"], "BODY" => $BODY, "TAGS" => $arIBlockElement["TAGS"], "SITE_ID" => $arSITE, "PARAM1" => $arIBlock["IBLOCK_TYPE_ID"], "PARAM2" => $IBLOCK_ID, "DATE_FROM" => strlen($arIBlockElement["DATE_FROM"]) > 0 ? $arIBlockElement["DATE_FROM"] : false, "DATE_TO" => strlen($arIBlockElement["DATE_TO"]) > 0 ? $arIBlockElement["DATE_TO"] : false, "PERMISSIONS" => $arPermissions, "URL" => $DETAIL_URL);
                 if ($oCallback) {
                     $res = call_user_func(array($oCallback, $callback_method), $Result);
                     if (!$res) {
                         return $IBLOCK_ID . "." . $arIBlockElement["ID"];
                     }
                 } else {
                     $arResult[] = $Result;
                 }
                 if ($limit !== false) {
                     $limit--;
                     if ($limit <= 0) {
                         return $IBLOCK_ID . "." . $arIBlockElement["ID"];
                     }
                 }
             }
         }
         if ($arIBlock["INDEX_SECTION"] == 'Y') {
             $strSql = "SELECT BS.ID, BS.NAME, " . "\t" . $DB->DateToCharFunction("BS.TIMESTAMP_X") . " as LAST_MODIFIED, " . "\tBS.DESCRIPTION_TYPE, BS.DESCRIPTION, BS.XML_ID as EXTERNAL_ID, BS.CODE, " . "\tBS.IBLOCK_ID " . "FROM b_iblock_section BS " . "WHERE BS.IBLOCK_ID=" . $IBLOCK_ID . " " . "\tAND BS.GLOBAL_ACTIVE='Y' " . $strNSFilter3 . "ORDER BY BS.ID ";
             $dbrIBlockSection = $DB->Query($strSql);
             while ($arIBlockSection = $dbrIBlockSection->Fetch()) {
                 $DETAIL_URL = "=ID=" . $arIBlockSection["ID"] . "&EXTERNAL_ID=" . $arIBlockSection["EXTERNAL_ID"] . "&CODE=" . $arIBlockSection["CODE"] . "&IBLOCK_TYPE_ID=" . $arIBlock["IBLOCK_TYPE_ID"] . "&IBLOCK_ID=" . $arIBlockSection["IBLOCK_ID"] . "&IBLOCK_CODE=" . $arIBlock["IBLOCK_CODE"] . "&IBLOCK_EXTERNAL_ID=" . $arIBlock["IBLOCK_EXTERNAL_ID"];
                 $BODY = $arIBlockSection["DESCRIPTION_TYPE"] == "html" ? CSearch::KillTags($arIBlockSection["DESCRIPTION"]) : $arIBlockSection["DESCRIPTION"];
                 $BODY .= $USER_FIELD_MANAGER->OnSearchIndex("IBLOCK_" . $arIBlockSection["IBLOCK_ID"] . "_SECTION", $arIBlockSection["ID"]);
                 if ($arIBlock["RIGHTS_MODE"] !== "E") {
                     $arPermissions = $arGroups;
                 } else {
                     $obSectionRights = new CIBlockSectionRights($IBLOCK_ID, $arIBlockSection["ID"]);
                     $arPermissions = $obSectionRights->GetGroups(array("section_read"));
                 }
                 $Result = array("ID" => "S" . $arIBlockSection["ID"], "LAST_MODIFIED" => $arIBlockSection["LAST_MODIFIED"], "TITLE" => $arIBlockSection["NAME"], "BODY" => $BODY, "SITE_ID" => $arSITE, "PARAM1" => $arIBlock["IBLOCK_TYPE_ID"], "PARAM2" => $IBLOCK_ID, "PERMISSIONS" => $arPermissions, "URL" => $DETAIL_URL);
                 if ($oCallback) {
                     $res = call_user_func(array($oCallback, $callback_method), $Result);
                     if (!$res) {
                         return $IBLOCK_ID . ".S" . $arIBlockSection["ID"];
                     }
                 } else {
                     $arResult[] = $Result;
                 }
             }
         }
         $strNSFilter2 = "";
         $strNSFilter3 = "";
     }
     if ($oCallback) {
         return false;
     }
     return $arResult;
 }
                }
                break;
            case "activate":
            case "deactivate":
                $ibp = new CIBlockProperty();
                $arFields = array("ACTIVE" => $_REQUEST['action'] == "activate" ? "Y" : "N");
                if (!$ibp->Update($ID, $arFields)) {
                    $lAdmin->AddUpdateError(GetMessage("IBP_ADM_SAVE_ERROR", array("#ID#" => $ID, "#ERROR_TEXT#" => $ibp->LAST_ERROR)), $ID);
                }
                break;
        }
    }
}
$arHeader = array(array("id" => "ID", "content" => GetMessage("IBP_ADM_ID"), "sort" => "ID", "align" => "right", "default" => true), array("id" => "NAME", "content" => GetMessage("IBP_ADM_NAME"), "sort" => "NAME", "default" => true), array("id" => "CODE", "content" => GetMessage("IBP_ADM_CODE"), "sort" => "CODE", "default" => true), array("id" => "PROPERTY_TYPE", "content" => GetMessage("IBP_ADM_PROPERTY_TYPE"), "sort" => "PROPERTY_TYPE", "default" => true), array("id" => "SORT", "content" => GetMessage("IBP_ADM_SORT"), "sort" => "SORT", "align" => "right", "default" => true), array("id" => "ACTIVE", "content" => GetMessage("IBP_ADM_ACTIVE"), "sort" => "ACTIVE", "align" => "center", "default" => true), array("id" => "IS_REQUIRED", "content" => GetMessage("IBP_ADM_IS_REQUIRED"), "sort" => "IS_REQUIRED", "align" => "center", "default" => true), array("id" => "MULTIPLE", "content" => GetMessage("IBP_ADM_MULTIPLE"), "sort" => "MULTIPLE", "align" => "center", "default" => true), array("id" => "SEARCHABLE", "content" => GetMessage("IBP_ADM_SEARCHABLE"), "sort" => "SEARCHABLE", "align" => "center", "default" => true), array("id" => "FILTRABLE", "content" => GetMessage("IBP_ADM_FILTRABLE"), "sort" => "FILTRABLE", "align" => "center"), array("id" => "XML_ID", "content" => GetMessage("IBP_ADM_XML_ID"), "sort" => "XML_ID"), array("id" => "WITH_DESCRIPTION", "content" => GetMessage("IBP_ADM_WITH_DESCRIPTION"), "sort" => "WITH_DESCRIPTION", "align" => "center"), array("id" => "HINT", "content" => GetMessage("IBP_ADM_HINT")));
$arPropType = array(Iblock\PropertyTable::TYPE_STRING => GetMessage("IBLOCK_PROP_S"), Iblock\PropertyTable::TYPE_NUMBER => GetMessage("IBLOCK_PROP_N"), Iblock\PropertyTable::TYPE_LIST => GetMessage("IBLOCK_PROP_L"), Iblock\PropertyTable::TYPE_FILE => GetMessage("IBLOCK_PROP_F"), Iblock\PropertyTable::TYPE_SECTION => GetMessage("IBLOCK_PROP_G"), Iblock\PropertyTable::TYPE_ELEMENT => GetMessage("IBLOCK_PROP_E"));
$arUserTypeList = CIBlockProperty::GetUserType();
Main\Type\Collection::sortByColumn($arUserTypeList, array('DESCRIPTION' => SORT_STRING));
foreach ($arUserTypeList as $arUserType) {
    $arPropType[$arUserType["PROPERTY_TYPE"] . ":" . $arUserType["USER_TYPE"]] = $arUserType["DESCRIPTION"];
}
$lAdmin->AddHeaders($arHeader);
$selectFields = array_fill_keys($lAdmin->GetVisibleHeaderColumns(), true);
$selectFields['ID'] = true;
$selectFieldsMap = array_fill_keys(array_keys($arHeader), false);
$selectFieldsMap = array_merge($selectFieldsMap, $selectFields);
if (!isset($by)) {
    $by = 'SORT';
}
if (!isset($order)) {
    $order = 'ASC';
}
Example #22
0
 public function GetDocumentFieldTypes($documentType)
 {
     $v = substr($documentType, strlen("type_"));
     if (intval($v) . "!" != $v . "!") {
         throw new CBPArgumentOutOfRangeException("documentType", $documentType);
     }
     $iblockId = intval($v);
     $typesMap = FieldType::getBaseTypesMap();
     $arResult = array("S" => array("Name" => GetMessage("BPVDX_STRING"), "BaseType" => "string", 'typeClass' => $typesMap[FieldType::STRING]), "T" => array("Name" => GetMessage("BPVDX_TEXT"), "BaseType" => "text", 'typeClass' => $typesMap[FieldType::TEXT]), "N" => array("Name" => GetMessage("BPVDX_NUM"), "BaseType" => "double", 'typeClass' => $typesMap[FieldType::DOUBLE]), "L" => array("Name" => GetMessage("BPVDX_LIST"), "BaseType" => "select", "Complex" => true, 'typeClass' => $typesMap[FieldType::SELECT]), "F" => array("Name" => GetMessage("BPVDX_FILE"), "BaseType" => "file", 'typeClass' => $typesMap[FieldType::FILE]), "B" => array("Name" => GetMessage("BPVDX_YN"), "BaseType" => "bool", 'typeClass' => $typesMap[FieldType::BOOL]));
     foreach (CIBlockProperty::GetUserType() as $ar) {
         $t = $ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"];
         if (COption::GetOptionString("bizproc", "SkipNonPublicCustomTypes", "N") == "Y" && !array_key_exists("GetPublicEditHTML", $ar) && $t != "S:UserID" && $t != "S:DateTime") {
             continue;
         }
         $arResult[$t] = array("Name" => $ar["DESCRIPTION"], "BaseType" => "string", 'typeClass' => '\\Bitrix\\Iblock\\BizprocType\\UserTypeProperty');
         if ($t == "S:UserID") {
             $arResult[$t]["BaseType"] = "user";
             $arResult[$t]['typeClass'] = $typesMap[FieldType::USER];
         } elseif ($t == "S:employee" && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y") {
             $arResult[$t]["BaseType"] = "user";
             $arResult[$t]['typeClass'] = '\\Bitrix\\Iblock\\BizprocType\\UserTypePropertyEmployee';
         } elseif ($t == "S:DateTime") {
             $arResult[$t]["BaseType"] = "datetime";
             $arResult[$t]["typeClass"] = $typesMap[FieldType::DATETIME];
         } elseif ($t == "S:Date") {
             $arResult[$t]["BaseType"] = "date";
             $arResult[$t]["typeClass"] = $typesMap[FieldType::DATE];
         } elseif ($t == "E:EList") {
             $arResult[$t]["BaseType"] = "string";
             $arResult[$t]["Complex"] = true;
             $arResult[$t]['typeClass'] = '\\Bitrix\\Iblock\\BizprocType\\UserTypePropertyElist';
         } elseif ($t == 'S:HTML') {
             $arResult[$t]['typeClass'] = '\\Bitrix\\Iblock\\BizprocType\\UserTypePropertyHtml';
         } elseif ($t == 'S:DiskFile') {
             $arResult[$t]["BaseType"] = "int";
             $arResult[$t]['typeClass'] = '\\Bitrix\\Iblock\\BizprocType\\UserTypePropertyDiskFile';
         }
     }
     return $arResult;
 }
Example #23
0
 private function getPropsList($iblockId, $skuPropertyId = 0)
 {
     $arResult = array();
     $dbrFProps = \CIBlockProperty::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "!XML_ID" => "CML2_LINK", "CHECK_PERMISSIONS" => "N"));
     while ($arProp = $dbrFProps->GetNext()) {
         if ($skuPropertyId == $arProp['ID']) {
             continue;
         }
         $arProp["PROPERTY_USER_TYPE"] = !empty($arProp["USER_TYPE"]) ? \CIBlockProperty::GetUserType($arProp["USER_TYPE"]) : array();
         $arResult[] = $arProp;
     }
     return $arResult;
 }
Example #24
0
 /**
  * <p>Метод изменяет параметры свойства с кодом <i>ID</i>. Перед изменением параметров вызываются обработчики события <a href="http://dev.1c-bitrix.ru/api_help/iblock/events/onbeforeiblockpropertyupdate.php">OnBeforeIBlockPropertyUpdate</a> из которых можно отменить изменения или переопределить поля. А после изменения параметром вызывается событие <a href="http://dev.1c-bitrix.ru/api_help/iblock/events/onafteriblockpropertyupdate.php">OnAfterIBlockPropertyUpdate</a>. Метод динамичный.</p>
  *
  *
  * @param int $ID  ID изменяемой записи. </htm
  *
  * @param array $arFields  Массив Array("поле"=&gt;"значение", ...). Содержит значения <a
  * href="http://dev.1c-bitrix.ru/api_help/iblock/fields.php#fproperty">всех полей</a> изменяемого
  * свойства. Кроме того, с помощью поля "VALUES", значением которого
  * должен быть массив вида Array(Array("VALUE"=&gt;"значение", "DEF"=&gt;"по
  * умолчанию (Y/N)", "SORT"=&gt;"индекс сортировки"),...), можно установить
  * варианты выбора для свойств типа "список" (подробнее смотрите
  * метод <a href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockproperty/index.php">CIBlockProperty</a>::<a
  * href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockproperty/updateenum.php">UpdateEnum()</a>).
  *
  * @return bool 
  *
  * <h4>Example</h4> 
  * <pre>
  * &lt;?<br>$arFields = Array(<br>  "NAME" =&gt; "Цвет",<br>  "ACTIVE" =&gt; "Y",<br>  "SORT" =&gt; "100",<br>  "CODE" =&gt; "color",<br>  "PROPERTY_TYPE" =&gt; "L",<br>  "IBLOCK_ID" =&gt; 11<br>  );<br><br>$arFields["VALUES"][0] = Array(<br>  "VALUE" =&gt; "Красный",<br>  "DEF" =&gt; "N",<br>  "SORT" =&gt; "100"<br>}<br><br>$arFields["VALUES"][1] = Array(<br>  "VALUE" =&gt; "Желтый",<br>  "DEF" =&gt; "N",<br>  "SORT" =&gt; "200"<br>}<br><br>$arFields["VALUES"][2] = Array(<br>  "VALUE" =&gt; "Зеленый",<br>  "DEF" =&gt; "Y",<br>  "SORT" =&gt; "300"<br>}<br><br>$ibp = new CIBlockProperty;<br>if(!$ibp-&gt;Update($ID, $arFields))<br>	echo $ibp-&gt;LAST_ERROR;<br>?
  * 
  * В случае обновления информации в пользовательском типе свойства для сохранения ключа USER_TYPE_SETTINGS необходимо указать еще ключ USER_TYPE с реальным значением. В противном случае ключ USER_TYPE_SETTINGS не обновится. Неверными будут следующие варианты:
  * 
  * 
  * $arFields = array(
  *    'PROPERTY_TYPE' =&gt; 'E',
  *    'USER_TYPE_SETTINGS' =&gt; array(
  *       'WIDTH' =&gt; '10',
  *       'HEIGHT' =&gt; '10',
  *    ),
  * );
  * $ibp = new CIBlockProperty();
  * $ibp-&gt;Update($ID, $arFields));
  * 
  * $arFields = array(
  *    'PROPERTY_TYPE' =&gt; 'E',
  *    'USER_TYPE_SETTINGS' =&gt; array(
  *       'WIDTH' =&gt; '10',
  *       'HEIGHT' =&gt; '10',
  *    ),
  *    'USER_TYPE' =&gt; '',
  * );
  * $ibp = new CIBlockProperty();
  * $ibp-&gt;Update($ID, $arFields));
  * 
  * $arFields = array(
  *    'PROPERTY_TYPE' =&gt; 'E',
  *    'USER_TYPE_SETTINGS' =&gt; array(
  *       'WIDTH' =&gt; '10',
  *       'HEIGHT' =&gt; '10',
  *    ),
  *    'USER_TYPE' =&gt; 'xxx'
  * );
  * $ibp = new CIBlockProperty();
  * $ibp-&gt;Update($ID, $arFields));
  * 
  * //включить индексацию свойства для поиска
  *  $arFields = Array(
  *      'SEARCHABLE'=&gt;'Y'
  * );
  * $ibp = new CIBlockProperty;
  * if(!$ibp-&gt;Update($prop['ID'], $arFields))
  *      echo $ibp-&gt;LAST_ERROR;
  * 
  * 
  * 
  * // добавление свойства в умный фильтр: 
  * $arFields = Array('SMART_FILTER' =&gt; 'Y', 'IBLOCK_ID' =&gt; 123);
  * $ibp = new CIBlockProperty();
  * if(!$ibp-&gt;Update($prop['ID'], $arFields))
  * echo $ibp-&gt;LAST_ERROR; 
  * 
  * //IBLOCK_ID в arFields указывать обязательно, иначе свойство не будет включено в умный фильтр, и при этом не выдаст ошибки.
  * //Чтобы исключить свойство из умного фильтра в arFileds заменить:  'SMART_FILTER'=&gt;'N'
  * </pre>
  *
  *
  * <h4>See Also</h4> 
  * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockproperty/add.php">CIBlockProperty::Add</a>
  * </li> <li><a href="http://dev.1c-bitrix.ru/api_help/iblock/fields.php#fproperty">Поля свойства</a></li>
  * <li><a
  * href="http://dev.1c-bitrix.ru/api_help/iblock/events/onbeforeiblockpropertyupdate.php">OnBeforeIBlockPropertyUpdate</a></li>
  * <li><a
  * href="http://dev.1c-bitrix.ru/api_help/iblock/events/onafteriblockpropertyupdate.php">OnAfterIBlockPropertyUpdate</a></li>
  * </ul> <br><p><b>Примечание:</b> если используются <b>Инфоблоки 2.0</b> и
  * изменяется базовый тип свойства, то все текущие значения свойств
  * у существующих элементов очищаются.</p> <br><a name="examples"></a>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockproperty/update.php
  * @author Bitrix
  */
 public function Update($ID, $arFields, $bCheckDescription = false)
 {
     global $DB;
     $ID = IntVal($ID);
     if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") {
         $arFields["ACTIVE"] = "N";
     }
     if (is_set($arFields, "SEARCHABLE") && $arFields["SEARCHABLE"] != "Y") {
         $arFields["SEARCHABLE"] = "N";
     }
     if (is_set($arFields, "FILTRABLE") && $arFields["FILTRABLE"] != "Y") {
         $arFields["FILTRABLE"] = "N";
     }
     if (is_set($arFields, "MULTIPLE") && $arFields["MULTIPLE"] != "Y") {
         $arFields["MULTIPLE"] = "N";
     }
     if (is_set($arFields, "LIST_TYPE") && $arFields["LIST_TYPE"] != "C") {
         $arFields["LIST_TYPE"] = "L";
     }
     if (!$this->CheckFields($arFields, $ID)) {
         $Result = false;
         $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR;
     } elseif (!$this->_Update($ID, $arFields, $bCheckDescription)) {
         $Result = false;
         $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR;
     } else {
         if (isset($arFields["USER_TYPE"])) {
             $arUserType = CIBlockProperty::GetUserType($arFields["USER_TYPE"]);
             if (array_key_exists("ConvertToDB", $arUserType)) {
                 $arValue = array("VALUE" => $arFields["DEFAULT_VALUE"]);
                 $arValue = call_user_func_array($arUserType["ConvertToDB"], array($arFields, $arValue));
                 if (is_array($arValue) && isset($arValue["VALUE"]) && strlen($arValue["VALUE"])) {
                     $arFields["DEFAULT_VALUE"] = $arValue["VALUE"];
                 } else {
                     $arFields["DEFAULT_VALUE"] = false;
                 }
             }
             if (array_key_exists("PrepareSettings", $arUserType)) {
                 $arFieldsResult = call_user_func_array($arUserType["PrepareSettings"], array($arFields));
                 if (is_array($arFieldsResult) && array_key_exists('USER_TYPE_SETTINGS', $arFieldsResult)) {
                     $arFields = array_merge($arFields, $arFieldsResult);
                     $arFields["USER_TYPE_SETTINGS"] = serialize($arFields["USER_TYPE_SETTINGS"]);
                 } else {
                     $arFields["USER_TYPE_SETTINGS"] = serialize($arFieldsResult);
                 }
             } else {
                 $arFields["USER_TYPE_SETTINGS"] = false;
             }
         }
         unset($arFields["ID"]);
         unset($arFields["VERSION"]);
         unset($arFields["TIMESTAMP_X"]);
         $strUpdate = $DB->PrepareUpdate("b_iblock_property", $arFields);
         if (strlen($strUpdate) > 0) {
             $strSql = "UPDATE b_iblock_property SET " . $strUpdate . " WHERE ID=" . $ID;
             $DB->QueryBind($strSql, array("USER_TYPE_SETTINGS" => $arFields["USER_TYPE_SETTINGS"]));
         }
         if (is_set($arFields, "VALUES")) {
             $this->UpdateEnum($ID, $arFields["VALUES"]);
         }
         if (array_key_exists("IBLOCK_ID", $arFields) && CIBlock::GetArrayByID($arFields["IBLOCK_ID"], "SECTION_PROPERTY") === "Y") {
             if (!array_key_exists("SECTION_PROPERTY", $arFields) || $arFields["SECTION_PROPERTY"] !== "N") {
                 $arLink = array("SMART_FILTER" => $arFields["SMART_FILTER"]);
                 if (array_key_exists("DISPLAY_TYPE", $arFields)) {
                     $arLink["DISPLAY_TYPE"] = $arFields["DISPLAY_TYPE"];
                 }
                 if (array_key_exists("DISPLAY_EXPANDED", $arFields)) {
                     $arLink["DISPLAY_EXPANDED"] = $arFields["DISPLAY_EXPANDED"];
                 }
                 if (array_key_exists("FILTER_HINT", $arFields)) {
                     $arLink["FILTER_HINT"] = $arFields["FILTER_HINT"];
                 }
                 CIBlockSectionPropertyLink::Set(0, $ID, $arLink);
             } else {
                 CIBlockSectionPropertyLink::Delete(0, $ID);
             }
         }
         global $BX_IBLOCK_PROP_CACHE;
         if (is_set($arFields, "IBLOCK_ID")) {
             unset($BX_IBLOCK_PROP_CACHE[$arFields["IBLOCK_ID"]]);
         } else {
             $BX_IBLOCK_PROP_CACHE = array();
         }
         $Result = true;
     }
     $arFields["ID"] = $ID;
     $arFields["RESULT"] =& $Result;
     foreach (GetModuleEvents("iblock", "OnAfterIBlockPropertyUpdate", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$arFields));
     }
     return $Result;
 }
Example #25
0
	if($f_TYPE=="E" && count($arSelectedProps)>0)
	{
		$rsProperties = CIBlockElement::GetProperty($IBLOCK_ID, $arRes["ID"]);
		while($ar = $rsProperties->GetNext())
		{
			if(!array_key_exists($ar["ID"], $arProperties))
				$arProperties[$ar["ID"]] = array();
			$arProperties[$ar["ID"]][$ar["PROPERTY_VALUE_ID"]] = $ar;
		}

		foreach($arSelectedProps as $aProp)
		{
			$arViewHTML = array();
			$arEditHTML = array();
			if(strlen($aProp["USER_TYPE"])>0)
				$arUserType = CIBlockProperty::GetUserType($aProp["USER_TYPE"]);
			else
				$arUserType = array();
			$max_file_size_show=100000;

			$last_property_id = false;
			foreach($arProperties[$aProp["ID"]] as $prop_id => $prop)
			{
				$prop['PROPERTY_VALUE_ID'] = intval($prop['PROPERTY_VALUE_ID']);
				$VALUE_NAME = 'FIELDS['.$f_TYPE.$f_ID.'][PROPERTY_'.$prop['ID'].']['.$prop['PROPERTY_VALUE_ID'].'][VALUE]';
				$DESCR_NAME = 'FIELDS['.$f_TYPE.$f_ID.'][PROPERTY_'.$prop['ID'].']['.$prop['PROPERTY_VALUE_ID'].'][DESCRIPTION]';
				//View part
				if(array_key_exists("GetAdminListViewHTML", $arUserType))
				{
					$arViewHTML[] = call_user_func_array($arUserType["GetAdminListViewHTML"],
						array(
 public function GetDocumentFieldTypes($documentType)
 {
     if ($storage = self::needProxyToDiskByDocType($documentType)) {
         return self::proxyToDisk(__FUNCTION__, array(\Bitrix\Disk\BizProcDocumentCompatible::generateDocumentType($storage->getId())));
     }
     $arResult = array("string" => array("Name" => GetMessage("BPCGHLP_PROP_STRING"), "BaseType" => "string"), "text" => array("Name" => GetMessage("BPCGHLP_PROP_TEXT"), "BaseType" => "text"), "int" => array("Name" => GetMessage("BPCGHLP_PROP_INT"), "BaseType" => "int"), "double" => array("Name" => GetMessage("BPCGHLP_PROP_DOUBLE"), "BaseType" => "double"), "select" => array("Name" => GetMessage("BPCGHLP_PROP_SELECT"), "BaseType" => "select", "Complex" => true), "bool" => array("Name" => GetMessage("BPCGHLP_PROP_BOOL"), "BaseType" => "bool"), "date" => array("Name" => GetMessage("BPCGHLP_PROP_DATA"), "BaseType" => "date"), "datetime" => array("Name" => GetMessage("BPCGHLP_PROP_DATETIME"), "BaseType" => "datetime"), "user" => array("Name" => GetMessage("BPCGHLP_PROP_USER"), "BaseType" => "user"));
     foreach (CIBlockProperty::GetUserType() as $ar) {
         $t = $ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"];
         if (!array_key_exists("GetPublicEditHTML", $ar) || $t == "S:UserID" || $t == "S:DateTime") {
             continue;
         }
         $arResult[$t] = array("Name" => $ar["DESCRIPTION"], "BaseType" => "string");
     }
     return $arResult;
 }
Example #27
0
 public function GetArray()
 {
     if (is_array($this->_property)) {
         return array("SORT" => $this->_sort, "NAME" => $this->_property["NAME"], "IS_REQUIRED" => $this->_property["IS_REQUIRED"], "MULTIPLE" => $this->_property["MULTIPLE"], "DEFAULT_VALUE" => $this->_property["DEFAULT_VALUE"], "TYPE" => $this->GetTypeID(), "PROPERTY_TYPE" => $this->_property["PROPERTY_TYPE"], "PROPERTY_USER_TYPE" => $this->_property["USER_TYPE"] ? CIBlockProperty::GetUserType($this->_property["USER_TYPE"]) : false, "CODE" => $this->_property["CODE"], "ID" => $this->_property["ID"], "LINK_IBLOCK_ID" => $this->_property["LINK_IBLOCK_ID"], "USER_TYPE_SETTINGS" => $this->_property["USER_TYPE_SETTINGS"]);
     } else {
         return false;
     }
 }
Example #28
0
function _ShowUserPropertyField($name, $property_fields, $values, $bInitDef = false, $bVarsFromForm = false, $max_file_size_show = 50000, $form_name = "form_element", $bCopy = false)
{
    global $bCopy;
    $start = 0;
    if (!is_array($property_fields["~VALUE"])) {
        $values = array();
    } else {
        $values = $property_fields["~VALUE"];
    }
    unset($property_fields["VALUE"]);
    unset($property_fields["~VALUE"]);
    $html = '<table cellpadding="0" cellspacing="0" border="0" class="nopadding" width="100%" id="tb' . md5($name) . '">';
    $arUserType = CIBlockProperty::GetUserType($property_fields["USER_TYPE"]);
    $bMultiple = $property_fields["MULTIPLE"] == "Y" && array_key_exists("GetPropertyFieldHtmlMulty", $arUserType);
    $max_val = -1;
    if ($arUserType["PROPERTY_TYPE"] !== "F" || !$bCopy) {
        if ($bMultiple) {
            $html .= '<tr><td>';
            $html .= call_user_func_array($arUserType["GetPropertyFieldHtmlMulty"], array($property_fields, $values, array("VALUE" => 'PROP[' . $property_fields["ID"] . ']', "FORM_NAME" => $form_name, "MODE" => "FORM_FILL", "COPY" => $bCopy)));
            $html .= '</td></tr>';
        } else {
            foreach ($values as $key => $val) {
                if ($bCopy) {
                    $key = "n" . $start;
                    $start++;
                }
                if (!is_array($val) || !array_key_exists("VALUE", $val)) {
                    $val = array("VALUE" => $val, "DESCRIPTION" => "");
                }
                $html .= '<tr><td>';
                if (array_key_exists("GetPropertyFieldHtml", $arUserType)) {
                    $html .= call_user_func_array($arUserType["GetPropertyFieldHtml"], array($property_fields, $val, array("VALUE" => 'PROP[' . $property_fields["ID"] . '][' . $key . '][VALUE]', "DESCRIPTION" => 'PROP[' . $property_fields["ID"] . '][' . $key . '][DESCRIPTION]', "FORM_NAME" => $form_name, "MODE" => "FORM_FILL", "COPY" => $bCopy)));
                } else {
                    $html .= '&nbsp;';
                }
                $html .= '</td></tr>';
                if (substr($key, -1, 1) == 'n' && $max_val < intval(substr($key, 1))) {
                    $max_val = intval(substr($key, 1));
                }
                if ($property_fields["MULTIPLE"] != "Y") {
                    $bVarsFromForm = true;
                    break;
                }
            }
        }
    }
    if (!$bVarsFromForm && !$bMultiple) {
        $bDefaultValue = is_array($property_fields["DEFAULT_VALUE"]) || strlen($property_fields["DEFAULT_VALUE"]);
        if ($property_fields["MULTIPLE"] == "Y") {
            $cnt = IntVal($property_fields["MULTIPLE_CNT"]);
            if ($cnt <= 0 || $cnt > 30) {
                $cnt = 5;
            }
            if ($bInitDef && $bDefaultValue) {
                $cnt++;
            }
        } else {
            $cnt = 1;
        }
        for ($i = $max_val + 1; $i < $max_val + 1 + $cnt; $i++) {
            if ($i == 0 && $bInitDef && $bDefaultValue) {
                $val = array("VALUE" => $property_fields["DEFAULT_VALUE"], "DESCRIPTION" => "");
            } else {
                $val = array("VALUE" => "", "DESCRIPTION" => "");
            }
            $key = "n" . ($start + $i);
            $html .= '<tr><td>';
            if (array_key_exists("GetPropertyFieldHtml", $arUserType)) {
                $html .= call_user_func_array($arUserType["GetPropertyFieldHtml"], array($property_fields, $val, array("VALUE" => 'PROP[' . $property_fields["ID"] . '][' . $key . '][VALUE]', "DESCRIPTION" => 'PROP[' . $property_fields["ID"] . '][' . $key . '][DESCRIPTION]', "FORM_NAME" => $form_name, "MODE" => "FORM_FILL", "COPY" => $bCopy)));
            } else {
                $html .= '&nbsp;';
            }
            $html .= '</td></tr>';
        }
        $max_val += $cnt;
    }
    if ($property_fields["MULTIPLE"] == "Y" && $arUserType["USER_TYPE"] !== "HTML" && $arUserType["USER_TYPE"] !== "employee" && !$bMultiple) {
        $html .= '<tr><td><input type="button" value="' . GetMessage("IBLOCK_AT_PROP_ADD") . '" onClick="addNewRow(\'tb' . md5($name) . '\')"></td></tr>';
    }
    $html .= '</table>';
    echo $html;
}
    foreach ($PARAMS as $key => $value) {
        if ('TITLE' != $key) {
            ?>
<input type="hidden" name="PARAMS[<?php 
            echo htmlspecialcharsbx($key);
            ?>
]" value="<?php 
            echo htmlspecialcharsbx($value);
            ?>
"><?php 
        }
    }
    ?>
		<table class="edit-table" width="100%"><tbody><?php 
    $arProperty['USER_TYPE'] = trim($arProperty['USER_TYPE']);
    $arUserType = '' != $arProperty['USER_TYPE'] ? CIBlockProperty::GetUserType($arProperty['USER_TYPE']) : array();
    $arPropertyFields = array();
    $USER_TYPE_SETTINGS_HTML = "";
    if (isset($arUserType["GetSettingsHTML"])) {
        $USER_TYPE_SETTINGS_HTML = call_user_func_array($arUserType["GetSettingsHTML"], array($arProperty, array("NAME" => "PROPERTY_USER_TYPE_SETTINGS"), &$arPropertyFields));
    }
    ?>
<input type="hidden" id="PROPERTY_PROPERTY_TYPE" name="PROPERTY_PROPERTY_TYPE" value="<?php 
    echo htmlspecialcharsbx($arProperty['PROPERTY_TYPE'] . ($arProperty['USER_TYPE'] ? ':' . $arProperty['USER_TYPE'] : ''));
    ?>
">
		<tr>
			<td width="40%">ID:</td>
			<td width="60%"><?php 
    echo 0 < intval($arProperty['ID']) ? $arProperty['ID'] : GetMessage("BT_ADM_IEP_PROP_NEW");
    ?>
Example #30
0
 function __construct($key, $property)
 {
     parent::__construct($key);
     if (is_array($property)) {
         $this->property = $property;
         if (strlen($property["USER_TYPE"])) {
             $propertyUserType = \CIBlockProperty::GetUserType($property["USER_TYPE"]);
             if (array_key_exists("GetPublicViewHTML", $propertyUserType) && is_callable($propertyUserType["GetPublicViewHTML"])) {
                 $this->propertyFormatFunction = $propertyUserType["GetPublicViewHTML"];
             }
         }
     }
 }