<?
// CRM server conection data
define('CRM_HOST', 'xxx.bitrix24.ua'); // your CRM domain name
define('CRM_PORT', '443'); // CRM server port
define('CRM_PATH', '/crm/configs/import/lead.php'); // CRM server REST service path
// CRM server authorization data
define('CRM_AUTH', ''); // authorization hash Иван
/********************************************************************************************/
// POST processing
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// <BX 24>
// get lead data from the form
$postData = array(
'TITLE' => isset($cid) ? $cid : 'нет id',//$leadData['TITLE'],
'SOURCE_ID' => $id_source,
'PHONE_WORK' => $_POST['phone'],
'EMAIL_WORK' => $_POST['email'],
'NAME' => $_POST['name'],
'COMMENTS' => $_POST['textarea-559'],
'POST' => $_POST['worker'],
'COMPANY_TITLE' => $_POST['companyname'],
'UF_CRM_1465143139' => $_SERVER['REMOTE_ADDR'], //ip
'UF_CRM_1464512340' => $data['city'], //город
'UF_CRM_1465133417' => date("G:i:s"),
'WEB_WORK' => $_SERVER['SERVER_NAME'],
'UF_CRM_1465134700' => $_GET['utm_source'],
'UF_CRM_1465134877' => $_GET['utm_medium'],
'UF_CRM_1465134895' => $_GET['utm_campaign'],
'UF_CRM_1465143206' => $_GET['utm_term'],
'UF_CRM_1465134928' => rawurldecode( http_build_query($_GET, '', ' | ')),
'UF_CRM_1465143371' => $wpcf7->title,
'UF_CRM_1465143551' => $_POST['tovar_info'], //товар
'UF_CRM_1465157060' => $_POST['file_list'], //файлы прайс
);
// append authorization data
if (defined('CRM_AUTH')) {
$postData['AUTH'] = CRM_AUTH;
}else{
$postData['LOGIN'] = CRM_LOGIN;
$postData['PASSWORD'] = CRM_PASSWORD;
}
// open socket to CRM
$fp = fsockopen("ssl://".CRM_HOST, CRM_PORT, $errno, $errstr, 30);
if ($fp){
// prepare POST data
$strPostData = '';
foreach ($postData as $key => $value)
$strPostData .= ($strPostData == '' ? '' : '&').$key.'='.urlencode($value);
// prepare POST headers
$str = "POST ".CRM_PATH." HTTP/1.0\r\n";
$str .= "Host: ".CRM_HOST."\r\n";
$str .= "Content-Type: application/x-www-form-urlencoded\r\n";
$str .= "Content-Length: ".strlen($strPostData)."\r\n";
$str .= "Connection: close\r\n\r\n";
$str .= $strPostData;
// send POST to CRM
fwrite($fp, $str);
// get CRM headers
$result = '';
while (!feof($fp))
{
$result .= fgets($fp, 128);
}
fclose($fp);
$response = explode("\r\n\r\n", $result);
// </BX 24>
}else{
echo 'Connection Failed! '.$errstr.' ('.$errno.')';
}
}
?>