case 'employee': if ($arField['SHOW_FILTER'] !== 'N') { $arField['SHOW_FILTER'] = 'I'; // Force exact match for 'USER' field type } break; default: $arField['SHOW_FILTER'] = 'N'; break; } if (!$strError) { if ($arResult['NEW_FIELD']) { $arResult['FIELD_ID'] = $arField['FIELD_NAME'] = $CCrmFields->GetNextFieldId(); $res = $CCrmFields->AddField($arField); } else { $res = $CCrmFields->UpdateField($arResult['FIELD']['ID'], $arField); } if ($res) { //Save default value for 'SHOW_IN_LIST' if ($arResult['NEW_FIELD']) { $defaultShowInList = CUserOptions::GetOption('crm', 'uf_show_in_list', 'N'); if ($arField['SHOW_IN_LIST'] === 'N' && $defaultShowInList !== 'N') { CUserOptions::DeleteOption('crm', 'uf_show_in_list'); } elseif ($arField['SHOW_IN_LIST'] === 'Y' && $defaultShowInList !== 'Y') { CUserOptions::SetOption('crm', 'uf_show_in_list', 'Y'); } } //Register/Unregister fild in entity list --> $gridID = CCrmGridOptions::GetDefaultGrigID(CCrmOwnerType::ResolveIDByUFEntityID($arResult['ENTITY_ID'])); if ($arField['SHOW_IN_LIST'] === 'Y') { CCrmGridOptions::AddVisibleColumn($gridID, $arResult['FIELD_ID']);
if ($_POST['action_button_' . $arResult['GRID_ID']] == 'edit' && isset($_POST['FIELDS']) && is_array($_POST['FIELDS'])) { $gridID = CCrmGridOptions::GetDefaultGrigID(CCrmOwnerType::ResolveIDByUFEntityID($arResult['ENTITY_ID'])); foreach ($_POST['FIELDS'] as $ID => &$arPostField) { $arPresetField = $CCrmFields->GetByID($ID); $arField = array(); //Sanitaizing foreach ($arPostField as $k => $v) { if (strpos($k, '~') === 0) { continue; } $arField[$k] = $v; } if (empty($arField)) { continue; } if (!$CCrmFields->UpdateField($ID, $arField)) { continue; } if (isset($arField['SHOW_IN_LIST']) && $arField['SHOW_IN_LIST'] !== $arPresetField['SHOW_IN_LIST']) { if ($arField['SHOW_IN_LIST'] === 'Y') { CCrmGridOptions::AddVisibleColumn($gridID, $arPresetField['FIELD_NAME']); } else { CCrmGridOptions::RemoveVisibleColumn($gridID, $arPresetField['FIELD_NAME']); } } } unset($arPostField); //Clear components cache $CACHE_MANAGER->ClearByTag('crm_fields_list_' . $arResult['ENTITY_ID']); } if ($_POST['action_all_rows_' . $arResult['GRID_ID']] == 'Y' && $_POST['action_button_' . $arResult['GRID_ID']] == 'delete') {