/** * Запускает событие по атрибутам модели * @param string $eventName * @return bool */ public function riseEvent($eventName) { if ($eventName == 'afterSave') { $val = $this->getValue(); if (!empty($val)) { $current = is_array($val) ? array_map('intval', $val) : array(intval($val)); } else { $current = array(); } sort($current); $inDb = $this->getSectionsId(); if ($inDb !== $current) { if (!\CModule::IncludeModule('iblock')) { throw new \bxar\Exception('Iblock module is not installed'); } \CIBlockElement::SetElementSection($this->getModel()->getAttribute('id')->getValue(), !empty($current) ? $current : null); } $this->_sections = null; } }
function Update($ID, $arFields, $bWorkFlow = false, $bUpdateSearch = true, $bResizePictures = false, $bCheckDiskQuota = true) { global $DB, $USER; $ID = intval($ID); $db_element = CIBlockElement::GetList(array(), array("ID" => $ID, "SHOW_HISTORY" => "Y"), false, false, array("ID", "TIMESTAMP_X", "MODIFIED_BY", "DATE_CREATE", "CREATED_BY", "IBLOCK_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "SORT", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_TEXT", "DETAIL_TEXT_TYPE", "WF_STATUS_ID", "WF_PARENT_ELEMENT_ID", "WF_NEW", "WF_COMMENTS", "IN_SECTIONS", "CODE", "TAGS", "XML_ID", "TMP_ID")); if (!($ar_element = $db_element->Fetch())) { return false; } $arIBlock = CIBlock::GetArrayByID($ar_element["IBLOCK_ID"]); $bWorkFlow = $bWorkFlow && is_array($arIBlock) && $arIBlock["WORKFLOW"] != "N" && CModule::IncludeModule("workflow"); $ar_wf_element = $ar_element; $LAST_ID = 0; if ($bWorkFlow) { $LAST_ID = CIBlockElement::WF_GetLast($ID); if ($LAST_ID != $ID) { $db_element = CIBlockElement::GetByID($LAST_ID); if (!($ar_wf_element = $db_element->Fetch())) { return false; } } $arFields["WF_PARENT_ELEMENT_ID"] = $ID; if (!array_key_exists("PROPERTY_VALUES", $arFields) || !is_array($arFields["PROPERTY_VALUES"])) { $arFields["PROPERTY_VALUES"] = array(); } $bFieldProps = array(); foreach ($arFields["PROPERTY_VALUES"] as $k => $v) { $bFieldProps[$k] = true; } $arFieldProps =& $arFields['PROPERTY_VALUES']; $props = CIBlockElement::GetProperty($ar_element["IBLOCK_ID"], $ar_wf_element["ID"]); while ($arProp = $props->Fetch()) { $pr_val_id = $arProp['PROPERTY_VALUE_ID']; if ($arProp['PROPERTY_TYPE'] == 'F' && strlen($pr_val_id) > 0) { if (strlen($arProp["CODE"]) > 0 && is_set($arFieldProps, $arProp["CODE"])) { $pr_id = $arProp["CODE"]; } else { $pr_id = $arProp['ID']; } if (array_key_exists($pr_id, $arFieldProps) && array_key_exists($pr_val_id, $arFieldProps[$pr_id]) && is_array($arFieldProps[$pr_id][$pr_val_id])) { $new_value = $arFieldProps[$pr_id][$pr_val_id]; if (strlen($new_value['name']) <= 0 && $new_value['del'] != "Y" && strlen($new_value['VALUE']['name']) <= 0 && $new_value['VALUE']['del'] != "Y") { if (array_key_exists('DESCRIPTION', $new_value) && $new_value['DESCRIPTION'] != $arProp['DESCRIPTION']) { $p = array("VALUE" => CFile::MakeFileArray($arProp['VALUE'])); $p["DESCRIPTION"] = $new_value["DESCRIPTION"]; $p["MODULE_ID"] = "iblock"; $arFieldProps[$pr_id][$pr_val_id] = $p; } elseif ($arProp['VALUE'] > 0) { $arFieldProps[$pr_id][$pr_val_id] = array("VALUE" => $arProp['VALUE'], "DESCRIPTION" => $arProp["DESCRIPTION"]); } } } else { $arFieldProps[$pr_id][$pr_val_id] = array("VALUE" => $arProp['VALUE'], "DESCRIPTION" => $arProp["DESCRIPTION"]); } continue; } if (strlen($pr_val_id) <= 0 || array_key_exists($arProp["ID"], $bFieldProps) || strlen($arProp["CODE"]) > 0 && array_key_exists($arProp["CODE"], $bFieldProps)) { continue; } $arFieldProps[$arProp["ID"]][$pr_val_id] = array("VALUE" => $arProp['VALUE'], "DESCRIPTION" => $arProp["DESCRIPTION"]); } if ($ar_wf_element["IN_SECTIONS"] == "Y") { $ar_wf_element["IBLOCK_SECTION"] = array(); $rsSections = CIBlockElement::GetElementGroups($ar_element["ID"], true, array('ID', 'IBLOCK_ELEMENT_ID')); while ($arSection = $rsSections->Fetch()) { $ar_wf_element["IBLOCK_SECTION"][] = $arSection["ID"]; } } unset($ar_wf_element["DATE_ACTIVE_FROM"]); unset($ar_wf_element["DATE_ACTIVE_TO"]); unset($ar_wf_element["EXTERNAL_ID"]); unset($ar_wf_element["TIMESTAMP_X"]); unset($ar_wf_element["ID"]); $arFields = $arFields + $ar_wf_element; } $arFields["WF"] = $bWorkFlow ? "Y" : "N"; $bBizProc = is_array($arIBlock) && $arIBlock["BIZPROC"] == "Y" && IsModuleInstalled("bizproc"); if (array_key_exists("BP_PUBLISHED", $arFields)) { if ($bBizProc) { if ($arFields["BP_PUBLISHED"] == "Y") { $arFields["WF_STATUS_ID"] = 1; $arFields["WF_NEW"] = false; } else { $arFields["WF_STATUS_ID"] = 2; $arFields["WF_NEW"] = "Y"; $arFields["BP_PUBLISHED"] = "N"; } } else { $arFields["WF_NEW"] = false; unset($arFields["BP_PUBLISHED"]); } } else { $arFields["WF_NEW"] = false; } if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") { $arFields["ACTIVE"] = "N"; } if (is_set($arFields, "PREVIEW_TEXT_TYPE") && $arFields["PREVIEW_TEXT_TYPE"] != "html") { $arFields["PREVIEW_TEXT_TYPE"] = "text"; } if (is_set($arFields, "DETAIL_TEXT_TYPE") && $arFields["DETAIL_TEXT_TYPE"] != "html") { $arFields["DETAIL_TEXT_TYPE"] = "text"; } $strWarning = ""; if ($bResizePictures) { $arDef = $arIBlock["FIELDS"]["PREVIEW_PICTURE"]["DEFAULT_VALUE"]; if ($arDef["DELETE_WITH_DETAIL"] === "Y" && $arFields["DETAIL_PICTURE"]["del"] === "Y") { $arFields["PREVIEW_PICTURE"]["del"] = "Y"; } if ($arDef["FROM_DETAIL"] === "Y" && ($arFields["PREVIEW_PICTURE"]["size"] <= 0 || $arDef["UPDATE_WITH_DETAIL"] === "Y") && is_array($arFields["DETAIL_PICTURE"]) && $arFields["DETAIL_PICTURE"]["size"] > 0) { if ($arFields["PREVIEW_PICTURE"]["del"] !== "Y" && $arDef["UPDATE_WITH_DETAIL"] !== "Y") { $rsElement = CIBlockElement::GetList(array("ID" => "DESC"), array("ID" => $ar_wf_element["ID"], "IBLOCK_ID" => $ar_wf_element["IBLOCK_ID"], "SHOW_HISTORY" => "Y"), false, false, array("ID", "PREVIEW_PICTURE")); $arOldElement = $rsElement->Fetch(); } else { $arOldElement = false; } if (!$arOldElement || !$arOldElement["PREVIEW_PICTURE"]) { $arNewPreview = $arFields["DETAIL_PICTURE"]; $arNewPreview["COPY_FILE"] = "Y"; $arNewPreview["description"] = $arFields["PREVIEW_PICTURE"]["description"]; $arFields["PREVIEW_PICTURE"] = $arNewPreview; } } if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arFields["PREVIEW_PICTURE"]["size"] > 0 && $arDef["SCALE"] === "Y") { $arNewPicture = CIBlock::ResizePicture($arFields["PREVIEW_PICTURE"], $arDef); if (is_array($arNewPicture)) { $arNewPicture["description"] = $arFields["PREVIEW_PICTURE"]["description"]; $arFields["PREVIEW_PICTURE"] = $arNewPicture; } elseif ($arDef["IGNORE_ERRORS"] !== "Y") { unset($arFields["PREVIEW_PICTURE"]); $strWarning .= GetMessage("IBLOCK_FIELD_PREVIEW_PICTURE") . ": " . $arNewPicture . "<br>"; } } if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arDef["USE_WATERMARK_FILE"] === "Y") { if (strlen($arFields["PREVIEW_PICTURE"]["tmp_name"]) > 0 && ($arFields["PREVIEW_PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"] || $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PREVIEW_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["PREVIEW_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["PREVIEW_PICTURE"]["tmp_name"], $tmp_name); $arFields["PREVIEW_PICTURE"]["copy"] = true; $arFields["PREVIEW_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["PREVIEW_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_FILE_POSITION"], "type" => "file", "size" => "real", "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100), "file" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_FILE"]))); } if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arDef["USE_WATERMARK_TEXT"] === "Y") { if (strlen($arFields["PREVIEW_PICTURE"]["tmp_name"]) > 0 && ($arFields["PREVIEW_PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"] || $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PREVIEW_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["PREVIEW_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["PREVIEW_PICTURE"]["tmp_name"], $tmp_name); $arFields["PREVIEW_PICTURE"]["copy"] = true; $arFields["PREVIEW_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["PREVIEW_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_TEXT_POSITION"], "type" => "text", "coefficient" => $arDef["WATERMARK_TEXT_SIZE"], "text" => $arDef["WATERMARK_TEXT"], "font" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]), "color" => $arDef["WATERMARK_TEXT_COLOR"])); } $arDef = $arIBlock["FIELDS"]["DETAIL_PICTURE"]["DEFAULT_VALUE"]; if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["SCALE"] === "Y") { $arNewPicture = CIBlock::ResizePicture($arFields["DETAIL_PICTURE"], $arDef); if (is_array($arNewPicture)) { $arNewPicture["description"] = $arFields["DETAIL_PICTURE"]["description"]; $arFields["DETAIL_PICTURE"] = $arNewPicture; } elseif ($arDef["IGNORE_ERRORS"] !== "Y") { unset($arFields["DETAIL_PICTURE"]); $strWarning .= GetMessage("IBLOCK_FIELD_DETAIL_PICTURE") . ": " . $arNewPicture . "<br>"; } } if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["USE_WATERMARK_FILE"] === "Y") { if (strlen($arFields["DETAIL_PICTURE"]["tmp_name"]) > 0 && ($arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PREVIEW_PICTURE"]["tmp_name"] || $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name); $arFields["DETAIL_PICTURE"]["copy"] = true; $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_FILE_POSITION"], "type" => "file", "size" => "real", "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100), "file" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_FILE"]))); } if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["USE_WATERMARK_TEXT"] === "Y") { if (strlen($arFields["DETAIL_PICTURE"]["tmp_name"]) > 0 && ($arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PREVIEW_PICTURE"]["tmp_name"] || $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name); $arFields["DETAIL_PICTURE"]["copy"] = true; $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_TEXT_POSITION"], "type" => "text", "coefficient" => $arDef["WATERMARK_TEXT_SIZE"], "text" => $arDef["WATERMARK_TEXT"], "font" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]), "color" => $arDef["WATERMARK_TEXT_COLOR"])); } } $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($ar_element["IBLOCK_ID"], $ar_element["ID"]); if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"])) { if (strlen($arFields["PREVIEW_PICTURE"]["name"]) <= 0 && strlen($arFields["PREVIEW_PICTURE"]["del"]) <= 0 && !is_set($arFields["PREVIEW_PICTURE"], "description")) { unset($arFields["PREVIEW_PICTURE"]); } else { $arFields["PREVIEW_PICTURE"]["MODULE_ID"] = "iblock"; $arFields["PREVIEW_PICTURE"]["old_file"] = $ar_wf_element["PREVIEW_PICTURE"]; $arFields["PREVIEW_PICTURE"]["name"] = \Bitrix\Iblock\Template\Helper::makeFileName($ipropTemplates, "ELEMENT_PREVIEW_PICTURE_FILE_NAME", array_merge($ar_element, $arFields), $arFields["PREVIEW_PICTURE"]); } } if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"])) { if (strlen($arFields["DETAIL_PICTURE"]["name"]) <= 0 && strlen($arFields["DETAIL_PICTURE"]["del"]) <= 0 && !is_set($arFields["DETAIL_PICTURE"], "description")) { unset($arFields["DETAIL_PICTURE"]); } else { $arFields["DETAIL_PICTURE"]["MODULE_ID"] = "iblock"; $arFields["DETAIL_PICTURE"]["old_file"] = $ar_wf_element["DETAIL_PICTURE"]; $arFields["DETAIL_PICTURE"]["name"] = \Bitrix\Iblock\Template\Helper::makeFileName($ipropTemplates, "ELEMENT_DETAIL_PICTURE_FILE_NAME", array_merge($ar_element, $arFields), $arFields["DETAIL_PICTURE"]); } } if (is_set($arFields, "DATE_ACTIVE_FROM")) { $arFields["ACTIVE_FROM"] = $arFields["DATE_ACTIVE_FROM"]; } if (is_set($arFields, "DATE_ACTIVE_TO")) { $arFields["ACTIVE_TO"] = $arFields["DATE_ACTIVE_TO"]; } if (is_set($arFields, "EXTERNAL_ID")) { $arFields["XML_ID"] = $arFields["EXTERNAL_ID"]; } $PREVIEW_tmp = is_set($arFields, "PREVIEW_TEXT") ? $arFields["PREVIEW_TEXT"] : $ar_wf_element["PREVIEW_TEXT"]; $PREVIEW_TYPE_tmp = is_set($arFields, "PREVIEW_TEXT_TYPE") ? $arFields["PREVIEW_TEXT_TYPE"] : $ar_wf_element["PREVIEW_TEXT_TYPE"]; $DETAIL_tmp = is_set($arFields, "DETAIL_TEXT") ? $arFields["DETAIL_TEXT"] : $ar_wf_element["DETAIL_TEXT"]; $DETAIL_TYPE_tmp = is_set($arFields, "DETAIL_TEXT_TYPE") ? $arFields["DETAIL_TEXT_TYPE"] : $ar_wf_element["DETAIL_TEXT_TYPE"]; $arFields["SEARCHABLE_CONTENT"] = ToUpper((is_set($arFields, "NAME") ? $arFields["NAME"] : $ar_wf_element["NAME"]) . "\r\n" . ($PREVIEW_TYPE_tmp == "html" ? HTMLToTxt($PREVIEW_tmp) : $PREVIEW_tmp) . "\r\n" . ($DETAIL_TYPE_tmp == "html" ? HTMLToTxt($DETAIL_tmp) : $DETAIL_tmp)); if (is_set($arFields["IBLOCK_SECTION_ID"]) && !is_set($arFields, "IBLOCK_SECTION")) { $arFields["IBLOCK_SECTION"] = array($arFields["IBLOCK_SECTION_ID"]); } $arFields["IBLOCK_ID"] = $ar_element["IBLOCK_ID"]; if (!$this->CheckFields($arFields, $ID, $bCheckDiskQuota) || strlen($strWarning)) { $this->LAST_ERROR .= $strWarning; $Result = false; $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR; } else { unset($arFields["ID"]); if (array_key_exists("PREVIEW_PICTURE", $arFields)) { $SAVED_PREVIEW_PICTURE = $arFields["PREVIEW_PICTURE"]; } else { $SAVED_PREVIEW_PICTURE = false; } if (array_key_exists("DETAIL_PICTURE", $arFields)) { $SAVED_DETAIL_PICTURE = $arFields["DETAIL_PICTURE"]; } else { $SAVED_DETAIL_PICTURE = false; } // edit was done in workflow mode if ($bWorkFlow) { $arFields["WF_PARENT_ELEMENT_ID"] = $ID; if (array_key_exists("PREVIEW_PICTURE", $arFields)) { if (is_array($arFields["PREVIEW_PICTURE"])) { if (strlen($arFields["PREVIEW_PICTURE"]["name"]) <= 0 && strlen($arFields["PREVIEW_PICTURE"]["del"]) <= 0) { if (array_key_exists("description", $arFields["PREVIEW_PICTURE"])) { $arFile = CFile::GetFileArray($ar_wf_element["PREVIEW_PICTURE"]); if ($arFields["PREVIEW_PICTURE"]["description"] != $arFile["DESCRIPTION"]) { //Description updated, so it's new file $arNewFile = CFile::MakeFileArray($ar_wf_element["PREVIEW_PICTURE"]); $arNewFile["description"] = $arFields["PREVIEW_PICTURE"]["description"]; $arNewFile["MODULE_ID"] = "iblock"; $arFields["PREVIEW_PICTURE"] = $arNewFile; } else { $arFields["PREVIEW_PICTURE"] = $ar_wf_element["PREVIEW_PICTURE"]; } } else { //File was not changed at all $arFields["PREVIEW_PICTURE"] = $ar_wf_element["PREVIEW_PICTURE"]; } } else { unset($arFields["PREVIEW_PICTURE"]["old_file"]); } } } else { $arFields["PREVIEW_PICTURE"] = $ar_wf_element["PREVIEW_PICTURE"]; } if (array_key_exists("DETAIL_PICTURE", $arFields)) { if (is_array($arFields["DETAIL_PICTURE"])) { if (strlen($arFields["DETAIL_PICTURE"]["name"]) <= 0 && strlen($arFields["DETAIL_PICTURE"]["del"]) <= 0) { if (array_key_exists("description", $arFields["DETAIL_PICTURE"])) { $arFile = CFile::GetFileArray($ar_wf_element["DETAIL_PICTURE"]); if ($arFields["DETAIL_PICTURE"]["description"] != $arFile["DESCRIPTION"]) { //Description updated, so it's new file $arNewFile = CFile::MakeFileArray($ar_wf_element["DETAIL_PICTURE"]); $arNewFile["description"] = $arFields["DETAIL_PICTURE"]["description"]; $arNewFile["MODULE_ID"] = "iblock"; $arFields["DETAIL_PICTURE"] = $arNewFile; } else { $arFields["DETAIL_PICTURE"] = $ar_wf_element["DETAIL_PICTURE"]; } } else { //File was not changed at all $arFields["DETAIL_PICTURE"] = $ar_wf_element["DETAIL_PICTURE"]; } } else { unset($arFields["DETAIL_PICTURE"]["old_file"]); } } } else { $arFields["DETAIL_PICTURE"] = $ar_wf_element["DETAIL_PICTURE"]; } $NID = $this->Add($arFields); if ($NID > 0) { if ($arFields["WF_STATUS_ID"] == 1) { $DB->Query("UPDATE b_iblock_element SET TIMESTAMP_X=TIMESTAMP_X, WF_NEW=null WHERE ID=" . $ID); $DB->Query("UPDATE b_iblock_element SET TIMESTAMP_X=TIMESTAMP_X, WF_NEW=null WHERE WF_PARENT_ELEMENT_ID=" . $ID); $ar_wf_element["WF_NEW"] = false; } if ($this->bWF_SetMove) { CIBlockElement::WF_SetMove($NID, $LAST_ID); } if ($ar_element["WF_STATUS_ID"] != 1 && $ar_wf_element["WF_STATUS_ID"] != $arFields["WF_STATUS_ID"] && $arFields["WF_STATUS_ID"] != 1) { $DB->Query("UPDATE b_iblock_element SET TIMESTAMP_X=TIMESTAMP_X, WF_STATUS_ID=" . $arFields["WF_STATUS_ID"] . " WHERE ID=" . $ID); } } //element was not published, so keep original if (is_set($arFields, "WF_STATUS_ID") && $arFields["WF_STATUS_ID"] != 1 && $ar_element["WF_STATUS_ID"] == 1 || !is_set($arFields, "WF_STATUS_ID") && $ar_wf_element["WF_STATUS_ID"] != 1) { CIBlockElement::WF_CleanUpHistoryCopies($ID); return true; } $arFields['WF_PARENT_ELEMENT_ID'] = false; $rs = $DB->Query("SELECT PREVIEW_PICTURE, DETAIL_PICTURE from b_iblock_element WHERE ID = " . $NID); $ar_new_element = $rs->Fetch(); } else { $ar_new_element = false; } if ($ar_new_element) { if (!intval($ar_new_element["PREVIEW_PICTURE"])) { $arFields["PREVIEW_PICTURE"] = false; } else { $arFields["PREVIEW_PICTURE"] = $ar_new_element["PREVIEW_PICTURE"]; } if (!intval($ar_new_element["DETAIL_PICTURE"])) { $arFields["DETAIL_PICTURE"] = false; } else { $arFields["DETAIL_PICTURE"] = $ar_new_element["DETAIL_PICTURE"]; } if (is_array($arFields["PROPERTY_VALUES"]) && count($arFields["PROPERTY_VALUES"]) > 0) { $i = 0; $db_prop = CIBlockProperty::GetList(array(), array("IBLOCK_ID" => $arFields["IBLOCK_ID"], "CHECK_PERMISSIONS" => "N", "PROPERTY_TYPE" => "F")); while ($arProp = $db_prop->Fetch()) { $i++; unset($arFields["PROPERTY_VALUES"][$arProp["CODE"]]); unset($arFields["PROPERTY_VALUES"][$arProp["ID"]]); $arFields["PROPERTY_VALUES"][$arProp["ID"]] = array(); } if ($i > 0) { //Delete previous files $props = CIBlockElement::GetProperty($arFields["IBLOCK_ID"], $ID, "sort", "asc", array("PROPERTY_TYPE" => "F", "EMPTY" => "N")); while ($arProp = $props->Fetch()) { $arFields["PROPERTY_VALUES"][$arProp["ID"]][$arProp['PROPERTY_VALUE_ID']] = array("VALUE" => array("del" => "Y"), "DESCRIPTION" => false); } //Add copy from history $arDup = array(); //This is cure for files duplication bug (just save element one more time) $props = CIBlockElement::GetProperty($arFields["IBLOCK_ID"], $NID, "sort", "asc", array("PROPERTY_TYPE" => "F", "EMPTY" => "N")); while ($arProp = $props->Fetch()) { if (!array_key_exists($arProp["VALUE"], $arDup)) { $arFields["PROPERTY_VALUES"][$arProp["ID"]][$arProp['PROPERTY_VALUE_ID']] = array("VALUE" => $arProp["VALUE"], "DESCRIPTION" => $arProp["DESCRIPTION"]); $arDup[$arProp["VALUE"]] = true; //This is cure for files duplication bug } } } } } else { if (array_key_exists("PREVIEW_PICTURE", $arFields)) { CFile::SaveForDB($arFields, "PREVIEW_PICTURE", "iblock"); } if (array_key_exists("DETAIL_PICTURE", $arFields)) { CFile::SaveForDB($arFields, "DETAIL_PICTURE", "iblock"); } } unset($arFields["IBLOCK_ID"]); unset($arFields["WF_NEW"]); unset($arFields["IBLOCK_SECTION_ID"]); $bTimeStampNA = false; if (is_set($arFields, "TIMESTAMP_X") && ($arFields["TIMESTAMP_X"] === NULL || $arFields["TIMESTAMP_X"] === false)) { $bTimeStampNA = true; unset($arFields["TIMESTAMP_X"]); } $strUpdate = $DB->PrepareUpdate("b_iblock_element", $arFields, "iblock"); if (strlen($strUpdate) > 0) { $strUpdate .= ", "; } $strSql = "UPDATE b_iblock_element SET " . $strUpdate . ($bTimeStampNA ? "TIMESTAMP_X=TIMESTAMP_X" : "TIMESTAMP_X=now()") . " WHERE ID=" . $ID; $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); if (array_key_exists("PROPERTY_VALUES", $arFields) && is_array($arFields["PROPERTY_VALUES"]) && count($arFields["PROPERTY_VALUES"]) > 0) { CIBlockElement::SetPropertyValues($ID, $ar_element["IBLOCK_ID"], $arFields["PROPERTY_VALUES"]); } if (is_set($arFields, "IBLOCK_SECTION")) { CIBlockElement::SetElementSection($ID, $arFields["IBLOCK_SECTION"], false, $arIBlock["RIGHTS_MODE"] === "E" ? $arIBlock["ID"] : 0); } if ($arIBlock["RIGHTS_MODE"] === "E") { $obElementRights = new CIBlockElementRights($arIBlock["ID"], $ID); if (array_key_exists("RIGHTS", $arFields) && is_array($arFields["RIGHTS"])) { $obElementRights->SetRights($arFields["RIGHTS"]); } } if (array_key_exists("IPROPERTY_TEMPLATES", $arFields)) { $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($arIBlock["ID"], $ID); $ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]); } if ($bUpdateSearch) { CIBlockElement::UpdateSearch($ID, true); } if ($bWorkFlow) { CIBlockElement::WF_CleanUpHistoryCopies($ID); } //Restore saved values if ($SAVED_PREVIEW_PICTURE !== false) { $arFields["PREVIEW_PICTURE_ID"] = $arFields["PREVIEW_PICTURE"]; $arFields["PREVIEW_PICTURE"] = $SAVED_PREVIEW_PICTURE; } else { unset($arFields["PREVIEW_PICTURE"]); } if ($SAVED_DETAIL_PICTURE !== false) { $arFields["DETAIL_PICTURE_ID"] = $arFields["DETAIL_PICTURE"]; $arFields["DETAIL_PICTURE"] = $SAVED_DETAIL_PICTURE; } else { unset($arFields["DETAIL_PICTURE"]); } if ($arIBlock["FIELDS"]["LOG_ELEMENT_EDIT"]["IS_REQUIRED"] == "Y") { $USER_ID = is_object($USER) ? intval($USER->GetID()) : 0; $arEvents = GetModuleEvents("main", "OnBeforeEventLog", true); if (empty($arEvents) || ExecuteModuleEventEx($arEvents[0], array($USER_ID)) === false) { $rsElement = CIBlockElement::GetList(array(), array("=ID" => $ID, "CHECK_PERMISSIONS" => "N", "SHOW_NEW" => "Y"), false, false, array("ID", "NAME", "LIST_PAGE_URL", "CODE")); $arElement = $rsElement->GetNext(); $res = array("ID" => $ID, "CODE" => $arElement["CODE"], "NAME" => $arElement["NAME"], "ELEMENT_NAME" => $arIBlock["ELEMENT_NAME"], "USER_ID" => $USER_ID, "IBLOCK_PAGE_URL" => $arElement["LIST_PAGE_URL"]); CEventLog::Log("IBLOCK", "IBLOCK_ELEMENT_EDIT", "iblock", $arIBlock["ID"], serialize($res)); } } $Result = true; /************* QUOTA *************/ $_SESSION["SESS_RECOUNT_DB"] = "Y"; /************* QUOTA *************/ } $arFields["ID"] = $ID; $arFields["IBLOCK_ID"] = $ar_element["IBLOCK_ID"]; $arFields["RESULT"] =& $Result; if (isset($arFields["PREVIEW_PICTURE"]) && $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && $arFields["PREVIEW_PICTURE"]["copy"]) { @unlink($arFields["PREVIEW_PICTURE"]["tmp_name"]); @rmdir(dirname($arFields["PREVIEW_PICTURE"]["tmp_name"])); } if (isset($arFields["DETAIL_PICTURE"]) && $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && $arFields["DETAIL_PICTURE"]["copy"]) { @unlink($arFields["DETAIL_PICTURE"]["tmp_name"]); @rmdir(dirname($arFields["DETAIL_PICTURE"]["tmp_name"])); } foreach (GetModuleEvents("iblock", "OnAfterIBlockElementUpdate", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arFields)); } if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("iblock_id_" . $arIBlock["ID"]); } return $Result; }
$obElement = new CIBlockElement(); /*Build filter*/ $arFilter = array("IBLOCK_ID" => $arIBlock["ID"], "CHECK_PERMISSIONS" => $arParams["CAN_EDIT"] || $arParams["SOCNET_GROUP_ID"] ? "N" : "Y"); if ($_POST["action_all_rows_" . $arResult["GRID_ID"]] == "Y") { if (!$arResult["ANY_SECTION"]) { $arFilter["SECTION_ID"] = $arResult["SECTION_ID"]; } } else { $arFilter["=ID"] = $_POST["ID"]; } /*Take action*/ if ($_POST["action_button_" . $arResult["GRID_ID"]] == "section") { if (!$arResult["IS_SOCNET_GROUP_CLOSED"] && ($lists_perm >= CListPermissions::CAN_WRITE || CIBlockSectionRights::UserHasRightTo($arIBlock["ID"], $_POST["section_to_move"], "section_element_bind"))) { $rsElements = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID")); while ($arElement = $rsElements->Fetch()) { $obElement->SetElementSection($arElement["ID"], array($_POST["section_to_move"]), false, $arIBlock["RIGHTS_MODE"] == "E" ? $arIBlock["ID"] : 0); } } } elseif ($_POST["action_button_" . $arResult["GRID_ID"]] == "delete" && isset($_POST["ID"]) && is_array($_POST["ID"])) { $rsElements = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID")); while ($arElement = $rsElements->Fetch()) { if (!$arResult["IS_SOCNET_GROUP_CLOSED"] && ($lists_perm >= CListPermissions::CAN_WRITE || CIBlockElementRights::UserHasRightTo($arIBlock["ID"], $arElement["ID"], "element_delete"))) { $DB->StartTransaction(); $APPLICATION->ResetException(); if (!$obElement->Delete($arElement["ID"])) { $DB->Rollback(); if ($ex = $APPLICATION->GetException()) { $strError = GetMessage("CC_BLL_DELETE_ERROR") . " " . $ex->GetString(); } else { $strError = GetMessage("CC_BLL_DELETE_ERROR") . " " . GetMessage("CC_BLL_UNKNOWN_ERROR"); }
function Add($arFields, $bWorkFlow = false, $bUpdateSearch = true, $bResizePictures = false) { global $DB, $USER; $arIBlock = CIBlock::GetArrayByID($arFields["IBLOCK_ID"]); $bWorkFlow = $bWorkFlow && is_array($arIBlock) && $arIBlock["WORKFLOW"] != "N" && CModule::IncludeModule("workflow"); $bBizProc = is_array($arIBlock) && $arIBlock["BIZPROC"] == "Y" && IsModuleInstalled("bizproc"); if (array_key_exists("BP_PUBLISHED", $arFields)) { if ($bBizProc) { if ($arFields["BP_PUBLISHED"] == "Y") { $arFields["WF_STATUS_ID"] = 1; $arFields["WF_NEW"] = false; } else { $arFields["WF_STATUS_ID"] = 2; $arFields["WF_NEW"] = "Y"; $arFields["BP_PUBLISHED"] = "N"; } } else { unset($arFields["BP_PUBLISHED"]); } } if (array_key_exists("IBLOCK_SECTION_ID", $arFields)) { if (!array_key_exists("IBLOCK_SECTION", $arFields)) { $arFields["IBLOCK_SECTION"] = array($arFields["IBLOCK_SECTION_ID"]); } elseif (is_array($arFields["IBLOCK_SECTION"]) && !in_array($arFields["IBLOCK_SECTION_ID"], $arFields["IBLOCK_SECTION"])) { unset($arFields["IBLOCK_SECTION_ID"]); } } $strWarning = ""; if ($bResizePictures) { $arDef = $arIBlock["FIELDS"]["PREVIEW_PICTURE"]["DEFAULT_VALUE"]; if ($arDef["FROM_DETAIL"] === "Y" && is_array($arFields["DETAIL_PICTURE"]) && $arFields["DETAIL_PICTURE"]["size"] > 0 && ($arDef["UPDATE_WITH_DETAIL"] === "Y" || $arFields["PREVIEW_PICTURE"]["size"] <= 0)) { $arNewPreview = $arFields["DETAIL_PICTURE"]; $arNewPreview["COPY_FILE"] = "Y"; if (isset($arFields["PREVIEW_PICTURE"]) && is_array($arFields["PREVIEW_PICTURE"]) && isset($arFields["PREVIEW_PICTURE"]["description"])) { $arNewPreview["description"] = $arFields["PREVIEW_PICTURE"]["description"]; } $arFields["PREVIEW_PICTURE"] = $arNewPreview; } if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arDef["SCALE"] === "Y") { $arNewPicture = CIBlock::ResizePicture($arFields["PREVIEW_PICTURE"], $arDef); if (is_array($arNewPicture)) { $arNewPicture["description"] = $arFields["PREVIEW_PICTURE"]["description"]; $arFields["PREVIEW_PICTURE"] = $arNewPicture; } elseif ($arDef["IGNORE_ERRORS"] !== "Y") { unset($arFields["PREVIEW_PICTURE"]); $strWarning .= GetMessage("IBLOCK_FIELD_PREVIEW_PICTURE") . ": " . $arNewPicture . "<br>"; } } if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arDef["USE_WATERMARK_FILE"] === "Y") { if (strlen($arFields["PREVIEW_PICTURE"]["tmp_name"]) > 0 && ($arFields["PREVIEW_PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"] || $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PREVIEW_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["PREVIEW_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["PREVIEW_PICTURE"]["tmp_name"], $tmp_name); $arFields["PREVIEW_PICTURE"]["copy"] = true; $arFields["PREVIEW_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["PREVIEW_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_FILE_POSITION"], "type" => "file", "size" => "real", "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100), "file" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_FILE"]))); } if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arDef["USE_WATERMARK_TEXT"] === "Y") { if (strlen($arFields["PREVIEW_PICTURE"]["tmp_name"]) > 0 && ($arFields["PREVIEW_PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"] || $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PREVIEW_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["PREVIEW_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["PREVIEW_PICTURE"]["tmp_name"], $tmp_name); $arFields["PREVIEW_PICTURE"]["copy"] = true; $arFields["PREVIEW_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["PREVIEW_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_TEXT_POSITION"], "type" => "text", "coefficient" => $arDef["WATERMARK_TEXT_SIZE"], "text" => $arDef["WATERMARK_TEXT"], "font" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]), "color" => $arDef["WATERMARK_TEXT_COLOR"])); } $arDef = $arIBlock["FIELDS"]["DETAIL_PICTURE"]["DEFAULT_VALUE"]; if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["SCALE"] === "Y") { $arNewPicture = CIBlock::ResizePicture($arFields["DETAIL_PICTURE"], $arDef); if (is_array($arNewPicture)) { $arNewPicture["description"] = $arFields["DETAIL_PICTURE"]["description"]; $arFields["DETAIL_PICTURE"] = $arNewPicture; } elseif ($arDef["IGNORE_ERRORS"] !== "Y") { unset($arFields["DETAIL_PICTURE"]); $strWarning .= GetMessage("IBLOCK_FIELD_DETAIL_PICTURE") . ": " . $arNewPicture . "<br>"; } } if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["USE_WATERMARK_FILE"] === "Y") { if (strlen($arFields["DETAIL_PICTURE"]["tmp_name"]) > 0 && ($arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PREVIEW_PICTURE"]["tmp_name"] || $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name); $arFields["DETAIL_PICTURE"]["copy"] = true; $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_FILE_POSITION"], "type" => "file", "size" => "real", "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100), "file" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_FILE"]))); } if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["USE_WATERMARK_TEXT"] === "Y") { if (strlen($arFields["DETAIL_PICTURE"]["tmp_name"]) > 0 && ($arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PREVIEW_PICTURE"]["tmp_name"] || $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])) { $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"])); CheckDirPath($tmp_name); copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name); $arFields["DETAIL_PICTURE"]["copy"] = true; $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name; } CIBLock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_TEXT_POSITION"], "type" => "text", "coefficient" => $arDef["WATERMARK_TEXT_SIZE"], "text" => $arDef["WATERMARK_TEXT"], "font" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]), "color" => $arDef["WATERMARK_TEXT_COLOR"])); } } $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($arFields["IBLOCK_ID"], 0); if (is_set($arFields, "PREVIEW_PICTURE")) { if (is_array($arFields["PREVIEW_PICTURE"])) { if (strlen($arFields["PREVIEW_PICTURE"]["name"]) <= 0 && strlen($arFields["PREVIEW_PICTURE"]["del"]) <= 0) { unset($arFields["PREVIEW_PICTURE"]); } else { $arFields["PREVIEW_PICTURE"]["MODULE_ID"] = "iblock"; $arFields["PREVIEW_PICTURE"]["name"] = \Bitrix\Iblock\Template\Helper::makeFileName($ipropTemplates, "ELEMENT_PREVIEW_PICTURE_FILE_NAME", $arFields, $arFields["PREVIEW_PICTURE"]); } } else { if (intval($arFields["PREVIEW_PICTURE"]) <= 0) { unset($arFields["PREVIEW_PICTURE"]); } } } if (is_set($arFields, "DETAIL_PICTURE")) { if (is_array($arFields["DETAIL_PICTURE"])) { if (strlen($arFields["DETAIL_PICTURE"]["name"]) <= 0 && strlen($arFields["DETAIL_PICTURE"]["del"]) <= 0) { unset($arFields["DETAIL_PICTURE"]); } else { $arFields["DETAIL_PICTURE"]["MODULE_ID"] = "iblock"; $arFields["DETAIL_PICTURE"]["name"] = \Bitrix\Iblock\Template\Helper::makeFileName($ipropTemplates, "ELEMENT_DETAIL_PICTURE_FILE_NAME", $arFields, $arFields["DETAIL_PICTURE"]); } } else { if (intval($arFields["DETAIL_PICTURE"]) <= 0) { unset($arFields["DETAIL_PICTURE"]); } } } if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") { $arFields["ACTIVE"] = "N"; } if (is_set($arFields, "PREVIEW_TEXT_TYPE") && $arFields["PREVIEW_TEXT_TYPE"] != "html") { $arFields["PREVIEW_TEXT_TYPE"] = "text"; } if (is_set($arFields, "DETAIL_TEXT_TYPE") && $arFields["DETAIL_TEXT_TYPE"] != "html") { $arFields["DETAIL_TEXT_TYPE"] = "text"; } if (is_set($arFields, "DATE_ACTIVE_FROM")) { $arFields["ACTIVE_FROM"] = $arFields["DATE_ACTIVE_FROM"]; } if (is_set($arFields, "DATE_ACTIVE_TO")) { $arFields["ACTIVE_TO"] = $arFields["DATE_ACTIVE_TO"]; } if (is_set($arFields, "EXTERNAL_ID")) { $arFields["XML_ID"] = $arFields["EXTERNAL_ID"]; } if ($bWorkFlow) { $arFields["WF"] = "Y"; if ($arFields["WF_STATUS_ID"] != 1) { $arFields["WF_NEW"] = "Y"; } else { $arFields["WF_NEW"] = ""; } } $arFields["SEARCHABLE_CONTENT"] = $arFields["NAME"]; if (isset($arFields["PREVIEW_TEXT"])) { if (isset($arFields["PREVIEW_TEXT_TYPE"]) && $arFields["PREVIEW_TEXT_TYPE"] == "html") { $arFields["SEARCHABLE_CONTENT"] .= "\r\n" . HTMLToTxt($arFields["PREVIEW_TEXT"]); } else { $arFields["SEARCHABLE_CONTENT"] .= "\r\n" . $arFields["PREVIEW_TEXT"]; } } if (isset($arFields["DETAIL_TEXT"])) { if (isset($arFields["DETAIL_TEXT_TYPE"]) && $arFields["DETAIL_TEXT_TYPE"] == "html") { $arFields["SEARCHABLE_CONTENT"] .= "\r\n" . HTMLToTxt($arFields["DETAIL_TEXT"]); } else { $arFields["SEARCHABLE_CONTENT"] .= "\r\n" . $arFields["DETAIL_TEXT"]; } } $arFields["SEARCHABLE_CONTENT"] = ToUpper($arFields["SEARCHABLE_CONTENT"]); if (!$this->CheckFields($arFields) || strlen($strWarning)) { $this->LAST_ERROR .= $strWarning; $Result = false; $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR; } else { if (array_key_exists("PREVIEW_PICTURE", $arFields)) { $SAVED_PREVIEW_PICTURE = $arFields["PREVIEW_PICTURE"]; if (is_array($arFields["PREVIEW_PICTURE"])) { CFile::SaveForDB($arFields, "PREVIEW_PICTURE", "iblock"); } if ($bWorkFlow) { $COPY_PREVIEW_PICTURE = $arFields["PREVIEW_PICTURE"]; } } if (array_key_exists("DETAIL_PICTURE", $arFields)) { $SAVED_DETAIL_PICTURE = $arFields["DETAIL_PICTURE"]; if (is_array($arFields["DETAIL_PICTURE"])) { CFile::SaveForDB($arFields, "DETAIL_PICTURE", "iblock"); } if ($bWorkFlow) { $COPY_DETAIL_PICTURE = $arFields["DETAIL_PICTURE"]; } } unset($arFields["ID"]); if (is_object($USER)) { if (!isset($arFields["CREATED_BY"]) || intval($arFields["CREATED_BY"]) <= 0) { $arFields["CREATED_BY"] = intval($USER->GetID()); } if (!isset($arFields["MODIFIED_BY"]) || intval($arFields["MODIFIED_BY"]) <= 0) { $arFields["MODIFIED_BY"] = intval($USER->GetID()); } } $arFields["~TIMESTAMP_X"] = $arFields["~DATE_CREATE"] = $DB->CurrentTimeFunction(); foreach (GetModuleEvents("iblock", "OnIBlockElementAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($arFields)); } $IBLOCK_SECTION_ID = $arFields["IBLOCK_SECTION_ID"]; unset($arFields["IBLOCK_SECTION_ID"]); $ID = $DB->Add("b_iblock_element", $arFields, array("DETAIL_TEXT", "SEARCHABLE_CONTENT"), "iblock"); if (array_key_exists("PREVIEW_PICTURE", $arFields)) { $arFields["PREVIEW_PICTURE_ID"] = $arFields["PREVIEW_PICTURE"]; $arFields["PREVIEW_PICTURE"] = $SAVED_PREVIEW_PICTURE; } if (array_key_exists("DETAIL_PICTURE", $arFields)) { $arFields["DETAIL_PICTURE_ID"] = $arFields["DETAIL_PICTURE"]; $arFields["DETAIL_PICTURE"] = $SAVED_DETAIL_PICTURE; } if (CIBlockElement::GetIBVersion($arFields["IBLOCK_ID"]) == 2) { $DB->Query("INSERT INTO b_iblock_element_prop_s" . $arFields["IBLOCK_ID"] . "(IBLOCK_ELEMENT_ID)VALUES(" . $ID . ")"); } if (!isset($arFields["XML_ID"]) || strlen($arFields["XML_ID"]) <= 0) { $arFields["XML_ID"] = $ID; $DB->Query("UPDATE b_iblock_element SET XML_ID = " . $ID . " WHERE ID = " . $ID); } if (is_set($arFields, "PROPERTY_VALUES")) { CIBlockElement::SetPropertyValues($ID, $arFields["IBLOCK_ID"], $arFields["PROPERTY_VALUES"]); } if (is_set($arFields, "IBLOCK_SECTION")) { CIBlockElement::SetElementSection($ID, $arFields["IBLOCK_SECTION"], true, $arIBlock["RIGHTS_MODE"] === "E" ? $arIBlock["ID"] : 0, $IBLOCK_SECTION_ID); } if ($arIBlock["RIGHTS_MODE"] === "E") { $obElementRights = new CIBlockElementRights($arIBlock["ID"], $ID); if (!is_set($arFields, "IBLOCK_SECTION") || empty($arFields["IBLOCK_SECTION"])) { $obElementRights->ChangeParents(array(), array(0)); } if (array_key_exists("RIGHTS", $arFields) && is_array($arFields["RIGHTS"])) { $obElementRights->SetRights($arFields["RIGHTS"]); } } if (array_key_exists("IPROPERTY_TEMPLATES", $arFields)) { $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($arIBlock["ID"], $ID); $ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]); } if ($bUpdateSearch) { CIBlockElement::UpdateSearch($ID); } \Bitrix\Iblock\PropertyIndex\Manager::updateElementIndex($arIBlock["ID"], $ID); if (!isset($arFields["WF_PARENT_ELEMENT_ID"]) && $arIBlock["FIELDS"]["LOG_ELEMENT_ADD"]["IS_REQUIRED"] == "Y") { $USER_ID = is_object($USER) ? intval($USER->GetID()) : 0; $arEvents = GetModuleEvents("main", "OnBeforeEventLog", true); if (empty($arEvents) || ExecuteModuleEventEx($arEvents[0], array($USER_ID)) === false) { $rsElement = CIBlockElement::GetList(array(), array("=ID" => $ID), false, false, array("LIST_PAGE_URL", "NAME", "CODE")); $arElement = $rsElement->GetNext(); $res = array("ID" => $ID, "CODE" => $arElement["CODE"], "NAME" => $arElement["NAME"], "ELEMENT_NAME" => $arIBlock["ELEMENT_NAME"], "USER_ID" => $USER_ID, "IBLOCK_PAGE_URL" => $arElement["LIST_PAGE_URL"]); CEventLog::Log("IBLOCK", "IBLOCK_ELEMENT_ADD", "iblock", $arIBlock["ID"], serialize($res)); } } if ($bWorkFlow && intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0) { // It is completly new element - so make it copy unset($arFields["WF_NEW"]); $arFields["WF_PARENT_ELEMENT_ID"] = $ID; $arNewFields = $arFields; $arNewFields["PREVIEW_PICTURE"] = $COPY_PREVIEW_PICTURE; $arNewFields["DETAIL_PICTURE"] = $COPY_DETAIL_PICTURE; if (is_array($arNewFields["PROPERTY_VALUES"])) { $i = 0; $db_prop = CIBlockProperty::GetList(array(), array("IBLOCK_ID" => $arFields["IBLOCK_ID"], "CHECK_PERMISSIONS" => "N", "PROPERTY_TYPE" => "F")); while ($arProp = $db_prop->Fetch()) { $i++; unset($arNewFields["PROPERTY_VALUES"][$arProp["CODE"]]); unset($arNewFields["PROPERTY_VALUES"][$arProp["ID"]]); $arNewFields["PROPERTY_VALUES"][$arProp["ID"]] = array(); } if ($i > 0) { $props = CIBlockElement::GetProperty($arFields["IBLOCK_ID"], $ID, "sort", "asc", array("PROPERTY_TYPE" => "F", "EMPTY" => "N")); while ($arProp = $props->Fetch()) { $arNewFields["PROPERTY_VALUES"][$arProp["ID"]][$arProp['PROPERTY_VALUE_ID']] = array("VALUE" => $arProp["VALUE"], "DESCRIPTION" => $arProp["DESCRIPTION"]); } } } $WF_ID = $this->Add($arNewFields); if ($this->bWF_SetMove) { CIBlockElement::WF_SetMove($WF_ID); } } $Result = $ID; $arFields["ID"] =& $ID; $_SESSION["SESS_RECOUNT_DB"] = "Y"; self::$elementIblock[$ID] = $arIBlock['ID']; } if (isset($arFields["PREVIEW_PICTURE"]) && is_array($arFields["PREVIEW_PICTURE"]) && isset($arFields["PREVIEW_PICTURE"]["COPY_FILE"]) && $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && $arFields["PREVIEW_PICTURE"]["copy"]) { @unlink($arFields["PREVIEW_PICTURE"]["tmp_name"]); @rmdir(dirname($arFields["PREVIEW_PICTURE"]["tmp_name"])); } if (isset($arFields["DETAIL_PICTURE"]) && is_array($arFields["DETAIL_PICTURE"]) && isset($arFields["DETAIL_PICTURE"]["COPY_FILE"]) && $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && $arFields["DETAIL_PICTURE"]["copy"]) { @unlink($arFields["DETAIL_PICTURE"]["tmp_name"]); @rmdir(dirname($arFields["DETAIL_PICTURE"]["tmp_name"])); } $arFields["RESULT"] =& $Result; foreach (GetModuleEvents("iblock", "OnAfterIBlockElementAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arFields)); } CIBlock::clearIblockTagCache($arIBlock['ID']); return $Result; }
public static function OnBeforePrologHandler() { global $USER_FIELD_MANAGER; if (isset($_REQUEST['action_button']) && !isset($_REQUEST['action'])) { $_REQUEST['action'] = $_REQUEST['action_button']; } if (!isset($_REQUEST['action'])) { return; } $BID = isset($_REQUEST['ID']) ? (int) $_REQUEST['ID'] : 0; if ($_REQUEST['action'] == 'asd_prop_export' && $BID > 0 && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($BID)) { $strPath = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/tmp/asd.iblock/'; $strName = 'asd_props_export_' . $BID . '_' . md5(LICENSE_KEY) . '.xml'; CheckDirPath($strPath); if ($hdlOutput = fopen($strPath . $strName, 'wb')) { fwrite($hdlOutput, '<?xml version="1.0" encoding="' . SITE_CHARSET . '"?>' . "\n"); fwrite($hdlOutput, '<asd_iblock_props>' . "\n"); fwrite($hdlOutput, CASDiblockTools::ExportPropsToXML($BID, $_REQUEST['p'])); if ($_REQUEST['forms'] == 'Y') { fwrite($hdlOutput, CASDiblockTools::ExportSettingsToXML($BID, array('forms'))); } fwrite($hdlOutput, '</asd_iblock_props>' . "\n"); fclose($hdlOutput); } ?> <script type="text/javascript"> top.BX.closeWait(); top.BX.WindowManager.Get().AllowClose(); top.BX.WindowManager.Get().Close(); window.location.href = '/bitrix/tools/asd.iblock/props_export.php?ID=<?php echo $BID; ?> '; </script><?php die; } if ($_REQUEST['action'] == 'asd_prop_import' && $BID > 0 && !$_FILES['xml_file']['error'] && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($BID)) { CASDiblockTools::ImportPropsFromXML($BID, $_FILES['xml_file']['tmp_name'], $arOldNewID); CASDiblockTools::ImportFormsFromXML($BID, $_FILES['xml_file']['tmp_name'], $arOldNewID); LocalRedirect('/bitrix/admin/iblock_edit.php?type=' . $_REQUEST['type'] . '&tabControl_active_tab=edit2&lang=' . LANGUAGE_ID . '&ID=' . $BID . '&admin=Y'); } $IBLOCK_ID = 0; if (isset($_REQUEST['IBLOCK_ID'])) { $IBLOCK_ID = (int) $_REQUEST['IBLOCK_ID']; if ($IBLOCK_ID < 0) { $IBLOCK_ID = 0; } } if ($_REQUEST['action'] == 'asd_reverse' && $IBLOCK_ID > 0 && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($IBLOCK_ID)) { $LIST_MODE = CIBlock::GetArrayByID($IBLOCK_ID, 'LIST_MODE'); if (!strlen($LIST_MODE)) { $LIST_MODE = COption::GetOptionString('iblock', 'combined_list_mode', 'N') == 'Y' ? 'C' : 'S'; } $LIST_MODE = $LIST_MODE == 'C' ? 'S' : 'C'; $ib = new CIBlock(); $ib->Update($IBLOCK_ID, array('LIST_MODE' => $LIST_MODE)); LocalRedirect('/bitrix/admin/' . ($LIST_MODE == 'S' ? 'iblock_element_admin' : 'iblock_list_admin') . '.php?IBLOCK_ID=' . $IBLOCK_ID . '&type=' . htmlspecialcharsbx($_REQUEST['type']) . '&find_section_section=' . intval($_REQUEST['find_section_section']) . '&lang=' . LANGUAGE_ID); } $strCurPage = $GLOBALS['APPLICATION']->GetCurPage(); $bElemPage = $strCurPage == '/bitrix/admin/iblock_element_admin.php' || $strCurPage == '/bitrix/admin/cat_product_admin.php'; $bSectPage = $strCurPage == '/bitrix/admin/iblock_section_admin.php' || $strCurPage == '/bitrix/admin/cat_section_admin.php'; $bMixPage = $strCurPage == '/bitrix/admin/iblock_list_admin.php'; $bRightPage = $bElemPage || $bSectPage || $bMixPage; $successRedirect = false; if ($bRightPage && $_REQUEST['action'] == 'asd_copy_in_list' && strlen($_REQUEST['ID']) > 0) { $bDoAction = true; $_REQUEST['action'] = 'asd_copy'; $_REQUEST['asd_ib_dest'] = $IBLOCK_ID; $_REQUEST['ID'] = array($_REQUEST['ID']); } else { $bDoAction = false; } if ($bRightPage && check_bitrix_sessid() && !empty($_REQUEST['ID']) && ($_SERVER['REQUEST_METHOD'] == 'POST' || $bDoAction) && CModule::IncludeModule('iblock') && ($_REQUEST['action'] == 'asd_copy' || $_REQUEST['action'] == 'asd_move') && isset($_REQUEST['asd_ib_dest']) && (int) $_REQUEST['asd_ib_dest'] > 0 && CASDIblockRights::IsIBlockDisplay($_REQUEST['asd_ib_dest'])) { $intSrcIBlockID = $IBLOCK_ID; $intDestIBlockID = (int) $_REQUEST['asd_ib_dest']; $intSetSectID = 0; if (isset($_REQUEST['asd_sect_dest'])) { $intSetSectID = (int) $_REQUEST['asd_sect_dest']; if ($intSetSectID < 0) { $intSetSectID = 0; } } $boolCreateElement = false; $boolCreateSection = false; if ($bElemPage || $bMixPage) { $boolCreateElement = CASDIblockRights::IsSectionElementCreate($intDestIBlockID, $intSetSectID); } if ($bSectPage || $bMixPage) { $boolCreateSection = CASDIblockRights::IsSectionSectionCreate($intDestIBlockID, $intSetSectID); } if ($boolCreateElement || $boolCreateSection) { $arPropListCache = array(); $arOldPropListCache = array(); $arNamePropListCache = array(); $arOldNamePropListCache = array(); $boolUFListCache = false; $arUFListCache = array(); $arOldUFListCache = array(); $arUFEnumCache = array(); $arOldUFEnumCache = array(); $arUFNameEnumCache = array(); $arOldUFNameEnumCache = array(); $arDestIBlock = CIBlock::GetArrayByID($intDestIBlockID); $arDestIBFields = $arDestIBlock['FIELDS']; $boolCodeUnique = false; if ($arDestIBFields['CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') { $boolCodeUnique = $intSrcIBlockID == $intDestIBlockID; } $boolSectCodeUnique = false; if ($arDestIBFields['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') { $boolSectCodeUnique = $intSrcIBlockID == $intDestIBlockID; } $boolCatalog = CModule::IncludeModule('catalog'); $boolCopyCatalog = false; $boolNewCatalog = false; if ($boolCatalog) { $boolCopyCatalog = is_array(CCatalog::GetByID($intDestIBlockID)); $boolNewCatalog = $boolCopyCatalog; if ($boolCopyCatalog) { $boolCopyCatalog = is_array(CCatalog::GetByID($intSrcIBlockID)); } } $el = new CIBlockElement(); $sc = new CIBlockSection(); $obEnum = new CUserFieldEnum(); foreach ($_REQUEST['ID'] as $eID) { $boolCopyElem = false; $boolCopySect = false; if ($bMixPage) { if (substr($eID, 0, 1) != 'E') { $boolCopySect = true; } else { $boolCopyElem = true; } $ID = (int) substr($eID, 1); } else { $boolCopyElem = $bElemPage; $boolCopySect = $bSectPage; $ID = (int) $eID; } if ($boolCreateElement && $boolCopyElem) { if ($obSrc = CIBlockElement::GetByID($ID)->GetNextElement()) { $arSrc = $obSrc->GetFields(); $arSrcPr = $obSrc->GetProperties(false, array('EMPTY' => 'N')); $arSrc['PREVIEW_PICTURE'] = (int) $arSrc['PREVIEW_PICTURE']; if ($arSrc['PREVIEW_PICTURE'] > 0) { $arSrc['PREVIEW_PICTURE'] = CFile::MakeFileArray($arSrc['PREVIEW_PICTURE']); if (empty($arSrc['PREVIEW_PICTURE'])) { $arSrc['PREVIEW_PICTURE'] = false; } else { $arSrc['PREVIEW_PICTURE']['COPY_FILE'] = 'Y'; } } else { $arSrc['PREVIEW_PICTURE'] = false; } $arSrc['DETAIL_PICTURE'] = (int) $arSrc['DETAIL_PICTURE']; if ($arSrc['DETAIL_PICTURE'] > 0) { $arSrc['DETAIL_PICTURE'] = CFile::MakeFileArray($arSrc['DETAIL_PICTURE']); if (empty($arSrc['DETAIL_PICTURE'])) { $arSrc['DETAIL_PICTURE'] = false; } else { $arSrc['DETAIL_PICTURE']['COPY_FILE'] = 'Y'; } } else { $arSrc['DETAIL_PICTURE'] = false; } $arSrc = array('IBLOCK_ID' => $intDestIBlockID, 'ACTIVE' => $arSrc['ACTIVE'], 'ACTIVE_FROM' => $arSrc['ACTIVE_FROM'], 'ACTIVE_TO' => $arSrc['ACTIVE_TO'], 'SORT' => $arSrc['SORT'], 'NAME' => $arSrc['~NAME'], 'PREVIEW_PICTURE' => $arSrc['PREVIEW_PICTURE'], 'PREVIEW_TEXT' => $arSrc['~PREVIEW_TEXT'], 'PREVIEW_TEXT_TYPE' => $arSrc['PREVIEW_TEXT_TYPE'], 'DETAIL_TEXT' => $arSrc['~DETAIL_TEXT'], 'DETAIL_TEXT_TYPE' => $arSrc['DETAIL_TEXT_TYPE'], 'DETAIL_PICTURE' => $arSrc['DETAIL_PICTURE'], 'WF_STATUS_ID' => $arSrc['WF_STATUS_ID'], 'CODE' => $arSrc['~CODE'], 'TAGS' => $arSrc['~TAGS'], 'XML_ID' => $arSrc['~XML_ID'], 'PROPERTY_VALUES' => array()); if ($arDestIBFields['CODE']['IS_REQUIRED'] == 'Y') { if (!strlen($arSrc['CODE'])) { $arSrc['CODE'] = mt_rand(100000, 1000000); } } if ($arDestIBFields['CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') { $boolElCodeUnique = $boolCodeUnique; if (!$boolCodeUnique) { $rsCheckItems = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, '=CODE' => $arSrc['CODE'], 'CHECK_PERMISSIONS' => 'N'), false, array('nTopCount' => 1), array('ID', 'IBLOCK_ID')); if ($arCheck = $rsCheckItems->Fetch()) { $boolElCodeUnique = true; } } if ($boolElCodeUnique) { $arSrc['CODE'] .= mt_rand(100, 10000); } } if ($intSetSectID > 0) { $arSrc['IBLOCK_SECTION_ID'] = $intSetSectID; } elseif ($intSrcIBlockID == $intDestIBlockID) { $arSectionList = array(); $rsSections = CIBlockElement::GetElementGroups($ID, true); while ($arSection = $rsSections->Fetch()) { $arSectionList[] = $arSection['ID']; } $arSrc['IBLOCK_SECTION'] = $arSectionList; } if ($intSrcIBlockID != $intDestIBlockID) { if (empty($arPropListCache)) { $rsProps = CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, 'PROPERTY_TYPE' => 'L', 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N')); while ($arProp = $rsProps->Fetch()) { $arValueList = array(); $arNameList = array(); $rsValues = CIBlockProperty::GetPropertyEnum($arProp['ID']); while ($arValue = $rsValues->Fetch()) { $arValueList[$arValue['XML_ID']] = $arValue['ID']; $arNameList[$arValue['ID']] = trim($arValue['VALUE']); } if (!empty($arValueList)) { $arPropListCache[$arProp['CODE']] = $arValueList; } if (!empty($arNameList)) { $arNamePropListCache[$arProp['CODE']] = $arNameList; } } } if (empty($arOldPropListCache)) { $rsProps = CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $intSrcIBlockID, 'PROPERTY_TYPE' => 'L', 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N')); while ($arProp = $rsProps->Fetch()) { $arValueList = array(); $arNameList = array(); $rsValues = CIBlockProperty::GetPropertyEnum($arProp['ID']); while ($arValue = $rsValues->Fetch()) { $arValueList[$arValue['ID']] = $arValue['XML_ID']; $arNameList[$arValue['ID']] = trim($arValue['VALUE']); } if (!empty($arValueList)) { $arOldPropListCache[$arProp['CODE']] = $arValueList; } if (!empty($arNameList)) { $arOldNamePropListCache[$arProp['CODE']] = $arNameList; } } } } foreach ($arSrcPr as &$arProp) { if ($arProp['USER_TYPE'] == 'HTML') { if (is_array($arProp['~VALUE'])) { if ($arProp['MULTIPLE'] == 'N') { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array('VALUE' => array('TEXT' => $arProp['~VALUE']['TEXT'], 'TYPE' => $arProp['~VALUE']['TYPE'])); if ($arProp['WITH_DESCRIPTION'] == 'Y') { $arSrc['PROPERTY_VALUES'][$arProp['CODE']]['DESCRIPTION'] = $arProp['~DESCRIPTION']; } } else { if (!empty($arProp['~VALUE'])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array(); foreach ($arProp['~VALUE'] as $propValueKey => $propValue) { $oneNewValue = array('VALUE' => array('TEXT' => $propValue['TEXT'], 'TYPE' => $propValue['TYPE'])); if ($arProp['WITH_DESCRIPTION'] == 'Y') { $oneNewValue['DESCRIPTION'] = $arProp['~DESCRIPTION'][$propValueKey]; } $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $oneNewValue; unset($oneNewValue); } unset($propValue, $propValueKey); } } } } elseif ($arProp['PROPERTY_TYPE'] == 'F') { if (is_array($arProp['VALUE'])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array(); foreach ($arProp['VALUE'] as $propValueKey => $file) { if ($file > 0) { $tmpValue = CFile::MakeFileArray($file); if (!is_array($tmpValue)) { continue; } if ($arProp['WITH_DESCRIPTION'] == 'Y') { $tmpValue = array('VALUE' => $tmpValue, 'DESCRIPTION' => $arProp['~DESCRIPTION'][$propValueKey]); } $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $tmpValue; } } } elseif ($arProp['VALUE'] > 0) { $tmpValue = CFile::MakeFileArray($arProp['VALUE']); if (is_array($tmpValue)) { if ($arProp['WITH_DESCRIPTION'] == 'Y') { $tmpValue = array('VALUE' => $tmpValue, 'DESCRIPTION' => $arProp['~DESCRIPTION']); } $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $tmpValue; } } } elseif ($arProp['PROPERTY_TYPE'] == 'L') { if (!empty($arProp['VALUE_ENUM_ID'])) { if ($intSrcIBlockID == $arSrc['IBLOCK_ID']) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['VALUE_ENUM_ID']; } else { if (isset($arPropListCache[$arProp['CODE']]) && isset($arOldPropListCache[$arProp['CODE']])) { if (is_array($arProp['VALUE_ENUM_ID'])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array(); foreach ($arProp['VALUE_ENUM_ID'] as &$intValueID) { $strValueXmlID = $arOldPropListCache[$arProp['CODE']][$intValueID]; if (isset($arPropListCache[$arProp['CODE']][$strValueXmlID])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $arPropListCache[$arProp['CODE']][$strValueXmlID]; } else { $strValueName = $arOldNamePropListCache[$arProp['CODE']][$intValueID]; $intValueKey = array_search($strValueName, $arNamePropListCache[$arProp['CODE']]); if ($intValueKey !== false) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $intValueKey; } } } if (isset($intValueID)) { unset($intValueID); } if (empty($arSrc['PROPERTY_VALUES'][$arProp['CODE']])) { unset($arSrc['PROPERTY_VALUES'][$arProp['CODE']]); } } else { $strValueXmlID = $arOldPropListCache[$arProp['CODE']][$arProp['VALUE_ENUM_ID']]; if (isset($arPropListCache[$arProp['CODE']][$strValueXmlID])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arPropListCache[$arProp['CODE']][$strValueXmlID]; } else { $strValueName = $arOldNamePropListCache[$arProp['CODE']][$arProp['VALUE_ENUM_ID']]; $intValueKey = array_search($strValueName, $arNamePropListCache[$arProp['CODE']]); if ($intValueKey !== false) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $intValueKey; } } } } } } } elseif ($arProp['PROPERTY_TYPE'] == 'S' || $arProp['PROPERTY_TYPE'] == 'N') { if ($arProp['MULTIPLE'] == 'Y') { if (is_array($arProp['~VALUE'])) { if ($arProp['WITH_DESCRIPTION'] == 'Y') { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array(); foreach ($arProp['~VALUE'] as $propValueKey => $propValue) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = array('VALUE' => $propValue, 'DESCRIPTION' => $arProp['~DESCRIPTION'][$propValueKey]); } unset($propValue, $propValueKey); } else { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['~VALUE']; } } } else { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['WITH_DESCRIPTION'] == 'Y' ? array('VALUE' => $arProp['~VALUE'], 'DESCRIPTION' => $arProp['~DESCRIPTION']) : $arProp['~VALUE']; } } else { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['~VALUE']; } } if (isset($arProp)) { unset($arProp); } AddMessage2Log($arSrc['PROPERTY_VALUES']); $intNewID = $el->Add($arSrc, true, true, true); if ($intNewID) { if ($boolCatalog && $boolCopyCatalog) { $priceRes = CPrice::GetListEx(array(), array('PRODUCT_ID' => $ID), false, false, array('PRODUCT_ID', 'EXTRA_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO')); while ($arPrice = $priceRes->Fetch()) { $arPrice['PRODUCT_ID'] = $intNewID; CPrice::Add($arPrice); } } if ($boolCatalog && $boolNewCatalog) { $arProduct = array('ID' => $intNewID); if ($boolCopyCatalog) { $productRes = CCatalogProduct::GetList(array(), array('ID' => $ID), false, false, array('QUANTITY', 'QUANTITY_TRACE_ORIG', 'CAN_BUY_ZERO_ORIG', 'NEGATIVE_AMOUNT_TRACE_ORIG', 'SUBSCRIBE_ORIG', 'WEIGHT', 'PRICE_TYPE', 'RECUR_SCHEME_TYPE', 'RECUR_SCHEME_LENGTH', 'TRIAL_PRICE_ID', 'WITHOUT_ORDER', 'SELECT_BEST_PRICE', 'VAT_ID', 'VAT_INCLUDED', 'WIDTH', 'LENGTH', 'HEIGHT', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY', 'MEASURE')); if ($arCurProduct = $productRes->Fetch()) { $arProduct = $arCurProduct; $arProduct['ID'] = $intNewID; $arProduct['QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE_ORIG']; $arProduct['CAN_BUY_ZERO'] = $arProduct['CAN_BUY_ZERO_ORIG']; $arProduct['NEGATIVE_AMOUNT_TRACE'] = $arProduct['NEGATIVE_AMOUNT_TRACE_ORIG']; if (isset($arProduct['SUBSCRIBE_ORIG'])) { $arProduct['SUBSCRIBE'] = $arProduct['SUBSCRIBE_ORIG']; } foreach ($arProduct as $productKey => $productValue) { if ($productValue === null) { unset($arProduct[$productKey]); } } } } CCatalogProduct::Add($arProduct, false); } if ($_REQUEST['action'] == 'asd_move') { if (CASDIblockRights::IsElementDelete($intSrcIBlockID, $ID)) { $el->Delete($ID); } else { CASDiblock::$error .= '[' . $ID . '] ' . GetMessage('ASD_ACTION_ERR_DELETE_ELEMENT_RIGHTS') . "\n"; } } } else { CASDiblock::$error .= '[' . $ID . '] ' . $el->LAST_ERROR . "\n"; } } } if ($boolCreateSection && $boolCopySect) { if ($_REQUEST['action'] == 'asd_move') { continue; } $rsSections = CIBlockSection::GetList(array(), array('ID' => $ID, 'IBLOCK_ID' => $intSrcIBlockID), false, array('ID', 'NAME', 'XML_ID', 'CODE', 'IBLOCK_SECTION_ID', 'IBLOCK_ID', 'ACTIVE', 'SORT', 'PICTURE', 'DESCRIPTION', 'DESCRIPTION_TYPE', 'DETAIL_PICTURE', 'SOCNET_GROUP_ID', 'UF_*')); if ($arSrcSect = $rsSections->Fetch()) { $arDestSect = $arSrcSect; unset($arDestSect['ID']); $arDestSect['IBLOCK_ID'] = $intDestIBlockID; if ($arDestIBFields['SECTION_CODE']['IS_REQUIRED'] == 'Y') { if (!strlen($arDestSect['CODE'])) { $arDestSect['CODE'] = mt_rand(100000, 1000000); } } if ($arDestIBFields['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') { $boolScCodeUnique = $boolSectCodeUnique; if (!$boolSectCodeUnique) { $rsCheckItems = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, '=CODE' => $arSrc['CODE'], 'CHECK_PERMISSIONS' => 'N'), false, array('nTopCount' => 1), array('ID', 'IBLOCK_ID')); if ($arCheck = $rsCheckItems->Fetch()) { $boolScCodeUnique = true; } } if ($boolScCodeUnique) { $arDestSect['CODE'] .= mt_rand(100, 10000); } } if ($intSetSectID > 0) { $arDestSect['IBLOCK_SECTION_ID'] = $intSetSectID; } elseif ($intSrcIBlockID != $intDestIBlockID) { $arDestSect['IBLOCK_SECTION_ID'] = 0; } $arDestSect['PICTURE'] = (int) $arDestSect['PICTURE']; if ($arDestSect['PICTURE'] > 0) { $arDestSect['PICTURE'] = CFile::MakeFileArray($arDestSect['PICTURE']); if (empty($arDestSect['PICTURE'])) { $arDestSect['PICTURE'] = false; } else { $arDestSect['PICTURE']['COPY_FILE'] = 'Y'; } } else { $arDestSect['PICTURE'] = false; } $arDestSect['DETAIL_PICTURE'] = (int) $arDestSect['DETAIL_PICTURE']; if ($arDestSect['DETAIL_PICTURE'] > 0) { $arDestSect['DETAIL_PICTURE'] = CFile::MakeFileArray($arDestSect['DETAIL_PICTURE']); if (empty($arDestSect['DETAIL_PICTURE'])) { $arDestSect['DETAIL_PICTURE'] = false; } else { $arDestSect['DETAIL_PICTURE']['COPY_FILE'] = 'Y'; } } else { $arDestSect['DETAIL_PICTURE'] = false; } if (!$boolUFListCache) { $boolUFListCache = true; $arUFListCache = $USER_FIELD_MANAGER->GetUserFields('IBLOCK_' . $intDestIBlockID . '_SECTION'); if (!empty($arUFListCache)) { if ($intSrcIBlockID != $intDestIBlockID) { $arOldUFListCache = $USER_FIELD_MANAGER->GetUserFields('IBLOCK_' . $intSrcIBlockID . '_SECTION'); if (empty($arOldUFListCache)) { $arUFListCache = array(); } } else { $arOldUFListCache = $arUFListCache; } } if (!empty($arUFListCache)) { if ($intSrcIBlockID != $intDestIBlockID) { foreach ($arUFListCache as &$arOneUserField) { if ('enum' == $arOneUserField['USER_TYPE']['BASE_TYPE']) { $arUFEnumCache[$arOneUserField['FIELD_NAME']] = array(); $arUFNameEnumCache[$arOneUserField['FIELD_NAME']] = array(); $rsEnum = $obEnum->GetList(array(), array('USER_FIELD_ID' => $arOneUserField['ID'])); while ($arEnum = $rsEnum->Fetch()) { $arUFEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['XML_ID']] = $arEnum['ID']; $arUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = trim($arEnum['VALUE']); } } } if (isset($arOneUserField)) { unset($arOneUserField); } foreach ($arOldUFListCache as &$arOneUserField) { if ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'enum') { $arOldUFEnumCache[$arOneUserField['FIELD_NAME']] = array(); $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']] = array(); $rsEnum = $obEnum->GetList(array(), array('USER_FIELD_ID' => $arOneUserField['ID'])); while ($arEnum = $rsEnum->Fetch()) { $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = $arEnum['XML_ID']; $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = trim($arEnum['VALUE']); } } } if (isset($arOneUserField)) { unset($arOneUserField); } } } } if (!empty($arUFListCache)) { foreach ($arUFListCache as &$arOneUserField) { if (!isset($arDestSect[$arOneUserField['FIELD_NAME']])) { continue; } if ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'file') { if (!empty($arDestSect[$arOneUserField['FIELD_NAME']])) { if (is_array($arDestSect[$arOneUserField['FIELD_NAME']])) { $arNewFileList = array(); foreach ($arDestSect[$arOneUserField['FIELD_NAME']] as &$intFileID) { $arNewFile = false; $intFileID = (int) $intFileID; if ($intFileID > 0) { $arNewFile = CFile::MakeFileArray($intFileID); } if (!empty($arNewFile)) { $arNewFileList[] = $arNewFile; } } if (isset($intFileID)) { unset($intFileID); } $arDestSect[$arOneUserField['FIELD_NAME']] = !empty($arNewFileList) ? $arNewFileList : false; } else { $arNewFile = false; $intFileID = (int) $arDestSect[$arOneUserField['FIELD_NAME']]; if ($intFileID > 0) { $arNewFile = CFile::MakeFileArray($intFileID); } $arDestSect[$arOneUserField['FIELD_NAME']] = !empty($arNewFile) ? $arNewFile : false; } } else { $arDestSect[$arOneUserField['FIELD_NAME']] = false; } } elseif ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'enum') { if (!empty($arDestSect[$arOneUserField['FIELD_NAME']])) { if ($intSrcIBlockID != $intDestIBlockID) { if (array_key_exists($arOneUserField['FIELD_NAME'], $arUFEnumCache) && array_key_exists($arOneUserField['FIELD_NAME'], $arOldUFEnumCache)) { if (is_array($arDestSect[$arOneUserField['FIELD_NAME']])) { $arNewEnumList = array(); foreach ($arDestSect[$arOneUserField['FIELD_NAME']] as &$intValueID) { $strValueXmlID = $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$intValueID]; if (array_key_exists($strValueXmlID, $arUFEnumCache[$arOneUserField['FIELD_NAME']])) { $arNewEnumList[] = $arUFEnumCache[$arOneUserField['FIELD_NAME']][$strValueXmlID]; } else { $strValueName = $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$intValueID]; $intValueKey = array_search($strValueName, $arUFNameEnumCache[$arOneUserField['FIELD_NAME']]); if ($intValueKey !== false) { $arNewEnumList[] = $intValueKey; } } } if (isset($intValueID)) { unset($intValueID); } if (!empty($arNewEnumList)) { $arDestSect[$arOneUserField['FIELD_NAME']] = $arNewEnumList; } } else { $strValueXmlID = $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$arDestSect[$arOneUserField['FIELD_NAME']]]; if (array_key_exists($strValueXmlID, $arUFEnumCache[$arOneUserField['FIELD_NAME']])) { $arDestSect[$arOneUserField['FIELD_NAME']] = $arUFEnumCache[$arOneUserField['FIELD_NAME']][$strValueXmlID]; } else { $strValueName = $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arDestSect[$arOneUserField['FIELD_NAME']]]; $intValueKey = array_search($strValueName, $arUFNameEnumCache[$arOneUserField['FIELD_NAME']]); if ($intValueKey !== false) { $arDestSect[$arOneUserField['FIELD_NAME']] = $intValueKey; } } } } } } else { $arDestSect[$arOneUserField['FIELD_NAME']] = false; } } } if (isset($arOneUserField)) { unset($arOneUserField); } } $intNewID = $sc->Add($arDestSect); if (!$intNewID) { CASDiblock::$error .= '[' . $ID . '] ' . $sc->LAST_ERROR . "\n"; } } } } $successRedirect = true; } unset($_REQUEST['action']); if (isset($_REQUEST['action_button'])) { unset($_REQUEST['action_button']); } if ($successRedirect) { LocalRedirect($GLOBALS['APPLICATION']->GetCurPageParam('', array('action', 'action_button', 'asd_ib_dest', 'asd_sect_dest', 'ID'))); } } if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'asd_remove' && $IBLOCK_ID > 0 && isset($_REQUEST['find_section_section']) && check_bitrix_sessid() && CASDIblockRights::IsIBlockDisplay($IBLOCK_ID)) { $intSectionID = (int) $_REQUEST['find_section_section']; if ($intSectionID > 0) { $strCurPage = $GLOBALS['APPLICATION']->GetCurPage(); $bElemPage = $strCurPage == '/bitrix/admin/iblock_element_admin.php' || $strCurPage == '/bitrix/admin/cat_product_admin.php'; $bMixPage = $strCurPage == '/bitrix/admin/iblock_list_admin.php'; if ($bElemPage || $bMixPage) { foreach ($_REQUEST['ID'] as $eID) { if ($bMixPage) { if (substr($eID, 0, 1) != 'E') { continue; } $ID = (int) substr($eID, 1); } else { $ID = (int) $eID; } if ($ID <= 0) { continue; } if (CASDIblockRights::IsElementEdit($IBLOCK_ID, $ID)) { $arSectionList = array(); $rsSections = CIBlockElement::GetElementGroups($ID, true); while ($arSection = $rsSections->Fetch()) { $arSection['ID'] = (int) $arSection['ID']; if ($arSection['ID'] != $intSectionID) { $arSectionList[] = $arSection['ID']; } } CIBlockElement::SetElementSection($ID, $arSectionList, false); $successRedirect = true; } } } } unset($_REQUEST['action']); if (isset($_REQUEST['action_button'])) { unset($_REQUEST['action_button']); } if ($successRedirect) { LocalRedirect($GLOBALS['APPLICATION']->GetCurPageParam('', array('action', 'action_button'))); } } }
protected function workWithDropped(array $droppedSection, $downloadedSectionId) { $this->abortIfNeeded(); $droppedElementQuery = CIBlockElement::GetList(array(), array('CHECK_PERMISSIONS' => 'N', 'INCLUDE_SUBSECTIONS' => 'Y', 'SECTION_ID' => $droppedSection['ID'], 'IBLOCK_ID' => $droppedSection['IBLOCK_ID'])); if (!$droppedElementQuery) { //empty spaces return true; } while ($droppedElement = $droppedElementQuery->Fetch()) { $this->abortIfNeeded(); //prepare $this->uniqualizeElement($droppedElement, $downloadedSectionId); //move to new life CIBlockElement::SetElementSection($droppedElement['ID'], array($downloadedSectionId)); static::$countConvertElements++; } //empty spaces return true; }
/** * <p>Метод обновляет привязки Wiki-страницы к категориям. Динамичный метод.</p> * * * @param int $ID Идентификатор Wiki-страницы * * @param int $IBLOCK_ID Идентификатор Инфо.блока * * @param array $arCats Массив наименований категорий страницы * * @return void * * <h4>Example</h4> * <pre> * <?<br> * // Обновим категории страницы с идентификатором 13 из инфо.блока с идентификатором 2 * $arCats = array('Категория 1', 'Категория 2'); * $ID = 13; * $IBLOCK_ID = 2; * * $CWiki = new CWiki(); * $CWiki->UpdateCategory($ID, $IBLOCK_ID, $arCats);<br>?> * </pre> * * * <h4>See Also</h4> * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/wiki/classes/cwiki/GetCategory.php">CWiki::GetCategory</a> </li> * </ul><a name="examples"></a> * * * @static * @link http://dev.1c-bitrix.ru/api_help/wiki/classes/cwiki/UpdateCategory.php * @author Bitrix */ public function UpdateCategory($ID, $IBLOCK_ID, $arCats) { $this->CleanCacheById($ID, $IBLOCK_ID); $arFilter = array('IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'); $arElement = self::GetElementById($ID, $arFilter); $bCategoryPage = false; $sCatName = ''; $arCatsID = array(); if (CWikiUtils::IsCategoryPage($arElement['~NAME'], $sCatName)) { $bCategoryPage = true; } if ($bCategoryPage) { // get current category $arFilter = array('NAME' => $sCatName, 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'); if (CWikiSocnet::IsSocNet()) { $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder; $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder; } $rsCurCats = CIBlockSection::GetList(array(), $arFilter); $arCurCat = $rsCurCats->GetNext(); if (empty($arCurCat)) { $CIB_S = new CIBlockSection(); $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['NAME'] = $sCatName; $_arFields['XML_ID'] = $sCatName; if (CWikiSocnet::IsSocNet()) { $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId; } $iCurCatID = $CIB_S->Add($_arFields); if ($iCurCatID != false) { $arCatsID[] = $iCurCatID; } } else { $iCurCatID = $arCurCat['ID']; $arCatsID[] = $arCurCat['ID']; } // Page bind only to this category CIBlockElement::SetElementSection($ID, $arCatsID); $CIB_S = new CIBlockSection(); if (!empty($arCats)) { // Nova create a category if it still has no $arFilter = array('NAME' => $arCats[0], 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'); if (CWikiSocnet::IsSocNet()) { $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder; $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder; } $rsCats = CIBlockSection::GetList(array(), $arFilter); $arCat = $rsCats->GetNext(); if (empty($arCat)) { $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['NAME'] = CWikiUtils::htmlspecialcharsback($arCats[0]); $_arFields['XML_ID'] = CWikiUtils::htmlspecialcharsback($arCats[0]); $_arFields['CHECK_PERMISSIONS'] = 'N'; if (CWikiSocnet::IsSocNet()) { $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId; } $iCatID = $CIB_S->Add($_arFields); } else { $iCatID = $arCat['ID']; } $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['IBLOCK_SECTION_ID'] = $iCatID; // current category doing this subcategory $CIB_S->Update($iCurCatID, $_arFields); } else { $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['IBLOCK_SECTION_ID'] = 0; if (CWikiSocnet::IsSocNet()) { $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId; } // bind to the root category $CIB_S->Update($iCurCatID, $_arFields); } } else { $arExistsCatsId = array(); $arDelCatId = array(); $rsSect = CIBlockElement::GetElementGroups($ID, false); //$arResult['SECTIONS'] = array(); //erase candidat while ($arSect = $rsSect->GetNext()) { $arExistsCatsId[] = $arSect['ID']; } if (!empty($arCats)) { $arFilter = array('NAME' => $arCats, 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'); if (CWikiSocnet::IsSocNet()) { $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder; $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder; } $rsCats = CIBlockSection::GetList(array(), $arFilter); while ($arCat = $rsCats->GetNext()) { $arExiststInBlockCats[] = $arCat['~NAME']; $arCatsID[] = $arCat['ID']; } $CIB_S = new CIBlockSection(); foreach ($arCats as $sCatName) { if (!in_array($sCatName, $arExiststInBlockCats)) { $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['NAME'] = CWikiUtils::htmlspecialcharsback($sCatName, false); $_arFields['XML_ID'] = CWikiUtils::htmlspecialcharsback($sCatName, false); $_arFields['CHECK_PERMISSIONS'] = 'N'; if (CWikiSocnet::IsSocNet()) { $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId; } $iCatID = $CIB_S->Add($_arFields); if ($iCatID != false) { $arCatsID[] = $iCatID; } } } //bind to the item if (!empty($arCatsID)) { //if (CWikiSocnet::IsSocNet()) // $arCatsID[] = CWikiSocnet::$iCatId; CIBlockElement::SetElementSection($ID, $arCatsID); } } else { $arCatsID = array(); if (CWikiSocnet::IsSocNet()) { $arCatsID = CWikiSocnet::$iCatId; } CIBlockElement::SetElementSection($ID, $arCatsID); } if (is_array($arCatsID)) { $arDelCatId = array_diff($arExistsCatsId, $arCatsID); } if (!empty($arDelCatId)) { foreach ($arDelCatId as $_iCatId) { $obRes = CIBlockSection::GetList(array(), array('ID' => $_iCatId, 'IBLOCK_ID' => $IBLOCK_ID), true); $arCatProp = $obRes->Fetch(); if ($arCatProp['ELEMENT_CNT'] == 0) { CIBlockSection::Delete($_iCatId); } } } } }
function COPY($options, $drop = false) { $statusSymlinkDelete = false; $arCacheCleanID = array(); if (!$this->CheckWebRights("", array("action" => "create"), true)) { return $this->ThrowAccessDenied(__LINE__); } elseif ($_SERVER['REQUEST_METHOD'] == "MOVE" && !empty($_SERVER["CONTENT_LENGTH"])) { return "415 Unsupported media type"; } elseif ($options["path"] == $options["dest_url"]) { return "204 No Content"; } elseif (empty($options["dest_url"])) { return $this->ThrowError("502 bad gateway", "EMPTY_DESTINATION_URL", GetMessage("WD_FILE_ERROR2"), __LINE__); } $destUrl = $options["dest_url"]; if (substr($destUrl, -1) === "/") { $destUrl = substr($destUrl, 0, -1); } $destName = GetFileName($destUrl); if ($destUrl !== "" && $destName !== "") { $destParentDir = GetDirPath($destUrl); $destParentDir = count($destParentDir) > 0 ? $destParentDir : "/"; $o = array("path" => $destParentDir, "depth" => 1); $result = $this->PROPFIND($o, $files, array("COLUMNS" => array("ID", "NAME"), "return" => "array")); if (!empty($result["RESULT"])) { foreach ($result["RESULT"] as $key => $res) { if ($res["NAME"] === $destName) { if (strlen(GetFileExtension($destName)) > 0) { return $this->ThrowError("400 Bad Request", "FOLDER_IS_EXISTS", str_replace("#FILE#", '"' . $res["NAME"] . '"', GetMessage("WD_FILE_ERROR8")), __LINE__); } elseif (isset($options['section_id']) && $res['ID'] == $options['section_id']) { return $this->ThrowError("400 Bad Request", "SAME_FOLDER_IS_EXISTS", str_replace("#FOLDER#", '"' . $res["NAME"] . '"', GetMessage("WD_FILE_ERROR5")), __LINE__); } else { return $this->ThrowError("400 Bad Request", "FOLDER_IS_EXISTS", str_replace("#FOLDER#", '"' . $res["NAME"] . '"', GetMessage("WD_FILE_ERROR5")), __LINE__); } } } } } //$this->CheckUniqueName($basename, $section_id, &$res) //GetFileName() $arFrom = array(); $arTo = array(); $is_dir = false; ////////////// CHECK FROM $this->IsDir($options); $arFrom = $this->arParams; if ($this->arParams["not_found"]) { return $this->ThrowError("404 Not Found", "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND", GetMessage("WD_FILE_ERROR3"), __LINE__); } elseif ($this->arParams["is_dir"] === true) { $is_dir = true; if ($_SERVER['REQUEST_METHOD'] == "MOVE" && $options["depth"] != "infinity") { return "400 Bad request"; } elseif ($this->check_creator) { return $this->ThrowAccessDenied("USER_IS_NOT_CREATOR", __LINE__); } elseif (empty($options["path"])) { $options["path"] = $this->_get_path($arFrom["item_id"], false); } $res = $this->_udecode($options["dest_url"]); $res2 = str_replace("//", "/", $res . "/"); $res1 = str_replace("//", "/", $options["path"] . "/"); if ($res1 === $res2) { return "204 No Content"; } elseif (strtolower(substr($res2, 0, strlen($res1))) == strtolower($res1) && strlen($res1) != strlen($res2)) { return $this->ThrowError("400 Bad Request", "SECTION_IS_NOT_UPDATED", GetMessage("WD_FILE_ERROR100"), __LINE__); } } else { // found and is_file } if (!empty($arFrom['parent_id'])) { list($contextType, $contextEntityId) = $this->getContextData(); $sectionData = $this->getSectionDataForLinkAnalyze($arFrom['parent_id']); if (CWebDavSymlinkHelper::isLink($contextType, $contextEntityId, $sectionData)) { $arFrom['is_symlink'] = true; $arFrom['symlink_section_data'] = $sectionData; $arFrom['symlink_section_data_link'] = CWebDavSymlinkHelper::getLinkData($contextType, $contextEntityId, $sectionData); } } ////////////// CHECK TO $arToParams = array("path" => $options['dest_url']); if (strpos($options['dest_url'], '.Trash') !== false) { $arToParams['check_permissions'] = false; } $this->IsDir($arToParams); $arTo = $this->arParams; if (!empty($arTo['parent_id'])) { list($contextType, $contextEntityId) = $this->getContextData(); $sectionData = $this->getSectionDataForLinkAnalyze($arTo['parent_id']); if (CWebDavSymlinkHelper::isLink($contextType, $contextEntityId, $sectionData)) { $arTo['is_symlink'] = true; $arTo['symlink_section_data'] = $sectionData; $arTo['symlink_section_data_link'] = CWebDavSymlinkHelper::getLinkData($contextType, $contextEntityId, $sectionData); } } if ($this->arParams["not_found"] == true) { if ($this->e_rights && strpos($options['dest_url'], '.Trash') === false && !$this->CheckWebRights("COPY", array('action' => $drop ? 'move' : 'copy', 'from' => array($arFrom), 'to' => array($arTo)), false)) { return $this->ThrowAccessDenied(__LINE__); } //$arTo = false; } elseif ($arFrom["is_dir"] === true && $arTo["is_file"] === true || $arFrom["is_file"] === true && $arTo["is_dir"] === true) { return $this->ThrowError("400 Bad Request", "FOLDER_IS_EXISTS", str_replace("#FOLDER#", $this->arParams["item_id"], GetMessage("WD_FILE_ERROR5")), __LINE__); } elseif (!$this->CheckWebRights("COPY", array('action' => $drop ? 'move' : 'copy', 'from' => array($arFrom), 'to' => array($arTo)), false)) { return $this->ThrowAccessDenied(__LINE__); } elseif ($arFrom["item_id"] == $arTo["item_id"] && $arFrom['basename'] == $arTo['basename']) { // else - trying to change case in name return "204 No Content"; } elseif ($arFrom["element_array"]["WF_PARENT_ELEMENT_ID"] > 0) { unset($arTo["item_id"]); } elseif (isset($options['rename']) && $options['rename'] === true) { // fix fast delete to trash from different folders with the same file name $nameSuffix = 1; do { $tmpName = $options["dest_url"] . " (" . $nameSuffix++ . ")"; $this->IsDir(array("path" => $tmpName)); $arTo = $this->arParams; } while ($arTo["not_found"] !== true); $options['dest_url'] = $tmpName; } elseif (!$options["overwrite"]) { return $this->ThrowError('412 Precondition failed', "FILE_OR_FOLDER_ALREADY_EXISTS", GetMessage("WD_FILE_ERROR4"), __LINE__); } elseif (!$this->CheckName($arTo["basename"])) { return $this->ThrowError("400 bad request", "BAD_NAME", GetMessage("WD_FILE_ERROR101"), __LINE__); } elseif ($arTo["is_file"] && $this->check_creator && $arTo["element_array"]["CREATED_BY"] != $GLOBALS["USER"]->GetID()) { return $this->ThrowAccessDenied("USER_IS_NOT_CREATOR", __LINE__); } if ($this->workflow == 'workflow' && $arFrom["is_file"] && !CWorkflow::IsAdmin() && !$GLOBALS['USER']->CanDoOperation('webdav_change_settings')) { $bNeedCheckWfRights = false; if ($this->e_rights) { $arToParent = $this->GetObject(array('section_id' => $arTo['parent_id'])); if ($arToParent['is_dir']) { $bNeedCheckWfRights = !$this->GetPermission('SECTION', $arToParent['item_id'], 'element_edit_any_wf_status'); } } else { $bNeedCheckWfRights = $this->permission < 'W'; } if ($bNeedCheckWfRights && CIBlockElement::WF_GetStatusPermission($arFrom["element_array"]["WF_STATUS_ID"]) != 2) { return $this->ThrowError("400 bad request", "BAD_WF_RIGHTS", GetMessage("WD_FILE_ERROR110"), __LINE__); } } if ($arTo['parent_id'] == $this->GetMetaID('TRASH')) { $arCheckTrashElement = $arFrom[$arFrom['is_dir'] ? 'dir_array' : 'element_array']; if ($this->_parse_webdav_info($arCheckTrashElement) && !isset($arCheckTrashElement['PROPS']['BX:']['UNDELETE'])) { return $this->ThrowAccessDenied("BAD_NAME", __LINE__); } } if ($arFrom["is_file"]) { $el = new CIBlockElement(); if ($arTo["item_id"] && $arTo['item_id'] !== $arFrom['item_id']) { $this->_ib_elm_delete($arTo['item_id']); // TODO: need to check permissions ? } //drop == true if this action is @move@ //is file if ($drop) { $actionRename = $arFrom['parent_id'] == $arTo['parent_id']; $arFields = array("NAME" => $arTo["basename"], "MODIFIED_BY" => $GLOBALS['USER']->GetID(), "IBLOCK_SECTION_ID" => $arTo["parent_id"]); $this->_onEvent($arFrom['parent_id'] != $arTo['parent_id'] ? 'Move' : 'Rename', $arFrom['element_id'], 'FILE', array('TO' => $arFrom['parent_id'] != $arTo['parent_id'] ? $arTo["parent_id"] : $arTo["basename"])); //from symlink move. Not rename!!!! if (!$actionRename && (!empty($arFrom['is_symlink']) || !empty($arTo['is_symlink']))) { $targetIblockId = $this->IBLOCK_ID; if (!empty($arTo['is_symlink'])) { $targetIblockId = $arTo['symlink_section_data']['IBLOCK_ID']; } //move and don't delete item if (self::_move_from_iblock_to_iblock($arFrom['item_id'], $targetIblockId, $arTo['parent_id'], false, true)) { $statusSymlinkDelete = $this->DELETE(array("element_id" => $arFrom['item_id'])); } } else { if ($this->workflow == 'workflow') { if ($arTo["parent_id"] != $arFrom["parent_id"]) { $arFields["WF_COMMENTS"] = GetMessage("WD_FILE_IS_MOVED"); $el->SetElementSection($arFrom["item_id"], $arTo["parent_id"]); // TODO: need to check permissions ??? } else { $arFields["WF_COMMENTS"] = GetMessage("WD_FILE_IS_RENAMED"); } if ($arTo["parent_id"] != $arFrom["parent_id"] && $arTo["basename"] != $arFrom["element_name"]) { $arFields["WF_COMMENTS"] = GetMessage("WD_FILE_IS_MOVED_AND_RENAMED"); } } if ($this->workflow == 'bizproc' || $this->workflow == 'bizproc_limited') { $this->AddDocumentToHistory($arFrom['item_id'], $arFrom['element_name']); } $el->Update($arFrom["item_id"], $arFields, $this->workflow == 'workflow', true, false, false); // TODO: need to check permissions ??? $arCacheCleanID[] = 'element' . $arFrom["item_id"]; if ($this->workflow == 'bizproc' || $this->workflow == 'bizproc_limited') { $db_res2 = CIBlockElement::GetList(array(), array("WF_PARENT_ELEMENT_ID" => $arFrom["item_id"], "SHOW_HISTORY" => "Y"), false, false, array("ID")); if ($db_res2 && ($res2 = $db_res2->Fetch())) { do { $res = $el->Update($res2["ID"], array("IBLOCK_SECTION_ID" => $arFields["IBLOCK_SECTION_ID"]), false, true, false, false); $arCacheCleanID[] = 'element' . $res2["ID"]; } while ($res2 = $db_res2->Fetch()); } } } } else { //from symlink copy if (!empty($arFrom['is_symlink']) || !empty($arTo['is_symlink'])) { $targetIblockId = $this->IBLOCK_ID; if (!empty($arTo['is_symlink'])) { $targetIblockId = $arTo['symlink_section_data']['IBLOCK_ID']; } //move and don't delete item if (!self::_move_from_iblock_to_iblock($arFrom['item_id'], $targetIblockId, $arTo['parent_id'], false, true)) { return '403 Forbidden'; } } else { $options = array('path' => $options["dest_url"], 'content_length' => $arFrom["file_array"]['FILE_SIZE'], 'content_type' => $arFrom["file_array"]['CONTENT_TYPE']); $stat = $this->PUT($options); if ($stat === false) { return '403 Forbidden'; } elseif (is_resource($stat) && get_resource_type($stat) == 'stream') { fclose($stat); $arTmpFile = CFile::MakeFileArray($arFrom['element_array']['PROPERTY_FILE_VALUE']); // since CopyDirFiles doesn't support clouds if (!(is_array($arTmpFile) && is_set($arTmpFile, 'tmp_name'))) { return false; } CopyDirFiles($arTmpFile['tmp_name'], $options["TMP_FILE"]); clearstatcache(); $options['USER_FIELDS'] = $this->GetUfFieldsSimpleArray($arFrom['item_id']); if (!$this->put_commit($options)) { return $this->ThrowError('409 Conflict', "BAD_BP_PERMISSIONS", GetMessage("WD_FILE_ERROR110"), __LINE__); } } } } $this->_onEvent(($arFrom['parent_id'] != $arTo['parent_id'] ? 'Move' : 'Rename') . 'Finished', $arFrom['element_id'], 'FILE'); } else { $se = new CIBlockSection(); $actionRename = $arFrom['parent_id'] == $arTo['parent_id']; $actionWithSymlink = !empty($arFrom['is_symlink']) || !empty($arTo['is_symlink']); $actionMoveInSymlink = false; if ($actionWithSymlink) { $actionMoveInSymlink = $arFrom['symlink_section_data_link'] == $arTo['symlink_section_data_link']; } //drop == true if this action is @move@ //not symlink and move! but if action rename in symlink - run this code block if (!$actionWithSymlink && $drop || $actionWithSymlink && $actionRename || $actionMoveInSymlink) { $this->_onEvent($arFrom['parent_id'] != $arTo['parent_id'] ? 'Move' : 'Rename', $arFrom['item_id'], 'FOLDER', array('TO' => $arFrom['parent_id'] != $arTo['parent_id'] ? $arTo["parent_id"] : $arTo["basename"])); $GLOBALS['DB']->StartTransaction(); if (isset($options['overwrite']) && $arTo['is_dir'] === true && $arTo['item_id'] !== $arFrom['item_id']) { $se->Delete($arTo['item_id']); } $result = $se->Update($arFrom["item_id"], array("NAME" => $arTo["basename"], "IBLOCK_SECTION_ID" => $arTo["parent_id"])); // TODO: need to check permissions ??? if ($result == false) { $GLOBALS['DB']->Rollback(); return $this->ThrowError("409 Conflict", "SECTION_IS_NOT_UPDATED", $se->LAST_ERROR ? $se->LAST_ERROR : GetMessage("WD_FILE_ERROR102"), __LINE__); } else { $arCacheCleanID[] = 'section' . $arFrom["item_id"]; $this->ClearCache("section"); $GLOBALS['DB']->Commit(); } } else { if (isset($options['overwrite']) && $arTo['is_dir'] === true) { $se->Delete($arTo['item_id']); } if ($arTo["item_id"] === false) { $arPath = explode("/", $options["dest_url"]); $this->IsDir(array('path' => "/" . implode("/", array_slice($arPath, 0, -1)))); if ($this->arParams["not_found"] === false) { if ($this->arParams["item_id"] == 0) { // root $arTo["dir_array"] = array("LEFT_MARGIN" => 0, "RIGHT_MARGIN" => $this->INT_MAX); } if ($arTo["dir_array"]["LEFT_MARGIN"] - 1 < $arFrom["dir_array"]["LEFT_MARGIN"] && $arFrom["dir_array"]["RIGHT_MARGIN"] < $arTo["dir_array"]["RIGHT_MARGIN"] + 1) { // If folder moved to upper folder } elseif ($arTo["dir_array"]["RIGHT_MARGIN"] < $arFrom["dir_array"]["LEFT_MARGIN"] || $arFrom["dir_array"]["RIGHT_MARGIN"] < $arTo["dir_array"]["LEFT_MARGIN"]) { // if folder moved to neighbourhood folder } elseif ($arFrom["dir_array"]["LEFT_MARGIN"] - 1 <= $arTo["dir_array"]["LEFT_MARGIN"] && $arTo["dir_array"]["RIGHT_MARGIN"] <= $arFrom["dir_array"]["RIGHT_MARGIN"] + 1 || $arTo["dir_array"]["ID"] == $arFrom["dir_array"]["ID"]) { return $this->ThrowError("400 Bad Request", "SECTION_IS_NOT_UPDATED", GetMessage("WD_FILE_ERROR100"), __LINE__); } if (!empty($arTo['is_symlink'])) { $parentSectionId = $this->arParams["item_id"]; if ($this->arParams["item_id"] == $arTo['symlink_section_data_link']['ID']) { $parentSectionId = $arTo['symlink_section_data_link'][self::UF_LINK_SECTION_ID]; } $arTo["dir_array"]["ID"] = $se->Add(array("IBLOCK_ID" => $arTo['symlink_section_data']['IBLOCK_ID'], "IBLOCK_SECTION_ID" => $parentSectionId, "NAME" => end(array_slice($arPath, -1, 1)))); $arTo["dir_array"]['IBLOCK_ID'] = $arTo['symlink_section_data']['IBLOCK_ID']; } else { $arTo["dir_array"]["ID"] = $se->Add(array("IBLOCK_ID" => $this->IBLOCK_ID, "IBLOCK_SECTION_ID" => $this->arParams["item_id"], "NAME" => end(array_slice($arPath, -1, 1)))); } if ($arTo["dir_array"]["ID"] === false) { return $this->ThrowError("409 Conflict", "FOLDER_IS_NOT_MOVED", str_replace(array("#FOLDER#", "#TEXT_ERROR#"), array("/" . implode("/", $arPath), $se->LAST_ERROR), GetMessage("WD_FILE_ERROR103")), __LINE__); } else { $returnSection = $arTo["dir_array"]["ID"]; $this->_onEvent('Add', $returnSection, 'FOLDER'); } } } else { return $this->ThrowError("409 Conflict", "FOLDER_IS_NOT_MOVED", str_replace(array("#FOLDER#", "#TEXT_ERROR#"), array($options["dest_url"], $se->LAST_ERROR), GetMessage("WD_FILE_ERROR103")), __LINE__); } $arFrom["dir_array"]['is_symlink'] = !empty($arFrom['is_symlink']); $arFrom["dir_array"]['symlink_section_data'] = empty($arFrom['symlink_section_data']) ? array() : $arFrom['symlink_section_data']; $arTo["dir_array"]['is_symlink'] = !empty($arTo['is_symlink']); $arTo["dir_array"]['symlink_section_data'] = empty($arTo['symlink_section_data']) ? array() : $arTo['symlink_section_data']; $result = $this->copy_commit($arFrom["dir_array"], $arTo["dir_array"], $options, $drop); if ($result === true && $drop === true) { if ($actionWithSymlink) { $this::$lastActionMoveWithSymlink = true; $this->DELETE(array("section_id" => $arFrom["item_id"])); } else { CIBlockSection::Delete($arFrom["item_id"]); } $this->ClearCache("section"); } elseif (is_string($result) && strpos($result, "403") !== false) { return $this->ThrowAccessDenied(__LINE__); } } if ($result !== true) { return $result; } } if ($arFrom['element_id']) { CWebDavDiskDispatcher::sendEventToOwners($arFrom['element_array'], null, 'copy'); } elseif ($arFrom['is_dir']) { CWebDavDiskDispatcher::sendEventToOwners(null, $arFrom['dir_array'], 'copy'); } $this->ClearCache($arCacheCleanID, 'local'); if (isset($returnSection)) { $this->arParams["changed_section_id"] = $returnSection; } if ($statusSymlinkDelete !== false) { return $statusSymlinkDelete; } return $arTo["not_found"] ? "201 Created" : "204 No Content"; }
/** * Сохраняет запись * @return bool */ public function save() { if (!\CModule::IncludeModule('iblock') || !$this->validate() || !$this->riseEvent('beforeSave')) { return false; } $ib = new \CIBlockElement(); //собираем поля элемента $arFields = array(); $arProperties = array(); foreach ($this->getAttributes() as $key => $attr) { if (strpos($key, 'property_') === 0) { $arProperties[$attr->getParam('id')] = $attr->getValueToDb(); } elseif ($key !== 'id') { $arFields[strtoupper($key)] = $attr->getValueToDb(); } } //записываем поля элемента if (!$this->isNew()) { $id = $this->getAttribute('id')->getValue(); /* меняем местами обновление свойств инфоблока и стандартных полей, для правильного срабатывания событий, fix at 30/09/2016 */ //отдельно обновляем пользовательские свойства, чтобы не перезаписывать те, которы не были обновлены //если обновлять свойства вместе с основными параметрами, будут возникать дубли, поэтому свойства сохраняем отдельно if (!empty($arProperties)) { \CIBlockElement::SetPropertyValuesEx($id, $this->getAttribute('iblock_id')->getValue(), $arProperties); } //при обновлении элемента сначала записываем базовые поля $res = $ib->Update($id, $arFields); if (!$res) { throw new Exception($ib->LAST_ERROR); } $this->riseEvent('afterSave'); } else { //при вставке нового элемента записываем сразу все пользовательские свойства if (!empty($arProperties)) { $arFields['PROPERTY_VALUES'] = $arProperties; } $new = $ib->Add($arFields); if ($new) { $this->getAttribute('id')->setValue($new); $this->riseEvent('afterSave'); } else { throw new Exception($ib->LAST_ERROR); } } if (isset($arFields['IBLOCK_SECTION_ID']) && is_array($arFields['IBLOCK_SECTION_ID'])) { \CIBlockElement::SetElementSection($this->getAttribute('id')->getValue(), $arFields['IBLOCK_SECTION_ID']); } return true; }