无法从Bitrix用户表单获取图像到pdf文档

时间:2019-07-29 04:00:55

标签: php html api bitrix

我正在使用CMS bitrix格式的mikehaertl / phpwkhtmltopdf制作pdf文档。一切进展顺利,但唯一的问题是我无法显示用户在生成pdf时放在表格上的图像。

我阅读了bitrix api文档,但未发现有关我的问题的任何信息。我试图使用CFile :: ShowImage获取图像,但我认为我做错了。希望有人可以帮助我解决我的问题

<?

include_once('/home/bitrix/vendor/autoload.php');

use Bitrix\Main\Loader;
use mikehaertl\wkhtmlto\Pdf;

AddEventHandler("iblock", "OnAfterIBlockElementAdd", 
Array("AfterElementAdd", "AfterElementAddSendMail"));
class AfterElementAdd
{
function AfterElementAddSendMail(&$arFields)
{

    if($arFields["IBLOCK_ID"] == 53)
    {


     $arEventFields = array(
         "NAME_CANDIDATE"         => $arFields['NAME'],
         "COMPANY_CANDIDATE"        => $arFields['PROPERTY_VALUES'] 
['SURNAME']
         );


     CEvent::Send("NEW_ORDER_CALL", SITE_ID, $arEventFields);
    }
}
}

AddEventHandler('form', 'onAfterResultAdd', 'art_send_resume_sed');
function art_send_resume_sed($WEB_FORM_ID, $RESULT_ID)
{
if($WEB_FORM_ID == 6 && Loader::includeModule('iblock') && 
Loader::includeModule('form')){
    ini_set("soap.wsdl_cache_enabled", 0);

    $client = new SoapClient('******',  array('trace' => true, 'login' => 
'*****', 'password' => '*****') );

    $arResult = '';
    $arAnswer2 = '';

    $arAnswer = CFormResult::GetDataByID(
        $RESULT_ID, 
        array(),  // вопрос "Какие области знаний вас интересуют?" 
        $arResult, 
        $arAnswer2);

    /*$rsResult = CFormResult::GetByID($RESULT_ID);
    $arResult = $rsResult->Fetch();*/

    //file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/testt- 
147/soap_send_resume-484848498498498.log', var_export([$arResult, 
$arAnswer, $arAnswer2], 1), FILE_APPEND);

    $date = new DateTime($arAnswer['SIMPLE_QUESTION_904'][0] 
['USER_TEXT']);
    $new_date_format = $date->format('Y-m-d');

    $rsElement = CIBlockElement::GetList(
        $arOrder  = array("SORT" => "ASC"),
        $arFilter = array(
            "ACTIVE"    => "Y",
            "ID" => $arAnswer['ID_VACANCY'][0]['USER_TEXT']
        ),
        false,
        false,
        $arSelectFields = array(
            "PROPERTY_REQUEST_ID",
            "PROPERTY_NAME_VACANT_POST",
            "PROPERTY_STRUCTURAL_SUBDIVISION",
            "PROPERTY_QUALIFICATION_CRITERIA",
            "PROPERTY_COMPETENCY",
            "PROPERTY_FUNCTIONAL_REQUIREMENTS_CANDIDATE",
        )
    );

    $REQUEST_ID = 0;
    if($arElement = $rsElement->fetch()) {
        $REQUEST_ID = $arElement['PROPERTY_REQUEST_ID_VALUE']['TEXT'];
        $arVacancy = $arElement;
    }

 if(!$REQUEST_ID){
   file_put_contents(__DIR__ . '/soap_send_resume-484848498498498.log', 
date('Y-m-d H:i:s') . ' - Не найден REQUEST_ID, искалось в вакансии с ID: 
' . var_export($arAnswer['ID_VACANCY'][0]['USER_TEXT'], 1), FILE_APPEND);
    return;
  }

    $previous_work = function($place_work, $unit, $position, $start_work, 
$end_work, $reason_dismisal){
        return
        '<row>' .
            '<column type="string" name="tf_01609f" title="Место работы">' .
                htmlspecialcharsEx($place_work) . 
            '</column>' .
            '<column type="string" name="tf_416fc5" 
title="Подразделение">' .
                htmlspecialcharsEx($unit) .
            '</column>' . 
            '<column type="string" name="tf_411221" title="Должность">' . 
                htmlspecialcharsEx($position) .
            '</column>' . 
            '<column type="string" name="tf_b16fc5" title="Начало 
работы">' .
                htmlspecialcharsEx($start_work) .
            '</column>' . 
            '<column type="string" name="tf_318b75" title="Завершение работы">' . 
                htmlspecialcharsEx($end_work) .
            '</column>' .
            '<column type="string" name="tf_713d5b" title="Причина увольнения">' .
                htmlspecialcharsEx($reason_dismisal) .
            '</column>' .
        '</row>';
    };

    $learn = function($name_center, $theme, $year){
        return
        '<row>' .
            '<column type="string" name="tf_81fe37" title="Наименование обучающего центра">' .
                htmlspecialcharsEx($name_center) .
            '</column>' .
            '<column type="string" name="tf_41b603" title="Тема обучения">' .
                htmlspecialcharsEx($theme) .
            '</column>' .
            '<column type="string" name="tf_31e64c" title="Год обучения">' .
                htmlspecialcharsEx($year) .
            '</column>' .
        '</row>';
    };

        $pdfHTML = '<table border="1"><tbody>';
$pdfHTML .= '<tr border="0" style="background-repeat:no-repeat; 
background-attachment: fixed; opacity: 0.5; background-position:center 
10px;" background="https://damu.kz/upload/logo_h.png">';
    $pdfHTML .= '<td colspan="2" style="height:70px">';
    $pdfHTML .= '</td>';
    $pdfHTML .= '</tr>';


  foreach ($arAnswer as $items) {
$isAnswer = false;
foreach ($items as $item) {
    if (trim($item['ANSWER_TEXT']) || trim($item['USER_TEXT'])) {
        $isAnswer = true;
        break;
    }
}
if ($isAnswer) {
    $pdfHTML .= '<tr>';
    $pdfHTML .= '<td>';
    $pdfHTML .= htmlspecialcharsEx($items['0']['TITLE']);
    $pdfHTML .= '</td>';
    $pdfHTML .= '<td>';
    foreach ($items as $item) {
        if (!empty($item['USER_TEXT'])){
            $pdfHTML .= htmlspecialcharsEx($item['USER_TEXT']);
        }
        if (!empty($item['ANSWER_TEXT'])) {
            $pdfHTML .= htmlspecialcharsEx($item['ANSWER_TEXT']);
        }
        $pdfHTML .= '<br>';
    }
    $pdfHTML .= '</td>';
    $pdfHTML .= '</tr>';
}

}
$pdfHTML .= '</tbody></table>';

    // You can pass a filename, a HTML string, an URL or an options array 
to the constructor
    $pdf = new Pdf($pdfHTML);

    $pdf->setOptions([
        'encoding' => 'UTF-8',
        'javascript-delay' => 3000,
        'user-style-sheet' => 
'https://www.damu.kz/bitrix/php_interface/pdf.css',
    ]);

    $content = $pdf->toString();

    $anketaKandidata =  '<?xml version="1.0" encoding="UTF-8"?><root>'
    . '<item name="resume-' . intval($RESULT_ID) . '.pdf" 
mime_type="application/pdf" size="' . strlen($content) . '" md5sum="' . 
md5($content) . '">' . base64_encode($content) . '</item>'
    . '</root>';

    $data = [
        'photo' => CFile::ShowImage($arValues["form_image_22423"], 200, 200, "border=0", "", true),
        'familiya' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_909'][0]['USER_TEXT']),
        'imya' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_975'][0]['USER_TEXT']),
        'otchestvo' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_314'][0]['USER_TEXT']),
        'data_rozhdeniya' => htmlspecialcharsEx($new_date_format),
        'pol' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_288'][0]['ANSWER_TEXT']),
        'adres_prozhivaniya' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_281'][0]['USER_TEXT']),
        'elektronnij_adres' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_530'][0]['USER_TEXT']),
        'nomer_telefona' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_321'][0]['USER_TEXT']),

        'predidushaya_rabota' => 
        '<?xml version="1.0" encoding="UTF-8"?>' .
        '<root>' .
            $previous_work(
                $arAnswer['SIMPLE_QUESTION_597'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_453'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_918'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_910'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_697'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_1000'][0]['USER_TEXT']
            ) .
            $previous_work(
                $arAnswer['SIMPLE_QUESTION_285'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_494'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_843'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_458'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_585'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_1001'][0]['USER_TEXT']
            ) .
            $previous_work(
                $arAnswer['SIMPLE_QUESTION_285_1GjIE'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_494_bVWHT'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_843_rhrYI'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_458_OvJ2I'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_585_CYS2e'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_1002'][0]['USER_TEXT']
            ) .
            $previous_work(
                $arAnswer['SIMPLE_QUESTION_285_1GjIE_Dag26'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_494_bVWHT_zVCkR'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_843_rhrYI_xm36d'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_458_lgzLx'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_585_CYS2e_qb8NR'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_1003'][0]['USER_TEXT']
            ) .
        '</root>',

        'obuchenie' =>
        '<?xml version="1.0" encoding="UTF-8"?>' .
        '<root>' .
            $learn(
                $arAnswer['SIMPLE_QUESTION_748'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_738'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_863'][0]['USER_TEXT']
            ) .
            $learn(
                $arAnswer['SIMPLE_QUESTION_790'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_254'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_958'][0]['USER_TEXT']
            ) .
            $learn(
                $arAnswer['SIMPLE_QUESTION_835'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_930'][0]['USER_TEXT'],
                $arAnswer['SIMPLE_QUESTION_948'][0]['USER_TEXT']
            ) .
        '</root>',

        'vremya_pristupleniya' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_804'][0]['USER_TEXT']),

        'kontakti_rabotodatelej' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_256'][0]['USER_TEXT']) . ' ' . htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_256_ThcVv'][0]['USER_TEXT']),

        'rezultati_raboti' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_489'][0]['USER_TEXT']),
        'zayavka' => $arVacancy['PROPERTY_REQUEST_ID_VALUE']['TEXT'],
        'otkuda_izvestno' => htmlspecialcharsEx($arAnswer['SIMPLE_QUESTION_799'][0]['USER_TEXT']),

        'nazvanie_dolzhnosti' => $arVacancy['PROPERTY_NAME_VACANT_POST_VALUE']['TEXT'],
        'strukturnoe_podrazdelenie' => $arVacancy['PROPERTY_STRUCTURAL_SUBDIVISION_VALUE'],
        'kompetentsii' => $arVacancy['PROPERTY_COMPETENCY_VALUE']['TEXT'],
        'kvalifikatsionnie_trebovaniya' => $arVacancy['PROPERTY_QUALIFICATION_CRITERIA_VALUE']['TEXT'],
        'anketa_kandidata' => $anketaKandidata,
    ];
    if ($arResult["isFormImage"] == "Y")
    {
        $arResult["FORM_IMAGE"]["ID"] = $arResult["arForm"]["IMAGE_ID"];
        // assign form image url
        $arResult["FORM_IMAGE"]["URL"] = CFile::GetPath($arResult["arForm"]["IMAGE_ID"]);

        // check image file existance and assign image data
        if (
            file_exists($_SERVER["DOCUMENT_ROOT"].$arResult["FORM_IMAGE"]["URL"]) 
            && 
            list(
                $arResult["FORM_IMAGE"]["WIDTH"], 
                $arResult["FORM_IMAGE"]["HEIGHT"], 
                $arResult["FORM_IMAGE"]["TYPE"], 
                $arResult["FORM_IMAGE"]["ATTR"]
            ) = @getimagesize($_SERVER["DOCUMENT_ROOT"].$arResult["FORM_IMAGE"]["URL"])
        )
        {
            $arResult["FORM_IMAGE"]["HTML_CODE"] = CFile::ShowImage($arResult["arForm"]["IMAGE_ID"]);
        }
    }


    //file_put_contents(__DIR__ . '/soap_send_resume-484848498498498.log', var_export([$data], 1), FILE_APPEND);

    try{
        $client->WSServer_resume($data);
    }catch(\Exception $e){
        file_put_contents(__DIR__ . '/soap_send_resume-484848498498498.log', 'ERROR send resume:' . var_export([$e], 1), FILE_APPEND);
        return 'Error';
    }

    //var_dump($client->__getLastResponse());
}
}
?>

我在pdf表单上拥有所有文本字段,但无法显示图像。

0 个答案:

没有答案