Exemplo n.º 1
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);
		}
	}
Exemplo n.º 2
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);
Exemplo n.º 3
0
	public static function AddDefaultWorkflowTemplates($documentType, $additionalModuleId = null)
	{
		if (!empty($additionalModuleId))
		{
			$additionalModuleId = preg_replace("/[^a-z0-9_.]/i", "", $additionalModuleId);
			$arModule = array($additionalModuleId, $documentType[0], 'bizproc');
		}
		else
		{
			$arModule = array($documentType[0], 'bizproc');
		}

		$bIn = false;
		foreach ($arModule as $sModule)
		{
			if($handle = opendir($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates'))
			{
				$bIn = true;
				while(false !== ($file = readdir($handle)))
				{
					if(!is_file($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates/'.$file))
						continue;
					$arFields = false;
					include($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates/'.$file);
					if(is_array($arFields))
					{
						/*
						 * If DOCUMENT_TYPE not defined, use current documentType
						 * Overwise check if DOCUMENT_TYPE equals to current documentType
						 */
						if (!array_key_exists("DOCUMENT_TYPE", $arFields))
							$arFields["DOCUMENT_TYPE"] = $documentType;
						elseif($arFields["DOCUMENT_TYPE"] != $documentType)
							continue;
						
						$arFields["SYSTEM_CODE"] = $file;
						if(is_object($GLOBALS['USER']))
							$arFields["USER_ID"] = $GLOBALS['USER']->GetID();
						$arFields["MODIFIER_USER"] = new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser);
						try
						{
							CBPWorkflowTemplateLoader::Add($arFields);
						}
						catch (Exception $e)
						{
						}
					}
				}
				closedir($handle);
			}
			if ($bIn)
				break;
		}
	}
Exemplo n.º 4
0
 /**
  *
  * 1) шаг первый - создание Инфоблока
  * 2) шаг второй - создание шаблона Бизнес-Процесса
  * @param array $arResult - массив с данными
  * @param array $arParams - 
  */
 public static function addBP($arResult, $arParams)
 {
     if (!CModule::IncludeModule("iblock")) {
         ShowError('Нет модуля iblock');
     }
     if (!CModule::IncludeModule("bizproc")) {
         ShowError('Нет модуля bizproc');
     }
     $ib = new CIBlock();
     $description = 'описание';
     /*
      ШАГ 1
     */
     $arFields = array("IBLOCK_TYPE_ID" => $arParams["IBLOCK_TYPE"], "LID" => "s1", "NAME" => $arResult["Data"]["Name"], "CODE" => "select_color", "ACTIVE" => 'Y', "SORT" => $arResult["Data"]["Sort"], "PICTURE" => intval($arResult["Data"]["Image"]) > 0 ? CFile::MakeFileArray($arResult["Data"]["Image"]) : false, "DESCRIPTION" => $description, "DESCRIPTION_TYPE" => 'text', "WORKFLOW" => 'N', "BIZPROC" => 'Y', "VERSION" => 1, "ELEMENT_ADD" => $arResult["Data"]["ElementAdd"]);
     foreach ($arResult["Data"]["UserGroups"] as $v) {
         $arFields["GROUP_ID"][$v] = "R";
     }
     if ($arParams["BLOCK_ID"] <= 0) {
         $opRes = $iblockId = $ib->Add($arFields);
     } else {
         $opRes = $ib->Update($arParams["BLOCK_ID"], $arFields);
         $iblockId = $arParams["BLOCK_ID"];
     }
     /*
      ШАГ 2
     */
     if ($opRes) {
         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);
                     }
                 }
             }
         }
         /*
          * разворачиваем шаблон БП из файла
          */
         $templateFileNameBP = $_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/adeveloper.bp/data/bp-sc.bpt';
         $f = fopen($templateFileNameBP, "rb");
         $datum = fread($f, filesize($templateFileNameBP));
         fclose($f);
         try {
             $BLOCK_ID = $opRes;
             $r = CBPWorkflowTemplateLoader::ImportTemplate($ID, array("bizproc", "CBPVirtualDocument", "type_" . $BLOCK_ID), 1, "Шаблон БП", "Описание шаблона", $datum);
         } catch (Exception $e) {
             $errTmp = preg_replace("#[\r\n]+#", " ", $e->getMessage());
         }
     } else {
         ShowError("Инфоблока нет");
     }
     return $opRes;
 }
Exemplo n.º 5
0
 function InitializeIBlock($taskType, $ownerId, $forumId)
 {
     $iblockId = COption::GetOptionInt("intranet", "iblock_tasks", 0);
     if ($iblockId <= 0) {
         return 0;
     }
     $forumId = intval($forumId);
     $arTasksConverted2BP = array();
     $keyTasksConverted2BP = $iblockId . "_" . $taskType . ($taskType == "group" ? "_" . $ownerId : "");
     global $CACHE_MANAGER;
     if ($CACHE_MANAGER->Read(2592000, "IntranetTasksConverted2BP")) {
         $arTasksConverted2BP = $CACHE_MANAGER->Get("IntranetTasksConverted2BP");
         if (array_key_exists($keyTasksConverted2BP, $arTasksConverted2BP)) {
             return $arTasksConverted2BP[$keyTasksConverted2BP];
         }
     }
     $globalParentSectionId = 0;
     $dbIBlock = CIBlock::GetList(array(), array("ID" => $iblockId, "ACTIVE" => "Y"));
     if ($arIBlock = $dbIBlock->Fetch()) {
         $arIBlockProperties = array();
         $dbIBlockProps = CIBlock::GetProperties($iblockId);
         while ($arIBlockProps = $dbIBlockProps->Fetch()) {
             $ind = StrLen($arIBlockProps["CODE"]) > 0 ? $arIBlockProps["CODE"] : $arIBlockProps["ID"];
             $arIBlockProperties[StrToUpper($ind)] = $arIBlockProps;
         }
         $arTasksProps = array("TASKPRIORITY" => array("NAME" => GetMessage("INTI_TASKPRIORITY"), "ACTIVE" => "Y", "SORT" => 100, "CODE" => "TaskPriority", "PROPERTY_TYPE" => "L", "USER_TYPE" => false, "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "Y", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId, "VALUES" => array(array("VALUE" => "   " . GetMessage("INTI_TASKPRIORITY_1"), "DEF" => "N", "SORT" => 100, "XML_ID" => "1"), array("VALUE" => "  " . GetMessage("INTI_TASKPRIORITY_2"), "DEF" => "Y", "SORT" => 200, "XML_ID" => "2"), array("VALUE" => " " . GetMessage("INTI_TASKPRIORITY_3"), "DEF" => "N", "SORT" => 300, "XML_ID" => "3"))), "TASKCOMPLETE" => array("NAME" => GetMessage("INTI_TASKCOMPLETE"), "ACTIVE" => "Y", "SORT" => 300, "CODE" => "TaskComplete", "PROPERTY_TYPE" => "N", "USER_TYPE" => false, "ROW_COUNT" => 1, "COL_COUNT" => 5, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKASSIGNEDTO" => array("NAME" => GetMessage("INTI_TASKASSIGNEDTO"), "ACTIVE" => "Y", "SORT" => 400, "CODE" => "TaskAssignedTo", "PROPERTY_TYPE" => "S", "USER_TYPE" => "UserID", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "Y", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKTRACKERS" => array("NAME" => GetMessage("INTI_TASKTRACKERS"), "ACTIVE" => "Y", "SORT" => 400, "CODE" => "TaskTrackers", "PROPERTY_TYPE" => "S", "USER_TYPE" => "UserID", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "Y", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKALERT" => array("NAME" => GetMessage("INTI_TASKALERT"), "ACTIVE" => "Y", "SORT" => 500, "CODE" => "TaskAlert", "PROPERTY_TYPE" => "S", "USER_TYPE" => false, "DEFAULT_VALUE" => "Y", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKSIZE" => array("NAME" => GetMessage("INTI_TASKSIZE"), "ACTIVE" => "Y", "SORT" => 600, "CODE" => "TaskSize", "PROPERTY_TYPE" => "N", "USER_TYPE" => false, "ROW_COUNT" => 1, "COL_COUNT" => 5, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKSIZEREAL" => array("NAME" => GetMessage("INTI_TASKSIZEREAL"), "ACTIVE" => "Y", "SORT" => 700, "CODE" => "TaskSizeReal", "PROPERTY_TYPE" => "N", "USER_TYPE" => false, "ROW_COUNT" => 1, "COL_COUNT" => 5, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKFINISH" => array("NAME" => GetMessage("INTI_TASKFINISH"), "ACTIVE" => "Y", "SORT" => 800, "CODE" => "TaskFinish", "PROPERTY_TYPE" => "S", "USER_TYPE" => "DateTime", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKFILES" => array("NAME" => GetMessage("INTI_TASKFILES"), "ACTIVE" => "Y", "SORT" => 900, "CODE" => "TaskFiles", "PROPERTY_TYPE" => "F", "USER_TYPE" => false, "ROW_COUNT" => 10, "COL_COUNT" => 60, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "Y", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKREPORT" => array("NAME" => GetMessage("INTI_TASKREPORT"), "ACTIVE" => "Y", "SORT" => 1000, "CODE" => "TaskReport", "PROPERTY_TYPE" => "S", "USER_TYPE" => false, "ROW_COUNT" => 10, "COL_COUNT" => 60, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKREMIND" => array("NAME" => GetMessage("INTI_TASKREMIND"), "ACTIVE" => "Y", "SORT" => 300, "CODE" => "TaskRemind", "PROPERTY_TYPE" => "S", "USER_TYPE" => "DateTime", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "VERSION" => array("NAME" => GetMessage("INTI_VERSION"), "ACTIVE" => "Y", "SORT" => 1100, "CODE" => "VERSION", "PROPERTY_TYPE" => "N", "USER_TYPE" => false, "ROW_COUNT" => 1, "COL_COUNT" => 10, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "TASKVERSION" => array("NAME" => GetMessage("INTI_TASKVERSION"), "ACTIVE" => "Y", "SORT" => 1100, "CODE" => "TASKVERSION", "PROPERTY_TYPE" => "N", "USER_TYPE" => false, "ROW_COUNT" => 1, "COL_COUNT" => 10, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId));
         foreach ($arTasksProps as $propKey => $arProp) {
             if (!array_key_exists($propKey, $arIBlockProperties)) {
                 $ibp = new CIBlockProperty();
                 $ibp->Add($arProp);
             }
         }
         $dbSectionsList = CIBlockSection::GetList(array(), array("GLOBAL_ACTIVE" => "Y", "XML_ID" => $taskType == "group" ? $ownerId : "users_tasks", "IBLOCK_ID" => $iblockId, "SECTION_ID" => 0), false);
         if ($arSection = $dbSectionsList->GetNext()) {
             $globalParentSectionId = $arSection["ID"];
         }
         if ($globalParentSectionId <= 0) {
             if ($taskType == "group") {
                 $folderName = "-";
                 $folderXmlId = $ownerId;
                 if ($arGroup = CSocNetGroup::GetByID($ownerId)) {
                     $folderName = $arGroup["NAME"] . " [" . $ownerId . "]";
                     $folderXmlId = $ownerId;
                 }
             } else {
                 $folderName = "User Tasks";
                 $folderXmlId = "users_tasks";
             }
             $arFields = array("IBLOCK_ID" => $iblockId, "IBLOCK_SECTION_ID" => 0, "ACTIVE" => "Y", "NAME" => $folderName, "XML_ID" => $folderXmlId);
             $iblockSection = new CIBlockSection();
             $globalParentSectionId = $iblockSection->Add($arFields, true);
             CIntranetTasks::InstallDefaultViews($taskType, $ownerId);
         }
         $db = CBPWorkflowTemplateLoader::GetList(array(), array("DOCUMENT_TYPE" => array("intranet", "CIntranetTasksDocument", "x" . $iblockId)), false, false, array("ID"));
         //			while ($ar = $db->Fetch())
         //			{
         //				try
         //				{
         //					CBPWorkflowTemplateLoader::Delete($ar["ID"]);
         //				}
         //				catch(Exception $e)
         //				{
         //					CBPWorkflowTemplateLoader::Update($ar["ID"], array("AUTO_EXECUTE" => 0));
         //				}
         //			}
         $workflowTemplateId = 0;
         if ($ar = $db->Fetch()) {
             $workflowTemplateId = $ar["ID"];
         } else {
             require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/intranet/classes/general/tasks_wf_template.php";
             $workflowTemplateId = CBPWorkflowTemplateLoader::Add($arFields);
         }
         $arTaskStatusTmp = array();
         $arTaskStatusTmpAlt = array();
         $dbRes = CIBlockProperty::GetPropertyEnum("TaskStatus", array("SORT" => "ASC"), array("IBLOCK_ID" => $iblockId));
         while ($arRes = $dbRes->Fetch()) {
             $arTaskStatusTmp[StrToUpper($arRes["XML_ID"])] = $arRes["ID"];
             $arTaskStatusTmpAlt[$arRes["ID"]] = $arRes["XML_ID"];
         }
         $dbResult = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $iblockId, "INCLUDE_SUBSECTIONS" => "Y", "!PROPERTY_TASKVERSION" => 2), false, false, array("ID", "PROPERTY_TASKSTATUS", "PROPERTY_TASKASSIGNEDTO", "IBLOCK_SECTION_ID"));
         if ($arResult = $dbResult->Fetch()) {
             $arOldTasksWFs = array();
             $arOldTasksSTs = array();
             require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/intranet/classes/general/tasks_wf_template1.php";
             $arOldTasksWFsTmp = array();
             foreach ($arOldTasksWFs as $t1 => $t2) {
                 if (array_key_exists($t1, $arTaskStatusTmp)) {
                     $arOldTasksWFsTmp[$arTaskStatusTmp[$t1]] = $t2;
                 }
             }
             $arOldTasksSTsTmp = array();
             foreach ($arOldTasksSTs as $t1 => $t2) {
                 if (array_key_exists($t1, $arTaskStatusTmp)) {
                     $arOldTasksSTsTmp[$arTaskStatusTmp[$t1]] = $t2;
                 }
             }
             do {
                 $taskTypeTmp = "";
                 $ownerIdTmp = "";
                 $v = CIntranetTasks::PrepareSectionForPrint($arResult["IBLOCK_SECTION_ID"]);
                 foreach ($v as $k1 => $v1) {
                     $taskTypeTmp = $v1["XML_ID"] == "users_tasks" ? "user" : "group";
                     $ownerIdTmp = $taskTypeTmp == "user" ? $arResult["PROPERTY_TASKASSIGNEDTO_VALUE"] : $v1["XML_ID"];
                     break;
                 }
                 if ($taskTypeTmp == "group") {
                     $pathTemplate = str_replace(array("#GROUP_ID#", "#TASK_ID#"), array($ownerIdTmp, "{=Document:ID}"), COption::GetOptionString("intranet", "path_task_group_entry", "/workgroups/group/#GROUP_ID#/tasks/task/view/#TASK_ID#/"));
                 } else {
                     $pathTemplate = str_replace(array("#USER_ID#", "#TASK_ID#"), array($ownerIdTmp, "{=Document:ID}"), COption::GetOptionString("intranet", "path_task_user_entry", "/company/personal/user/#USER_ID#/tasks/task/view/#TASK_ID#/"));
                 }
                 $pathTemplate = str_replace('#HTTP_HOST#', $_SERVER['HTTP_HOST'], "http://#HTTP_HOST#" . $pathTemplate);
                 $workflowId = uniqid("", true);
                 if (array_key_exists($arResult["PROPERTY_TASKSTATUS_ENUM_ID"], $arOldTasksWFsTmp)) {
                     $v = $arOldTasksWFsTmp[$arResult["PROPERTY_TASKSTATUS_ENUM_ID"]];
                     $v = str_replace(array("#TPT_TASK_ID_LEN#", "#TPT_TASK_ID#", "#TPT_WORKFLOW_ID_LEN#", "#TPT_WORKFLOW_ID#", "#TPT_DOCUMENT_LEN1#", "#TPT_DOCUMENT_LEN2#", "#TPT_DOCUMENT_LEN3#", "#TPT_DOCUMENT_ROOT#", "#TPT_OWNER_ID#", "#TPT_TASK_TYPE_LEN#", "#TPT_TASK_TYPE#", "#TPT_PATH_TEMPLATE_LEN#", "#TPT_PATH_TEMPLATE#", "#TPT_FORUM_ID#", "#TPT_IBLOCKID_ID#"), array(strlen($arResult["ID"]), $arResult["ID"], strlen($workflowId), $workflowId, 25 + strlen($_SERVER["DOCUMENT_ROOT"]), 25 + strlen($_SERVER["DOCUMENT_ROOT"]), 34 + strlen($_SERVER["DOCUMENT_ROOT"]), $_SERVER["DOCUMENT_ROOT"], $ownerIdTmp, strlen($taskTypeTmp), $taskTypeTmp, strlen($pathTemplate), $pathTemplate, $forumId, $iblockId), $v);
                     CBPWorkflowPersister::__InsertWorkflowHack($workflowId, $v);
                 }
                 if (array_key_exists($arResult["PROPERTY_TASKSTATUS_ENUM_ID"], $arOldTasksSTsTmp)) {
                     CBPStateService::__InsertStateHack($workflowId, "intranet", "CIntranetTasksDocument", $arResult["ID"], $workflowTemplateId, $arOldTasksSTsTmp[$arResult["PROPERTY_TASKSTATUS_ENUM_ID"]]["STATE"], $arOldTasksSTsTmp[$arResult["PROPERTY_TASKSTATUS_ENUM_ID"]]["STATE_TITLE"], $arOldTasksSTsTmp[$arResult["PROPERTY_TASKSTATUS_ENUM_ID"]]["PARAMS"], $arOldTasksSTsTmp[$arResult["PROPERTY_TASKSTATUS_ENUM_ID"]]["PERMS"]);
                 } else {
                     CBPStateService::__InsertStateHack($workflowId, "intranet", "CIntranetTasksDocument", $arResult["ID"], $workflowTemplateId, $arOldTasksSTs["COMPLETED"]["STATE"], $arOldTasksSTs["COMPLETED"]["STATE_TITLE"], $arOldTasksSTs["COMPLETED"]["PARAMS"], $arOldTasksSTs["COMPLETED"]["PERMS"]);
                 }
                 CIBlockElement::SetPropertyValues($arResult["ID"], $iblockId, 2, "TASKVERSION");
             } while ($arResult = $dbResult->Fetch());
         }
         $arTasksConverted2BP[$keyTasksConverted2BP] = $globalParentSectionId;
         $CACHE_MANAGER->Clean("IntranetTasksConverted2BP");
         $CACHE_MANAGER->Read(2592000, "IntranetTasksConverted2BP");
         $CACHE_MANAGER->Set("IntranetTasksConverted2BP", $arTasksConverted2BP);
     }
     return $globalParentSectionId;
 }
Exemplo n.º 6
0
    function GetContent($arParams)
    {
        if (!CModule::IncludeModule('iblock')) {
            return false;
        }
        if ($_POST['library_resource_type'] != "folder") {
            //iblock
            $iblock_type = '';
            $iblock_id = 0;
            if ($_POST['library_IBLOCK_TYPE'] != '') {
                $res = CIBlockType::GetByID($_POST['library_IBLOCK_TYPE']);
                if ($res_arr = $res->Fetch()) {
                    $iblock_type = $res_arr["ID"];
                }
                if ($iblock_type != '') {
                    if ($_POST['library_NEW_IBLOCK'] == 'Y') {
                        //new iblock
                        $ib = new CIBlock();
                        $arFields = array("ACTIVE" => "Y", "VERSION" => 1, "LIST_PAGE_URL" => $arParams['path'], "DETAIL_PAGE_URL" => $arParams['path'] . 'element/view/#ID#/', "NAME" => $_POST['library_TITLE'], "IBLOCK_TYPE_ID" => $iblock_type, "LID" => array($arParams['site']), "SORT" => "500", "WORKFLOW" => "N", "BIZPROC" => "N", "SECTION_CHOOSER" => "L");
                        if (is_array($_POST['library_PERMISSION'])) {
                            $arPerm = array();
                            foreach ($_POST['library_PERMISSION'] as $grp => $perm) {
                                if ($perm == 'R' || $perm == 'U' || $perm == 'W') {
                                    $arPerm[$grp] = $perm;
                                }
                                if ($perm == 'U') {
                                    $arFields['BIZPROC'] = 'Y';
                                }
                            }
                            $arFields["GROUP_ID"] = $arPerm;
                        }
                        $iblock_id = $ib->Add($arFields);
                    } elseif (intval($_POST['library_IBLOCK_ID']) > 0) {
                        //existing iblock: need check permissions
                        if (CIBlock::GetPermission($_POST['library_IBLOCK_ID']) >= "X") {
                            $iblock_id = intval($_POST['library_IBLOCK_ID']);
                        }
                    }
                }
            }
            //forum for comments
            $forum_id = 0;
            if ($_POST['library_USE_COMMENTS'] == 'Y') {
                if ($_POST['library_NEW_FORUM'] == 'Y') {
                    CModule::IncludeModule('forum');
                    //new forum
                    $arFields = array("NAME" => GetMessage("library_wizard_forum_name") . " \"" . $_POST['library_TITLE'] . "\"", "SITES" => array($arParams['site'] => $arParams["path"] . "element/view/#PARAM2#/"), "ACTIVE" => "Y", "INDEXATION" => "N", "SORT" => 150, "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_TOPIC_TITLED" => "Y");
                    if (is_array($_POST['library_FORUM_PERMISSION'])) {
                        $arPerm = array();
                        foreach ($_POST['library_FORUM_PERMISSION'] as $grp => $perm) {
                            if ($perm == 'E' || $perm == 'M') {
                                $arPerm[$grp] = $perm;
                            }
                        }
                        $arFields["GROUP_ID"] = $arPerm;
                    }
                    $forum_id = CForumNew::Add($arFields);
                } elseif (intval($_POST['library_FORUM_ID']) > 0) {
                    $forum_id = intval($_POST['library_FORUM_ID']);
                }
            }
            //file size
            $iUploadMaxFilesize = intval(ini_get('upload_max_filesize'));
            $iPostMaxSize = intval(ini_get('post_max_size'));
            $iUploadMaxFilesize = min($iUploadMaxFilesize, $iPostMaxSize);
            //bizproc templates
            if ($_POST['library_NEW_IBLOCK'] == 'Y' && $iblock_id > 0 && CModule::IncludeModule("bizproc")) {
                $documentType = array("webdav", "CIBlockDocumentWebdav", "iblock_" . $iblock_id);
                if (!function_exists("__wd_replace_user_and_groups")) {
                    function __wd_replace_user_and_groups(&$val, $key, $params = array())
                    {
                        if ($key == "MailText") {
                            $val = str_replace("/company/personal/bizproc/{=Workflow:id}/", $params["path"], $val);
                        }
                        return true;
                    }
                }
                if ($handle = opendir($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/bizproc/templates')) {
                    $arr = array("path" => str_replace("//", "/", $arParams["path"] . "/webdav_bizproc_view/{=Document:ID}/"));
                    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;
                        array_walk_recursive($arFields["TEMPLATE"], "__wd_replace_user_and_groups", $arr);
                        if ($file == "status.php") {
                            $arFields["AUTO_EXECUTE"] = CBPDocumentEventType::Create;
                        }
                        if (is_array($arFields)) {
                            $arFields["DOCUMENT_TYPE"] = $documentType;
                            $arFields["SYSTEM_CODE"] = $file;
                            if (is_object($GLOBALS['USER'])) {
                                $arFields["USER_ID"] = $GLOBALS['USER']->GetID();
                            }
                            try {
                                CBPWorkflowTemplateLoader::Add($arFields);
                            } catch (Exception $e) {
                            }
                        }
                    }
                    closedir($handle);
                }
            }
            $s = '<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");?>
<?$APPLICATION->IncludeComponent("bitrix:webdav", ".default", array(
	"RESOURCE_TYPE" => "IBLOCK", 
	"IBLOCK_TYPE" => "' . EscapePHPString($iblock_type) . '",
	"IBLOCK_ID" => "' . intval($iblock_id) . '",
	"NAME_FILE_PROPERTY" => "FILE",
	"REPLACE_SYMBOLS" => "N",
	"USE_AUTH" => "Y",
	"UPLOAD_MAX_FILESIZE" => "' . $iUploadMaxFilesize . '",
	"UPLOAD_MAX_FILE" => "4",
	"SEF_MODE" => "Y",
	"SEF_FOLDER" => "' . EscapePHPString($arParams["path"]) . '",
	"AJAX_MODE" => "N",
	"AJAX_OPTION_SHADOW" => "Y",
	"AJAX_OPTION_JUMP" => "N",
	"AJAX_OPTION_STYLE" => "Y",
	"AJAX_OPTION_HISTORY" => "N",
	"CACHE_TYPE" => "A",
	"CACHE_TIME" => "3600",
	"COLUMNS" => array(
		0 => "NAME",
		1 => "TIMESTAMP_X",
		2 => "USER_NAME",
		3 => "FILE_SIZE",
		4 => "WF_STATUS_ID",
		5 => "",
	),
	"PAGE_ELEMENTS" => "50",
	"PAGE_NAVIGATION_TEMPLATE" => "",
	"STR_TITLE" => "' . EscapePHPString($_POST['library_TITLE']) . '",
	"SET_TITLE" => "Y",
	"DISPLAY_PANEL" => "N",
	"SHOW_TAGS" => "' . ($_POST['library_SHOW_TAGS'] == 'Y' ? 'Y' : 'N') . '",
	"TAGS_PAGE_ELEMENTS" => "' . (intval($_POST['library_TAGS_PAGE_ELEMENTS']) > 0 ? intval($_POST['library_TAGS_PAGE_ELEMENTS']) : 50) . '",
	"TAGS_PERIOD" => "",
	"TAGS_INHERIT" => "Y",
	"TAGS_FONT_MAX" => "30",
	"TAGS_FONT_MIN" => "14",
	"TAGS_COLOR_NEW" => "486DAA",
	"TAGS_COLOR_OLD" => "486DAA",
	"TAGS_SHOW_CHAIN" => "Y",
	"USE_COMMENTS" => "' . ($_POST['library_USE_COMMENTS'] == 'Y' ? 'Y' : 'N') . '",
	"FORUM_ID" => "' . intval($forum_id) . '",
	"PATH_TO_SMILE" => "/bitrix/images/forum/smile/",
	"USE_CAPTCHA" => "Y",
	"PREORDER" => "Y",
	"AJAX_OPTION_ADDITIONAL" => "",
	"SEF_URL_TEMPLATES" => array(
		"user_view" => "/company/personal/user/#USER_ID#/",
		"sections" => "#PATH#",
		"section_edit" => "folder/edit/#SECTION_ID#/#ACTION#/",
		"element" => "element/view/#ELEMENT_ID#/",
		"element_edit" => "element/edit/#ACTION#/#ELEMENT_ID#/",
		"element_history" => "element/history/#ELEMENT_ID#/",
		"element_history_get" => "element/historyget/#ELEMENT_ID#/#ELEMENT_NAME#",
		"element_upload" => "element/upload/#SECTION_ID#/",
		"help" => "help",
		"search" => "search/",
	)
	),
	false
);?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>';
            return $s;
        } else {
            $_REQUEST["library_FOLDER"] = strtolower(str_replace("//", "/", "/" . $_REQUEST["library_FOLDER"] . "/"));
            CheckDirPath($_SERVER['DOCUMENT_ROOT'] . $_REQUEST["library_FOLDER"], true);
            if (!empty($_REQUEST["library_FOLDER_PERMISSION"]) && is_array($_REQUEST["library_FOLDER_PERMISSION"])) {
                $GLOBALS["APPLICATION"]->SetFileAccessPermission($_REQUEST["library_FOLDER"], $_REQUEST["library_FOLDER_PERMISSION"]);
            }
            $s = '<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");?>
<?$APPLICATION->IncludeComponent("bitrix:webdav", ".default", array(
	"RESOURCE_TYPE" => "FOLDER",
	"FOLDER" => "' . EscapePHPString($_REQUEST["library_FOLDER"]) . '",
	"USE_AUTH" => "Y",
	"SEF_MODE" => "Y",
	"SEF_FOLDER" =>  "' . EscapePHPString($arParams["path"]) . '",
	"CACHE_TYPE" => "A",
	"CACHE_TIME" => "3600",
	"COLUMNS" => array(
		0 => "NAME",
		1 => "FILE_SIZE",
		2 => "TIMESTAMP_X",
		4 => "",
	),
	"SET_TITLE" => "Y"
	),
	false
);?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>';
            return $s;
        }
    }