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()); }
$bpEvent, array("Groups" => $arCurrentUserGroups, "User" => $USER->GetID()), $arErrorTmp ); if (!empty($arErrorsTmp)) { foreach ($arErrorsTmp as $e) $strWarning .= $e["message"]."<br />"; } } } } $arDocumentStates = null; CBPDocument::AddDocumentToHistory(array(MODULE_ID, ENTITY, $ID), $BP_HISTORY_NAME, $GLOBALS["USER"]->GetID()); } } } if($strWarning == '') { if(!$customTabber->Action()) { if ($ex = $APPLICATION->GetException()) $strWarning .= $ex->GetString(); else $strWarning .= "Error. "; } }
} else { if (!array_key_exists($bpTemplateId, $arDocumentStates)) { continue; } $bpId = $arBizProcWorkflowId[$bpTemplateId]; } $arErrorTmp = array(); CBPDocument::SendExternalEvent($bpId, $bpEvent, array("Groups" => $arCurrentUserGroups, "User" => $GLOBALS["USER"]->GetID()), $arErrorTmp); foreach ($arErrorsTmp as $e) { $strWarning .= $e["message"] . "<br />"; } } } } $arDocumentStates = null; CBPDocument::AddDocumentToHistory(BizProcDocument::getDocumentComplexId($arParams["IBLOCK_TYPE_ID"], $arResult["ELEMENT_ID"]), $arElement["NAME"], $GLOBALS["USER"]->GetID()); } } if (!$strError) { //Successfull update //And go to proper page if (isset($_POST["save"])) { LocalRedirect($arResult["~LIST_SECTION_URL"]); } elseif ($lists_perm < CListPermissions::CAN_READ && !CIBlockElementRights::UserHasRightTo($arResult["IBLOCK_ID"], $arResult["ELEMENT_ID"], "element_read")) { LocalRedirect($arResult["~LIST_SECTION_URL"]); } else { $url = CHTTP::urlAddParams(str_replace(array("#list_id#", "#section_id#", "#element_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($_POST["IBLOCK_SECTION_ID"]), $arResult["ELEMENT_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_ELEMENT_URL"]), array($tab_name => $_POST[$tab_name]), array("skip_empty" => true, "encode" => true)); if (isset($_GET["list_section_id"]) && strlen($_GET["list_section_id"]) == 0) { $url = CHTTP::urlAddParams($url, array("list_section_id" => "")); } LocalRedirect($url);
} if ($bBizproc && count($arResult["ERRORS"]) == 0) { $arBizProcWorkflowId = array(); foreach ($arDocumentStates as $arDocumentState) { if (strlen($arDocumentState["ID"]) <= 0) { $arErrorsTmp = array(); $arBizProcWorkflowId[$arDocumentState["TEMPLATE_ID"]] = CBPDocument::StartWorkflow($arDocumentState["TEMPLATE_ID"], array("iblock", "CIBlockDocument", $arParams["ID"]), $arBizProcParametersValues[$arDocumentState["TEMPLATE_ID"]], $arErrorsTmp); foreach ($arErrorsTmp as $e) { $arResult["ERRORS"][] = $e["message"]; } } } } if ($bBizproc && count($arResult["ERRORS"]) == 0) { $arDocumentStates = null; CBPDocument::AddDocumentToHistory(array("iblock", "CIBlockDocument", $arParams["ID"]), $arUpdateValues["NAME"], $USER->GetID()); } // redirect to element edit form or to elements list if (count($arResult["ERRORS"]) == 0) { if (!empty($_REQUEST["iblock_submit_c"])) { if (strlen($arParams["LIST_URL"]) > 0) { $sRedirectUrl = $arParams["LIST_URL"]; } else { if (strlen($SEF_URL) > 0) { $SEF_URL = str_replace("edit=Y", "", $SEF_URL); $SEF_URL = str_replace("?&", "?", $SEF_URL); $SEF_URL = str_replace("&&", "&", $SEF_URL); $sRedirectUrl = $SEF_URL; } else { $sRedirectUrl = $APPLICATION->GetCurPageParam("", array("edit", "CODE"), $get_index_page = false); }
case "delete": if ($arParams["MODULE_ID"] == "webdav") { if (CBPDocument::CanUserOperateDocument(CBPWebDavCanUserOperateOperation::DeleteDocument, $GLOBALS["USER"]->GetID(), $arParams["DOCUMENT_ID"], array("UserGroups" => $GLOBALS["USER"]->GetUserGroupArray()))) { CBPHistoryService::Delete($ID, $arParams["DOCUMENT_ID"]); } else { $arError[] = array("id" => "access_denied", "text" => GetMessage("BPADH_NO_PERMS")); } } else { CBPHistoryService::Delete($ID, $arParams["DOCUMENT_ID"]); } break; case "recover": if ($arParams["MODULE_ID"] == "webdav" && isset($arParams["OBJECT"])) { $arParams['OBJECT']->IsDir(array('element_id' => $arParams["DOCUMENT_ID"][2])); if (($arParams["OBJECT"]->workflow == 'bizproc' || $arParams["OBJECT"]->workflow == 'bizproc_limited') && $arParams['OBJECT']->arParams['not_found'] == false) { CBPDocument::AddDocumentToHistory($arParams['DOCUMENT_ID'], $arParams['OBJECT']->arParams["element_name"], $GLOBALS["USER"]->GetID()); if (method_exists('CIBlockDocumentWebdav', 'TruncateHistory')) { CIBlockDocumentWebdav::TruncateHistory($arParams['OBJECT']->wfParams['DOCUMENT_TYPE'], $arParams["DOCUMENT_ID"][2]); } } } try { if (!CBPHistoryService::RecoverDocumentFromHistory($ID)) { $arError[] = array("id" => "not recover", "text" => GetMessage("BPADH_RECOVERY_ERROR")); } } catch (Exception $e) { $arError[] = array("id" => "not recover", "text" => $e->getMessage()); } break; } if (!empty($arError)) {
/** * Метод клонирует документ. * * @param string $documentId - ID документа. * @param string $arFields - поля для замены. */ public function CloneElement($ID, $arFields = array(), $arParams = array()) { global $DB; $ID = intval($ID); $CHILD_ID = parent::CloneElement($ID, $arFields); if ($CHILD_ID > 0) { $db_res = CIBlockElement::GetList(array(), array("ID" => $ID, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"), false, false, array("IBLOCK_ID", "ID", "NAME")); $arParent = $db_res->Fetch(); CBPDocument::AddDocumentToHistory(array("webdav", "CIBlockDocumentWebdavSocnet", $CHILD_ID), str_replace(array("#ID#", "#NAME#", "#PARENT_ID#", "#PARENT_NAME#"), array($CHILD_ID, $arFields["NAME"], $ID, $arParent["NAME"]), GetMessage("IBD_TEXT_002")), $GLOBALS["USER"]->GetID()); } return $CHILD_ID; }
function AddDocumentToHistory($docID, $fileName) { global $USER; $documentId = $this->wfParams["DOCUMENT_TYPE"]; $documentId[2] = $docID; $userID = $USER->GetID(); $rDoc = CIBlockElement::GetList(array(), array('ID' => $docID), false, false, array('MODIFIED_BY')); if ($rDoc && ($arDoc = $rDoc->Fetch())) { $userID = $arDoc['MODIFIED_BY']; } $historyDoc = CWebdavDocumentHistory::IsHistoryUpdate($documentId); $historyIndex = false; if ($historyDoc) { $historyIndex = CWebdavDocumentHistory::UpdateDocumentHistory($documentId, $historyDoc['ID']); } else { $historyIndex = CBPDocument::AddDocumentToHistory($documentId, $fileName, $userID); } return $historyIndex; }
} else { if (!array_key_exists($bpTemplateId, $arDocumentStates)) { continue; } $bpId = $arBizProcWorkflowId[$bpTemplateId]; } $arErrorTmp = array(); CBPDocument::SendExternalEvent($bpId, $bpEvent, array("Groups" => $arCurrentUserGroups, "User" => $GLOBALS["USER"]->GetID()), $arErrorTmp); foreach ($arErrorsTmp as $e) { $strWarning .= $e["message"] . "<br />"; } } } } $arDocumentStates = null; CBPDocument::AddDocumentToHistory(array("iblock", "CIBlockDocument", $arResult["ELEMENT_ID"]), $arElement["NAME"], $GLOBALS["USER"]->GetID()); } } if (!$strError) { //Successfull update $tab_name = $arResult["FORM_ID"] . "_active_tab"; //And go to proper page if (isset($_POST["save"])) { LocalRedirect($arResult["~LIST_SECTION_URL"]); } elseif ($lists_perm < CListPermissions::CAN_READ && !CIBlockElementRights::UserHasRightTo($arResult["IBLOCK_ID"], $arResult["ELEMENT_ID"], "element_read")) { LocalRedirect($arResult["~LIST_SECTION_URL"]); } else { $url = CHTTP::urlAddParams(str_replace(array("#list_id#", "#section_id#", "#element_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($_POST["IBLOCK_SECTION_ID"]), $arResult["ELEMENT_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_ELEMENT_URL"]), array($tab_name => $_POST[$tab_name]), array("skip_empty" => true, "encode" => true)); if (isset($_GET["list_section_id"]) && strlen($_GET["list_section_id"]) == 0) { $url = CHTTP::urlAddParams($url, array("list_section_id" => "")); }