if ($arParams["SHOW_WORKFLOW"] || $this->StartResultCache(false, $arParams["CACHE_GROUPS"] === "N" ? false : $USER->GetGroups())) { if (!CModule::IncludeModule("iblock")) { $this->AbortResultCache(); ShowError(GetMessage("IBLOCK_MODULE_NOT_INSTALLED")); return; } if ($arParams["ELEMENT_ID"] > 0) { $ELEMENT_ID = $arParams["ELEMENT_ID"]; } else { //Handle case when ELEMENT_CODE used $ELEMENT_ID = CIBlockFindTools::GetElementID($arParams["ELEMENT_ID"], $arParams["ELEMENT_CODE"], false, false, array("IBLOCK_ACTIVE" => "Y", "IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE_DATE" => "Y", "ACTIVE" => "Y", "CHECK_PERMISSIONS" => "Y")); } if ($ELEMENT_ID) { $WF_SHOW_HISTORY = "N"; if ($arParams["SHOW_WORKFLOW"] && CModule::IncludeModule("workflow")) { $WF_ELEMENT_ID = CIBlockElement::WF_GetLast($ELEMENT_ID); $WF_STATUS_ID = CIBlockElement::WF_GetCurrentStatus($WF_ELEMENT_ID, $WF_STATUS_TITLE); $WF_STATUS_PERMISSION = CIBlockElement::WF_GetStatusPermission($WF_STATUS_ID); if ($WF_STATUS_ID == 1 || $WF_STATUS_PERMISSION < 1) { $WF_ELEMENT_ID = $ELEMENT_ID; } else { $WF_SHOW_HISTORY = "Y"; } $ELEMENT_ID = $WF_ELEMENT_ID; } //SELECT $arSelect = array_merge($arParams["FIELD_CODE"], array("ID", "CODE", "IBLOCK_ID", "IBLOCK_SECTION_ID", "SECTION_PAGE_URL", "NAME", "DETAIL_PICTURE", "PREVIEW_PICTURE", "DETAIL_TEXT", "DETAIL_PAGE_URL", "PREVIEW_TEXT_TYPE", "DETAIL_TEXT_TYPE")); $bGetProperty = count($arParams["PROPERTY_CODE"]) > 0 || $arParams["BROWSER_TITLE"] != "-" || $arParams["META_KEYWORDS"] != "-" || $arParams["META_DESCRIPTION"] != "-"; if ($bGetProperty) { $arSelect[] = "PROPERTY_*"; }
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; }
$arMeasureIDs = array(); $arCatalogRights = array(); // List build while($arRes = $rsData->NavNext(true, "f_")) { $sec_list_url = htmlspecialcharsbx(CIBlock::GetAdminSectionListLink($IBLOCK_ID, array('find_section_section'=>$f_ID))); $el_edit_url = htmlspecialcharsbx(CIBlock::GetAdminElementEditLink($IBLOCK_ID, $f_ID, array('find_section_section'=>intval($find_section_section), "WF"=>"Y")));; $sec_edit_url = htmlspecialcharsbx(CIBlock::GetAdminSectionEditLink($IBLOCK_ID, $f_ID, array('find_section_section'=>intval($find_section_section)))); $arRes_orig = $arRes; if($f_TYPE=="E") { if($bWorkFlow) { $LAST_ID = CIBlockElement::WF_GetLast($arRes['ID']); if($LAST_ID!=$arRes['ID']) { $rsData2 = CIBlockElement::GetList( Array(), Array( "ID"=>$LAST_ID, "SHOW_HISTORY"=>"Y" ), false, Array("nTopCount"=>1), $arSelectedFields ); if(isset($arCatGroup)) { $arRes_tmp = Array();
//This function returns array with prices description and access rights //in case catalog module n/a prices get values from element properties $arResultPrices = CIBlockPriceTools::GetCatalogPrices($arParams["IBLOCK_ID"], $arParams["PRICE_CODE"]); $arResultPricesAllow = CIBlockPriceTools::GetAllowCatalogPrices($arResultPrices); if ($bCatalog && $boolNeedCatalogCache && !empty($arResultPricesAllow)) { $boolNeedCatalogCache = CIBlockPriceTools::SetCatalogDiscountCache($arResultPricesAllow, $USER->GetUserGroupArray()); } $WF_SHOW_HISTORY = "N"; if ($arParams["SHOW_WORKFLOW"] && CModule::IncludeModule("workflow")) { $arResultModules['workflow'] = true; $WF_ELEMENT_ID = CIBlockElement::WF_GetLast($arParams["ELEMENT_ID"]); $WF_STATUS_ID = CIBlockElement::WF_GetCurrentStatus($WF_ELEMENT_ID, $WF_STATUS_TITLE); $WF_STATUS_PERMISSION = CIBlockElement::WF_GetStatusPermission($WF_STATUS_ID); if ($WF_STATUS_ID == 1 || $WF_STATUS_PERMISSION < 1) $WF_ELEMENT_ID = $arParams["ELEMENT_ID"]; else $WF_SHOW_HISTORY = "Y"; $arParams["ELEMENT_ID"] = $WF_ELEMENT_ID; } //SELECT $arSelect = array( "ID", "IBLOCK_ID",
public static function WF_GetCurrentStatus($ELEMENT_ID, &$STATUS_TITLE) { global $DB; if (CModule::IncludeModule("workflow")) { $ELEMENT_ID = intval($ELEMENT_ID); $WF_ID = intval(CIBlockElement::WF_GetLast($ELEMENT_ID)); if ($WF_ID <= 0) { $WF_ID = $ELEMENT_ID; } if ($WF_ID > 0) { $strSql = "SELECT E.WF_STATUS_ID, S.TITLE " . "FROM b_iblock_element E, b_workflow_status S " . "WHERE E.ID = " . $WF_ID . " " . "\tAND\tS.ID = E.WF_STATUS_ID"; $z = $DB->Query($strSql); $zr = $z->Fetch(); $STATUS_ID = $zr["WF_STATUS_ID"]; $STATUS_TITLE = $zr["TITLE"]; } } return intval($STATUS_ID); }
if(!($arElement = $rsElement->Fetch())) { $error = new _CIBlockError(1, "BAD_ELEMENT", GetMessage("IBLOCK_BAD_ELEMENT")); $APPLICATION->SetTitle($arIBTYPE["ELEMENT_NAME"].": ".GetMessage("IBLOCK_EDIT_TITLE")); $errorTriger = true; } } if (!$errorTriger) { // workflow mode $isLocked = false; if($ID>0 && $WF=="Y") { // get ID of the last record in workflow $WF_ID = CIBlockElement::WF_GetLast($ID); // check for edit permissions $STATUS_ID = CIBlockElement::WF_GetCurrentStatus($WF_ID, $STATUS_TITLE); $STATUS_PERMISSION = CIBlockElement::WF_GetStatusPermission($STATUS_ID); if($STATUS_ID>1 && $STATUS_PERMISSION<2) { $error = new _CIBlockError(1, "ACCESS_DENIED", GetMessage("IBLOCK_ACCESS_DENIED_STATUS")); $errorTriger = true; } elseif($STATUS_ID==1) { $WF_ID = $ID; $STATUS_ID = CIBlockElement::WF_GetCurrentStatus($WF_ID, $STATUS_TITLE); $STATUS_PERMISSION = CIBlockElement::WF_GetStatusPermission($STATUS_ID);
function CheckWebRights($method = "", $arParams = array(), $simple = true) { if ($this->withoutAuthorization) { return true; } $strong = $method !== ""; $path = ''; if (is_array($arParams['arElement'])) { $path = isset($arParams['arElement']['item_id']) ? $arParams['arElement']['item_id'] : ''; } elseif (is_string($arParams['arElement'])) { $path = $arParams['arElement']; } $result = $this->CheckRights($method, $strong, $path); if (!$result || $simple) { return $result; } $arError = array(); $action = strtolower(is_set($arParams, "action") ? $arParams["action"] : $arParams["ACTION"]); $arElement = is_set($arParams, "arElement") ? $arParams["arElement"] : array(); static $arErrors = array(); $static_id = md5(serialize(array($action, $arElement["ID"], $GLOBALS["USER"]->GetID()))); if (array_key_exists($static_id, $arErrors)) { $arError = $arErrors[$static_id]; } else { if ($this->e_rights) { foreach (array('arElement', 'from', 'to') as $elm) { if (is_set($arParams, $elm)) { if ((!isset($arParams[$elm]['not_found']) || $arParams[$elm]['not_found'] === true) && !in_array($action, array('create', 'copy', 'move', 'mkcol'))) { $arError[] = array("id" => "bad_element", "text" => GetMessage("WD_FILE_ERROR105")); } } } if (empty($arError)) { if ($action == 'copy') { //from[] //to[] $arTo = isset($arParams['to']) ? $arParams['to'] : array(); $arFrom = isset($arParams['from']) ? $arParams['from'] : array(); $nCount = min(sizeof($arTo), sizeof($arFrom)); for ($i = 0; $i < $nCount; $i++) { $To = $arTo[$i]; $From = $arFrom[$i]; $type = $To['is_file'] ? 'ELEMENT' : 'SECTION'; $id = $To['not_found'] ? $To['parent_id'] : $To['item_id']; $op = $From['is_file'] ? 'section_element_bind' : 'section_section_bind'; if (!$this->GetPermission($type, $id, $op)) { $arError[] = array("id" => "", "text" => GetMessage("WD_ACCESS_DENIED")); } } } elseif ($action == 'create' || $action == 'mkcol') { //arElement //null if (empty($arElement)) { $arParent = $this->GetObject(); $bAllowEdit = false; if ($arParent['not_found'] === false) { $bAllowEdit = $this->GetPermission($arParent['is_file'] ? 'ELEMENT' : 'SECTION', $arParent['item_id'], 'element_edit'); } return $bAllowEdit; } else { $type = 'SECTION'; if (isset($arElement['parent_id']) && $arElement['parent_id'] > 0) { $id = $arElement['parent_id']; } else { $id = $this->IBLOCK_ID; $type = 'IBLOCK'; } if ($action == 'mkcol') { return $this->GetPermission($type, $id, 'section_section_bind'); } if ($arElement['is_dir']) { if (!$this->GetPermission($type, $id, 'section_section_bind')) { $arError[] = array("id" => "", "text" => GetMessage("WD_ACCESS_DENIED")); } } else { if (!empty($arParams['create_element_in_section']) || $this->workflow != "workflow" && $this->workflow != "bizproc") { if (!$this->GetPermission($type, $id, 'section_element_bind')) { $arError[] = array("id" => "cannot_create", "text" => GetMessage("WD_ACCESS_DENIED")); } } elseif ($this->workflow == "workflow") { $db_res = CWorkflowStatus::GetDropDownList("N", "desc"); if (!($db_res && ($res = $db_res->Fetch()))) { $arError[] = array("id" => "bad_wf_statuses", "text" => GetMessage("WD_ACCESS_DENIED")); } } elseif ($this->workflow == 'bizproc') { $arDocumentStates = CBPDocument::GetDocumentStates($this->wfParams['DOCUMENT_TYPE'], null); $arUserGroups = $this->USER["GROUPS"]; $arUserGroups[] = "Author"; $canWrite = false; if (!CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::WriteDocument, $GLOBALS["USER"]->GetID(), $this->wfParams['DOCUMENT_TYPE'], array("IBlockPermission" => $this->permission, "AllUserGroups" => $arUserGroups, "DocumentStates" => $arDocumentStates))) { $arError[] = array("id" => "bad_bizproc_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } } } } elseif ($action == 'delete' || $action == 'undelete') { //arElement $type = $arElement['is_dir'] ? 'SECTION' : 'ELEMENT'; if ($type == 'ELEMENT') { $res = $this->GetPermission($type, $arElement['item_id'], 'element_delete'); if (!$res) { $arError[] = array("id" => "", "text" => GetMessage("WD_ACCESS_DENIED")); } } else { $res = $this->GetPermission($type, $arElement['item_id'], 'section_delete', false); if (!$res) { $arError[] = array("id" => "", "text" => GetMessage("WD_ACCESS_DENIED")); } } } elseif ($action == 'destroy') { //arElement $id = $arElement['item_id']; $type = $arElement['is_dir'] ? 'SECTION' : 'ELEMENT'; $op = $arElement['is_dir'] ? 'section_delete' : 'element_delete'; if (!$this->GetPermission($type, $id, $op, false)) { $arError[] = array("id" => "", "text" => GetMessage("WD_ACCESS_DENIED")); } } elseif ($action == 'edit' || $action == 'lock' || $action == 'proppatch' || $action == 'delete_dropped') { //arElement $id = $arElement['item_id']; $type = $arElement['is_dir'] ? 'SECTION' : 'ELEMENT'; if ($arElement['is_dir']) { if (!$this->GetPermission($type, $id, 'section_edit')) { $arError[] = array("id" => "", "text" => GetMessage("WD_ACCESS_DENIED")); } } else { if ($arElement["LOCK_STATUS_BP"] == "red") { $arError[] = array("id" => "locked", "text" => GetMessage("WD_FILE_ERROR107")); } elseif ($this->check_creator && $arElement["CREATED_BY"] != $GLOBALS["USER"]->GetID()) { $arError[] = array("id" => "bad_author", "text" => GetMessage("WD_FILE_ERROR108")); } elseif ($this->GetPermission($type, $id, 'element_edit_any_wf_status')) { true; } elseif ($this->workflow == "workflow" && $this->GetPermission($type, $id, 'element_edit')) { $arWorkFlow = array("LAST_ID" => CIBlockElement::WF_GetLast($arElement["item_id"])); $arWorkFlow["STATUS_ID"] = CIBlockElement::WF_GetCurrentStatus($arWorkFlow["LAST_ID"], $arWorkFlow["STATUS_TITLE"]); $arWorkFlow["STATUS_PERMISSION"] = CIBlockElement::WF_GetStatusPermission($arWorkFlow["STATUS_ID"]); if ($arWorkFlow["STATUS_ID"] > 1 && $arWorkFlow["STATUS_PERMISSION"] < 2) { $arError[] = array("id" => "bad_wf_status_permission", "text" => GetMessage("WD_FILE_ERROR109")); } } elseif ($this->workflow == 'bizproc' && $this->GetPermission($type, $id, 'element_edit')) { $documentId = $this->wfParams['DOCUMENT_TYPE']; $documentId[2] = $arElement["item_id"]; $arDocumentStates = CBPDocument::GetDocumentStates($this->wfParams['DOCUMENT_TYPE'], $documentId); $arUserGroups = $this->USER["GROUPS"]; if ($arElement["CREATED_BY"] == $GLOBALS["USER"]->GetID()) { $arUserGroups[] = "Author"; } if (!CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::WriteDocument, $GLOBALS["USER"]->GetID(), $documentId, array("IBlockPermission" => $this->permission, "AllUserGroups" => $arUserGroups, "DocumentStates" => $arDocumentStates))) { $arError[] = array("id" => "bad_bizproc_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } else { $arError[] = array("id" => "bad_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } } elseif ($action == 'read' || $action == 'propfind') { //arElement, null if ($arElement) { $id = $arElement['item_id']; $type = $arElement['is_dir'] ? 'SECTION' : 'ELEMENT'; $op = $arElement['is_dir'] ? 'section_read' : 'element_read'; if (!$this->GetPermission($type, $id, $op)) { $arError[] = array("id" => "bad_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } if ($type == 'SECTION' && $id == $this->GetMetaID('TRASH')) { if (!$this->GetPermission($type, $id, 'section_delete')) { $arError[] = array("id" => "bad_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } } else { if (!$this->GetPermission('IBLOCK', $this->IBLOCK_ID, 'section_read')) { $arError[] = array("id" => "bad_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } } elseif ($action == 'move') { //from // auto recusive //to // auto recusive $arTo = isset($arParams['to']) ? $arParams['to'] : array(); $arFrom = isset($arParams['from']) ? $arParams['from'] : array(); $nCount = min(sizeof($arTo), sizeof($arFrom)); for ($i = 0; $i < $nCount; $i++) { $To = $arTo[$i]; $From = $arFrom[$i]; $type = $From['is_dir'] ? 'SECTION' : 'ELEMENT'; $id = $From['item_id']; $op = $From['is_dir'] ? 'section_edit' : 'element_edit'; if (!$this->GetPermission($type, $id, $op)) { $arError[] = array("id" => "bad_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } if ($To['not_found']) { $type = 'SECTION'; $id = $To['parent_id']; $op = $arFrom['is_dir'] ? 'section_section_bind' : 'section_element_bind'; // TODO: bizproc ? if (!$this->GetPermission($type, $id, $op)) { $arError[] = array("id" => "bad_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } else { $type = $To['is_dir'] ? 'SECTION' : 'ELEMENT'; $id = $To['item_id']; $op = $To['is_dir'] ? $arFrom['is_dir'] ? 'section_section_bind' : 'section_element_bind' : 'element_edit'; // TODO: bizproc ? if (!$this->GetPermission($type, $id, $op)) { $arError[] = array("id" => "bad_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } } } } } else { // check iblock rights if ($this->permission < "R") { $arError[] = array("id" => "cannot_read", "text" => GetMessage("WD_ACCESS_DENIED")); } elseif ($this->permission > "U") { true; } elseif ($action == "read" || $action == "propfind") { true; } elseif ($this->permission < "U") { $arError[] = array("id" => "cannot_workflow", "text" => GetMessage("WD_ACCESS_DENIED")); } elseif ($action == "create") { if ($this->workflow != "workflow" && $this->workflow != "bizproc") { $arError[] = array("id" => "cannot_write", "text" => GetMessage("WD_ACCESS_DENIED")); } elseif ($this->workflow == "workflow") { $db_res = CWorkflowStatus::GetDropDownList("N", "desc"); if (!($db_res && ($res = $db_res->Fetch()))) { $arError[] = array("id" => "bad_wf_statuses", "text" => GetMessage("WD_ACCESS_DENIED")); } } elseif ($this->workflow == 'bizproc') { $arDocumentStates = CBPDocument::GetDocumentStates($this->wfParams['DOCUMENT_TYPE'], null); $arUserGroups = $this->USER["GROUPS"]; $arUserGroups[] = "Author"; $canWrite = false; if (!CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::WriteDocument, $GLOBALS["USER"]->GetID(), $this->wfParams['DOCUMENT_TYPE'], array("IBlockPermission" => $this->permission, "AllUserGroups" => $arUserGroups, "DocumentStates" => $arDocumentStates))) { $arError[] = array("id" => "bad_bizproc_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } } elseif (!is_array($arElement) || empty($arElement)) { $arError[] = array("id" => "bad_element", "text" => GetMessage("WD_FILE_ERROR105")); } elseif ($action == "clone") { if ($this->workflow != "bizproc") { $arError[] = array("id" => "bad_workflow", "text" => GetMessage("WD_FILE_ERROR106")); } else { // User has to have permissions to read parent document && to create new document $arDocumentStates = CBPDocument::GetDocumentStates($this->wfParams['DOCUMENT_TYPE'], null); if (!($arElement["PERMISSION"] >= "R" && CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::WriteDocument, $GLOBALS["USER"]->GetID(), $this->wfParams['DOCUMENT_TYPE'], array("IBlockPermission" => $this->permission, "AllUserGroups" => array_merge($this->USER["GROUPS"], array("author")), "DocumentStates" => $arDocumentStates)))) { $arError[] = array("id" => "bad_permission", "text" => GetMessage("WD_ACCESS_DENIED")); } } } elseif (!in_array($action, array("delete", "move", "edit", "unlock", "lock"))) { $arError[] = array("id" => "bad_action", "text" => GetMessage("WD_ERROR_BAD_ACTION")); } else { if ($arElement["LOCK_STATUS_BP"] == "red") { $arError[] = array("id" => "locked", "text" => GetMessage("WD_FILE_ERROR107")); } elseif ($arElement["LOCK_STATUS"] == "red" && ($action != "unlock" || $arElement["SHOW"]["UNLOCK"] != "Y")) { $arError[] = array("id" => "locked", "text" => str_replace(array("#ID#", "#DATE#"), array($arElement["locked_by"], $arElement["date_lock"]), GetMessage("WD_ERROR_ELEMENT_LOCKED"))); } elseif ($this->check_creator && $arElement["CREATED_BY"] != $GLOBALS["USER"]->GetID()) { $arError[] = array("id" => "bad_author", "text" => GetMessage("WD_FILE_ERROR108")); } elseif ($this->workflow == "workflow") { $arWorkFlow = array("LAST_ID" => CIBlockElement::WF_GetLast($arElement["item_id"])); $arWorkFlow["STATUS_ID"] = CIBlockElement::WF_GetCurrentStatus($arWorkFlow["LAST_ID"], $arWorkFlow["STATUS_TITLE"]); $arWorkFlow["STATUS_PERMISSION"] = CIBlockElement::WF_GetStatusPermission($arWorkFlow["STATUS_ID"]); if ($arWorkFlow["STATUS_ID"] > 1 && $arWorkFlow["STATUS_PERMISSION"] < 2) { $arError[] = array("id" => "bad_wf_status_permission", "text" => GetMessage("WD_FILE_ERROR109")); } } elseif ($this->workflow == 'bizproc') { $documentId = $this->wfParams['DOCUMENT_TYPE']; $documentId[2] = $arElement["item_id"]; $arDocumentStates = CBPDocument::GetDocumentStates($this->wfParams['DOCUMENT_TYPE'], $documentId); $arUserGroups = $this->USER["GROUPS"]; if ($arElement["CREATED_BY"] == $GLOBALS["USER"]->GetID()) { $arUserGroups[] = "Author"; } if (!CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::WriteDocument, $GLOBALS["USER"]->GetID(), $documentId, array("IBlockPermission" => $this->permission, "AllUserGroups" => $arUserGroups, "DocumentStates" => $arDocumentStates))) { $arError[] = array("id" => "bad_bizproc_permision", "text" => GetMessage("WD_ACCESS_DENIED")); } } } } $arErrors[$static_id] = $arError; } if (empty($arError)) { $e = new CAdminException($arError); $this->LAST_ERROR = $e->GetString(); if ($this->LAST_ERROR == '<br>') { $this->LAST_ERROR = ''; } return true; } else { $e = new CAdminException($arError); $this->LAST_ERROR = $e->GetString(); if ($this->LAST_ERROR == '<br>') { $this->LAST_ERROR = ''; } return false; } }
ShowError(GetMessage("WD_ACCESS_DENIED")); return 0; } $res = array("UNLOCK" => "N", "EDIT" => CWebDavIblock::CheckRight($arResult["ELEMENT"]["PERMISSION"], "element_edit") >= "W" ? "Y" : "N", "DELETE" => CWebDavIblock::CheckRight($arResult["ELEMENT"]["PERMISSION"], "element_edit") >= "W" ? "Y" : "N", "HISTORY" => "Y"); if ($arResult["ELEMENT"]["LOCK_STATUS"] == "yellow" || $arResult["ELEMENT"]["LOCK_STATUS"] == "red" && (CWorkflow::IsAdmin() || $USER->CanDoOperation('webdav_change_settings'))) { $res["UNLOCK"] = "Y"; } if ($arResult["ELEMENT"]["LOCK_STATUS"] == "red") { $res["EDIT"] = "N"; } elseif (CWebDavIblock::CheckRight($arResult["ELEMENT"]["PERMISSION"], "element_bizproc_start") == "U") { $res["EDIT"] = $arResult["ELEMENT"]["WF_STATUS_ID"] > 1 && $arResult["WF_STATUSES_PERMISSION"][$arResult["ELEMENT"]["WF_STATUS_ID"]] < 2 ? "N" : "Y"; } $arResult["ELEMENT"]["SHOW"] = $res; /************** Last element ***************************************/ $arResult["ELEMENT"]["LAST"] = $arResult["ELEMENT"]; $LAST_ID = CIBlockElement::WF_GetLast($arResult["ELEMENT"]["ID"]); if ($LAST_ID != $arResult["ELEMENT"]["ID"]) { $db_res = CIBlockElement::GetByID($LAST_ID); if ($db_res && ($res = $db_res->Fetch())) { $arResult["ELEMENT"]["LAST"] = $res; } } /************** Versions *******************************************/ $db_res = CIBlockElement::WF_GetHistoryList($arParams['ELEMENT_ID'], $by = 's_id', $order = 'desc', array("IBLOCK_ID" => $arParams['IBLOCK_ID']), $is_filtered); if ($db_res) { $db_res->NavStart($arParams["PAGE_ELEMENTS"]); $arResult["NAV_RESULT"] = $db_res; $arResult["NAV_STRING"] = $db_res->GetPageNavStringEx($navComponentObject, GetMessage("WD_DOCUMENTS"), $arParams["PAGE_NAVIGATION_TEMPLATE"]); if ($this->__parent) { $this->__parent->arResult["HISTORY_LENGTH"] = $db_res->NavRecordCount; }