Example #1
0
 public static function RenderResponsiblePanel($arParams)
 {
     $prefix = isset($arParams['PREFIX']) ? $arParams['PREFIX'] : '';
     $editable = isset($arParams['EDITABLE']) ? $arParams['EDITABLE'] : false;
     $userProfileUrlTemplate = isset($arParams['USER_PROFILE_URL_TEMPLATE']) ? $arParams['USER_PROFILE_URL_TEMPLATE'] : '';
     $userID = isset($arParams['USER_ID']) ? $arParams['USER_ID'] : '';
     $showUrl = $userID > 0 && $userProfileUrlTemplate !== '' ? str_replace('#user_id#', $userID, $userProfileUrlTemplate) : '#';
     echo '<div class="crm-detail-info-resp-block">';
     echo '<div class="crm-detail-info-resp-header">';
     echo '<span class="crm-detail-info-resp-text">', htmlspecialcharsbx(GetMessage('CRM_ENTITY_INFO_RESPONSIBLE')), '</span>';
     $editButtonID = '';
     if ($editable) {
         $editButtonID = isset($arParams['EDIT_BUTTON_ID']) ? $arParams['EDIT_BUTTON_ID'] : '';
         if ($editButtonID === '') {
             $editButtonID = $prefix !== '' ? "{$prefix}_responsible_edit" : 'responsible_edit';
         }
         echo '<span class="crm-detail-info-resp-edit" id="', htmlspecialcharsbx($editButtonID), '">', htmlspecialcharsbx(GetMessage('CRM_ENTITY_INFO_RESPONSIBLE_CHANGE')), '</span>';
     }
     echo '</div>';
     $containerID = isset($arParams['CONTAINER_ID']) ? $arParams['CONTAINER_ID'] : '';
     if ($containerID === '') {
         $containerID = $prefix !== '' ? "{$prefix}_responsible_container" : 'responsible_container';
     }
     echo '<a class="crm-detail-info-resp crm-detail-info-head-resp" id="', htmlspecialcharsbx($containerID), '" target="_blank" href="', htmlspecialcharsbx($showUrl), '">';
     echo '<div class="crm-detail-info-resp-img">';
     $photoUrl = isset($arParams['PHOTO_URL']) ? $arParams['PHOTO_URL'] : '';
     $photoID = isset($arParams['PHOTO']) ? intval($arParams['PHOTO']) : 0;
     if ($photoUrl === '' && $photoID > 0) {
         $photoInfo = CFile::ResizeImageGet($photoID, array('width' => 38, 'height' => 38), BX_RESIZE_IMAGE_EXACT);
         if (is_array($photoInfo) && isset($photoInfo['src'])) {
             $photoUrl = $photoInfo['src'];
         }
     }
     if ($photoUrl !== '') {
         echo '<img alt="" src="', htmlspecialcharsbx($photoUrl), '"/>';
     }
     echo '</div>';
     echo '<span class="crm-detail-info-resp-name">', isset($arParams['NAME']) ? htmlspecialcharsbx($arParams['NAME']) : '', '</span>';
     echo '<span class="crm-detail-info-resp-descr">', isset($arParams['WORK_POSITION']) ? htmlspecialcharsbx($arParams['WORK_POSITION']) : '', '</span>';
     echo '</a>';
     $serviceUrl = isset($arParams['SERVICE_URL']) ? $arParams['SERVICE_URL'] : '';
     $userInfoProviderID = isset($arParams['USER_INFO_PROVIDER_ID']) ? $arParams['USER_INFO_PROVIDER_ID'] : '';
     if ($userInfoProviderID === '') {
         $userInfoProviderID = $serviceUrl !== '' ? md5(strtolower($serviceUrl)) : '';
     }
     if ($userInfoProviderID !== '') {
         if (!self::$USER_INFO_PROVIDER_MESSAGES_REGISTRED) {
             echo '<script type="text/javascript">', 'BX.ready(function(){', 'BX.CrmUserInfoProvider.messages = ', '{ "generalError":"', GetMessageJS('CRM_GET_USER_INFO_GENERAL_ERROR'), '" }', '});', '</script>';
             self::$USER_INFO_PROVIDER_MESSAGES_REGISTRED = true;
         }
         echo '<script type="text/javascript">', 'BX.ready(function(){', 'BX.CrmUserInfoProvider.createIfNotExists(', '"', CUtil::JSEscape($userInfoProviderID), '",', '{ "serviceUrl":"', CUtil::JSEscape($serviceUrl), '", "userProfileUrlTemplate":"', CUtil::JSEscape($userProfileUrlTemplate), '" }', ');', '});', '</script>';
     }
     $instantEditorID = isset($arParams['INSTANT_EDITOR_ID']) ? $arParams['INSTANT_EDITOR_ID'] : '';
     $fieldID = isset($arParams['FIELD_ID']) ? $arParams['FIELD_ID'] : '';
     if (!$editable) {
         echo '<script type="text/javascript">', 'BX.ready(function(){', 'BX.CrmUserLinkField.create(', '{', '"containerId":"', CUtil::JSEscape($containerID), '"', ', "userInfoProviderId":"', CUtil::JSEscape($userInfoProviderID), '"', ', "editorId":"', CUtil::JSEscape($instantEditorID), '"', ', "fieldId":"', CUtil::JSEscape($fieldID), '"', '}', ');', '});', '</script>';
     } else {
         $userSelectorName = isset($arParams['USER_SELECTOR_NAME']) ? $arParams['USER_SELECTOR_NAME'] : '';
         if ($userSelectorName === '') {
             $userSelectorName = $prefix !== '' ? "{$prefix}_responsible_selector" : 'responsible_selector';
         }
         $enableLazyLoad = isset($arParams['ENABLE_LAZY_LOAD']) ? $arParams['ENABLE_LAZY_LOAD'] : false;
         if ($enableLazyLoad) {
             $GLOBALS['APPLICATION']->AddHeadScript('/bitrix/components/bitrix/intranet.user.selector.new/templates/.default/users.js');
             $GLOBALS['APPLICATION']->SetAdditionalCSS('/bitrix/components/bitrix/intranet.user.selector.new/templates/.default/style.css');
         } else {
             $GLOBALS['APPLICATION']->IncludeComponent('bitrix:intranet.user.selector.new', '.default', array('MULTIPLE' => 'N', 'NAME' => $userSelectorName, 'POPUP' => 'Y', 'SITE_ID' => SITE_ID), null, array('HIDE_ICONS' => 'Y'));
         }
         echo '<script type="text/javascript">';
         echo 'BX.ready(function(){';
         echo 'BX.CrmSidebarUserSelector.create(', '"', $userSelectorName, '", ', 'BX("', CUtil::JSEscape($editButtonID), '"), ', 'BX("', CUtil::JSEscape($containerID), '"), ', '"', CUtil::JSEscape($userSelectorName), '", ', '{', '"userInfoProviderId":"', CUtil::JSEscape($userInfoProviderID), '"', ', "editorId":"', CUtil::JSEscape($instantEditorID), '"', ', "fieldId":"', CUtil::JSEscape($fieldID), '"', ', "enableLazyLoad":', $enableLazyLoad ? 'true' : 'false', ', "serviceUrl":"', CUtil::JSEscape($serviceUrl), '"', '}', ');';
         echo '});';
         echo '</script>';
     }
     echo '</div>';
 }