protected function setupRecoveryData(Recovery\EntityRecoveryData $recoveryData, array &$fields)
 {
     $recoveryData->setTitle(\CCrmContact::GetFullName($fields, true));
     if (isset($fields['ASSIGNED_BY_ID'])) {
         $recoveryData->setResponsibleID((int) $fields['ASSIGNED_BY_ID']);
     }
 }
 public static function prepareRecoveryData($entityTypeID, $entityID, array $options = null)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = intval($entityTypeID);
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentException('Is not defined', 'entityTypeID');
     }
     if (!is_int($entityID)) {
         $entityID = intval($entityID);
     }
     if ($entityID <= 0) {
         throw new Main\ArgumentException('Must be greater than zero', 'entityID');
     }
     if (!is_array($options)) {
         $options = array();
     }
     $item = new EntityRecoveryData();
     $item->setEntityTypeID($entityTypeID);
     $item->setEntityID($entityID);
     $userID = isset($options['USER_ID']) ? intval($options['USER_ID']) : 0;
     if ($userID > 0) {
         $item->setUserID($userID);
     }
     if ($entityTypeID === \CCrmOwnerType::Lead) {
         $result = \CCrmLead::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
         $fields = is_object($result) ? $result->Fetch() : null;
         if (!is_array($fields)) {
             throw new Main\ObjectNotFoundException("The lead with ID '{$entityTypeID}' is not found");
         }
         $item->setDataItem('FIELDS', $fields);
         if (isset($fields['TITLE'])) {
             $item->setTitle($fields['TITLE']);
         }
         if (isset($fields['ASSIGNED_BY_ID'])) {
             $item->setResponsibleID(intval($fields['ASSIGNED_BY_ID']));
         }
     } elseif ($entityTypeID === \CCrmOwnerType::Contact) {
         $result = \CCrmContact::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
         $fields = is_object($result) ? $result->Fetch() : null;
         if (!is_array($fields)) {
             throw new Main\ObjectNotFoundException("The contact with ID '{$entityTypeID}' is not found");
         }
         $item->setDataItem('FIELDS', $fields);
         $item->setTitle(\CCrmContact::GetFullName($fields, true));
         if (isset($fields['ASSIGNED_BY_ID'])) {
             $item->setResponsibleID(intval($fields['ASSIGNED_BY_ID']));
         }
     } elseif ($entityTypeID === \CCrmOwnerType::Company) {
         $result = \CCrmCompany::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
         $fields = is_object($result) ? $result->Fetch() : null;
         if (!is_array($fields)) {
             throw new Main\ObjectNotFoundException("The company with ID '{$entityTypeID}' is not found");
         }
         $item->setDataItem('FIELDS', $fields);
         if (isset($fields['TITLE'])) {
             $item->setTitle($fields['TITLE']);
         }
         if (isset($fields['ASSIGNED_BY_ID'])) {
             $item->setResponsibleID(intval($fields['ASSIGNED_BY_ID']));
         }
     } else {
         throw new Main\NotSupportedException("The entity type '" . \CCrmOwnerType::ResolveName($entityTypeID) . "' is not supported in current context");
     }
     $entityTypeName = \CCrmOwnerType::ResolveName($entityTypeID);
     //MULTI FIELDS -->
     $multiFieldData = array();
     $multiFieldTypes = array(\CCrmFieldMulti::PHONE, \CCrmFieldMulti::EMAIL, \CCrmFieldMulti::WEB, \CCrmFieldMulti::IM);
     foreach ($multiFieldTypes as $multiFieldType) {
         $result = \CCrmFieldMulti::GetListEx(array('ID' => 'ASC'), array('TYPE_ID' => $multiFieldType, 'ENTITY_ID' => $entityTypeName, 'ELEMENT_ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, array('nTopCount' => 50), array('VALUE_TYPE', 'VALUE'));
         if (!is_object($result)) {
             continue;
         }
         while ($multiFields = $result->Fetch()) {
             $valueType = isset($multiFields['VALUE_TYPE']) ? $multiFields['VALUE_TYPE'] : '';
             $value = isset($multiFields['VALUE']) ? $multiFields['VALUE'] : '';
             if ($value === '') {
                 continue;
             }
             if (!isset($multiFieldData[$multiFieldType])) {
                 $multiFieldData[$multiFieldType] = array();
             }
             $multiFieldData[$multiFieldType][] = array('VALUE_TYPE' => $valueType, 'VALUE' => $value);
         }
     }
     if (!empty($multiFieldData)) {
         $item->setDataItem('MULTI_FIELDS', $multiFieldData);
     }
     //<-- MULTI FIELDS
     //ACTIVITIES -->
     $activityIDs = \CCrmActivity::GetBoundIDs($entityTypeID, $entityID);
     if (!empty($activityIDs)) {
         $item->setDataItem('ACTIVITY_IDS', $activityIDs);
     }
     //<-- ACTIVITIES
     //EVENTS -->
     $eventIDs = array();
     $result = \CCrmEvent::GetListEx(array('EVENT_REL_ID' => 'ASC'), array('ENTITY_TYPE' => $entityTypeName, 'ENTITY_ID' => $entityID, 'EVENT_TYPE' => 0, 'CHECK_PERMISSIONS' => 'N'), false, false, array('EVENT_REL_ID'));
     if (is_object($result)) {
         while ($eventFields = $result->Fetch()) {
             $eventIDs[] = intval($eventFields['EVENT_REL_ID']);
         }
     }
     if (!empty($eventIDs)) {
         $item->setDataItem('EVENT_IDS', $eventIDs);
     }
     //<-- EVENTS
     return $item;
 }
Exemple #3
0
 $arQuote['~BEGINDATE'] = $arQuote['BEGINDATE'];
 /*$arQuote['~EVENT_DATE'] = $arQuote['EVENT_DATE'];*/
 $currencyID = isset($arQuote['~CURRENCY_ID']) ? $arQuote['~CURRENCY_ID'] : CCrmCurrency::GetBaseCurrencyID();
 $arQuote['~CURRENCY_ID'] = $currencyID;
 $arQuote['CURRENCY_ID'] = htmlspecialcharsbx($currencyID);
 $arQuote['FORMATTED_OPPORTUNITY'] = CCrmCurrency::MoneyToString($arQuote['~OPPORTUNITY'], $arQuote['~CURRENCY_ID']);
 $entityID = $arQuote['ID'];
 $arQuote['PATH_TO_QUOTE_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_QUOTE_SHOW'], array('quote_id' => $entityID));
 $arQuote['PATH_TO_QUOTE_EDIT'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_QUOTE_EDIT'], array('quote_id' => $entityID));
 $arQuote['PATH_TO_QUOTE_COPY'] = CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_QUOTE_EDIT'], array('quote_id' => $entityID)), array('copy' => 1));
 $arQuote['PATH_TO_QUOTE_DELETE'] = CHTTP::urlAddParams($bInternal ? $APPLICATION->GetCurPage() : $arParams['PATH_TO_QUOTE_LIST'], array('action_' . $arResult['GRID_ID'] => 'delete', 'ID' => $entityID, 'sessid' => bitrix_sessid()));
 $contactID = isset($arQuote['~CONTACT_ID']) ? intval($arQuote['~CONTACT_ID']) : 0;
 $arQuote['PATH_TO_CONTACT_SHOW'] = $contactID <= 0 ? '' : CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_SHOW'], array('contact_id' => $contactID));
 $arQuote['~CONTACT_FORMATTED_NAME'] = $contactID <= 0 ? '' : CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('LOGIN' => '', 'NAME' => isset($arQuote['~CONTACT_NAME']) ? $arQuote['~CONTACT_NAME'] : '', 'LAST_NAME' => isset($arQuote['~CONTACT_LAST_NAME']) ? $arQuote['~CONTACT_LAST_NAME'] : '', 'SECOND_NAME' => isset($arQuote['~CONTACT_SECOND_NAME']) ? $arQuote['~CONTACT_SECOND_NAME'] : ''), false, false);
 $arQuote['CONTACT_FORMATTED_NAME'] = htmlspecialcharsbx($arQuote['~CONTACT_FORMATTED_NAME']);
 $arQuote['~CONTACT_FULL_NAME'] = CCrmContact::GetFullName(array('NAME' => isset($arQuote['CONTACT_NAME']) ? $arQuote['CONTACT_NAME'] : '', 'LAST_NAME' => isset($arQuote['CONTACT_LAST_NAME']) ? $arQuote['CONTACT_LAST_NAME'] : '', 'SECOND_NAME' => isset($arQuote['CONTACT_SECOND_NAME']) ? $arQuote['CONTACT_SECOND_NAME'] : ''), false);
 $arQuote['CONTACT_FULL_NAME'] = htmlspecialcharsbx($arQuote['~CONTACT_FULL_NAME']);
 $companyID = isset($arQuote['~COMPANY_ID']) ? intval($arQuote['~COMPANY_ID']) : 0;
 $arQuote['PATH_TO_COMPANY_SHOW'] = $companyID <= 0 ? '' : CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_COMPANY_SHOW'], array('company_id' => $companyID));
 $leadID = isset($arQuote['~LEAD_ID']) ? intval($arQuote['~LEAD_ID']) : 0;
 $arQuote['PATH_TO_LEAD_SHOW'] = $leadID <= 0 ? '' : CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_SHOW'], array('lead_id' => $leadID));
 $dealID = isset($arQuote['~DEAL_ID']) ? intval($arQuote['~DEAL_ID']) : 0;
 $arQuote['PATH_TO_DEAL_SHOW'] = $dealID <= 0 ? '' : CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_SHOW'], array('deal_id' => $dealID));
 $arQuote['PATH_TO_USER_PROFILE'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_USER_PROFILE'], array('user_id' => $arQuote['ASSIGNED_BY']));
 $arQuote['PATH_TO_USER_BP'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_USER_BP'], array('user_id' => $userID));
 $arQuote['PATH_TO_USER_CREATOR'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_USER_PROFILE'], array('user_id' => $arQuote['CREATED_BY']));
 $arQuote['PATH_TO_USER_MODIFIER'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_USER_PROFILE'], array('user_id' => $arQuote['MODIFY_BY']));
 $arQuote['CREATED_BY_FORMATTED_NAME'] = CUser::FormatName($arParams['NAME_TEMPLATE'], array('LOGIN' => $arQuote['CREATED_BY_LOGIN'], 'NAME' => $arQuote['CREATED_BY_NAME'], 'LAST_NAME' => $arQuote['CREATED_BY_LAST_NAME'], 'SECOND_NAME' => $arQuote['CREATED_BY_SECOND_NAME']), true, false);
 $arQuote['MODIFY_BY_FORMATTED_NAME'] = CUser::FormatName($arParams['NAME_TEMPLATE'], array('LOGIN' => $arQuote['MODIFY_BY_LOGIN'], 'NAME' => $arQuote['MODIFY_BY_NAME'], 'LAST_NAME' => $arQuote['MODIFY_BY_LAST_NAME'], 'SECOND_NAME' => $arQuote['MODIFY_BY_SECOND_NAME']), true, false);
 /*$typeID = isset($arQuote['TYPE_ID']) ? $arQuote['TYPE_ID'] : '';
 	$arQuote['QUOTE_TYPE_NAME'] = isset($arResult['TYPE_LIST'][$typeID]) ? $arResult['TYPE_LIST'][$typeID] : $typeID;*/
Exemple #4
0
 public function ListAddEnumFieldsValue($arParams, &$arValue, &$arReplaceValue, $delimiter = '<br />', $textonly = false, $arOptions = array())
 {
     global $APPLICATION;
     $arUserFields = $this->GetUserFields($this->sEntityID, 0, LANGUAGE_ID);
     $bSecondLoop = false;
     $arValuePrepare = array();
     if (!is_array($arOptions)) {
         $arOptions = array();
     }
     // The first loop to collect all the data fields
     foreach ($arUserFields as $FIELD_NAME => &$arUserField) {
         foreach ($arValue as $ID => $data) {
             if (!isset($arValue[$ID][$FIELD_NAME]) && $arUserField['USER_TYPE']['USER_TYPE_ID'] != 'boolean') {
                 continue;
             }
             if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'boolean') {
                 if (isset($arValue[$ID][$FIELD_NAME])) {
                     $arValue[$ID][$FIELD_NAME] == ($arValue[$ID][$FIELD_NAME] == 1 || $arValue[$ID][$FIELD_NAME] == 'Y' ? 'Y' : 'N');
                 }
                 $arVal = $arValue[$ID][$FIELD_NAME];
                 if (!is_array($arVal)) {
                     $arVal = array($arVal);
                 }
                 foreach ($arVal as $val) {
                     $val = (string) $val;
                     if (strlen($val) <= 0) {
                         //Empty value is always 'N' (not default field value)
                         $val = 'N';
                     }
                     $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . ($val == 1 ? GetMessage('MAIN_YES') : GetMessage('MAIN_NO'));
                     if ($arUserField['MULTIPLE'] == 'Y') {
                         $arValue[$ID][$FIELD_NAME][] = $val == 1 || $val == 'Y' ? 'Y' : 'N';
                     } else {
                         $arValue[$ID][$FIELD_NAME] = $val == 1 || $val == 'Y' ? 'Y' : 'N';
                     }
                 }
             } elseif ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'crm_status') {
                 $ar = CCrmStatus::GetStatusList($arUserField['SETTINGS']['ENTITY_TYPE']);
                 $arReplaceValue[$ID][$FIELD_NAME] = isset($ar[$arValue[$ID][$FIELD_NAME]]) ? $ar[$arValue[$ID][$FIELD_NAME]] : '';
             } else {
                 if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'crm') {
                     $arParams['CRM_ENTITY_TYPE'] = array();
                     if ($arUserField['SETTINGS']['LEAD'] == 'Y') {
                         $arParams['CRM_ENTITY_TYPE'][] = 'LEAD';
                     }
                     if ($arUserField['SETTINGS']['CONTACT'] == 'Y') {
                         $arParams['CRM_ENTITY_TYPE'][] = 'CONTACT';
                     }
                     if ($arUserField['SETTINGS']['COMPANY'] == 'Y') {
                         $arParams['CRM_ENTITY_TYPE'][] = 'COMPANY';
                     }
                     if ($arUserField['SETTINGS']['DEAL'] == 'Y') {
                         $arParams['CRM_ENTITY_TYPE'][] = 'DEAL';
                     }
                     $arParams['CRM_PREFIX'] = false;
                     if (count($arParams['CRM_ENTITY_TYPE']) > 1) {
                         $arParams['CRM_PREFIX'] = true;
                     }
                     $bSecondLoop = true;
                     $arVal = $arValue[$ID][$FIELD_NAME];
                     if (!is_array($arVal)) {
                         $arVal = array($arVal);
                     }
                     foreach ($arVal as $value) {
                         if ($arParams['CRM_PREFIX']) {
                             $ar = explode('_', $value);
                             $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']][CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
                             $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['FIELD'][$ID][$FIELD_NAME][CUserTypeCrm::GetLongEntityType($ar[0])][intval($ar[1])] = intval($ar[1]);
                         } else {
                             if (is_numeric($value)) {
                                 $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']][$arParams['CRM_ENTITY_TYPE'][0]][] = $value;
                                 $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['FIELD'][$ID][$FIELD_NAME][$arParams['CRM_ENTITY_TYPE'][0]][$value] = $value;
                             } else {
                                 $ar = explode('_', $value);
                                 $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']][CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
                                 $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['FIELD'][$ID][$FIELD_NAME][CUserTypeCrm::GetLongEntityType($ar[0])][intval($ar[1])] = intval($ar[1]);
                             }
                         }
                     }
                     $arReplaceValue[$ID][$FIELD_NAME] = '';
                 } else {
                     if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'file' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'employee' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'iblock_element' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'enumeration' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'iblock_section') {
                         $bSecondLoop = true;
                         $arVal = $arValue[$ID][$FIELD_NAME];
                         $arReplaceValue[$ID][$FIELD_NAME] = '';
                         if (!is_array($arVal)) {
                             $arVal = array($arVal);
                         }
                         foreach ($arVal as $value) {
                             $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['FIELD'][$ID][$FIELD_NAME][$value] = $value;
                             $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['ID'][] = $value;
                         }
                     } else {
                         if ($arUserField['MULTIPLE'] == 'Y' && is_array($arValue[$ID][$FIELD_NAME])) {
                             array_walk($arValue[$ID][$FIELD_NAME], create_function('&$v', '$v = htmlspecialcharsbx($v);'));
                             $arReplaceValue[$ID][$FIELD_NAME] = implode($delimiter, $arValue[$ID][$FIELD_NAME]);
                         }
                     }
                 }
             }
         }
     }
     unset($arUserField);
     // The second loop for special field
     if ($bSecondLoop) {
         $arValueReplace = array();
         $arList = array();
         foreach ($arValuePrepare as $KEY => $VALUE) {
             // collect multi data
             if ($KEY == 'iblock_section') {
                 $dbRes = CIBlockSection::GetList(array('left_margin' => 'asc'), array('ID' => $VALUE['ID']), false);
                 while ($arRes = $dbRes->Fetch()) {
                     $arList[$KEY][$arRes['ID']] = $arRes;
                 }
             } elseif ($KEY == 'file') {
                 $dbRes = CFile::GetList(array(), array('@ID' => implode(',', $VALUE['ID'])));
                 while ($arRes = $dbRes->Fetch()) {
                     $arList[$KEY][$arRes['ID']] = $arRes;
                 }
             } elseif ($KEY == 'iblock_element') {
                 $dbRes = CIBlockElement::GetList(array('SORT' => 'DESC', 'NAME' => 'ASC'), array('ID' => $VALUE['ID']), false);
                 while ($arRes = $dbRes->Fetch()) {
                     $arList[$KEY][$arRes['ID']] = $arRes;
                 }
             } elseif ($KEY == 'employee') {
                 $dbRes = CUser::GetList($by = 'last_name', $order = 'asc', array('ID' => implode('|', $VALUE['ID'])));
                 while ($arRes = $dbRes->Fetch()) {
                     $arList[$KEY][$arRes['ID']] = $arRes;
                 }
             } elseif ($KEY == 'enumeration') {
                 foreach ($VALUE['ID'] as $___value) {
                     $rsEnum = CUserFieldEnum::GetList(array(), array('ID' => $___value));
                     while ($arRes = $rsEnum->Fetch()) {
                         $arList[$KEY][$arRes['ID']] = $arRes;
                     }
                 }
             } elseif ($KEY == 'crm') {
                 if (isset($VALUE['LEAD']) && !empty($VALUE['LEAD'])) {
                     $dbRes = CCrmLead::GetList(array('TITLE' => 'ASC', 'LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $VALUE['LEAD']));
                     while ($arRes = $dbRes->Fetch()) {
                         $arList[$KEY]['LEAD'][$arRes['ID']] = $arRes;
                     }
                 }
                 if (isset($VALUE['CONTACT']) && !empty($VALUE['CONTACT'])) {
                     $dbRes = CCrmContact::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $VALUE['CONTACT']));
                     while ($arRes = $dbRes->Fetch()) {
                         $arList[$KEY]['CONTACT'][$arRes['ID']] = $arRes;
                     }
                 }
                 if (isset($VALUE['COMPANY']) && !empty($VALUE['COMPANY'])) {
                     $dbRes = CCrmCompany::GetList(array('TITLE' => 'ASC'), array('ID' => $VALUE['COMPANY']));
                     while ($arRes = $dbRes->Fetch()) {
                         $arList[$KEY]['COMPANY'][$arRes['ID']] = $arRes;
                     }
                 }
                 if (isset($VALUE['DEAL']) && !empty($VALUE['DEAL'])) {
                     $dbRes = CCrmDeal::GetList(array('TITLE' => 'ASC'), array('ID' => $VALUE['DEAL']));
                     while ($arRes = $dbRes->Fetch()) {
                         $arList[$KEY]['DEAL'][$arRes['ID']] = $arRes;
                     }
                 }
             }
             // assemble multi data
             foreach ($VALUE['FIELD'] as $ID => $arFIELD_NAME) {
                 foreach ($arFIELD_NAME as $FIELD_NAME => $FIELD_VALUE) {
                     foreach ($FIELD_VALUE as $FIELD_VALUE_NAME => $FIELD_VALUE_ID) {
                         if ($KEY == 'iblock_section') {
                             $sname = htmlspecialcharsbx($arList[$KEY][$FIELD_VALUE_ID]['NAME']);
                             $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                         }
                         if ($KEY == 'iblock_element') {
                             $sname = htmlspecialcharsbx($arList[$KEY][$FIELD_VALUE_ID]['NAME']);
                             if (!$textonly) {
                                 $surl = GetIBlockElementLinkById($arList[$KEY][$FIELD_VALUE_ID]['ID']);
                                 if ($surl && strlen($surl) > 0) {
                                     $sname = '<a href="' . $surl . '">' . $sname . '</a>';
                                 }
                             }
                             $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                         } else {
                             if ($KEY == 'employee') {
                                 $sname = CUser::FormatName(CSite::GetNameFormat(false), $arList[$KEY][$FIELD_VALUE_ID], false, true);
                                 if (!$textonly) {
                                     $ar['PATH_TO_USER_PROFILE'] = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_user_profile'), array('user_id' => $arList[$KEY][$FIELD_VALUE_ID]['ID']));
                                     $sname = '<a href="' . $ar['PATH_TO_USER_PROFILE'] . '" id="balloon_' . $arParams['GRID_ID'] . '_' . $arList[$KEY][$FIELD_VALUE_ID]['ID'] . '">' . $sname . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arList[$KEY][$FIELD_VALUE_ID]['ID'] . ', "balloon_' . $arParams['GRID_ID'] . '_' . $arList[$KEY][$FIELD_VALUE_ID]['ID'] . '", "");</script>';
                                 }
                                 $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                             } else {
                                 if ($KEY == 'enumeration') {
                                     $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . htmlspecialcharsbx($arList[$KEY][$FIELD_VALUE_ID]['VALUE']);
                                 } else {
                                     if ($KEY == 'file') {
                                         $fileInfo = $arList[$KEY][$FIELD_VALUE_ID];
                                         if ($textonly) {
                                             $fileUrl = CFile::GetFileSRC($fileInfo);
                                         } else {
                                             $fileUrlTemplate = isset($arOptions['FILE_URL_TEMPLATE']) ? $arOptions['FILE_URL_TEMPLATE'] : '';
                                             $fileUrl = $fileUrlTemplate === '' ? CFile::GetFileSRC($fileInfo) : CComponentEngine::MakePathFromTemplate($fileUrlTemplate, array('owner_id' => $ID, 'field_name' => $FIELD_NAME, 'file_id' => $fileInfo['ID']));
                                         }
                                         $sname = $textonly ? $fileUrl : '<a href="' . htmlspecialcharsbx($fileUrl) . '" target="_blank">' . htmlspecialcharsbx($arList[$KEY][$FIELD_VALUE_ID]['FILE_NAME']) . '</a>';
                                         $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                                     } else {
                                         if ($KEY == 'crm') {
                                             foreach ($FIELD_VALUE_ID as $CID) {
                                                 $link = '';
                                                 $title = '';
                                                 $prefix = '';
                                                 if ($FIELD_VALUE_NAME == 'LEAD') {
                                                     $link = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $CID));
                                                     $title = $arList[$KEY]['LEAD'][$CID]['TITLE'];
                                                     $prefix = 'L';
                                                 } elseif ($FIELD_VALUE_NAME == 'CONTACT') {
                                                     $link = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $CID));
                                                     $title = CCrmContact::GetFullName($arList[$KEY]['CONTACT'][$CID], true);
                                                     $prefix = 'C';
                                                 } elseif ($FIELD_VALUE_NAME == 'COMPANY') {
                                                     $link = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $CID));
                                                     $title = $arList[$KEY]['COMPANY'][$CID]['TITLE'];
                                                     $prefix = 'CO';
                                                 } elseif ($FIELD_VALUE_NAME == 'DEAL') {
                                                     $link = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $CID));
                                                     $title = $arList[$KEY]['DEAL'][$CID]['TITLE'];
                                                     $prefix = 'D';
                                                 }
                                                 $sname = htmlspecialcharsbx($title);
                                                 if (!$textonly) {
                                                     $tooltip = '<script type="text/javascript">BX.tooltip(' . $CID . ', "balloon_' . $ID . '_' . $FIELD_NAME . '_' . $FIELD_VALUE_NAME . '_' . $CID . '", "/bitrix/components/bitrix/crm.' . strtolower($FIELD_VALUE_NAME) . '.show/card.ajax.php", "crm_balloon' . ($FIELD_VALUE_NAME == 'LEAD' || $FIELD_VALUE_NAME == 'DEAL' || $FIELD_VALUE_NAME == 'QUOTE' ? '_no_photo' : '_' . strtolower($FIELD_VALUE_NAME)) . '", true);</script>';
                                                     $sname = '<a href="' . $link . '" target="_blank" id="balloon_' . $ID . '_' . $FIELD_NAME . '_' . $FIELD_VALUE_NAME . '_' . $CID . '">' . $sname . '</a>' . $tooltip;
                                                 } else {
                                                     $sname = "[{$prefix}]{$sname}";
                                                 }
                                                 $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }