26 $templateIds =
array();
27 $db = CBPWorkflowTemplateLoader::GetList(
array(),
array(
"DOCUMENT_TYPE" => $oldType),
false,
false,
array(
"ID"));
28 while (
$ar = $db->Fetch())
29 $templateIds[] =
$ar[
"ID"];
31 foreach ($templateIds as $id)
32 CBPWorkflowTemplateLoader::Update($id,
array(
"DOCUMENT_TYPE" => $newType));
34 if (
count($templateIds) > 0)
36 CBPHistoryService::MigrateDocumentType($oldType, $newType, $templateIds);
37 CBPStateService::MigrateDocumentType($oldType, $newType, $templateIds);
110 $arDocumentStates =
array();
112 if ($documentId !=
null)
113 $arDocumentStates = CBPStateService::GetDocumentStates($documentId);
115 $arTemplateStates = CBPWorkflowTemplateLoader::GetDocumentTypeStates(
120 return ($arDocumentStates + $arTemplateStates);
125 $documentId = CBPHelper::ParseDocumentId($documentId);
133 if ($limit > 0 &&
count($workflowIds) > $limit)
135 $workflowIds = array_slice($workflowIds, 0, $limit);
138 return CBPStateService::GetDocumentStates($documentId, $workflowIds);
150 $arDocumentState = CBPStateService::GetDocumentStates($documentId, $workflowId);
151 return $arDocumentState;
156 CBPStateService::MergeStates($firstDocumentId, $secondDocumentId);
158 CBPHistoryService::MergeHistory($firstDocumentId, $secondDocumentId);
173 if (!is_array($arState))
183 if ($appendExtendedGroups)
192 $allowableEvents = [];
193 if (is_array($arState[
'STATE_PARAMETERS']) && $arState[
'STATE_PARAMETERS'])
195 foreach ($arState[
'STATE_PARAMETERS'] as $parameter)
197 $parameter[
'PERMISSION'] = CBPHelper::convertToExtendedGroups($parameter[
'PERMISSION']);
198 if (!$parameter[
'PERMISSION'] || array_intersect(
$arGroups, $parameter[
'PERMISSION']))
200 $allowableEvents[] = [
201 'NAME' => $parameter[
'NAME'],
202 'TITLE' => !empty($parameter[
'TITLE']) ? $parameter[
'TITLE'] : $parameter[
'NAME'],
208 return $allowableEvents;
213 [
$moduleId,
$entity, $documentType] = CBPHelper::ParseDocumentId($parameterDocumentId);
221 $runtime = CBPRuntime::GetRuntime();
222 $runtime->StartRuntime();
224 $historyService = $runtime->GetService(
"HistoryService");
225 $documentService = $runtime->GetService(
"DocumentService");
229 $historyIndex = $historyService->AddHistory(
231 "DOCUMENT_ID" => $parameterDocumentId,
238 $arDocument = $documentService->GetDocumentForHistory($parameterDocumentId, $historyIndex);
239 if (!is_array($arDocument))
242 $historyService->UpdateHistory(
246 "DOCUMENT" => $arDocument,
250 return $historyIndex;
268 if (!is_array($arStates))
274 if ($appendExtendedGroups)
283 foreach ($arStates as $arState)
285 if (is_array($arState[
"STATE_PERMISSIONS"]) &&
count($arState[
"STATE_PERMISSIONS"]) > 0)
290 foreach ($arState[
"STATE_PERMISSIONS"] as $operation => $arOperationGroups)
292 $arOperationGroups = CBPHelper::convertToExtendedGroups($arOperationGroups);
295 $result[] = mb_strtolower($operation);
318 $operation = trim($operation);
319 if ($operation ==
'')
323 if ($operations ===
null)
326 return in_array($operation, $operations);
339 public static function startWorkflow($workflowTemplateId, $documentId, $parameters, &
$errors, $parentWorkflow =
null)
342 $parameters = static::prepareWorkflowParameters($workflowTemplateId, $parameters);
346 $wi = CBPRuntime::GetRuntime()->createWorkflow($workflowTemplateId, $documentId, $parameters, $parentWorkflow);
349 return $wi->GetInstanceId();
354 "code" => $e->getCode(),
355 "message" => $e->getMessage(),
356 "file" => $e->getFile() .
" [" . $e->getLine() .
"]",
366 $runtime = CBPRuntime::GetRuntime(
true);
368 $parameters = static::prepareWorkflowParameters($workflowTemplateId, $parameters);
372 $workflow = $runtime->createDebugWorkflow($workflowTemplateId, $documentId, $parameters);
375 return $workflow->getInstanceId();
380 "code" => $e->getCode(),
381 "message" => $e->getMessage(),
382 "file" => $e->getFile().
" [".$e->getLine().
"]"
389 private static function prepareWorkflowParameters($workflowTemplateId, $parameters):
array
391 static $usagesCache = [];
393 if (!is_array($parameters))
395 $parameters = [$parameters];
398 if (!array_key_exists(static::PARAM_TAGRET_USER, $parameters))
400 $currentUserId = Main\Engine\CurrentUser::get()->getId();
401 $parameters[static::PARAM_TAGRET_USER] = isset($currentUserId) ?
"user_{$currentUserId}" :
null;
404 if (!isset($parameters[static::PARAM_MODIFIED_DOCUMENT_FIELDS]))
406 $parameters[static::PARAM_MODIFIED_DOCUMENT_FIELDS] =
false;
409 if (!isset($parameters[static::PARAM_DOCUMENT_EVENT_TYPE]))
414 if (!isset($parameters[static::PARAM_PRE_GENERATED_WORKFLOW_ID]))
419 if (!isset($usagesCache[$workflowTemplateId]))
421 $tpl = WorkflowTemplateTable::getById($workflowTemplateId)->fetchObject();
426 $usages = $tpl->collectUsages();
427 $usagesCache[$workflowTemplateId] = $usages->getValuesBySourceType(
428 SourceType::DocumentField
431 catch (\Throwable $e)
433 $usagesCache[$workflowTemplateId] = [];
438 $parameters[static::PARAM_USED_DOCUMENT_FIELDS] = $usagesCache[$workflowTemplateId] ?? [];
452 public static function autoStartWorkflows($documentType, $autoExecute, $documentId, $arParameters, &$arErrors)
454 static $usagesCache = [];
457 $runtime = CBPRuntime::GetRuntime();
459 if (!is_array($arParameters))
460 $arParameters =
array($arParameters);
462 if (!isset($arParameters[static::PARAM_TAGRET_USER]))
463 $arParameters[static::PARAM_TAGRET_USER] = is_object(
$GLOBALS[
"USER"]) ?
"user_".intval(
$GLOBALS[
"USER"]->GetID()) :
null;
465 if (!isset($arParameters[static::PARAM_MODIFIED_DOCUMENT_FIELDS]))
466 $arParameters[static::PARAM_MODIFIED_DOCUMENT_FIELDS] =
false;
468 $arParameters[static::PARAM_DOCUMENT_EVENT_TYPE] = $autoExecute;
470 $templates = CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType($documentType, $autoExecute);
475 if (!isset($usagesCache[
$template[
'ID']]))
477 $tpl = WorkflowTemplateTable::getById(
$template[
'ID'])->fetchObject();
480 $usages = $tpl->collectUsages();
481 $usagesCache[
$template[
'ID']] = $usages->getValuesBySourceType(
482 SourceType::DocumentField
487 $arParameters[static::PARAM_USED_DOCUMENT_FIELDS] = $usagesCache[
$template[
'ID']] ?? [];
489 $wi = $runtime->CreateWorkflow(
$template[
'ID'], $documentId, $arParameters);
495 "code" => $e->getCode(),
496 "message" => $e->getMessage(),
497 "file" => $e->getFile().
" [".$e->getLine().
"]"
511 public static function sendExternalEvent($workflowId, $workflowEvent, $arParameters, &$arErrors)
517 CBPRuntime::SendExternalEvent($workflowId, $workflowEvent, $arParameters);
522 "code" => $e->getCode(),
523 "message" => $e->getMessage(),
524 "file" => $e->getFile().
" [".$e->getLine().
"]"
537 public static function terminateWorkflow($workflowId, $documentId, &$arErrors, $stateTitle =
'')
541 $runtime = CBPRuntime::GetRuntime();
545 $workflow = $runtime->GetWorkflow($workflowId,
true);
548 $d = $workflow->GetDocumentId();
549 if ($d[0] != $documentId[0] || $d[1] != $documentId[1] || mb_strtolower($d[2]) !== mb_strtolower($documentId[2]))
552 $workflow->Terminate(
null, $stateTitle);
557 "code" => $e->getCode(),
558 "message" => $e->getMessage(),
559 "file" => $e->getFile().
" [".$e->getLine().
"]"
566 public static function killWorkflow($workflowId, $terminate =
true, $documentId =
null)
570 static::TerminateWorkflow($workflowId, $documentId,
$errors);
575 CBPTaskService::DeleteByWorkflow($workflowId);
576 CBPStateService::DeleteWorkflow($workflowId);
582 CBPTrackingService::DeleteByWorkflow($workflowId);
585 $event =
new Event(
'bizproc',
'onAfterWorkflowKill', [
'ID' => $workflowId]);
602 foreach ($instanceIds as $instanceId)
604 static::TerminateWorkflow($instanceId, $documentId,
$errors);
608 if ($debugSession && $debugSession->isFixedDocument($documentId))
613 \CBPHistoryService::DeleteByDocument($documentId);
621 CBPRuntime::getRuntime()->onDocumentDelete($documentId);
631 $result = $task?->postTaskForm(is_array($arRequest) ? $arRequest : []);
638 'code' =>
$error->getCode(),
639 'message' =>
$error->getMessage(),
641 'customData' =>
$error->getCustomData(),
653 return CBPActivity::CallStaticMethod(
662 return CBPActivity::CallStaticMethod(
690 $ids = array_filter(array_map(
'intval', (
array)$ids));
699 array(
'ID',
'NAME',
'WORKFLOW_ID',
'ACTIVITY',
'ACTIVITY_NAME',
'IS_INLINE'));
702 if ($task[
'IS_INLINE'] ==
'Y')
704 $taskErrors =
array();
706 if (!empty($taskErrors))
707 foreach ($taskErrors as
$error)
725 public static function delegateTasks($fromUserId, $toUserId, $ids =
array(), &
$errors =
array(), $allowedDelegationType =
null)
728 'USER_ID' => $fromUserId,
735 $ids = array_filter(array_map(
'intval', (
array)$ids));
742 $isSinglePostfix =
count($ids) === 1 ?
'_SINGLE_MSGVER_1' :
'_MSGVER_1';
749 array(
'ID',
'NAME',
'WORKFLOW_ID',
'ACTIVITY_NAME',
'DELEGATION_TYPE')
752 $trackingService =
null;
754 $workflowIdsToSync = [];
760 $errors[] = Main\Localization\Loc::getMessage(
'BPCGDOC_ERROR_DELEGATE_2_SINGLE_MSGVER_1');
765 if ($allowedDelegationType && !in_array((
int)$task[
'DELEGATION_TYPE'], $allowedDelegationType,
true))
768 'BPCGDOC_ERROR_DELEGATE_' . $task[
'DELEGATION_TYPE'] . $isSinglePostfix,
769 [
'#NAME#' => $task[
'NAME']],
774 $errors[] =
GetMessage(
'BPCGDOC_ERROR_DELEGATE' . $isSinglePostfix, [
'#NAME#' => $task[
'NAME']]);
780 $runtime = CBPRuntime::GetRuntime();
781 $runtime->StartRuntime();
783 $trackingService = $runtime->GetService(
'TrackingService');
787 $trackingService->Write(
788 $task[
'WORKFLOW_ID'],
790 $task[
'ACTIVITY_NAME'],
795 '#NAME#' => $task[
'NAME'],
796 '#FROM#' =>
'{=user:user_'.$fromUserId.
'}',
797 '#TO#' =>
'{=user:user_'.$toUserId.
'}'
800 $workflowIdsToSync[$task[
'WORKFLOW_ID']] =
true;
806 'FROM_USER_ID' => $fromUserId,
807 'TO_USER_ID' => $toUserId,
809 "NOTIFY_MODULE" =>
"bizproc",
810 "NOTIFY_EVENT" =>
"delegate_task",
811 "NOTIFY_TAG" =>
"BIZPROC|TASK|".$task[
'ID'],
812 'MESSAGE' =>
GetMessage(
'BPCGDOC_DELEGATE_NOTIFY_TEXT_MSGVER_1',
array(
813 '#TASK_URL#' =>
'/company/personal/bizproc/'.(
int)$task[
'ID'].
'/',
814 '#TASK_NAME#' => $task[
'NAME']
821 if ($workflowIdsToSync)
823 foreach (array_keys($workflowIdsToSync) as $workflowId)
825 Bizproc\Workflow\Entity\WorkflowUserTable::syncOnTaskUpdated($workflowId);
841 return CBPActivity::CallStaticMethod(
$activity,
'getTaskControls', [$arTask,
$userId]);
862 "message" =>
GetMessage(
"BPCGDOC_EMPTY_WD_ID_MSGVER_1"),
867 if (!isset($arWorkflowParameters) || !is_array($arWorkflowParameters))
868 $arWorkflowParameters =
array();
870 $arWorkflowParametersValues =
array();
873 foreach ($_FILES as
$k => $v)
875 if (array_key_exists(
"name", $v))
877 if (is_array($v[
"name"]))
879 $ks = array_keys($v[
"name"]);
883 foreach ($v as $k1 => $v1)
884 $ar[$k1] = $v1[$ks[
$i]];
886 $arRequest[
$k][] =
$ar;
896 if (
count($arWorkflowParameters) > 0)
898 $arErrorsTmp =
array();
901 foreach ($arWorkflowParameters as $parameterKey => $arParameter)
904 $ar[$parameterKey] = $arRequest[
$key] ??
null;
907 $arWorkflowParametersValues = CBPWorkflowTemplateLoader::CheckWorkflowParameters(
908 $arWorkflowParameters,
915 return $arWorkflowParametersValues;
933 if (!isset($arWorkflowParameters) || !is_array($arWorkflowParameters))
934 $arWorkflowParameters =
array();
937 $formName =
"start_workflow_form1";
939 if ($documentType ==
null)
943 $documentType =
$arResult[
"DOCUMENT_TYPE"];
946 $arParametersValues =
array();
947 $keys = array_keys($arWorkflowParameters);
948 foreach ($keys as
$key)
953 $arParametersValues[
$key] = $v;
957 $keys1 = array_keys($v);
958 foreach ($keys1 as $key1)
959 $arParametersValues[
$key][$key1] = $v[$key1];
963 $runtime = CBPRuntime::GetRuntime();
964 $runtime->StartRuntime();
965 $documentService = $runtime->GetService(
"DocumentService");
967 foreach ($arWorkflowParameters as $parameterKey => $arParameter)
969 $parameterKeyExt =
"bizproc".$templateId.
"_".$parameterKey;
971 <td
align=
"right" width=
"40%" valign=
"top" class=
"field-name"><?= $arParameter[
"Required"] ?
"<span class=\"required\">*</span> " :
""?><?=
htmlspecialcharsbx($arParameter[
"Name"]) ?>:<?
if ($arParameter[
"Description"] <>
'') echo
"<br /><small>".htmlspecialcharsbx($arParameter[
"Description"]).
"</small><br />";?></td>
972 <td
width=
"60%" valign=
"top"><?
973 echo $documentService->GetFieldInputControl(
976 [
'Form' => $formName,
'Field' => $parameterKeyExt],
977 $arParametersValues[$parameterKey] ??
null,
987 $GLOBALS[
"BP_AddShowParameterInit_".$module.
"_".
$entity.
"_".$document_type] = 1;
988 CUtil::InitJSCore(
array(
"window",
"ajax"));
990 $dts = \CBPDocument::signDocumentType([$module,
$entity, $document_type]);
992<script src=
"/bitrix/js/bizproc/bizproc.js"></script>
994 function BPAShowSelector(
id, type, mode, arCurValues)
996 <?
if(
$type==
"only_users"):?>
997 var def_mode =
"only_users";
1004 var module =
'<?=CUtil::JSEscape($module)?>';
1005 var entity =
'<?=CUtil::JSEscape($entity)?>';
1006 var documentType =
'<?=CUtil::JSEscape($document_type)?>';
1007 var documentId =
'<?=CUtil::JSEscape($document_id)?>';
1009 var loadAccessLib = (typeof BX.Access ===
'undefined');
1011 var contentUrl =
'/bitrix/tools/bizproc/compatible_selector.php?mode=public&bxpublic=Y&lang=<?=LANGUAGE_ID?>'
1012 +
'&dts=<?=CUtil::JSEscape($dts)?>'
1013 +(loadAccessLib?
'&load_access_lib=Y':
'');
1015 if (mode ==
"only_users")
1017 BX.WindowManager.setStartZIndex(1150);
1019 'content_url': contentUrl,
1021 'document_type': documentType,
1022 'document_id': documentId,
1026 'sessid':
'<?= bitrix_sessid() ?>'
1034 if (typeof arWorkflowConstants ===
'undefined')
1035 arWorkflowConstants = {};
1037 var workflowTemplateNameCur = workflowTemplateName;
1038 var workflowTemplateDescriptionCur = workflowTemplateDescription;
1039 var workflowTemplateAutostartCur = workflowTemplateAutostart;
1040 var arWorkflowParametersCur = arWorkflowParameters;
1041 var arWorkflowVariablesCur = arWorkflowVariables;
1042 var arWorkflowConstantsCur = arWorkflowConstants;
1043 var arWorkflowTemplateCur = Array(rootActivity.Serialize());
1047 if (arCurValues[
'workflowTemplateName'])
1048 workflowTemplateNameCur = arCurValues[
'workflowTemplateName'];
1049 if (arCurValues[
'workflowTemplateDescription'])
1050 workflowTemplateDescriptionCur = arCurValues[
'workflowTemplateDescription'];
1051 if (arCurValues[
'workflowTemplateAutostart'])
1052 workflowTemplateAutostartCur = arCurValues[
'workflowTemplateAutostart'];
1053 if (arCurValues[
'arWorkflowParameters'])
1054 arWorkflowParametersCur = arCurValues[
'arWorkflowParameters'];
1055 if (arCurValues[
'arWorkflowVariables'])
1056 arWorkflowVariablesCur = arCurValues[
'arWorkflowVariables'];
1057 if (arCurValues[
'arWorkflowConstants'])
1058 arWorkflowConstantsCur = arCurValues[
'arWorkflowConstants'];
1059 if (arCurValues[
'arWorkflowTemplate'])
1060 arWorkflowTemplateCur = arCurValues[
'arWorkflowTemplate'];
1064 'document_type': documentType,
1065 'document_id': documentId,
1068 'selectorMode': mode,
1069 'workflowTemplateName': workflowTemplateNameCur,
1070 'workflowTemplateDescription': workflowTemplateDescriptionCur,
1071 'workflowTemplateAutostart': workflowTemplateAutostartCur,
1072 'sessid':
'<?= bitrix_sessid() ?>'
1075 JSToPHPHidd(p, arWorkflowParametersCur,
'arWorkflowParameters');
1076 JSToPHPHidd(p, arWorkflowVariablesCur,
'arWorkflowVariables');
1077 JSToPHPHidd(p, arWorkflowConstantsCur,
'arWorkflowConstants');
1078 JSToPHPHidd(p, arWorkflowTemplateCur,
'arWorkflowTemplate');
1081 'content_url': contentUrl,
1097 $defaultRows =
$type ==
"user" ? 3 : 1;
1102 $s =
'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td valign="top">';
1103 $s .=
'<textarea onkeydown="i' .
'f(event.keyCode==45)BPAShowSelector(\''.Cutil::JSEscape(
htmlspecialcharsbx($id)).
'\', \
''.Cutil::JSEscape(
$type).
'\');
" ';
1104 $s .= 'rows="'.$rows.'" ';
1105 $s .= 'cols="'.$cols.'" ';
1106 $s .= 'name="'.htmlspecialcharsbx($name).'" ';
1107 $s .= 'id="'.htmlspecialcharsbx($id).'" ';
1108 $s .= 'style="width: 100%
"';
1109 $s .= '>'.htmlspecialcharsbx($values).'</textarea>';
1110 $s .= '</td><td valign="top" style="padding-
left:4px
" width="30
">';
1111 $s .= CBPHelper::renderControlSelectorButton($id, $type, array('title' => GetMessage("BIZPROC_AS_SEL_FIELD_BUTTON
").' (Insert)'));
1112 $s .= '</td></tr></table>';
1114 elseif($type == "bool")
1116 $s = '<table cellpadding="0
" cellspacing="0
" border="0
" width="100%
"><tr><td valign="top" width="30
">';
1117 $s .= '<select name="'.htmlspecialcharsbx($name).'"><option value=""></option><option value="Y
"'.($values=='Y'?' selected':'').'>'.GetMessage('MAIN_YES').'</option><option value="N
"'.($values=='N'?' selected':'').'>'.GetMessage('MAIN_NO').'</option>';
1118 $s .= '</td><td style="padding-
left:4px
"><textarea ';
1119 $s .= 'rows="'.$rows.'" ';
1120 $s .= 'cols="'.$cols.'" ';
1121 $s .= 'name="'.htmlspecialcharsbx($name).'_X
" ';
1122 $s .= 'id="'.htmlspecialcharsbx($id).'" ';
1123 $s .= 'style="width: 100%
"';
1124 $s .= '>'.($values=="Y
" || $values=="N
"?"":htmlspecialcharsbx($values));
1125 $s .= '</textarea></td>';
1126 $s .= '<td valign="top" style="padding-
left:4px
" width="30
">';
1127 $s .= CBPHelper::renderControlSelectorButton($id, $type);
1128 $s .= '</td></tr></table>';
1130 elseif ($type == 'datetime')
1132 $s = '<table cellpadding="0
" cellspacing="0
" border="0
" width="100%
"><tr><td valign="top"><textarea ';
1133 $s .= 'rows="'.$rows.'" ';
1134 $s .= 'cols="'.$cols.'" ';
1135 $s .= 'name="'.htmlspecialcharsbx($name).'" ';
1136 $s .= 'id="'.htmlspecialcharsbx($id).'" ';
1137 $s .= 'style="width: 100%
"';
1138 $s .= '>'.htmlspecialcharsbx($values);
1139 $s .= '</textarea></td><td valign="top" style="padding-
left:4px
" width="20
">'.CAdminCalendar::Calendar(htmlspecialcharsbx($name), "", "", true).'</td>';
1140 $s .= '<td valign="top" style="padding-
left:4px
" width="30
">';
1141 $s .= CBPHelper::renderControlSelectorButton($id, $type);
1142 $s .= '</td></tr></table>';
1146 $s = '<table cellpadding="0
" cellspacing="0
" border="0
" width="100%
"><tr><td valign="top"><textarea ';
1147 $s .= 'rows="'.$rows.'" ';
1148 $s .= 'cols="'.$cols.'" ';
1149 if (!empty($arParams['maxlength']))
1151 $s .= 'maxlength="'.intval($arParams['maxlength
']).'" ';
1153 $s .= 'name="'.htmlspecialcharsbx($name).'" ';
1154 $s .= 'id="'.htmlspecialcharsbx($id).'" ';
1155 $s .= 'style="width: 100%
"';
1156 $s .= '>'.htmlspecialcharsbx($values);
1157 $s .= '</textarea></td>';
1158 $s .= '<td valign="top" style="padding-
left:4px
" width="30
">';
1159 $s .= CBPHelper::renderControlSelectorButton($id, $type);
1160 $s .= '</td></tr></table>';
1166 public static function _ReplaceTaskURL($str, $documentType)
1168 $chttp = new CHTTP();
1169 $baseHref = $chttp->URN2URI('');
1172 Array('#HTTP_HOST#', '#TASK_URL#', '#BASE_HREF#'),
1173 Array($_SERVER['HTTP_HOST'], ($documentType[0]=="iblock
"?"/bitrix/admin/bizproc_task.php?workflow_id={=
Workflow:
id}
":"/company/personal/bizproc/{=
Workflow:
id}/
"), $baseHref),
1178 public static function addDefaultWorkflowTemplates($documentType, $additionalModuleId = null)
1180 if (!empty($additionalModuleId))
1182 $additionalModuleId = preg_replace("/[^a-z0-9_.]/i
", "", $additionalModuleId);
1183 $arModule = array($additionalModuleId, $documentType[0], 'bizproc');
1187 $arModule = array($documentType[0], 'bizproc');
1191 foreach ($arModule as $sModule)
1193 if (file_exists($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates'))
1195 if($handle = opendir($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates'))
1198 while(false !== ($file = readdir($handle)))
1200 if(!is_file($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates/'.$file))
1203 include($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates/'.$file);
1204 if(is_array($arFields))
1207 * If DOCUMENT_TYPE not defined, use current documentType
1208 * Overwise check if DOCUMENT_TYPE equals to current documentType
1210 if (!array_key_exists("DOCUMENT_TYPE
", $arFields))
1211 $arFields["DOCUMENT_TYPE
"] = $documentType;
1212 elseif($arFields["DOCUMENT_TYPE
"] != $documentType)
1215 $arFields["SYSTEM_CODE
"] = $file;
1216 if(is_object($GLOBALS['USER']))
1217 $arFields["USER_ID
"] = $GLOBALS['USER']->GetID();
1218 $arFields["MODIFIER_USER
"] = new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser);
1221 CBPWorkflowTemplateLoader::Add($arFields);
1223 catch (Exception $e)
1257 public static function getWorkflowTemplatesForDocumentType($documentType, $showSystemTemplates = true)
1261 "DOCUMENT_TYPE
" => $documentType,
1263 '<AUTO_EXECUTE' => CBPDocumentEventType::Automation
1266 if (!$showSystemTemplates)
1268 $filter['IS_SYSTEM'] = 'N';
1271 $dbWorkflowTemplate = CBPWorkflowTemplateLoader::GetList(
1272 ['SORT'=>'ASC','NAME'=>'ASC'],
1276 array("ID
", "NAME
", "DESCRIPTION
", "MODIFIED
", "USER_ID
", "AUTO_EXECUTE
", "USER_NAME
", "USER_LAST_NAME
", "USER_LOGIN
", "USER_SECOND_NAME
", 'PARAMETERS')
1278 while ($arWorkflowTemplate = $dbWorkflowTemplate->GetNext())
1280 $arWorkflowTemplate["USER
"] = "(
".$arWorkflowTemplate["USER_LOGIN
"].")
".(($arWorkflowTemplate["USER_NAME
"] <> '' || $arWorkflowTemplate["USER_LAST_NAME
"] <> '') ? " " : "").CUser::FormatName(COption::GetOptionString("bizproc
", "name_template
", CSite::GetNameFormat(false), SITE_ID), array("NAME
" => $arWorkflowTemplate["USER_NAME
"], "LAST_NAME
" => $arWorkflowTemplate["USER_LAST_NAME
"], "SECOND_NAME
" => $arWorkflowTemplate["USER_SECOND_NAME
"]), false, false);
1282 $arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] = "";
1284 if ($arWorkflowTemplate["AUTO_EXECUTE
"] == CBPDocumentEventType::None)
1285 $arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] .= GetMessage("BPCGDOC_AUTO_EXECUTE_NONE
");
1287 if (($arWorkflowTemplate["AUTO_EXECUTE
"] & CBPDocumentEventType::Create) != 0)
1289 if ($arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] <> '')
1290 $arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] .= ",
";
1291 $arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] .= GetMessage("BPCGDOC_AUTO_EXECUTE_CREATE
");
1294 if (($arWorkflowTemplate["AUTO_EXECUTE
"] & CBPDocumentEventType::Edit) != 0)
1296 if ($arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] <> '')
1297 $arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] .= ",
";
1298 $arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] .= GetMessage("BPCGDOC_AUTO_EXECUTE_EDIT
");
1301 if (($arWorkflowTemplate["AUTO_EXECUTE
"] & CBPDocumentEventType::Delete) != 0)
1303 if ($arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] <> '')
1304 $arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] .= ",
";
1305 $arWorkflowTemplate["AUTO_EXECUTE_TEXT
"] .= GetMessage("BPCGDOC_AUTO_EXECUTE_DELETE
");
1308 $arWorkflowTemplate['HAS_PARAMETERS'] = count($arWorkflowTemplate['PARAMETERS']) > 0;
1310 $arResult[] = $arWorkflowTemplate;
1316 public static function getNumberOfWorkflowTemplatesForDocumentType($documentType)
1318 $n = CBPWorkflowTemplateLoader::GetList(
1320 array("DOCUMENT_TYPE
" => $documentType, "ACTIVE
"=>"Y
"),
1333 public static function deleteWorkflowTemplate($id, $documentType, &$arErrors)
1335 $arErrors = array();
1337 $dbTemplates = CBPWorkflowTemplateLoader::GetList(
1339 array("ID
" => $id, "DOCUMENT_TYPE
" => $documentType),
1344 $arTemplate = $dbTemplates->Fetch();
1347 $arErrors[] = array(
1349 "message
" => str_replace("#ID#
", $id, GetMessage("BPCGDOC_INVALID_WF_ID_MSGVER_1
")),
1357 CBPWorkflowTemplateLoader::Delete($id);
1359 catch (Exception $e)
1361 $arErrors[] = array(
1362 "code
" => $e->getCode(),
1363 "message
" => $e->getMessage(),
1364 "file
" => $e->getFile()." [
".$e->getLine()."]
"
1377 public static function updateWorkflowTemplate($id, $documentType, $arFields, &$arErrors)
1379 $arErrors = array();
1381 $dbTemplates = CBPWorkflowTemplateLoader::GetList(
1383 array("ID
" => $id, "DOCUMENT_TYPE
" => $documentType),
1388 $arTemplate = $dbTemplates->Fetch();
1391 $arErrors[] = array(
1393 "message
" => str_replace("#ID#
", $id, GetMessage("BPCGDOC_INVALID_WF_ID_MSGVER_1
")),
1401 CBPWorkflowTemplateLoader::Update($id, $arFields);
1403 catch (Exception $e)
1405 $arErrors[] = array(
1406 "code
" => $e->getCode(),
1407 "message
" => $e->getMessage(),
1408 "file
" => $e->getFile()." [
".$e->getLine()."]
"
1422 public static function canUserOperateDocument($operation, $userId, $parameterDocumentId, $arParameters = array())
1424 [$moduleId, $entity, $documentId] = CBPHelper::ParseDocumentId($parameterDocumentId);
1426 if ($moduleId <> '')
1427 CModule::IncludeModule($moduleId);
1429 if (class_exists($entity))
1430 return call_user_func_array(array($entity, "CanUserOperateDocument
"), array($operation, $userId, $documentId, $arParameters));
1444 public static function canUserOperateDocumentType($operation, $userId, $parameterDocumentType, $arParameters = array())
1446 [$moduleId, $entity, $documentType] = CBPHelper::ParseDocumentId($parameterDocumentType);
1448 if ($moduleId <> '')
1449 CModule::IncludeModule($moduleId);
1451 if (class_exists($entity))
1452 return call_user_func_array(array($entity, "CanUserOperateDocumentType
"), array($operation, $userId, $documentType, $arParameters));
1463 public static function getDocumentAdminPage($parameterDocumentId)
1465 [$moduleId, $entity, $documentId] = CBPHelper::ParseDocumentId($parameterDocumentId);
1467 if ($moduleId <> '')
1468 CModule::IncludeModule($moduleId);
1470 if (class_exists($entity))
1471 return call_user_func_array(array($entity, "GetDocumentAdminPage
"), array($documentId));
1481 public static function getDocumentName($parameterDocumentId)
1483 [$moduleId, $entity, $documentId] = CBPHelper::ParseDocumentId($parameterDocumentId);
1485 if ($moduleId <> '')
1486 CModule::IncludeModule($moduleId);
1488 if (class_exists($entity) && method_exists($entity, 'getDocumentName'))
1489 return call_user_func_array(array($entity, "
getDocumentName"), array($documentId));
1510 public static function getUserTasksForWorkflow($userId, $workflowId)
1512 $userId = intval($userId);
1516 $workflowId = trim($workflowId);
1517 if ($workflowId == '')
1520 $arResult = array();
1522 $dbTask = CBPTaskService::GetList(
1524 array("WORKFLOW_ID
" => $workflowId, "USER_ID
" => $userId, 'STATUS' => CBPTaskStatus::Running),
1527 array("ID
", "WORKFLOW_ID
", "NAME
", "DESCRIPTION
")
1529 while ($arTask = $dbTask->GetNext())
1530 $arResult[] = $arTask;
1535 public static function prepareFileForHistory($documentId, $fileId, $historyIndex)
1537 return CBPHistoryService::PrepareFileForHistory($documentId, $fileId, $historyIndex);
1540 public static function isAdmin()
1542 global $APPLICATION;
1543 return ($APPLICATION->GetGroupRight("bizproc
") >= "W");
1546 public static function getDocumentFromHistory($historyId, &$arErrors)
1548 $arErrors = array();
1552 $historyId = intval($historyId);
1553 if ($historyId <= 0)
1554 throw new CBPArgumentNullException("historyId
");
1556 return CBPHistoryService::GetById($historyId);
1558 catch (Exception $e)
1560 $arErrors[] = array(
1561 "code
" => $e->getCode(),
1562 "message
" => $e->getMessage(),
1563 "file
" => $e->getFile()." [
".$e->getLine()."]
"
1569 public static function getAllowableUserGroups($parameterDocumentType)
1571 [$moduleId, $entity, $documentType] = CBPHelper::ParseDocumentId($parameterDocumentType);
1573 if ($moduleId <> '')
1574 CModule::IncludeModule($moduleId);
1576 if (class_exists($entity))
1578 $result = call_user_func_array(array($entity, "GetAllowableUserGroups
"), array($documentType));
1580 foreach ($result as $key => $value)
1581 $result1[mb_strtolower($key)] = $value;
1588 public static function onAfterTMDayStart($data)
1590 if (!CModule::IncludeModule("im
"))
1593 $userId = (int) $data['USER_ID'];
1595 $iterator = Bizproc\Workflow\Entity\WorkflowInstanceTable::getList(
1597 'select' => [new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(\'x\')')],
1599 '=STARTED_BY' => $userId,
1600 '<OWNED_UNTIL' => Main\Type\DateTime::createFromTimestamp(
1601 time() - Bizproc\Workflow\Entity\WorkflowInstanceTable::LOCKED_TIME_INTERVAL
1606 $row = $iterator->fetch();
1607 if (!empty($row['CNT']))
1609 $path = IsModuleInstalled('bitrix24') ? '/bizproc/bizproc/?type=is_locked'
1610 : Main\Config\Option::get("bizproc
", "locked_wi_path
", '/services/bp/instances.php?type=is_locked');
1613 'FROM_USER_ID' => 0,
1614 'TO_USER_ID' => $userId,
1615 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM,
1616 'NOTIFY_MODULE' => 'bizproc',
1617 'NOTIFY_EVENT' => 'wi_locked',
1618 'TITLE' => Main\Localization\Loc::getMessage('BPCGDOC_WI_LOCKED_NOTICE_TITLE_MSGVER_1'),
1619 'MESSAGE' => Main\Localization\Loc::getMessage(
1620 'BPCGDOC_WI_LOCKED_NOTICE_MESSAGE',
1621 ['#PATH#' => $path, '#CNT#' => $row['CNT']]
1633 public static function sendB24LimitsNotifyToAdmins()
1643 public static function getDocumentFieldsAliasesMap($fields)
1645 if (empty($fields) || !is_array($fields))
1651 foreach ($fields as $key => $property)
1653 if (isset($property['Alias']))
1655 $aliases[$property['Alias']] = $key;
1667 public static function isExpression($value)
1669 //go to internal alias
1670 return CBPActivity::isExpression($value);
1673 public static function parseExpression($expression)
1676 if (is_string($expression) && preg_match(CBPActivity::ValuePattern, $expression, $matches))
1679 'object' => $matches['object'],
1680 'field' => $matches['field'],
1681 'modifiers' => array()
1683 if (!empty($matches['mod1']))
1684 $result['modifiers'][] = $matches['mod1'];
1685 if (!empty($matches['mod2']))
1686 $result['modifiers'][] = $matches['mod2'];
1693 public static function signParameters(array $parameters)
1695 return self::signArray($parameters, 'bizproc_wf_params');
1702 public static function unSignParameters($unsignedData)
1704 return self::unSignArray($unsignedData, 'bizproc_wf_params');
1707 public static function signDocumentType(array $documentType)
1709 return self::signArray($documentType, 'bizproc_document_type');
1716 public static function unSignDocumentType($unsignedData): ?array
1718 $dt = self::unSignArray($unsignedData, 'bizproc_document_type');
1722 private static function signArray(array $source, $salt)
1724 $signer = new Main\Security\Sign\Signer;
1725 $jsonData = Main\Web\Json::encode($source);
1727 return $signer->sign($jsonData, $salt);
1730 private static function unSignArray(string $unsignedSource, $salt)
1732 $signer = new Main\Security\Sign\Signer;
1736 $unsigned = $signer->unsign($unsignedSource, $salt);
1737 $result = Main\Web\Json::decode($unsigned);
1739 catch (\Exception $e)
1747 public static function getTemplatesForStart($userId, $documentType, $documentId = null, array $parameters = array())
1749 if (!isset($parameters['UserGroups']))
1751 $currentUser = \Bitrix\Main\Engine\CurrentUser::get();
1752 $currentUserId = $currentUser->getId();
1754 $parameters['UserGroups'] = (
1755 $currentUserId !== null && ((int)$currentUserId === (int)$userId)
1756 ? $currentUser->getUserGroups()
1757 : CUser::GetUserGroup($userId)
1760 if (!isset($parameters['DocumentStates']))
1762 $parameters['DocumentStates'] = static::GetDocumentStates($documentType, $documentId);
1764 $op = CBPCanUserOperateOperation::StartWorkflow;
1766 $templates = array();
1767 $dbWorkflowTemplate = CBPWorkflowTemplateLoader::GetList(
1768 array('SORT' => 'ASC', 'NAME' => 'ASC'),
1770 "DOCUMENT_TYPE
" => $documentType,
1773 '<AUTO_EXECUTE' => CBPDocumentEventType::Automation
1777 array("ID
", "NAME
", "DESCRIPTION
", "PARAMETERS
")
1779 while ($arWorkflowTemplate = $dbWorkflowTemplate->fetch())
1781 $parameters['WorkflowTemplateId'] = $arWorkflowTemplate['ID'];
1784 if (!CBPDocument::CanUserOperateDocument($op, $userId, $documentId, $parameters))
1789 elseif (!CBPDocument::CanUserOperateDocumentType($op, $userId, $documentType, $parameters))
1794 $templates[] = array(
1795 'id' => $arWorkflowTemplate['ID'],
1796 'name' => $arWorkflowTemplate['NAME'],
1797 'description' => $arWorkflowTemplate['DESCRIPTION'],
1798 'hasParameters' => count($arWorkflowTemplate['PARAMETERS']) > 0,
1799 'isConstantsTuned' => CBPWorkflowTemplateLoader::isConstantsTuned($arWorkflowTemplate["ID
"])
1806 public static function getUserGroups(array $parameterDocumentType, array $parameterDocumentId, int $userId)
1808 [$moduleId, $entity, $documentType] = CBPHelper::ParseDocumentId($parameterDocumentType);
1812 \Bitrix\Main\Loader::includeModule($moduleId);
1815 if (class_exists($entity) && method_exists($entity, 'GetUserGroups'))
1817 return call_user_func([$entity, 'GetUserGroups'], $parameterDocumentType, $parameterDocumentId, $userId);
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getActiveSession()
static deleteByWorkflowId(string $workflowId)
static getTask(string $associatedActivity, array $task, int $userId)
static getIdsByDocument(array $documentId)
static mergeByDocument($paramFirstDocumentId, $paramSecondDocumentId)
static migrateDocumentType($paramOldType, $paramNewType, $workflowTemplateIds)
static maskAsZombie(array $documentId)
static onDocumentDelete(array $docId)
static mergeDocuments($firstDocumentId, $secondDocumentId)
static addShowParameterInit($module, $type, $document_type, $entity="", $document_id='')
static getAllowableOperations($userId, $arGroups, $arStates, $appendExtendedGroups=false)
const PARAM_DOCUMENT_EVENT_TYPE
static onDocumentDelete($documentId, &$errors)
const PARAM_DOCUMENT_TYPE
static terminateWorkflow($workflowId, $documentId, &$arErrors, $stateTitle='')
static canOperate($operation, $userId, $arGroups, $arStates)
static getTaskControls($arTask, $userId=0)
static getDocumentState($documentId, $workflowId)
static setTasksUserStatus($userId, $status, $ids=array(), &$errors=array())
const PARAM_PRE_GENERATED_WORKFLOW_ID
static getDocumentStates($documentType, $documentId=null)
static startWorkflowParametersValidate($templateId, $arWorkflowParameters, $documentType, &$arErrors)
static getAllowableEvents($userId, $arGroups, $arState, $appendExtendedGroups=false)
const PARAM_USED_DOCUMENT_FIELDS
const PARAM_USE_FORCED_TRACKING
static showTaskForm($arTask, $userId, $userName="", $arRequest=null)
static startDebugWorkflow($workflowTemplateId, $documentId, $parameters, &$errors)
static autoStartWorkflows($documentType, $autoExecute, $documentId, $arParameters, &$arErrors)
static getDocumentName($parameterDocumentId)
static killWorkflow($workflowId, $terminate=true, $documentId=null)
const PARAM_MODIFIED_DOCUMENT_FIELDS
static addDocumentToHistory($parameterDocumentId, $name, $userId)
static sendExternalEvent($workflowId, $workflowEvent, $arParameters, &$arErrors)
static startWorkflowParametersShow($templateId, $arWorkflowParameters, $formName, $bVarsFromForm, $documentType=null)
static migrateDocumentType($oldType, $newType)
static startWorkflow($workflowTemplateId, $documentId, $parameters, &$errors, $parentWorkflow=null)
static showParameterField($type, $name, $values, $arParams=Array())
static getActiveStates(array $documentId, $limit=0)
static postTaskForm($arTask, $userId, $arRequest, &$arErrors, $userName="")
const PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT
static generateWorkflowId()
static GetList($arOrder=array("ID"=> "DESC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
static delegateTask($taskId, $fromUserId, $toUserId)
static getOriginalTaskUserId($taskId, $realUserId)
static IncludeModule($module_name)
bx popup label bx width30 PAGE_NEW_MENU_NAME text width
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
bx_acc_lim_group_list limitGroupList[] multiple<?=$group[ 'ID']?> ID selected margin top
hidden mSiteList<?=htmlspecialcharsbx(serialize( $siteList))?><?=htmlspecialcharsbx( $siteList[ $j]["ID"])?> _Propery<? if(((COption::GetOptionString( $module_id, "different_set", "N")=="Y") &&( $j !=0))||(COption::GetOptionString( $module_id, "different_set", "N")=="N")) echo "display: none;"?> top adm detail content cell l top adm detail content cell r heading center center ID left
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
GetMessage($name, $aReplace=null)
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"