Current Path : /var/www/u0635749/data/www/hobbyclick.ru/public/local/php_interface/ |
Current File : /var/www/u0635749/data/www/hobbyclick.ru/public/local/php_interface/init.php |
<?php use Tequila\Metods\ConnectInIblock, Bitrix\Iblock\ElementTable, Bitrix\Main\Web\HttpClient, Bitrix\Main\Config\Option; define("CATALOG_IBLOCK_ID", 5); define("OFFER_IBLOCK_ID", 16); define("HALL_IBLOCK_ID", 15); define("PREPOD_IBLOCK", 13); define("CHANGES_IBLOCK", 26); define("CITIES_IBLOCK", 27); define("HLBL_COMFORT", 7); define("HLBL_METRO", 4); define("FEEDBACK_IBLOCK_ID", 24); define("DOP_INFO_HL_ID", 8); define("NEXT_DAYS", '29 days'); define("Y_API_KEY", '0323102f-b7c5-40cd-80a3-39d236238876'); require_once(__DIR__ . '/../../../vendor/autoload.php'); function reInitDance() { $tn = new ConnectInIblock(); return 'reInitDance()'; } function Transliterate($string) { $cyr=array( "Щ", "Ш", "Ч", "Ц","Ю", "Я", "Ж", "А","Б","В","Г","Д","Е","Ё","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х", "Ь","Ы","Ъ","Э","Є","Ї", "щ", "ш", "ч", "ц","ю", "я", "ж", "а","б","в","г","д","е","ё","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х", "ь","ы","ъ","э","є","ї", " " ); $lat=array( "Shh","Sh","Ch","C","Ju","Ja","Zh","A","B","V","G","D","Je","Jo","Z","I","J","K","L","M","N","O","P","R","S","T","U","F","Kh","'","Y","`","E","Je","Ji", "shh","sh","ch","c","ju","ja","zh","a","b","v","g","d","je","jo","z","i","j","k","l","m","n","o","p","r","s","t","u","f","kh","'","y","`","e","je","ji", "_" ); for($i=0; $i<count($cyr); $i++) { $c_cyr = $cyr[$i]; $c_lat = $lat[$i]; $string = str_replace($c_cyr, $c_lat, $string); } $string = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]e/", "\${1}e", $string); $string = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]/", "\${1}'", $string); $string = preg_replace("/([eyuioaEYUIOA]+)[Kk]h/", "\${1}h", $string); $string = preg_replace("/^kh/", "h", $string); $string = preg_replace("/^Kh/", "H", $string); return $string; } function getSectionInfo($id, $IBLOCK_ID) { CModule::IncludeModule("iblock"); $SectList = CIBlockSection::GetList(array("NAME" => "ASC"), array("IBLOCK_ID" => $IBLOCK_ID, "ID" => $id), false, array("ID", "IBLOCK_ID", "SORT", "ACTIVE", "CODE", "SECTION_ID", "NAME", "SECTION_PAGE_URL", "UF_*")); while ($SectListGet = $SectList->GetNext()) { if ($SectListGet['ID'] == $id) { $section = $SectListGet; } } return $section; } function getElementInfo($id, $IBLOCK_ID) { CModule::IncludeModule("iblock"); $SectList = CIBlockElement::GetList(array("NAME" => "ASC"), array("IBLOCK_ID" => $IBLOCK_ID, "ID" => $id), false, array( "ID", "IBLOCK_ID", "ACTIVE", "CODE", "PREVIEW_PICTURE", "SECTION_ID", "NAME", "DETAIL_PAGE_URL", "PROPERTY_*" )); while ($SectListGet = $SectList->GetNextElement()) { $arFields = $SectListGet->GetFields(); $section = $arFields; $section["PROPERTIES"] = $SectListGet->GetProperties(); } return $section; } function getReviews($id) { CModule::IncludeModule("iblock"); $SectList = CIBlockElement::GetList(array("NAME" => "ASC"), array("IBLOCK_ID" => 24, "PROPERTY_TEACHER" => $id), false, array( "ID", "IBLOCK_ID", "ACTIVE", "CODE", "PREVIEW_PICTURE", "SECTION_ID", "NAME", "DETAIL_PAGE_URL", "PROPERTY_*" )); $review = array(); $review['count'] = 0; while ($SectListGet = $SectList->GetNextElement()) { $fields = $SectListGet->GetFields(); $prop = $SectListGet->GetProperties(); $review['review'] = $review['review'] + $prop['REVIEW']['VALUE']; $review['count']++; } $review['review2'] = intVal($review['review'] / $review['count']); return $review; } function getIp() { $keys = [ 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' ]; foreach ($keys as $key) { if (!empty($_SERVER[$key])) { $ip = trim(end(explode(',', $_SERVER[$key]))); if (filter_var($ip, FILTER_VALIDATE_IP)) { return $ip; } } } } function haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000) { // convert from degrees to radians $latFrom = deg2rad($latitudeFrom); $lonFrom = deg2rad($longitudeFrom); $latTo = deg2rad($latitudeTo); $lonTo = deg2rad($longitudeTo); $latDelta = $latTo - $latFrom; $lonDelta = $lonTo - $lonFrom; $angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) + cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2))); return $angle * $earthRadius; } function vincentyGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000) { // convert from degrees to radians $latFrom = deg2rad($latitudeFrom); $lonFrom = deg2rad($longitudeFrom); $latTo = deg2rad($latitudeTo); $lonTo = deg2rad($longitudeTo); $lonDelta = $lonTo - $lonFrom; $a = pow(cos($latTo) * sin($lonDelta), 2) + pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2); $b = sin($latFrom) * sin($latTo) + cos($latFrom) * cos($latTo) * cos($lonDelta); $angle = atan2(sqrt($a), $b); return $angle * $earthRadius; } function sortByRating($arItems) { foreach ($arItems as &$arItem) { $arRatings = []; foreach ($arItem['LERN'] as $arLern) { $arRatings[] = $arLern['PREPOD']['PROPERTY_RATING_VALUE']; } $arItem['MAX_RATING'] = max($arRatings); } unset($arItem, $arRatings); usort($arItems, function ($a, $b) { if ($a['MAX_RATING'] == $b['MAX_RATING']) { return 0; } return ($a['MAX_RATING'] > $b['MAX_RATING']) ? -1 : 1; }); foreach ($arItems as &$arItem) { usort($arItem['LERN'], function ($a, $b) { if ($a['PREPOD']['PROPERTY_RATING_VALUE'] == $b['PREPOD']['PROPERTY_RATING_VALUE']) { return 0; } return ($a['PREPOD']['PROPERTY_RATING_VALUE'] > $b['PREPOD']['PROPERTY_RATING_VALUE']) ? -1 : 1; }); } unset($arItem); return $arItems; } function getCityNow() { $ip = getIp(); $result = file_get_contents("http://www.geoplugin.net/php.gp?ip=".$ip); if($result==false) { $cityPicker['CITY']="Москва"; $cityPicker['HREF']="https://spb.hobbyclick.ru/"; $cityPicker['HREFNOW']="https://hobbyclick.ru/"; } else { if ($result['geoplugin_region']=="St.-Petersburg" || $result['geoplugin_region']=="Leningrad"){ $cityPicker['CITY']="Санкт-Петербург"; $cityPicker['HREF']="https://hobbyclick.ru/"; $cityPicker['HREFNOW']="https://spb.hobbyclick.ru/"; } else { $cityPicker['CITY']="Москва"; $cityPicker['HREF']="https://spb.hobbyclick.ru/"; $cityPicker['HREFNOW']="https://hobbyclick.ru/"; } } /* 17/09/2021 наебнулся ipgeobase.ru и ложил весь сайт. мы написали эксепшн if($result==false), но файл_гет_контент секунд по 20 не давал сайту грузится. переписали плагин под сервис geoplugin.net $ip = getIp(); $result = file_get_contents("http://ipgeobase.ru:7020/geo?ip=".$ip); if($result==false) { $cityPicker['CITY']="Москва"; $cityPicker['HREF']="https://spb.hobbyclick.ru/"; $cityPicker['HREFNOW']="https://hobbyclick.ru/"; } else { $xml = new SimpleXMLElement($result); if ($xml->ip->region=="Санкт-Петербург"){ $cityPicker['CITY']="Санкт-Петербург"; $cityPicker['HREF']="https://hobbyclick.ru/"; $cityPicker['HREFNOW']="https://spb.hobbyclick.ru/"; } else { $cityPicker['CITY']="Москва"; $cityPicker['HREF']="https://spb.hobbyclick.ru/"; $cityPicker['HREFNOW']="https://hobbyclick.ru/"; } }*/ return $cityPicker; } function sortByLength($arItems) { $ip = getIp(); $result = file_get_contents("http://www.geoplugin.net/php.gp?ip=".$ip); foreach ($arItems as &$arItem) { $latLng = explode(',', $arItem['PROPERTIES']['KARTA']['VALUE']); $arItem['TO_USER_DISTANCE'] = vincentyGreatCircleDistance($latLng[0], $latLng[1], $result['geoplugin_latitude'], $result['geoplugin_longitude']); } unset($arItem); usort($arItems, function ($a, $b) { if ($a['TO_USER_DISTANCE'] == $b['TO_USER_DISTANCE']) { return 0; } return ($a['TO_USER_DISTANCE'] < $b['TO_USER_DISTANCE']) ? -1 : 1; }); /*$result = file_get_contents("http://ipgeobase.ru:7020/geo?ip=" . $ip); $xml = new SimpleXMLElement($result); foreach ($arItems as &$arItem) { $latLng = explode(',', $arItem['PROPERTIES']['KARTA']['VALUE']); $arItem['TO_USER_DISTANCE'] = vincentyGreatCircleDistance($latLng[0], $latLng[1], $xml->ip->lat, $xml->ip->lng); } unset($arItem); usort($arItems, function ($a, $b) { if ($a['TO_USER_DISTANCE'] == $b['TO_USER_DISTANCE']) { return 0; } return ($a['TO_USER_DISTANCE'] < $b['TO_USER_DISTANCE']) ? -1 : 1; });*/ return $arItems; } function sortByStart($arItems) { foreach ($arItems as &$arItem) { uasort($arItem['LERN'], function ($a, $b) { return $a['PREPOD']['PROPERTY_START_YEAR_VALUE'] < $b['PREPOD']['PROPERTY_START_YEAR_VALUE'] ? 1 : 0; }); } unset($arItem); return $arItems; } AddEventHandler('main', 'OnBuildGlobalMenu', 'OnBuildGlobalMenuHandlerNext'); function OnBuildGlobalMenuHandlerNext(&$arGlobalMenu, &$arModuleMenu) { $moduleID = 'tq_filter_seo'; if (!isset($arGlobalMenu[$moduleID])) { $arGlobalMenu[$moduleID] = array( 'menu_id' => $moduleID, 'text' => 'SEO фильтра', 'title' => 'SEO фильтра', 'sort' => 1000, 'items_id' => $moduleID . '_items', ); } $arMenu = array( 'menu_id' => $moduleID, 'text' => 'SEO фильтра', 'title' => 'SEO фильтра', 'sort' => 1000, 'items_id' => $moduleID . '_items', 'icon' => 'imi_next', 'url' => '/bitrix/admin/' . $moduleID . '.php', ); $arGlobalMenu[$moduleID]['items'][$moduleID] = $arMenu; $moduleID = 'tq_sitemap'; if (!isset($arGlobalMenu[$moduleID])) { $arGlobalMenu[$moduleID] = array( 'menu_id' => $moduleID, 'text' => 'Настройка sitemap.xml', 'title' => 'Настройка sitemap.xml', 'sort' => 1000, 'items_id' => $moduleID . '_items', ); } $arMenu = array( 'menu_id' => $moduleID, 'text' => 'Настройка sitemap.xml', 'title' => 'Настройка sitemap.xml', 'sort' => 1000, 'items_id' => $moduleID . '_items', 'icon' => 'imi_next', 'url' => '/bitrix/admin/' . $moduleID . '.php', ); $arGlobalMenu[$moduleID]['items'][$moduleID] = $arMenu; } /** * @param array $arParams * @param string $text * @return string * @throws **/ function getSeoItem(array $arParams, $text = '') { if ($text && $arParams) { preg_match_all('#\{(.*?)\}#', $text, $arMatches); if ($arMatches) { foreach ($arMatches[1] as $key => &$arMatch) { preg_match_all('#\#(.*?)\##', $arMatch, $arPropMatches); if ($arPropMatches) { foreach ($arPropMatches[1] as $propKey => $arPropMatch) { if ($arParams[$arPropMatch]) { $arMatch = str_replace($arPropMatches[0][$propKey], $arParams[$arPropMatch], $arMatch); } else { $arMatch = ''; } } } } $text = str_replace($arMatches[0], $arMatches[1], $text); } preg_match_all('#\#(.*?)\##', $text, $arPropMatches); if ($arPropMatches) { foreach ($arPropMatches[1] as $propKey => &$arPropMatch) { if ($arParams[$arPropMatch]) { $arPropMatch = $arParams[$arPropMatch]; } else { $arPropMatch = ''; } } $text = str_replace($arPropMatches[0], $arPropMatches[1], $text); } } else { $text = ''; } return $text; } /** * @param array $arParams * @throws **/ function setSeo(array $arParams) { global $APPLICATION; global $USER; $moduleName = 'tq_filter_seo'; $h1 = getSeoItem($arParams, Option::get($moduleName, 'h1')); $title = getSeoItem($arParams, Option::get($moduleName, 'title')); $description = getSeoItem($arParams, Option::get($moduleName, 'description')); if ($title) { $APPLICATION->SetPageProperty('title', $title); } if ($h1) { $APPLICATION->setTitle($h1); $APPLICATION->SetPageProperty("h1", $h1); } if ($description) { $APPLICATION->SetPageProperty("description", $description); } } AddEventHandler("main", "OnEndBufferContent", "ChangeMyContent"); function ChangeMyContent(&$content) { if (strpos($_SERVER['REQUEST_URI'], '/bitrix/') === false) { \Bitrix\Main\Loader::includeModule('iblock'); $name = ''; $select = [ 'ID', 'NAME', 'CODE', ]; $filter = [ '=IBLOCK_ID' => CITIES_IBLOCK, 'ACTIVE' => 'Y', '=CODE' => $_SERVER['HTTP_HOST'], ]; $res = ElementTable::getList([ 'select' => $select, 'filter' => $filter, ]); if ($ob = $res->fetch()) { $name = $ob['NAME']; } $content = str_replace('{CITY}', $name, $content); } GLOBAL $APPLICATION; if ($APPLICATION->GetCurPage(false) == '/bitrix/admin/iblock_element_edit.php' && $_GET['ID']){ CModule::IncludeModule("iblock"); $res = CIBlockElement::GetByID($_GET['ID']); if($ar_res = $res->GetNext()){ if ($ar_res['IBLOCK_ID'] == 16){ $form = '<script> let id_product = '.$_GET['ID'].'; let request = new XMLHttpRequest(); const url = "/form_in_admin.php?ID=" + id_product; request.open("GET", url); request.setRequestHeader("Content-Type", "application/x-www-form-url"); request.addEventListener("readystatechange", () => { if (request.readyState === 4 && request.status === 200) { let liLast = document.createElement("div"); liLast.innerHTML = request.responseText; document.querySelector("#cat_edit1 .adm-detail-content-item-block-view-tab").append(liLast); } }); request.send(); function submitSkidka(){ let skikda = document.querySelector("#skidka").value; let siteSkidka = document.querySelector("#siteSkidka").value; let tovar = document.querySelector("#tovarId").value; let url = "/ajax/skidkaAdd.php?skikda=" + skikda+"&siteSkidka="+siteSkidka+"&tovarId="+tovar; let request = new XMLHttpRequest(); request.open("GET", url); request.setRequestHeader("Content-Type", "application/x-www-form-url"); request.addEventListener("readystatechange", () => { document.location.reload(); }); request.send(); } function deliteSkidka(el){ let skikda = el.getAttribute("data-id"); let url = "/ajax/skidkaDelite.php?skikda=" + skikda; let request = new XMLHttpRequest(); request.open("GET", url); request.setRequestHeader("Content-Type", "application/x-www-form-url"); request.addEventListener("readystatechange", () => { document.location.reload(); }); request.send(); } </script> '; $content.=$form; } } } } /** * Получение координат адреса * * @param $address string - адрес точки * @return bool | array - false или массив с координатами [долгота, широта] */ function getCoordNameByAddress(string $address) { $obCache = new CPHPCache; $life_time = 30*60*24*30; $cache_id = $address; if ($obCache->InitCache($life_time, $cache_id, "/")) { $arCoords = $obCache->GetVars(); } else { $address = preg_replace("/ {2,}/", " ", $address); $address = str_replace(" ", "+", $address); $options = array( "redirect" => true, // true, если нужно выполнять редиректы "redirectMax" => 5, // Максимальное количество редиректов "waitResponse" => true, // true - ждать ответа, false - отключаться после запроса "socketTimeout" => 30, // Таймаут соединения, сек "streamTimeout" => 60, // Таймаут чтения ответа, сек, 0 - без таймаута "version" => HttpClient::HTTP_1_0, // версия HTTP (HttpClient::HTTP_1_0 или HttpClient::HTTP_1_1) "proxyHost" => "", // адрес "proxyPort" => "", // порт "proxyUser" => "", // имя "proxyPassword" => "", // пароль "compress" => false, // true - принимать gzip (Accept-Encoding: gzip) "charset" => "", // Кодировка тела для POST и PUT "disableSslVerification" => false, // true - отключить проверку ssl (с 15.5.9) ); $url = 'https://geocode-maps.yandex.ru/1.x/'; $body = [ 'apikey' => Y_API_KEY, 'geocode' => $address, 'kind' => 'metro', 'format' => 'json', 'results' => 1 ]; $url = sprintf('%s?%s', $url, http_build_query($body)); $httpClient = new HttpClient($options); $httpClient->get($url); $result = $httpClient->getResult(); if ($result) { $result = json_decode($result); // получение координат точки $coord = $result->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos; $arCoords = explode(" ", $coord); } else { $arCoords = []; } $obCache->StartDataCache(); $obCache->EndDataCache($arCoords); } return $arCoords; } /** * Получение ближайшего метро по координатам * * @param array $arCoords * @return array|boolean- false или название ближайшего метро */ function getMetroNameByCoord(array $arCoords) { $arMetros = []; $coordinates = implode(',', $arCoords); $obCache = new CPHPCache; $life_time = 30*60*24*30; $cache_id = $coordinates; if ($obCache->InitCache($life_time, $cache_id, "/coordmetro/")) { $arMetros = $obCache->GetVars(); } else { $options = array( "redirect" => true, // true, если нужно выполнять редиректы "redirectMax" => 5, // Максимальное количество редиректов "waitResponse" => true, // true - ждать ответа, false - отключаться после запроса "socketTimeout" => 30, // Таймаут соединения, сек "streamTimeout" => 60, // Таймаут чтения ответа, сек, 0 - без таймаута "version" => HttpClient::HTTP_1_0, // версия HTTP (HttpClient::HTTP_1_0 или HttpClient::HTTP_1_1) "proxyHost" => "", // адрес "proxyPort" => "", // порт "proxyUser" => "", // имя "proxyPassword" => "", // пароль "compress" => false, // true - принимать gzip (Accept-Encoding: gzip) "charset" => "", // Кодировка тела для POST и PUT "disableSslVerification" => false, // true - отключить проверку ssl (с 15.5.9) ); $url = 'https://geocode-maps.yandex.ru/1.x/'; $body = [ 'apikey' => Y_API_KEY, 'geocode' => $coordinates, 'kind' => 'metro', 'format' => 'json', 'results' => 3 ]; $url = sprintf('%s?%s', $url, http_build_query($body)); $httpClient = new HttpClient($options); $httpClient->get($url); $arParams = array("replace_space" => "-", "replace_other" => "-"); $result = json_decode($httpClient->getResult(), true); if ($result) { foreach ($result['response']['GeoObjectCollection']['featureMember'] as $arMetro) { $pos = explode(' ', $arMetro['GeoObject']['Point']['pos']); $distance = getDistance(deg2rad($arCoords[0]), deg2rad($pos[0]), deg2rad($arCoords[1]), deg2rad($pos[1])); $arMetros[strtolower(Cutil::translit(str_replace('метро ', '', $arMetro['GeoObject']['name']), "ru", $arParams))] = [ 'name' => str_replace('метро ', '', $arMetro['GeoObject']['name']), 'distance' => $distance ]; } } $obCache->StartDataCache(); $obCache->EndDataCache($arMetros); } return $arMetros; } function getDistance($lat1, $lat2, $lon1, $lon2) { $r = 6371; // Earth's radius $sin1 = sin(($lat1 - $lat2) / 2); $sin2 = sin(($lon1 - $lon2) / 2); $distance = 2 * $r * asin(sqrt($sin1 * $sin1 + $sin2 * $sin2 * cos($lat1) * cos($lat2))); if($distance<1){ $result = sprintf('%s м.',round($distance * 1000)); }else{ $result = sprintf('%s км.',number_format($distance,'1','.',' ')); } return $result; } AddEventHandler("iblock", "OnAfterIBlockElementUpdate", "OnAfterBlockElementDays"); AddEventHandler("iblock", "OnAfterIBlockElementAdd", "OnAfterBlockElementDays"); function OnAfterBlockElementDays(&$arFields) { //lea //if(!isset($arFields['PROPERTY_VALUES']['99'])){ //var_dump('<pre>',$arFields); //var_dump('<pre>222',$_REQUEST['PROP']['99']);die(); //} /// if ($arFields['IBLOCK_ID'] == 16){ $VALUES = array(); $res = CIBlockElement::GetProperty(16, $arFields['ID'], "sort", "asc", array("CODE" => "daytime")); while ($ob = $res->GetNext()) { $VALUES[] = $ob['VALUE']; } $arrayDate = array("ПН" => "DATE_1", "ВТ" => "DATE_2", "СР" => "DATE_3", "ЧТ" => "DATE_4", "ПТ" => "DATE_5", "СБ" => "DATE_6", "ВС" => "DATE_0"); foreach($VALUES as $val){ $date = explode("-", $val); $dateNow = strtoupper($date[0]); $finaldate[$dateNow][] = $date[1].'-'.$date[2]; } $useArray = array(); foreach($finaldate as $key=>$val){ $test = CIBlockElement::SetPropertyValueCode($arFields['ID'], $arrayDate[$key],$val); $useArray[] = $arrayDate[$key]; } $arrDif = array_diff($useArray, $arrayDate); foreach($arrayDate as $v){ if (!in_array($v, $useArray)){ $test = CIBlockElement::SetPropertyValueCode($arFields['ID'], $v,array('')); } } } } AddEventHandler('main', 'OnEpilog', 'catalogPage', 1); function catalogPage(){ GLOBAL $APPLICATION; if($APPLICATION->GetCurPage()=="/catalog/"){ GLOBAL $APPLICATION; $APPLICATION->RestartBuffer(); require $_SERVER['DOCUMENT_ROOT'].SITE_TEMPLATE_PATH.'/header.php'; require $_SERVER['DOCUMENT_ROOT'].'/catalog/sections.php'; require $_SERVER['DOCUMENT_ROOT'].SITE_TEMPLATE_PATH.'/footer.php'; } } use Bitrix\Main\Loader; AddEventHandler("sale", "OnSaleStatusOrder", "OrderComplete"); function OrderComplete($orderID, &$arFields) { Loader::includeModule("sale"); if ($arFields == 'F' || $arFields == 'P') { $arOrder = CSaleOrder::GetByID($orderID); $db_props = CSaleOrderPropsValue::GetOrderProps($orderID); while ($arProps = $db_props->Fetch()) { $arOrder[$arProps['CODE']] = $arProps; } // Интеграция с Б24 $queryUrl = 'https://tequila.bitrix24.ru/rest/6687/ir8yg7ewvfze2108/crm.lead.add.json'; $queryData = http_build_query(array( 'fields' => array( 'TITLE' => 'Заявка на сайте hobbyclick.ru', 'NAME' => $arOrder['USER_NAME'], 'LAST_NAME' => $arOrder['USER_LAST_NAME'], 'COMMENTS' => 'Преподаватель: '.$arOrder['PREPOD']['VALUE'].'<br>Заявка с сайта hobbyclick.ru', 'PHONE' => [['VALUE' => $arOrder['PHONE']['VALUE'], 'VALUE_TYPE' => 'WORK']], 'EMAIL' => [['VALUE' => $arOrder['EMAIL']['VALUE'], 'VALUE_TYPE' => 'WORK']], 'UF_CRM_1506523304' => $arOrder['DAY_TIME']['VALUE'], 'UF_CRM_1506435059' => $arOrder['ID_B24_STYLE']['VALUE'], 'UF_CRM_1508423907' => $arOrder['ADDRESS_ID']['VALUE'] ), 'params' => array("REGISTER_SONET_EVENT" => "Y") )); // Обращаемся к Битрикс24 при помощи функции curl_exec $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $queryUrl, CURLOPT_POSTFIELDS => $queryData, )); $result = curl_exec($curl); curl_close($curl); $result = json_decode($result, 1); if (array_key_exists('error', $result)) { file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/PAYED-log.txt', date("d.m.Y H:i:s — ") . '$out: ' . var_export("Ошибка при сохранении лида: ".$result['error_description']."<br/>", true) . "\n", FILE_APPEND); } file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/PAYED-log.txt', date("d.m.Y H:i:s — ") . '$out: ' . var_export($arOrder, true) . "\n", FILE_APPEND); } } ?>