function UpdateListItems($listName, $updates) { global $USER; $arPaths = array('user' => COption::GetOptionString('intranet', 'path_task_user_entry', '/company/personal/user/#USER_ID#/tasks/task/view/#TASK_ID#/'), 'group' => COption::GetOptionString('intranet', 'path_task_group_entry', '/workgroups/group/#GROUP_ID#/tasks/task/view/#TASK_ID#/')); if (!$this->__Init()) { return $this->error; } if (!($listName_original = CIntranetUtils::checkGUID($listName))) { return new CSoapFault('Data error', 'Wrong GUID - ' . $listName); } $listName = ToUpper(CIntranetUtils::makeGUID($listName_original)); // one more dirty hack. now for bx. //define('BX_INTASKS_FROM_COMPONENT', true); //CModule::IncludeModule('socialnetwork'); //include($_SERVER['DOCUMENT_ROOT'].BX_PERSONAL_ROOT.'/components/bitrix/intranet.tasks/init.php'); //include($_SERVER['DOCUMENT_ROOT'].BX_PERSONAL_ROOT.'/components/bitrix/intranet.tasks/action.php'); $obResponse = new CXMLCreator('Results'); $arStatusValues = array(); $obStatus = CIBlockProperty::GetPropertyEnum('TaskStatus', array('SORT' => 'asc'), array('IBLOCK_ID' => $this->IBLOCK_ID)); while ($arStatus = $obStatus->Fetch()) { $arStatusValues[$arStatus['XML_ID']] = $arStatus['ID']; if ($arStatus['XML_ID'] == 'NotAccepted') { $arStatusValues[$arStatus['VALUE']] = $arStatus['ID']; } } /* $arPriorityValues = array(); $obPriority = CIBlockProperty::GetPropertyEnum('TaskPriority', array('SORT' => 'asc'), array('IBLOCK_ID' => $this->IBLOCK_ID)); while ($arPriority = $obPriority->Fetch()) $arPriorityValues[$arPriority['XML_ID']] = $arPriority['ID']; */ $arPriorityValues = array_flip($this->arProperties['TaskPriority']['VARIANTS_ID']); $arStatusValues = array_flip($this->arProperties['TaskStatus']['VARIANTS_ID']); $arStatusXML_ID = array_flip($this->arProperties['TaskStatus']['VARIANTS']); $obBatch = $updates->children[0]; $atrONERROR = $obBatch->getAttribute('OnError'); $atrDATEINUTC = $obBatch->getAttribute('DateInUtc'); $atrPROPERTIES = $obBatch->getAttribute('Properties'); $arChanges = $obBatch->children; $arResultIDs = array(); $dateStart = ConvertTimeStamp(strtotime('-1 hour'), 'FULL'); $arResponseRows = array(); $arResponseRowsError = array(); $arReplicationIDs = array(); foreach ($arChanges as $obMethod) { $arData = array('_command' => $obMethod->getAttribute('Cmd')); $ID = false; $bUpdate = true; $arElement = false; $arSection = $this->arUsersSection; foreach ($obMethod->children as $obField) { $name = $obField->getAttribute('Name'); if ($name == 'MetaInfo') { $name .= '_' . $obField->getAttribute('Property'); } $arData[$name] = $obField->content; } $obResponseRow = new CXMLCreator('Result'); $obResponseRow->setAttribute('ID', $obMethod->getAttribute('ID') . ',' . $arData['_command']); $obResponseRow->setAttribute('List', $listName); $obResponseRow->addChild($obErrorCode = new CXMLCreator('ErrorCode')); if ($arData['ID'] > 0) { //$dbRes = CIBlockElement::GetByID($arData['ID']); $arElement = CIntranetTasks::GetById($arData['ID']); if (!is_array($arElement)) { $obErrorCode->setData('0x81020016'); $bUpdate = false; } else { //$arElement = $obElement->GetFields(); //$arElement['prop'] = $obElement->GetProperties(); if ($arElement['IBLOCK_SECTION_ID'] != $arSection['ID']) { if (!($arSection = $this->__getSection($arElement['IBLOCK_SECTION_ID']))) { return new CSoapFault('Some error', 'Unknown error with iblock sections'); } } // don't forget about depth of sections, Max has modification if ($arElement['taskType'] == "group") { $arGroupTmp = CSocNetGroup::GetByID($arElement['ownerId']); if ($arGroupTmp["CLOSED"] == "Y") { if (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") != "Y") { return new CSoapFault('Cannot modify archive group task', 'Cannot modify archive group task'); } } } $arElement['arParams'] = array($arElement['taskType'] == 'user' ? 'PATH_TO_USER_TASKS_TASK' : 'PATH_TO_GROUP_TASKS_TASK' => str_replace(array('#USER_ID#', '#GROUP_ID#', '#TASK_ID#'), array($USER->GetID(), $arSection['XML_ID'], $arElement['ID']), $arPaths[$arElement['taskType']])); } } if ($bUpdate) { if ($arData['_command'] == 'Delete') { $arError = false; if (CIntranetTasksDocument::CanUserOperateDocument(INTASK_DOCUMENT_OPERATION_DELETE_DOCUMENT, $USER->GetID(), $arElement['ID'], array())) { if (!CIntranetTasks::Delete($arElement['ID'], $arError)) { $obErrorCode->setData('0x81020014'); } else { $obErrorCode->setData('0x00000000'); } } else { $obErrorCode->setData('0x81020014'); } /* 0x00000000 - ok 0x81020015 - data conflict 0x81020014 - generic error such as invalid value for Field 0x81020016 - item does not exist */ } elseif ($arData['_command'] == 'New' || $arData['_command'] == 'Update') { /* $arData['Body'] = str_replace('</DIV>', "\r\n</DIV>", $arData['Body']); $arData['Body'] = strip_tags($arData['Body']); $arData['Body'] = trim($arData['Body']); $arData['Body'] = htmlspecialcharsback($arData['Body']); */ $arData['Body'] = trim($arData['Body']); $arData['Body'] = str_replace(array(" ", " ", ' '), "", $arData['Body']); $arData['Body'] = preg_replace("/<![^>]*>/", '', $arData['Body']); if (($pos = strpos($arData['Body'], '<BODY>')) !== false) { $arData['Body'] = substr($arData['Body'], $pos + 6); } echo $pos . ' '; if (($pos = strpos($arData['Body'], '</BODY>')) !== false) { $arData['Body'] = substr($arData['Body'], 0, $pos); } echo $pos . ' '; $TZBias = intval(date('Z')); $arData['StartDate'] = $arData['StartDate'] ? $this->__makeTS($arData['StartDate']) + $TZBias : ''; $arData['DueDate'] = $arData['DueDate'] ? $this->__makeTS($arData['DueDate']) + $TZBias : ''; $arData['MetaInfo_DateComplete'] = $arData['MetaInfo_DateComplete'] ? $this->__makeTS($arData['EndDate']) + $TZBias : ''; if ($arData['Status'] == $arStatusValues['NotAccepted']) { $arData['Status'] = 'NotAccepted'; } $arFields = array('IBLOCK_ID' => $this->IBLOCK_ID, 'IBLOCK_SECTION_ID' => $arSection['ID'], 'MODIFIED_BY' => $USER->GetID(), 'NAME' => $arData['Title'] ? $arData['Title'] : GetMessage('INTR_OUTLOOK_TASK_NO_TITLE'), 'DATE_ACTIVE_FROM' => $arData['StartDate'] ? ConvertTimeStamp($arData['StartDate']) : '', 'DATE_ACTIVE_TO' => $arData['DueDate'] ? ConvertTimeStamp($arData['DueDate']) : '', 'DETAIL_TEXT_TYPE' => 'html', 'DETAIL_TEXT' => $arData['Body'], 'PROPERTY_TaskPriority' => $arData['Priority'] ? $arPriorityValues[$arData['Priority']] : false, 'PROPERTY_TaskComplete' => $arData['PercentComplete'] * 100, 'PROPERTY_TaskSize' => $arData['MetaInfo_TotalWork'] / 60, 'PROPERTY_TaskSizeReal' => $arData['MetaInfo_ActualWork'] / 60, 'PROPERTY_TaskFinish' => $arData['MetaInfo_DateComplete'] ? ConvertTimeStamp($arData['MetaInfo_DateComplete']) : ''); if (false === $arFields['PROPERTY_TaskPriority']) { $arPrior = array_keys($arElement['PROPERTY_TaskPriority']); $arFields['PROPERTY_TaskPriority'] = $arPrior[0]; } if ($assigned_to = $arData['AssignedTo']) { if ($USER_ID = $this->__getUser($assigned_to)) { $arFields['PROPERTY_TaskAssignedTo'] = $USER_ID; } else { $obErrorCode->setData('0x81020054'); $bUpdate = false; } } if ($bUpdate) { $bConfirm = false; $bComplete = false; if ($arData['_command'] != 'New') { if (false && $arElement['PROPERTY_VERSION'] > $arData['owshiddenversion']) { $obErrorCode->setData('0x81020015'); $bUpdate = false; } else { foreach ($arElement as $fld => $value) { if (substr($fld, 0, 9) == 'PROPERTY_') { if (!$arFields[$fld] && $fld != 'PROPERTY_TaskFiles') { $arFields[$fld] = $arElement[$fld]; } } } $arFields['PROPERTY_VERSION']++; } $statusOld = $this->__GetTaskStatus($arElement['ID'], $arElement['IBLOCK_ID']); } else { $arFields['PROPERTY_VERSION'] = $arData['owshiddenversion']; $statusOld = -1; } if (!$arFields['PROPERTY_TaskPriority']) { $arFields['PROPERTY_TaskPriority'] = 2; } if (!$arFields['PROPERTY_TaskAssignedTo']) { $arFields['PROPERTY_TaskAssignedTo'] = $USER->GetID(); } elseif ($arFields['PROPERTY_TaskAssignedTo'] != $USER->GetID()) { $arData['Status'] = 'NotAccepted'; } $statusNew = $arData['Status'] ? $arStatusXML_ID[$arData['Status']] : $statusOld; $ID = 0; if ($bUpdate) { $arError = false; if ($arData['_command'] == 'New') { if ($ID = CIntranetTasks::Add($arFields, $arError)) { $arDocumentStates = CBPDocument::GetDocumentStates(array("intranet", "CIntranetTasksDocument", "x" . $this->IBLOCK_ID), null); $arDocumentStates = array_values($arDocumentStates); $pathTemplate = str_replace(array("#USER_ID#", "#TASK_ID#"), array($USER->GetID(), "{=Document:ID}"), COption::GetOptionString("intranet", "path_task_user_entry", "/company/personal/user/#USER_ID#/tasks/task/view/#TASK_ID#/")); $arErrors = array(); CBPDocument::StartWorkflow($arDocumentStates[0]["TEMPLATE_ID"], array("intranet", "CIntranetTasksDocument", $ID), array("OwnerId" => $arFields['PROPERTY_TaskAssignedTo'], "TaskType" => 'user', "PathTemplate" => $pathTemplate, "ForumId" => COption::GetOptionInt('intranet', 'task_forum_id', 0), "IBlockId" => $this->IBLOCK_ID), $arErrors); CIntranetTasks::ChangeStatus($ID, $statusNew); $arReplicationIDs[$ID] = $arData['MetaInfo_ReplicationID']; $obErrorCode->setData('0x00000000'); } } else { if (CIntranetTasks::Update($arData['ID'], $arFields, $arError)) { if ($statusOld != $statusNew) { CIntranetTasks::ChangeStatus($arData['ID'], $statusNew); } $ID = $arData['ID']; $obErrorCode->setData('0x00000000'); } } if (is_array($arError) && count($arError) > 0) { $ID = 0; $obErrorCode->setData('0x81020014'); $bUpdate = false; } else { $taskType = $arElement ? $arElement['taskType'] : 'user'; $ownerId = $arElement ? $arElement['ownerId'] : $USER->GetID(); $arParams = $arElement ? $arElement['arParams'] : array('PATH_TO_USER_TASKS_TASK' => str_replace(array('#USER_ID#', '#GROUP_ID#', '#TASK_ID#'), array($USER->GetID(), $arSection['XML_ID'], $ID), $arPaths['user'])); } } } } } if ($ID > 0) { $arResponseRows[$ID] = $obResponseRow; } else { $arResponseRowsError[] = $obResponseRow; } } $dbRes = CIntranetTasks::GetList(array('ID' => 'ASC'), array('IBLOCK_ID' => $this->IBLOCK_ID, 'ID' => array_keys($arResponseRows))); while ($arRes = $dbRes->Fetch()) { if ($arResponseRows[$arRes['ID']]) { $obRow = $this->__getRow($arRes, $listName, $last_change = 0); if ($arReplicationIDs[$arRes['ID']]) { $obRow->setAttribute('ows_MetaInfo_ReplicationID', $arReplicationIDs[$arRes['ID']]); } $obRow->setAttribute('xmlns:z', "#RowsetSchema"); $arResponseRows[$arRes['ID']]->addChild($obRow); $obResponse->addChild($arResponseRows[$arRes['ID']]); } } foreach ($arResponseRowsError as $obChange) { $obResponse->addChild($obChange); } return array('UpdateListItemsResult' => $obResponse); }
if ($bizProcEvent == "SetResponsibleEvent" && $GLOBALS["USER"]->GetID() == $taskAssignedToUserId) { CBPDocument::SendExternalEvent($arDocumentState["ID"], "HEEA_NotAccepted_ApproveEvent", array("Groups" => $arCurrentUserGroups, "User" => $GLOBALS["USER"]->GetID()), $arErrorTmp); if (count($arErrorsTmp) > 0) { foreach ($arErrorsTmp as $e) { $arResult["ErrorMessage"] .= $e["message"] . "<br />"; } } } } } } } if ($bTextModified) { $arFields = array("MODIFIED_BY" => $GLOBALS["USER"]->GetID(), "DETAIL_TEXT" => $detailText); $arErrorsTmp = array(); CIntranetTasks::Update($arParams["TASK_ID"], $arFields, $arErrorsTmp); if (count($arErrorsTmp) > 0) { foreach ($arErrorsTmp as $e) { $arResult["ErrorMessage"] .= $e["message"] . "<br />"; } } } if (strlen($arResult["ErrorMessage"]) <= 0) { if (strlen($_POST["save"]) > 0) { if (array_key_exists("back_url", $_REQUEST) && strlen($_REQUEST["back_url"]) > 0) { $redirectPath = $_REQUEST["back_url"]; } else { $redirectPath = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_TASKS"], array("owner_id" => $ownerId)); } } else { $redirectPath = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_TASKS_TASK"], array("owner_id" => $taskType == "user" ? $taskAssignedToUserId : $ownerId, "task_id" => $arParams["TASK_ID"], "action" => "view"));