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()); }
public function CheckFields($ID = false, $bAutoExec = false, $CreatedBy = 0, $arEntityAttr = array()) { global $USER; $this->LAST_ERROR = ''; if (!CModule::IncludeModule('bizproc')) { return true; } $this->arDocumentStates = CBPDocument::GetDocumentStates(array('crm', $this->sDocument, $this->sEntityType), $ID == false ? null : array('crm', $this->sDocument, $this->sEntityType . '_' . $ID)); $arCurrentUserGroups = $this->arCurrentUserGroups; if (is_object($USER)) { if ($ID == false) { $arCurrentUserGroups[] = 'Author'; $bCanWrite = CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::WriteDocument, $USER->GetID(), array('crm', $this->sDocument, $this->sEntityType), array('AllUserGroups' => $arCurrentUserGroups, 'DocumentStates' => $this->arDocumentStates, 'UserIsAdmin' => $USER->IsAdmin())); } else { if ($USER->GetID() == $CreatedBy) { $arCurrentUserGroups[] = 'Author'; } $bCanWrite = CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::WriteDocument, $USER->GetID(), array('crm', $this->sDocument, $this->sEntityType . '_' . $ID), array('AllUserGroups' => $arCurrentUserGroups, 'DocumentStates' => $this->arDocumentStates, 'CreatedBy' => $CreatedBy != 0 ? $CreatedBy : 0, 'UserIsAdmin' => $USER->IsAdmin(), 'CRMEntityAttr' => $arEntityAttr)); } } else { $bCanWrite = true; } if (!$bCanWrite) { $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED'); return false; } $arBizProcParametersValues = array(); foreach ($this->arDocumentStates as $arDocumentState) { if (strlen($arDocumentState['ID']) <= 0) { if ($bAutoExec) { foreach ($arDocumentState['TEMPLATE_PARAMETERS'] as $parameterKey => $arParam) { if ($arParam['Required'] && !isset($_REQUEST['bizproc' . $arDocumentState['TEMPLATE_ID'] . '_' . $parameterKey]) && strlen($arParam['Default']) > 0) { $_REQUEST['bizproc' . $arDocumentState['TEMPLATE_ID'] . '_' . $parameterKey] = $arParam['Default']; } } } $arErrorsTmp = array(); $arBizProcParametersValues[$arDocumentState['TEMPLATE_ID']] = CBPDocument::StartWorkflowParametersValidate($arDocumentState['TEMPLATE_ID'], $arDocumentState['TEMPLATE_PARAMETERS'], array('crm', $this->sDocument, $ID == false ? $this->sEntityType : $this->sEntityType . '_' . $ID), $arErrorsTmp); if (count($arErrorsTmp) > 0) { $this->LAST_ERROR = ''; foreach ($arErrorsTmp as $e) { $this->LAST_ERROR .= $e['message'] . '<br />'; } return false; } } } return $arBizProcParametersValues; }
} if ($arResult["ELEMENT_ID"]) { $canWrite = CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::WriteDocument, $USER->GetID(), BizProcDocument::getDocumentComplexId($arParams["IBLOCK_TYPE_ID"], $arResult["ELEMENT_ID"]), array("AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates)); } else { $canWrite = CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::WriteDocument, $USER->GetID(), $documentType, array("AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates)); } if (!$canWrite) { $strError = GetMessage("CC_BLEE_ACCESS_DENIED_STATUS"); } if (!$strError) { $arBizProcParametersValues = array(); foreach ($arDocumentStates as $arDocumentState) { if (strlen($arDocumentState["ID"]) <= 0) { $templatesOnStartup = true; $arErrorsTmp = array(); $arBizProcParametersValues[$arDocumentState["TEMPLATE_ID"]] = CBPDocument::StartWorkflowParametersValidate($arDocumentState["TEMPLATE_ID"], $arDocumentState["TEMPLATE_PARAMETERS"], $documentType, $arErrorsTmp); foreach ($arErrorsTmp as $e) { $strError .= $e["message"] . "<br />"; } } } $templates = array_merge(\CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType($documentType, CBPDocumentEventType::Create), \CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType($documentType, CBPDocumentEventType::Edit)); $error = false; foreach ($templates as $template) { if (!CBPWorkflowTemplateLoader::isConstantsTuned($template["ID"]) && !$error) { $error = true; $strError .= GetMessage('CC_BLEE_IS_CONSTANTS_TUNED') . "<br />"; $arResult["isConstantsTuned"] = true; } } }
} } if ($bBizproc) { if($canWrite) { $arBizProcParametersValues = array(); foreach ($arDocumentStates as $arDocumentState) { if (strlen($arDocumentState["ID"]) <= 0) { $arErrorsTmp = array(); $arBizProcParametersValues[$arDocumentState["TEMPLATE_ID"]] = CBPDocument::StartWorkflowParametersValidate( $arDocumentState["TEMPLATE_ID"], $arDocumentState["TEMPLATE_PARAMETERS"], array(MODULE_ID, ENTITY, DOCUMENT_TYPE), $arErrorsTmp ); if (!empty($arErrorsTmp)) { foreach ($arErrorsTmp as $e) $strWarning .= $e["message"]."<br />"; } } } } else { $strWarning .= GetMessage("IBLOCK_ACCESS_DENIED_STATUS")."<br />"; }
$arCurrentUserGroups[] = "Author"; } if ($arParams["ID"]) { $canWrite = CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::WriteDocument, $USER->GetID(), array("iblock", "CIBlockDocument", $arParams["ID"]), array("AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates)); } else { $canWrite = CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::WriteDocument, $USER->GetID(), array("iblock", "CIBlockDocument", $DOCUMENT_TYPE), array("AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates)); } if (!$canWrite) { $arResult["ERRORS"][] = GetMessage("CC_BIEAF_ACCESS_DENIED_STATUS"); } if (count($arResult["ERRORS"]) == 0) { $arBizProcParametersValues = array(); foreach ($arDocumentStates as $arDocumentState) { if (strlen($arDocumentState["ID"]) <= 0) { $arErrorsTmp = array(); $arBizProcParametersValues[$arDocumentState["TEMPLATE_ID"]] = CBPDocument::StartWorkflowParametersValidate($arDocumentState["TEMPLATE_ID"], $arDocumentState["TEMPLATE_PARAMETERS"], array("iblock", "CIBlockDocument", $DOCUMENT_TYPE), $arErrorsTmp); foreach ($arErrorsTmp as $e) { $arResult["ERRORS"][] = $e["message"]; } } } } } if (count($arResult["ERRORS"]) == 0) { if ($arParams["ELEMENT_ASSOC"] == "PROPERTY_ID") { $arUpdatePropertyValues[$arParams["ELEMENT_ASSOC_PROPERTY"]] = $USER->GetID(); } $arUpdateValues["MODIFIED_BY"] = $USER->GetID(); $arUpdateValues["PROPERTY_VALUES"] = $arUpdatePropertyValues; if ($bWorkflowIncluded && strlen($arParams["STATUS_NEW"]) > 0) { $arUpdateValues["WF_STATUS_ID"] = $arParams["STATUS_NEW"];
/** * Метод - просто агрегатор действий по проверке корректности входных данных * * @param string $documentType - тип документа. * @param array $arDocumentStates - массив шаблонов БП документа. * @param array $arBizProcParametersValues - массив входных параметров для шаблонов. * @param array $arErrors - массив ошибок. */ public function StartWorkflowsParametersValidate($documentType, $arDocumentStates, &$arBizProcParametersValues, &$arErrors) { $arBizProcParametersValues = array(); $arDocumentStates = is_array($arDocumentStates) ? $arDocumentStates : array(); foreach ($arDocumentStates as $arDocumentState) { if (strlen($arDocumentState["ID"]) <= 0) { $arErrorsTmp = array(); $arBizProcParametersValues[$arDocumentState["TEMPLATE_ID"]] = CBPDocument::StartWorkflowParametersValidate($arDocumentState["TEMPLATE_ID"], $arDocumentState["TEMPLATE_PARAMETERS"], $documentType, $arErrorsTmp); foreach ($arErrorsTmp as $e) { $arErrors[] = array("id" => "bizproc_validate", "text" => $e["message"]); } } } return empty($arErrors); }