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);
     }
 }
Example #2
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));
 }
Example #3
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;
 }
Example #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);
 }
Example #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));
 }
 private static function GetHistoryService()
 {
     if (self::$historyService == null && CModule::IncludeModule('bizproc')) {
         $runtime = CBPRuntime::GetRuntime();
         $runtime->StartRuntime();
         self::$historyService = $runtime->GetService("HistoryService");
     }
     return self::$historyService;
 }
 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;
 }
 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);
 }
Example #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;
 }
Example #11
0
 /**
  * @param FieldType $fieldType
  * @return array
  */
 private static function getDocumentSelectFields(FieldType $fieldType)
 {
     $runtime = \CBPRuntime::getRuntime();
     $runtime->startRuntime();
     $documentService = $runtime->getService("DocumentService");
     $result = array();
     $fields = $documentService->getDocumentFields($fieldType->getDocumentType());
     foreach ($fields as $key => $field) {
         if ($field['Type'] == 'select' && substr($key, -10) != '_PRINTABLE') {
             $result[$key] = $field;
         }
     }
     return $result;
 }
Example #12
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;
 }
Example #13
0
 public static function OnEvent($workflowId, $eventName, $arEventParameters = array())
 {
     $num = func_num_args();
     if ($num > 3) {
         for ($i = 3; $i < $num; $i++) {
             $arEventParameters[] = func_get_arg($i);
         }
     }
     if ($arEventParameters["EntityId"] != null && $arEventParameters["EntityId"] != $arEventParameters[0]) {
         return;
     }
     try {
         CBPRuntime::SendExternalEvent($workflowId, $eventName, $arEventParameters);
     } catch (Exception $e) {
     }
 }
Example #14
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;
 }
Example #15
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;
 }
 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;
 }
 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());
         }
     }
 }
Example #19
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';
 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;
 }
Example #21
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;
 }
Example #22
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;
 }
Example #23
0
 public static function OnUnlockDocument($workflowId, $eventName, $documentId = array())
 {
     CBPRuntime::SendExternalEvent($workflowId, $eventName, array());
 }
Example #24
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);
     }
 }
 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;
 }
Example #26
0
 protected function getBizprocData()
 {
     $userId = $this->getUser()->getID();
     $currentUserGroups = $this->getUser()->getUserGroupArray();
     if (!$this->lists['ELEMENT_FIELDS'] || $this->lists['ELEMENT_FIELDS']['CREATED_BY'] == $userId) {
         $currentUserGroups[] = 'Author';
     }
     $documentType = 'iblock_' . $this->iblockId;
     CBPDocument::addShowParameterInit('lists', 'only_users', $documentType);
     $this->lists['BIZPROC_FIELDS'] = array();
     $bizprocIndex = 0;
     $documentStates = CBPDocument::getDocumentStates(array('lists', 'BizprocDocument', $documentType), null);
     $runtime = CBPRuntime::getRuntime();
     $runtime->startRuntime();
     $documentService = $runtime->getService('DocumentService');
     foreach ($documentStates as $documentState) {
         $bizprocIndex++;
         $viewWorkflow = CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::StartWorkflow, $userId, array('lists', 'BizprocDocument', $documentType), array('sectionId' => 0, 'AllUserGroups' => $currentUserGroups, 'DocumentStates' => $documentStates, 'WorkflowId' => $documentState['ID'] > 0 ? $documentState['ID'] : $documentState['TEMPLATE_ID']));
         if ($viewWorkflow) {
             $templateId = intval($documentState['TEMPLATE_ID']);
             $workflowParameters = $documentState['TEMPLATE_PARAMETERS'];
             if (!is_array($workflowParameters)) {
                 $workflowParameters = array();
             }
             if (strlen($documentState["ID"]) <= 0 && $templateId > 0) {
                 $parametersValues = array();
                 $keys = array_keys($workflowParameters);
                 foreach ($keys as $key) {
                     $value = $workflowParameters[$key]["Default"];
                     if (!is_array($value)) {
                         $parametersValues[$key] = htmlspecialcharsbx($value);
                     } else {
                         $keys1 = array_keys($value);
                         foreach ($keys1 as $key1) {
                             $parametersValues[$key][$key1] = htmlspecialcharsbx($value[$key1]);
                         }
                     }
                 }
                 foreach ($workflowParameters as $parameterKey => $arParameter) {
                     $parameterKeyExt = "bizproc" . $templateId . "_" . $parameterKey;
                     $html = $documentService->GetFieldInputControl(array('lists', 'BizprocDocument', $documentType), $arParameter, array("Form" => "start_workflow_form1", "Field" => $parameterKeyExt), $parametersValues[$parameterKey], false, true);
                     $this->lists['BIZPROC_FIELDS'][$parameterKeyExt . $bizprocIndex] = array("id" => $parameterKeyExt . $bizprocIndex, "required" => $arParameter["Required"], "name" => $arParameter["Name"], "title" => $arParameter["Description"], "type" => "custom", "value" => $html, 'show' => 'Y');
                 }
             }
         }
     }
 }
Example #27
0
 public static function onTaskChange($documentId, $taskId, $taskData, $status)
 {
     CListsLiveFeed::setMessageLiveFeed($taskData['USERS'], $documentId, $taskData['WORKFLOW_ID'], false);
     if ($status == CBPTaskChangedStatus::Delegate) {
         $runtime = CBPRuntime::getRuntime();
         /**
          * @var CBPAllStateService $stateService
          */
         $stateService = $runtime->getService('StateService');
         $stateService->setStatePermissions($taskData['WORKFLOW_ID'], array('R' => array('user_' . $taskData['USERS'][0])), array('setMode' => CBPSetPermissionsMode::Hold, 'setScope' => CBPSetPermissionsMode::ScopeDocument));
     }
 }
Example #28
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;
 }
 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;
 }
Example #30
0
 protected function getData()
 {
     $this->arResult['SHOW_MODE'] = 'SelectWorkflow';
     $this->arResult['TEMPLATES'] = array();
     $this->arResult['PARAMETERS_VALUES'] = array();
     $this->arResult['ERROR_MESSAGE'] = '';
     $runtime = CBPRuntime::getRuntime();
     $runtime->startRuntime();
     $this->arResult['DocumentService'] = $runtime->getService('DocumentService');
     foreach ($this->arResult['DOCUMENT_DATA'] as $nameModule => $data) {
         $workflowTemplateObject = CBPWorkflowTemplateLoader::getList(array(), array('DOCUMENT_TYPE' => $data['DOCUMENT_TYPE'], 'ACTIVE' => 'Y'), false, false, array('ID', 'NAME', 'DESCRIPTION', 'MODIFIED', 'USER_ID', 'PARAMETERS'));
         while ($workflowTemplate = $workflowTemplateObject->getNext()) {
             if (!CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $this->getUser()->getID(), $data['DOCUMENT_ID'], array())) {
                 continue;
             }
             if ($nameModule == 'DISK') {
                 $this->arResult['TEMPLATES'][$workflowTemplate['ID']] = $workflowTemplate;
                 $this->arResult['TEMPLATES'][$workflowTemplate['ID']]['URL'] = htmlspecialcharsex($this->getApplication()->getCurPageParam('workflow_template_id=' . $workflowTemplate['ID'] . '&' . bitrix_sessid_get(), array('workflow_template_id', 'sessid')));
             } else {
                 $this->arResult['TEMPLATES_OLD'][$workflowTemplate['ID']] = $workflowTemplate;
                 $this->arResult['TEMPLATES_OLD'][$workflowTemplate['ID']]['URL'] = htmlspecialcharsex($this->getApplication()->getCurPageParam('workflow_template_id=' . $workflowTemplate['ID'] . '&old=1&' . bitrix_sessid_get(), array('workflow_template_id', 'sessid')));
             }
         }
     }
     if ($this->arParams['TEMPLATE_ID'] > 0 && strlen($this->request->getPost('CancelStartParamWorkflow')) <= 0 && (array_key_exists($this->arParams['TEMPLATE_ID'], $this->arResult['TEMPLATES']) || array_key_exists($this->arParams['TEMPLATE_ID'], $this->arResult['TEMPLATES_OLD']))) {
         if (array_key_exists($this->arParams['TEMPLATE_ID'], $this->arResult['TEMPLATES'])) {
             $templates = $this->arResult['TEMPLATES'];
             $documentParameters = $this->arResult['DOCUMENT_DATA']['DISK'];
             $this->arResult['CHECK_TEMPLATE'] = 'DISK';
         } else {
             $templates = $this->arResult['TEMPLATES_OLD'];
             $documentParameters = $this->arResult['DOCUMENT_DATA']['WEBDAV'];
             $this->arResult['CHECK_TEMPLATE'] = 'WEBDAV';
         }
         $workflowTemplate = $templates[$this->arParams['TEMPLATE_ID']];
         $arWorkflowParameters = array();
         $canStartWorkflow = false;
         if (count($workflowTemplate['PARAMETERS']) <= 0) {
             $canStartWorkflow = true;
         } elseif ($this->request->isPost() && strlen($this->request->getPost('DoStartParamWorkflow')) > 0 && check_bitrix_sessid()) {
             $errorsTemporary = array();
             $request = $this->request->getPostList()->toArray();
             foreach ($_FILES as $key => $value) {
                 if (array_key_exists('name', $value)) {
                     if (is_array($value['name'])) {
                         $keys = array_keys($value['name']);
                         for ($i = 0, $cnt = count($keys); $i < $cnt; $i++) {
                             $array = array();
                             foreach ($value as $k1 => $v1) {
                                 $array[$k1] = $v1[$keys[$i]];
                             }
                             $request[$key][] = $array;
                         }
                     } else {
                         $request[$key] = $value;
                     }
                 }
             }
             $arWorkflowParameters = CBPWorkflowTemplateLoader::checkWorkflowParameters($workflowTemplate['PARAMETERS'], $request, $documentParameters['DOCUMENT_TYPE'], $errorsTemporary);
             if (count($errorsTemporary) > 0) {
                 $canStartWorkflow = false;
                 foreach ($errorsTemporary as $e) {
                     $this->errorCollection->add(array(new Error($e['message'])));
                 }
             } else {
                 $canStartWorkflow = true;
             }
         }
         if ($canStartWorkflow) {
             $errorsTemporary = array();
             $workflowId = CBPDocument::startWorkflow($this->arParams['TEMPLATE_ID'], $documentParameters['DOCUMENT_ID'], array_merge($arWorkflowParameters, array('TargetUser' => 'user_' . intval($this->getUser()->getID()))), $errorsTemporary);
             if (count($errorsTemporary) > 0) {
                 $this->arResult['SHOW_MODE'] = 'StartWorkflowError';
                 foreach ($errorsTemporary as $e) {
                     $this->errorCollection->add(array(new Error('[' . $e['code'] . '] ' . $e['message'])));
                 }
             } else {
                 $this->arResult['SHOW_MODE'] = 'StartWorkflowSuccess';
                 if (strlen($this->arResult['back_url']) > 0) {
                     LocalRedirect(str_replace('#WF#', $workflowId, $this->request->getQuery('back_url')));
                     $this->end(true);
                 }
             }
         } else {
             $doStartParam = $this->request->isPost() && strlen($this->request->getPost('DoStartParamWorkflow') && check_bitrix_sessid()) > 0;
             $keys = array_keys($workflowTemplate['PARAMETERS']);
             foreach ($keys as $key) {
                 $value = $doStartParam ? $this->request->getQuery($key) : $workflowTemplate['PARAMETERS'][$key]['Default'];
                 if (!is_array($value)) {
                     $this->arResult['PARAMETERS_VALUES'][$key] = CBPHelper::convertParameterValues($value);
                 } else {
                     $keys1 = array_keys($value);
                     foreach ($keys1 as $key1) {
                         $this->arResult['PARAMETERS_VALUES'][$key][$key1] = CBPHelper::convertParameterValues($value[$key1]);
                     }
                 }
             }
             $this->arResult['SHOW_MODE'] = 'WorkflowParameters';
         }
         if ($this->errorCollection->hasErrors()) {
             $error = array_shift($this->getErrors());
             ShowError($error->getMessage());
         }
     } else {
         $this->arResult['SHOW_MODE'] = 'SelectWorkflow';
     }
 }