<?
$_SERVER['DOCUMENT_ROOT'] = '/home/bitrix/www/'; // на один уровень выше, чем /cron/
define('NO_KEEP_STATISTIC', true);
define('NOT_CHECK_PERMISSIONS',true);
define('SITE_ID', 's1');
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
require($DOCUMENT_ROOT.'/bitrix/modules/main/include/prolog_before.php');
?>
<?
$xmlbody = '<?xml version="1.0" encoding="UTF-8"?><companies>';
$i = 0;
$today = date("d.m.Y");
CModule::IncludeModule("iblock");
$arSelect = Array("ID", "NAME", "PROPERTY_PHONE", "PROPERTY_PHONE_CENTRAL","PROPERTY_ADDRESS","PROPERTY_HOURS","PROPERTY_GEO", "PROPERTY_YAADRESS1","PROPERTY_YAADRESS2","PROPERTY_YADATA","PROPERTY_YAID",);
$arFilter = Array("IBLOCK_ID"=>5, "ACTIVE"=>"Y");

$res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilter, false, Array("nPageSize"=>333), $arSelect);

while($ob = $res->GetNextElement())
{
 $arFields = $ob->GetFields();

	$geo = explode(",", $arFields["PROPERTY_GEO_VALUE"]);

	$xmlbody .= '<company>
			<company-id>'.$arFields["PROPERTY_YAID_VALUE"].'</company-id>
			<name lang="ru">Эволюция Автолизинга</name>
			<shortname lang="ru">ЛК Эволюция</shortname>
			<address lang="ru">'.$arFields["PROPERTY_YAADRESS1_VALUE"].'</address>
			<country lang="ru">Россия</country>
			<address-add lang="ru">'.$arFields["PROPERTY_YAADRESS2_VALUE"].'</address-add>
			<phone>
				<number>'.$arFields["PROPERTY_PHONE_VALUE"].'</number>
				<info>Горячая линия</info>
				<type>phone</type>
			</phone>
			<email>buy@evoleasing.ru</email>
			<url>https://evoleasing.ru</url>
			<add-url>https://www.instagram.com/evoleasing/</add-url>
			<add-url>https://www.facebook.com/evoleasing</add-url>
			<add-url>https://vk.com/evoleasing</add-url>
			<info-page>https://evoleasing.ru/about/contacts/</info-page>
			<working-time lang="ru">пн-пт 9:00-18:00</working-time>
			<rubric-id>184105576</rubric-id>
			<inn>9724016636</inn> 
			<ogrn>1207700245037</ogrn>
			<actualization-date>'.$today.'</actualization-date>
			<photos>
				<photo url="https://evoleasing.ru/upload/img/logo.png" alt="Лого Эволюция Автолизинга" type="LOGO"></photo>
			</photos>
			<coordinates>
			  <lon>'.$geo[1].'</lon>
			  <lat>'.$geo[0].'</lat>
        	</coordinates>
		</company>
		';
?><pre><?
	$i++;
	print_r($i." => ".$arFields["PROPERTY_YAID_VALUE"]);
?></pre><?
}
?><pre><?
	//print_r($arFields);
?></pre><?
$xmlbody .= '</companies>';
?><pre><?//print_r($xmlbody);?></pre><?
$file = $DOCUMENT_ROOT . "/upload/docs/yasprav.xml";

$handle = fopen($file, "w+");//Открываем для записи в конец.
if (!$handle) {
  echo "Oшибка: файл не создался-".$text;
} else {
  fputs ($handle, $xmlbody); 
  fclose($handle);
	echo "Ok! Сохранено по <a href='https://www.evoleasing.ru/upload/docs/yasprav.xml'>ссылке!</a> ".$today;
}
?>
<?require($DOCUMENT_ROOT.'/bitrix/modules/main/include/epilog_after.php');?>
