<?
$_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"]);
	$arFields["PROPERTY_YAADRESS2_VALUE"] = str_replace('&quot;', '', $arFields["PROPERTY_YAADRESS2_VALUE"]);
	$xmlbody .= '<company>
			<company-id>'.$arFields["PROPERTY_YAID_VALUE"].'</company-id>
			<actualization-date>'.$today.'</actualization-date>
			<name lang="ru">Эволюция Автолизинга</name>
			<shortname lang="ru">ЛК Эволюция</shortname>
			<name lang="en">Evoleasing</name>
			<country lang="ru">Россия</country>
			<address lang="ru">'.$arFields["PROPERTY_YAADRESS1_VALUE"].'</address>
			<address-add lang="ru">'.$arFields["PROPERTY_YAADRESS2_VALUE"].'</address-add>
			<phone>
				<type>phone</type>
				<number>8 (800) 333-75-75</number>
			</phone>
			<email>info@evoleasing.ru</email>
			<working-time lang="ru">пн-пт 09:00-18:00</working-time>
			<rubric-id main="true">184105576</rubric-id>
			<url>https://www.evoleasing.ru</url>
			<add-url>https://wa.me/74951466767</add-url>
			<add-url>https://t.me/evoleasingbot</add-url>
			<add-url>https://vk.me/evoleasing</add-url>
			<photos>
				<photo url="https://www.evoleasing.ru/upload/img/logo.png">
					<tag>LOGO</tag>
				</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');?>
