Exemplo n.º 1
0
    function SaveEvent($arParams)
    {
        global $DB;
        $iblockId = $arParams['iblockId'];
        $ownerType = $arParams['ownerType'];
        $ownerId = $arParams['ownerId'];
        $bCheckPermissions = $arParams["bCheckPermissions"] !== false;
        $calendarId = intVal($arParams['calendarId']);
        $sectionId = $arParams['sectionId'];
        $fullUrl = $arParams['fullUrl'];
        $userId = $arParams['userId'];
        $bIsInvitingEvent = $arParams['isMeeting'] && intval($arParams['prop']['PARENT']) > 0;
        $bExchange = CEventCalendar::IsExchangeEnabled() && $ownerType == 'USER';
        $bCalDav = CEventCalendar::IsCalDAVEnabled() && $ownerType == 'USER';
        if (!$bIsInvitingEvent) {
            // *** ADD MEETING ROOM ***
            $loc_old = CEventCalendar::ParseLocation($arParams['location']['old']);
            $loc_new = CEventCalendar::ParseLocation($arParams['location']['new']);
            if ($loc_old['mrid'] !== false && $loc_old['mrevid'] !== false && ($loc_old['mrid'] !== $loc_new['mrid'] || $arParams['location'])) {
                if ($loc_old['mrid'] == $arParams['VMiblockId']) {
                    CEventCalendar::ReleaseVR(array('mrevid' => $loc_old['mrevid'], 'mrid' => $loc_old['mrid'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting']));
                } else {
                    CEventCalendar::ReleaseMR(array('mrevid' => $loc_old['mrevid'], 'mrid' => $loc_old['mrid'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting']));
                }
            }
            if ($loc_new['mrid'] !== false) {
                if ($loc_new['mrid'] == $arParams['VMiblockId']) {
                    $mrevid = CEventCalendar::ReserveVR(array('mrid' => $loc_new['mrid'], 'dateFrom' => $arParams['dateFrom'], 'dateTo' => $arParams['dateTo'], 'name' => $arParams['name'], 'description' => GetMessage('EC_RESERVE_FOR_EVENT') . ': ' . $arParams['name'], 'persons' => count($arParams['guests']), 'members' => $arParams['guests'], 'regularity' => $arParams['prop']['PERIOD_TYPE'], 'regularity_count' => $arParams['prop']['PERIOD_COUNT'], 'regularity_length' => $arParams['prop']['EVENT_LENGTH'], 'regularity_additional' => $arParams['prop']['PERIOD_ADDITIONAL'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting']));
                } else {
                    $mrevid = CEventCalendar::ReserveMR(array('mrid' => $loc_new['mrid'], 'dateFrom' => $arParams['dateFrom'], 'dateTo' => $arParams['dateTo'], 'name' => $arParams['name'], 'description' => GetMessage('EC_RESERVE_FOR_EVENT') . ': ' . $arParams['name'], 'persons' => $arParams['isMeeting'] && count($arParams['guests']) > 0 ? count($arParams['guests']) : 1, 'regularity' => $arParams['prop']['PERIOD_TYPE'], 'regularity_count' => $arParams['prop']['PERIOD_COUNT'], 'regularity_length' => $arParams['prop']['EVENT_LENGTH'], 'regularity_additional' => $arParams['prop']['PERIOD_ADDITIONAL'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting']));
                }
                if ($mrevid && $mrevid != 'reserved' && $mrevid != 'expire' && $mrevid > 0) {
                    $loc_new = 'ECMR_' . $loc_new['mrid'] . '_' . $mrevid;
                    $arParams["prop"]['LOCATION'] = $loc_new;
                } else {
                    $arParams["prop"]['LOCATION'] = '';
                    if ($mrevid == 'reserved') {
                        $loc_new = 'bxec_error_reserved';
                    } elseif ($mrevid == 'expire') {
                        $loc_new = 'bxec_error_expire';
                    } else {
                        $loc_new = 'bxec_error';
                    }
                }
            } else {
                $loc_new = $loc_new['str'];
                $arParams["prop"]['LOCATION'] = $loc_new;
            }
        }
        //$bSocNetLog = (!isset($arParams['bSocNetLog']) || $arParams['bSocNetLog'] != false) && !$arParams["prop"]["PRIVATE"];
        //if(cmodule::includemodule('security'))
        if (CModule::IncludeModule("security")) {
            $filter = new CSecurityFilter();
            $arParams['desc'] = $filter->TestXSS($arParams['desc'], 'replace');
        } else {
            $arParams['desc'] = htmlspecialcharsex($arParams['desc']);
        }
        if ($calendarId > 0) {
            //cheking permissions and correct nesting
            //if (!CEventCalendar::CheckCalendar(array('iblockId' => $iblockId, 'ownerId' => $ownerId, 'ownerType' => $ownerType, 'calendarId' => $calendarId, 'sectionId' => $sectionId)))
            //	return CEventCalendar::ThrowError(GetMessage('EC_CALENDAR_CREATE_ERROR').' '.GetMessage('EC_CAL_INCORRECT_ERROR'));
        } else {
            // Creating default calendar section for owner
            $bDisplayCalendar = !$arParams["notDisplayCalendar"];
            // Output js with calendar description
            $newSectionId = 'none';
            // by reference
            $calendarId = CECCalendar::CreateDefault(array('ownerType' => $ownerType, 'ownerId' => $ownerId, 'iblockId' => $iblockId, 'sectionId' => $sectionId), $bDisplayCalendar, $newSectionId);
            if (!$calendarId) {
                return CEventCalendar::ThrowError('2' . GetMessage('EC_CALENDAR_CREATE_ERROR'));
            }
            if ($newSectionId != 'none') {
                $arParams['sectionId'] = $newSectionId;
            }
        }
        $arParams['calendarId'] = $calendarId;
        if ($bIsInvitingEvent && !isset($arParams["CONFIRMED"]) && isset($arParams["status"])) {
            $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, $arParams["status"]);
        } else {
            if ($arParams["CONFIRMED"] == "Q") {
                $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, "Q");
            } elseif ($arParams["CONFIRMED"] == "Y") {
                $arParams["prop"]["CONFIRMED"] = CEventCalendar::GetConfirmedID($iblockId, "Y");
            } else {
                unset($arParams["prop"]["CONFIRMED"]);
            }
        }
        if (isset($arParams["remind"])) {
            if ($arParams["remind"] !== false) {
                $arParams["prop"]["REMIND_SETTINGS"] = $arParams["remind"]['count'] . '_' . $arParams["remind"]['type'];
            } else {
                if (!$arParams['bNew']) {
                    $arParams["prop"]["REMIND_SETTINGS"] = '';
                }
            }
        }
        if (!isset($arParams['prop']['VERSION'])) {
            if (!$arParams['bNew']) {
                $dbProp = CIBlockElement::GetProperty($iblockId, $arParams['id'], 'sort', 'asc', array('CODE' => 'VERSION'));
                if ($arProp = $dbProp->Fetch()) {
                    $arParams['prop']['VERSION'] = intval($arProp['VALUE']);
                }
            }
            if ($arParams['prop']['VERSION'] <= 0) {
                $arParams['prop']['VERSION'] = 1;
            }
            $arParams['prop']['VERSION']++;
        }
        if ($arParams['isMeeting']) {
            $arParams['prop']['IS_MEETING'] = 'Y';
        }
        if (!$bIsInvitingEvent) {
            $arParams['prop']['HOST_IS_ABSENT'] = $arParams['isMeeting'] && !in_array($userId, $arParams['guests']) ? 'Y' : 'N';
            if ($arParams['isMeeting'] && strlen($arParams['meetingText'])) {
                $arParams['prop']['MEETING_TEXT'] = array('VALUE' => array("TYPE" => 'text', "TEXT" => $arParams['meetingText']));
            }
        }
        $arFields = array("ACTIVE" => "Y", "IBLOCK_SECTION" => $calendarId, "IBLOCK_ID" => $iblockId, "NAME" => $arParams['name'], "ACTIVE_FROM" => $arParams['dateFrom'], "ACTIVE_TO" => $arParams['dateTo'], "DETAIL_TEXT" => $arParams['desc'], "DETAIL_TEXT_TYPE" => 'html', "MODIFIED_BY" => $GLOBALS['USER']->GetID(), "PROPERTY_VALUES" => $arParams['prop']);
        if ($ownerType == 'GROUP' && $ownerId > 0) {
            $arFields['SOCNET_GROUP_ID'] = $ownerId;
        }
        if ($bExchange || $bCalDav) {
            foreach ($arFields["PROPERTY_VALUES"] as $prKey => $prVal) {
                $arFields["PROPERTY_" . $prKey] = $prVal;
            }
        }
        // If it's EXCHANGE - we try to save event to exchange
        if ($bExchange) {
            $calendarXmlId = CECCalendar::GetExchangeXmlId($iblockId, $calendarId);
            if (strlen($calendarXmlId) > 0 && $calendarXmlId !== 0) {
                if ($arParams['bNew']) {
                    $exchRes = CDavExchangeCalendar::DoAddItem($ownerId, $calendarXmlId, $arFields);
                } else {
                    $eventModLabel = CECEvent::GetExchModLabel($iblockId, $arParams['id']);
                    $eventXmlId = CECEvent::GetExchangeXmlId($iblockId, $arParams['id']);
                    $exchRes = CDavExchangeCalendar::DoUpdateItem($ownerId, $eventXmlId, $eventModLabel, $arFields);
                }
                if (!is_array($exchRes) || !array_key_exists("XML_ID", $exchRes)) {
                    return CEventCalendar::ThrowError(CEventCalendar::CollectExchangeErros($exchRes));
                }
                // It's ok, we successfuly save event to exchange calendar - and save it to DB
                $arFields['XML_ID'] = $exchRes['XML_ID'];
                $arFields['PROPERTY_VALUES']['BXDAVEX_LABEL'] = $exchRes['MODIFICATION_LABEL'];
            }
        }
        if ($bCalDav) {
            $connectionId = CECCalendar::GetCalDAVConnectionId($iblockId, $calendarId);
            if ($connectionId > 0) {
                $calendarCalDAVXmlId = CECCalendar::GetCalDAVXmlId($iblockId, $calendarId);
                if ($arParams['bNew']) {
                    $DAVRes = CDavGroupdavClientCalendar::DoAddItem($connectionId, $calendarCalDAVXmlId, $arFields);
                } else {
                    $eventCalDAVModLabel = CECEvent::GetCalDAVModLabel($iblockId, $arParams['id']);
                    $eventXmlId = CECEvent::GetExchangeXmlId($iblockId, $arParams['id']);
                    $DAVRes = CDavGroupdavClientCalendar::DoUpdateItem($connectionId, $calendarCalDAVXmlId, $eventXmlId, $eventCalDAVModLabel, $arFields);
                }
                if (!is_array($DAVRes) || !array_key_exists("XML_ID", $DAVRes)) {
                    return CEventCalendar::ThrowError(CEventCalendar::CollectCalDAVErros($DAVRes));
                }
                // // It's ok, we successfuly save event to caldav calendar - and save it to DB
                $arFields['XML_ID'] = $DAVRes['XML_ID'];
                $arFields['PROPERTY_VALUES']['BXDAVCD_LABEL'] = $DAVRes['MODIFICATION_LABEL'];
            }
        }
        $bs = new CIBlockElement();
        $res = false;
        if (!$arParams['bNew']) {
            $ID = $arParams['id'];
            if ($ID > 0) {
                $res = $bs->Update($ID, $arFields, false);
            }
        } else {
            //This sets appropriate owner if event created by owner of the meeting and this calendar belongs to guest which is not current user
            if ($ownerType == 'USER' && $ownerId > 0 && $userId != $ownerId) {
                $arFields['CREATED_BY'] = $ownerId;
            }
            $ID = $bs->Add($arFields, false);
            $res = $ID > 0;
        }
        if ($arParams['isMeeting'] && !$bIsInvitingEvent) {
            $this->CheckParentProperty($arParams['userIblockId'], $iblockId);
            $arGuestConfirm = $this->InviteGuests($ID, $arFields, $arParams['guests'], $arParams);
        }
        if (!$res) {
            return CEventCalendar::ThrowError('4' . $bs->LAST_ERROR);
        } else {
            CIBlockElement::RecalcSections($ID);
        }
        if (!$bPeriodic && !$arParams["notDisplayCalendar"]) {
            if ($arParams['bNew']) {
                ?>
<script>window._bx_new_event = {ID: <?php 
                echo $ID;
                ?>
, IBLOCK_ID: '<?php 
                echo $iblockId;
                ?>
', LOC: '<?php 
                echo CUtil::JSEscape($loc_new);
                ?>
', arGuestConfirm: <?php 
                echo CUtil::PhpToJSObject($arGuestConfirm);
                ?>
};</script><?php 
            } else {
                ?>
<script>window._bx_existent_event = {ID: <?php 
                echo intVal($ID);
                ?>
, NAME : '<?php 
                echo CUtil::JSEscape($arParams['name']);
                ?>
', DETAIL_TEXT: '<?php 
                echo CUtil::JSEscape($arParams['desc']);
                ?>
', DATE_FROM : '<?php 
                echo $arParams['dateFrom'];
                ?>
', DATE_TO : '<?php 
                echo $arParams['dateTo'];
                ?>
', LOC: '<?php 
                echo CUtil::JSEscape($loc_new);
                ?>
', arGuestConfirm: <?php 
                echo CUtil::PhpToJSObject($arGuestConfirm);
                ?>
};</script>
<?php 
            }
        }
        $this->ClearCache($this->cachePath . 'events/' . $iblockId . '/');
        if ($bSocNetLog && $ownerType) {
            CEventCalendar::SocNetLog(array('iblockId' => $iblockId, 'ownerType' => $ownerType, 'ownerId' => $ownerId, 'target' => $arParams['bNew'] ? 'add_event' : 'edit_event', 'id' => $ID, 'name' => $arParams['name'], 'desc' => $arParams['desc'], 'from' => $arParams['dateFrom'], 'to' => $arParams['dateTo'], 'calendarId' => $calendarId, 'accessibility' => $arParams["prop"]["ACCESSIBILITY"], 'importance' => $arParams["prop"]["IMPORTANCE"], 'pathToGroupCalendar' => $arParams["pathToGroupCalendar"], 'pathToUserCalendar' => $arParams["pathToUserCalendar"]));
        }
        if (array_key_exists("remind", $arParams)) {
            CECEvent::AddReminder(array('iblockId' => $iblockId, 'ownerType' => $ownerType, 'ownerId' => $ownerId, 'userId' => $userId, 'fullUrl' => $fullUrl, 'id' => $ID, 'dateFrom' => $arParams['dateFrom'], 'remind' => $arParams["remind"], 'bNew' => $arParams['bNew']));
        }
        return $ID;
    }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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.º 4
0
             if (array_key_exists($v, $arField["Options"])) {
                 $arResult["Task"][$fieldKey][$v] = $arField["Options"][$v];
             }
         }
     } else {
         if (array_key_exists($arFields[$fieldKey], $arField["Options"])) {
             $arResult["Task"][$fieldKey][$arFields[$fieldKey]] = $arField["Options"][$arFields[$fieldKey]];
         }
     }
     $arResult["Task"][$fieldKey . "_PRINTABLE"] = $arResult["Task"][$fieldKey];
 } elseif ($arField["Type"] == "text") {
     if ($isInSecurity) {
         $filter = new CSecurityFilter();
         if (is_array($arFields[$fieldKey])) {
             foreach ($arFields[$fieldKey] as $k => $v) {
                 $arResult["Task"][$fieldKey][$k] = $filter->TestXSS($v);
             }
         } else {
             $arResult["Task"][$fieldKey] = $filter->TestXSS($arFields[$fieldKey]);
         }
     } else {
         if (is_array($arFields[$fieldKey])) {
             foreach ($arFields[$fieldKey] as $k => $v) {
                 $arResult["Task"][$fieldKey][$k] = htmlspecialcharsbx($v);
             }
         } else {
             $arResult["Task"][$fieldKey] = htmlspecialcharsbx($arFields[$fieldKey]);
         }
     }
     $arResult["Task"][$fieldKey . "_PRINTABLE"] = $arResult["Task"][$fieldKey];
 } else {