public function Execute()
 {
     if (!CModule::IncludeModule("calendar")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $documentService = $this->workflow->GetService("DocumentService");
     $fromTs = CCalendar::Timestamp($this->CalendarFrom);
     $toTs = $this->CalendarTo == '' ? $fromTs : CCalendar::Timestamp($this->CalendarTo);
     $arFields = array("CAL_TYPE" => !$this->CalendarType ? 'user' : $this->CalendarType, "NAME" => trim($this->CalendarName) == '' ? GetMessage('EC_DEFAULT_EVENT_NAME') : $this->CalendarName, "DESCRIPTION" => $this->CalendarDesrc, "SKIP_TIME" => date('H:i', $fromTs) == '00:00' && date('H:i', $toTs) == '00:00', "IS_MEETING" => false, "RRULE" => false);
     if ($fromTs == $toTs && !$arFields["SKIP_TIME"]) {
         $toTs += 3600;
     }
     $arFields['DATE_FROM'] = CCalendar::Date($fromTs);
     $arFields['DATE_TO'] = CCalendar::Date($toTs);
     if ($this->CalendarSection && intVal($this->CalendarSection) > 0) {
         $arFields['SECTIONS'] = array(intVal($this->CalendarSection));
     }
     if ($this->CalendarOwnerId || $arFields["CAL_TYPE"] != "user" && $arFields["CAL_TYPE"] != "group") {
         $arFields["OWNER_ID"] = $this->CalendarOwnerId;
         $eventId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true));
     } else {
         $arCalendarUser = CBPHelper::ExtractUsers($this->CalendarUser, $documentId);
         foreach ($arCalendarUser as $calendarUser) {
             $arFields["CAL_TYPE"] = "user";
             $arFields["OWNER_ID"] = $calendarUser;
             $eventId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true));
         }
     }
     return CBPActivityExecutionStatus::Closed;
 }
 private function getSocnetRights($users)
 {
     $users = (array) $users;
     $result = array();
     $toExtract = array();
     foreach ($users as $user) {
         $user = (string) $user;
         if (strpos($user, 'user_') === 0) {
             $result[] = 'U' . substr($user, strlen('user_'));
         } elseif (strpos($user, 'group_') === 0) {
             $code = strtoupper(substr($user, strlen('group_')));
             if (preg_match('#^(DR[0-9]+|SG[0-9]+)$#', $code)) {
                 $result[] = $code;
             } elseif (preg_match('#^SG([0-9]+)_K$#', $code, $matches)) {
                 $result[] = 'SG' . $matches[1];
             } else {
                 $toExtract[] = $user;
             }
         } else {
             $toExtract[] = $user;
         }
     }
     if ($toExtract) {
         $extracted = CBPHelper::ExtractUsers($toExtract, $this->GetDocumentId());
         if (is_array($extracted)) {
             foreach ($extracted as $u) {
                 $result[] = 'U' . $u;
             }
         }
     }
     return array_unique($result);
 }
Example #3
0
 public function Execute()
 {
     if (!CModule::IncludeModule("socialnetwork")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $ownerId = CBPHelper::ExtractUsers($this->OwnerId, $documentId, true);
     $users = array_unique(CBPHelper::ExtractUsers($this->Users, $documentId, false));
     $dbSubjects = CSocNetGroupSubject::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("SITE_ID" => SITE_ID), false, false, array("ID"));
     $row = $dbSubjects->fetch();
     if (!$row) {
         $this->WriteToTrackingService(GetMessage("BPCWG_ERROR_SUBJECT_ID"));
         return CBPActivityExecutionStatus::Closed;
     }
     $subjectId = $row['ID'];
     unset($dbSubjects, $row);
     $options = array("SITE_ID" => SITE_ID, "NAME" => $this->GroupName, "VISIBLE" => "Y", "OPENED" => "N", "CLOSED" => "N", "SUBJECT_ID" => $subjectId, "INITIATE_PERMS" => SONET_ROLES_OWNER, "SPAM_PERMS" => SONET_ROLES_USER);
     $groupId = CSocNetGroup::CreateGroup($ownerId, $options);
     if (!$groupId) {
         $this->WriteToTrackingService(GetMessage("BPCWG_ERROR_CREATE_GROUP"));
         return CBPActivityExecutionStatus::Closed;
     }
     $this->GroupId = $groupId;
     foreach ($users as $user) {
         if ($user == $ownerId) {
             continue;
         }
         CSocNetUserToGroup::Add(array("USER_ID" => $user, "GROUP_ID" => $groupId, "ROLE" => SONET_ROLES_USER, "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "INITIATED_BY_TYPE" => SONET_INITIATED_BY_GROUP, "INITIATED_BY_USER_ID" => $ownerId, "MESSAGE" => false));
     }
     return CBPActivityExecutionStatus::Closed;
 }
Example #4
0
 public function Execute()
 {
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $historyService = $this->workflow->GetService("HistoryService");
     $documentService = $this->workflow->GetService("DocumentService");
     $userId = CBPHelper::ExtractUsers($this->UserId, $documentId, true);
     if ($userId == null || intval($userId) <= 0) {
         $userId = 1;
     }
     $historyIndex = $historyService->AddHistory(array("DOCUMENT_ID" => $documentId, "NAME" => "New", "DOCUMENT" => null, "USER_ID" => $userId));
     $arDocument = $documentService->GetDocumentForHistory($documentId, $historyIndex);
     if (!is_array($arDocument)) {
         return CBPActivityExecutionStatus::Closed;
     }
     $name = $this->Name;
     if ($name == null || strlen($name) <= 0) {
         if (array_key_exists("NAME", $arDocument) && is_string($arDocument["NAME"]) && strlen($arDocument["NAME"]) > 0) {
             $name = $arDocument["NAME"];
         } elseif (array_key_exists("TITLE", $arDocument) && is_string($arDocument["TITLE"]) && strlen($arDocument["TITLE"]) > 0) {
             $name = $arDocument["TITLE"];
         } else {
             $name = Date("Y-m-d H:i:s");
         }
     }
     $historyService->UpdateHistory($historyIndex, array("NAME" => $name, "DOCUMENT" => $arDocument));
     return CBPActivityExecutionStatus::Closed;
 }
Example #5
0
 public function Execute()
 {
     if (!CModule::IncludeModule("intranet")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $calendarIblockId = COption::GetOptionInt("intranet", 'iblock_calendar', 0);
     if ($calendarIblockId <= 0) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $arCalendarUser = CBPHelper::ExtractUsers($this->CalendarUser, $documentId);
     foreach ($arCalendarUser as $calendarUser) {
         $Params = array('iblockId' => $calendarIblockId, 'ownerType' => "USER", 'ownerId' => $calendarUser, 'cacheTime' => 0, 'pageUrl' => false, 'allowSuperpose' => false, 'allowResMeeting' => false, 'allowVideoMeeting' => false, 'userIblockId' => $calendarIblockId);
         $EC = new CEventCalendar();
         $EC->Init($Params);
         $sectionId = $EC->GetSectionIDByOwnerId($calendarUser, 'USER', $calendarIblockId);
         if ($sectionId <= 0) {
             $sectionId = CEventCalendar::CreateSectionForOwner($calendarUser, "USER", $calendarIblockId);
         }
         $arGuestCalendars = $EC->GetCalendars(array('sectionId' => $sectionId, 'iblockId' => $calendarIblockId, 'ownerType' => 'USER', 'ownerId' => $calendarUser, 'bOwner' => true, 'forExport' => true, 'bOnlyID' => true));
         $arParams = array('iblockId' => $calendarIblockId, 'ownerType' => "USER", 'ownerId' => $calendarUser, 'sectionId' => $sectionId, 'bNew' => true, 'name' => $this->CalendarName, 'desc' => $this->CalendarDesrc, 'dateFrom' => cutZeroTime($this->CalendarFrom), 'dateTo' => cutZeroTime($this->CalendarTo), 'isMeeting' => false, 'prop' => array('PERIOD_TYPE' => 'NONE', 'ACCESSIBILITY' => 'busy', 'IMPORTANCE' => 'normal', 'PRIVATE' => false), 'userId' => $calendarUser, 'userIblockId' => $calendarIblockId, 'location' => array('new' => '', 'change' => true));
         if (count($arGuestCalendars) > 0) {
             $arParams["calendarId"] = $arGuestCalendars[0];
         }
         $EC->SaveEvent($arParams);
     }
     if (isset($EC)) {
         $EC->ClearCache($EC->cachePath . 'events/' . $calendarIblockId . '/');
     }
     return CBPActivityExecutionStatus::Closed;
 }
 public function Execute()
 {
     if (!CModule::IncludeModule("intranet")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $absenceIblockId = COption::GetOptionInt("intranet", 'iblock_absence', 0);
     if ($absenceIblockId <= 0) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $documentService = $this->workflow->GetService("DocumentService");
     $arAbsenceUserTmp = $this->AbsenceUser;
     $arAbsenceUser = CBPHelper::ExtractUsers($arAbsenceUserTmp, $documentId, false);
     $arAbsenceTypes = array();
     $dbTypeRes = CIBlockPropertyEnum::GetList(array("SORT" => "ASC", "VALUE" => "ASC"), array('IBLOCK_ID' => $absenceIblockId, 'PROPERTY_ID' => 'ABSENCE_TYPE'));
     while ($arTypeValue = $dbTypeRes->GetNext()) {
         $arAbsenceTypes[$arTypeValue['XML_ID']] = $arTypeValue['ID'];
     }
     foreach ($arAbsenceUser as $absenceUser) {
         $arFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $absenceIblockId, 'ACTIVE_FROM' => $this->AbsenceFrom, 'ACTIVE_TO' => $this->AbsenceTo, "NAME" => $this->AbsenceName, "PREVIEW_TEXT" => $this->AbsenceDesrc, "PREVIEW_TEXT_TYPE" => "text", "PROPERTY_VALUES" => array("USER" => $absenceUser, "STATE" => $this->AbsenceState, "FINISH_STATE" => $this->AbsenceFinishState, "ABSENCE_TYPE" => $arAbsenceTypes[$this->AbsenceType]));
         $el = new CIBlockElement();
         $el->Add($arFields);
     }
     return CBPActivityExecutionStatus::Closed;
 }
 public function Execute()
 {
     if (!CModule::IncludeModule("forum")) {
         return CBPActivityExecutionStatus::Closed;
     }
     if (!CModule::IncludeModule("iblock")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $forumId = intval($this->ForumId);
     if ($forumId <= 0) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $iblockId = $this->IBlockId;
     $dbResult = CIBlockElement::GetProperty($iblockId, $documentId[2], false, false, array("CODE" => "FORUM_TOPIC_ID"));
     $arResult = $dbResult->Fetch();
     if (!$arResult) {
         $obProperty = new CIBlockProperty();
         $obProperty->Add(array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => "Forum topic", "CODE" => "FORUM_TOPIC_ID"));
         $obProperty->Add(array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => "Forum message count", "CODE" => "FORUM_MESSAGE_CNT"));
         $dbResult = CIBlockElement::GetProperty($iblockId, $documentId[2], false, false, array("CODE" => "FORUM_TOPIC_ID"));
         $arResult = $dbResult->Fetch();
     }
     $forumTopicId = intval($arResult["VALUE"]);
     $arForumUserTmp = $this->ForumUser;
     $arForumUser = CBPHelper::ExtractUsers($arForumUserTmp, $documentId, true);
     $forumUserId = 1;
     $forumUserName = "******";
     if ($arForumUser != null) {
         $forumUserId = $arForumUser;
         $dbResult = CUser::GetByID($forumUserId);
         if ($arResult = $dbResult->Fetch()) {
             $forumUserName = CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $arResult, true);
         }
     }
     $newTopic = "N";
     if ($forumTopicId <= 0) {
         $documentService = $this->workflow->GetService("DocumentService");
         $document = $documentService->GetDocument($documentId);
         $newTopic = "Y";
         $arFields = array("TITLE" => $document["NAME"], "FORUM_ID" => $forumId, "USER_START_ID" => $forumUserId, "USER_START_NAME" => $forumUserName, "LAST_POSTER_NAME" => $forumUserName, "APPROVED" => "Y");
         $forumTopicId = CForumTopic::Add($arFields);
         CIBlockElement::SetPropertyValues($documentId[2], $iblockId, $forumTopicId, "FORUM_TOPIC_ID");
     }
     $arFields = array("POST_MESSAGE" => $this->ForumPostMessage, "AUTHOR_ID" => $forumUserId, "AUTHOR_NAME" => $forumUserName, "FORUM_ID" => $forumId, "TOPIC_ID" => $forumTopicId, "APPROVED" => "Y", "NEW_TOPIC" => $newTopic, "PARAM2" => $documentId[2]);
     $forumMessageId = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
     return CBPActivityExecutionStatus::Closed;
 }
Example #8
0
 public function Execute()
 {
     if (!CModule::IncludeModule("intranet")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $iblockId = COption::GetOptionInt("intranet", "iblock_tasks", 0);
     if ($iblockId <= 0) {
         return CBPActivityExecutionStatus::Closed;
     }
     $parentSectionId = 0;
     $dbSectionsList = CIBlockSection::GetList(array(), array("GLOBAL_ACTIVE" => "Y", "XML_ID" => $this->TaskType == "group" ? $this->TaskOwnerId : "users_tasks", "IBLOCK_ID" => $iblockId, "SECTION_ID" => 0), false);
     if ($arSection = $dbSectionsList->GetNext()) {
         $parentSectionId = $arSection["ID"];
     }
     if ($parentSectionId <= 0) {
         $dbSectionsList = CIBlockSection::GetList(array(), array("GLOBAL_ACTIVE" => "Y", "XML_ID" => "users_tasks", "IBLOCK_ID" => $iblockId, "SECTION_ID" => 0), false);
         if ($arSection = $dbSectionsList->GetNext()) {
             $parentSectionId = $arSection["ID"];
         }
     }
     if ($parentSectionId <= 0) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $arTaskCreatedBy = CBPHelper::ExtractUsers($this->TaskCreatedBy, $documentId, true);
     $arTaskAssignedTo = CBPHelper::ExtractUsers($this->TaskAssignedTo, $documentId, true);
     if (!$arTaskCreatedBy || !$arTaskAssignedTo) {
         return CBPActivityExecutionStatus::Closed;
     }
     if ($this->TaskType != "group") {
         $this->TaskOwnerId = $arTaskAssignedTo;
     }
     $arTaskTrackers = CBPHelper::ExtractUsers($this->TaskTrackers, $documentId);
     $arFields = array("IBLOCK_SECTION_ID" => $parentSectionId, "MODIFIED_BY" => $arTaskCreatedBy, "CREATED_BY" => $arTaskCreatedBy, "DATE_CREATE" => date($GLOBALS["DB"]->DateFormatToPHP(FORMAT_DATETIME)), "ACTIVE_FROM" => $this->TaskActiveFrom, "ACTIVE_TO" => $this->TaskActiveTo, "NAME" => $this->TaskName, "DETAIL_TEXT" => $this->TaskDetailText, "PROPERTY_TaskPriority" => $this->TaskPriority, "PROPERTY_TaskAssignedTo" => $arTaskAssignedTo, "PROPERTY_TaskTrackers" => $arTaskTrackers);
     $taskId = CIntranetTasksDocument::CreateDocument($arFields);
     if ($this->TaskType == "group") {
         $pathTemplate = str_replace(array("#GROUP_ID#", "#TASK_ID#"), array($this->TaskOwnerId, "{=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($this->TaskOwnerId, "{=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);
     $arTemplateStates = CBPWorkflowTemplateLoader::GetDocumentTypeStates(array("intranet", "CIntranetTasksDocument", "x" . $iblockId), CBPDocumentEventType::Create);
     foreach ($arTemplateStates as $arState) {
         CBPDocument::StartWorkflow($arState["TEMPLATE_ID"], array("intranet", "CIntranetTasksDocument", $taskId), array("OwnerId" => $this->TaskOwnerId, "TaskType" => $this->TaskType, "PathTemplate" => $pathTemplate, "ForumId" => intval($this->TaskForumId), "IBlockId" => $iblockId), $arErrorsTmp);
     }
     return CBPActivityExecutionStatus::Closed;
 }
Example #9
0
 private function GetUsersList($arUsersList, $bSkipAbsent = true)
 {
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     if (!CModule::IncludeModule("intranet")) {
         $bSkipAbsent = false;
     }
     $arUsers = CBPHelper::ExtractUsers($arUsersList, $documentId, false);
     if ($bSkipAbsent) {
         $arKeys = array_keys($arUsers);
         foreach ($arKeys as $key) {
             if (CIntranetUtils::IsUserAbsent($arUsers[$key])) {
                 unset($arUsers[$key]);
             }
         }
     }
     return $arUsers;
 }
 public function Execute()
 {
     if (!CModule::IncludeModule("socialnetwork")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $arMessageUserFrom = CBPHelper::ExtractUsers($this->MessageUserFrom, $documentId, true);
     $arMessageUserTo = CBPHelper::ExtractUsers($this->MessageUserTo, $documentId, false);
     $arMessageFields = array("=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM, "FROM_USER_ID" => $arMessageUserFrom, "MESSAGE" => CBPHelper::ConvertTextForMail($this->MessageText));
     $ar = array();
     foreach ($arMessageUserTo as $userTo) {
         if (in_array($userTo, $ar)) {
             continue;
         }
         $ar[] = $userTo;
         $arMessageFields["TO_USER_ID"] = $userTo;
         CSocNetMessages::Add($arMessageFields);
     }
     return CBPActivityExecutionStatus::Closed;
 }
Example #11
0
 public function Execute()
 {
     if (!CModule::IncludeModule("im")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $arMessageUserFrom = CBPHelper::ExtractUsers($this->MessageUserFrom, $documentId, true);
     $arMessageUserTo = CBPHelper::ExtractUsers($this->MessageUserTo, $documentId, false);
     $arMessageFields = array("FROM_USER_ID" => $arMessageUserFrom, "NOTIFY_TYPE" => intval($this->MessageType), "NOTIFY_MESSAGE" => $this->MessageSite, "NOTIFY_MESSAGE_OUT" => $this->MessageOut, "NOTIFY_MODULE" => "bizproc", "NOTIFY_EVENT" => "activity");
     $ar = array();
     foreach ($arMessageUserTo as $userTo) {
         if (in_array($userTo, $ar)) {
             continue;
         }
         $ar[] = $userTo;
         $arMessageFields["TO_USER_ID"] = $userTo;
         CIMNotify::Add($arMessageFields);
     }
     return CBPActivityExecutionStatus::Closed;
 }
Example #12
0
 public function Execute()
 {
     $activityData = $this->getRestActivityData();
     if (!$activityData) {
         throw new Exception(Loc::getMessage('BPRA_NOT_FOUND_ERROR'));
     }
     if (!Loader::includeModule('rest')) {
         return CBPActivityExecutionStatus::Closed;
     }
     $propertiesData = array();
     if (!empty($activityData['PROPERTIES'])) {
         foreach ($activityData['PROPERTIES'] as $name => $property) {
             $propertiesData[$name] = $this->{$name};
         }
     }
     $auth = null;
     $userId = CBPHelper::ExtractUsers($this->AuthUserId, $this->GetDocumentId(), true);
     if ($userId > 0) {
         $auth = CRestUtil::getAuthForEvent($activityData['APP_ID'], $userId, array('WORKFLOW_ID' => $this->getWorkflowInstanceId(), 'ACTIVITY_NAME' => $this->name, 'CODE' => $activityData['CODE']));
     }
     $this->eventId = \Bitrix\Main\Security\Random::getString(32, true);
     $queryItems = array(Sqs::queryItem($activityData['HANDLER'], array('workflow_id' => $this->getWorkflowInstanceId(), 'code' => $activityData['CODE'], 'document_id' => $this->GetDocumentId(), 'event_token' => self::generateToken($this->getWorkflowInstanceId(), $this->name, $this->eventId), 'properties' => $propertiesData, 'auth' => $auth, 'ts' => time())));
     Sqs::query($queryItems);
     if ($this->SetStatusMessage == 'Y') {
         $message = $this->StatusMessage;
         if (empty($message)) {
             $message = Loc::getMessage('BPRA_DEFAULT_STATUS_MESSAGE');
         }
         $this->SetStatusTitle($message);
     }
     if ($this->UseSubscription != 'Y') {
         return CBPActivityExecutionStatus::Closed;
     }
     $this->Subscribe($this);
     return CBPActivityExecutionStatus::Executing;
 }
Example #13
0
 public function OnExternalEvent($arEventParameters = array())
 {
     if ($this->executionStatus == CBPActivityExecutionStatus::Closed) {
         return;
     }
     $timeoutDuration = $this->CalculateTimeoutDuration();
     if ($timeoutDuration > 0) {
         if (array_key_exists("SchedulerService", $arEventParameters) && $arEventParameters["SchedulerService"] == "OnAgent") {
             $this->IsTimeout = 1;
             $this->taskStatus = CBPTaskStatus::Timeout;
             $this->Unsubscribe($this);
             $this->workflow->CloseActivity($this);
             return;
         }
     }
     if (!array_key_exists("USER_ID", $arEventParameters) || intval($arEventParameters["USER_ID"]) <= 0) {
         return;
     }
     if (empty($arEventParameters["REAL_USER_ID"])) {
         $arEventParameters["REAL_USER_ID"] = $arEventParameters["USER_ID"];
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $arUsers = CBPHelper::ExtractUsers($this->Users, $documentId, false);
     $arEventParameters["USER_ID"] = intval($arEventParameters["USER_ID"]);
     $arEventParameters["REAL_USER_ID"] = intval($arEventParameters["REAL_USER_ID"]);
     if (!in_array($arEventParameters["USER_ID"], $arUsers)) {
         return;
     }
     if ($this->IsPropertyExists("LastReviewer")) {
         $this->LastReviewer = "user_" . $arEventParameters["REAL_USER_ID"];
     }
     $taskService = $this->workflow->GetService("TaskService");
     $taskService->MarkCompleted($this->taskId, $arEventParameters["REAL_USER_ID"], CBPTaskUserStatus::Ok);
     $dbUser = CUser::GetById($arEventParameters["REAL_USER_ID"]);
     if ($arUser = $dbUser->Fetch()) {
         $this->Comments = $this->Comments . CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $arUser) . " (" . $arUser["LOGIN"] . ")" . (strlen($arEventParameters["COMMENT"]) > 0 ? ": " : "") . $arEventParameters["COMMENT"] . "\n";
     }
     $this->WriteToTrackingService(str_replace(array("#PERSON#", "#COMMENT#"), array("{=user:user_" . $arEventParameters["REAL_USER_ID"] . "}", strlen($arEventParameters["COMMENT"]) > 0 ? ": " . $arEventParameters["COMMENT"] : ""), GetMessage("BPAR_ACT_REVIEW_TRACK")), $arEventParameters["REAL_USER_ID"]);
     $result = "Continue";
     $this->arReviewOriginalResults[] = $arEventParameters["USER_ID"];
     $this->arReviewResults[] = $arEventParameters["REAL_USER_ID"];
     $this->ReviewedCount = count($this->arReviewResults);
     if ($this->IsPropertyExists("ApproveType") && $this->ApproveType == "any") {
         $result = "Finish";
     } else {
         $allAproved = true;
         foreach ($arUsers as $userId) {
             if (!in_array($userId, $this->arReviewOriginalResults)) {
                 $allAproved = false;
             }
         }
         if ($allAproved) {
             $result = "Finish";
         }
     }
     if (!$this->IsPropertyExists("SetStatusMessage") || $this->SetStatusMessage == "Y") {
         $messageTemplate = $this->IsPropertyExists("StatusMessage") && strlen($this->StatusMessage) > 0 ? $this->StatusMessage : GetMessage("BPAR_ACT_INFO");
         $votedPercent = intval($this->ReviewedCount / $this->TotalCount * 100);
         $votedCount = $this->ReviewedCount;
         $totalCount = $this->TotalCount;
         $reviewers = "";
         if (strpos($messageTemplate, "#REVIEWERS#") !== false) {
             $reviewers = $this->GetReviewersNames();
         }
         if ($reviewers == "") {
             $reviewers = GetMessage("BPAA_ACT_APPROVERS_NONE");
         }
         $this->SetStatusTitle(str_replace(array("#PERC#", "#PERCENT#", "#REV#", "#REVIEWED#", "#TOT#", "#TOTAL#", "#REVIEWERS#"), array($votedPercent, $votedPercent, $votedCount, $votedCount, $totalCount, $totalCount, $reviewers), $messageTemplate));
     }
     if ($result != "Continue") {
         $this->WriteToTrackingService(GetMessage("BPAR_ACT_REVIEWED"));
         $this->taskStatus = CBPTaskStatus::CompleteOk;
         $this->Unsubscribe($this);
         $this->workflow->CloseActivity($this);
     }
 }
Example #14
0
 public function Execute()
 {
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $documentService = $this->workflow->GetService("DocumentService");
     $strMailUserFrom = "";
     list($mailUserFromArray, $mailUserFromArrayString) = static::ExtractEmails($this->MailUserFromArray);
     $arMailUserFromArray = CBPHelper::ExtractUsers($mailUserFromArray, $documentId, false);
     foreach ($arMailUserFromArray as $user) {
         $dbUser = CUser::GetList($b = "", $o = "", array("ID_EQUAL_EXACT" => $user));
         if ($arUser = $dbUser->Fetch()) {
             if (strlen($strMailUserFrom) > 0) {
                 $strMailUserFrom .= ", ";
             }
             if (!defined("BX_MS_SMTP") || BX_MS_SMTP !== true) {
                 if (strlen($arUser["NAME"]) > 0 || strlen($arUser["LAST_NAME"]) > 0) {
                     $strMailUserFrom .= "'" . preg_replace("#['\r\n]+#", "", CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $arUser)) . "' <";
                 }
             }
             $strMailUserFrom .= preg_replace("#[\r\n]+#", "", $arUser["EMAIL"]);
             if (!defined("BX_MS_SMTP") || BX_MS_SMTP !== true) {
                 if (strlen($arUser["NAME"]) > 0 || strlen($arUser["LAST_NAME"]) > 0) {
                     $strMailUserFrom .= ">";
                 }
             }
         }
     }
     $mailUserFromTmp = $this->MailUserFrom;
     if (strlen($mailUserFromTmp) > 0) {
         if (strlen($strMailUserFrom) > 0) {
             $strMailUserFrom .= ", ";
         }
         $strMailUserFrom .= preg_replace("#[\r\n]+#", "", $mailUserFromTmp);
     }
     if (!empty($mailUserFromArrayString)) {
         foreach ($mailUserFromArrayString as $s) {
             if (strlen($strMailUserFrom) > 0) {
                 $strMailUserFrom .= ", ";
             }
             $strMailUserFrom .= $s;
         }
     }
     $strMailUserTo = "";
     list($MailUserToArray, $MailUserToArrayString) = static::ExtractEmails($this->MailUserToArray);
     $arMailUserToArray = CBPHelper::ExtractUsers($MailUserToArray, $documentId, false);
     foreach ($arMailUserToArray as $user) {
         $dbUser = CUser::GetList($b = "", $o = "", array("ID_EQUAL_EXACT" => $user));
         if ($arUser = $dbUser->Fetch()) {
             if (strlen($strMailUserTo) > 0) {
                 $strMailUserTo .= ", ";
             }
             $strMailUserTo .= preg_replace("#[\r\n]+#", "", $arUser["EMAIL"]);
         }
     }
     $mailUserToTmp = $this->MailUserTo;
     if (strlen($mailUserToTmp) > 0) {
         if (strlen($strMailUserTo) > 0) {
             $strMailUserTo .= ", ";
         }
         $strMailUserTo .= preg_replace("#[\r\n]+#", "", $mailUserToTmp);
     }
     if (!empty($MailUserToArrayString)) {
         foreach ($MailUserToArrayString as $s) {
             if (strlen($strMailUserTo) > 0) {
                 $strMailUserTo .= ", ";
             }
             $strMailUserTo .= $s;
         }
     }
     $charset = $this->MailCharset;
     if (!$this->IsPropertyExists("DirrectMail") || $this->DirrectMail == "Y") {
         global $APPLICATION;
         $strMailUserFrom = $APPLICATION->ConvertCharset($strMailUserFrom, SITE_CHARSET, $charset);
         $strMailUserFrom = CBPMailActivity::EncodeHeaderFrom($strMailUserFrom, $charset);
         $strMailUserTo = $APPLICATION->ConvertCharset($strMailUserTo, SITE_CHARSET, $charset);
         $strMailUserTo = CBPMailActivity::EncodeMimeString($strMailUserTo, $charset);
         $mailSubject = $APPLICATION->ConvertCharset($this->MailSubject, SITE_CHARSET, $charset);
         $mailSubject = CBPMailActivity::EncodeSubject($mailSubject, $charset);
         $mailText = $APPLICATION->ConvertCharset(CBPHelper::ConvertTextForMail($this->MailText), SITE_CHARSET, $charset);
         $eol = CAllEvent::GetMailEOL();
         mail($strMailUserTo, $mailSubject, $mailText, "From: " . $strMailUserFrom . $eol . "Reply-To: " . $strMailUserFrom . $eol . "X-Priority: 3 (Normal)" . $eol . "Content-Type: text/" . ($this->MailMessageType == "html" ? "html" : "plain") . "; charset=" . $charset . $eol . "X-Mailer: PHP/" . phpversion());
     } else {
         $siteId = null;
         if ($this->IsPropertyExists("MailSite")) {
             $siteId = $this->MailSite;
         }
         if (strlen($siteId) <= 0) {
             $siteId = SITE_ID;
         }
         $arFields = array("SENDER" => $strMailUserFrom, "RECEIVER" => $strMailUserTo, "TITLE" => $this->MailSubject, "MESSAGE" => CBPHelper::ConvertTextForMail($this->MailText));
         $event = new CEvent();
         $event->Send("BIZPROC_MAIL_TEMPLATE", $siteId, $arFields, "N");
     }
     return CBPActivityExecutionStatus::Closed;
 }
 public function OnExternalEvent($arEventParameters = array())
 {
     if ($this->executionStatus == CBPActivityExecutionStatus::Closed) {
         return;
     }
     $timeoutDuration = $this->CalculateTimeoutDuration();
     if ($timeoutDuration > 0) {
         if (array_key_exists("SchedulerService", $arEventParameters) && $arEventParameters["SchedulerService"] == "OnAgent") {
             $this->IsTimeout = 1;
             $this->taskStatus = CBPTaskStatus::Timeout;
             $this->Unsubscribe($this);
             $this->workflow->CloseActivity($this);
             return;
         }
     }
     if (!array_key_exists("USER_ID", $arEventParameters) || intval($arEventParameters["USER_ID"]) <= 0) {
         return;
     }
     if (empty($arEventParameters["REAL_USER_ID"])) {
         $arEventParameters["REAL_USER_ID"] = $arEventParameters["USER_ID"];
     }
     $rootActivity = $this->GetRootActivity();
     $arUsers = $this->taskUsers;
     if (empty($arUsers)) {
         //compatibility
         $arUsers = CBPHelper::ExtractUsers($this->Users, $this->GetDocumentId(), false);
     }
     $arEventParameters["USER_ID"] = intval($arEventParameters["USER_ID"]);
     $arEventParameters["REAL_USER_ID"] = intval($arEventParameters["REAL_USER_ID"]);
     if (!in_array($arEventParameters["USER_ID"], $arUsers)) {
         return;
     }
     $taskService = $this->workflow->GetService("TaskService");
     $taskService->MarkCompleted($this->taskId, $arEventParameters["REAL_USER_ID"], CBPTaskUserStatus::Ok);
     $this->Comments = $arEventParameters["COMMENT"];
     if ($this->IsPropertyExists("InfoUser")) {
         $this->InfoUser = "******" . $arEventParameters["REAL_USER_ID"];
     }
     $this->WriteToTrackingService(str_replace(array("#PERSON#", "#COMMENT#"), array("{=user:user_" . $arEventParameters["REAL_USER_ID"] . "}", strlen($arEventParameters["COMMENT"]) > 0 ? ": " . $arEventParameters["COMMENT"] : ""), GetMessage("BPRIA_ACT_APPROVE_TRACK")), $arEventParameters["REAL_USER_ID"]);
     $this->ResponcedInformation = $arEventParameters["RESPONCE"];
     //$rootActivity->SetVariablesTypes($arEventParameters["RESPONCE_TYPES"]);
     $rootActivity->SetVariables($arEventParameters["RESPONCE"]);
     $this->taskStatus = CBPTaskStatus::CompleteOk;
     $this->Unsubscribe($this);
     //$this->SetStatusTitle();
     $this->workflow->CloseActivity($this);
 }
 public function OnExternalEvent($arEventParameters = array())
 {
     if ($this->executionStatus == CBPActivityExecutionStatus::Closed) {
         return;
     }
     $timeoutDuration = $this->CalculateTimeoutDuration();
     if ($timeoutDuration > 0) {
         if (array_key_exists("SchedulerService", $arEventParameters) && $arEventParameters["SchedulerService"] == "OnAgent") {
             $this->IsTimeout = 1;
             $this->Unsubscribe($this);
             $this->ExecuteOnNonApprove();
             return;
         }
     }
     if (!array_key_exists("USER_ID", $arEventParameters) || intval($arEventParameters["USER_ID"]) <= 0) {
         return;
     }
     if (!array_key_exists("APPROVE", $arEventParameters)) {
         return;
     }
     $approve = $arEventParameters["APPROVE"] ? true : false;
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $arUsersTmp = $this->Users;
     $arUsers = CBPHelper::ExtractUsers($arUsersTmp, $documentId, false);
     $arEventParameters["USER_ID"] = intval($arEventParameters["USER_ID"]);
     if (!in_array($arEventParameters["USER_ID"], $arUsers)) {
         return;
     }
     if ($this->IsPropertyExists("LastApprover")) {
         $this->LastApprover = "user_" . $arEventParameters["USER_ID"];
     }
     $taskService = $this->workflow->GetService("TaskService");
     $taskService->MarkCompleted($this->taskId, $arEventParameters["USER_ID"]);
     $dbUser = CUser::GetById($arEventParameters["USER_ID"]);
     if ($arUser = $dbUser->Fetch()) {
         $this->Comments = $this->Comments . CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $arUser) . " (" . $arUser["LOGIN"] . "): " . ($approve ? GetMessage("BPAA_LOG_Y") : GetMessage("BPAA_LOG_N")) . "\n" . (strlen($arEventParameters["COMMENT"]) > 0 ? GetMessage("BPAA_LOG_COMMENTS") . ": " . $arEventParameters["COMMENT"] : "") . "\n";
     }
     if ($approve) {
         $this->WriteToTrackingService(str_replace(array("#PERSON#", "#COMMENT#"), array("{=user:user_" . $arEventParameters["USER_ID"] . "}", strlen($arEventParameters["COMMENT"]) > 0 ? ": " . $arEventParameters["COMMENT"] : ""), GetMessage("BPAA_ACT_APPROVE_TRACK")), $arEventParameters["USER_ID"]);
     } else {
         $this->WriteToTrackingService(str_replace(array("#PERSON#", "#COMMENT#"), array("{=user:user_" . $arEventParameters["USER_ID"] . "}", strlen($arEventParameters["COMMENT"]) > 0 ? ": " . $arEventParameters["COMMENT"] : ""), GetMessage("BPAA_ACT_NONAPPROVE_TRACK")), $arEventParameters["USER_ID"]);
     }
     $result = "Continue";
     $this->arApproveResults[$arEventParameters["USER_ID"]] = $approve;
     if ($approve) {
         $this->ApprovedCount = $this->ApprovedCount + 1;
     } else {
         $this->NotApprovedCount = $this->NotApprovedCount + 1;
     }
     $this->VotedCount = count($this->arApproveResults);
     $this->VotedPercent = intval($this->VotedCount / $this->TotalCount * 100);
     $this->ApprovedPercent = intval($this->ApprovedCount / $this->TotalCount * 100);
     $this->NotApprovedPercent = intval($this->NotApprovedCount / $this->TotalCount * 100);
     if ($this->ApproveType == "any") {
         $result = $approve ? "Approve" : "NonApprove";
     } elseif ($this->ApproveType == "all" || $this->ApproveType == "vote" && $this->ApproveMinPercent >= 100) {
         if (!$approve) {
             $result = "NonApprove";
         } else {
             $allAproved = true;
             foreach ($arUsers as $userId) {
                 if (!isset($this->arApproveResults[$userId])) {
                     // && $this->arApproveResults[$userId]!==true
                     $allAproved = false;
                 }
             }
             if ($allAproved) {
                 $result = "Approve";
             }
         }
     } elseif ($this->ApproveType == "vote") {
         if ($this->ApproveWaitForAll == "Y") {
             if ($this->VotedPercent == 100) {
                 if ($this->ApprovedPercent > $this->ApproveMinPercent) {
                     $result = "Approve";
                 } else {
                     $result = "NonApprove";
                 }
             }
         } else {
             if ($this->ApprovedPercent > $this->ApproveMinPercent) {
                 $result = "Approve";
             } elseif (($this->VotedCount - $this->ApprovedCount) / $this->TotalCount * 100 >= 100 - $this->ApproveMinPercent) {
                 $result = "NonApprove";
             }
         }
     }
     $approvers = "";
     $rejecters = "";
     if (!$this->IsPropertyExists("SetStatusMessage") || $this->SetStatusMessage == "Y") {
         $messageTemplate = $this->IsPropertyExists("StatusMessage") && strlen($this->StatusMessage) > 0 ? $this->StatusMessage : GetMessage("BPAA_ACT_INFO");
         $votedPercent = $this->VotedPercent;
         $votedCount = $this->VotedCount;
         $totalCount = $this->TotalCount;
         if (strpos($messageTemplate, "#REJECTERS#") !== false) {
             $rejecters = $this->GetApproversNames(false);
         }
         if (strpos($messageTemplate, "#APPROVERS#") !== false) {
             $approvers = $this->GetApproversNames(true);
         }
         if ($approvers == "") {
             $approvers = GetMessage("BPAA_ACT_APPROVERS_NONE");
         }
         if ($rejecters == "") {
             $rejecters = GetMessage("BPAA_ACT_APPROVERS_NONE");
         }
         $this->SetStatusTitle(str_replace(array("#PERC#", "#PERCENT#", "#REV#", "#VOTED#", "#TOT#", "#TOTAL#", "#APPROVERS#", "#REJECTERS#"), array($votedPercent, $votedPercent, $votedCount, $votedCount, $totalCount, $totalCount, $approvers, $rejecters), $messageTemplate));
     }
     if ($result != "Continue") {
         $this->Unsubscribe($this);
         if ($rejecters == "") {
             $this->Rejecters = $this->GetApproversNames(false);
         } else {
             $this->Rejecters = $rejecters;
         }
         if ($approvers == "") {
             $this->Approvers = $this->GetApproversNames(true);
         } else {
             $this->Approvers = $approvers;
         }
         if ($result == "Approve") {
             $this->ExecuteOnApprove();
         } else {
             $this->ExecuteOnNonApprove();
         }
     }
 }
Example #17
0
 public function Execute()
 {
     if (!CModule::IncludeModule('crm')) {
         CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $documentService = $this->workflow->GetService("DocumentService");
     $strMailUserFrom = "";
     $arMailUserFromArray = CBPHelper::ExtractUsers($this->MailUserFromArray, $documentId, false);
     foreach ($arMailUserFromArray as $user) {
         $dbUser = CUser::GetList($b = "", $o = "", array("ID_EQUAL_EXACT" => $user));
         if ($arUser = $dbUser->Fetch()) {
             if (strlen($strMailUserFrom) > 0) {
                 $strMailUserFrom .= ", ";
             }
             if (!defined("BX_MS_SMTP") || BX_MS_SMTP !== true) {
                 if (strlen($arUser["NAME"]) > 0 || strlen($arUser["LAST_NAME"]) > 0) {
                     $strMailUserFrom .= "'" . preg_replace("#['\r\n]+#", "", CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $arUser)) . "' <";
                 }
             }
             $strMailUserFrom .= preg_replace("#[\r\n]+#", "", $arUser["EMAIL"]);
             if (!defined("BX_MS_SMTP") || BX_MS_SMTP !== true) {
                 if (strlen($arUser["NAME"]) > 0 || strlen($arUser["LAST_NAME"]) > 0) {
                     $strMailUserFrom .= ">";
                 }
             }
         }
     }
     $mailUserFromTmp = $this->MailUserFrom;
     if (strlen($mailUserFromTmp) > 0) {
         if (strlen($strMailUserFrom) > 0) {
             $strMailUserFrom .= ", ";
         }
         $strMailUserFrom .= preg_replace("#[\r\n]+#", "", $mailUserFromTmp);
     }
     $strMailTo = '';
     if (is_array($this->MailCrmEntityToArray)) {
         $addressType = $this->MailCrmEntityAddressType !== '' ? $this->MailCrmEntityAddressType : 'WORK';
         foreach ($this->MailCrmEntityToArray as &$entityData) {
             $s = '';
             if (is_string($entityData)) {
                 $s = trim($entityData);
             } elseif (is_array($entityData) && isset($entityData['VALUE'])) {
                 $s = trim($entityData['VALUE']);
             }
             if ($s === '') {
                 continue;
             }
             $entityInfo = array();
             if (CCrmEntityHelper::ParseEntityKey($s, $entityInfo)) {
                 //Process entity key
                 $dbResult = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityInfo['ENTITY_TYPE_NAME'], 'ELEMENT_ID' => $entityInfo['ENTITY_ID'], 'TYPE_ID' => 'EMAIL', 'VALUE_TYPE' => $addressType));
                 if ($dbResult) {
                     while ($arField = $dbResult->Fetch()) {
                         $v = isset($arField['VALUE']) ? trim($arField['VALUE']) : '';
                         if ($v === '' || !check_email($v)) {
                             continue;
                         }
                         if ($strMailTo !== '') {
                             $strMailTo .= ', ';
                         }
                         $strMailTo .= preg_replace("#[\r\n]+#", "", $v);
                         break;
                     }
                 }
             } else {
                 $ary = explode(',', $s);
                 foreach ($ary as &$v) {
                     $v = trim($v);
                     if ($v === '' || !check_email($v)) {
                         continue;
                     }
                     if ($strMailTo !== '') {
                         $strMailTo .= ', ';
                     }
                     $strMailTo .= preg_replace("#[\r\n]+#", "", $v);
                 }
                 unset($v);
             }
         }
         unset($entityData);
     }
     $strReplyTo = $strMailUserFrom;
     $strCrmEmail = CCrmMailHelper::ExtractEmail(COption::GetOptionString('crm', 'mail', ''));
     if ($strCrmEmail !== '') {
         $strReplyTo .= ', ' . $strCrmEmail;
     }
     $charset = $this->MailCharset;
     if (!$this->IsPropertyExists("DirrectMail") || $this->DirrectMail == "Y") {
         global $APPLICATION;
         $strMailUserFrom = $APPLICATION->ConvertCharset($strMailUserFrom, SITE_CHARSET, $charset);
         $strMailUserFrom = self::EncodeHeaderFrom($strMailUserFrom, $charset);
         $strReplyTo = $APPLICATION->ConvertCharset($strReplyTo, SITE_CHARSET, $charset);
         $strReplyTo = self::EncodeHeaderFrom($strReplyTo, $charset);
         $strMailTo = $APPLICATION->ConvertCharset($strMailTo, SITE_CHARSET, $charset);
         $strMailTo = self::EncodeMimeString($strMailTo, $charset);
         $mailSubject = $APPLICATION->ConvertCharset($this->MailSubject, SITE_CHARSET, $charset);
         $mailSubject = self::EncodeSubject($mailSubject, $charset);
         $mailText = $APPLICATION->ConvertCharset(CBPHelper::ConvertTextForMail($this->MailText), SITE_CHARSET, $charset);
         $eol = CAllEvent::GetMailEOL();
         mail($strMailTo, $mailSubject, $mailText, "From: " . $strMailUserFrom . $eol . "Reply-To: " . $strReplyTo . $eol . "X-Priority: 3 (Normal)" . $eol . "Content-Type: text/" . ($this->MailMessageType == "html" ? "html" : "plain") . "; charset=" . $charset . $eol . "X-Mailer: PHP/" . phpversion());
     } else {
         $siteId = null;
         if ($this->IsPropertyExists("MailSite")) {
             $siteId = $this->MailSite;
         }
         if (strlen($siteId) <= 0) {
             $siteId = SITE_ID;
         }
         $arFields = array("SENDER" => $strMailUserFrom, "RECEIVER" => $strMailTo, "REPLY_TO" => $strReplyTo, "TITLE" => $this->MailSubject, "MESSAGE" => CBPHelper::ConvertTextForMail($this->MailText));
         $event = new CEvent();
         $event->Send("BIZPROC_MAIL_TEMPLATE", $siteId, $arFields, "N");
     }
     return CBPActivityExecutionStatus::Closed;
 }
Example #18
0
 public function Execute()
 {
     if (!CModule::IncludeModule("tasks")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $arFields = $this->Fields;
     $arFields["CREATED_BY"] = CBPHelper::ExtractUsers($this->Fields["CREATED_BY"], $documentId, true);
     $arFields["RESPONSIBLE_ID"] = CBPHelper::ExtractUsers($this->Fields["RESPONSIBLE_ID"], $documentId, true);
     $arFields["ACCOMPLICES"] = CBPHelper::ExtractUsers($this->Fields["ACCOMPLICES"], $documentId);
     $arFields["AUDITORS"] = CBPHelper::ExtractUsers($this->Fields["AUDITORS"], $documentId);
     if (isset($this->Fields['DESCRIPTION'])) {
         $arFields['DESCRIPTION'] = preg_replace('/\\[url=(.*)\\](.*)\\[\\/url\\]/i' . BX_UTF_PCRE_MODIFIER, '<a href="${1}">${2}</a>', $this->Fields['DESCRIPTION']);
     }
     if (!$arFields["SITE_ID"]) {
         $arFields["SITE_ID"] = SITE_ID;
     }
     if ($this->AUTO_LINK_TO_CRM_ENTITY && CModule::IncludeModule('crm')) {
         $rootActivity = $this->GetRootActivity();
         $documentId = $rootActivity->GetDocumentId();
         $documentType = $rootActivity->GetDocumentType();
         $letter = CCrmOwnerTypeAbbr::ResolveByTypeID(CCrmOwnerType::ResolveID($documentType[2]));
         $arFields['UF_CRM_TASK'] = array(str_replace($documentType[2], $letter, $documentId[2]));
     }
     $arUnsetFields = array();
     foreach ($arFields as $fieldName => $fieldValue) {
         if (substr($fieldName, -5) === '_text') {
             $arFields[substr($fieldName, 0, -5)] = $fieldValue;
             $arUnsetFields[] = $fieldName;
         }
     }
     foreach ($arUnsetFields as $fieldName) {
         unset($arFields[$fieldName]);
     }
     // Check fields for "white" list
     $arFieldsChecked = array();
     foreach (array_keys($arFields) as $fieldName) {
         if (in_array($fieldName, static::$arAllowedTasksFieldNames, true) || strlen($fieldName) > 3 && substr($fieldName, 0, 3) === 'UF_') {
             if ('UF_TASK_WEBDAV_FILES' == $fieldName && is_array($arFields[$fieldName])) {
                 foreach ($arFields[$fieldName] as $key => $fileId) {
                     if (!empty($fileId) && is_string($fileId) && substr($fileId, 0, 1) != 'n') {
                         if (CModule::IncludeModule("disk") && \Bitrix\Disk\Configuration::isSuccessfullyConverted()) {
                             $item = \Bitrix\Disk\Internals\FileTable::getList(array('select' => array('ID'), 'filter' => array('=XML_ID' => $fileId, 'TYPE' => \Bitrix\Disk\Internals\FileTable::TYPE_FILE)))->fetch();
                             if ($item) {
                                 $arFields[$fieldName][$key] = 'n' . $item['ID'];
                             }
                         }
                     }
                 }
                 unset($fileId);
             }
             $arFieldsChecked[$fieldName] = $arFields[$fieldName];
         }
     }
     $task = new CTasks();
     $result = $task->Add($arFieldsChecked, array('USER_ID' => 1));
     if (!$result) {
         $arErrors = $task->GetErrors();
         if (count($arErrors) > 0) {
             $errorDesc = array();
             if (is_array($arErrors) && !empty($arErrors)) {
                 foreach ($arErrors as $error) {
                     $errorDesc[] = $error['text'] . ' (' . $error['id'] . ')';
                 }
             }
             $this->WriteToTrackingService(GetMessage("BPSA_TRACK_ERROR") . (!empty($errorDesc) ? ' ' . implode(', ', $errorDesc) : ''));
         }
         return CBPActivityExecutionStatus::Closed;
     }
     $this->TaskId = $result;
     $this->WriteToTrackingService(str_replace("#VAL#", $result, GetMessage("BPSA_TRACK_OK")));
     if ($this->isInEventActivityMode || !$this->HoldToClose) {
         return CBPActivityExecutionStatus::Closed;
     }
     $this->Subscribe($this);
     $this->isInEventActivityMode = false;
     $this->WriteToTrackingService(GetMessage("BPSA_TRACK_SUBSCR"));
     return CBPActivityExecutionStatus::Executing;
 }