Exemplo n.º 1
0
 public static function addSignature(&$message, $contentType = 0)
 {
     if (!Bitrix24Manager::isEnabled()) {
         return false;
     }
     self::includeLangFile();
     $text = '';
     if (!Bitrix24Manager::isPaidAccount()) {
         $text = GetMessage('CRM_B24_EMAIL_FREE_LICENSE_SIGNATURE');
     } elseif (self::isSignatureEnabled()) {
         $text = GetMessage('CRM_B24_EMAIL_PAID_LICENSE_SIGNATURE');
     }
     if ($text === '') {
         return false;
     }
     if (!\CCrmContentType::IsDefined($contentType)) {
         $contentType = \CCrmContentType::PlainText;
     }
     if ($contentType === \CCrmContentType::BBCode) {
         $message .= "\n\n" . $text;
     } elseif ($contentType === \CCrmContentType::Html) {
         //Convert BBCODE to HTML
         $parser = new \CTextParser();
         $message .= "<br/><br/>" . $parser->convertText($text);
     } elseif ($contentType === \CCrmContentType::PlainText) {
         $message .= "\n\n" . preg_replace('/\\[[^\\]]+\\]/', '', $text);
     }
     return true;
 }
Exemplo n.º 2
0
 public static function PrepareTemplate($template, $entityTypeID, $entityID, $contentTypeID = 0)
 {
     $template = strval($template);
     if ($template === '') {
         return '';
     }
     $entityTypeName = CCrmOwnerType::ResolveName($entityTypeID);
     $entityID = intval($entityID);
     if ($entityTypeName === '' || $entityID <= 0) {
         return $template;
     }
     $matches = null;
     $result = preg_match_all('/#' . $entityTypeName . '\\.[^#]+#/i', $template, $matches, PREG_OFFSET_CAPTURE);
     if (!(is_int($result) && $result > 0)) {
         return $template;
     }
     $mapper = self::ResolveMapper($entityTypeID, $entityID);
     if ($mapper === null) {
         return $template;
     }
     $contentTypeID = intval($contentTypeID);
     if (!CCrmContentType::IsDefined($contentTypeID)) {
         $contentTypeID = CCrmContentType::PlainText;
     }
     $mapper->SetContentType($contentTypeID);
     $replaceKeys = array();
     $replaceValues = array();
     foreach ($matches[0] as &$match) {
         $key = $match[0];
         if (isset($replacements[$key])) {
             continue;
         }
         $path = substr($key, 1, strlen($key) - 2);
         $replaceKeys[] = $key;
         $replaceValues[] = $mapper->MapPath($path);
     }
     unset($match);
     return !empty($replaceKeys) ? str_replace($replaceKeys, $replaceValues, $template) : $template;
 }
Exemplo n.º 3
0
 public static function GetAllDescriptions()
 {
     if (!self::$ALL_DESCRIPTIONS) {
         self::$ALL_DESCRIPTIONS = array(self::Undefined => '', self::PlainText => 'Plain text', self::BBCode => 'bbCode', self::Html => 'HTML');
     }
     return self::$ALL_DESCRIPTIONS;
 }
Exemplo n.º 4
0
    $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)) {
            $contentTypeID = CCrmContentType::PlainText;
        }
        $body = CCrmTemplateManager::PrepareTemplate($body, CCrmOwnerType::ResolveID($ownerTypeName), $ownerID, $contentTypeID);
    }
    echo CUtil::PhpToJSObject(array('DATA' => array('ID' => $templateID, 'OWNER_TYPE' => $ownerTypeName, 'OWNER_ID' => $ownerID, 'FROM' => isset($fields['EMAIL_FROM']) ? $fields['EMAIL_FROM'] : '', 'SUBJECT' => isset($fields['SUBJECT']) ? $fields['SUBJECT'] : '', 'BODY' => $body)));
    die;
} elseif ($action == 'GET_ACTIVITY_COMMUNICATIONS') {
    $ID = isset($_POST['ID']) ? intval($_POST['ID']) : 0;
    echo CUtil::PhpToJSObject(array('ACTIVITY_COMMUNICATIONS' => GetCrmActivityCommunications($ID)));
    die;
} elseif ($action == 'GET_ACTIVITY_COMMUNICATIONS_PAGE') {
    $ID = isset($_POST['ID']) ? intval($_POST['ID']) : 0;
    $pageSize = isset($_POST['PAGE_SIZE']) ? intval($_POST['PAGE_SIZE']) : 20;
    $pageNumber = isset($_POST['PAGE_NUMBER']) ? intval($_POST['PAGE_NUMBER']) : 1;
    echo CUtil::PhpToJSObject(array('ACTIVITY_COMMUNICATIONS_PAGE' => GetCrmActivityCommunicationsPage($ID, $pageSize, $pageNumber)));
Exemplo n.º 5
0
 public function processMethodRequest($name, $nameDetails, $arParams, $nav, $server)
 {
     $descriptions = null;
     $name = strtoupper($name);
     if ($name === 'OWNERTYPE') {
         $descriptions = CCrmOwnerType::GetDescriptions(array(CCrmOwnerType::Lead, CCrmOwnerType::Deal, CCrmOwnerType::Contact, CCrmOwnerType::Company));
     } elseif ($name === 'CONTENTTYPE') {
         $descriptions = CCrmContentType::GetAllDescriptions();
     } elseif ($name === 'ACTIVITYTYPE') {
         $descriptions = CCrmActivityType::GetAllDescriptions();
     } elseif ($name === 'ACTIVITYPRIORITY') {
         $descriptions = CCrmActivityPriority::GetAllDescriptions();
     } elseif ($name === 'ACTIVITYDIRECTION') {
         $descriptions = CCrmActivityDirection::GetAllDescriptions();
     } elseif ($name === 'ACTIVITYNOTIFYTYPE') {
         $descriptions = CCrmActivityNotifyType::GetAllDescriptions();
     }
     if (!is_array($descriptions)) {
         return parent::processMethodRequest($name, $nameDetails, $arParams, $nav, $server);
     }
     $result = array();
     foreach ($descriptions as $k => &$v) {
         $result[] = array('ID' => $k, 'NAME' => $v);
     }
     unset($v);
     return $result;
 }