function GetTasksList($iblockId, $arOrder = array("SORT" => "ASC"), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array()) { global $USER; $iblockId = IntVal($iblockId); $arFilter["IBLOCK_ID"] = $iblockId; $arFilter["SHOW_NEW"] = "Y"; if (count($arSelectFields) > 0) { if (!in_array("IBLOCK_SECTION_ID", $arSelectFields)) { $arSelectFields[] = "IBLOCK_SECTION_ID"; } if (!in_array("ID", $arSelectFields)) { $arSelectFields[] = "ID"; } if (!in_array("IBLOCK_ID", $arSelectFields)) { $arSelectFields[] = "IBLOCK_ID"; } if (!in_array("CREATED_BY", $arSelectFields)) { $arSelectFields[] = "CREATED_BY"; } } $arResultList = array(); $arCache = array(); $isInSecurity = CModule::IncludeModule("security"); $dbTasksList = CIBlockElement::GetList($arOrder, $arFilter, $arGroupBy, $arNavStartParams, $arSelectFields); while ($obTask = $dbTasksList->GetNextElement()) { $arResult = array(); $arFields = $obTask->GetFields(); foreach ($arFields as $fieldKey => $fieldValue) { if (substr($fieldKey, 0, 1) == "~") { continue; } $arResult[$fieldKey] = $fieldValue; if (in_array($fieldKey, array("MODIFIED_BY", "CREATED_BY"))) { $arResult[$fieldKey . "_PRINTABLE"] = CIntranetTasks::PrepareUserForPrint($fieldValue); } elseif ($fieldKey == "DETAIL_TEXT") { if ($isInSecurity) { $filter = new CSecurityFilter(); $arResult["DETAIL_TEXT_PRINTABLE"] = $filter->TestXSS($arFields["~DETAIL_TEXT"]); $arResult["DETAIL_TEXT"] = $arResult["DETAIL_TEXT_PRINTABLE"]; } else { $arResult["DETAIL_TEXT_PRINTABLE"] = nl2br($arFields["DETAIL_TEXT"]); $arResult["DETAIL_TEXT"] = $arFields["DETAIL_TEXT"]; } } else { $arResult[$fieldKey . "_PRINTABLE"] = $fieldValue; } } $arProperties = $obTask->GetProperties(); foreach ($arProperties as $propertyKey => $propertyValue) { $arResult["PROPERTY_" . $propertyKey] = $propertyValue["VALUE"]; if (strtoupper($propertyKey) == "TASKCOMPLETE") { $ps = intval($propertyValue["VALUE"]); if ($ps > 100) { $ps = 100; } elseif ($ps < 0) { $ps = 0; } $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = '<div class="task-complete-bar-out" title="' . GetMessage("INTASK_L_TASKCOMPLETE", array("#PRC#" => IntVal($propertyValue["VALUE"]))) . '">'; if ($ps > 0) { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] .= '<div class="task-complete-bar-in" style="width:' . $ps . '%;"><div class="empty"></div></div>'; } $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] .= '</div>'; } elseif (strlen($propertyValue["USER_TYPE"]) > 0) { if ($propertyValue["USER_TYPE"] == "UserID") { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = CIntranetTasks::PrepareUserForPrint($propertyValue["VALUE"]); } else { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = $propertyValue["VALUE"]; } } elseif ($propertyValue["PROPERTY_TYPE"] == "G") { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = array(); $vx = CIntranetTasks::PrepareSectionForPrint($propertyValue["VALUE"], $propertyValue["LINK_IBLOCK_ID"]); foreach ($vx as $vx1 => $vx2) { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$vx1] = $vx2["NAME"]; } } elseif ($propertyValue["PROPERTY_TYPE"] == "L") { $arResult["PROPERTY_" . $propertyKey] = array(); $arPropertyValue = $propertyValue["VALUE"]; $arPropertyKey = $propertyValue["VALUE_ENUM_ID"]; if (!is_array($arPropertyValue)) { $arPropertyValue = array($arPropertyValue); $arPropertyKey = array($arPropertyKey); } for ($i = 0, $cnt = count($arPropertyValue); $i < $cnt; $i++) { $arResult["PROPERTY_" . $propertyKey][$arPropertyKey[$i]] = $arPropertyValue[$i]; } $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = $arResult["PROPERTY_" . $propertyKey]; } elseif ($propertyValue["PROPERTY_TYPE"] == "S" && $propertyValue["ROW_COUNT"] > 1) { if (is_array($propertyValue["VALUE"])) { $arResult["PROPERTY_" . $propertyKey] = array(); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = array(); if ($isInSecurity) { foreach ($propertyValue["~VALUE"] as $k => $v) { $filter = new CSecurityFilter(); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$k] = $filter->TestXSS($v); $arResult["PROPERTY_" . $propertyKey][$k] = $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$k]; } } else { foreach ($propertyValue["VALUE"] as $k => $v) { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$k] = nl2br($v); $arResult["PROPERTY_" . $propertyKey][$k] = $v; } } } else { if ($isInSecurity) { $filter = new CSecurityFilter(); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = $filter->TestXSS($propertyValue["~VALUE"]); $arResult["PROPERTY_" . $propertyKey] = $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"]; } else { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = nl2br($propertyValue["VALUE"]); $arResult["PROPERTY_" . $propertyKey] = $propertyValue["VALUE"]; } } } } $arResult["ROOT_SECTION_ID"] = 0; $arResult["IBLOCK_SECTION_ID_PRINTABLE"] = array(); $v = CIntranetTasks::PrepareSectionForPrint($arResult["IBLOCK_SECTION_ID"], $iblockId); if (is_array($v)) { foreach ($v as $k1 => $v1) { if ($arResult["ROOT_SECTION_ID"] == 0) { $arResult["ROOT_SECTION_ID"] = $k1; $taskType = $v1["XML_ID"] == "users_tasks" ? "user" : "group"; $ownerId = $taskType == "user" ? $arResult["PROPERTY_TaskAssignedTo"] : $v1["XML_ID"]; } else { $arResult["IBLOCK_SECTION_ID_PRINTABLE"][$k1] = $v1["NAME"]; } } } if (!array_key_exists($taskType . "_" . $ownerId, $arCache)) { $arCurrentUserGroups = array(); if ($taskType == "group") { $arCurrentUserGroups[] = SONET_ROLES_ALL; if ($GLOBALS["USER"]->IsAuthorized()) { $arCurrentUserGroups[] = SONET_ROLES_AUTHORIZED; } $r = CSocNetUserToGroup::GetUserRole($USER->GetID(), $ownerId); if (strlen($r) > 0) { $arCurrentUserGroups[] = $r; } } else { $arCurrentUserGroups[] = SONET_RELATIONS_TYPE_ALL; if ($GLOBALS["USER"]->IsAuthorized()) { $arCurrentUserGroups[] = SONET_RELATIONS_TYPE_AUTHORIZED; } if (CSocNetUserRelations::IsFriends($USER->GetID(), $ownerId)) { $arCurrentUserGroups[] = SONET_RELATIONS_TYPE_FRIENDS; } } $arCache[$taskType . "_" . $ownerId] = $arCurrentUserGroups; } $arCurrentUserGroups = $arCache[$taskType . "_" . $ownerId]; if ($USER->GetID() == $arResult["CREATED_BY"]) { $arCurrentUserGroups[] = "author"; } if ($USER->GetID() == $arResult["PROPERTY_TaskAssignedTo"]) { $arCurrentUserGroups[] = "responsible"; } if (is_array($arResult["PROPERTY_TaskTrackers"]) && in_array($USER->GetID(), $arResult["PROPERTY_TaskTrackers"])) { $arCurrentUserGroups[] = "trackers"; } $arResult["DocumentState"] = array(); $arDocumentStates = CBPDocument::GetDocumentStates(array("intranet", "CIntranetTasksDocument", "x" . $iblockId), array("intranet", "CIntranetTasksDocument", $arResult["ID"])); $kk = array_keys($arDocumentStates); foreach ($kk as $k) { $arResult["DocumentState"] = $arDocumentStates[$k]; $arResult["DocumentState"]["AllowableEvents"] = CBPDocument::GetAllowableEvents($GLOBALS["USER"]->GetID(), $arCurrentUserGroups, $arDocumentStates[$k]); } $arResult["TaskType"] = $taskType; $arResult["OwnerId"] = $ownerId; $arResult["CurrentUserCanViewTask"] = CIntranetTasksDocument::CanUserOperateDocument(INTASK_DOCUMENT_OPERATION_READ_DOCUMENT, $GLOBALS["USER"]->GetID(), $arResult["ID"], array("TaskType" => $taskType, "OwnerId" => $ownerId, "AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates)); $arResult["CurrentUserCanCommentTask"] = CIntranetTasksDocument::CanUserOperateDocument(INTASK_DOCUMENT_OPERATION_COMMENT_DOCUMENT, $GLOBALS["USER"]->GetID(), $arResult["ID"], array("TaskType" => $taskType, "OwnerId" => $ownerId, "AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates)); $arResult["CurrentUserCanDeleteTask"] = CIntranetTasksDocument::CanUserOperateDocument(INTASK_DOCUMENT_OPERATION_DELETE_DOCUMENT, $GLOBALS["USER"]->GetID(), $arResult["ID"], array("TaskType" => $taskType, "OwnerId" => $ownerId, "AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates)); $arResult["CurrentUserCanWriteTask"] = CIntranetTasksDocument::CanUserOperateDocument(INTASK_DOCUMENT_OPERATION_WRITE_DOCUMENT, $GLOBALS["USER"]->GetID(), $arResult["ID"], array("TaskType" => $taskType, "OwnerId" => $ownerId, "AllUserGroups" => $arCurrentUserGroups, "DocumentStates" => $arDocumentStates)); $arResultList[] = $arResult; } $dbTasksList = new CDBResult(); $dbTasksList->InitFromArray($arResultList); return $dbTasksList; }
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); }
function GetRootSectionId($taskType, $ownerId) { $iblockId = COption::GetOptionInt("intranet", "iblock_tasks", 0); if ($iblockId <= 0) { return 0; } $globalParentSectionId = 0; $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); } return $globalParentSectionId; }
public function GetDocument($documentId, $nameTemplate = false, $bShowLogin = true, $bShowTooltip = false, $arTooltipParams = false) { $iblockId = COption::GetOptionInt("intranet", "iblock_tasks", 0); if ($iblockId <= 0) { return false; } $isInSecurity = CModule::IncludeModule("security"); $arResult = false; $dbResult = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y", "IBLOCK_ID" => $iblockId)); if ($objResult = $dbResult->GetNextElement()) { $arResult = array(); $arFields = $objResult->GetFields(); foreach ($arFields as $fieldKey => $fieldValue) { if (substr($fieldKey, 0, 1) == "~") { continue; } $arResult[$fieldKey] = $fieldValue; if (in_array($fieldKey, array("MODIFIED_BY", "CREATED_BY"))) { $arResult[$fieldKey . "_PRINTABLE"] = CIntranetTasks::PrepareUserForPrint($fieldValue, $nameTemplate, $bShowLogin, $bShowTooltip, $arTooltipParams); } elseif ($fieldKey == "DETAIL_TEXT") { if ($isInSecurity) { $filter = new CSecurityFilter(); $arResult["DETAIL_TEXT_PRINTABLE"] = $filter->TestXSS($arFields["~DETAIL_TEXT_TYPE"] == "text" ? $arFields["DETAIL_TEXT"] : $arFields["~DETAIL_TEXT"], 'replace'); $arResult["DETAIL_TEXT"] = $arFields["~DETAIL_TEXT_TYPE"] == "text" ? nl2br($arFields["~DETAIL_TEXT"]) : $arFields["~DETAIL_TEXT"]; } else { $arResult["DETAIL_TEXT_PRINTABLE"] = nl2br($arFields["DETAIL_TEXT"]); $arResult["DETAIL_TEXT"] = $arFields["DETAIL_TEXT"]; } } else { $arResult[$fieldKey . "_PRINTABLE"] = $fieldValue; } } $arProperties = $objResult->GetProperties(); foreach ($arProperties as $propertyKey => $propertyValue) { if (is_array($propertyValue["VALUE"])) { $arResult["PROPERTY_" . $propertyKey] = array(); foreach ($propertyValue["VALUE"] as $k => $v) { $arResult["PROPERTY_" . $propertyKey][$propertyValue["PROPERTY_VALUE_ID"][$k]] = $v; } } else { $arResult["PROPERTY_" . $propertyKey] = $propertyValue["VALUE"]; } $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = $propertyValue["VALUE"]; if (strlen($propertyValue["USER_TYPE"]) > 0) { if ($propertyValue["USER_TYPE"] == "UserID") { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = CIntranetTasks::PrepareUserForPrint($propertyValue["VALUE"], $nameTemplate, $bShowLogin, $bShowTooltip, $arTooltipParams); } else { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = $propertyValue["VALUE"]; } } elseif ($arField["PROPERTY_TYPE"] == "G") { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = array(); $vx = CIntranetTasks::PrepareSectionForPrint($propertyValue["VALUE"], $propertyValue["LINK_IBLOCK_ID"]); foreach ($vx as $vx1 => $vx2) { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$vx1] = $vx2["NAME"]; } } elseif ($propertyValue["PROPERTY_TYPE"] == "L") { $arResult["PROPERTY_" . $propertyKey] = array(); $arPropertyValue = $propertyValue["VALUE"]; $arPropertyKey = $propertyValue["VALUE_ENUM_ID"]; if (!is_array($arPropertyValue)) { $arPropertyValue = array($arPropertyValue); $arPropertyKey = array($arPropertyKey); } for ($i = 0, $cnt = count($arPropertyValue); $i < $cnt; $i++) { $arResult["PROPERTY_" . $propertyKey][$arPropertyKey[$i]] = $arPropertyValue[$i]; } $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = $arResult["PROPERTY_" . $propertyKey]; } elseif ($propertyValue["PROPERTY_TYPE"] == "S" && $propertyValue["ROW_COUNT"] > 1) { if (is_array($propertyValue["VALUE"])) { $arResult["PROPERTY_" . $propertyKey] = array(); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = array(); if ($isInSecurity) { foreach ($propertyValue["~VALUE"] as $k => $v) { $filter = new CSecurityFilter(); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$k] = $filter->TestXSS($v, 'replace'); $arResult["PROPERTY_" . $propertyKey][$k] = $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$k]; } } else { foreach ($propertyValue["VALUE"] as $k => $v) { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$k] = nl2br($v); $arResult["PROPERTY_" . $propertyKey][$k] = $v; } } } else { if ($isInSecurity) { $filter = new CSecurityFilter(); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = $filter->TestXSS($propertyValue["~VALUE"], 'replace'); $arResult["PROPERTY_" . $propertyKey] = $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"]; } else { $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = nl2br($propertyValue["VALUE"]); $arResult["PROPERTY_" . $propertyKey] = $propertyValue["VALUE"]; } } } } $arResult["ROOT_SECTION_ID"] = 0; $arResult["IBLOCK_SECTION_ID_PRINTABLE"] = array(); $v = CIntranetTasks::PrepareSectionForPrint($arResult["IBLOCK_SECTION_ID"]); foreach ($v as $k1 => $v1) { if ($arResult["ROOT_SECTION_ID"] == 0) { $arResult["ROOT_SECTION_ID"] = $k1; $arResult["TaskType"] = $v1["XML_ID"] == "users_tasks" ? "user" : "group"; $arResult["OwnerId"] = $arResult["TaskType"] == "user" ? $arResult["PROPERTY_TaskAssignedTo"] : $v1["XML_ID"]; } else { $arResult["IBLOCK_SECTION_ID_PRINTABLE"][$k1] = $v1["NAME"]; } } } return $arResult; }
foreach ($arParams["COLUMNS"] as $field) { if (array_key_exists($field, $arResult["TaskFieldsMap"])) { $arResult["TasksPropsShow"][] = $arResult["TaskFieldsMap"][$field]; } } //$hFileTmp = fopen($_SERVER["DOCUMENT_ROOT"]."/+++++++.+++", "a"); // DUMPING //fwrite($hFileTmp, "CIBlockElement::GetList:\n".print_r(array($arOrderBy, $arFilter, false, $arNavStartParams, $arSelectFields), true)."\n\n\n"); //fwrite($hFileTmp, "arResult:\n".print_r($arResult, true)."\n\n\n"); //fclose($hFileTmp); $arPermsCache = array(); $dbTasksList = false; $arTasksListArray = array(); if ($taskType == "user" && !$arResult["isCurrentUser"]) { $arFilter["PROPERTY_TASKASSIGNEDTO"] = $ownerId; } list($dbTasksList, $dbTasksList1) = CIntranetTasks::GetListEx($arOrderBy, $arFilter, false, $arNavStartParams, $arSelectFields, $arParams['NAME_TEMPLATE'], $bUseLogin, true, array("DATE_TIME_FORMAT" => $arParams["DATE_TIME_FORMAT"], "THUMBNAIL_LIST_SIZE" => $arParams["THUMBNAIL_LIST_SIZE"], "USE_THUMBNAIL_LIST" => $arParams["USE_THUMBNAIL_LIST"], "SHOW_YEAR" => $arParams["SHOW_YEAR"], "CACHE_TYPE" => $arParams["CACHE_TYPE"], "CACHE_TIME" => $arParams["CACHE_TIME"], "PATH_TO_SONET_MESSAGES_CHAT" => $arParams["PATH_TO_MESSAGES_CHAT"], "PATH_TO_SONET_USER_PROFILE" => $arParams["PATH_TO_USER"], "PATH_TO_CONPANY_DEPARTMENT" => $arParams["~PATH_TO_CONPANY_DEPARTMENT"], "PATH_TO_VIDEO_CALL" => $arParams["~PATH_TO_VIDEO_CALL"], "INLINE" => $arParams["INLINE"])); //$dbTasksList->NavStart($arParams["ITEMS_COUNT"]); while ($arTask = $dbTasksList->Fetch()) { $currentTaskAssignedToUser = $arTask["PROPERTY_TaskAssignedTo"]; $currentTaskStatusId = $arTask["DocumentState"]["STATE_NAME"]; $currentTaskStatus = $arTask["DocumentState"]["STATE_TITLE"]; if (is_array($arTask["PROPERTY_TaskPriority"])) { foreach ($arTask["PROPERTY_TaskPriority"] as $k => $v) { $currentTaskPriorityId = $k; $iii1 = 0; foreach ($arResult["TaskFields"]["PROPERTY_TaskPriority"]["Options"] as $kkk1 => $vvv1) { $iii1++; if ($vvv1 == $v) { $currentTaskPriority = $iii1; break; }
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"));
$arResult["TasksPropsShow"][] = $arResult["TaskFieldsMap"][$field]; } } $arPermsCache = array(); $dbTasksList = false; $arTasksListArray = array(); if ($taskType == "user") { //if (!$arResult["isCurrentUser"]) $arFilter["PROPERTY_TASKASSIGNEDTO"] = $ownerId; } else { $arFilter["SECTION_ID"] = $globalParentSectionId; $arFilter["INCLUDE_SUBSECTIONS"] = "Y"; } //echo "<pre><b>CIBlockElement::GetList</b>\n".print_r(array($arOrderBy, $arFilter, false, $arNavStartParams, $arSelectFields), true)."</pre>"; //echo "<pre>".print_r($arFilter, true)."</pre>"; $dbTasksList = CIntranetTasks::GetList($arOrderBy, $arFilter, false, $arNavStartParams, $arSelectFields); $dbTasksList->NavStart($arParams["ITEMS_COUNT"]); while ($arTask = $dbTasksList->Fetch()) { $currentTaskAssignedToUser = $arTask["PROPERTY_TaskAssignedTo"]; $currentTaskStatusId = $arTask["DocumentState"]["STATE_NAME"]; $currentTaskStatus = $arTask["DocumentState"]["STATE_TITLE"]; if (is_array($arTask["DocumentState"]["PROPERTY_TaskPriority"])) { foreach ($arTask["DocumentState"]["PROPERTY_TaskPriority"] as $k => $v) { $currentTaskPriorityId = $k; $currentTaskPriority = $v; } } $arTask["TASKSTATUS_PRINTABLE"] = $arTask["DocumentState"]["STATE_TITLE"]; if (is_array($arTask["PROPERTY_TaskPriority_PRINTABLE"])) { foreach ($arTask["PROPERTY_TaskPriority_PRINTABLE"] as $v) { $arTask["TASKPRIORITY_PRINTABLE"] = trim($v);