Exemplo n.º 1
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.º 2
0
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;
}
Exemplo n.º 3
0
 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;
 }