protected function processActionPerformActionBp() { if (!Loader::includeModule('bizproc')) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_LAC_MODULE_NOT_INSTALLED')))); } $this->checkRequiredPostParams(array('iblockTypeId', 'iblockId', 'sectionId', 'workflowId', 'elementId', 'action')); if ($this->request->getPost('iblockTypeId') == COption::getOptionString('lists', 'livefeed_iblock_type_id')) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_LAC_UNKNOWN_ERROR')))); } if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $this->iblockTypeId = $this->request->getPost('iblockTypeId'); $this->iblockId = $this->request->getPost('iblockId'); $this->sectionId = $this->request->getPost('sectionId'); $workflowId = $this->request->getPost('workflowId'); $elementId = $this->request->getPost('elementId'); $action = $this->request->getPost('action'); $this->documentStates = CBPDocument::getDocumentStates(BizProcDocument::generateDocumentComplexType($this->iblockTypeId, $this->iblockId), BizProcDocument::getDocumentComplexId($this->iblockTypeId, $elementId)); if (isset($this->documentStates[$workflowId]['WORKFLOW_STATUS']) && $this->documentStates[$workflowId]['WORKFLOW_STATUS'] !== null) { $this->terminateWorkflow($workflowId, $elementId); } if ($action == 'delete') { if (CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::CreateWorkflow, $this->getUser(), BizProcDocument::getDocumentComplexId($this->iblockTypeId, $elementId), array("DocumentStates" => $this->documentStates))) { CBPTaskService::DeleteByWorkflow($workflowId); CBPTrackingService::DeleteByWorkflow($workflowId); CBPStateService::DeleteWorkflow($workflowId); } else { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_LAC_ACCESS_DENIED')))); } if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } } $this->sendJsonSuccessResponse(array('message' => Loc::getMessage('LISTS_LAC_MESSAGE_SUCCESS'))); }
protected function getBizprocData() { $userId = $this->getUser()->getID(); $currentUserGroups = $this->getUser()->getUserGroupArray(); if (!$this->lists['ELEMENT_FIELDS'] || $this->lists['ELEMENT_FIELDS']['CREATED_BY'] == $userId) { $currentUserGroups[] = 'Author'; } $documentType = 'iblock_' . $this->iblockId; CBPDocument::addShowParameterInit('lists', 'only_users', $documentType); $this->lists['BIZPROC_FIELDS'] = array(); $bizprocIndex = 0; $documentStates = CBPDocument::getDocumentStates(array('lists', 'BizprocDocument', $documentType), null); $runtime = CBPRuntime::getRuntime(); $runtime->startRuntime(); $documentService = $runtime->getService('DocumentService'); foreach ($documentStates as $documentState) { $bizprocIndex++; $viewWorkflow = CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::StartWorkflow, $userId, array('lists', 'BizprocDocument', $documentType), array('sectionId' => 0, 'AllUserGroups' => $currentUserGroups, 'DocumentStates' => $documentStates, 'WorkflowId' => $documentState['ID'] > 0 ? $documentState['ID'] : $documentState['TEMPLATE_ID'])); if ($viewWorkflow) { $templateId = intval($documentState['TEMPLATE_ID']); $workflowParameters = $documentState['TEMPLATE_PARAMETERS']; if (!is_array($workflowParameters)) { $workflowParameters = array(); } if (strlen($documentState["ID"]) <= 0 && $templateId > 0) { $parametersValues = array(); $keys = array_keys($workflowParameters); foreach ($keys as $key) { $value = $workflowParameters[$key]["Default"]; if (!is_array($value)) { $parametersValues[$key] = htmlspecialcharsbx($value); } else { $keys1 = array_keys($value); foreach ($keys1 as $key1) { $parametersValues[$key][$key1] = htmlspecialcharsbx($value[$key1]); } } } foreach ($workflowParameters as $parameterKey => $arParameter) { $parameterKeyExt = "bizproc" . $templateId . "_" . $parameterKey; $html = $documentService->GetFieldInputControl(array('lists', 'BizprocDocument', $documentType), $arParameter, array("Form" => "start_workflow_form1", "Field" => $parameterKeyExt), $parametersValues[$parameterKey], false, true); $this->lists['BIZPROC_FIELDS'][$parameterKeyExt . $bizprocIndex] = array("id" => $parameterKeyExt . $bizprocIndex, "required" => $arParameter["Required"], "name" => $arParameter["Name"], "title" => $arParameter["Description"], "type" => "custom", "value" => $html, 'show' => 'Y'); } } } } }
function CanUserOperateDocumentType($operation, $userId, $documentType, $parameters = array()) { $documentType = trim($documentType); if (strlen($documentType) <= 0) { return false; } $parameters["IBlockId"] = intval(substr($documentType, strlen("iblock_"))); $parameters['sectionId'] = !empty($parameters['sectionId']) ? (int) $parameters['sectionId'] : 0; if (!array_key_exists("IBlockRightsMode", $parameters)) { $parameters["IBlockRightsMode"] = CIBlock::getArrayByID($parameters["IBlockId"], "RIGHTS_MODE"); } if ($parameters["IBlockRightsMode"] === "E") { if ($operation === CBPCanUserOperateOperation::CreateWorkflow) { return CIBlockRights::userHasRightTo($parameters["IBlockId"], $parameters["IBlockId"], "iblock_rights_edit"); } elseif ($operation === CBPCanUserOperateOperation::WriteDocument) { return CIBlockSectionRights::userHasRightTo($parameters["IBlockId"], $parameters["sectionId"], "section_element_bind"); } elseif ($operation === CBPCanUserOperateOperation::ViewWorkflow || $operation === CBPCanUserOperateOperation::StartWorkflow) { if (!array_key_exists("WorkflowId", $parameters)) { return false; } if ($operation === CBPCanUserOperateOperation::ViewWorkflow) { return CIBlockRights::userHasRightTo($parameters["IBlockId"], 0, "element_read"); } if ($operation === CBPCanUserOperateOperation::StartWorkflow) { return CIBlockSectionRights::userHasRightTo($parameters["IBlockId"], $parameters['sectionId'], "section_element_bind"); } $userId = intval($userId); if (!array_key_exists("AllUserGroups", $parameters)) { if (!array_key_exists("UserGroups", $parameters)) { $parameters["UserGroups"] = CUser::getUserGroup($userId); } $parameters["AllUserGroups"] = $parameters["UserGroups"]; $parameters["AllUserGroups"][] = "Author"; } if (!array_key_exists("DocumentStates", $parameters)) { if ($operation === CBPCanUserOperateOperation::StartWorkflow) { $parameters["DocumentStates"] = CBPWorkflowTemplateLoader::getDocumentTypeStates(array("lists", get_called_class(), "iblock_" . $parameters["IBlockId"])); } else { $parameters["DocumentStates"] = CBPDocument::getDocumentStates(array("lists", get_called_class(), "iblock_" . $parameters["IBlockId"]), null); } } if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"])) { $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]); } else { return false; } $allowableOperations = CBPDocument::getAllowableOperations($userId, $parameters["AllUserGroups"], $parameters["DocumentStates"], true); if (!is_array($allowableOperations)) { return false; } if ($operation === CBPCanUserOperateOperation::ViewWorkflow && in_array("read", $allowableOperations) || $operation === CBPCanUserOperateOperation::StartWorkflow && in_array("write", $allowableOperations)) { return true; } $chop = $operation === CBPCanUserOperateOperation::ViewWorkflow ? "element_read" : "section_element_bind"; $tasks = self::getRightsTasks(); foreach ($allowableOperations as $op) { if (isset($tasks[$op])) { $op = $tasks[$op]['ID']; } $ar = CTask::getOperations($op, true); if (in_array($chop, $ar)) { return true; } } } return false; } if (!array_key_exists("IBlockPermission", $parameters)) { if (CModule::includeModule('lists')) { $parameters["IBlockPermission"] = CLists::getIBlockPermission($parameters["IBlockId"], $userId); } else { $parameters["IBlockPermission"] = CIBlock::getPermission($parameters["IBlockId"], $userId); } } if ($parameters["IBlockPermission"] <= "R") { return false; } elseif ($parameters["IBlockPermission"] >= "W") { return true; } $userId = intval($userId); if (!array_key_exists("AllUserGroups", $parameters)) { if (!array_key_exists("UserGroups", $parameters)) { $parameters["UserGroups"] = CUser::getUserGroup($userId); } $parameters["AllUserGroups"] = $parameters["UserGroups"]; $parameters["AllUserGroups"][] = "Author"; } if (!array_key_exists("DocumentStates", $parameters)) { $parameters["DocumentStates"] = CBPDocument::getDocumentStates(array("lists", get_called_class(), "iblock_" . $parameters["IBlockId"]), null); } if (array_key_exists("WorkflowId", $parameters)) { if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"])) { $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]); } else { return false; } } $allowableOperations = CBPDocument::getAllowableOperations($userId, $parameters["AllUserGroups"], $parameters["DocumentStates"]); if (!is_array($allowableOperations)) { return false; } $r = false; switch ($operation) { case CBPCanUserOperateOperation::ViewWorkflow: $r = in_array("read", $allowableOperations); break; case CBPCanUserOperateOperation::StartWorkflow: $r = in_array("write", $allowableOperations); break; case CBPCanUserOperateOperation::CreateWorkflow: $r = in_array("write", $allowableOperations); break; case CBPCanUserOperateOperation::WriteDocument: $r = in_array("write", $allowableOperations); break; case CBPCanUserOperateOperation::ReadDocument: $r = false; break; default: $r = false; } return $r; }
protected function getBizProcData(BaseObject $object, SecurityContext $securityContext, array $actions, array $columnsBizProc, array $bizprocIcon, array $exportData) { $documentData = array('DISK' => array('DOCUMENT_TYPE' => \Bitrix\Disk\BizProcDocument::generateDocumentComplexType($this->storage->getId()), 'DOCUMENT_ID' => \Bitrix\Disk\BizProcDocument::getDocumentComplexId($object->getId())), 'WEBDAV' => array('DOCUMENT_TYPE' => \Bitrix\Disk\BizProcDocumentCompatible::generateDocumentComplexType($this->storage->getId()), 'DOCUMENT_ID' => \Bitrix\Disk\BizProcDocumentCompatible::getDocumentComplexId($object->getId()))); $listBpTemplates = array(); foreach ($this->arParams['TEMPLATE_BIZPROC'] as $idTemplate => $valueTemplate) { $url = CComponentEngine::MakePathFromTemplate($valueTemplate['URL'], array("ELEMENT_ID" => $object->getId())); $listBpTemplates[] = array("ICONCLASS" => "", "TEXT" => $valueTemplate['NAME'], "ONCLICK" => "jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "');"); } if ($object->canStartBizProc($securityContext) && !empty($listBpTemplates)) { $actions[] = array("ICONCLASS" => "bizproc_start", "TEXT" => Loc::getMessage("DISK_FOLDER_LIST_ACT_START_BIZPROC"), "MENU" => $listBpTemplates); } $webdavFileId = $object->getXmlId(); if (!empty($webdavFileId)) { if (Loader::includeModule("iblock")) { if ($this->storage->getProxyType() instanceof ProxyType\Group) { $iblock = CIBlockElement::getList(array(), array("ID" => $webdavFileId, 'SHOW_NEW' => 'Y'), false, false, array('ID', 'IBLOCK_ID'))->fetch(); $entity = 'CIBlockDocumentWebdavSocnet'; } else { $iblock = CIBlockElement::getList(array(), array("ID" => $webdavFileId, 'SHOW_NEW' => 'Y'), false, false, array('ID', 'IBLOCK_ID'))->fetch(); $entity = 'CIBlockDocumentWebdav'; } if (!empty($iblock)) { $documentData['OLD_FILE'] = array('DOCUMENT_TYPE' => array('webdav', $entity, "iblock_" . $iblock['IBLOCK_ID']), 'DOCUMENT_ID' => array('webdav', $entity, $iblock['ID'])); } } } foreach ($documentData as $nameModuleId => $data) { $temporary[$nameModuleId] = CBPDocument::getDocumentStates($data['DOCUMENT_TYPE'], $data['DOCUMENT_ID']); } if (isset($temporary['OLD_FILE'])) { $documentStates = array_merge($temporary['DISK'], $temporary['WEBDAV'], $temporary['OLD_FILE']); } else { $documentStates = array_merge($temporary['DISK'], $temporary['WEBDAV']); } foreach ($documentStates as $key => $documentState) { if (empty($documentState['ID'])) { unset($documentStates[$key]); } } $columnsBizProc['BIZPROC'] = ""; $bizprocIcon['BIZPROC'] = ""; if (!empty($documentStates)) { if (count($documentStates) == 1) { $documentState = reset($documentStates); if ($documentState['WORKFLOW_STATUS'] > 0 || empty($documentState['WORKFLOW_STATUS'])) { $tasksWorkflow = CBPDocument::getUserTasksForWorkflow($this->getUser()->GetID(), $documentState["ID"]); $columnsBizProc["BIZPROC"] = '<div class="bizproc-item-title">' . htmlspecialcharsbx($documentState["TEMPLATE_NAME"]) . ': ' . '<span class="bizproc-item-title bizproc-state-title" style="">' . '<a href="' . $exportData["OPEN_URL"] . '#tab-bp">' . (strlen($documentState["STATE_TITLE"]) > 0 ? htmlspecialcharsbx($documentState["STATE_TITLE"]) : htmlspecialcharsbx($documentState["STATE_NAME"])) . '</a>' . '</span>' . '</div>'; $columnsBizProc['BIZPROC'] = str_replace("'", "\"", $columnsBizProc['BIZPROC']); $bizprocIcon["BIZPROC"] = "<div class=\"element-bizproc-status bizproc-statuses " . (!(strlen($documentState["ID"]) <= 0 || strlen($documentState["WORKFLOW_STATUS"]) <= 0) ? 'bizproc-status-' . (empty($tasksWorkflow) ? "inprogress" : "attention") : '') . "\" onmouseover='BX.hint(this, \"" . addslashes($columnsBizProc["BIZPROC"]) . "\")'></div>"; if (!empty($tasksWorkflow)) { $tmp = array(); foreach ($tasksWorkflow as $val) { $url = CComponentEngine::makePathFromTemplate($this->arParams["PATH_TO_DISK_TASK"], array("ID" => $val["ID"])); $url .= "?back_url=" . urlencode($this->getApplication()->getCurPageParam()); $tmp[] = '<a href="' . $url . '">' . $val["NAME"] . '</a>'; } $columnsBizProc["BIZPROC"] .= '<div class="bizproc-tasks">' . implode(", ", $tmp) . '</div>'; return array($actions, $columnsBizProc, $bizprocIcon); } return array($actions, $columnsBizProc, $bizprocIcon); } return array($actions, $columnsBizProc, $bizprocIcon); } else { $tasks = array(); $inprogress = false; foreach ($documentStates as $key => $documentState) { if ($documentState['WORKFLOW_STATUS'] > 0 || empty($documentState['WORKFLOW_STATUS'])) { $tasksWorkflow = CBPDocument::getUserTasksForWorkflow($this->getUser()->GetID(), $documentState["ID"]); if (!$inprogress) { $inprogress = strlen($documentState['ID']) > 0 && strlen($documentState['WORKFLOW_STATUS']) > 0; } if (!empty($tasksWorkflow)) { foreach ($tasksWorkflow as $val) { $tasks[] = $val; } } } } $columnsBizProc["BIZPROC"] = '<span class="bizproc-item-title">' . Loc::getMessage("DISK_FOLDER_LIST_GRID_BIZPROC") . ': <a href="' . $exportData["OPEN_URL"] . '#tab-bp" title="' . Loc::getMessage("DISK_FOLDER_LIST_GRID_BIZPROC_TITLE") . '">' . count($documentStates) . '</a></span>' . (!empty($tasks) ? '<br /><span class="bizproc-item-title">' . Loc::getMessage("DISK_FOLDER_LIST_GRID_BIZPROC_TASKS") . ': <a href="' . $this->arParams["PATH_TO_DISK_TASK_LIST"] . '" title="' . Loc::getMessage("DISK_FOLDER_LIST_GRID_BIZPROC_TASKS_TITLE") . '">' . count($tasks) . '</a></span>' : ''); $bizprocIcon["BIZPROC"] = "<div class=\"element-bizproc-status bizproc-statuses " . ($inprogress ? ' bizproc-status-' . (empty($tasks) ? "inprogress" : "attention") : '') . "\" onmouseover='BX.hint(this, \"" . addslashes($columnsBizProc['BIZPROC']) . "\")'></div>"; return array($actions, $columnsBizProc, $bizprocIcon); } } return array($actions, $columnsBizProc, $bizprocIcon); }
/** * @param string $workflowId * @param string $iblockType * @param int $elementId * @param int $iblockId * @param string $action Action stop or delete * @return string error */ public static function completeWorkflow($workflowId, $iblockType, $elementId, $iblockId, $action) { if (!Loader::includeModule('bizproc')) { return Loc::getMessage('LISTS_MODULE_BIZPROC_NOT_INSTALLED'); } global $USER; $userId = $USER->getID(); $documentType = BizprocDocument::generateDocumentComplexType($iblockType, $iblockId); $documentId = BizprocDocument::getDocumentComplexId($iblockType, $elementId); $documentStates = CBPDocument::getDocumentStates($documentType, $documentId); $permission = CBPDocument::canUserOperateDocument($action == 'stop' ? CBPCanUserOperateOperation::StartWorkflow : CBPCanUserOperateOperation::CreateWorkflow, $userId, $documentId, array("DocumentStates" => $documentStates)); if (!$permission) { return Loc::getMessage('LISTS_ACCESS_DENIED'); } $stringError = ''; if ($action == 'stop') { $errors = array(); CBPDocument::terminateWorkflow($workflowId, $documentId, $errors); if (!empty($errors)) { $stringError = ''; foreach ($errors as $error) { $stringError .= $error['message']; } $listError[] = array('id' => 'stopBizproc', 'text' => $stringError); } } else { $errors = array(); if (isset($documentStates[$workflowId]['WORKFLOW_STATUS']) && $documentStates[$workflowId]['WORKFLOW_STATUS'] !== null) { CBPDocument::terminateWorkflow($workflowId, $documentId, $errors); } if (!empty($errors)) { $stringError = ''; foreach ($errors as $error) { $stringError .= $error['message']; } $listError[] = array('id' => 'stopBizproc', 'text' => $stringError); } else { CBPTaskService::deleteByWorkflow($workflowId); CBPTrackingService::deleteByWorkflow($workflowId); CBPStateService::deleteWorkflow($workflowId); } } if (empty($listError) && Loader::includeModule('socialnetwork') && $iblockType == COption::getOptionString("lists", "livefeed_iblock_type_id")) { $sourceId = CBPStateService::getWorkflowIntegerId($workflowId); $resultQuery = CSocNetLog::getList(array(), array('EVENT_ID' => 'lists_new_element', 'SOURCE_ID' => $sourceId), false, false, array('ID')); while ($log = $resultQuery->fetch()) { CSocNetLog::delete($log['ID']); } } if (!empty($listError)) { $errorObject = new CAdminException($listError); $stringError = $errorObject->getString(); } return $stringError; }
protected function showBizProc($documentData) { $this->arResult['BIZPROC_PERMISSION'] = array(); $this->arResult['BIZPROC_PERMISSION']['START'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']); $this->arResult['BIZPROC_PERMISSION']['VIEW'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::ViewWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']); $this->arResult['BIZPROC_PERMISSION']['STOP'] = $this->arResult['BIZPROC_PERMISSION']['START']; $this->arResult['BIZPROC_PERMISSION']['DROP'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::CreateWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']); foreach ($documentData as $nameModuleId => $data) { $temporary[$nameModuleId] = CBPDocument::getDocumentStates($data['DOCUMENT_TYPE'], $data['DOCUMENT_ID']); } if (isset($temporary['OLD_FILE'])) { $allBizProcArray = array_merge($temporary['DISK'], $temporary['WEBDAV'], $temporary['OLD_FILE']); } else { $allBizProcArray = array_merge($temporary['DISK'], $temporary['WEBDAV']); } if (!empty($allBizProcArray)) { $userGroup = $this->getUser()->getUserGroupArray(); $userGroup[] = 'author'; if ($this->request->isPost() && intval($this->request->getPost('bizproc_index')) > 0) { $bizProcWorkflowId = array(); $bizprocIndex = intval($this->request->getPost('bizproc_index')); for ($i = 1; $i <= $bizprocIndex; $i++) { $bpId = trim($this->request->getPost("bizproc_id_" . $i)); $bpTemplateId = intval($this->request->getPost("bizproc_template_id_" . $i)); $bpEvent = trim($this->request->getPost("bizproc_event_" . $i)); if (strlen($bpId) > 0) { if (!array_key_exists($bpId, $allBizProcArray)) { continue; } } else { if (!array_key_exists($bpTemplateId, $allBizProcArray)) { continue; } $bpId = $bizProcWorkflowId[$bpTemplateId]; } if (strlen($bpEvent) > 0) { $errors = array(); CBPDocument::sendExternalEvent($bpId, $bpEvent, array("Groups" => $userGroup, "User" => $this->getUser()->getId()), $errors); } else { $errors = array(); foreach ($allBizProcArray as $idBizProc => $bizProcArray) { if ($idBizProc == $bpId) { CBPDocument::TerminateWorkflow($bpId, $bizProcArray['DOCUMENT_ID'], $errors); } } } if (!empty($errors)) { foreach ($errors as $error) { $this->arResult['ERROR_MESSAGE'] = $error['message']; } } else { LocalRedirect($this->arResult['PATH_TO_FILE_VIEW'] . "#tab-bp"); } } } $this->arResult['BIZPROC_LIST'] = array(); $count = 1; foreach ($allBizProcArray as $idBizProc => $bizProcArray) { if (intVal($bizProcArray["WORKFLOW_STATUS"]) < 0 || $idBizProc <= 0) { continue; } else { if (!CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::ViewWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID'], array("DocumentStates" => $bizProcArray, "WorkflowId" => $bizProcArray["ID"] > 0 ? $bizProcArray["ID"] : $bizProcArray["TEMPLATE_ID"]))) { continue; } } $groups = CBPDocument::getAllowableUserGroups($documentData['DISK']['DOCUMENT_TYPE']); foreach ($groups as $key => $val) { $groups[strtolower($key)] = $val; } $users = array(); $dmpWorkflow = CBPTrackingService::getList(array("ID" => "DESC"), array("WORKFLOW_ID" => $idBizProc, "TYPE" => array(CBPTrackingType::Report, CBPTrackingType::Custom, CBPTrackingType::FaultActivity)), false, array("nTopCount" => 5), array("ID", "TYPE", "MODIFIED", "ACTION_NOTE", "ACTION_TITLE", "ACTION_NAME", "EXECUTION_STATUS", "EXECUTION_RESULT")); while ($track = $dmpWorkflow->getNext()) { $messageTemplate = ""; switch ($track["TYPE"]) { case 1: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_1"); break; case 2: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_2"); break; case 3: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_3"); break; case 4: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_4"); break; case 5: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_5"); break; default: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_6"); } $name = strlen($track["ACTION_TITLE"]) > 0 ? $track["ACTION_TITLE"] : $track["ACTION_NAME"]; switch ($track["EXECUTION_STATUS"]) { case CBPActivityExecutionStatus::Initialized: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_1"); break; case CBPActivityExecutionStatus::Executing: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_2"); break; case CBPActivityExecutionStatus::Canceling: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_3"); break; case CBPActivityExecutionStatus::Closed: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_4"); break; case CBPActivityExecutionStatus::Faulting: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_5"); break; default: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_6"); } switch ($track["EXECUTION_RESULT"]) { case CBPActivityExecutionResult::None: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_1"); break; case CBPActivityExecutionResult::Succeeded: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_2"); break; case CBPActivityExecutionResult::Canceled: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_3"); break; case CBPActivityExecutionResult::Faulted: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_4"); break; case CBPActivityExecutionResult::Uninitialized: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_5"); break; default: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_6"); } $note = strlen($track["ACTION_NOTE"]) > 0 ? ": " . $track["ACTION_NOTE"] : ""; $pattern = array("#ACTIVITY#", "#STATUS#", "#RESULT#", "#NOTE#"); $replaceArray = array($name, $status, $result, $note); if (!empty($track["ACTION_NAME"]) && !empty($track["ACTION_TITLE"])) { $pattern[] = $track["ACTION_NAME"]; $replaceArray[] = $track["ACTION_TITLE"]; } $messageTemplate = str_replace($pattern, $replaceArray, $messageTemplate); if (preg_match_all("/(?<=\\{\\=user\\:)([^\\}]+)(?=\\})/is", $messageTemplate, $arMatches)) { $pattern = array(); $replacement = array(); foreach ($arMatches[0] as $user) { $user = preg_quote($user); if (in_array("/\\{\\=user\\:" . $user . "\\}/is", $pattern)) { continue; } $replace = ""; if (array_key_exists(strtolower($user), $groups)) { $replace = $groups[strtolower($user)]; } elseif (array_key_exists(strtoupper($user), $groups)) { $replace = $groups[strtoupper($user)]; } else { $id = intVal(str_replace("user_", "", $user)); if (!array_key_exists($id, $users)) { $dbRes = \CUser::getByID($id); $users[$id] = false; if ($dbRes && ($arUser = $dbRes->getNext())) { $name = \CUser::formatName($this->arParams["NAME_TEMPLATE"], $arUser); $arUser["FULL_NAME"] = empty($name) ? $arUser["LOGIN"] : $name; $users[$id] = $arUser; } } if (!empty($users[$id])) { $replace = "<a href=\"" . \CComponentEngine::makePathFromTemplate('/company/personal/user/#USER_ID#/', array("USER_ID" => $id)) . "\">" . $users[$id]["FULL_NAME"] . "</a>"; } } if (!empty($replace)) { $pattern[] = "/\\{\\=user\\:" . $user . "\\}/is"; $pattern[] = "/\\{\\=user\\:user\\_" . $user . "\\}/is"; $replacement[] = $replace; $replacement[] = $replace; } } $messageTemplate = preg_replace($pattern, $replacement, $messageTemplate); } $this->arResult['BIZPROC_LIST'][$count]['DUMP_WORKFLOW'][] = $messageTemplate; } $tasks = CBPDocument::getUserTasksForWorkflow($this->getUser()->getId(), $idBizProc); $events = CBPDocument::getAllowableEvents($this->getUser()->getId(), $userGroup, $bizProcArray); if (!empty($tasks)) { foreach ($tasks as $task) { $urlTaskBizproc = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_DISK_TASK'], array("ID" => $task['ID'])); $urlTaskBizproc .= "?back_url=" . urlencode($this->getApplication()->getCurPage()) . "&file=" . $this->file->getName(); $this->arResult['BIZPROC_LIST'][$count]['TASK']['URL'] = $urlTaskBizproc; $this->arResult['BIZPROC_LIST'][$count]['TASK']['TASK_ID'] = $task['ID']; $this->arResult['BIZPROC_LIST'][$count]['TASK']['TASK_NAME'] = $task['NAME']; } } $this->arResult['BIZPROC_LIST'][$count]['ID'] = $bizProcArray['ID']; $this->arResult['BIZPROC_LIST'][$count]['WORKFLOW_STATUS'] = $bizProcArray["WORKFLOW_STATUS"]; $this->arResult['BIZPROC_LIST'][$count]['TEMPLATE_ID'] = $bizProcArray['TEMPLATE_ID']; $this->arResult['BIZPROC_LIST'][$count]['TEMPLATE_NAME'] = $bizProcArray['TEMPLATE_NAME']; $this->arResult['BIZPROC_LIST'][$count]['STATE_MODIFIED'] = $bizProcArray['STATE_MODIFIED']; $this->arResult['BIZPROC_LIST'][$count]['STATE_TITLE'] = $bizProcArray['STATE_TITLE']; $this->arResult['BIZPROC_LIST'][$count]['STATE_NAME'] = $bizProcArray['STATE_NAME']; $this->arResult['BIZPROC_LIST'][$count]['EVENTS'] = $events; $count++; } } }