В init.php
// передача заявок в CallTouch
function sendCalltouchRequest($ctSubject, $ctName, $ctPhone, $ctComment) {
$ctCallValue = $_COOKIE['_ct_session_id'];
$ctSiteID = '1234567890';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded;charset=utf-8"));
curl_setopt($ch, CURLOPT_URL,'https://api.calltouch.ru/calls-service/RestAPI/requests/'.$ctSiteID.'/register/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"fio=".$ctName
."&phoneNumber=".$ctPhone
."&subject=".$ctSubject
."&comment=".$ctComment
."".($ctCallValue != 'undefined' ? "&sessionId=".$ctCallValue : ""));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$calltouch = curl_exec($ch);
curl_close ($ch);
}
AddEventHandler('form', 'onAfterResultAdd', 'onAfterResultAddHandler');
function onAfterResultAddHandler($WEB_FORM_ID, $RESULT_ID) {
if ($WEB_FORM_ID == 1) { // Форма 1
$arFields = array("NAME", "PHONE", "MODEL", "YEAR", "DATE", "COMMENT", "URL");
} elseif ($WEB_FORM_ID == 2) { // Форма 2
$arFields = array("NAME", "PHONE", "URL");
} else { // Остальные
$arFields = array("NAME", "PHONE", "URL");
}
$arAnswers = CFormResult::GetDataByID($RESULT_ID, $arFields, $arAnswersFields, $arAnswersFieldsValues);
foreach($arAnswersFieldsValues as $key => $ans) {
$answer = current($ans);
if (in_array($key, array("NAME", "PHONE"))) {
$answers[$key] = $answer['USER_TEXT'];
} else {
$answers['OTHER'] .= $answer['TITLE'].': '.$answer['USER_TEXT'].'; ';
}
}
sendCalltouchRequest($arAnswersFields['NAME'], $answers['NAME'], $answers['PHONE'], $answers['OTHER']);
}
Комментарии ()