public function Execute() { $rootActivity = $this->GetRootActivity(); $documentId = $rootActivity->GetDocumentId(); CBPDocument::TerminateWorkflow($this->GetWorkflowInstanceId(), $documentId, $arErrorsTmp); throw new Exception("TerminateActivity"); return CBPActivityExecutionStatus::Closed; }
include($_SERVER["DOCUMENT_ROOT"].$arIBTYPE["EDIT_FILE_BEFORE"]); } if ( $bBizproc && $canWrite && $historyId <= 0 && $ID > 0 && $REQUEST_METHOD=="GET" && isset($_REQUEST["stop_bizproc"]) && strlen($_REQUEST["stop_bizproc"]) > 0 && check_bitrix_sessid() ) { CBPDocument::TerminateWorkflow( $_REQUEST["stop_bizproc"], array(MODULE_ID, ENTITY, $ID), $ar ); if (!empty($ar)) { $str = ""; foreach ($ar as $a) $str .= $a["message"]; $error = new _CIBlockError(2, "STOP_BP_ERROR", $str); } else { LocalRedirect($APPLICATION->GetCurPageParam("", array("stop_bizproc", "sessid"))); } }
} else { $arResult["SECTION_ID"] = false; } $tab_name = $arResult["FORM_ID"] . "_active_tab"; //Assume there was no error $bVarsFromForm = false; //Form submitted if ($_SERVER["REQUEST_METHOD"] == "POST" && check_bitrix_sessid() && !$arResult["IS_SOCNET_GROUP_CLOSED"] && ($arParams["CAN_EDIT"] || $ELEMENT_ID > 0 && CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $ELEMENT_ID, "element_delete"))) { $obList->ActualizeDocumentAdminPage(str_replace(array("#list_id#", "#group_id#"), array($arResult["IBLOCK_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_ELEMENT_URL"])); //When Save or Apply buttons was pressed if (isset($_POST["action"]) && $_POST["action"] == "stop_bizproc") { if (isset($_POST["stop_bizproc"]) && strlen($_POST["stop_bizproc"]) && $bBizproc) { $strError = ""; if (CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $arResult["ELEMENT_ID"], "element_rights_edit")) { $arErrorsTmp = array(); CBPDocument::TerminateWorkflow($_POST["stop_bizproc"], BizprocDocument::getDocumentComplexId($arParams["IBLOCK_TYPE_ID"], $arResult["ELEMENT_ID"]), $arErrorsTmp); foreach ($arErrorsTmp as $a) { $strError .= $a["message"] . "<br />"; } } else { $strError .= GetMessage("CC_BLEE_ACCESS_DENIED") . "<br />"; } if ($strError) { ShowError($strError); $bVarsFromForm = true; } else { $url = CHTTP::urlAddParams(str_replace(array("#list_id#", "#section_id#", "#element_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($arResult["ELEMENT_FIELDS"]["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);
} } else { $arResult["ErrorMessage"] .= GetMessage("BPWC_WLC_MISSING_DOCUMENT") . ". "; } } else { $arResult["ErrorMessage"] .= GetMessage("BPWC_WLC_MISSING_BP") . ". "; } if (strlen($arResult["ErrorMessage"]) <= 0) { LocalRedirect($APPLICATION->GetCurPageParam("", array("sessid", "stop_bizproc_id", "process_state_event", "bizproc_event", "bizproc_id", "delete_bizproc_id"))); } } } if ($_SERVER["REQUEST_METHOD"] == "GET" && strlen($_REQUEST["stop_bizproc_id"]) > 0 && check_bitrix_sessid() && $arResult["AllowAdmin"]) { $arState = CBPStateService::GetWorkflowState($_REQUEST["stop_bizproc_id"]); if (count($arState) > 0) { CBPDocument::TerminateWorkflow($_REQUEST["stop_bizproc_id"], $arState["DOCUMENT_ID"], $arErrorsTmp); if (count($arErrorsTmp) > 0) { foreach ($arErrorsTmp as $e) { $arResult["ErrorMessage"] .= $e["message"] . ". "; } } } else { $arResult["ErrorMessage"] .= GetMessage("BPWC_WLC_MISSING_BP") . ". "; } if (strlen($arResult["ErrorMessage"]) <= 0) { LocalRedirect($APPLICATION->GetCurPageParam("", array("sessid", "stop_bizproc_id", "delete_bizproc_id"))); } } if ($_SERVER["REQUEST_METHOD"] == "GET" && strlen($_REQUEST["delete_bizproc_id"]) > 0 && check_bitrix_sessid() && $arResult["AllowAdmin"]) { $arState = CBPStateService::GetWorkflowState($_REQUEST["delete_bizproc_id"]); if (count($arState) > 0) {
if ($_REQUEST["AJAX_CALL"] != "Y" || !empty($_REQUEST["bxajaxid"])) { LocalRedirect($url); } $APPLICATION->RestartBuffer(); echo CUtil::PhpToJSObject(array("result" => $res["LOCK_STATUS"], "status" => $status)); die; } /******************************************************************** / LOCK ********************************************************************/ $CHILD_ID = false; $this->IncludeComponentLang("action.php"); if (!check_bitrix_sessid()) { $arError[] = array("id" => "bad_sessid", "text" => GetMessage("WD_ERROR_BAD_SESSID")); } elseif ($ob->workflow == "bizproc" && strlen($_REQUEST["stop_bizproc"]) > 0) { CBPDocument::TerminateWorkflow($_REQUEST["stop_bizproc"], array("webdav", $arParams["BIZPROC"]["ENTITY"], $arParams["ELEMENT_ID"]), $ar); foreach ($ar as $a) { $arError[] = array("id" => "bizproc", "text" => $a["message"]); } } elseif ($arParams["ACTION"] == "CLONE") { global $DB; $DB->startTransaction(); $options = array("clone" => true, "PARENT_ELEMENT_ID" => $arParams["ELEMENT_ID"], "FILE_NAME" => $arResult["ELEMENT"]["NAME"], "NAME" => !empty($_REQUEST["NAME"]) ? $_REQUEST["NAME"] : $arResult["ELEMENT"]["NAME"], "WF_STATUS_ID" => "2", "PREVIEW_TEXT" => trim($_REQUEST["PREVIEW_TEXT"]), "arFile" => $_FILES[$ob->file_prop]); if (!$ob->put_commit($options) || $options["ELEMENT_ID"] <= 0) { $DB->rollback(); $arError[] = array("id" => "clone_error", "text" => $ob->LAST_ERROR); } else { $DB->commit(); $ob->UNLOCK($tmp = array("element_id" => $arParams["ELEMENT_ID"])); $arParams["ELEMENT_ID"] = $options["ELEMENT_ID"]; }
} } else { $arResult["SECTION_ID"] = false; } //Assume there was no error $bVarsFromForm = false; //Form submitted if ($_SERVER["REQUEST_METHOD"] == "POST" && check_bitrix_sessid() && ($arParams["CAN_EDIT"] || $ELEMENT_ID > 0 && CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $ELEMENT_ID, "element_delete"))) { $obList->ActualizeDocumentAdminPage(str_replace(array("#list_id#", "#group_id#"), array($arResult["IBLOCK_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_ELEMENT_URL"])); //When Save or Apply buttons was pressed if (isset($_POST["action"]) && $_POST["action"] == "stop_bizproc") { if (isset($_POST["stop_bizproc"]) && strlen($_POST["stop_bizproc"]) && $bBizproc) { $strError = ""; if (CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $arResult["ELEMENT_ID"], "element_rights_edit")) { $arErrorsTmp = array(); CBPDocument::TerminateWorkflow($_POST["stop_bizproc"], array("iblock", "CIBlockDocument", $arResult["ELEMENT_ID"]), $arErrorsTmp); foreach ($arErrorsTmp as $a) { $strError .= $a["message"] . "<br />"; } } else { $strError .= GetMessage("CC_BLEE_ACCESS_DENIED") . "<br />"; } if ($strError) { ShowError($strError); $bVarsFromForm = true; } else { $url = CHTTP::urlAddParams(str_replace(array("#list_id#", "#section_id#", "#element_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($arResult["ELEMENT_FIELDS"]["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);
$arResult["ERROR_MESSAGE"] = ""; $arParams["StartWorkflowPermission"] = CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $USER->GetID(), $arParams["DOCUMENT_ID"], array("DocumentStates" => $arDocumentStates)) ? "Y" : "N"; $arParams["StopWorkflowPermission"] = $arParams["StartWorkflowPermission"]; $arParams["DropWorkflowPermission"] = CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::CreateWorkflow, $GLOBALS["USER"]->GetID(), $arParams["DOCUMENT_ID"], array("DocumentStates" => $arDocumentStates)) ? "Y" : "N"; /******************************************************************** Action ********************************************************************/ if (!((!empty($_REQUEST["action"]) || $_SERVER['REQUEST_METHOD'] == "POST") && check_bitrix_sessid())) { } elseif (!empty($_POST["cancel"]) && !empty($arParams["back_url"])) { LocalRedirect($arParams["back_url"]); } else { if ($_REQUEST["action"] == "stop_bizproc") { if ($arParams["StopWorkflowPermission"] != "Y") { $arError[] = array("id" => "access_denied", "text" => GetMessage("BPADH_NO_PERMS")); } else { CBPDocument::TerminateWorkflow($_REQUEST["id"], $arParams["DOCUMENT_ID"], $ar); if (count($ar) > 0) { $str = ""; foreach ($ar as $a) { $str .= $a["message"]; } $arError[] = array("id" => "stop_bizproc", "text" => $str); } } } elseif ($_REQUEST["action"] == "del_bizproc") { if ($arParams["DropWorkflowPermission"] != "Y") { $arError[] = array("id" => "access_denied", "text" => GetMessage("BPADH_NO_PERMS")); } else { CBPTrackingService::DeleteByWorkflow($_REQUEST["id"]); CBPStateService::DeleteWorkflow($_REQUEST["id"]); }
public function processActionStopBizProc() { $this->checkRequiredPostParams(array('fileId', 'idBizProc')); if (!Loader::includeModule("bizproc")) { $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FILE_VIEW_BIZPROC_LOAD'))); } if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $fileId = (int) $this->request->getPost('fileId'); /** @var File $file */ $file = File::loadById($fileId); if (!$file) { $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FILE_VIEW_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT)); $this->sendJsonErrorResponse(); } $documentData = array('DISK' => array('DOCUMENT_ID' => \Bitrix\Disk\BizProcDocument::getDocumentComplexId($fileId)), 'WEBDAV' => array('DOCUMENT_ID' => \Bitrix\Disk\BizProcDocumentCompatible::getDocumentComplexId($fileId))); $webdavFileId = $file->getXmlId(); if (!empty($webdavFileId)) { $documentData['OLD_FILE_COMMON'] = array('DOCUMENT_ID' => array('webdav', 'CIBlockDocumentWebdav', $webdavFileId)); $documentData['OLD_FILE_GROUP'] = array('DOCUMENT_ID' => array('webdav', 'CIBlockDocumentWebdavSocnet', $webdavFileId)); } $workflowId = $this->request->getPost('idBizProc'); $error = array(); foreach ($documentData as $nameModule => $data) { $availabilityProcess = CBPDocument::GetDocumentState($data['DOCUMENT_ID'], $workflowId); if (!empty($availabilityProcess)) { if (CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $this->getUser()->getId(), $data['DOCUMENT_ID'])) { CBPDocument::TerminateWorkflow($workflowId, $data['DOCUMENT_ID'], $error); } } } if ($error) { $this->errorCollection->addOne(new Error(array_shift($error))); $this->sendJsonErrorResponse(); } $this->sendJsonSuccessResponse(); }
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++; } } }