public static function GetEntityDataByCalRel($sCalRel) { $sCalRel = trim($sCalRel); $_arData = explode('_', $sCalRel); $arData = array('ID' => $_arData[1], 'SHORT_TYPE' => $_arData[0], 'TYPE' => CUserTypeCrm::GetLongEntityType($_arData[0])); return $arData; }
} $arParams['PREFIX'] = false; if (count($arParams['ENTITY_TYPE']) > 1) { $arParams['PREFIX'] = true; } $arValue = array(); foreach ($arResult['VALUE'] as $value) { if ($arParams['PREFIX']) { $ar = explode('_', $value); $arValue[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]); } else { if (is_numeric($value)) { $arValue[$arParams['ENTITY_TYPE'][0]][] = $value; } else { $ar = explode('_', $value); $arValue[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]); } } } $arResult['VALUE'] = array(); if ($arParams['arUserField']['SETTINGS']['LEAD'] == 'Y' && isset($arValue['LEAD']) && !empty($arValue['LEAD'])) { $dbRes = CCrmLead::GetList(array('TITLE' => 'ASC', 'LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arValue['LEAD'])); while ($arRes = $dbRes->Fetch()) { $arResult['VALUE']['LEAD'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $arRes['ID']))); } } if ($arParams['arUserField']['SETTINGS']['CONTACT'] == 'Y' && isset($arValue['CONTACT']) && !empty($arValue['CONTACT'])) { $dbRes = CCrmContact::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arValue['CONTACT'])); while ($arRes = $dbRes->Fetch()) { $arResult['VALUE']['CONTACT'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['FULL_NAME'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $arRes['ID']))); }
} $arResult['ELEMENT'][] = array('title' => $arRes['NAME'], 'desc' => CCrmProduct::FormatPrice($arRes), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_product_show'), array('product_id' => $arRes['ID'])), 'type' => 'product', 'selected' => $sSelected); } unset($arProducts); } if (!empty($arResult['SELECTED'])) { foreach ($arResult['SELECTED'] as $value) { if ($arResult['PREFIX'] === 'Y') { $ar = explode('_', $value); $arSelected[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]); } else { if (is_numeric($value)) { $arSelected[$arParams['ENTITY_TYPE'][0]][] = $value; } else { $ar = explode('_', $value); $arSelected[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]); } } } if ($arSettings['LEAD'] == 'Y' && isset($arSelected['LEAD']) && !empty($arSelected['LEAD'])) { $hasNameFormatter = method_exists("CCrmLead", "PrepareFormattedName"); $obRes = CCrmLead::GetListEx(array('ID' => 'DESC'), array('=ID' => $arSelected['LEAD']), false, false, $hasNameFormatter ? array('ID', 'TITLE', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME') : array('ID', 'TITLE', 'FULL_NAME')); $arFiles = array(); $ar = array(); while ($arRes = $obRes->Fetch()) { $arRes['SID'] = $arResult['PREFIX'] == 'Y' ? 'L_' . $arRes['ID'] : $arRes['ID']; if (isset($arResult['SELECTED'][$arRes['SID']])) { unset($arResult['SELECTED'][$arRes['SID']]); $sSelected = 'Y'; } else { $sSelected = 'N';
public static function RefreshCalendarBindings() { if (!(IsModuleInstalled('calendar') && CModule::IncludeModule('calendar'))) { return false; } global $DB; $dbResult = $DB->Query('SELECT OWNER_ID, OWNER_TYPE_ID, ASSOCIATED_ENTITY_ID FROM ' . CCrmActivity::TABLE_NAME . ' WHERE OWNER_ID > 0 AND OWNER_TYPE_ID > 0 AND ASSOCIATED_ENTITY_ID > 0 AND TYPE_ID IN (' . CCrmActivityType::Call . ', ' . CCrmActivityType::Meeting . ')', false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__); if (!$dbResult) { return false; } while ($arResult = $dbResult->Fetch()) { $ownerID = intval($arResult['OWNER_ID']); $ownerTypeID = intval($arResult['OWNER_TYPE_ID']); $assocEntityID = intval($arResult['ASSOCIATED_ENTITY_ID']); if ($ownerID > 0 && $ownerTypeID > 0 && $assocEntityID > 0) { CCalendarEvent::UpdateUserFields($assocEntityID, array('UF_CRM_CAL_EVENT' => array(CUserTypeCrm::GetShortEntityType(CCrmOwnerType::ResolveName($ownerTypeID)) . '_' . $ownerID))); } } return true; }
if (!empty($arParams['INTERNAL_FILTER']) && is_array($arParams['INTERNAL_FILTER'])) { $arParams['GRID_ID_SUFFIX'] = $this->GetParent() !== null ? $this->GetParent()->GetName() : ''; $arFilter = $arParams['INTERNAL_FILTER']; } if (!empty($arParams['INTERNAL_SORT']) && is_array($arParams['INTERNAL_SORT'])) { $arSort = $arParams['INTERNAL_SORT']; } $sShortEntity = ''; $iEntityID = 0; if (isset($arFilter['ENTITY_TYPE'])) { $sShortEntity = CUserTypeCrm::GetShortEntityType($arFilter['ENTITY_TYPE']); } if (isset($arFilter['ENTITY_ID'])) { $iEntityID = (int) $arFilter['ENTITY_ID']; if ($iEntityID > 0 && !empty($sShortEntity)) { $sShortEntity = CUserTypeCrm::GetShortEntityType('LEAD'); } } if (empty($arParams['ACTIVITY_CALENDAR_COUNT'])) { $arParams['ACTIVITY_CALENDAR_COUNT'] = 20; } $arNavParams = array('nPageSize' => $arParams['ACTIVITY_CALENDAR_COUNT']); $arNavigation = CDBResult::GetNavParams($arNavParams); global $APPLICATION; $arResult['GRID_ID'] = 'CRM_ACTIVITY_CALENDAR_LIST' . ($bInternal ? '_' . $arParams['GRID_ID_SUFFIX'] : ''); $arResult['FILTER'] = array(); $arResult['FILTER_PRESETS'] = array(); if (!$bInternal) { $arEntityType = array('' => '', 'LEAD' => GetMessage('CRM_ENTITY_TYPE_LEAD'), 'CONTACT' => GetMessage('CRM_ENTITY_TYPE_CONTACT'), 'COMPANY' => GetMessage('CRM_ENTITY_TYPE_COMPANY'), 'DEAL' => GetMessage('CRM_ENTITY_TYPE_DEAL')); ob_start(); $GLOBALS["APPLICATION"]->IncludeComponent('bitrix:crm.entity.selector', '', array('ENTITY_TYPE' => array('LEAD', 'CONTACT', 'COMPANY', 'DEAL'), 'INPUT_NAME' => 'UF_CRM_CAL_EVENT', 'INPUT_VALUE' => isset($_REQUEST['UF_CRM_CAL_EVENT']) ? $_REQUEST['UF_CRM_CAL_EVENT'] : '', 'FORM_NAME' => $arResult['GRID_ID'], 'MULTIPLE' => 'N', 'FILTER' => true), false, array('HIDE_ICONS' => 'Y'));
if (0 >= $intRemLen) { $intRemLen = 15; } } $strPriority = ''; if (isset($_POST['PRIORITY'])) { $strPriority = ToLower($_POST['PRIORITY']); } if (!in_array($strPriority, $arPriorityType)) { $strPriority = 'normal'; } $arResult['VALUES']['REMIND_LEN'] = $intRemLen; $arResult['VALUES']['REMIND_TYPE'] = $strRemType; $arResult['VALUES']['PRIORITY'] = $strPriority; if (false == $boolError) { $strEntityShort = CUserTypeCrm::GetShortEntityType($arResult['ENTITY_TYPE']) . '_'; foreach ($arID as $intID => $iUserID) { $arCrmEvents = array(); $arCrmEvents[] = $strEntityShort . $intID; $arFields = array('CAL_TYPE' => 'user', 'OWNER_ID' => $iUserID, 'NAME' => $arResult['VALUES']['CALENDAR_TOPIC'], 'DT_FROM' => $arResult['VALUES']['CALENDAR_FROM'], 'DT_TO' => $arResult['VALUES']['CALENDAR_TO'], 'DESCRIPTION' => $arResult['VALUES']['CALENDAR_DESC'], 'IMPORTANCE' => $strPriority); if ('Y' == $arResult['VALUES']['REMIND_FLAG']) { $arFields['REMIND'] = array(array('type' => $strRemType, 'count' => $intRemLen)); } $intEventID = CCalendar::SaveEvent(array('arFields' => $arFields, 'userId' => $iUserID, 'autoDetectSection' => true, 'autoCreateSection' => true)); if (0 < intval($intEventID)) { CCalendarEvent::UpdateUserFields($intEventID, array('UF_CRM_CAL_EVENT' => $arCrmEvents)); } else { $boolError = true; $arResult['ERROR_MESSAGE'][] = GetMessage('BX_CRM_CACA_ERR_ADD_FAIL'); } }
public static function GetList($arSort = array(), $arFilter = array(), $nPageTop = false) { global $DB, $USER; $currentUser = isset($USER) && (get_class($USER) === 'CUser' || $USER instanceof CUser) ? $USER : new CUser(); $arSqlSearch = array(); $strSqlSearch = ""; $err_mess = self::err_mess() . '<br />Function: GetList<br />Line: '; if (isset($arFilter['ENTITY'])) { $ar = explode('_', $arFilter['ENTITY']); $arFilter['ENTITY_TYPE'] = CUserTypeCrm::GetLongEntityType($ar[0]); $arFilter['ENTITY_ID'] = intval($ar[1]); unset($arFilter['ENTITY']); } // permission check $strPermission = ""; if (!$currentUser->IsAdmin()) { $CCrmPerms = new CCrmPerms($currentUser->GetID()); $arUserAttr = array(); $arEntity = array(); if (empty($arFilter['ENTITY_TYPE'])) { $arEntity = array('LEAD', 'DEAL', 'CONTACT', 'COMPANY', 'QUOTE'); } else { if (is_array($arFilter['ENTITY_TYPE'])) { $arEntity = $arFilter['ENTITY_TYPE']; } else { $arEntity = array($arFilter['ENTITY_TYPE']); } } $arInEntity = array(); foreach ($arEntity as $sEntityType) { $arEntityAttr = $CCrmPerms->GetUserAttrForSelectEntity($sEntityType, 'READ'); $arUserAttr[$sEntityType] = $arEntityAttr; } if (empty($arUserAttr)) { $CDBResult = new CDBResult(); $CDBResult->InitFromArray(array()); return $CDBResult; } $arUserPerm = array(); foreach ($arUserAttr as $sEntityType => $_arAttrs) { if (isset($_arAttrs[0]) && is_array($_arAttrs[0]) && empty($_arAttrs[0])) { $arInEntity[] = $sEntityType; continue; } foreach ($_arAttrs as $_arAttr) { if (empty($_arAttr)) { continue; } $_icnt = count($_arAttr); $_idcnt = -1; foreach ($_arAttr as $sAttr) { if ($sAttr[0] == 'D') { $_idcnt++; } } if ($_icnt == 1 && ($_idcnt == 1 || $_idcnt == -1)) { $_idcnt = 0; } $arUserPerm[] = "(P.ENTITY = '{$sEntityType}' AND SUM(CASE WHEN P.ATTR = '" . implode("' or P.ATTR = '", $_arAttr) . "' THEN 1 ELSE 0 END) = " . ($_icnt - $_idcnt) . ')'; } } $arPermission = array(); if (!empty($arInEntity)) { $arPermission[] = " CER.ENTITY_TYPE IN ('" . implode("','", $arInEntity) . "')"; } if (!empty($arUserPerm)) { $arPermission[] = "\n\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\tSELECT 1\n\t\t\t\t\t\t\tFROM b_crm_entity_perms P\n\t\t\t\t\t\t\tWHERE P.ENTITY = CER.ENTITY_TYPE AND CER.ENTITY_ID = P.ENTITY_ID\n\t\t\t\t\t\t\tGROUP BY P.ENTITY, P.ENTITY_ID\n\t\t\t\t\t\t\tHAVING " . implode(" \n\t\t\t\t\t\t\t\tOR ", $arUserPerm) . "\n\t\t\t\t\t\t)"; } if (!empty($arPermission)) { $strPermission = 'AND (' . implode(' OR ', $arPermission) . ')'; } } $sOrder = ''; foreach ($arSort as $key => $val) { $ord = strtoupper($val) != 'ASC' ? 'DESC' : 'ASC'; switch (strtoupper($key)) { case 'ID': $sOrder .= ', CER.ID ' . $ord; break; case 'CREATED_BY_ID': $sOrder .= ', CE.CREATED_BY_ID ' . $ord; break; case 'EVENT_TYPE': $sOrder .= ', CE.EVENT_TYPE ' . $ord; break; case 'ENTITY_TYPE': $sOrder .= ', CER.ENTITY_TYPE ' . $ord; break; case 'ENTITY_ID': $sOrder .= ', CER.ENTITY_ID ' . $ord; break; case 'EVENT_ID': $sOrder .= ', CE.EVENT_ID ' . $ord; break; case 'DATE_CREATE': $sOrder .= ', CE.DATE_CREATE ' . $ord; break; case 'EVENT_NAME': $sOrder .= ', CE.EVENT_NAME ' . $ord; break; case 'ENTITY_FIELD': $sOrder .= ', CER.ENTITY_FIELD ' . $ord; break; } } if (strlen($sOrder) <= 0) { $sOrder = 'CER.ID DESC'; } $strSqlOrder = ' ORDER BY ' . TrimEx($sOrder, ','); // where $arWhereFields = array('ID' => array('TABLE_ALIAS' => 'CER', 'FIELD_NAME' => 'CER.ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'ENTITY_TYPE' => array('TABLE_ALIAS' => 'CER', 'FIELD_NAME' => 'CER.ENTITY_TYPE', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'EVENT_REL_ID' => array('TABLE_ALIAS' => 'CER', 'FIELD_NAME' => 'CER.EVENT_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'EVENT_ID' => array('TABLE_ALIAS' => 'CE', 'FIELD_NAME' => 'CE.EVENT_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'CREATED_BY_ID' => array('TABLE_ALIAS' => 'CE', 'FIELD_NAME' => 'CE.CREATED_BY_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'ASSIGNED_BY_ID' => array('TABLE_ALIAS' => 'CER', 'FIELD_NAME' => 'CER.ASSIGNED_BY_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'EVENT_TYPE' => array('TABLE_ALIAS' => 'CE', 'FIELD_NAME' => 'CE.EVENT_TYPE', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'EVENT_DESC' => array('TABLE_ALIAS' => 'CE', 'FIELD_NAME' => 'CE.EVENT_TEXT_1', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'ENTITY_ID' => array('TABLE_ALIAS' => 'CER', 'FIELD_NAME' => 'CER.ENTITY_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'ENTITY_FIELD' => array('TABLE_ALIAS' => 'CER', 'FIELD_NAME' => 'CER.ENTITY_FIELD', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'DATE_CREATE' => array('TABLE_ALIAS' => 'CE', 'FIELD_NAME' => 'CE.DATE_CREATE', 'FIELD_TYPE' => 'datetime', 'JOIN' => false)); $obQueryWhere = new CSQLWhere(); $obQueryWhere->SetFields($arWhereFields); if (!is_array($arFilter)) { $arFilter = array(); } $sQueryWhereFields = $obQueryWhere->GetQuery($arFilter); if (!empty($sQueryWhereFields)) { $strSqlSearch .= "\n\t\t\t\tAND ({$sQueryWhereFields}) "; } $strSql = "\n\t\t\tSELECT\n\t\t\t\tCER.ID,\n\t\t\t\tCER.ENTITY_TYPE,\n\t\t\t\tCER.ENTITY_ID,\n\t\t\t\tCER.ENTITY_FIELD,\n\t\t\t\t" . $DB->DateToCharFunction('CE.DATE_CREATE') . " DATE_CREATE,\n\t\t\t\tCER.EVENT_ID,\n\t\t\t\tCE.EVENT_NAME,\n\t\t\t\tCE.EVENT_TYPE,\n\t\t\t\tCE.EVENT_TEXT_1,\n\t\t\t\tCE.EVENT_TEXT_2,\n\t\t\t\tCE.FILES,\n\t\t\t\tCE.CREATED_BY_ID,\n\t\t\t\tU.LOGIN as CREATED_BY_LOGIN,\n\t\t\t\tU.NAME as CREATED_BY_NAME,\n\t\t\t\tU.LAST_NAME as CREATED_BY_LAST_NAME,\n\t\t\t\tU.SECOND_NAME as CREATED_BY_SECOND_NAME\n\t\t\tFROM\n\t\t\t\tb_crm_event_relations CER,\n\t\t\t\tb_crm_event CE LEFT JOIN b_user U ON CE.CREATED_BY_ID = U.ID\n\t\t\tWHERE\n\t\t\t\tCER.EVENT_ID = CE.ID\n\t\t\t\t{$strSqlSearch}\n\t\t\t\t{$strPermission}\n\t\t\t\t{$strSqlOrder}"; if ($nPageTop !== false) { $nPageTop = (int) $nPageTop; $strSql = $DB->TopSql($strSql, $nPageTop); } $res = $DB->Query($strSql, false, $err_mess . __LINE__); $res->SetUserFields(array('FILES' => array('MULTIPLE' => 'Y'))); return $res; }
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; } } } } } } } } } } } }