示例#1
0
 protected function processActionDefault()
 {
     if ($this->storage->isEnabledBizProc()) {
         $documentData = array('DISK' => \Bitrix\Disk\BizProcDocument::generateDocumentComplexType($this->storage->getId()), 'WEBDAV' => \Bitrix\Disk\BizProcDocumentCompatible::generateDocumentComplexType($this->storage->getId()));
         if (!empty($this->arParams['FILE_ID'])) {
             $autoExecute = CBPDocumentEventType::Edit;
         } else {
             $autoExecute = CBPDocumentEventType::Create;
         }
         $this->arParams['BIZPROC_PARAMETERS'] = false;
         $this->arParams['BIZPROC_PARAMETERS_REQUIRED'] = array();
         $workflowTemplateId = '';
         foreach ($documentData as $nameModule => $data) {
             $workflowTemplateObject = CBPWorkflowTemplateLoader::getList(array(), array("DOCUMENT_TYPE" => $data, "AUTO_EXECUTE" => $autoExecute, "ACTIVE" => "Y"), false, false, array("ID", "PARAMETERS"));
             while ($workflowTemplate = $workflowTemplateObject->getNext()) {
                 if (!empty($workflowTemplate['PARAMETERS'])) {
                     foreach ($workflowTemplate['PARAMETERS'] as $parametersId => $parameters) {
                         if ($parameters['Required']) {
                             $this->arParams['BIZPROC_PARAMETERS_REQUIRED'][] = 'bizproc' . $workflowTemplate['ID'] . '_' . $parametersId;
                         }
                     }
                     $this->arParams['BIZPROC_PARAMETERS'] = true;
                 }
                 $workflowTemplateId = $workflowTemplate['ID'];
             }
         }
         $this->arParams['STATUS_START_BIZPROC'] = !empty($workflowTemplateId);
     }
     $this->arParams['STORAGE_ID'] = $this->storage->getId();
     $this->includeComponentTemplate();
 }
 /**
  * Static method returns loader object. Singleton pattern.
  *
  * @return CBPWorkflowTemplateLoader
  */
 public static function GetLoader()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
示例#3
0
	private static function UsersArrayToStringInternal($arUsers, $arWorkflowTemplate, $arAllowableUserGroups)
	{
		if (is_array($arUsers))
		{
			$r = array();

			$keys = array_keys($arUsers);
			foreach ($keys as $key)
				$r[$key] = self::UsersArrayToStringInternal($arUsers[$key], $arWorkflowTemplate, $arAllowableUserGroups);

			if (count($r) == 2)
			{
				$keys = array_keys($r);
				if ($keys[0] == 0 && $keys[1] == 1 && is_string($r[0]) && is_string($r[1]))
				{
					if (in_array($r[0], array("Document", "Template", "Variable", "User"))
						|| preg_match("#^A\d+_\d+_\d+_\d+$#i", $r[0])
						|| is_array($arWorkflowTemplate) && CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $r[0]) != null
						)
					{
						return "{=".$r[0].":".$r[1]."}";
					}
				}
			}

			return implode(", ", $r);
		}
		else
		{
			if (array_key_exists(strtolower($arUsers), $arAllowableUserGroups))
				return $arAllowableUserGroups[strtolower($arUsers)];

			$userId = 0;
			if (substr($arUsers, 0, strlen("user_")) == "user_")
				$userId = intval(substr($arUsers, strlen("user_")));

			if ($userId > 0)
			{
				$db = CUser::GetList(
					($by = "LAST_NAME"),
					($order = "asc"),
					array("ID_EQUAL_EXACT" => $userId),
					array(
						"NAV_PARAMS" => false,
					)
				);

				if ($ar = $db->Fetch())
				{
					$str = CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $ar, true);
					$str = $str." [".$ar["ID"]."]";
					return str_replace(",", " ", $str);
				}
			}

			return str_replace(",", " ", $arUsers);
		}
	}
示例#4
0
	function __wd_create_default_bp_user_and_groups($arr)
	{
		if($handle = opendir($_SERVER['DOCUMENT_ROOT'].'/'.BX_ROOT.'/modules/bizproc/templates'))
		{
			$documentType = array("webdav", "CIBlockDocumentWebdavSocnet", $arr["document_type"]);

			while(false !== ($file = readdir($handle)))
			{
				if(!is_file($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/bizproc/templates/'.$file))
				{
					continue;
				}


				$arFields = false;
				include($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/bizproc/templates/'.$file);
				if(is_array($arFields))
				{
					$arFields["DOCUMENT_TYPE"] = $documentType;
					$arFields["SYSTEM_CODE"] = $file;
					$arFields["USER_ID"]	= $GLOBALS['USER']->GetID();
					array_walk_recursive($arFields["TEMPLATE"], "__wd_replace_user_and_groups", $arr);
					if ($file == "status.php")
					{
						$arFields["AUTO_EXECUTE"] = CBPDocumentEventType::Create;
						if (!empty($arFields["PARAMETERS"]) && !empty($arFields["PARAMETERS"]["Approvers"]))
						{
							$name = "";
							if ($GLOBALS["USER"]->IsAuthorized() && $arr["owner"] == $GLOBALS["USER"]->GetID())
							{
								$name = trim($GLOBALS["USER"]->GetFirstName()." ".$GLOBALS["USER"]->GetLastName());
								$name = (empty($name) ? $GLOBALS["USER"]->GetLogin() : $name);
							}
							else
							{
								$dbUser = CUser::GetByID($arr["owner"]);
								$arUser = $dbUser->Fetch();
								$name = trim($arUser["NAME"]." ".$arUser["LAST_NAME"]);
								$name = (empty($name) ? $arUser["LOGIN"] : $name);
							}

							$arFields["PARAMETERS"]["Approvers"]["Default"] = $name.' ['.$arr["owner"].']';
						}
					}

					try
					{
						CBPWorkflowTemplateLoader::Add($arFields);
					}
					catch (Exception $e)
					{
					}
				}
			}
			closedir($handle);
		}
	}
 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;
 }
示例#6
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;
 }
示例#7
0
 protected function getTemplatesIdList()
 {
     if (!Loader::includeModule('bizproc') || empty($this->iblockTypeId) || empty($this->iblockId)) {
         return array();
     }
     $documentType = BizprocDocument::generateDocumentComplexType($this->iblockTypeId, $this->iblockId);
     $templates = array_merge(\CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType($documentType, CBPDocumentEventType::Create), \CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType($documentType, CBPDocumentEventType::Edit));
     $templateData = array();
     foreach ($templates as $template) {
         $templateData[$template['ID']]['ID'] = $template['ID'];
         $templateData[$template['ID']]['NAME'] = $template['NAME'];
     }
     return $templateData;
 }
示例#8
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;
 }
 public static function HasAutoWorkflows($ownerTypeID, $eventType)
 {
     if (!(IsModuleInstalled('bizproc') && CModule::IncludeModule('bizproc'))) {
         return false;
     }
     $ownerTypeID = (int) $ownerTypeID;
     $eventType = (int) $eventType;
     $docName = self::ResolveDocumentName($ownerTypeID);
     if ($docName === '') {
         return false;
     }
     $ownerTypeName = CCrmOwnerType::ResolveName($ownerTypeID);
     if ($ownerTypeName === '') {
         return false;
     }
     $ary = CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType(array('crm', $docName, $ownerTypeName), $eventType);
     return !empty($ary);
 }
 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;
 }
示例#11
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;
 }
示例#12
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;
 }
示例#13
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;
 }
        header("Pragma: public");
        echo $datum;
    }
    die;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_REQUEST['import_template'] == 'Y' && check_bitrix_sessid()) {
    $APPLICATION->RestartBuffer();
    //CUtil::DecodeUriComponent($_POST);
    $r = 0;
    $errTmp = "";
    if (is_uploaded_file($_FILES['import_template_file']['tmp_name'])) {
        $f = fopen($_FILES['import_template_file']['tmp_name'], "rb");
        $datum = fread($f, filesize($_FILES['import_template_file']['tmp_name']));
        fclose($f);
        try {
            $r = CBPWorkflowTemplateLoader::ImportTemplate($ID, array(MODULE_ID, ENTITY, $document_type), $_POST["import_template_autostart"], $_POST["import_template_name"], $_POST["import_template_description"], $datum);
        } catch (Exception $e) {
            $errTmp = $e->getMessage();
        }
    }
    ?>
	<script>
	<?php 
    if (intval($r) <= 0) {
        ?>
		alert('<?php 
        echo GetMessage("BIZPROC_WFEDIT_IMPORT_ERROR") . (strlen($errTmp) > 0 ? ": " . $errTmp : "");
        ?>
');
	<?php 
    } else {
 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 function processActionCheckDataElementCreation()
 {
     if ($_POST["save"] != "Y" && $_POST["changePostFormTab"] != "lists" && !check_bitrix_sessid()) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_CONNECTION_MODULE_IBLOCK'))));
     }
     if (!Loader::IncludeModule('bizproc')) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_CONNECTION_MODULE_BIZPROC'))));
     }
     if (!Loader::includeModule('iblock')) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_CONNECTION_MODULE_IBLOCK'))));
     }
     $this->iblockId = intval($this->request->getPost('IBLOCK_ID'));
     $this->iblockTypeId = COption::GetOptionString("lists", "livefeed_iblock_type_id");
     $this->checkPermissionElement();
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $templateId = intval($_POST['TEMPLATE_ID']);
     $documentType = BizprocDocument::generateDocumentComplexType(COption::GetOptionString("lists", "livefeed_iblock_type_id"), $this->iblockId);
     if (!empty($templateId)) {
         if (CModule::IncludeModule('bizproc')) {
             if (!CBPWorkflowTemplateLoader::isConstantsTuned($templateId)) {
                 $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_CONSTANTS_TUNED_NEW'))));
                 $this->sendJsonErrorResponse();
             }
         }
     } else {
         if (CModule::IncludeModule("bizproc")) {
             $templateObject = CBPWorkflowTemplateLoader::getTemplatesList(array('ID' => 'DESC'), array('DOCUMENT_TYPE' => $documentType, 'AUTO_EXECUTE' => CBPDocumentEventType::Create), false, false, array('ID'));
             $template = $templateObject->fetch();
             if (!empty($template)) {
                 if (!CBPWorkflowTemplateLoader::isConstantsTuned($template["ID"])) {
                     $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_CONSTANTS_TUNED_NEW'))));
                     $this->sendJsonErrorResponse();
                 }
             } else {
                 $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_NOT_BIZPROC_TEMPLATE'))));
                 $this->sendJsonErrorResponse();
             }
         }
     }
     $list = new CList($this->iblockId);
     $fields = $list->getFields();
     $elementData = array("IBLOCK_ID" => $this->iblockId, "NAME" => $_POST["NAME"]);
     $props = array();
     foreach ($fields as $fieldId => $field) {
         if ($fieldId == "PREVIEW_PICTURE" || $fieldId == "DETAIL_PICTURE") {
             $elementData[$fieldId] = $_FILES[$fieldId];
             if (isset($_POST[$fieldId . "_del"]) && $_POST[$fieldId . "_del"] == "Y") {
                 $elementData[$fieldId]["del"] = "Y";
             }
         } elseif ($fieldId == "PREVIEW_TEXT" || $fieldId == "DETAIL_TEXT") {
             if (isset($field["SETTINGS"]) && is_array($field["SETTINGS"]) && $field["SETTINGS"]["USE_EDITOR"] == "Y") {
                 $elementData[$fieldId . "_TYPE"] = "html";
             } else {
                 $elementData[$fieldId . "_TYPE"] = "text";
             }
             $elementData[$fieldId] = $_POST[$fieldId];
         } elseif ($fieldId == 'ACTIVE_FROM' || $fieldId == 'ACTIVE_TO') {
             $elementData[$fieldId] = array_shift($_POST[$fieldId]);
         } elseif ($list->is_field($fieldId)) {
             $elementData[$fieldId] = $_POST[$fieldId];
         } elseif ($field["PROPERTY_TYPE"] == "F") {
             if (isset($_POST[$fieldId . "_del"])) {
                 $deleteArray = $_POST[$fieldId . "_del"];
             } else {
                 $deleteArray = array();
             }
             $props[$field["ID"]] = array();
             $files = $this->unEscape($_FILES);
             CFile::ConvertFilesToPost($files[$fieldId], $props[$field["ID"]]);
             foreach ($props[$field["ID"]] as $fileId => $file) {
                 if (isset($deleteArray[$fileId]) && (!is_array($deleteArray[$fileId]) && $deleteArray[$fileId] == "Y" || is_array($deleteArray[$fileId]) && $deleteArray[$fileId]["VALUE"] == "Y")) {
                     if (isset($props[$field["ID"]][$fileId]["VALUE"])) {
                         $props[$field["ID"]][$fileId]["VALUE"]["del"] = "Y";
                     } else {
                         $props[$field["ID"]][$fileId]["del"] = "Y";
                     }
                 }
             }
         } elseif ($field["PROPERTY_TYPE"] == "N") {
             if (is_array($_POST[$fieldId]) && !array_key_exists("VALUE", $_POST[$fieldId])) {
                 $props[$field["ID"]] = array();
                 foreach ($_POST[$fieldId] as $key => $value) {
                     if (is_array($value)) {
                         if (strlen($value["VALUE"])) {
                             $value = str_replace(" ", "", str_replace(",", ".", $value["VALUE"]));
                             if (!is_numeric($value)) {
                                 $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_VALIDATE_FIELD_ERROR', array('#NAME#' => $field['NAME'])))));
                                 $this->sendJsonErrorResponse();
                             }
                             $props[$field["ID"]][$key] = doubleval($value);
                         }
                     } else {
                         if (strlen($value)) {
                             $value = str_replace(" ", "", str_replace(",", ".", $value));
                             if (!is_numeric($value)) {
                                 $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_VALIDATE_FIELD_ERROR', array('#NAME#' => $field['NAME'])))));
                                 $this->sendJsonErrorResponse();
                             }
                             $props[$field["ID"]][$key] = doubleval($value);
                         }
                     }
                 }
             } else {
                 if (is_array($_POST[$fieldId])) {
                     if (strlen($_POST[$fieldId]["VALUE"])) {
                         $value = str_replace(" ", "", str_replace(",", ".", $_POST[$fieldId]["VALUE"]));
                         if (!is_numeric($value)) {
                             $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_VALIDATE_FIELD_ERROR', array('#NAME#' => $field['NAME'])))));
                             $this->sendJsonErrorResponse();
                         }
                         $props[$field["ID"]] = doubleval($value);
                     }
                 } else {
                     if (strlen($_POST[$fieldId])) {
                         $value = str_replace(" ", "", str_replace(",", ".", $_POST[$fieldId]));
                         if (!is_numeric($value)) {
                             $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_VALIDATE_FIELD_ERROR', array('#NAME#' => $field['NAME'])))));
                             $this->sendJsonErrorResponse();
                         }
                         $props[$field["ID"]] = doubleval($value);
                     }
                 }
             }
         } else {
             $props[$field["ID"]] = $_POST[$fieldId];
         }
     }
     $elementData["MODIFIED_BY"] = $this->getUser()->getID();
     unset($elementData["TIMESTAMP_X"]);
     if (!empty($props)) {
         $elementData["PROPERTY_VALUES"] = $props;
     }
     $documentStates = CBPDocument::GetDocumentStates($documentType, null);
     $userId = $this->getUser()->getId();
     $write = CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::WriteDocument, $userId, $documentType, array('AllUserGroups' => array(), 'DocumentStates' => $documentStates));
     if (!$write) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_IS_ACCESS_DENIED_STATUS'))));
         $this->sendJsonErrorResponse();
     }
     $bizprocParametersValues = array();
     foreach ($documentStates as $documentState) {
         if (strlen($documentState["ID"]) <= 0) {
             $errors = array();
             $bizprocParametersValues[$documentState['TEMPLATE_ID']] = CBPDocument::StartWorkflowParametersValidate($documentState['TEMPLATE_ID'], $documentState['TEMPLATE_PARAMETERS'], $documentType, $errors);
             $stringError = '';
             foreach ($errors as $e) {
                 $stringError .= $e['message'] . '<br />';
             }
         }
     }
     if (!empty($stringError)) {
         $this->errorCollection->add(array(new Error($stringError)));
         $this->sendJsonErrorResponse();
     }
     $objectElement = new CIBlockElement();
     $idElement = $objectElement->Add($elementData, false, true, true);
     if ($idElement) {
         $bizProcWorkflowId = array();
         foreach ($documentStates as $documentState) {
             if (strlen($documentState["ID"]) <= 0) {
                 $errorsTmp = array();
                 $bizProcWorkflowId[$documentState['TEMPLATE_ID']] = CBPDocument::StartWorkflow($documentState['TEMPLATE_ID'], array('lists', 'BizprocDocument', $idElement), array_merge($bizprocParametersValues[$documentState['TEMPLATE_ID']], array('TargetUser' => 'user_' . intval($this->getUser()->getID()))), $errorsTmp);
             }
         }
         if (!empty($errorsTmp)) {
             $documentStates = null;
             CBPDocument::AddDocumentToHistory(array('lists', 'BizprocDocument', $idElement), $elementData['NAME'], $this->getUser()->getID());
         }
     } else {
         $this->errorCollection->add(array(new Error($objectElement->LAST_ERROR)));
         $this->sendJsonErrorResponse();
     }
     $this->sendJsonSuccessResponse(array());
 }
示例#17
0
 /**
  * Creates new workflow instance from the specified template.
  *
  * @param int $workflowTemplateId - ID of the workflow template
  * @param string $documentId - ID of the document
  * @param mixed $workflowParameters - Optional parameters of the created workflow instance
  * @param array|null $parentWorkflow - Parent Workflow information.
  * @return CBPWorkflow
  * @throws CBPArgumentNullException
  * @throws CBPArgumentOutOfRangeException
  * @throws Exception
  * @throws \Bitrix\Main\ArgumentNullException
  */
 public function CreateWorkflow($workflowTemplateId, $documentId, $workflowParameters = array(), $parentWorkflow = null)
 {
     $workflowTemplateId = intval($workflowTemplateId);
     if ($workflowTemplateId <= 0) {
         throw new Exception("workflowTemplateId");
     }
     $arDocumentId = CBPHelper::ParseDocumentId($documentId);
     $limit = \Bitrix\Main\Config\Option::get("bizproc", "limit_simultaneous_processes", "0");
     if (intval($limit) > 0) {
         if (CBPStateService::CountDocumentWorkflows($documentId) >= $limit) {
             throw new Exception(GetMessage("BPCGDOC_LIMIT_SIMULTANEOUS_PROCESSES", array("#NUM#" => $limit)));
         }
     }
     if (!$this->isStarted) {
         $this->StartRuntime();
     }
     $workflowId = uniqid("", true);
     if ($parentWorkflow) {
         $this->addWorkflowToChain($workflowId, $parentWorkflow);
         if ($this->checkWorkflowRecursion($workflowId, $workflowTemplateId)) {
             throw new Exception(GetMessage("BPCGDOC_WORKFLOW_RECURSION_LOCK"));
         }
     }
     $workflow = new CBPWorkflow($workflowId, $this);
     $loader = CBPWorkflowTemplateLoader::GetLoader();
     list($rootActivity, $workflowVariablesTypes, $workflowParametersTypes) = $loader->LoadWorkflow($workflowTemplateId);
     if ($rootActivity == null) {
         throw new Exception("EmptyRootActivity");
     }
     //if (!is_a($rootActivity, "IBPRootActivity"))
     //	throw new Exception("RootActivityIsNotAIBPRootActivity");
     foreach (GetModuleEvents("bizproc", "OnCreateWorkflow", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($workflowTemplateId, $documentId, &$workflowParameters));
     }
     $workflow->Initialize($rootActivity, $arDocumentId, $workflowParameters, $workflowVariablesTypes, $workflowParametersTypes, $workflowTemplateId);
     $starterUserId = 0;
     if (isset($workflowParameters[CBPDocument::PARAM_TAGRET_USER])) {
         $starterUserId = intval(substr($workflowParameters[CBPDocument::PARAM_TAGRET_USER], strlen("user_")));
     }
     $this->arServices["StateService"]->AddWorkflow($workflowId, $workflowTemplateId, $arDocumentId, $starterUserId);
     $this->arWorkflows[$workflowId] = $workflow;
     return $workflow;
 }
 public static function Delete($id)
 {
     $loader = CBPWorkflowTemplateLoader::GetLoader();
     $loader->DeleteTemplate($id);
     self::cleanTemplateCache($id);
 }
示例#19
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;
 }
示例#20
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;
 }
示例#21
0
    }
}
foreach ($arCustomFilter as $FIELD_ID => $arCallback) {
    $filtered = false;
    call_user_func_array($arCallback["callback"], array($arListFields[$FIELD_ID], array("VALUE" => $FIELD_ID, "GRID_ID" => $arResult["GRID_ID"]), &$arFilter, &$filtered));
}
$arFilter["IBLOCK_ID"] = $arIBlock["ID"];
$arFilter["CHECK_PERMISSIONS"] = $lists_perm >= CListPermissions::CAN_READ ? "N" : "Y";
if (!$arResult["ANY_SECTION"]) {
    $arFilter["SECTION_ID"] = $arResult["SECTION_ID"];
}
/** @var CIBlockResult $rsElements */
$rsElements = CIBlockElement::GetList($grid_sort["sort"], $arFilter, false, $grid_options->GetNavParams(), $arSelect);
if ($arResult["BIZPROC"] == "Y") {
    $arUserGroupsForBP = CUser::GetUserGroup($USER->GetID());
    $arDocumentStatesForBP = CBPWorkflowTemplateLoader::GetDocumentTypeStates(BizProcDocument::generateDocumentComplexType($arParams["IBLOCK_TYPE_ID"], $arIBlock["ID"]));
} else {
    $arUserGroupsForBP = array();
    $arDocumentStatesForBP = array();
}
$arResult["ELEMENTS_CAN_DELETE"] = array();
$arResult["ELEMENTS_CAN_MOVE"] = array();
$arResult["ELEMENTS_ROWS"] = array();
$check = false;
while ($obElement = $rsElements->GetNextElement()) {
    $check = true;
    $data = $obElement->GetFields();
    $aCols = array();
    if (!empty($arProperties)) {
        $rsProp = CIBlockElement::GetProperty($arIBlock["ID"], $data["ID"]);
        while ($arProp = $rsProp->Fetch()) {
示例#22
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;
 }
示例#23
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;
 }
示例#24
0
 $arResult["Blocks"] = array();
 $dbBlockList = CIBlock::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("ACTIVE" => "Y", "SITE_ID" => SITE_ID, "TYPE" => $arParams["IBLOCK_TYPE"]));
 while ($arBlock = $dbBlockList->GetNext()) {
     $arBlock["LIST_URL"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_LIST"], array("block_id" => $arBlock["ID"]));
     if (intval($arBlock["PICTURE"]) <= 0) {
         $arBlock["PICTURE"] = "/bitrix/images/bizproc/vd_bp.jpg";
     }
     $arMessagesTmp = CIBlock::GetMessages($arBlock["ID"]);
     $arBlock["CreateTitle"] = htmlspecialcharsbx(is_array($arMessagesTmp) && array_key_exists("ELEMENT_ADD", $arMessagesTmp) ? $arMessagesTmp["ELEMENT_ADD"] : "");
     $workflowTemplateId = 0;
     $db = CBPWorkflowTemplateLoader::GetList(array(), array("DOCUMENT_TYPE" => array("bizproc", "CBPVirtualDocument", "type_" . $arBlock["ID"])), false, false, array("ID"));
     if ($ar = $db->Fetch()) {
         $workflowTemplateId = intval($ar["ID"]);
     }
     if ($workflowTemplateId > 0) {
         $arWorkflowTemplate = CBPWorkflowTemplateLoader::GetTemplateState($workflowTemplateId);
         if (!is_array($arWorkflowTemplate["STATE_PERMISSIONS"]) || count($arWorkflowTemplate["STATE_PERMISSIONS"]) <= 0) {
             $arWorkflowTemplate["STATE_PERMISSIONS"]["create"] = array("author");
         }
         $arAllowableOperations = CBPDocument::GetAllowableOperations($GLOBALS["USER"]->GetID(), $GLOBALS["USER"]->GetUserGroupArray(), array($arWorkflowTemplate));
         $arBlock["START_URL"] = "";
         if ($arResult["AdminAccess"] || (is_array($arAllowableOperations) && in_array("create", $arAllowableOperations) || is_array($arWorkflowTemplate["STATE_PERMISSIONS"]["create"]) && in_array("author", $arWorkflowTemplate["STATE_PERMISSIONS"]["create"]))) {
             $arBlock["START_URL"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_START"], array("block_id" => $arBlock["ID"]));
         }
     }
     $arBlock["DELETE_URL"] = "";
     if ($arResult["AdminAccess"]) {
         $arBlock["EDIT_URL"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_EDIT"], array("block_id" => $arBlock["ID"]));
         $arBlock["DELETE_URL"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_INDEX"], array());
         $arBlock["DELETE_URL"] .= strpos($arBlock["DELETE_URL"], "?") === false ? "?" : "&";
         $arBlock["DELETE_URL"] .= "delete_block_id=" . $arBlock["ID"] . "&" . bitrix_sessid_get();
 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());
         }
     }
 }
示例#26
0
 public static function &FindActivityInTemplate(&$arWorkflowTemplate, $activityName)
 {
     return CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
 }
示例#27
0
 function CanUserOperateDocumentType($operation, $userId, $documentType, $parameters = array())
 {
     $documentType = trim($documentType);
     if (strlen($documentType) <= 0) {
         return false;
     }
     $parameters["IBlockId"] = intval(substr($documentType, strlen("iblock_")));
     $parameters['sectionId'] = !empty($parameters['sectionId']) ? (int) $parameters['sectionId'] : 0;
     if (!array_key_exists("IBlockRightsMode", $parameters)) {
         $parameters["IBlockRightsMode"] = CIBlock::getArrayByID($parameters["IBlockId"], "RIGHTS_MODE");
     }
     if ($parameters["IBlockRightsMode"] === "E") {
         if ($operation === CBPCanUserOperateOperation::CreateWorkflow) {
             return CIBlockRights::userHasRightTo($parameters["IBlockId"], $parameters["IBlockId"], "iblock_rights_edit");
         } elseif ($operation === CBPCanUserOperateOperation::WriteDocument) {
             return CIBlockSectionRights::userHasRightTo($parameters["IBlockId"], $parameters["sectionId"], "section_element_bind");
         } elseif ($operation === CBPCanUserOperateOperation::ViewWorkflow || $operation === CBPCanUserOperateOperation::StartWorkflow) {
             if (!array_key_exists("WorkflowId", $parameters)) {
                 return false;
             }
             if ($operation === CBPCanUserOperateOperation::ViewWorkflow) {
                 return CIBlockRights::userHasRightTo($parameters["IBlockId"], 0, "element_read");
             }
             if ($operation === CBPCanUserOperateOperation::StartWorkflow) {
                 return CIBlockSectionRights::userHasRightTo($parameters["IBlockId"], $parameters['sectionId'], "section_element_bind");
             }
             $userId = intval($userId);
             if (!array_key_exists("AllUserGroups", $parameters)) {
                 if (!array_key_exists("UserGroups", $parameters)) {
                     $parameters["UserGroups"] = CUser::getUserGroup($userId);
                 }
                 $parameters["AllUserGroups"] = $parameters["UserGroups"];
                 $parameters["AllUserGroups"][] = "Author";
             }
             if (!array_key_exists("DocumentStates", $parameters)) {
                 if ($operation === CBPCanUserOperateOperation::StartWorkflow) {
                     $parameters["DocumentStates"] = CBPWorkflowTemplateLoader::getDocumentTypeStates(array("lists", get_called_class(), "iblock_" . $parameters["IBlockId"]));
                 } else {
                     $parameters["DocumentStates"] = CBPDocument::getDocumentStates(array("lists", get_called_class(), "iblock_" . $parameters["IBlockId"]), null);
                 }
             }
             if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"])) {
                 $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]);
             } else {
                 return false;
             }
             $allowableOperations = CBPDocument::getAllowableOperations($userId, $parameters["AllUserGroups"], $parameters["DocumentStates"], true);
             if (!is_array($allowableOperations)) {
                 return false;
             }
             if ($operation === CBPCanUserOperateOperation::ViewWorkflow && in_array("read", $allowableOperations) || $operation === CBPCanUserOperateOperation::StartWorkflow && in_array("write", $allowableOperations)) {
                 return true;
             }
             $chop = $operation === CBPCanUserOperateOperation::ViewWorkflow ? "element_read" : "section_element_bind";
             $tasks = self::getRightsTasks();
             foreach ($allowableOperations as $op) {
                 if (isset($tasks[$op])) {
                     $op = $tasks[$op]['ID'];
                 }
                 $ar = CTask::getOperations($op, true);
                 if (in_array($chop, $ar)) {
                     return true;
                 }
             }
         }
         return false;
     }
     if (!array_key_exists("IBlockPermission", $parameters)) {
         if (CModule::includeModule('lists')) {
             $parameters["IBlockPermission"] = CLists::getIBlockPermission($parameters["IBlockId"], $userId);
         } else {
             $parameters["IBlockPermission"] = CIBlock::getPermission($parameters["IBlockId"], $userId);
         }
     }
     if ($parameters["IBlockPermission"] <= "R") {
         return false;
     } elseif ($parameters["IBlockPermission"] >= "W") {
         return true;
     }
     $userId = intval($userId);
     if (!array_key_exists("AllUserGroups", $parameters)) {
         if (!array_key_exists("UserGroups", $parameters)) {
             $parameters["UserGroups"] = CUser::getUserGroup($userId);
         }
         $parameters["AllUserGroups"] = $parameters["UserGroups"];
         $parameters["AllUserGroups"][] = "Author";
     }
     if (!array_key_exists("DocumentStates", $parameters)) {
         $parameters["DocumentStates"] = CBPDocument::getDocumentStates(array("lists", get_called_class(), "iblock_" . $parameters["IBlockId"]), null);
     }
     if (array_key_exists("WorkflowId", $parameters)) {
         if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"])) {
             $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]);
         } else {
             return false;
         }
     }
     $allowableOperations = CBPDocument::getAllowableOperations($userId, $parameters["AllUserGroups"], $parameters["DocumentStates"]);
     if (!is_array($allowableOperations)) {
         return false;
     }
     $r = false;
     switch ($operation) {
         case CBPCanUserOperateOperation::ViewWorkflow:
             $r = in_array("read", $allowableOperations);
             break;
         case CBPCanUserOperateOperation::StartWorkflow:
             $r = in_array("write", $allowableOperations);
             break;
         case CBPCanUserOperateOperation::CreateWorkflow:
             $r = in_array("write", $allowableOperations);
             break;
         case CBPCanUserOperateOperation::WriteDocument:
             $r = in_array("write", $allowableOperations);
             break;
         case CBPCanUserOperateOperation::ReadDocument:
             $r = false;
             break;
         default:
             $r = false;
     }
     return $r;
 }
示例#28
0
 global $CACHE_MANAGER;
 $CACHE_MANAGER->Clean("component_bizproc_wizards_templates");
 if (intval($arResult["Data"]["Image"]) > 0) {
     CFile::Delete($arResult["Data"]["Image"]);
 }
 if ($arParams["BLOCK_ID"] <= 0 && strlen($arResult["Data"]["Template"]) > 0) {
     $arVariables = false;
     if (method_exists($bpTemplateObject, "GetVariables")) {
         $arVariables = $bpTemplateObject->GetVariables();
         $ks = array_keys($arVariables);
         foreach ($ks as $k) {
             $arVariables[$k]["Default"] = $arResult["Data"]["TemplateVariables"][$k];
         }
     }
     $arFieldsT = array("DOCUMENT_TYPE" => array("bizproc", "CBPVirtualDocument", "type_" . $iblockId), "AUTO_EXECUTE" => CBPDocumentEventType::Create, "NAME" => $arResult["Data"]["Name"], "DESCRIPTION" => $arResult["Data"]["Description"], "TEMPLATE" => $bpTemplateObject->GetTemplate(), "PARAMETERS" => $bpTemplateObject->GetParameters(), "VARIABLES" => $arVariables, "USER_ID" => $GLOBALS["USER"]->GetID(), "ACTIVE" => 'Y', "MODIFIER_USER" => new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     CBPWorkflowTemplateLoader::Add($arFieldsT);
     if (method_exists($bpTemplateObject, "GetDocumentFields")) {
         $runtime = CBPRuntime::GetRuntime();
         $runtime->StartRuntime();
         $arResult["DocumentService"] = $runtime->GetService("DocumentService");
         $arDocumentFields = $bpTemplateObject->GetDocumentFields();
         if ($arDocumentFields && is_array($arDocumentFields) && count($arDocumentFields) > 0) {
             foreach ($arDocumentFields as $f) {
                 $arResult["DocumentService"]->AddDocumentField(array("bizproc", "CBPVirtualDocument", "type_" . $iblockId), $f);
             }
         }
     }
 }
 $redirectPath = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_LIST"], array("block_id" => $iblockId));
 $redirectPath .= (strpos($redirectPath, "?") !== false ? "&" : "?") . "template_type=" . $arResult["NewTemplateType"];
 LocalRedirect($redirectPath);
示例#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
 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';
     }
 }