Esempio n. 1
0
 public static function TrySendEmail($ID, &$arFields, &$arErrors)
 {
     global $APPLICATION;
     if (!CModule::IncludeModule('subscribe')) {
         $arErrors[] = array('CODE' => self::ERR_CANT_LOAD_SUBSCRIBE);
         return false;
     }
     $ID = intval($ID);
     if ($ID <= 0 && isset($arFields['ID'])) {
         $ID = intval($arFields['ID']);
     }
     if ($ID <= 0 || !is_array($arFields)) {
         $arErrors[] = array('CODE' => self::ERR_INVALID_DATA);
         return false;
     }
     $typeID = isset($arFields['TYPE_ID']) ? intval($arFields['TYPE_ID']) : CCrmActivityType::Undefined;
     if ($typeID !== CCrmActivityType::Email) {
         $arErrors[] = array('CODE' => self::ERR_INVALID_DATA);
         return false;
     }
     $urn = CCrmActivity::PrepareUrn($arFields);
     if (!($urn !== '' && CCrmActivity::Update($ID, array('URN' => $urn), false, false))) {
         $arErrors[] = array('CODE' => self::ERR_CANT_UPDATE_ACTIVITY);
         return false;
     }
     $settings = isset($arFields['SETTINGS']) && is_array($arFields['SETTINGS']) ? $arFields['SETTINGS'] : array();
     // Creating Email -->
     $crmEmail = CCrmMailHelper::ExtractEmail(COption::GetOptionString('crm', 'mail', ''));
     $from = isset($settings['MESSAGE_FROM']) ? trim(strval($settings['MESSAGE_FROM'])) : '';
     if ($from === '') {
         if ($crmEmail !== '') {
             $from = $crmEmail;
         } else {
             $arErrors[] = array('CODE' => self::ERR_CANT_FIND_EMAIL_FROM);
         }
     } elseif (!check_email($from)) {
         $arErrors[] = array('CODE' => self::ERR_INVALID_EMAIL, 'DATA' => array('EMAIL' => $from));
     }
     //Save user email in settings -->
     if ($from !== CUserOptions::GetOption('crm', 'activity_email_addresser', '')) {
         CUserOptions::SetOption('crm', 'activity_email_addresser', $from);
     }
     //<-- Save user email in settings
     $to = array();
     $commData = isset($arFields['COMMUNICATIONS']) ? $arFields['COMMUNICATIONS'] : array();
     foreach ($commData as &$commDatum) {
         $commType = isset($commDatum['TYPE']) ? strtoupper(strval($commDatum['TYPE'])) : '';
         $commValue = isset($commDatum['VALUE']) ? strval($commDatum['VALUE']) : '';
         if ($commType !== 'EMAIL' || $commValue === '') {
             continue;
         }
         if (!check_email($commValue)) {
             $arErrors[] = array('CODE' => self::ERR_INVALID_EMAIL, 'DATA' => array('EMAIL' => $commValue));
             continue;
         }
         $to[] = strtolower(trim($commValue));
     }
     unset($commDatum);
     if (count($to) == 0) {
         $arErrors[] = array('CODE' => self::ERR_CANT_FIND_EMAIL_TO);
     }
     if (!empty($arErrors)) {
         return false;
     }
     // Try to resolve posting charset -->
     $postingCharset = '';
     $siteCharset = defined('LANG_CHARSET') ? LANG_CHARSET : (defined('SITE_CHARSET') ? SITE_CHARSET : 'windows-1251');
     $arSupportedCharset = explode(',', COption::GetOptionString('subscribe', 'posting_charset'));
     if (count($arSupportedCharset) === 0) {
         $postingCharset = $siteCharset;
     } else {
         foreach ($arSupportedCharset as $curCharset) {
             if (strcasecmp($curCharset, $siteCharset) === 0) {
                 $postingCharset = $curCharset;
                 break;
             }
         }
         if ($postingCharset === '') {
             $postingCharset = $arSupportedCharset[0];
         }
     }
     //<-- Try to resolve posting charset
     $subject = isset($arFields['SUBJECT']) ? $arFields['SUBJECT'] : '';
     $description = isset($arFields['DESCRIPTION']) ? $arFields['DESCRIPTION'] : '';
     $descriptionType = isset($arFields['DESCRIPTION_TYPE']) ? intval($arFields['DESCRIPTION_TYPE']) : CCrmContentType::PlainText;
     $descriptionHtml = '';
     if ($descriptionType === CCrmContentType::Html) {
         $descriptionHtml = $description;
     } elseif ($descriptionType === CCrmContentType::BBCode) {
         $parser = new CTextParser();
         $descriptionHtml = $parser->convertText($description);
     } elseif ($descriptionType === CCrmContentType::PlainText) {
         $descriptionHtml = htmlspecialcharsbx($description);
     }
     $postingData = array('STATUS' => 'D', 'FROM_FIELD' => $from, 'TO_FIELD' => $from, 'BCC_FIELD' => implode(',', $to), 'SUBJECT' => $subject, 'BODY_TYPE' => 'html', 'BODY' => $descriptionHtml, 'DIRECT_SEND' => 'Y', 'SUBSCR_FORMAT' => 'html', 'CHARSET' => $postingCharset);
     CCrmActivity::InjectUrnInMessage($postingData, $urn, CCrmEMailCodeAllocation::GetCurrent());
     $posting = new CPosting();
     $postingID = $posting->Add($postingData);
     if ($postingID === false) {
         $arErrors[] = array('CODE' => self::ERR_CANT_ADD_POSTING, 'MESSAGE' => $posting->LAST_ERROR);
         return false;
     }
     $arUpdateFields = array('COMPLETED' => 'Y', 'ASSOCIATED_ENTITY_ID' => $postingID, 'SETTINGS' => $settings);
     $fromEmail = strtolower(trim(CCrmMailHelper::ExtractEmail($from)));
     if ($crmEmail !== '' && $fromEmail !== $crmEmail) {
         $arUpdateFields['SETTINGS']['MESSAGE_HEADERS'] = array('Reply-To' => "<{$fromEmail}>, <{$crmEmail}>");
     }
     $arUpdateFields['SETTINGS']['IS_MESSAGE_SENT'] = true;
     if (!CCrmActivity::Update($ID, $arUpdateFields, false, false)) {
         $arErrors[] = array('CODE' => self::ERR_CANT_UPDATE_ACTIVITY);
         return false;
     }
     // <-- Creating Email
     // Attaching files -->
     $storageTypeID = isset($arFields['STORAGE_TYPE_ID']) ? intval($arFields['STORAGE_TYPE_ID']) : StorageType::Undefined;
     $storageElementsID = isset($arFields['STORAGE_ELEMENT_IDS']) && is_array($arFields['STORAGE_ELEMENT_IDS']) ? $arFields['STORAGE_ELEMENT_IDS'] : array();
     $arRawFiles = StorageManager::makeFileArray($storageElementsID, $storageTypeID);
     foreach ($arRawFiles as &$arRawFile) {
         if (!$posting->SaveFile($postingID, $arRawFile)) {
             $arErrors[] = array('CODE' => self::ERR_CANT_SAVE_POSTING_FILE, 'MESSAGE' => $posting->LAST_ERROR);
             return false;
         }
     }
     unset($arRawFile);
     // <-- Attaching files
     // Sending Email -->
     if ($posting->ChangeStatus($postingID, 'P')) {
         $rsAgents = CAgent::GetList(array('ID' => 'DESC'), array('MODULE_ID' => 'subscribe', 'NAME' => 'CPosting::AutoSend(' . $postingID . ',%'));
         if (!$rsAgents->Fetch()) {
             CAgent::AddAgent('CPosting::AutoSend(' . $postingID . ',true);', 'subscribe', 'N', 0);
         }
     }
     // Try add event to entity
     $CCrmEvent = new CCrmEvent();
     $ownerID = isset($arFields['OWNER_ID']) ? intval($arFields['OWNER_ID']) : 0;
     $ownerTypeID = isset($arFields['OWNER_TYPE_ID']) ? intval($arFields['OWNER_TYPE_ID']) : 0;
     if ($ownerID > 0 && $ownerTypeID > 0) {
         $eventText = '';
         $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_SUBJECT') . ': ' . $subject . "\n\r";
         $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_FROM') . ': ' . $from . "\n\r";
         $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_TO') . ': ' . implode(',', $to) . "\n\r\n\r";
         $eventText .= $description;
         // Register event only for owner
         $CCrmEvent->Add(array('ENTITY' => array($ownerID => array('ENTITY_TYPE' => CCrmOwnerType::ResolveName($ownerTypeID), 'ENTITY_ID' => $ownerID)), 'EVENT_ID' => 'MESSAGE', 'EVENT_TEXT_1' => $eventText, 'FILES' => $arRawFiles));
     }
     // <-- Sending Email
     return true;
 }
Esempio n. 2
0
            if ($_POST['DEAL_DEFAULT_LIST_VIEW']) {
                \Bitrix\Crm\Settings\DealSettings::setDefaultListViewID($_POST['DEAL_DEFAULT_LIST_VIEW']);
            }
            LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_SM_CONFIG'], array()));
        }
    }
}
$arResult['FORM_ID'] = 'CRM_SM_CONFIG';
$arResult['BACK_URL'] = $arParams['PATH_TO_SM_CONFIG'];
$arResult['FIELDS'] = array();
$arResult['FIELDS']['tab_deal_config'][] = array('id' => 'DEAL_DEFAULT_LIST_VIEW', 'name' => GetMessage('CRM_FIELD_DEAL_DEFAULT_LIST_VIEW'), 'items' => \Bitrix\Crm\Settings\DealSettings::getViewDescriptions(), 'type' => 'list', 'value' => \Bitrix\Crm\Settings\DealSettings::getDefaultListViewID(), 'required' => false);
$arResult['FIELDS']['tab_deal_config'][] = array('id' => 'REFRESH_DEAL_CLOSEDATE', 'name' => GetMessage('CRM_FIELD_REFRESH_DEAL_CLOSEDATE'), 'type' => 'checkbox', 'value' => \Bitrix\Crm\Settings\DealSettings::isCloseDateSyncEnabled(), 'required' => false);
$arResult['FIELDS']['tab_activity_config'][] = array('id' => 'CALENDAR_DISPLAY_COMPLETED_CALLS', 'name' => GetMessage('CRM_FIELD_DISPLAY_COMPLETED_CALLS_IN_CALENDAR'), 'type' => 'checkbox', 'value' => CCrmActivityCalendarSettings::GetValue(CCrmActivityCalendarSettings::DisplayCompletedCalls, true), 'required' => false);
$arResult['FIELDS']['tab_activity_config'][] = array('id' => 'CALENDAR_DISPLAY_COMPLETED_MEETINGS', 'name' => GetMessage('CRM_FIELD_DISPLAY_COMPLETED_MEETINGS_IN_CALENDAR'), 'type' => 'checkbox', 'value' => CCrmActivityCalendarSettings::GetValue(CCrmActivityCalendarSettings::DisplayCompletedMeetings, true), 'required' => false);
$arResult['FIELDS']['tab_activity_config'][] = array('id' => 'RECKON_ACTIVITYLESS_ITEMS_IN_COUNTERS', 'name' => GetMessage('CRM_FIELD_RECKON_ACTIVITYLESS_ITEMS_IN_COUNTERS'), 'type' => 'checkbox', 'value' => CCrmUserCounterSettings::GetValue(CCrmUserCounterSettings::ReckonActivitylessItems, true), 'required' => false);
$arResult['FIELDS']['tab_outgoing_email'][] = array('id' => 'SERVICE_CODE_ALLOCATION', 'name' => GetMessage('CRM_FIELD_SERVICE_CODE_ALLOCATION'), 'items' => CCrmEMailCodeAllocation::GetAllDescriptions(), 'type' => 'list', 'value' => CCrmEMailCodeAllocation::GetCurrent(), 'required' => false);
if (Bitrix\Crm\Integration\Bitrix24Email::isEnabled()) {
    if (Bitrix\Crm\Integration\Bitrix24Email::allowDisableSignature()) {
        $arResult['FIELDS']['tab_outgoing_email'][] = array('id' => 'ENABLE_B24_EMAIL_SIGNATURE', 'name' => GetMessage('CRM_FIELD_ENABLE_B24_EMAIL_SIGNATURE'), 'type' => 'checkbox', 'value' => Bitrix\Crm\Integration\Bitrix24Email::isSignatureEnabled(), 'required' => false);
    } else {
        $arResult['FIELDS']['tab_outgoing_email'][] = array('id' => 'ENABLE_B24_EMAIL_SIGNATURE', 'name' => GetMessage('CRM_FIELD_ENABLE_B24_EMAIL_SIGNATURE'), 'type' => 'label', 'value' => Bitrix\Crm\Integration\Bitrix24Email::getSignatureExplanation(), 'required' => false);
    }
}
$arResult['FIELDS']['tab_format'][] = array('id' => 'PERSON_NAME_FORMAT_ID', 'name' => GetMessage('CRM_FIELD_PERSON_NAME_FORMAT'), 'type' => 'list', 'items' => \Bitrix\Crm\Format\PersonNameFormatter::getAllDescriptions(), 'value' => \Bitrix\Crm\Format\PersonNameFormatter::getFormatID(), 'required' => false);
$arResult['FIELDS']['tab_format'][] = array('id' => 'CALLTO_FORMAT', 'name' => GetMessage('CRM_FIELD_CALLTO_FORMAT'), 'type' => 'list', 'items' => CCrmCallToUrl::GetAllDescriptions(), 'value' => CCrmCallToUrl::GetFormat(CCrmCallToUrl::Bitrix), 'required' => false);
$calltoSettings = CCrmCallToUrl::GetCustomSettings();
$arResult['FIELDS']['tab_format'][] = array('id' => 'CALLTO_URL_TEMPLATE', 'name' => GetMessage('CRM_FIELD_CALLTO_URL_TEMPLATE'), 'type' => 'text', 'value' => isset($calltoSettings['URL_TEMPLATE']) ? $calltoSettings['URL_TEMPLATE'] : 'callto:[phone]', 'required' => false);
$arResult['FIELDS']['tab_format'][] = array('id' => 'CALLTO_CLICK_HANDLER', 'name' => GetMessage('CRM_FIELD_CALLTO_CLICK_HANDLER'), 'type' => 'textarea', 'value' => isset($calltoSettings['CLICK_HANDLER']) ? $calltoSettings['CLICK_HANDLER'] : '', 'required' => false);
$arResult['FIELDS']['tab_format'][] = array('id' => 'CALLTO_NORMALIZE_NUMBER', 'name' => GetMessage('CRM_FIELD_CALLTO_NORMALIZE_NUMBER'), 'type' => 'checkbox', 'value' => isset($calltoSettings['NORMALIZE_NUMBER']) ? $calltoSettings['NORMALIZE_NUMBER'] === 'Y' : true, 'required' => false);
$arResult['FIELDS']['tab_format'][] = array('id' => 'section_address_format', 'name' => GetMessage('CRM_SECTION_ADDRESS_FORMAT'), 'type' => 'section');
$curAddrFormatID = \Bitrix\Crm\Format\EntityAddressFormatter::getFormatID();
Esempio n. 3
0
 if (count($arSupportedCharset) === 0) {
     $postingCharset = $siteCharset;
 } else {
     foreach ($arSupportedCharset as $curCharset) {
         if (strcasecmp($curCharset, $siteCharset) === 0) {
             $postingCharset = $curCharset;
             break;
         }
     }
     if ($postingCharset === '') {
         $postingCharset = $arSupportedCharset[0];
     }
 }
 //<-- Try to resolve posting charset
 $postingData = array('STATUS' => 'D', 'FROM_FIELD' => $from, 'TO_FIELD' => $from, 'BCC_FIELD' => implode(',', $to), 'SUBJECT' => $subject, 'BODY_TYPE' => 'html', 'BODY' => $messageHtml !== '' ? $messageHtml : GetMessage('CRM_EMAIL_ACTION_DEFAULT_DESCRIPTION'), 'DIRECT_SEND' => 'Y', 'SUBSCR_FORMAT' => 'html', 'CHARSET' => $postingCharset);
 CCrmActivity::InjectUrnInMessage($postingData, $urn, CCrmEMailCodeAllocation::GetCurrent());
 $posting = new CPosting();
 $postingID = $posting->Add($postingData);
 if ($postingID === false) {
     $arErrors[] = GetMessage('CRM_ACTIVITY_COULD_NOT_CREATE_POSTING');
     $arErrors[] = $posting->LAST_ERROR;
 } else {
     // Attaching files -->
     $arRawFiles = isset($arFields['STORAGE_ELEMENT_IDS']) && !empty($arFields['STORAGE_ELEMENT_IDS']) ? \Bitrix\Crm\Integration\StorageManager::makeFileArray($arFields['STORAGE_ELEMENT_IDS'], $storageTypeID) : array();
     foreach ($arRawFiles as &$arRawFile) {
         if (isset($arRawFile['ORIGINAL_NAME'])) {
             $arRawFile['name'] = $arRawFile['ORIGINAL_NAME'];
         }
         if (!$posting->SaveFile($postingID, $arRawFile)) {
             $arErrors[] = GetMessage('CRM_ACTIVITY_COULD_NOT_SAVE_POSTING_FILE', array('#FILE_NAME#' => $arRawFile['ORIGINAL_NAME']));
             $arErrors[] = $posting->LAST_ERROR;
Esempio n. 4
0
 public static function GetAllDescriptions()
 {
     if (!self::$ALL_DESCRIPTIONS) {
         self::$ALL_DESCRIPTIONS = array(self::Body => GetMessage('CRM_EMAIL_CODE_ALLOCATION_BODY'), self::Subject => GetMessage('CRM_EMAIL_CODE_ALLOCATION_SUBJECT'), self::None => GetMessage('CRM_EMAIL_CODE_ALLOCATION_NONE'));
     }
     return self::$ALL_DESCRIPTIONS;
 }