Exemplo n.º 1
0
 public static function Delete($ID)
 {
     global $DB, $APPLICATION, $USER;
     $USER_ID = is_object($USER) ? intval($USER->GetID()) : 0;
     $ID = IntVal($ID);
     $APPLICATION->ResetException();
     foreach (GetModuleEvents("iblock", "OnBeforeIBlockElementDelete", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME'];
             $err_id = false;
             if ($ex = $APPLICATION->GetException()) {
                 $err .= ': ' . $ex->GetString();
                 $err_id = $ex->GetID();
             }
             $APPLICATION->throwException($err, $err_id);
             return false;
         }
     }
     $arSql = array("ID='" . $ID . "'", "WF_PARENT_ELEMENT_ID='" . $ID . "'");
     foreach ($arSql as $strWhere) {
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tID\n\t\t\t\t\t,IBLOCK_ID\n\t\t\t\t\t,WF_PARENT_ELEMENT_ID\n\t\t\t\t\t,WF_STATUS_ID\n\t\t\t\t\t,PREVIEW_PICTURE\n\t\t\t\t\t,DETAIL_PICTURE\n\t\t\t\t\t,XML_ID as EXTERNAL_ID\n\t\t\t\t\t,CODE\n\t\t\t\t\t,NAME\n\t\t\t\tFROM b_iblock_element\n\t\t\t\tWHERE " . $strWhere . "\n\t\t\t\tORDER BY ID DESC\n\t\t\t";
         $z = $DB->Query($strSql);
         while ($zr = $z->Fetch()) {
             $elementId = (int) $zr["ID"];
             $VERSION = CIBlockElement::GetIBVersion($zr["IBLOCK_ID"]);
             $db_res = CIBlockElement::GetProperty($zr["IBLOCK_ID"], $zr["ID"], "sort", "asc", array("PROPERTY_TYPE" => "F"));
             $arIBlockFields = CIBLock::GetArrayByID($zr["IBLOCK_ID"], "FIELDS");
             if (IntVal($zr["WF_PARENT_ELEMENT_ID"]) <= 0 && $arIBlockFields["LOG_ELEMENT_DELETE"]["IS_REQUIRED"] == "Y") {
                 $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();
                     $arIblock = CIBlock::GetArrayByID($zr['IBLOCK_ID']);
                     $res_log = 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_DELETE", "iblock", $zr["IBLOCK_ID"], serialize($res_log));
                 }
             }
             $piId = \Bitrix\Iblock\PropertyIndex\Manager::resolveElement($zr["IBLOCK_ID"], $zr["ID"]);
             foreach (GetModuleEvents("iblock", "OnIBlockElementDelete", true) as $arEvent) {
                 ExecuteModuleEventEx($arEvent, array($elementId, $zr));
             }
             while ($res = $db_res->Fetch()) {
                 CIBlockElement::DeleteFile($res["VALUE"], $zr["ID"], "PROPERTY", $zr["WF_PARENT_ELEMENT_ID"], $zr["IBLOCK_ID"]);
             }
             if ($VERSION == 2) {
                 if (!$DB->Query("DELETE FROM b_iblock_element_prop_m" . $zr["IBLOCK_ID"] . " WHERE IBLOCK_ELEMENT_ID = " . $elementId)) {
                     return false;
                 }
                 if (!$DB->Query("DELETE FROM b_iblock_element_prop_s" . $zr["IBLOCK_ID"] . " WHERE IBLOCK_ELEMENT_ID = " . $elementId)) {
                     return false;
                 }
             } else {
                 if (!$DB->Query("DELETE FROM b_iblock_element_property WHERE IBLOCK_ELEMENT_ID = " . $elementId)) {
                     return false;
                 }
             }
             static $arDelCache = array();
             if (!is_set($arDelCache, $zr["IBLOCK_ID"])) {
                 $arDelCache[$zr["IBLOCK_ID"]] = false;
                 $db_ps = $DB->Query("SELECT ID,IBLOCK_ID,VERSION,MULTIPLE FROM b_iblock_property WHERE PROPERTY_TYPE='E' AND (LINK_IBLOCK_ID=" . $zr["IBLOCK_ID"] . " OR LINK_IBLOCK_ID=0 OR LINK_IBLOCK_ID IS NULL)");
                 while ($ar_ps = $db_ps->Fetch()) {
                     if ($ar_ps["VERSION"] == 2) {
                         if ($ar_ps["MULTIPLE"] == "Y") {
                             $strTable = "b_iblock_element_prop_m" . $ar_ps["IBLOCK_ID"];
                         } else {
                             $strTable = "b_iblock_element_prop_s" . $ar_ps["IBLOCK_ID"];
                         }
                     } else {
                         $strTable = "b_iblock_element_property";
                     }
                     $arDelCache[$zr["IBLOCK_ID"]][$strTable][] = $ar_ps["ID"];
                 }
             }
             if ($arDelCache[$zr["IBLOCK_ID"]]) {
                 foreach ($arDelCache[$zr["IBLOCK_ID"]] as $strTable => $arProps) {
                     if (strncmp("b_iblock_element_prop_s", $strTable, 23) == 0) {
                         $tableFields = $DB->GetTableFields($strTable);
                         foreach ($arProps as $prop_id) {
                             $strSql = "UPDATE " . $strTable . " SET PROPERTY_" . $prop_id . "=null";
                             if (isset($tableFields["DESCRIPTION_" . $prop_id])) {
                                 $strSql .= ",DESCRIPTION_" . $prop_id . "=null";
                             }
                             $strSql .= " WHERE PROPERTY_" . $prop_id . "=" . $zr["ID"];
                             if (!$DB->Query($strSql)) {
                                 return false;
                             }
                         }
                     } elseif (strncmp("b_iblock_element_prop_m", $strTable, 23) == 0) {
                         $tableFields = $DB->GetTableFields(str_replace("prop_m", "prop_s", $strTable));
                         $strSql = "SELECT IBLOCK_PROPERTY_ID, IBLOCK_ELEMENT_ID FROM " . $strTable . " WHERE IBLOCK_PROPERTY_ID IN (" . implode(", ", $arProps) . ") AND VALUE_NUM=" . $zr["ID"];
                         $rs = $DB->Query($strSql);
                         while ($ar = $rs->Fetch()) {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . str_replace("prop_m", "prop_s", $strTable) . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $ar["IBLOCK_PROPERTY_ID"] . "=null\n\t\t\t\t\t\t\t\t\t" . (isset($tableFields["DESCRIPTION_" . $ar["IBLOCK_PROPERTY_ID"]]) ? ",DESCRIPTION_" . $ar["IBLOCK_PROPERTY_ID"] . "=null" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ar["IBLOCK_ELEMENT_ID"] . "\n\t\t\t\t\t\t\t\t";
                             if (!$DB->Query($strSql)) {
                                 return false;
                             }
                         }
                         $strSql = "DELETE FROM " . $strTable . " WHERE IBLOCK_PROPERTY_ID IN (" . implode(", ", $arProps) . ") AND VALUE_NUM=" . $zr["ID"];
                         if (!$DB->Query($strSql)) {
                             return false;
                         }
                     } else {
                         $strSql = "DELETE FROM " . $strTable . " WHERE IBLOCK_PROPERTY_ID IN (" . implode(", ", $arProps) . ") AND VALUE_NUM=" . $zr["ID"];
                         if (!$DB->Query($strSql)) {
                             return false;
                         }
                     }
                 }
             }
             if (!$DB->Query("DELETE FROM b_iblock_section_element WHERE IBLOCK_ELEMENT_ID = " . $elementId)) {
                 return false;
             }
             $obIBlockElementRights = new CIBlockElementRights($zr["IBLOCK_ID"], $zr["ID"]);
             $obIBlockElementRights->DeleteAllRights();
             $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($zr["IBLOCK_ID"], $zr["ID"]);
             $ipropTemplates->delete();
             if (IntVal($zr["WF_PARENT_ELEMENT_ID"]) <= 0 && $zr["WF_STATUS_ID"] == 1 && CModule::IncludeModule("search")) {
                 CSearch::DeleteIndex("iblock", $elementId);
             }
             CIBlockElement::DeleteFile($zr["PREVIEW_PICTURE"], $zr["ID"], "PREVIEW", $zr["WF_PARENT_ELEMENT_ID"], $zr["IBLOCK_ID"]);
             CIBlockElement::DeleteFile($zr["DETAIL_PICTURE"], $zr["ID"], "DETAIL", $zr["WF_PARENT_ELEMENT_ID"], $zr["IBLOCK_ID"]);
             if (CModule::IncludeModule("workflow")) {
                 $DB->Query("DELETE FROM b_workflow_move WHERE IBLOCK_ELEMENT_ID=" . $elementId);
             }
             $DB->Query("DELETE FROM b_iblock_element_lock WHERE IBLOCK_ELEMENT_ID=" . $elementId);
             $DB->Query("DELETE FROM b_rating_vote WHERE ENTITY_TYPE_ID = 'IBLOCK_ELEMENT' AND ENTITY_ID = " . $elementId);
             $DB->Query("DELETE FROM b_rating_voting WHERE ENTITY_TYPE_ID = 'IBLOCK_ELEMENT' AND ENTITY_ID = " . $elementId);
             if (!$DB->Query("DELETE FROM b_iblock_element WHERE ID=" . $elementId)) {
                 return false;
             }
             if (isset(self::$elementIblock[$elementId])) {
                 unset(self::$elementIblock[$elementId]);
             }
             \Bitrix\Iblock\PropertyIndex\Manager::deleteElementIndex($zr["IBLOCK_ID"], $piId);
             if (CModule::IncludeModule("bizproc")) {
                 CBPDocument::OnDocumentDelete(array("iblock", "CIBlockDocument", $zr["ID"]), $arErrorsTmp);
             }
             foreach (GetModuleEvents("iblock", "OnAfterIBlockElementDelete", true) as $arEvent) {
                 ExecuteModuleEventEx($arEvent, array($zr));
             }
             CIBlock::clearIblockTagCache($zr['IBLOCK_ID']);
             unset($elementId);
         }
     }
     /************* QUOTA *************/
     $_SESSION["SESS_RECOUNT_DB"] = "Y";
     /************* QUOTA *************/
     return true;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
		}
		else
		{
			$WF_ID=0;
			$ID=0;
			if(is_array($IBLOCK_SECTION_ID))
			{
				foreach($IBLOCK_SECTION_ID as $id)
					if($id > 0)
						$str_IBLOCK_ELEMENT_SECTION[] = $id;
			}
			elseif($IBLOCK_SECTION_ID > 0)
			{
				$str_IBLOCK_ELEMENT_SECTION[] = $IBLOCK_SECTION_ID;
			}
			$ipropTemlates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($IBLOCK_ID, 0);
			$ipropTemlates->getValuesEntity()->setParents($str_IBLOCK_ELEMENT_SECTION);
		}
		$str_IPROPERTY_TEMPLATES = $ipropTemlates->findTemplates();
		$str_IPROPERTY_TEMPLATES["ELEMENT_PREVIEW_PICTURE_FILE_NAME"] = \Bitrix\Iblock\Template\Helper::convertModifiersToArray($str_IPROPERTY_TEMPLATES["ELEMENT_PREVIEW_PICTURE_FILE_NAME"]);
		$str_IPROPERTY_TEMPLATES["ELEMENT_DETAIL_PICTURE_FILE_NAME"] = \Bitrix\Iblock\Template\Helper::convertModifiersToArray($str_IPROPERTY_TEMPLATES["ELEMENT_DETAIL_PICTURE_FILE_NAME"]);
	}

	if($bCopy)
	{
		$str_XML_ID = "";
	}

	if($ID > 0 && !$bCopy)
	{
		if($view=="Y" || ($bBizproc && !$canWrite))