protected function processActionCheckDataElementCreation() { if ($_POST["save"] != "Y" && $_POST["changePostFormTab"] != "lists" && !check_bitrix_sessid()) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_CONNECTION_MODULE_IBLOCK')))); } if (!Loader::IncludeModule('bizproc')) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_CONNECTION_MODULE_BIZPROC')))); } if (!Loader::includeModule('iblock')) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_CONNECTION_MODULE_IBLOCK')))); } $this->iblockId = intval($this->request->getPost('IBLOCK_ID')); $this->iblockTypeId = COption::GetOptionString("lists", "livefeed_iblock_type_id"); $this->checkPermissionElement(); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $templateId = intval($_POST['TEMPLATE_ID']); $documentType = BizprocDocument::generateDocumentComplexType(COption::GetOptionString("lists", "livefeed_iblock_type_id"), $this->iblockId); if (!empty($templateId)) { if (CModule::IncludeModule('bizproc')) { if (!CBPWorkflowTemplateLoader::isConstantsTuned($templateId)) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_CONSTANTS_TUNED_NEW')))); $this->sendJsonErrorResponse(); } } } else { if (CModule::IncludeModule("bizproc")) { $templateObject = CBPWorkflowTemplateLoader::getTemplatesList(array('ID' => 'DESC'), array('DOCUMENT_TYPE' => $documentType, 'AUTO_EXECUTE' => CBPDocumentEventType::Create), false, false, array('ID')); $template = $templateObject->fetch(); if (!empty($template)) { if (!CBPWorkflowTemplateLoader::isConstantsTuned($template["ID"])) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_CONSTANTS_TUNED_NEW')))); $this->sendJsonErrorResponse(); } } else { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_NOT_BIZPROC_TEMPLATE')))); $this->sendJsonErrorResponse(); } } } $list = new CList($this->iblockId); $fields = $list->getFields(); $elementData = array("IBLOCK_ID" => $this->iblockId, "NAME" => $_POST["NAME"]); $props = array(); foreach ($fields as $fieldId => $field) { if ($fieldId == "PREVIEW_PICTURE" || $fieldId == "DETAIL_PICTURE") { $elementData[$fieldId] = $_FILES[$fieldId]; if (isset($_POST[$fieldId . "_del"]) && $_POST[$fieldId . "_del"] == "Y") { $elementData[$fieldId]["del"] = "Y"; } } elseif ($fieldId == "PREVIEW_TEXT" || $fieldId == "DETAIL_TEXT") { if (isset($field["SETTINGS"]) && is_array($field["SETTINGS"]) && $field["SETTINGS"]["USE_EDITOR"] == "Y") { $elementData[$fieldId . "_TYPE"] = "html"; } else { $elementData[$fieldId . "_TYPE"] = "text"; } $elementData[$fieldId] = $_POST[$fieldId]; } elseif ($fieldId == 'ACTIVE_FROM' || $fieldId == 'ACTIVE_TO') { $elementData[$fieldId] = array_shift($_POST[$fieldId]); } elseif ($list->is_field($fieldId)) { $elementData[$fieldId] = $_POST[$fieldId]; } elseif ($field["PROPERTY_TYPE"] == "F") { if (isset($_POST[$fieldId . "_del"])) { $deleteArray = $_POST[$fieldId . "_del"]; } else { $deleteArray = array(); } $props[$field["ID"]] = array(); $files = $this->unEscape($_FILES); CFile::ConvertFilesToPost($files[$fieldId], $props[$field["ID"]]); foreach ($props[$field["ID"]] as $fileId => $file) { if (isset($deleteArray[$fileId]) && (!is_array($deleteArray[$fileId]) && $deleteArray[$fileId] == "Y" || is_array($deleteArray[$fileId]) && $deleteArray[$fileId]["VALUE"] == "Y")) { if (isset($props[$field["ID"]][$fileId]["VALUE"])) { $props[$field["ID"]][$fileId]["VALUE"]["del"] = "Y"; } else { $props[$field["ID"]][$fileId]["del"] = "Y"; } } } } elseif ($field["PROPERTY_TYPE"] == "N") { if (is_array($_POST[$fieldId]) && !array_key_exists("VALUE", $_POST[$fieldId])) { $props[$field["ID"]] = array(); foreach ($_POST[$fieldId] as $key => $value) { if (is_array($value)) { if (strlen($value["VALUE"])) { $value = str_replace(" ", "", str_replace(",", ".", $value["VALUE"])); if (!is_numeric($value)) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_VALIDATE_FIELD_ERROR', array('#NAME#' => $field['NAME']))))); $this->sendJsonErrorResponse(); } $props[$field["ID"]][$key] = doubleval($value); } } else { if (strlen($value)) { $value = str_replace(" ", "", str_replace(",", ".", $value)); if (!is_numeric($value)) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_VALIDATE_FIELD_ERROR', array('#NAME#' => $field['NAME']))))); $this->sendJsonErrorResponse(); } $props[$field["ID"]][$key] = doubleval($value); } } } } else { if (is_array($_POST[$fieldId])) { if (strlen($_POST[$fieldId]["VALUE"])) { $value = str_replace(" ", "", str_replace(",", ".", $_POST[$fieldId]["VALUE"])); if (!is_numeric($value)) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_VALIDATE_FIELD_ERROR', array('#NAME#' => $field['NAME']))))); $this->sendJsonErrorResponse(); } $props[$field["ID"]] = doubleval($value); } } else { if (strlen($_POST[$fieldId])) { $value = str_replace(" ", "", str_replace(",", ".", $_POST[$fieldId])); if (!is_numeric($value)) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_VALIDATE_FIELD_ERROR', array('#NAME#' => $field['NAME']))))); $this->sendJsonErrorResponse(); } $props[$field["ID"]] = doubleval($value); } } } } else { $props[$field["ID"]] = $_POST[$fieldId]; } } $elementData["MODIFIED_BY"] = $this->getUser()->getID(); unset($elementData["TIMESTAMP_X"]); if (!empty($props)) { $elementData["PROPERTY_VALUES"] = $props; } $documentStates = CBPDocument::GetDocumentStates($documentType, null); $userId = $this->getUser()->getId(); $write = CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::WriteDocument, $userId, $documentType, array('AllUserGroups' => array(), 'DocumentStates' => $documentStates)); if (!$write) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_ACCESS_DENIED_STATUS')))); $this->sendJsonErrorResponse(); } $bizprocParametersValues = array(); foreach ($documentStates as $documentState) { if (strlen($documentState["ID"]) <= 0) { $errors = array(); $bizprocParametersValues[$documentState['TEMPLATE_ID']] = CBPDocument::StartWorkflowParametersValidate($documentState['TEMPLATE_ID'], $documentState['TEMPLATE_PARAMETERS'], $documentType, $errors); $stringError = ''; foreach ($errors as $e) { $stringError .= $e['message'] . '<br />'; } } } if (!empty($stringError)) { $this->errorCollection->add(array(new Error($stringError))); $this->sendJsonErrorResponse(); } $objectElement = new CIBlockElement(); $idElement = $objectElement->Add($elementData, false, true, true); if ($idElement) { $bizProcWorkflowId = array(); foreach ($documentStates as $documentState) { if (strlen($documentState["ID"]) <= 0) { $errorsTmp = array(); $bizProcWorkflowId[$documentState['TEMPLATE_ID']] = CBPDocument::StartWorkflow($documentState['TEMPLATE_ID'], array('lists', 'BizprocDocument', $idElement), array_merge($bizprocParametersValues[$documentState['TEMPLATE_ID']], array('TargetUser' => 'user_' . intval($this->getUser()->getID()))), $errorsTmp); } } if (!empty($errorsTmp)) { $documentStates = null; CBPDocument::AddDocumentToHistory(array('lists', 'BizprocDocument', $idElement), $elementData['NAME'], $this->getUser()->getID()); } } else { $this->errorCollection->add(array(new Error($objectElement->LAST_ERROR))); $this->sendJsonErrorResponse(); } $this->sendJsonSuccessResponse(array()); }
$fieldType = 'boolean'; break; default: $fieldType = 'string'; } $arUserField = array("ENTITY_ID" => "HLBLOCK_" . $highBlockID, "FIELD_NAME" => $fieldName, "USER_TYPE_ID" => $fieldType, "XML_ID" => "", "SORT" => $intSortStep, "MULTIPLE" => "N", "MANDATORY" => $fieldMandatory, "SHOW_FILTER" => "N", "SHOW_IN_LIST" => "Y", "EDIT_IN_LIST" => "Y", "IS_SEARCHABLE" => "N", "SETTINGS" => array()); if (isset($_POST['PROPERTY_USER_TYPE_SETTINGS']['LANG'][$fieldName])) { $arUserField["EDIT_FORM_LABEL"] = $arUserField["LIST_COLUMN_LABEL"] = $arUserField["LIST_FILTER_LABEL"] = array(LANGUAGE_ID => $_POST['PROPERTY_USER_TYPE_SETTINGS']['LANG'][$fieldName]); } $obUserField->Add($arUserField); $intSortStep += 100; } } $arImageResult = array(); if (isset($_FILES['PROPERTY_DIRECTORY_VALUES']) && is_array($_FILES['PROPERTY_DIRECTORY_VALUES'])) { CFile::ConvertFilesToPost($_FILES['PROPERTY_DIRECTORY_VALUES'], $arImageResult); } if ($_POST["PROPERTY_USER_TYPE_SETTINGS"]["TABLE_NAME"] == '-1' && isset($result) && $result->isSuccess()) { $hlblock = Bitrix\Highloadblock\HighloadBlockTable::getById($highBlockID)->fetch(); } else { $hlblock = Bitrix\Highloadblock\HighloadBlockTable::getList(array('filter' => array('=TABLE_NAME' => $_POST['PROPERTY_USER_TYPE_SETTINGS']['TABLE_NAME'])))->fetch(); } $entity = Bitrix\Highloadblock\HighloadBlockTable::compileEntity($hlblock); $entityDataClass = $entity->getDataClass(); $fieldsList = $entityDataClass::getMap(); if (count($fieldsList) == 1 && isset($fieldsList['ID'])) { $fieldsList = $entityDataClass::getEntity()->getFields(); } foreach ($_POST['PROPERTY_DIRECTORY_VALUES'] as $dirKey => $arDirValue) { if (isset($arDirValue["UF_DELETE"])) { if ($arDirValue["UF_DELETE"] === 'Y') {
function EditFormAddFields($entity_id, &$arFields) { global $HTTP_POST_FILES; $arUserFields = $this->GetUserFields($entity_id); foreach($arUserFields as $arUserField) { if($arUserField["EDIT_IN_LIST"]=="Y") { if($arUserField["USER_TYPE"]["BASE_TYPE"]=="file") { if (isset($HTTP_POST_FILES[$arUserField["FIELD_NAME"]])) { if(is_array($HTTP_POST_FILES[$arUserField["FIELD_NAME"]]["name"])) { $arFields[$arUserField["FIELD_NAME"]] = array(); foreach($HTTP_POST_FILES[$arUserField["FIELD_NAME"]]["name"] as $key => $value) { $old_id = $GLOBALS[$arUserField["FIELD_NAME"]."_old_id"][$key]; $arFields[$arUserField["FIELD_NAME"]][$key] = array( "name" => $HTTP_POST_FILES[$arUserField["FIELD_NAME"]]["name"][$key], "type" => $HTTP_POST_FILES[$arUserField["FIELD_NAME"]]["type"][$key], "tmp_name" => $HTTP_POST_FILES[$arUserField["FIELD_NAME"]]["tmp_name"][$key], "error" => $HTTP_POST_FILES[$arUserField["FIELD_NAME"]]["error"][$key], "size" => $HTTP_POST_FILES[$arUserField["FIELD_NAME"]]["size"][$key], "del" => is_array($GLOBALS[$arUserField["FIELD_NAME"]."_del"]) && ( in_array($old_id, $GLOBALS[$arUserField["FIELD_NAME"]."_del"]) || ( array_key_exists($key, $GLOBALS[$arUserField["FIELD_NAME"]."_del"]) && $GLOBALS[$arUserField["FIELD_NAME"]."_del"][$key] == "Y" ) ), "old_id" => $old_id ); } } else { $arFields[$arUserField["FIELD_NAME"]] = $HTTP_POST_FILES[$arUserField["FIELD_NAME"]]; $arFields[$arUserField["FIELD_NAME"]]["del"] = $GLOBALS[$arUserField["FIELD_NAME"]."_del"]; $arFields[$arUserField["FIELD_NAME"]]["old_id"] = $GLOBALS[$arUserField["FIELD_NAME"]."_old_id"]; } } else { if(isset($GLOBALS[$arUserField["FIELD_NAME"]])) { if(!is_array($GLOBALS[$arUserField["FIELD_NAME"]])) { if(intval($GLOBALS[$arUserField["FIELD_NAME"]]) > 0) { $arFields[$arUserField["FIELD_NAME"]] = intval($GLOBALS[$arUserField["FIELD_NAME"]]); } } else { $fields = array(); foreach($GLOBALS[$arUserField["FIELD_NAME"]] as $val) { if(intval($val) > 0) { $fields[] = intval($val); } } $arFields[$arUserField["FIELD_NAME"]] = $fields; } } } } else { if (isset($HTTP_POST_FILES[$arUserField["FIELD_NAME"]])) { $arFile = array(); CFile::ConvertFilesToPost($HTTP_POST_FILES[$arUserField["FIELD_NAME"]], $arFile); if(isset($GLOBALS[$arUserField["FIELD_NAME"]])) { if($arUserField["MULTIPLE"] == "Y") { foreach($_REQUEST[$arUserField["FIELD_NAME"]] as $key => $value) $arFields[$arUserField["FIELD_NAME"]][$key] = array_merge($value, $arFile[$key]); } else { $arFields[$arUserField["FIELD_NAME"]] = array_merge($_REQUEST[$arUserField["FIELD_NAME"]], $arFile); } } else { $arFields[$arUserField["FIELD_NAME"]] = $arFile; } } else { if(isset($GLOBALS[$arUserField["FIELD_NAME"]])) $arFields[$arUserField["FIELD_NAME"]] = $GLOBALS[$arUserField["FIELD_NAME"]]; } } } } }
if (isset($arField["SETTINGS"]) && is_array($arField["SETTINGS"]) && $arField["SETTINGS"]["USE_EDITOR"] == "Y") { $arElement[$FIELD_ID . "_TYPE"] = "html"; } else { $arElement[$FIELD_ID . "_TYPE"] = "text"; } $arElement[$FIELD_ID] = $_POST[$FIELD_ID]; } elseif ($obList->is_field($FIELD_ID)) { $arElement[$FIELD_ID] = $_POST[$FIELD_ID]; } elseif ($arField["PROPERTY_TYPE"] == "F") { if (isset($_POST[$FIELD_ID . "_del"])) { $arDel = $_POST[$FIELD_ID . "_del"]; } else { $arDel = array(); } $arProps[$arField["ID"]] = array(); CFile::ConvertFilesToPost($_FILES[$FIELD_ID], $arProps[$arField["ID"]]); foreach ($arProps[$arField["ID"]] as $file_id => $arFile) { if (isset($arDel[$file_id]) && (!is_array($arDel[$file_id]) && $arDel[$file_id] == "Y" || is_array($arDel[$file_id]) && $arDel[$file_id]["VALUE"] == "Y")) { if (isset($arProps[$arField["ID"]][$file_id]["VALUE"])) { $arProps[$arField["ID"]][$file_id]["VALUE"]["del"] = "Y"; } else { $arProps[$arField["ID"]][$file_id]["del"] = "Y"; } } } } elseif ($arField["PROPERTY_TYPE"] == "N") { if (is_array($_POST[$FIELD_ID]) && !array_key_exists("VALUE", $_POST[$FIELD_ID])) { $arProps[$arField["ID"]] = array(); foreach ($_POST[$FIELD_ID] as $key => $value) { if (is_array($value)) { if (strlen($value["VALUE"])) {
} if (!empty($arPropertyPopupIB1)) { __showPopup("IB_SEG_ADD_PROP_IN_TITLE", $arPropertyPopupIB1); } $arPropertyPopupIB2 = array("NAME" => array("TEXT" => GetMessage("IB_SEG_TITLE"), "ONCLICK" => "obPropertyTable.addPropertyInTitle('{=this.property.CML2_LINK.NAME}')", "CODE" => 'NAME')); foreach ($arAllParentProperties as $key => $property) { $arPropertyPopupIB2[$property["CODE"]] = array("TEXT" => htmlspecialcharsbx($property["NAME"]), "ONCLICK" => "obPropertyTable.addPropertyInTitle('{=this.property.CML2_LINK.property." . $property["CODE"] . "}')", "CODE" => $property["CODE"]); } if (!empty($arPropertyPopupIB2)) { __showPopup("IB_SEG_ADD_PROP_IN_TITLE2", $arPropertyPopupIB2); } $errorMessage = ''; if (!$bReadOnly && check_bitrix_sessid()) { $arImageCombinationResult = $arPropertyValueCombinationResult = array(); if (isset($_FILES['PROP']) && is_array($_FILES['PROP'])) { CFile::ConvertFilesToPost($_FILES['PROP'], $arImageCombinationResult); } if (isset($_POST["PROP"]) && is_array($_POST["PROP"])) { foreach ($_POST["PROP"] as $propKey => $arTmpProperty) { $rowId = 0; if (is_array($arTmpProperty)) { foreach ($arTmpProperty as $eachPropertyValue) { $arPropertyValueCombinationResult[$rowId][$propKey] = $eachPropertyValue; $rowId++; } } } } $arCombinationResult = $arPropertyValue = $arPriceGroup = array(); $idNewElement = false; $obIBlockElement = new CIBlockElement();
if ($productID <= 0) { // Setup catalog ID for new product $productFields['CATALOG_ID'] = $catalogID > 0 ? $catalogID : CCrmCatalog::EnsureDefaultExists(); } // Product properties values $arPropsValues = array(); foreach ($arResult['PROPS'] as $propID => $arProp) { if ($arProp['PROPERTY_TYPE'] == 'F') { if (isset($_POST[$propID . '_del'])) { $arDel = $_POST[$propID . '_del']; } else { $arDel = array(); } $arPropsValues[$arProp['ID']] = array(); if (isset($_FILES[$propID])) { CFile::ConvertFilesToPost($_FILES[$propID], $arPropsValues[$arProp['ID']]); foreach ($arPropsValues[$arProp['ID']] as $file_id => $arFile) { if (isset($arDel[$file_id]) && (!is_array($arDel[$file_id]) && $arDel[$file_id] == 'Y' || is_array($arDel[$file_id]) && $arDel[$file_id]['VALUE'] == 'Y')) { if (isset($arPropsValues[$arProp['ID']][$file_id]['VALUE'])) { $arPropsValues[$arProp['ID']][$file_id]['VALUE']['del'] = 'Y'; } else { $arPropsValues[$arProp['ID']][$file_id]['del'] = 'Y'; } } } } } elseif ($arProp['PROPERTY_TYPE'] == 'N') { if (is_array($_POST[$propID]) && !array_key_exists('VALUE', $_POST[$propID])) { $arPropsValues[$arProp['ID']] = array(); foreach ($_POST[$propID] as $key => $value) { if (is_array($value)) {