Пример #1
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $documentService = $runtime->GetService("DocumentService");
     $arFieldTypes = $documentService->GetDocumentFieldTypes($documentType);
     $arProperties = array("VariableValue" => array());
     if (!is_array($arWorkflowVariables)) {
         $arWorkflowVariables = array();
     }
     if (count($arWorkflowVariables) <= 0) {
         $arErrors[] = array("code" => "EmptyVariables", "parameter" => "", "message" => GetMessage("BPSVA_EMPTY_VARS"));
         return false;
     }
     $l = strlen("variable_field_");
     foreach ($arCurrentValues as $key => $varCode) {
         if (substr($key, 0, $l) === "variable_field_") {
             $ind = substr($key, $l);
             if ($ind . "!" === intval($ind) . "!") {
                 if (array_key_exists($varCode, $arWorkflowVariables)) {
                     $arProperties["VariableValue"][$varCode] = $documentService->GetFieldInputValue($documentType, $arWorkflowVariables[$varCode], $varCode, $arCurrentValues, $arErrors);
                 }
             }
         }
     }
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #2
0
 public function SetState($workflowId, $arState, $arStatePermissions = array())
 {
     global $DB;
     $workflowId = trim($workflowId);
     if (strlen($workflowId) <= 0) {
         throw new Exception("workflowId");
     }
     $state = trim($arState["STATE"]);
     $stateTitle = trim($arState["TITLE"]);
     $stateParameters = "";
     if (count($arState["PARAMETERS"]) > 0) {
         $stateParameters = serialize($arState["PARAMETERS"]);
     }
     $DB->Query("UPDATE b_bp_workflow_state SET " . "\tSTATE = " . (strlen($state) > 0 ? "'" . $DB->ForSql($state) . "'" : "NULL") . ", " . "\tSTATE_TITLE = " . (strlen($stateTitle) > 0 ? "'" . $DB->ForSql($stateTitle) . "'" : "NULL") . ", " . "\tSTATE_PARAMETERS = " . (strlen($stateParameters) > 0 ? "'" . $DB->ForSql($stateParameters) . "'" : "NULL") . ", " . "\tMODIFIED = " . $DB->CurrentTimeFunction() . " " . "WHERE ID = '" . $DB->ForSql($workflowId) . "' ");
     if ($arStatePermissions !== false) {
         $DB->Query("DELETE FROM b_bp_workflow_permissions " . "WHERE WORKFLOW_ID = '" . $DB->ForSql($workflowId) . "' ");
         foreach ($arStatePermissions as $permission => $arObjects) {
             foreach ($arObjects as $object) {
                 $DB->Query("INSERT INTO b_bp_workflow_permissions (WORKFLOW_ID, OBJECT_ID, PERMISSION) " . "VALUES ('" . $DB->ForSql($workflowId) . "', '" . $DB->ForSql($object) . "', '" . $DB->ForSql($permission) . "')");
             }
         }
         $arState = self::GetWorkflowState($workflowId);
         $runtime = $this->runtime;
         if (!isset($runtime) || !is_object($runtime)) {
             $runtime = CBPRuntime::GetRuntime();
         }
         $documentService = $runtime->GetService("DocumentService");
         $documentService->SetPermissions($arState["DOCUMENT_ID"], $workflowId, $arStatePermissions, true);
     }
 }
Пример #3
0
 public static function GetPropertiesDialog($documentType, $activityName, $arWorkflowTemplate, $arWorkflowParameters, $arWorkflowVariables, $arCurrentValues = null, $formName = "")
 {
     $runtime = CBPRuntime::GetRuntime();
     $arMap = array("GroupName" => "group_name", "OwnerId" => "owner_id", "Users" => 'users');
     if (!is_array($arCurrentValues)) {
         $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
         if (is_array($arCurrentActivity["Properties"])) {
             foreach ($arMap as $k => $v) {
                 if (array_key_exists($k, $arCurrentActivity["Properties"])) {
                     if ($k == "OwnerId" || $k == "Users") {
                         $arCurrentValues[$arMap[$k]] = CBPHelper::UsersArrayToString($arCurrentActivity["Properties"][$k], $arWorkflowTemplate, $documentType);
                     } else {
                         $arCurrentValues[$arMap[$k]] = $arCurrentActivity["Properties"][$k];
                     }
                 } else {
                     $arCurrentValues[$arMap[$k]] = "";
                 }
             }
         } else {
             foreach ($arMap as $k => $v) {
                 $arCurrentValues[$arMap[$k]] = "";
             }
         }
     }
     return $runtime->ExecuteResourceFile(__FILE__, "properties_dialog.php", array("arCurrentValues" => $arCurrentValues, "formName" => $formName));
 }
Пример #4
0
 public function executeComponent()
 {
     $id = $this->getWorkflowId();
     $this->arResult = array('NeedAuth' => $this->isAuthorizationNeeded() ? 'Y' : 'N', 'FatalErrorMessage' => '', 'ErrorMessage' => '');
     if ($id) {
         $workflowState = \CBPStateService::getWorkflowState($id);
         if (!$workflowState) {
             $this->arResult['FatalErrorMessage'] = Loc::getMessage('BPWFI_WORKFLOW_NOT_FOUND');
         } else {
             $this->arResult['WorkflowState'] = $workflowState;
             $this->arResult['WorkflowTrack'] = \CBPTrackingService::DumpWorkflow($id);
             if ($workflowState['STARTED_BY'] && ($photo = $this->getStartedByPhoto($workflowState['STARTED_BY']))) {
                 $this->arResult['startedByPhotoSrc'] = $photo['src'];
             }
             $runtime = CBPRuntime::GetRuntime();
             $runtime->StartRuntime();
             /**
              * @var CBPDocumentService $documentService
              */
             $documentService = $runtime->GetService('DocumentService');
             try {
                 $this->arResult['DOCUMENT_NAME'] = $documentService->getDocumentName($workflowState['DOCUMENT_ID']);
                 $this->arResult['DOCUMENT_ICON'] = $documentService->getDocumentIcon($workflowState['DOCUMENT_ID']);
             } catch (Main\ArgumentException $e) {
                 $this->arResult['FatalErrorMessage'] = $e->getMessage();
             }
         }
     }
     $this->includeComponentTemplate();
     if ($this->arParams['SET_TITLE']) {
         $this->setPageTitle(Loc::getMessage('BPWFI_PAGE_TITLE'));
     }
 }
 public static function CallStaticMethod($code, $method, $arParameters = array())
 {
     $runtime = CBPRuntime::GetRuntime();
     $runtime->IncludeActivityFile($code);
     $code = preg_replace("[^a-zA-Z0-9]", "", $code);
     $classname = 'CBP' . $code;
     return call_user_func_array(array($classname, $method), $arParameters);
 }
Пример #6
0
 public static function GetPropertiesDialog($documentType, $arWorkflowTemplate, $arWorkflowParameters, $arWorkflowVariables, $defaultValue, $arCurrentValues = null)
 {
     $runtime = CBPRuntime::GetRuntime();
     if (!is_array($arCurrentValues)) {
         $arCurrentValues = array("php_code_condition" => $defaultValue == null ? "" : $defaultValue);
     }
     return $runtime->ExecuteResourceFile(__FILE__, "properties_dialog.php", array("arCurrentValues" => $arCurrentValues));
 }
Пример #7
0
 private static function GetHistoryService()
 {
     if (self::$historyService == null && CModule::IncludeModule('bizproc')) {
         $runtime = CBPRuntime::GetRuntime();
         $runtime->StartRuntime();
         self::$historyService = $runtime->GetService("HistoryService");
     }
     return self::$historyService;
 }
Пример #8
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arProperties = array();
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #9
0
 public static function CallStaticMethod($code, $method, $arParameters = array())
 {
     $runtime = CBPRuntime::GetRuntime();
     $runtime->IncludeActivityFile($code);
     if (preg_match("#[^a-zA-Z0-9_]#", $code)) {
         throw new Exception("Activity '" . $code . "' is not valid");
     }
     $classname = 'CBP' . $code;
     return call_user_func_array(array($classname, $method), $arParameters);
 }
Пример #10
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arProperties = array("ExecuteCode" => $arCurrentValues["execute_code"]);
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #11
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $state = strlen($arCurrentValues["target_state_name_1"]) > 0 ? $arCurrentValues["target_state_name_1"] : $arCurrentValues["target_state_name"];
     $cancelCurrentState = isset($arCurrentValues['cancel_current_state']) && $arCurrentValues['cancel_current_state'] == 'Y' ? 'Y' : 'N';
     $arProperties = array('TargetStateName' => $state, 'CancelCurrentState' => $cancelCurrentState);
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #12
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arMap = array("sh_name" => "Name", "sh_user_id" => "UserId");
     $arProperties = array();
     foreach ($arMap as $key => $value) {
         $arProperties[$value] = $arCurrentValues[$key];
     }
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #13
0
 function UpdateHistory($ID, $IBLOCK_ID, $modifyComment = false)
 {
     global $USER;
     $rIBlock = CIBlock::getList(array(), array('ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'));
     $arIBlock = $rIBlock->GetNext();
     // add changes history
     if ($arIBlock['BIZPROC'] == 'Y' && CModule::IncludeModule('bizproc')) {
         $cRuntime = CBPRuntime::GetRuntime();
         $cRuntime->StartRuntime();
         $documentService = $cRuntime->GetService('DocumentService');
         $historyIndex = CBPHistoryService::Add(array('DOCUMENT_ID' => array('iblock', 'CWikiDocument', $ID), 'NAME' => 'New', 'DOCUMENT' => null, 'USER_ID' => $USER->GetID()));
         $arDocument = $documentService->GetDocumentForHistory(array('iblock', 'CWikiDocument', $ID), $historyIndex);
         $arDocument["MODIFY_COMMENT"] = $modifyComment ? $modifyComment : '';
         if (is_array($arDocument)) {
             CBPHistoryService::Update($historyIndex, array('NAME' => $arDocument['NAME'], 'DOCUMENT' => $arDocument));
         }
         return true;
     }
     return false;
 }
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arProperties = array("Permission" => array(), "Rewrite" => true);
     $documentService = $runtime->GetService("DocumentService");
     $arAllowableOperations = $documentService->GetAllowableOperations($documentType);
     foreach ($arAllowableOperations as $operationKey => $operationValue) {
         $arProperties["Permission"][$operationKey] = CBPHelper::UsersStringToArray($arCurrentValues["permission_" . $operationKey], $documentType, $arErrors);
         if (count($arErrors) > 0) {
             return false;
         }
     }
     $arProperties["Rewrite"] = $arCurrentValues["rewrite"] == "Y" ? "Y" : "N";
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #15
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arMap = array("message_user_from" => "MessageUserFrom", "message_user_to" => "MessageUserTo", "message_text" => "MessageText");
     $arProperties = array();
     foreach ($arMap as $key => $value) {
         if ($key == "message_user_from" || $key == "message_user_to") {
             continue;
         }
         $arProperties[$value] = $arCurrentValues[$key];
     }
     global $USER;
     if ($USER->IsAdmin() || CModule::IncludeModule("bitrix24") && CBitrix24::IsPortalAdmin($USER->GetID())) {
         $arProperties["MessageUserFrom"] = CBPHelper::UsersStringToArray($arCurrentValues["message_user_from"], $documentType, $arErrors);
         if (count($arErrors) > 0) {
             return false;
         }
     } else {
         $arProperties["MessageUserFrom"] = "user_" . $USER->GetID();
     }
     //global $USER;
     //if (!$USER->IsAdmin())
     //	$arProperties["MessageUserFrom"] = "user_".$USER->GetID();
     $arProperties["MessageUserTo"] = CBPHelper::UsersStringToArray($arCurrentValues["message_user_to"], $documentType, $arErrors);
     if (count($arErrors) > 0) {
         return false;
     }
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #16
0
 protected static function onTaskChange($taskId, $taskData, $status)
 {
     $workflowId = isset($taskData['WORKFLOW_ID']) ? $taskData['WORKFLOW_ID'] : null;
     if (!$workflowId) {
         $iterator = CBPTaskService::GetList(array('ID' => 'DESC'), array('ID' => $taskId), false, false, array('WORKFLOW_ID'));
         $row = $iterator->fetch();
         if (!$row) {
             return false;
         }
         $workflowId = $row['WORKFLOW_ID'];
         $taskData['WORKFLOW_ID'] = $workflowId;
     }
     //clean counters cache
     $users = array();
     if (!empty($taskData['USERS'])) {
         $users = $taskData['USERS'];
     }
     if (!empty($taskData['USERS_REMOVED'])) {
         $users = array_merge($users, $taskData['USERS_REMOVED']);
     }
     if (!empty($taskData['USERS_STATUSES'])) {
         $users = array_merge($users, array_keys($taskData['USERS_STATUSES']));
     }
     self::cleanCountersCache($users);
     //ping document
     $runtime = CBPRuntime::GetRuntime();
     $runtime->StartRuntime();
     $documentId = CBPStateService::GetStateDocumentId($workflowId);
     $documentService = $runtime->GetService('DocumentService');
     try {
         $documentService->onTaskChange($documentId, $taskId, $taskData, $status);
     } catch (Exception $e) {
     }
     return true;
 }
Пример #17
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arProperties = array();
     if (!isset($arCurrentValues["user_type"]) || !in_array($arCurrentValues["user_type"], array("boss", "random"))) {
         $arCurrentValues["user_type"] = "random";
     }
     $arProperties["UserType"] = $arCurrentValues["user_type"];
     if (!isset($arCurrentValues["max_level"]) || $arCurrentValues["max_level"] < 1 || $arCurrentValues["max_level"] > 10) {
         $arCurrentValues["max_level"] = 1;
     }
     $arProperties["MaxLevel"] = $arCurrentValues["max_level"];
     $arProperties["UserParameter"] = CBPHelper::UsersStringToArray($arCurrentValues["user_parameter"], $documentType, $arErrors);
     if (count($arErrors) > 0) {
         return false;
     }
     $arProperties["ReserveUserParameter"] = CBPHelper::UsersStringToArray($arCurrentValues["reserve_user_parameter"], $documentType, $arErrors);
     if (count($arErrors) > 0) {
         return false;
     }
     if (!isset($arCurrentValues["skip_absent"]) || !in_array($arCurrentValues["skip_absent"], array("Y", "N"))) {
         $arCurrentValues["skip_absent"] = "Y";
     }
     $arProperties["SkipAbsent"] = $arCurrentValues["skip_absent"];
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #18
0
 public static function CallStaticMethod($code, $method, $arParameters = array())
 {
     $runtime = CBPRuntime::GetRuntime();
     if (!$runtime->IncludeActivityFile($code)) {
         return array(array("code" => "ActivityNotFound", "parameter" => $code, "message" => GetMessage("BPGA_ACTIVITY_NOT_FOUND")));
     }
     if (preg_match("#[^a-zA-Z0-9_]#", $code)) {
         throw new Exception("Activity '" . $code . "' is not valid");
     }
     $classname = 'CBP' . $code;
     if (method_exists($classname, $method)) {
         return call_user_func_array(array($classname, $method), $arParameters);
     }
     return false;
 }
Пример #19
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arProperties = array("Fields" => array());
     $documentService = $runtime->GetService("DocumentService");
     $arDocumentFields = $documentService->GetDocumentFields($documentType);
     foreach ($arDocumentFields as $fieldKey => $fieldValue) {
         if (!$fieldValue["Editable"]) {
             continue;
         }
         $arFieldErrors = array();
         $r = $documentService->GetFieldInputValue($documentType, $fieldValue, $fieldKey, $arCurrentValues, $arFieldErrors);
         if (is_array($arFieldErrors) && !empty($arFieldErrors)) {
             $arErrors = array_merge($arErrors, $arFieldErrors);
         }
         if ($fieldValue["BaseType"] == "user") {
             if ($r === "author") {
                 //HACK: We can't resolve author for new document - setup target user as author.
                 $r = "{=Template:TargetUser}";
             } elseif (is_array($r)) {
                 $qty = count($r);
                 if ($qty == 0) {
                     $r = null;
                 } elseif ($qty == 1) {
                     $r = $r[0];
                 }
             }
         }
         if ($fieldValue["Required"] && $r == null) {
             $arErrors[] = array("code" => "emptyRequiredField", "message" => str_replace("#FIELD#", $fieldValue["Name"], GetMessage("BPCDA_FIELD_REQUIED")));
         }
         if ($r != null) {
             $arProperties["Fields"][$fieldKey] = $r;
         }
     }
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #20
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arProperties = array("FieldValue" => array());
     $documentService = $runtime->GetService("DocumentService");
     $arNewFieldsMap = array();
     if (array_key_exists("new_field_name", $arCurrentValues) && is_array($arCurrentValues["new_field_name"])) {
         $arNewFieldKeys = array_keys($arCurrentValues["new_field_name"]);
         foreach ($arNewFieldKeys as $k) {
             $code = trim($arCurrentValues["new_field_code"][$k]);
             //if (!array_key_exists($code, $arCurrentValues))
             //	continue;
             $arFieldsTmp = array("name" => $arCurrentValues["new_field_name"][$k], "code" => $code, "type" => $arCurrentValues["new_field_type"][$k], "multiple" => $arCurrentValues["new_field_mult"][$k], "required" => $arCurrentValues["new_field_req"][$k], "options" => $arCurrentValues["new_field_options"][$k]);
             $newCode = $documentService->AddDocumentField($documentType, $arFieldsTmp);
             $arNewFieldsMap[$newCode] = $code;
         }
     }
     $arDocumentFields = $documentService->GetDocumentFields($documentType);
     foreach ($arDocumentFields as $fieldKey => $fieldValue) {
         if (!$fieldValue["Editable"]) {
             continue;
         }
         $fieldKey1 = array_key_exists($fieldKey, $arNewFieldsMap) ? $arNewFieldsMap[$fieldKey] : $fieldKey;
         $arErrors = array();
         $r = $documentService->GetFieldInputValue($documentType, $fieldValue, $fieldKey1, $arCurrentValues, $arErrors);
         if (!is_null($r)) {
             $arProperties["FieldValue"][$fieldKey] = $r;
         }
     }
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #21
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arMap = array("review_users" => "Users", "approve_type" => "ApproveType", "review_overdue_date" => "OverdueDate", "review_name" => "Name", "review_description" => "Description", "review_parameters" => "Parameters", "status_message" => "StatusMessage", "set_status_message" => "SetStatusMessage", "task_button_message" => "TaskButtonMessage", "comment_label_message" => "CommentLabelMessage", "show_comment" => "ShowComment", "timeout_duration" => "TimeoutDuration", "timeout_duration_type" => "TimeoutDurationType", "access_control" => "AccessControl");
     $arProperties = array();
     foreach ($arMap as $key => $value) {
         if ($key == "review_users") {
             continue;
         }
         $arProperties[$value] = $arCurrentValues[$key];
     }
     $arProperties["Users"] = CBPHelper::UsersStringToArray($arCurrentValues["review_users"], $documentType, $arErrors);
     if (count($arErrors) > 0) {
         return false;
     }
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #22
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$workflowTemplate, &$workflowParameters, &$workflowVariables, $currentValues, &$errors)
 {
     $runtime = CBPRuntime::GetRuntime();
     $errors = array();
     $map = array('setstatusmessage' => 'SetStatusMessage', 'statusmessage' => 'StatusMessage', 'usesubscription' => 'UseSubscription', 'timeoutduration' => 'TimeoutDuration', 'timeoutdurationtype' => 'TimeoutDurationType');
     $properties = array();
     foreach ($map as $key => $value) {
         $properties[$value] = $currentValues[$key];
     }
     $activityData = self::getRestActivityData();
     $activityProperties = isset($activityData['PROPERTIES']) && is_array($activityData['PROPERTIES']) ? $activityData['PROPERTIES'] : array();
     /** @var CBPDocumentService $documentService */
     $documentService = $runtime->GetService('DocumentService');
     $activityDocumentType = is_array($activityData['DOCUMENT_TYPE']) ? $activityData['DOCUMENT_TYPE'] : $documentType;
     foreach ($activityProperties as $name => $property) {
         $requestName = strtolower($name);
         if (isset($properties[$requestName])) {
             continue;
         }
         $errors = array();
         $properties[$name] = $documentService->GetFieldInputValue($activityDocumentType, $property, $requestName, $currentValues, $errors);
         if (count($errors) > 0) {
             return false;
         }
     }
     if (static::checkAdminPermissions()) {
         $properties['AuthUserId'] = CBPHelper::usersStringToArray($currentValues['authuserid'], $documentType, $errors);
         if (count($errors) > 0) {
             return false;
         }
     } else {
         unset($properties['AuthUserId']);
     }
     if (!empty($activityData['USE_SUBSCRIPTION'])) {
         $properties['UseSubscription'] = $activityData['USE_SUBSCRIPTION'];
     }
     $errors = self::ValidateProperties($properties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($errors) > 0) {
         return false;
     }
     $currentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($workflowTemplate, $activityName);
     $currentActivity["Properties"] = $properties;
     return true;
 }
Пример #23
0
 /**
  * Static method transfer event to the specified workflow instance.
  * 
  * @param mixed $workflowId - ID of the workflow instance.
  * @param mixed $eventName - Event name.
  * @param mixed $arEventParameters - Event parameters.
  */
 public static function SendExternalEvent($workflowId, $eventName, $arEventParameters = array())
 {
     $runtime = CBPRuntime::GetRuntime();
     $workflow = $runtime->GetWorkflow($workflowId);
     if ($workflow) {
         $workflow->SendExternalEvent($eventName, $arEventParameters);
     }
 }
Пример #24
0
             LocalRedirect($backUrl);
         }
     }
 }
 require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
 $aMenu = array(array("TEXT" => GetMessage("BPAT_BACK"), "LINK" => $backUrl, "ICON" => "btn_list"));
 if ($showType == 'Form' && $allowAdminAccess) {
     $aMenu[] = array("TEXT" => GetMessage('BPAT_ACTION_DELEGATE'), 'ONCLICK' => 'bizprocShowDelegateDialog();');
 }
 $context = new CAdminContextMenu($aMenu);
 $context->Show();
 $APPLICATION->SetTitle(str_replace("#ID#", $taskId, GetMessage("BPAT_TITLE")));
 if (strlen($errorMessage) > 0) {
     CAdminMessage::ShowMessage($errorMessage);
 }
 $runtime = CBPRuntime::GetRuntime();
 $runtime->StartRuntime();
 $documentService = $runtime->GetService("DocumentService");
 if (empty($arTask["PARAMETERS"]["DOCUMENT_ID"])) {
     CAdminMessage::ShowMessage(GetMessage('BPAT_NO_STATE'));
     $showType = 'Success';
 } else {
     try {
         $documentType = $documentService->GetDocumentType($arTask["PARAMETERS"]["DOCUMENT_ID"]);
         if (!array_key_exists("BP_AddShowParameterInit_" . $documentType[0] . "_" . $documentType[1] . "_" . $documentType[2], $GLOBALS)) {
             $GLOBALS["BP_AddShowParameterInit_" . $documentType[0] . "_" . $documentType[1] . "_" . $documentType[2]] = 1;
             CBPDocument::AddShowParameterInit($documentType[0], "only_users", $documentType[2], $documentType[1]);
         }
     } catch (Exception $e) {
         CAdminMessage::ShowMessage(GetMessage('BPAT_NO_STATE'));
         $showType = 'Success';
Пример #25
0
 public static function ImportTemplate($id, $documentType, $autoExecute, $name, $description, $datum, $systemCode = null, $systemImport = false)
 {
     $id = intval($id);
     if ($id <= 0) {
         $id = 0;
     }
     $datumTmp = CheckSerializedData($datum) ? @unserialize($datum) : null;
     if (!is_array($datumTmp) || is_array($datumTmp) && !array_key_exists("TEMPLATE", $datumTmp)) {
         if (function_exists("gzcompress")) {
             $datumTmp = @gzuncompress($datum);
             $datumTmp = CheckSerializedData($datumTmp) ? @unserialize($datumTmp) : null;
         }
     }
     if (!is_array($datumTmp) || is_array($datumTmp) && !array_key_exists("TEMPLATE", $datumTmp)) {
         throw new Exception(GetMessage("BPCGWTL_WRONG_TEMPLATE"));
     }
     if (array_key_exists("VERSION", $datumTmp) && $datumTmp["VERSION"] == 2) {
         $datumTmp["TEMPLATE"] = self::ConvertArrayCharset($datumTmp["TEMPLATE"], BP_EI_DIRECTION_IMPORT);
         $datumTmp["PARAMETERS"] = self::ConvertArrayCharset($datumTmp["PARAMETERS"], BP_EI_DIRECTION_IMPORT);
         $datumTmp["VARIABLES"] = self::ConvertArrayCharset($datumTmp["VARIABLES"], BP_EI_DIRECTION_IMPORT);
         $datumTmp["CONSTANTS"] = isset($datumTmp["CONSTANTS"]) ? self::ConvertArrayCharset($datumTmp["CONSTANTS"], BP_EI_DIRECTION_IMPORT) : array();
         $datumTmp["DOCUMENT_FIELDS"] = self::ConvertArrayCharset($datumTmp["DOCUMENT_FIELDS"], BP_EI_DIRECTION_IMPORT);
     }
     if (!$systemImport) {
         if (!self::WalkThroughWorkflowTemplate($datumTmp["TEMPLATE"], array("CBPWorkflowTemplateLoader", "ImportTemplateChecker"), new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser))) {
             return false;
         }
     } elseif ($id > 0 && !empty($datumTmp["CONSTANTS"])) {
         $userConstants = self::getTemplateConstants($id);
         if (!empty($userConstants)) {
             foreach ($userConstants as $constantName => $constantData) {
                 if (isset($datumTmp["CONSTANTS"][$constantName])) {
                     $datumTmp["CONSTANTS"][$constantName]['Default'] = $constantData['Default'];
                 }
             }
         }
     }
     $templateData = array("DOCUMENT_TYPE" => $documentType, "AUTO_EXECUTE" => $autoExecute, "NAME" => $name, "DESCRIPTION" => $description, "TEMPLATE" => $datumTmp["TEMPLATE"], "PARAMETERS" => $datumTmp["PARAMETERS"], "VARIABLES" => $datumTmp["VARIABLES"], "CONSTANTS" => $datumTmp["CONSTANTS"], "USER_ID" => $systemImport ? 1 : $GLOBALS["USER"]->GetID(), "MODIFIER_USER" => new CBPWorkflowTemplateUser($systemImport ? 1 : CBPWorkflowTemplateUser::CurrentUser));
     if (!is_null($systemCode)) {
         $templateData["SYSTEM_CODE"] = $systemCode;
     }
     if ($id <= 0) {
         $templateData['ACTIVE'] = 'Y';
     }
     if ($id > 0) {
         self::Update($id, $templateData, $systemImport);
     } else {
         $id = self::Add($templateData, $systemImport);
     }
     $runtime = CBPRuntime::GetRuntime();
     $runtime->StartRuntime();
     $documentService = $runtime->GetService("DocumentService");
     $arDocumentFields = $documentService->GetDocumentFields($documentType);
     if (is_array($datumTmp["DOCUMENT_FIELDS"])) {
         $len = strlen("_PRINTABLE");
         $arFieldsTmp = array();
         foreach ($datumTmp["DOCUMENT_FIELDS"] as $code => $field) {
             if (!array_key_exists($code, $arDocumentFields) && strtoupper(substr($code, -$len)) != "_PRINTABLE") {
                 $arFieldsTmp[$code] = array("name" => $field["Name"], "code" => $code, "type" => $field["Type"], "multiple" => $field["Multiple"], "required" => $field["Required"]);
                 if (is_array($field["Options"]) && count($field["Options"]) > 0) {
                     foreach ($field["Options"] as $k => $v) {
                         $arFieldsTmp[$code]["options"] .= "[" . $k . "]" . $v . "\n";
                     }
                 }
                 unset($field["Name"], $field["Type"], $field["Multiple"], $field["Required"], $field["Options"]);
                 $arFieldsTmp[$code] = array_merge($arFieldsTmp[$code], $field);
             }
         }
         if (!empty($arFieldsTmp)) {
             \Bitrix\Main\Type\Collection::sortByColumn($arFieldsTmp, "sort");
             foreach ($arFieldsTmp as $fieldTmp) {
                 $documentService->AddDocumentField($documentType, $fieldTmp);
             }
         }
     }
     return $id;
 }
Пример #26
0
 public static function ExtractUsers($arUsersDraft, $documentId, $bFirst = false)
 {
     $result = array();
     if (!is_array($arUsersDraft)) {
         $arUsersDraft = array($arUsersDraft);
     }
     $l = strlen("user_");
     $runtime = CBPRuntime::GetRuntime();
     $documentService = $runtime->GetService("DocumentService");
     foreach ($arUsersDraft as $user) {
         if (substr($user, 0, $l) === "user_") {
             $user = intval(substr($user, $l));
             if ($user > 0 && !in_array($user, $result)) {
                 $result[] = $user;
             }
         } else {
             $arDSUsers = $documentService->GetUsersFromUserGroup($user, $documentId);
             foreach ($arDSUsers as $u) {
                 $u = intval($u);
                 if ($u > 0 && !in_array($u, $result)) {
                     $result[] = $u;
                 }
             }
         }
     }
     if (!$bFirst) {
         return $result;
     }
     if (count($result) > 0) {
         return $result[0];
     }
     return null;
 }
 private function SaveOrderDataCompanyBP($companyId, $isNewCompany, $arParameters = array())
 {
     $companyId = intval($companyId);
     if ($companyId <= 0) {
         return;
     }
     static $isBPIncluded = null;
     if ($isBPIncluded === null) {
         $isBPIncluded = CModule::IncludeModule("bizproc");
     }
     if (!$isBPIncluded) {
         return;
     }
     static $arBPTemplates = null;
     if ($arBPTemplates === null) {
         $arBPTemplates = CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType(array('crm', 'CCrmDocumentCompany', 'COMPANY'), $isNewCompany ? CBPDocumentEventType::Create : CBPDocumentEventType::Edit);
     }
     if (!is_array($arBPTemplates)) {
         return;
     }
     if (!is_array($arParameters)) {
         $arParameters = array($arParameters);
     }
     if (!array_key_exists("TargetUser", $arParameters)) {
         $assignedById = intval(COption::GetOptionString("crm", "sale_deal_assigned_by_id", "0"));
         if ($assignedById > 0) {
             $arParameters["TargetUser"] = "******" . $assignedById;
         }
     }
     $runtime = CBPRuntime::GetRuntime();
     foreach ($arBPTemplates as $wt) {
         try {
             $wi = $runtime->CreateWorkflow($wt["ID"], array('crm', 'CCrmDocumentCompany', 'COMPANY_' . $companyId), $arParameters);
             $wi->Start();
         } catch (Exception $e) {
             $this->AddError($e->getCode(), $e->getMessage());
         }
     }
 }
Пример #28
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $arErrors = array();
     $runtime = CBPRuntime::GetRuntime();
     $arProperties = array();
     if ($arCurrentValues["time_type_selector"] == "time") {
         if (strlen($arCurrentValues["delay_date"]) > 0 && ($d = MakeTimeStamp($arCurrentValues["delay_date"]))) {
             $arProperties["TimeoutTime"] = $d;
         } elseif (strlen($arCurrentValues["delay_date_x"]) > 0 && (preg_match('#^{=[A-Za-z0-9_]+:[A-Za-z0-9_]+}$#i', $arCurrentValues["delay_date_x"]) || substr($arCurrentValues["delay_date_x"], 0, 1) == "=")) {
             $arProperties["TimeoutTime"] = $arCurrentValues["delay_date_x"];
         }
     } else {
         $arProperties["TimeoutDuration"] = $arCurrentValues["delay_time"];
         $arProperties["TimeoutDurationType"] = $arCurrentValues["delay_type"];
     }
     $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($arErrors) > 0) {
         return false;
     }
     $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
     $arCurrentActivity["Properties"] = $arProperties;
     return true;
 }
Пример #29
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $runtime = CBPRuntime::GetRuntime();
     $arActivities = $runtime->SearchActivitiesByType("condition");
     if (!array_key_exists($arCurrentValues["condition_type"], $arActivities)) {
         $arErrors[] = array("code" => "", "message" => GetMessage("BPWA_INVALID_CONDITION_TYPE"));
         return false;
     }
     $condition = CBPActivityCondition::CallStaticMethod($arCurrentValues["condition_type"], "GetPropertiesDialogValues", array($documentType, $arWorkflowTemplate, $arWorkflowParameters, $arWorkflowVariables, $arCurrentValues, &$arErrors));
     if ($condition != null) {
         $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
         //if (!is_array($arCurrentActivity["Properties"]))
         $arCurrentActivity["Properties"] = array();
         $arCurrentActivity["Properties"][$arCurrentValues["condition_type"]] = $condition;
         return true;
     }
     return false;
 }
Пример #30
0
 public static function GetPropertiesDialogValues($documentType, $arWorkflowTemplate, $arWorkflowParameters, $arWorkflowVariables, $arCurrentValues, &$arErrors)
 {
     $runtime = CBPRuntime::GetRuntime();
     $arErrors = array();
     if (!array_key_exists("field_condition_count", $arCurrentValues) || strlen($arCurrentValues["field_condition_count"]) <= 0) {
         $arErrors[] = array("code" => "", "message" => GetMessage("BPFC_NO_WHERE"));
         return null;
     }
     $documentService = $runtime->GetService("DocumentService");
     $arDocumentFieldsTmp = $documentService->GetDocumentFields($documentType);
     $arResult = array();
     $arFieldConditionCount = explode(",", $arCurrentValues["field_condition_count"]);
     foreach ($arFieldConditionCount as $i) {
         if (intval($i) . "!" != $i . "!") {
             continue;
         }
         $i = intval($i);
         if (!array_key_exists("field_condition_field_" . $i, $arCurrentValues) || strlen($arCurrentValues["field_condition_field_" . $i]) <= 0) {
             continue;
         }
         $arErrors = array();
         $arCurrentValues["field_condition_value_" . $i] = $documentService->GetFieldInputValue($documentType, $arDocumentFieldsTmp[$arCurrentValues["field_condition_field_" . $i]], "field_condition_value_" . $i, $arCurrentValues, $arErrors);
         $arResult[] = array($arCurrentValues["field_condition_field_" . $i], htmlspecialcharsback($arCurrentValues["field_condition_condition_" . $i]), $arCurrentValues["field_condition_value_" . $i], (int) $arCurrentValues["field_condition_joiner_" . $i]);
     }
     if (count($arResult) <= 0) {
         $arErrors[] = array("code" => "", "message" => GetMessage("BPFC_NO_WHERE"));
         return null;
     }
     return $arResult;
 }