echo CUtil::PhpToJSObject(array('DATA' => array('ELEMENT_ID' => $elementID, 'INFO' => \Bitrix\Crm\Integration\StorageManager::getFileInfo($elementID, \Bitrix\Crm\Integration\StorageType::WebDav)))); die; } elseif ($action == 'GET_COMMUNICATION_HTML') { $typeName = isset($_POST['TYPE_NAME']) ? strval($_POST['TYPE_NAME']) : ''; $value = isset($_POST['VALUE']) ? strval($_POST['VALUE']) : ''; echo CUtil::PhpToJSObject(array('DATA' => array('HTML' => CCrmViewHelper::PrepareMultiFieldHtml($typeName, array('VALUE_TYPE_ID' => 'WORK', 'VALUE' => $value))))); die; } elseif ($action == 'PREPARE_MAIL_TEMPLATE') { $templateID = isset($_POST['TEMPLATE_ID']) ? intval($_POST['TEMPLATE_ID']) : 0; $ownerTypeName = isset($_POST['OWNER_TYPE']) ? strtoupper(strval($_POST['OWNER_TYPE'])) : ''; $ownerID = isset($_POST['OWNER_ID']) ? intval($_POST['OWNER_ID']) : 0; if ($templateID <= 0) { echo CUtil::PhpToJSObject(array('ERROR' => 'Invalid data')); die; } $dbResult = CCrmMailTemplate::GetList(array(), array('=ID' => $templateID), false, false, array('OWNER_ID', 'ENTITY_TYPE_ID', 'SCOPE', 'EMAIL_FROM', 'SUBJECT', 'BODY')); $fields = $dbResult->Fetch(); if (!is_array($fields)) { echo CUtil::PhpToJSObject(array('ERROR' => 'Invalid data')); die; } $templateOwnerID = isset($fields['OWNER_ID']) ? intval($fields['OWNER_ID']) : 0; $templateScope = isset($fields['SCOPE']) ? intval($fields['SCOPE']) : CCrmMailTemplateScope::Undefined; if ($templateScope !== CCrmMailTemplateScope::Common && $templateOwnerID !== intval($curUser->GetID())) { echo CUtil::PhpToJSObject(array('ERROR' => 'Invalid data')); die; } $body = isset($fields['BODY']) ? $fields['BODY'] : ''; if ($body !== '') { $contentTypeID = isset($_POST['CONTENT_TYPE']) ? CCrmContentType::ResolveTypeID($_POST['CONTENT_TYPE']) : CCrmContentType::Undefined; if (!CCrmContentType::IsDefined($contentTypeID)) {
$errors[] = GetMessage('CRM_MAIL_TEMPLATE_ADD_UNKNOWN_ERROR'); } } } if (!empty($errors)) { ShowError(implode("\n", $errors)); } else { if (isset($_POST['apply'])) { LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_MAIL_TEMPLATE_EDIT'], array('element_id' => $elementID))); } else { LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_MAIL_TEMPLATE_LIST'])); } } } elseif ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['delete'])) { if (CCrmMailTemplate::Exists($elementID) && !CCrmMailTemplate::Delete($elementID)) { $errors = CCrmMailTemplate::GetErrorMessages(); if (empty($errors)) { $errors[] = GetMessage('CRM_MAIL_TEMPLATE_DELETE_UNKNOWN_ERROR'); } ShowError(implode("\n", $errors)); return; } LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_MAIL_TEMPLATE_LIST'])); } } $arResult['ELEMENT_ID'] = $elementID; $arResult['ELEMENT'] = $element; $isEditMode = $elementID > 0; $arResult['FORM_ID'] = $arResult['GRID_ID'] = 'CRM_MAIL_TEMPLATE_EDIT'; $arResult['BACK_URL'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_MAIL_TEMPLATE_LIST'], array()); $arResult['FIELDS']['tab_1'][] = array('ID' => 'TITLE', 'NAME' => GetMessage('CRM_MAIL_TEMPLATE_TITLE'), 'VALUE' => isset($element['TITLE']) ? $element['TITLE'] : '', 'REQUIRED' => true);
$mailTemplate = COption::GetOptionString('crm', 'email_template'); $mailTemplate = CAllCrmMailTemplate::ConvertHtmlToBbCode($mailTemplate); if ($mailFrom !== '' || $mailTemplate !== '') { $element = array(); $element['TITLE'] = GetMessage('CRM_MAIL_TEMPLATE_COMMON_TEMPLATE_NAME'); $element['IS_ACTIVE'] = 'Y'; $element['OWNER_ID'] = CCrmSecurityHelper::GetCurrentUserID(); $element['SORT'] = 100; $element['EMAIL_FROM'] = $mailFrom; $element['SCOPE'] = CCrmMailTemplateScope::Common; $element['SUBJECT'] = ''; $element['BODY'] = $mailTemplate; $entityTypes = array(CCrmOwnerType::Lead, CCrmOwnerType::Deal, CCrmOwnerType::Contact, CCrmOwnerType::Company); foreach ($entityTypes as $entityTypeID) { $element['ENTITY_TYPE_ID'] = $entityTypeID; CCrmMailTemplate::Add($element); } } COption::SetOptionString('crm', '~CRM_MAIL_TEMPLATE_LIST_CONVERTING', 'Y'); } elseif ($conv === 'SKIP') { COption::SetOptionString('crm', '~CRM_MAIL_TEMPLATE_LIST_CONVERTING', 'Y'); } elseif ($conv === 'RESET') { COption::RemoveOption('crm', '~CRM_MAIL_TEMPLATE_LIST_CONVERTING'); } } LocalRedirect(CHTTP::urlDeleteParams($curPageUrl, array('conv'))); } } $gridOptions = new CCrmGridOptions($arResult['GRID_ID']); $gridSorting = $gridOptions->GetSorting(array('sort' => array('SORT' => 'asc'), 'vars' => array('by' => 'by', 'order' => 'order'))); $sort = $arResult['SORT'] = $gridSorting['sort'];
} if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } global $USER, $APPLICATION; $curPageUrl = $APPLICATION->GetCurPage(); $arParams['PATH_TO_MAIL_TEMPLATE_LIST'] = CrmCheckPath('PATH_TO_MAIL_TEMPLATE_LIST', $arParams['PATH_TO_MAIL_TEMPLATE_LIST'], $curPageUrl); $arParams['PATH_TO_MAIL_TEMPLATE_EDIT'] = CrmCheckPath('PATH_TO_MAIL_TEMPLATE_EDIT', $arParams['PATH_TO_MAIL_TEMPLATE_EDIT'], $curPageUrl . '?element_id=#element_id#&edit'); $arParams['PATH_TO_MAIL_TEMPLATE_ADD'] = CrmCheckPath('PATH_TO_MAIL_TEMPLATE_ADD', $arParams['PATH_TO_MAIL_TEMPLATE_ADD'], $curPageUrl . '?add'); if (!isset($arParams['TYPE'])) { $arParams['TYPE'] = 'list'; } $arResult['BUTTONS'] = array(); $elementID = isset($arParams['ELEMENT_ID']) ? intval($arParams['ELEMENT_ID']) : 0; if (!CCrmPerms::IsAccessEnabled()) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } $elementAdd = $elementEdit = $elementDelete = true; $exists = $elementID > 0 && CCrmMailTemplate::Exists($elementID); if ($arParams['TYPE'] !== 'list') { $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_MAIL_TEMPLATE_LIST'), 'TITLE' => GetMessage('CRM_MAIL_TEMPLATE_LIST_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_MAIL_TEMPLATE_LIST'], array()), 'ICON' => 'btn-list'); } if ($elementAdd) { $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_MAIL_TEMPLATE_ADD'), 'TITLE' => GetMessage('CRM_MAIL_TEMPLATE_ADD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_MAIL_TEMPLATE_ADD'], array()), 'ICON' => 'btn-new'); } if ($elementDelete && $arParams['TYPE'] == 'edit' && $exists) { $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_MAIL_TEMPLATE_DELETE'), 'TITLE' => GetMessage('CRM_MAIL_TEMPLATE_DELETE_TITLE'), 'LINK' => "javascript:crm_mail_template_delete('" . GetMessageJS('CRM_MAIL_TEMPLATE_DELETE_DLG_TITLE') . "', '" . GetMessageJS('CRM_MAIL_TEMPLATE_DELETE_DLG_MESSAGE') . "', '" . GetMessageJS('CRM_MAIL_TEMPLATE_DELETE_DLG_BTNTITLE') . "', '" . CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_MAIL_TEMPLATE_EDIT'], array('element_id' => $elementID)), array('delete' => '', 'sessid' => bitrix_sessid())) . "')", 'ICON' => 'btn-delete'); } $this->IncludeComponentTemplate();