Требуется разработчик! Поддержка серверов

CFormResult::Mail: метод Битрикс

Постоянная ссылка: http://bxapi.ru/src/?id=175880

<?php 
//    CFormResult::Mail()
//    /bitrix/modules/form/classes/general/form_callformresult.php:1723

    
function Mail($RESULT_ID$TEMPLATE_ID false)
    {
        global 
$APPLICATION$DB$MESS$strError;

        
$err_mess = (CAllFormResult::err_mess())."<br>Function: Mail<br>Line: ";
        
$RESULT_ID intval($RESULT_ID);

        
CTimeZone::Disable();
        
$arrResult CFormResult::GetDataByID($RESULT_ID, array(), $arrRES$arrANSWER);
        
CTimeZone::Enable();
        if (
$arrResult)
        {
            
$z CForm::GetByID($arrRES["FORM_ID"]);
            if (
$arrFORM $z->Fetch())
            {
                
$TEMPLATE_ID intval($TEMPLATE_ID);

                
$arrFormSites CForm::GetSiteArray($arrRES["FORM_ID"]);
                
$arrFormSites = (is_array($arrFormSites)) ? $arrFormSites : array();

                if (!
defined('SITE_ID') || !in_array(SITE_ID$arrFormSites))
                    return 
true;

                
$rs CSite::GetList(($by="sort"), ($order="asc"), array('ID' => implode('|'$arrFormSites)));
                
$arrSites = array();
                while (
$ar $rs->Fetch())
                {
                    if (
$ar["DEF"]=="Y"$def_site_id $ar["ID"];
                    
$arrSites[$ar["ID"]] = $ar;
                }

                
$arrFormTemplates CForm::GetMailTemplateArray($arrRES["FORM_ID"]);
                
$arrFormTemplates = (is_array($arrFormTemplates)) ? $arrFormTemplates : array();

                
$arrTemplates = array();
                
$rs = 009542fd392d345f7dc6f8b877b868faCEventMessage::GetList($by="id"$order="asc", array(
                    
"ACTIVE"        => "Y",
                    
"SITE_ID"        => SITE_ID,
                    
"EVENT_NAME"    => $arrFORM["MAIL_EVENT_TYPE"]
                    ));

                while (
$ar $rs->Fetch())
                {
                    if (
$TEMPLATE_ID>0)
                    {
                        if (
$TEMPLATE_ID == $ar["ID"])
                        {
                            
$arrTemplates[$ar["ID"]] = $ar;
                            break;
                        }
                    }
                    elseif (
in_array($ar["ID"],$arrFormTemplates)) $arrTemplates[$ar["ID"]] = $ar;
                }

                foreach(
$arrTemplates as $arrTemplate)
                {

                    
$OLD_MESS $MESS;
                    
$MESS = array();
                    
IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/admin/form_mail.php"$arrSites[$arrTemplate["SITE_ID"]]["LANGUAGE_ID"]);

                    
$USER_AUTH " ";
                    if (
intval($arrRES["USER_ID"])>0)
                    {
                        
$w CUser::GetByID($arrRES["USER_ID"]);
                        
$arrUSER $w->Fetch();
                        
$USER_ID $arrUSER["ID"];
                        
$USER_EMAIL $arrUSER["EMAIL"];
                        
$USER_NAME $arrUSER["NAME"]." ".$arrUSER["LAST_NAME"];
                        if (
$arrRES["USER_AUTH"]!="Y"$USER_AUTH="(".GetMessage("FORM_NOT_AUTHORIZED").")";
                    }
                    else
                    {
                        
$USER_ID GetMessage("FORM_NOT_REGISTERED");
                        
$USER_NAME "";
                        
$USER_AUTH "";
                        
$USER_EMAIL "";
                    }

                    
$arEventFields = array(
                        
"RS_FORM_ID"            => $arrFORM["ID"],
                        
"RS_FORM_NAME"            => $arrFORM["NAME"],
                        
"RS_FORM_VARNAME"        => $arrFORM["SID"],
                        
"RS_FORM_SID"            => $arrFORM["SID"],
                        
"RS_RESULT_ID"            => $arrRES["ID"],
                        
"RS_DATE_CREATE"        => $arrRES["DATE_CREATE"],
                        
"RS_USER_ID"            => $USER_ID,
                        
"RS_USER_EMAIL"            => $USER_EMAIL,
                        
"RS_USER_NAME"            => $USER_NAME,
                        
"RS_USER_AUTH"            => $USER_AUTH,
                        
"RS_STAT_GUEST_ID"        => $arrRES["STAT_GUEST_ID"],
                        
"RS_STAT_SESSION_ID"    => $arrRES["STAT_SESSION_ID"]
                        );
                    
$w CFormField::GetList($arrFORM["ID"], "ALL"$by$order, array(), $is_filtered);
                    while (
$wr=$w->Fetch())
                    {
                        
$answer "";
                        
$answer_raw '';
                        if (
is_array($arrResult[$wr["SID"]]))
                        {
                            
$bHasDiffTypes false;
                            
$lastType '';
                            foreach (
$arrResult[$wr['SID']] as $arrA)
                            {
                                if (
$lastType == ''$lastType $arrA['FIELD_TYPE'];
                                elseif (
$arrA['FIELD_TYPE'] != $lastType)
                                {
                                    
$bHasDiffTypes true;
                                    break;
                                }
                            }

                            foreach(
$arrResult[$wr["SID"]] as $arrA)
                            {
                                if (
$wr['ADDITIONAL'] == 'Y')
                                    
$arrA['FIELD_TYPE'] = $wr['FIELD_TYPE'];

                                
$USER_TEXT_EXIST = (strlen(trim($arrA["USER_TEXT"]))>0);
                                
$ANSWER_TEXT_EXIST = (strlen(trim($arrA["ANSWER_TEXT"]))>0);
                                
$ANSWER_VALUE_EXIST = (strlen(trim($arrA["ANSWER_VALUE"]))>0);
                                
$USER_FILE_EXIST = (intval($arrA["USER_FILE_ID"])>0);

                                if (
$arrTemplate["BODY_TYPE"]=="html")
                                {
                                    if (
                                        
$bHasDiffTypes
                                        
&&
                                        !
$USER_TEXT_EXIST
                                        
&&
                                        (
                                            
$arrA['FIELD_TYPE'] == 'text'
                                            
||
                                            
$arrA['FIELD_TYPE'] == 'textarea'
                                        
)
                                    )
                                        continue;

                                    if (
strlen(trim($answer))>0$answer .= "<br />";
                                    if (
strlen(trim($answer_raw))>0$answer_raw .= ",";

                                    if (
$ANSWER_TEXT_EXIST)
                                        
$answer .= $arrA["ANSWER_TEXT"].': ';

                                    switch (
$arrA['FIELD_TYPE'])
                                    {
                                        case 
'text':
                                        case 
'textarea':
                                        case 
'hidden':
                                        case 
'date':
                                        case 
'password':
                                        case 
'integer':

                                            if (
$USER_TEXT_EXIST)
                                            {
                                                
$answer .= trim($arrA["USER_TEXT"]);
                                                
$answer_raw .= trim($arrA["USER_TEXT"]);
                                            }

                                        break;

                                        case 
'email':
                                        case 
'url':

                                            if (
$USER_TEXT_EXIST)
                                            {
                                                
$answer .= '<a href="'.($arrA['FIELD_TYPE'] == 'email' 'mailto:' '').trim($arrA["USER_TEXT"]).'">'.trim($arrA["USER_TEXT"]).'</a>';
                                                
$answer_raw .= trim($arrA["USER_TEXT"]);
                                            }

                                        break;

                                        case 
'checkbox':
                                        case 
'multiselect':
                                        case 
'radio':
                                        case 
'dropdown':

                                            if (
$ANSWER_TEXT_EXIST)
                                            {
                                                
$answer substr($answer0, -2).' ';
                                                
$answer_raw .= $arrA['ANSWER_TEXT'];
                                            }

                                            if (
$ANSWER_VALUE_EXIST)
                                            {
                                                
$answer .= '('.$arrA['ANSWER_VALUE'].') ';
                                                if (!
$ANSWER_TEXT_EXIST)
                                                    
$answer_raw .= $arrA['ANSWER_VALUE'];
                                            }

                                            if (!
$ANSWER_VALUE_EXIST && !$ANSWER_TEXT_EXIST)
                                                
$answer_raw .= $arrA['ANSWER_ID'];

                                            
$answer .= '['.$arrA['ANSWER_ID'].']';

                                        break;

                                        case 
'file':
                                        case 
'image':

                                            if (
$USER_FILE_EXIST)
                                            {
                                                
$f CFile::GetByID($arrA["USER_FILE_ID"]);
                                                if (
$fr $f->Fetch())
                                                {
                                                    
$file_size CFile::FormatSize($fr["FILE_SIZE"]);
                                                    
$url = ($APPLICATION->IsHTTPS() ? "https://" "http://").$_SERVER["HTTP_HOST"]. "/bitrix/tools/form_show_file.php?rid=".$RESULT_ID"&hash=".$arrA["USER_FILE_HASH"]."&lang=".LANGUAGE_ID;

                                                    if (
$arrA["USER_FILE_IS_IMAGE"]=="Y")
                                                    {
                                                        
$answer .= "<a href=\"$url\">".$arrA["USER_FILE_NAME"]."</a> [".$fr["WIDTH"]." x ".$fr["HEIGHT"]."] (".$file_size.")";
                                                    }
                                                    else
                                                    {
                                                        
$answer .= "<a href=\"$url&action=download\">".$arrA["USER_FILE_NAME"]."</a> (".$file_size.")";
                                                    }

                                                    
$answer_raw .= $arrA['USER_FILE_NAME'];
                                                }
                                            }

                                        break;
                                    }
                                }
                                else
                                {
                                    if (
                                        
$bHasDiffTypes
                                        
&&
                                        !
$USER_TEXT_EXIST
                                        
&&
                                        (
                                            
$arrA['FIELD_TYPE'] == 'text'
                                            
||
                                            
$arrA['FIELD_TYPE'] == 'textarea'
                                        
)
                                    )
                                        continue;

                                    if (
strlen(trim($answer)) > 0$answer .= "\n";
                                    if (
strlen(trim($answer_raw)) > 0$answer_raw .= ",";

                                    if (
$ANSWER_TEXT_EXIST)
                                        
$answer .= $arrA["ANSWER_TEXT"].': ';

                                    switch (
$arrA['FIELD_TYPE'])
                                    {
                                        case 
'text':
                                        case 
'textarea':
                                        case 
'email':
                                        case 
'url':
                                        case 
'hidden':
                                        case 
'date':
                                        case 
'password':
                                        case 
'integer':

                                            if (
$USER_TEXT_EXIST)
                                            {
                                                
$answer .= trim($arrA["USER_TEXT"]);
                                                
$answer_raw .= trim($arrA["USER_TEXT"]);
                                            }

                                        break;

                                        case 
'checkbox':
                                        case 
'multiselect':
                                        case 
'radio':
                                        case 
'dropdown':

                                            if (
$ANSWER_TEXT_EXIST)
                                            {
                                                
$answer substr($answer0, -2).' ';
                                                
$answer_raw .= $arrA['ANSWER_TEXT'];
                                            }

                                            if (
$ANSWER_VALUE_EXIST)
                                            {
                                                
$answer .= '('.$arrA['ANSWER_VALUE'].') ';
                                                if (!
$ANSWER_TEXT_EXIST)
                                                {
                                                    
$answer_raw .= $arrA['ANSWER_VALUE'];
                                                }
                                            }

                                            if (!
$ANSWER_VALUE_EXIST && !$ANSWER_TEXT_EXIST)
                                            {
                                                
$answer_raw .= $arrA['ANSWER_ID'];
                                            }

                                            
$answer .= '['.$arrA['ANSWER_ID'].']';

                                        break;

                                        case 
'file':
                                        case 
'image':

                                            if (
$USER_FILE_EXIST)
                                            {
                                                
$f CFile::GetByID($arrA["USER_FILE_ID"]);
                                                if (
$fr $f->Fetch())
                                                {
                                                    
$file_size CFile::FormatSize($fr["FILE_SIZE"]);
                                                    
$url = ($APPLICATION->IsHTTPS() ? "https://" "http://").$_SERVER["HTTP_HOST"]. "/bitrix/tools/form_show_file.php?rid=".$RESULT_ID"&hash=".$arrA["USER_FILE_HASH"]."&action=download&lang=".LANGUAGE_ID;

                                                    if (
$arrA["USER_FILE_IS_IMAGE"]=="Y")
                                                    {
                                                        
$answer .= $arrA["USER_FILE_NAME"]." [".$fr["WIDTH"]." x ".$fr["HEIGHT"]."] (".$file_size.")\n".$url;
                                                    }
                                                    else
                                                    {
                                                        
$answer .= $arrA["USER_FILE_NAME"]." (".$file_size.")\n".$url."&action=download";
                                                    }
                                                }

                                                
$answer_raw .= $arrA['USER_FILE_NAME'];
                                            }

                                        break;
                                    }
                                }
                            }
                        }

                        
$arEventFields[$wr["SID"]] = (strlen($answer)<=0) ? " " $answer;
                        
$arEventFields[$wr["SID"].'_RAW'] = (strlen($answer_raw)<=0) ? " " $answer_raw;
                    }

                    
CEvent::Send($arrTemplate["EVENT_NAME"], $arrTemplate["SITE_ID"], $arEventFields"Y"$arrTemplate["ID"]);
                    
$MESS $OLD_MESS;
                } 
//foreach($arrTemplates as $arrTemplate)
                
return true;
            }
            else 
$strError .= GetMessage("FORM_ERROR_FORM_NOT_FOUND")."<br>";
        }
        else 
$strError .= GetMessage("FORM_ERROR_RESULT_NOT_FOUND")."<br>";
        return 
false;
    }

Блог разработчика

9 августа 2016 ResizeImageGet и простой водяной знак налету

Сегодня поговорим о том как проще всего воткнуть водяной знак на картинки в Битрикс. Например, на все изображения каталога.

21 июля 2016 Добавление вкладки в CRM коробки Битрикс24

В этом посте я покажу, как легко и просто добавить вкладку в сущность CRM. И не просто добавить, а вывести там свой контент.

21 июля 2016 Как просто обращаться из коробки Битрикс24 на сайт на базе Битрикс

К примеру вам хочется внутренним скриптом дернуть с сайта-магазина информацию, которая там, в свою очередь, закрыта некоторыми правами. Например, админскими. Можно конечно мутить свой REST, или иной формат общения, но проще всего воспользоваться штатным инструментом:

Текст сообщения*
Загрузить изображение