if ($arResult["PROCESSES"] && $arResult["USE_COMMENTS"]) { $documentState = CBPDocument::GetDocumentStates(BizprocDocument::generateDocumentComplexType($arIBlock["IBLOCK_TYPE_ID"], $arIBlock["ID"]), BizprocDocument::getDocumentComplexId($arIBlock["IBLOCK_TYPE_ID"], $data["ID"])); if (!empty($documentState)) { $documentState = current($documentState); $data["WORKFLOW_ID"] = $documentState["ID"]; } else { $data["WORKFLOW_ID"] = ''; } } $arUserGroupsForBPTmp = $arUserGroupsForBP; if ($USER->GetID() == $data["CREATED_BY"]) { $arUserGroupsForBPTmp[] = "Author"; } $arBPStart = array(); foreach ($arDocumentTemplates as $arWorkflowTemplate) { if (CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $USER->GetID(), BizprocDocument::getDocumentComplexId($arParams["IBLOCK_TYPE_ID"], intval($data["~ID"])), array("IBlockId" => $arIBlock["ID"], "AllUserGroups" => $arUserGroupsForBPTmp, "DocumentStates" => $arDocumentStatesForBP, "WorkflowId" => $arWorkflowTemplate["ID"]))) { $backUrl = $APPLICATION->GetCurPageParam(); $url = CHTTP::urlAddParams(str_replace(array("#list_id#", "#section_id#", "#element_id#", "#workflow_template_id#", "#group_id#"), array($arIBlock["ID"], intval($arResult["SECTION_ID"]), intval($data["~ID"]), $arWorkflowTemplate["ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["BIZPROC_WORKFLOW_START_URL"]), array("workflow_template_id" => $arWorkflowTemplate["ID"], "back_url" => $backUrl)); $url .= (strpos($url, "?") === false ? "?" : "&") . bitrix_sessid_get(); $arBPStart[] = array("TEXT" => $arWorkflowTemplate["NAME"], "ONCLICK" => "jsUtils.Redirect(arguments, '" . CUtil::JSEscape($url) . "')"); } } $url = str_replace(array("#list_id#", "#section_id#", "#element_id#", "#group_id#"), array($arIBlock["ID"], intval($arResult["SECTION_ID"]), intval($data["~ID"]), $arParams["SOCNET_GROUP_ID"]), $arParams["LIST_ELEMENT_URL"]); if ($arResult["ANY_SECTION"]) { $url = CHTTP::urlAddParams($url, array("list_section_id" => "")); } $aActions = array(); if (!$arResult["IS_SOCNET_GROUP_CLOSED"] && ($lists_perm >= CListPermissions::CAN_WRITE || CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $data["~ID"], "element_edit"))) { $aActions[] = array("ICONCLASS" => "edit", "TEXT" => GetMessage("CC_BLL_ELEMENT_ACTION_MENU_EDIT"), "ONCLICK" => "jsUtils.Redirect(arguments, '" . CUtil::JSEscape($url) . "')", "DEFAULT" => true); $arResult["ELEMENTS_CAN_MOVE"][] = $data["ID"]; } else {
} 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);
public function executeComponent() { if (!empty($this->arParams['ERROR'])) { ShowError(array_shift($this->arParams['ERROR'])); return; } $this->arResult['USER_ID'] = $this->arParams['USER_ID']; $this->arResult['GRID_ID'] = 'lists_processes'; $selectFields = array('ID', 'IBLOCK_TYPE_ID', 'IBLOCK_ID', 'NAME'); $gridOptions = new CGridOptions($this->arResult['GRID_ID']); $gridColumns = $gridOptions->getVisibleColumns(); $gridSort = $gridOptions->getSorting(array('sort' => array('ID' => 'desc'))); $this->arResult['HEADERS'] = array(array("id" => "ID", "name" => "ID", "default" => false, "sort" => "ID"), array('id' => 'DOCUMENT_NAME', 'name' => Loc::getMessage('CC_BLL_DOCUMENT_NAME'), 'default' => true, 'sort' => 'DOCUMENT_NAME'), array('id' => 'COMMENTS', 'name' => Loc::getMessage('CC_BLL_COMMENTS'), 'default' => true, 'sort' => '', 'hideName' => true, 'iconCls' => 'bp-comments-icon'), array('id' => 'WORKFLOW_PROGRESS', 'name' => Loc::getMessage('CC_BLL_WORKFLOW_PROGRESS'), 'default' => true, 'sort' => ''), array('id' => 'WORKFLOW_STATE', 'name' => Loc::getMessage('CC_BLL_WORKFLOW_STATE'), 'default' => false, 'sort' => '')); $this->arResult['FILTER'] = array(array("id" => "NAME", "name" => GetMessage("BPATL_NAME"), "type" => "string"), array('id' => 'TIMESTAMP_X', 'name' => Loc::getMessage('CC_BLL_MODIFIED'), 'type' => 'date'), array('id' => 'DATE_CREATE', 'name' => Loc::getMessage('CC_BLL_CREATED'), 'type' => 'date', 'default' => true)); $gridFilter = $gridOptions->getFilter($this->arResult['FILTER']); foreach ($gridFilter as $key => $value) { if (substr($key, -5) == "_from") { $op = ">="; $newKey = substr($key, 0, -5); } elseif (substr($key, -3) == "_to") { $op = "<="; $newKey = substr($key, 0, -3); if (in_array($newKey, array("TIMESTAMP_X", 'DATE_CREATE'))) { if (!preg_match("/\\d\\d:\\d\\d:\\d\\d\$/", $value)) { $value .= " 23:59:59"; } } } else { $op = ""; $newKey = $key; } $filter[$op . $newKey] = $value; } $this->arResult['SORT'] = $gridSort['sort']; $useComments = (bool) CModule::includeModule("forum"); $workflows = array(); $this->arResult['DATA'] = array(); $this->arResult["COMMENTS_COUNT"] = array(); $filter['CREATED_BY'] = $this->arParams['USER_ID']; $iblockTypeId = COption::GetOptionString("lists", "livefeed_iblock_type_id"); $filter['IBLOCK_TYPE'] = $iblockTypeId; $filter['CHECK_PERMISSIONS'] = $this->arParams['LIST_PERM'] >= CListPermissions::CAN_READ ? "N" : "Y"; $elementObject = CIBlockElement::getList($gridSort['sort'], $filter, false, $gridOptions->getNavParams(), $selectFields); $documentState = true; $path = rtrim(SITE_DIR, '/'); while ($element = $elementObject->fetch()) { $documentState = CBPDocument::GetDocumentStates(BizprocDocument::generateDocumentComplexType($iblockTypeId, $element['IBLOCK_ID']), BizprocDocument::getDocumentComplexId($iblockTypeId, $element['ID'])); $this->arResult['DATA'][$element['ID']]['ID'] = $element['ID']; $this->arResult['DATA'][$element['ID']]['DOCUMENT_NAME'] = $element['NAME']; $this->arResult['DATA'][$element['ID']]['DOCUMENT_URL'] = $path . COption::GetOptionString('lists', 'livefeed_url') . '?livefeed=y&list_id=' . $element["IBLOCK_ID"] . '&element_id=' . $element['ID']; if (!empty($documentState)) { $this->arResult['DATA'][$element['ID']]['DOCUMENT_STATE'] = true; $documentState = current($documentState); $this->arResult['DATA'][$element['ID']]['WORKFLOW_ID'] = $documentState['ID']; $this->arResult['DATA'][$element['ID']]["WORKFLOW_NAME"] = $documentState["TEMPLATE_NAME"]; $this->arResult['DATA'][$element['ID']]["WORKFLOW_STATE"] = $documentState["STATE_TITLE"]; $this->arResult['DATA'][$element['ID']]["WORKFLOW_STARTED"] = FormatDateFromDB($documentState["STARTED_FORMATTED"]); $this->arResult['DATA'][$element['ID']]["WORKFLOW_STARTED_BY"] = ""; if (intval($documentState["STARTED_BY"]) > 0) { $dbUserTmp = CUser::getByID($documentState["STARTED_BY"]); $arUserTmp = $dbUserTmp->fetch(); $this->arResult['DATA'][$element['ID']]["WORKFLOW_STARTED_BY"] = CUser::FormatName($this->arParams["NAME_TEMPLATE"], $arUserTmp, true); $this->arResult['DATA'][$element['ID']]["WORKFLOW_STARTED_BY"] .= " [" . $documentState["STARTED_BY"] . "]"; } $this->arResult['DATA'][$element['ID']]['MODULE_ID'] = $documentState["DOCUMENT_ID"][0]; $this->arResult['DATA'][$element['ID']]['ENTITY'] = $documentState["DOCUMENT_ID"][1]; $this->arResult['DATA'][$element['ID']]['DOCUMENT_ID'] = $documentState["DOCUMENT_ID"][2]; } else { $documentState = false; $this->arResult['DATA'][$element['ID']]['DOCUMENT_STATE'] = false; } } foreach ($this->arResult['DATA'] as $data) { if ($documentState) { if ($useComments) { $workflows[] = 'WF_' . $data['WORKFLOW_ID']; } } $actions = array(); if (strlen($data["DOCUMENT_URL"]) > 0) { $actions[] = array('ICONCLASS' => '', 'DEFAULT' => false, 'TEXT' => Loc::getMessage('CC_BLL_C_DOCUMENT'), 'ONCLICK' => 'window.open("' . $data["DOCUMENT_URL"] . '");'); } $this->arResult['RECORDS'][] = array('data' => $data, 'actions' => $actions); } if ($useComments && $documentState) { $workflows = array_unique($workflows); if ($workflows) { $iterator = CForumTopic::getList(array(), array("@XML_ID" => $workflows)); while ($row = $iterator->fetch()) { $this->arResult["COMMENTS_COUNT"][$row['XML_ID']] = $row['POSTS']; } } } $this->arResult['COUNTERS'] = array('all' => 0); $this->arResult["ROWS_COUNT"] = $elementObject->selectedRowsCount(); $this->arResult["NAV_RESULT"] = $elementObject; if ($this->arParams['SET_TITLE'] == 'Y') { $this->getApplication()->setTitle(Loc::getMessage('CC_BLL_TITLE')); } $this->includeComponentTemplate(); }
/** * @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; }
foreach ($arTasks as $arTask) { $back_url = CHTTP::urlAddParams($APPLICATION->GetCurPageParam("", array("lists_element_edit_active_tab")), array("lists_element_edit_active_tab" => "tab_bp")); $url = CHTTP::urlAddParams(str_replace(array("#list_id#", "#section_id#", "#element_id#", "#task_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($arResult["SECTION_ID"]), $arResult["ELEMENT_ID"], $arTask["ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~BIZPROC_TASK_URL"]), array("back_url" => $back_url), array("skip_empty" => true, "encode" => true)); $html .= '<a href="' . htmlspecialcharsbx($url) . '" title="' . strip_tags($arTask["DESCRIPTION"]) . '">' . $arTask["NAME"] . '</a><br />'; } $arTab2Fields[] = array("id" => "BIZPROC_TASKS" . $bizProcIndex, "name" => GetMessage("CT_BLEE_BIZPROC_TASKS"), "type" => "label", "value" => $html); } } } } if (!$bizProcIndex) { $arTab2Fields[] = array("id" => "BIZPROC_NO", "name" => GetMessage("CT_BLEE_BIZPROC_NA_LABEL"), "type" => "label", "value" => GetMessage("CT_BLEE_BIZPROC_NA")); } $custom_html .= '<input type="hidden" name="bizproc_index" value="' . $bizProcIndex . '">'; if ($arResult["ELEMENT_ID"]) { $bStartWorkflowPermission = CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $USER->GetID(), BizprocDocument::getDocumentComplexId($arParams["IBLOCK_TYPE_ID"], $arResult["ELEMENT_ID"]), array("AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates, "WorkflowId" => $arDocumentState["TEMPLATE_ID"])); if ($bStartWorkflowPermission) { $arTab2Fields[] = array("id" => "BIZPROC_NEW", "name" => GetMessage("CT_BLEE_BIZPROC_NEW"), "type" => "section"); $back_url = CHTTP::urlAddParams($APPLICATION->GetCurPageParam("", array("lists_element_edit_active_tab")), array("lists_element_edit_active_tab" => "tab_bp")); $url = CHTTP::urlAddParams(str_replace(array("#list_id#", "#section_id#", "#element_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($arResult["SECTION_ID"]), $arResult["ELEMENT_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~BIZPROC_WORKFLOW_START_URL"]), array("back_url" => $back_url, "sessid" => bitrix_sessid()), array("skip_empty" => true, "encode" => true)); $arTab2Fields[] = array("id" => "BIZPROC_NEW_START", "name" => GetMessage("CT_BLEE_BIZPROC_START"), "type" => "custom", "colspan" => true, "value" => '<a href="' . htmlspecialcharsbx($url) . '">' . GetMessage("CT_BLEE_BIZPROC_START") . '</a>'); } } $arTabs[] = array("id" => "tab_bp", "name" => GetMessage("CT_BLEE_BIZPROC_TAB"), "icon" => "", "fields" => $arTab2Fields); } if (isset($arResult["RIGHTS"])) { ob_start(); IBlockShowRights('element', $arResult["IBLOCK_ID"], $arResult["ELEMENT_ID"], "", "RIGHTS", $arResult["TASKS"], $arResult["RIGHTS"], true, $arResult["ELEMENT_ID"] <= 0, $arResult["SELECTED"], $arResult["HIGHLIGHT"]); $rights_html = ob_get_contents(); ob_end_clean(); $rights_fields = array(array("id" => "RIGHTS", "name" => GetMessage("CT_BLEE_ACCESS_RIGHTS"), "type" => "custom", "colspan" => true, "value" => $rights_html));
protected function getArrayBizproc($data = array()) { $currentUserId = $GLOBALS["USER"]->GetID(); $html = ""; if ($this->arResult["IBLOCK"]["BIZPROC"] == "Y" && CModule::IncludeModule('bizproc')) { $this->arResult["ELEMENTS_HEADERS"]["BIZPROC"] = array("name" => Loc::getMessage("CC_BLL_COLUMN_BIZPROC"), "default" => true, "sort" => false); $arDocumentStates = CBPDocument::GetDocumentStates(BizprocDocument::generateDocumentComplexType($this->arParams["IBLOCK_TYPE_ID"], $this->arResult["IBLOCK_ID"]), BizprocDocument::getDocumentComplexId($this->arParams["IBLOCK_TYPE_ID"], $data["ID"])); $userGroups = $GLOBALS["USER"]->GetUserGroupArray(); if ($data["~CREATED_BY"] == $currentUserId) { $userGroups[] = "Author"; } $ii = 0; foreach ($arDocumentStates as $workflowId => $workflowState) { if (strlen($workflowState["TEMPLATE_NAME"]) > 0) { $html .= "" . $workflowState["TEMPLATE_NAME"] . ":\r\n"; } else { $html .= "" . ++$ii . ":\r\n"; } $html .= "" . (strlen($workflowState["STATE_TITLE"]) > 0 ? $workflowState["STATE_TITLE"] : $workflowState["STATE_NAME"]) . "\r\n"; } } return $html; }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } $file = trim(preg_replace("'[\\\\/]+'", "/", dirname(__FILE__) . "/lang/" . LANGUAGE_ID . "/result_modifier.php")); __IncludeLang($file); $arArrays = array(); $arElements = array(); $arSections = array(); $CURRENT_USER_ID = $GLOBALS["USER"]->GetID(); $CURRENT_USER_GROUPS = $GLOBALS["USER"]->GetUserGroupArray(); foreach ($arResult["ELEMENTS_ROWS"] as $i => $arRow) { if ($arResult["BIZPROC"] == "Y") { $arDocumentStates = CBPDocument::GetDocumentStates(BizprocDocument::generateDocumentComplexType($arParams["IBLOCK_TYPE_ID"], $arResult["IBLOCK_ID"]), BizprocDocument::getDocumentComplexId($arParams["IBLOCK_TYPE_ID"], $arRow["data"]["ID"])); $USER_GROUPS = $CURRENT_USER_GROUPS; if ($arRow["data"]["~CREATED_BY"] == $CURRENT_USER_ID) { $USER_GROUPS[] = "Author"; } $ii = 0; $html = ""; $proccesses = false; if ($arResult["PROCESSES"] && $arResult["USE_COMMENTS"]) { $proccesses = true; $workflows = array(); } foreach ($arDocumentStates as $kk => $vv) { if ($vv["ID"] && $proccesses && !empty($arRow["data"]["WORKFLOW_ID"])) { $workflows[] = 'WF_' . $vv["ID"]; } $canViewWorkflow = CIBlockDocument::CanUserOperateDocument(CBPCanUserOperateOperation::ViewWorkflow, $CURRENT_USER_ID, $arRow["data"]["ID"], array("IBlockPermission" => $arResult["IBLOCK_PERM"], "AllUserGroups" => $USER_GROUPS, "DocumentStates" => $arDocumentStates, "WorkflowId" => $kk));