Your IP : 3.145.90.203
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
if (CModule::IncludeModule("iblock")){
// Очистка инфоблоков
$resultCountry = CIBlockElement::GetList(array("ID"=>"ASC"),array('IBLOCK_ID'=>12,));
$element = '';
while($element = $resultCountry->Fetch())
CIBlockElement::Delete($element['ID']);
$resultCity = CIBlockElement::GetList(array("ID"=>"ASC"),array('IBLOCK_ID'=>13,));
$element = '';
while($element = $resultCity->Fetch())
CIBlockElement::Delete($element['ID']);
$resultDiller = CIBlockElement::GetList(array("ID"=>"ASC"),array('IBLOCK_ID'=>16,));
$element = '';
while($element = $resultDiller->Fetch())
CIBlockElement::Delete($element['ID']);
$resultShop = CIBlockElement::GetList(array("ID"=>"ASC"),array('IBLOCK_ID'=>15,));
$element = '';
while($element = $resultShop->Fetch())
CIBlockElement::Delete($element['ID']);
//END Очистка инфоблоков
$arFilter = array(
//"IBLOCK_ID" => 32,
"IBLOCK_ID" => 34,
);
$arFile = CIBlockElement::GetList(array(), $arFilter, false, false, array());
while($fileXML = $arFile->GetNextElement())
{
$fileProp = $fileXML->GetProperties();
$file = CFile::GetPath( $fileProp["FILE"]["VALUE"] );
$file = substr($file, 1);
break;
}
$xml = simplexml_load_file($file);
$json_string = json_encode($xml);
$result_array = json_decode($json_string, TRUE);
$arData = $result_array["site"];
$arCountry = array();
$arCities = array();
$iC = 1;
foreach( $arData["countries"]["country"] as $country ){
$arFields = Array(
"IBLOCK_ID" => 12,
"NAME" => $country["@attributes"]["name"],
"ACTIVE" => "Y", // активен
"CODE" => $country["@attributes"]["url"],
"SORT" => $iC,
);
$arCountry[$country["@attributes"]["id"]] = elementAdd($arFields);
$iC++;
}
foreach( $arData["cities"]["city"] as $city ){
$acrive = 'N';
if ( $city["@attributes"]["status"] == 'active')
$acrive = 'Y';
$arFields = Array(
"IBLOCK_ID" => 13,
"NAME" => $city["@attributes"]["name"],
"ACTIVE" => $acrive, // активен
"CODE" => $city["@attributes"]["url"],
"PROPERTY_VALUES"=> array("COUNTRY" => $arCountry[$city["@attributes"]["country_id"]]),
);
$arCities[$city["@attributes"]["id"]] = elementAdd($arFields);
}
foreach( $arData["clients"]["client"] as $client ){
$arShop = array();
if( isset($client["shop"]) ){
$phone = '';
$email = '';
$workdescription = '';
$addressName = '';
$description = '';
$address = '';
$externalRef = '';
$acriveShop = 'N';
if( count( $client["shop"] ) > 1 ){
foreach( $client["shop"] as $shop ){
if ( $shop["@attributes"]["status"] == 'active')
$acriveShop = 'Y';
$addressName = ($shop["@attributes"]["name"] != '')? $shop["@attributes"]["name"] : $shop["@attributes"]["address"];
$workdescription = ($shop["@attributes"]["workdescription"] != '')? '<li>
<span>График работы:</span>
<span>'.$shop["@attributes"]["workdescription"].'</span>
</li>'
: '';
$external_ref = '';
if($shop["@attributes"]["external_ref"] != ''){
$external_ref = $shop["@attributes"]["external_ref"];
}
$internal_ref = '';
if($shop["@attributes"]["internal_ref"] != ''){
$internal_ref = ($external_ref != '')? ', '.$shop["@attributes"]["internal_ref"] : $shop["@attributes"]["internal_ref"];
}
$externalRef = ($external_ref != '' || $internal_ref != '')? $external_ref.$internal_ref : '';
if( $shop["@attributes"]["phone1"] != '' ){
$phone = '<li>
Тел.:
<a href="tel:'.preg_replace('/[^0-9]/', '', $shop["@attributes"]["phone1"]).'" class="call-to"><span class="tel">'.$shop["@attributes"]["phone1"].'</span></a>'
.(($shop["@attributes"]["phone2"] != '')? ', <a href="tel:'.preg_replace('/[^0-9]/', '', $shop["@attributes"]["phone2"]).'" class="call-to"><span class="tel">'.$shop["@attributes"]["phone2"].'</span></a>' : '')
.(($shop["@attributes"]["phone3"] != '')? ', <a href="tel:'.preg_replace('/[^0-9]/', '', $shop["@attributes"]["phone3"]).'" class="call-to"><span class="tel">'.$shop["@attributes"]["phone3"].'</span></a>' : '')
.'
</li> ';
}
if( $shop["@attributes"]["email1"] != '' && $client["@attributes"]["net_id"] == 1){
$email = '<a href="mailto:nahimovsky@rusklimat.ru" class="mail-to email">'.$shop["@attributes"]["email1"].'</a>'
.(($shop["@attributes"]["email2"] != '')? '<br> <a href="mailto:nahimovsky@rusklimat.ru" class="mail-to email">'.$shop["@attributes"]["email2"].'</a>' : '')
.(($shop["@attributes"]["email3"] != '')? '<br> <a href="mailto:nahimovsky@rusklimat.ru" class="mail-to email">'.$shop["@attributes"]["email3"].'</a>' : '');
}
$adressDesc = '';
if ( $shop["@attributes"]["address"] ){
$adressDesc = '<li>
'.$shop["@attributes"]["address"].', '.$externalRef.'
</li>';
}elseif( $externalRef ){
$adressDesc = '<li>
'.$externalRef.'
</li>';
}
$description = '<ul class="market-features">'
.$adressDesc
.$phone.
'</ul>'
.$email;
$arFields = Array(
"IBLOCK_ID" => 15,
"NAME" => $addressName,
"ACTIVE" => $acriveShop, // активен
"DETAIL_TEXT" => $description,
);
$arShop[] = array( 'VALUE' => elementAdd($arFields));
}
}else{
if ( $client["shop"]["@attributes"]["status"] == 'active')
$acriveShop = 'Y';
$addressName = ($client["shop"]["@attributes"]["name"] != '')? $client["shop"]["@attributes"]["name"] : $client["shop"]["@attributes"]["address"];
$workdescription = ($client["shop"]["@attributes"]["workdescription"] != '')? '<li>
<span>График работы:</span>
<span>'.$client["shop"]["@attributes"]["workdescription"].'</span>
</li>'
: '';
$externalRef = ($client["shop"]["@attributes"]["external_ref"] != '')? $client["shop"]["@attributes"]["external_ref"]
.( ($client["shop"]["@attributes"]["internal_ref"] != '')? ', '.$client["shop"]["@attributes"]["external_ref"]: '') : '';
if( $client["shop"]["@attributes"]["phone1"] != '' ){
$phone = '<li>
Тел.:
<a href="tel:'.preg_replace('/[^0-9]/', '', $client["shop"]["@attributes"]["phone1"]).'" class="call-to"><span class="tel">'.$client["shop"]["@attributes"]["phone1"].'</span></a>'
.(($client["shop"]["@attributes"]["phone2"] != '')? ', <a href="tel:'.preg_replace('/[^0-9]/', '', $client["shop"]["@attributes"]["phone2"]).'" class="call-to"><span class="tel">'.$client["shop"]["@attributes"]["phone2"].'</span></a>' : '')
.(($client["shop"]["@attributes"]["phone3"] != '')? ', <a href="tel:'.preg_replace('/[^0-9]/', '', $client["shop"]["@attributes"]["phone3"]).'" class="call-to"><span class="tel">'.$client["shop"]["@attributes"]["phone3"].'</span></a>' : '')
.'
</li> ';
}
if( $client["shop"]["@attributes"]["email1"] != '' && $client["@attributes"]["net_id"] == 1 ){
$email = '<a href="mailto:nahimovsky@rusklimat.ru" class="mail-to">'.$client["shop"]["@attributes"]["email1"].'</a>'
.(($client["shop"]["@attributes"]["email2"] != '')? '<br> <a href="mailto:nahimovsky@rusklimat.ru" class="mail-to email">'.$client["shop"]["@attributes"]["email2"].'</a>' : '')
.(($client["shop"]["@attributes"]["email3"] != '')? '<br> <a href="mailto:nahimovsky@rusklimat.ru" class="mail-to email">'.$client["shop"]["@attributes"]["email3"].'</a>' : '');
}
if ( $client["shop"]["@attributes"]["address"] ){
$address = '<li>
'.$client["shop"]["@attributes"]["address"].', '.$externalRef.'
</li>';
}elseif( $externalRef ){
$address = '<li>
'.$externalRef.'
</li>';
}
$description = '<ul class="market-features">
'.$address
.$phone.
'</ul>'
.$email;
$arFields = Array(
"IBLOCK_ID" => 15,
"NAME" => $addressName,
"ACTIVE" => $acriveShop, // активен
"DETAIL_TEXT" => $description,
);
$arShop[] = array( 'VALUE' => elementAdd($arFields));
}
}
$acrive = 'N';
if ( $client["@attributes"]["status"] == 'active')
$acrive = 'Y';
$siteClient = '';
if ( $client["@attributes"]["net_id"] == 1 ){
$siteClient = $client["@attributes"]["site1"];
}
$arFields = Array(
"IBLOCK_ID" => 16,
"NAME" => $client["@attributes"]["name"],
"ACTIVE" => $acrive, // активен
"PROPERTY_VALUES"=> array(
"PHONE" => $client["@attributes"]["phone"],
"SITE" => $siteClient,
"CITY" => $arCities[$client["@attributes"]["city_id"]],
"SHOPS" => $arShop,
),
);
$arCities[$city["@attributes"]["id"]] = elementAdd($arFields);
}
}
function elementAdd ($arLoadProductArray){
$el = new CIBlockElement;
if($PRODUCT_ID = $el->Add($arLoadProductArray))
return $PRODUCT_ID;
else
return $el->LAST_ERROR;
}
?>