Exemplo n.º 1
0
 private static function SendEmail($emails_to, $Files_Send, $index, $type_post_template = "ATTACH_FILES_BP", $subj = "", $sms_info)
 {
     //require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
     if (is_array($Files_Send)) {
         $arCopyFiles = array();
         foreach ($Files_Send as $key => $file) {
             // тут будет что-типа 0 => 4611 (просто номер файла)
             $arFile = CFile::GetFileArray($file);
             $arCopyFiles[] = $arFile;
         }
         $arFieldmail = array("NAME" => "user", "EMAIL_TO" => $emails_to);
         if ($index == 99) {
             foreach ($Files_Send as $key => $file) {
                 $arf = CFile::GetFileArray($file[ID]);
                 $fn = $arf['FILE_NAME'];
                 $arFieldmail['FILE'] = $arf['SRC'];
             }
         } else {
             $file = $Files_Send[$index];
             $arf = CFile::GetFileArray($file[ID]);
             $fn = $arf['FILE_NAME'];
             $arFieldmail['FILE'] = $arf['SRC'];
         }
         // define subj
         $its_ok = true;
         $dct = substr($fn, 0, 4);
         if ($dct == 'pred') {
             $subj .= 'Предложение ';
         } else {
             if ($dct == 'scet') {
                 $subj .= 'Счет ';
             } else {
                 $its_ok = false;
             }
         }
         $lpos = strpos($fn, '(');
         $rpos = strpos($fn, ')');
         if ($lpos === FALSE || $rpos === FALSE) {
             $its_ok = false;
         }
         if ($lpos >= $rpos) {
             $its_ok = false;
         }
         if ($its_ok) {
             $ss = substr($fn, $lpos + 1, $rpos - $lpos - 1);
             $subj .= $ss . ".";
         }
         $arFieldmail['SUBJECT'] = $subj;
         // send sms
         if (!empty($sms_info)) {
             $dealid = $sms_info["dealid"];
             $smsno = $sms_info["smsno"];
             $smstext = CArkaCrm::CreateSmsTextByDealIDAndFileName($dealid, $fn);
             CArkaSMS::SendSMS($smsno, $smstext);
         }
         //deb
         //AddMessage2Log('arFieldsmail is ' . serialize($arFieldmail));
         $event = new CEvent();
         $event->Send($type_post_template, SITE_ID, $arFieldmail);
     }
 }