Joywork/engine/classes/ObjectsParserIndividual.php

2223 lines
111 KiB
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?php
class ObjectsParserIndividual
{
private $metros = array();
private $agents = array();
private $rayons = array();
//xml в массив
public function XmlArray($path, $type = 'url'){
$array = array();
if($type == 'url'){
$string = file_get_contents($path);
/*$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_PROXY, $proxy); // $proxy is ip of proxy server
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
// curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE); // this results 0 every time
$response = curl_exec($ch);
if ($response === false) $response = curl_error($ch);
echo stripslashes($response);
curl_close($ch);*/
$xml = simplexml_load_string($string, null, LIBXML_NOCDATA);
} else if($type = 'file'){
$xml = simplexml_load_file($path, null, LIBXML_NOCDATA);
}
$array = json_decode(json_encode((array) $xml), true);
//var_dump($array);
$array = array($xml->getName() => $array);
return $array;
}
//Массив метро
public function set_metros($metros){
$tempMetros = array();
foreach ($metros['items']['item'] as $key => $metro) {
$tempMetros[$metro['id']] = $metro['name'];
}
$this->metros = $tempMetros;
}
public function get_metros($metro, $metroRegion){
$res = 0;
$sql = "SELECT * from metro WHERE metro = '$metro' AND region_rf_id = $metroRegion";
//echo $sql."\n";
$q=mysql_query($sql);
if(mysql_num_rows($q)>0){
$res = mysql_fetch_assoc($q)['id'];
}
return $res;
}
//Агенты
public function set_agents($phone, $email=false){
/* $sql = "SELECT * FROM users WHERE id = 5455";
$q = mysql_query($sql);
$r = mysql_fetch_assoc($q);
$agent = array('id'=>$r['id'], 'phone'=>$r['phone'], 'fio'=>$r['last_name'].' '.$r['first_name'].' '.$r['middle_name'], 'agencyId'=>5238);
*/
$agencyId = 23015;
$agencyPhone = '+79052698889';
$agent = "Не найден";
if(is_array($phone)){
$arrPhone = array();
foreach($phone as $ph){
$arrPhone[] = str_replace([' ', ')', '(','-'], '', $ph);
}
$sql = "SELECT * FROM users WHERE phone in ('".implode('\', \'', $arrPhone)."')";
} else {
$phone = str_replace([' ', ')', '(','-'], '', $phone);
if(strlen($phone) == 11) {
if(substr($phone, 0, 1) == "8"){
$phone = substr_replace($phone, '+7', 0, 1);
} else {
$phone = '+' . $phone;
}
}
$sql = "SELECT * FROM users WHERE phone='$phone'";
}
//echo $sql."\n";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0){
$r = mysql_fetch_assoc($q);
$agent = array('id'=>$r['id'], 'phone'=>$r['phone'], 'fio'=>$r['last_name'].' '.$r['first_name'].' '.$r['middle_name'], 'agencyId'=>$agencyId);
} else if( $email && !empty($email) ){
$sql = "SELECT * FROM users WHERE email='$email'";
//echo $sql ."\n";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0){
$r = mysql_fetch_assoc($q);
$agent = array('id'=>$r['id'], 'phone'=>$r['phone'], 'fio'=>$r['last_name'].' '.$r['first_name'].' '.$r['middle_name'], 'agencyId'=>$agencyId);
} else {
$sql = "SELECT * FROM users WHERE phone='{$agencyPhone}'";
//echo $sql ."\n";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0){
$r = mysql_fetch_assoc($q);
$agent = array('id'=>$r['id'], 'phone'=>$r['phone'], 'fio'=>$r['last_name'].' '.$r['first_name'].' '.$r['middle_name'], 'agencyId'=>$agencyId);
}
}
} else {
$sql = "SELECT * FROM users WHERE phone='{$agencyPhone}'";
//echo $sql ."\n";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0){
$r = mysql_fetch_assoc($q);
$agent = array('id'=>$r['id'], 'phone'=>$r['phone'], 'fio'=>$r['last_name'].' '.$r['first_name'].' '.$r['middle_name'], 'agencyId'=>$agencyId);
}
}
/* echo $sql ."\n";
var_dump($agent);*/
$CallEvents = new CallEvents();
$users = [];
$users = array_keys($CallEvents->getAllUserAgency($agencyId, $users));
if(in_array($agent['id'], $users)){
return $agent;
} else {
$sql = "SELECT * FROM users WHERE phone='{$agencyPhone}'";
//echo $sql ."\n";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0){
$r = mysql_fetch_assoc($q);
$agent = array('id'=>$r['id'], 'phone'=>$r['phone'], 'fio'=>$r['last_name'].' '.$r['first_name'].' '.$r['middle_name'], 'agencyId'=>$agencyId);
}
}
$sql = "SELECT * FROM users WHERE phone='{$agencyPhone}'";
//echo $sql ."\n";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0){
$r = mysql_fetch_assoc($q);
$agent = array('id'=>$r['id'], 'phone'=>$r['phone'], 'fio'=>$r['last_name'].' '.$r['first_name'].' '.$r['middle_name'], 'agencyId'=>$agencyId);
}
return $agent;
}
public function get_agents(){
return $this->agents;
}
//Регионы
public function set_rayons($rayon){
$rayonid = 0;
if(!is_array($rayon)){
$sql = "SELECT id, rayon FROM rayon where is_lo=0 and rayon = '".$rayon."' or rayon = '".str_replace(' район', '', $rayon)."'";
//echo $sql."\n";
$q= mysql_query($sql);
$r = mysql_fetch_assoc($q);
if(isset($r['id'])){
$rayonid = $r['id'];
}
}
return $rayonid;
}
//Фото
public function update_photo($objectId, $photos) {
//вставялем фото от 1 до 50
for($num = 1; $num <= 50; $num++) {
$sqlSelectPhoto = "select oop.id, oop.object_photo_id from objects_object_photo oop where oop.object_id = $objectId and sort_order = $num";
$rezSelectPhoto = mysql_query($sqlSelectPhoto);
if (isset($photos['photo' . $num]) && $photos['photo' . $num]) {
$p = $photos['photo' . $num];
if (mysql_num_rows($rezSelectPhoto) > 0) {
$ph = mysql_fetch_assoc($rezSelectPhoto);
$sqlUpdPhoto = "UPDATE object_photo SET photo = '$p' WHERE id = $ph[object_photo_id]";
mysql_query($sqlUpdPhoto);
} else {
$sqlInsPhoto = "INSERT INTO object_photo(photo) VALUES('$p')";
mysql_query($sqlInsPhoto);
$photoId = mysql_insert_id();
$sqlInsPhotoLink = "INSERT INTO objects_object_photo(object_id, object_photo_id, sort_order) VALUES($objectId, $photoId, $num)";
mysql_query($sqlInsPhotoLink);
//echo $sqlInsPhotoLink."\n";
}
} else {
if (mysql_num_rows($rezSelectPhoto) > 0) {
$ph = mysql_fetch_assoc($rezSelectPhoto);
$sqlDeletePhoto = "DELETE FROM object_photo where id = $ph[object_photo_id]";
// echo $sqlDeletePhoto."\n";
mysql_query($sqlDeletePhoto);
$sqlDeletePhotoLinks = "DELETE FROM objects_object_photo where id = $ph[id]";
//echo $sqlDeletePhotoLinks."\n";
mysql_query($sqlDeletePhotoLinks);
}
}
}
}
//Адрес
public function getDadate($address){
$token = "2f6595e671df25163a441a544bbed3683791c5d0";
$secret = null;
$dadata = new \Dadata\DadataClient($token, $secret);
$response = $dadata->suggest("address", $address);
return $response;
}
//Массив объектов
public function get_objects($url){
$agencyId = 23015;
$db_sphinx = new MysqlPdo(hstsph2, null, null, null, true, '9306');
$Selectel = SelectelApi::getTokenAndUrl();
$token = $Selectel[0];
$storageUrl = $Selectel[1];
//die();
$xmlArray = $this->XmlArray($url, 'fale');
$array = array();
echo count($xmlArray['realty-feed']['offer'])."\n";
$number = 0;
$total = 0;
$arrPhotosObj = array();
foreach ($xmlArray['realty-feed']['offer'] as $pole => $object) {
//var_dump($object);
//echo $number."\n";
//if(!in_array($object['@attributes']['internal-id'], $arr)){
$baseObject = array();
$spinxObject = array();
$objectPriceHistory = array();
$dopObject = array();
$additional_information = array();
$sp_metro = array();
$sale_objects = array();
$location = array();
$object_activities = array();
$object_event = array();
$object_nb_info = array();
$object_prices = array();
if(!isset($object['type'])){
echo "Не найдено type ".$object['@attributes']['external_id'];
} else {
$arrPole['type'] = 1;
if($object['type'] == 'продажа' || $object['type'] == 'Продажа') {
$baseObject[] = 'operation_type = 1';
$spinxObject['operation_type'] = "1";
}
else if($object['type'] == 'аренда' || $object['type'] == 'Аренда') {
$baseObject[] = 'operation_type = 0';
$spinxObject['operation_type'] = "0";
$baseObject[] = 'srok = 2';
$spinxObject['srok'] = "2";
}
}
// $sql = "SELECT `id`, `stage`, `deleted` FROM `clients` WHERE phone = '$phone' and (who_work in (".implode(',', $users)."))";
// echo $sql;
/* $sql_del = "delete from `clients` WHERE phone = '$phone' and (who_work in (".implode(',', $users)."))";
echo $sql_del."\n";
mysql_query($sql_del);*/
//$client_id = 0;
// $client = mysql_fetch_assoc(mysql_query($sql));
/* if(!empty($client) && $client){
$client_id = $client['id'];
} */
if(isset($object['deal-status'])){
if($object['deal-status'] == 'прямая продажа'){
$sale_objects[] = "deal_type = 1";
} else if ($object['deal-status'] == 'встречная продажа'){
$sale_objects[] = "deal_type = 2";
} else if ($object['deal-status'] == 'первичная продажа вторички' || $object['deal-status'] == 'первичная продажа'){
$sale_objects[] = "deal_type = 4";
} else if ($object['deal-status'] == 'переуступка'){
$sale_objects[] = "deal_type = 5";
} else if ($object['deal-status'] == 'размен'){
$sale_objects[] = "deal_type = 2";
} else if ($object['deal-status'] == 'продажа от застройщика'){
$sale_objects[] = "deal_type = 6";
} else {
echo $object['deal-status']."\n";
$sale_objects[] = "deal_type = 1";
}
$deal_type = 0;
if($object['deal-status'] == 'переуступка'){
$deal_type = 5;
/* $sqlLastNameCheck = "SELECT id FROM last_names WHERE BINARY value = '$fio_client'";
$rezLastNameCheck = mysql_query($sqlLastNameCheck);
if (mysql_num_rows($rezLastNameCheck) > 0) {
$lastNameId = mysql_fetch_assoc($rezLastNameCheck)['id'];
} else {
$sqlInsertLastName = "INSERT INTO last_names (value) VALUES ('$fio_client')";
mysql_query($sqlInsertLastName);
$lastNameId = mysql_insert_id();
}
// $object_nb_info[] = 'last_name_id = '.$lastNameId;
*/
}
} else {
$sale_objects[] = "deal_type = 1";
}
//$sale_objects[] = "deal_type = 6";
/* $object_nb_info[] = 'newbuilding_id=57008';
$object_nb_info[] = "nb_end_date='31.03.2023'";*/
if(isset($object['yandex-house-id']) && !empty($object['yandex-house-id'])){
$sql_n = "SELECT id FROM newbuildings WHERE yandex_housing_id = {$object['yandex-house-id']}";
$q_n = mysql_query($sql_n);
$r_n = mysql_fetch_assoc($q_n);
if($r_n){
$object_nb_info[] = 'newbuilding_id='.$r_n['id'];
}
} else if(isset($object['yandex-building-id']) && !empty($object['yandex-building-id'])){
$sql_n = "SELECT id FROM newbuildings WHERE yandex_id = {$object['yandex-building-id']}";
$q_n = mysql_query($sql_n);
$r_n = mysql_fetch_assoc($q_n);
if($r_n){
$object_nb_info[] = 'newbuilding_id='.$r_n['id'];
}
}
/* if(isset($object['building-name']) && !empty($object['building-name'])){
$object_nb_info[] = 'newbuilding_id=76047';
}*/
if($object['quality'] == 'Требует ремонта' || $object['quality'] == 'без отделки'){
$object_nb_info[] = 'zipal_new_flat_decoration_type_id = 1';
} else if($object['quality'] == 'Косметический'){
$object_nb_info[] = 'zipal_new_flat_decoration_type_id = 3';
} else if($object['quality'] == 'Хороший'){
$object_nb_info[] = 'zipal_new_flat_decoration_type_id = 3';
} else if ($object['quality'] == 'Дизайнерский'){
$object_nb_info[] = 'zipal_new_flat_decoration_type_id = 3';
} else if ($object['quality'] == 'С отделкой'){
$object_nb_info[] = 'zipal_new_flat_decoration_type_id = 3';
} else if ($object['quality'] == 'Черновая отделка'){
$object_nb_info[] = 'zipal_new_flat_decoration_type_id = 2';
} else if($object['quality'] == 'Евро'){
$object_nb_info[] = 'zipal_new_flat_decoration_type_id = 3';
}
if(!isset($object['category'])){
echo "Не найдено category ".$object['@attributes']['external_id'];
} else {
$object['category'] = mb_strtolower($object['category']);
if(empty($object['category'])){
$baseObject[] = 'type = 3';
$spinxObject['type'] = "3";
$nazv = "Дом ";
} else
if($object['category'] == "квартира" || $object['category'] == "дуплекс" || $object['category'] == "размен" || $object['category'] == "flat"){
$baseObject[] = 'type = 1';
$spinxObject['type'] = "1";
$nazv = "Квартира";
if(isset($object['rooms'])){
$nazv = $object['rooms']."-к квартира (".$object['area']['value']." м.кв)";
}
//$baseObject[] = "nazv = '".$nazv."'";
} else if($object['category'] == "дача" || $object['category'] == "дом" || $object['category'] == "коттедж" || $object['category'] =="дом с участком" || $object['category'] =="таунхаус" || $object['category'] =="house"){
$baseObject[] = 'type = 3';
$spinxObject['type'] = "3";
$nazv = "Дом (".$object['area']['value']." м.кв)";
//$baseObject[] = "nazv = '".$nazv."'";
if($object['category'] == "дача"){
$additional_information[] = 'house_category = 1';
}
if($object['category'] == "дом" || $object['category'] =="дом с участком"){
$additional_information[] = 'house_category = 4';
}
if($object['category'] == "коттедж"){
$additional_information[] = 'house_category = 2';
}
if($object['category'] == "таунхаус"){
$additional_information[] = 'house_category = 3';
}
} else if($object['category'] == "гараж"){
$nazv = "Гараж (".$object['area']['value']." м.кв)";
$baseObject[] = 'type = 4';
$spinxObject['type'] = "4";
$baseObject[] = 'type_category = 7';
$spinxObject['type_category'] = "7";
$additional_information[] = 'commercial_object_id = 7';
//$baseObject[] = "nazv = '".$nazv."'";
} else if($object['category'] == "комната"){
$baseObject[] = 'type = 2';
$spinxObject['type'] = "2";
$nazv = "Комната (".$object['area']['value']." м.кв)";
//$baseObject[] = "nazv = '".$nazv."'";
} else if($object['category'] == "участок" || $object['category'] == 'земельный участок'){
$baseObject[] = 'type = 7';
$spinxObject['type'] = "7";
$nazv = "Участок";
if(isset($object['area'])){
$nazv .= " (".$object['area']['value']." м.кв)";
}
//$baseObject[] = "nazv = '".$nazv."'";
} else if($object['category'] == "коммерческая" || $object['category'] == "commercial"){
$baseObject[] = 'type = 4';
$spinxObject['type'] = "4";
if(is_array($object['commercial-type'])){
$object['commercial-type'] = $object['commercial-type'][0];
}
if($object['commercial-type'] == 'Здания' || $object['commercial-type'] == 'auto repair'){
$baseObject[] = 'type_category = 6';
$spinxObject['type_category'] = "6";
$additional_information[] = 'commercial_object_id = 6';
if(isset($object['purpose'])){
$nazv = $object['purpose']." (".$object['area']['value']." м.кв)";
} else {
$nazv = "Коммерческая (".$object['area']['value']." м.кв)";
}
} else if($object['commercial-type'] == 'warehouse'){
$baseObject[] = 'type_category = 2';
$spinxObject['type_category'] = "2";
$additional_information[] = 'commercial_object_id = 2';
if(isset($object['purpose']) && !is_array($object['purpose'])){
$nazv = $object['purpose']." (".$object['area']['value']." м.кв)";
} else {
$nazv = "Коммерческая (".$object['area']['value']." м.кв)";
}
} else if($object['commercial-type'] == 'free purpose' || $object['commercial-type'] == 'manufacturing'){
$baseObject[] = 'type_category = 5';
$spinxObject['type_category'] = "5";
$additional_information[] = 'commercial_object_id = 5';
if(isset($object['purpose']) && !is_array($object['purpose'])){
$nazv = $object['purpose']." (".$object['area']['value']." м.кв)";
} else {
$nazv = "Коммерческая (".$object['area']['value']." м.кв)";
}
} else if($object['commercial-type'] == 'business' || $object['commercial-type'] == 'retail'){
$baseObject[] = 'type_category = 8';
$spinxObject['type_category'] = "8";
$additional_information[] = 'commercial_object_id = 8';
if(isset($object['purpose']) && !is_array($object['purpose'])){
$nazv = $object['purpose']." (".$object['area']['value']." м.кв)";
} else {
$nazv = "Коммерческая (".$object['area']['value']." м.кв)";
}
} else if($object['commercial-type'] == 'office'){
$baseObject[] = 'type_category = 1';
$spinxObject['type_category'] = "1";
$additional_information[] = 'commercial_object_id = 1';
$nazv = "Офис (".$object['area']['value']." м.кв)";
} else if($object['commercial-type'] == 'land'){
$baseObject[] = 'type_category = 9';
$spinxObject['type_category'] = "9";
$additional_information[] = 'commercial_object_id = 9';
$nazv = "Земельный участок (".$object['lot-area']['value']." ".$object['lot-area']['unit'].")";
} else {
echo $object['commercial-type']."\n";
}
// $baseObject[] = "nazv = '".$nazv."'";
} else if($object['category'] == "часть дома"){
$baseObject[] = 'type = 5';
$spinxObject['type'] = "5";
$nazv = "часть дома (".$object['area']['value']." м.кв)";
//$baseObject[] = "nazv = '".$nazv."'";
} else {
echo $object['category']."\n";
}
}
if(isset($object['title'])){
$nazv = $object['title'];
}
if(!empty($nazv)){
$baseObject[] = "nazv = '".$nazv."'";
}
$idRfRegion = 0;
if(trim($object['location']['region']) == "Краснодарский край"){
$baseObject[] = 'id_rf_region = 26';
$idRfRegion = 26;
} else if(isset($object['location']['region']) && ($object['location']['region'] == "Санкт-Петербург" || $object['location']['region'] == "Санкт-Петербург город" || $object['location']['region'] == "Ленинградская область" || $object['location']['region'] == "Ленинградская обл.") || $object['location']['locality-name'] == "Санкт-Петербург") {
$baseObject[] = 'id_rf_region = 2';
$idRfRegion = 2;
} else if(isset($object['location']['region']) && $object['location']['region'] == "Кировская область"){
$baseObject[] = 'id_rf_region = 46';
$idRfRegion = 46;
} else if(isset($object['location']['region']) && $object['location']['region'] == "Республика Татарстан"){
$baseObject[] = 'id_rf_region = 19';
$idRfRegion = 19;
} else if(isset($object['location']['region']) && $object['location']['region'] == "Удмуртская Республика"){
$baseObject[] = 'id_rf_region = 21';
$idRfRegion = 21;
} else if(isset($object['location']['locality-name']) && $object['location']['locality-name'] == "Санкт-Петербург") {
$baseObject[] = 'id_rf_region = 2';
$idRfRegion = 2;
} else if(isset($object['location']['region']) && $object['location']['region'] == "Волгоградская область"){
$baseObject[] = 'id_rf_region = 37';
$idRfRegion = 37;
}else if(isset($object['location']['region']) && $object['location']['region'] == "Новгородская область"){
$baseObject[] = 'id_rf_region = 56';
$idRfRegion = 56;
}else if(isset($object['location']['region']) && ($object['location']['region'] == "Псковская область")){
$baseObject[] = 'id_rf_region = 63';
$idRfRegion = 63;
}else if(isset($object['location']['region']) && ($object['location']['region'] == "Республика Карелия" || $object['location']['region'] == "Карелия республика" || $object['location']['region'] == "Карелия")){
$baseObject[] = 'id_rf_region = 13';
$idRfRegion = 13;
}else if(isset($object['location']['region']) && ($object['location']['region'] == "Республика Крым" || $object['location']['region'] == "Крым" || $object['location']['region'] == "Севастополь")){
$baseObject[] = 'id_rf_region = 3';
$idRfRegion = 3;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Рязанская область"){
$baseObject[] = 'id_rf_region = 65';
$idRfRegion = 65;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Ставропольский край"){
$baseObject[] = 'id_rf_region = 29';
$idRfRegion = 29;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Вологодская Область"){
$baseObject[] = 'id_rf_region = 38';
$idRfRegion = 38;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Воронежская область"){
$baseObject[] = 'id_rf_region = 39';
$idRfRegion = 39;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Самарская область"){
$baseObject[] = 'id_rf_region = 66';
$idRfRegion = 66;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Республика Тыва"){
$baseObject[] = 'id_rf_region = 20';
$idRfRegion = 20;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Ростовская область"){
$baseObject[] = 'id_rf_region = 64';
$idRfRegion = 64;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Красноярский край"){
$baseObject[] = 'id_rf_region = 27';
$idRfRegion = 27;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Москва" || $object['location']['locality-name'] == "г. Москва"){
$baseObject[] = 'id_rf_region = 1';
$idRfRegion = 1;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Московская область"){
$baseObject[] = 'id_rf_region = 1';
$idRfRegion = 1;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Алтайский край"){
$baseObject[] = 'id_rf_region = 25';
$idRfRegion = 25;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Свердловская область"){
$baseObject[] = 'id_rf_region = 69';
$idRfRegion = 69;
} else if (isset($object['location']['region']) && ($object['location']['region'] == "Республика Адыгея" || $object['location']['region'] == "Адыгея")){
$baseObject[] = 'id_rf_region = 4';
$idRfRegion = 4;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Оренбургская область"){
$baseObject[] = 'id_rf_region = 59';
$idRfRegion = 59;
} else if ((isset($object['location']['region']) && $object['location']['region'] == "Новосибирская область") || $object['location']['locality-name'] == "Новосибирск"){
$baseObject[] = 'id_rf_region = 57';
$idRfRegion = 57;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Костромская область"){
$baseObject[] = 'id_rf_region = 47';
$idRfRegion = 47;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Ивановская область"){
$baseObject[] = 'id_rf_region = 40';
$idRfRegion = 40;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Ярославская область"){
$baseObject[] = 'id_rf_region = 79';
$idRfRegion = 79;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Мурманская область"){
$baseObject[] = 'id_rf_region = 54';
$idRfRegion = 54;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Орловская область"){
$baseObject[] = 'id_rf_region = 60';
$idRfRegion = 60;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Омская область"){
$baseObject[] = 'id_rf_region = 58';
$idRfRegion = 58;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Нижегородская область"){
$baseObject[] = 'id_rf_region = 55';
$idRfRegion = 55;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Ульяновская область"){
$baseObject[] = 'id_rf_region = 76';
$idRfRegion = 76;
} else if (isset($object['location']['region']) && $object['location']['region'] == "Кемеровская область"){
$baseObject[] = 'id_rf_region = 45';
$idRfRegion = 45;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Республика Алтай"){
$baseObject[] = 'id_rf_region = 7';
$idRfRegion = 7;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Пермский край"){
$baseObject[] = 'id_rf_region = 62';
$idRfRegion = 62;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Республика Башкортостан"){
$baseObject[] = 'id_rf_region = 5';
$idRfRegion = 5;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Белгородская область"){
$baseObject[] = 'id_rf_region = 34';
$idRfRegion = 34;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Владимирская область"){
$baseObject[] = 'id_rf_region = 36';
$idRfRegion = 36;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Иркутская область"){
$baseObject[] = 'id_rf_region = 41';
$idRfRegion = 41;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Калининградская область"){
$baseObject[] = 'id_rf_region = 42';
$idRfRegion = 42;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Тюменская область"){
$baseObject[] = 'id_rf_region = 75';
$idRfRegion = 75;
} else if (isset($object['location']['region']) && trim($object['location']['region'])=="Курганская область"){
$baseObject[] = 'id_rf_region = 48';
$idRfRegion = 48;
} else if (isset($object['location']['region']) && trim($object['location']['region'])=="Ямало-Ненецкий автономный округ"){
$baseObject[] = 'id_rf_region = 92';
$idRfRegion = 92;
} else if (isset($object['location']['region']) && (trim($object['location']['region'])=="Хакасия Республика" || trim($object['location']['region'])=="Республика Хакасия")){
$baseObject[] = 'id_rf_region = 22';
$idRfRegion = 22;
} else if (isset($object['location']['region']) && trim($object['location']['region']) == "Томская область"){
$baseObject[] = 'id_rf_region = 73';
$idRfRegion = 73;
}
else {
/*echo $object['location']['locality-name']."\n";
$baseObject[] = 'id_rf_region = 37';*/
echo $object['location']['region']."\n";
}
/* if($idRfRegion == 0){
$baseObject[] = 'id_rf_region = 36';
$idRfRegion = 36;
}*/
$spinxObject['id_rf_region'] = $idRfRegion;
$rayon_id = 0;
//$location[] = "rf_region_rayon = ''";
if(isset($object['location']['sub-locality-name'])){
$rayon_id = $this->set_rayons($object['location']['sub-locality-name']);
//$location[] = "rf_region_rayon = '".$object['location']['sub-locality-name']."'";
} else if(isset($object['location']['district'])){
//$rayon_id = $this->set_rayons($object['location']['district']);
$location[] = "rf_region_rayon = '".$object['location']['district']."'";
} else {
//echo $object['location']['address']."\n";
$rayon_id = 0;
}
$dopObject[] = 'rayon = '.$rayon_id;
$baseObject[] = 'rayon = '.$rayon_id;
$spinxObject['rayon_id'] = $rayon_id;
$address = '';
if(isset($object['location']['region'])){
$address = $object['location']['region'];
}
// if(strpos($object['location']['locality-name'], 'Санкт-Петербург') === false){
if($address != '') $address .= ", ";
$address .= $object['location']['locality-name'];
// }
if(isset($object['location']['address']) && !empty($object['location']['address'])){
if($address != '') $address .= ", ";
$address .= $object['location']['address'];
}
// echo $address."\n";
if(isset($object['location']['address-full'])){
$address = $object['location']['address-full'];
}
if($address == ''){
echo "Не найдено адрес ".$object['@attributes']['external_id'];
}
//Получение массива метро
$metroRegion = $idRfRegion;
if ($idRfRegion == 19) {
$metroRegion = 1432;
}
if ($idRfRegion == 1) {
$metroRegion = 80;
}
if ($idRfRegion == 37) {
$metroRegion = 1468;
}
if ($idRfRegion == 55) {
$metroRegion = 1500;
}
if ($idRfRegion == 57) {
$metroRegion = 1504;
}
if ($idRfRegion == 66) {
$metroRegion = 1520;
}
if ($idRfRegion == 69) {
$metroRegion = 1526;
}
if ($idRfRegion == 2) {
$metroRegion = 81;
}
if(isset($object['location']['metro'])){
$ii=0;
if(!isset($object['location']['metro']['name'])){
foreach($object['location']['metro'] as $m){
$metro = $this->get_metros($m['name'], $metroRegion);
$sp_metro[] = $metro;
if($ii == 0){
if(isset($m['time-on-foot'])){
$baseObject[] = "peshkom = '".$m['time-on-foot']."'";
$spinxObject['peshkom'] = $m['time-on-foot'];
}
if(isset($m['time-on-transport'])){
$baseObject[] = "transport = '".$m['time-on-transport']."'";
$spinxObject['transport'] = $m['time-on-transport'];
}
}
$ii++;
}
} else {
$metro = $this->get_metros($object['location']['metro']['name'], $metroRegion);
$sp_metro[] = $metro;
if(isset($object['location']['metro']['time-on-foot'])){
$baseObject[] = "peshkom = '".$object['location']['metro']['time-on-foot']."'";
$spinxObject['transport'] = $object['location']['metro']['time-on-foot'];
}
if(isset($object['location']['metro']['time-on-transport'])){
$baseObject[] = "transport = '".$object['location']['metro']['time-on-transport']."'";
$spinxObject['transport'] = $object['location']['metro']['time-on-transport'];
}
}
}
if(isset($object['mortgage']) && $object['mortgage']){
$baseObject[] = "stoim_prim = 'Возможна ипотека'";
$spinxObject['stoim_prim'] = 'Возможна ипотека';
}
if(isset($object['video-review']['youtube-video-review-url'])){
$additional_information[] = "video_url = '".$object['video-review']['youtube-video-review-url']."'";
}
if(!isset($object['price']['value'])){
echo "Не найдено цена ".$object['@attributes']['external_id'];
$objectPriceHistory[] = "price = 0";
$objectPriceHistory[] = "date_change_price = '".date('Y-m-d H:i:s')."'";
}
if(isset($object['price']) && !empty($object['price']['value'])){
$baseObject[] = "stoim = '".$object['price']['value']."'";
$spinxObject['stoim'] = $object['price']['value'];
$spinxObject['sort_price'] = $object['price']['value'];
$objectPriceHistory[] = "price = '".$object['price']['value']."'";
$objectPriceHistory[] = "date_change_price = '".date('Y-m-d H:i:s')."'";
}
if(isset($object['price']) && isset($object['price']['currency'])){
$object_prices[] = 'price='.(int)$object['price']['value'];
$object_prices[] = 'prep_price=0';
$object_prices[] = 'start_price=0';
$object_prices[] = 'fact_price=0';
$object_prices[] = 'agency_id='.$agencyId;
if($object['price']['currency'] == 'RUB'){
$object_prices[] = 'currency=0';
} else if($object['price']['currency'] == 'USD'){
$object_prices[] = 'currency=1';
} else if($object['price']['currency'] == 'EUR'){
$object_prices[] = 'currency=2';
}
}
if(isset($object['room-furniture']) && $object['room-furniture'] > 0){
$baseObject[] = 'mebel = 1';
$spinxObject['mebel'] = 1;
}
if(isset($object['bathroom-unit'])){
if($object['bathroom-unit'] == "совмещенный"){
$additional_information[] = 'combined_wcs = 1';
} else if($object['bathroom-unit'] == "раздельный"){
$additional_information[] = 'separate_wcs = 1';
}
}
if(isset($object['renovation'])){
if($object['renovation'] == "требует ремонта"){
$additional_information[] = 'renovation = 4';
} else if($object['renovation'] == "хороший"){
$additional_information[] = 'renovation = 5';
} else if($object['renovation'] == "евро"){
$additional_information[] = 'renovation = 1';
}
else if($object['renovation'] == "частичный ремонт" || $object['renovation'] == "косметический" || $object['renovation'] == 'с отделкой'){
$additional_information[] = 'renovation = 2';
}
else if($object['renovation'] == "дизайнерский"){
$additional_information[] = 'renovation = 3';
}
}
if(isset($object['building-state'])){
if($object['building-state'] == 'unfinished'){
$object_nb_info[] = 'zipal_new_flat_type_id = 2';
}
}
if(isset($object['rooms'])){
$baseObject[] = "komnat = '".$object['rooms']."'";
$spinxObject['komnat'] = $object['rooms'];
}
if(isset($object['floor'])){
$baseObject[] = "etazh = '".$object['floor']."'";
$spinxObject['etazh'] = $object['floor'];
}
if(isset($object['floors-total'])){
$baseObject[] = "etazh_iz = '".$object['floors-total']."'";
}
if(isset($object['area']['value'])){
$baseObject[] = "ploshad = '".$object['area']['value']."'";
$spinxObject['ploshad'] = $object['area']['value'];
}
if(isset($object['living-space']['value'])){
$baseObject[] = "ploshad_komn = '".$object['living-space']['value']."'";
$spinxObject['ploshad_komn'] = $object['living-space']['value'];
}
if(isset($object['kitchen-space']['value'])){
$baseObject[] = "ploshad_k = '".$object['kitchen-space']['value']."'";
$spinxObject['ploshad_k'] = $object['kitchen-space']['value'];
}
if(isset($object['lot-area']['value'])){
$baseObject[] = "land_area = '".$object['lot-area']['value']."'";
}
if(isset($object['balcony'])){
if(is_array($object['balcony'])){
} else {
$additional_information[] = "balcony = '1'";
}
}
if(isset($object['ready-quarter']) && isset($object['built-year'])){
$object_nb_info[] = "nb_end_date='".$object['built-year']."-07-01'";
} else
if(isset($object['built-year'])){
$sale_objects[] = "build_year = '".$object['built-year']."'";
}
if(isset($object['building-type'])){
if(mb_strtolower($object['building-type']) == 'кирпично-монолитный' || mb_strtolower($object['building-type']) == 'монолитно-кирпичный'){
$sale_objects[] = 'house_material = 5';
$sale_objects[] = 'house_type = 15';
$baseObject[] = 'country_wall_type_id = 1';
} else if (mb_strtolower($object['building-type']) == 'кирпичный'){
$sale_objects[] = 'house_material = 1';
$sale_objects[] = 'house_type = 6';
$baseObject[] = 'country_wall_type_id = 1';
} else if (mb_strtolower($object['building-type']) == 'монолит' || mb_strtolower($object['building-type']) == 'монолитный'){
$sale_objects[] = 'house_material = 3';
$sale_objects[] = 'house_type = 17';
} else if (mb_strtolower($object['building-type']) == 'панельный' || mb_strtolower($object['building-type']) == 'панельный монолит'){
$sale_objects[] = 'house_material = 2';
$sale_objects[] = 'house_type = 16';
$baseObject[] = 'country_wall_type_id = 8';
} else if (mb_strtolower($object['building-type']) == 'железобетонный'){
$sale_objects[] = 'house_material = 8';
$sale_objects[] = 'house_type = 21';
$baseObject[] = 'country_wall_type_id = 8';
} else if (mb_strtolower($object['building-type']) == 'блочный' || mb_strtolower($object['building-type']) == 'газобетон' || mb_strtolower($object['building-type']) == 'блоки' || mb_strtolower($object['building-type']) == 'шлакобетон'){
$sale_objects[] = 'house_material = 4';
$sale_objects[] = 'house_type = 5';
$baseObject[] = 'country_wall_type_id = 4';
} else if (mb_strtolower($object['building-type'])=='брус') {
$sale_objects[] = 'house_material = 9';
$sale_objects[] = 'house_type = 18';
$baseObject[] = 'country_wall_type_id = 2';
} else if (mb_strtolower($object['building-type'])=='хрущевка') {
$sale_objects[] = 'house_material = 2';
$sale_objects[] = 'house_type = 2';
$baseObject[] = 'country_wall_type_id = 8';
} else if (mb_strtolower($object['building-type'])=='сталинский') {
$sale_objects[] = 'house_material = 1';
$sale_objects[] = 'house_type = 1';
$baseObject[] = 'country_wall_type_id = 1';
} else if (mb_strtolower($object['building-type'])=='деревянный' || mb_strtolower($object['building-type'])=='бревно/сруб/лафет') {
$sale_objects[] = 'house_material = 6';
$sale_objects[] = 'house_type = 18';
$baseObject[] = 'country_wall_type_id = 2';
} else if (mb_strtolower($object['building-type'])=='бревенчатый') {
$sale_objects[] = 'house_material = 6';
$sale_objects[] = 'house_type = 18';
$baseObject[] = 'country_wall_type_id = 3';
} else if (mb_strtolower($object['building-type'])=='индивидуальный проект') {
//$sale_objects[] = 'house_material = 6';
$sale_objects[] = 'house_type = 22';
//$baseObject[] = 'country_wall_type_id = 3';
} else if (mb_strtolower($object['building-type'])=='каркасный') {
$sale_objects[] = 'house_material = 6';
$sale_objects[] = 'house_type = 23';
$baseObject[] = 'country_wall_type_id = 2';
} else if (mb_strtolower($object['building-type'])=='щитовой') {
$sale_objects[] = 'house_material = 2';
$sale_objects[] = 'house_type = 24';
$baseObject[] = 'country_wall_type_id = 8';
} else if (mb_strtolower($object['building-type'])=='старый фонд') {
$sale_objects[] = 'house_material = 3';
$sale_objects[] = 'house_type = 3';
//$baseObject[] = 'country_wall_type_id = 3';
} else if (mb_strtolower($object['building-type'])=='пенобетон') {
$sale_objects[] = 'house_material = 10';
$sale_objects[] = 'house_type = 25';
$baseObject[] = 'country_wall_type_id = 6';
}
else {
echo mb_strtolower($object['building-type'])."\n";
}
}
if(isset($object['layout'])){
//echo $object['layout']."\n";
if($object['layout'] == "Изолированная"){
$additional_information[] = 'avito_room_type_id=2';
} else if($object['layout'] == "Смежная"){
$additional_information[] = 'avito_room_type_id=1';
} else if($object['layout'] == "Смежно-изолированная") {
$additional_information[] = 'avito_room_type_id=3';
}
}
// var_dump($object['description']);
if(isset($object['description'])){
$description = $object['description'];
$objRep = '';
$exD = explode(' ', $description);
//var_dump($exD);
if(isset($exD[0]) && isset($exD[1])){
$objRep .= $exD[0].' '.$exD[1];
}
$object['objRep'] = $objRep;
//echo $object['objRep']."\n";
$baseObject[]= "opis = '".mysql_real_escape_string($object['description'])."'";
$opis = mysql_real_escape_string($object['description']);
}
if(isset($object['window-view'])){
if($object['window-view'] == 'на улицу'){
$additional_information[] = 'window_view = 2';
} else if($object['window-view'] == 'во двор'){
$additional_information[] = 'window_view = 1';
}
}
if(isset($object['lot-type'])){
if($object['lot-type'] == 'ИЖС'){
$baseObject[] = "land_usage_type_id = 1";
} else if($object['lot-type'] == 'садоводство'){
$baseObject[] = "land_usage_type_id = 6";
}
}
if(isset($object['ceiling-height'])){
$additional_information[] = "ceiling_height = '".$object['ceiling-height']."'";
}
if(isset($object['cadastral-number'])){
$baseObject[] = "cadastral_number = '".$object['cadastral-number']."'";
}
if(isset($object['studio']) && $object['studio'] == 1){
if(!isset($object['rooms'])){
$baseObject[] = "komnat=1";
$spinxObject['komnat'] = 1;
}
$baseObject[] = "studio_flag=1";
}
/*if(isset($object['ipoteka']) && !empty($object['ipoteka'])){
if($object['ipoteka'] === true || $object['ipoteka'] == 1 || $object['ipoteka'] == "Да" || $object['ipoteka'] == "+"){
$baseObject[] = "stoim_prim = 'Возможна ипотека'";
}
}
if(isset($object['so']) && !empty($object['so'])){
$baseObject[] = "ploshad = '".$object['so']."'";
}
if(isset($object['level']) && !empty($object['level'])){
$baseObject[] = "etazh = '".$object['level']."'";
}
if(isset($object['level_total']) && !empty($object['level_total'])){
$baseObject[] = "etazh_iz = '".$object['level_total']."'";
}
if(isset($object['ceiling']) && !empty($object['ceiling'])){
$additional_information[] = "ceiling_height = '".$object['ceiling']."'";
}
if(isset($object['quality_id']) && !empty($object['quality_id'])){
$quality_id = '';
if($object['quality_id'] == 1){
$quality_id = 3;
} else if ($object['quality_id'] == 2){
$quality_id = 1;
} else if ($object['quality_id'] == 3){
$quality_id = 1;
} else if ($object['quality_id'] == 4){
$quality_id = 1;
} else if ($object['quality_id'] == 5){
$quality_id = 1;
}
else if ($object['quality_id'] == 6){
$quality_id = 5;
} else if ($object['quality_id'] == 7){
$quality_id = 1;
} else if ($object['quality_id'] == 8){
$quality_id = 2;
} else if ($object['quality_id'] == 9){
$quality_id = 2;
} else if ($object['quality_id'] == 10){
$quality_id = 2;
}
$additional_information[] = "commer_condition = '".$quality_id."'";
}
if(isset($object['built_year']) && !empty($object['built_year'])){
$additional_information[] = "commerc_year = '".$object['built_year']."'";
}
if(isset($object['description']) && !empty($object['description'])){
$baseObject[] = "opis = '".str_replace('\'','',$object['description'])."'";
}
if(isset($object['images'])){
$counter = 0;
foreach($object['images'] as $im){
foreach ($im as $image){
$counter++;
if($counter<21){
$baseObject[] = "photo$counter = '".$image['file_name_big']."'";
} else {
$additional_information[] = "photo$counter = '".$image['file_name_big']."'";
}
}
}
}
//var_dump($object);
$object_id = 0;
$sql = "SELECT * from bnru_objects WHERE bn_id=".$object['external_id'];
$q=mysql_query($sql);
$r=mysql_fetch_assoc($q);
$object_id = $r['object_id'];
//echo $object_id." - ";
//$cord = $object['gmap']['@attributes'];
//var_dump($sp_metro);
/*if (!empty($sp_metro)){
$sql = "UPDATE sp_metro SET ".implode(', ', $sp_metro)." WHERE id_obj=".$object_id;
if(!mysql_query($sql)){
echo mysql_error()."\n";
}
//echo $sql;
}*/
//echo "\n";
//$query = "INSERT INTO object_location (object_id, address,latitude, longitude) VALUES ($object_id, '$adress', '$cord[lat]', '$cord[lng]')";
/*if(!mysql_query($query)){
echo mysql_error()."\n";
}*/
$phone = '';
$fio_client = '';
if(!empty($baseObject) && !empty($object['@attributes']['internal-id'])){
//echo $object['external_id'].'-';
$user = $this->set_agents($object['sales-agent']['phone'],$object['sales-agent']['email']);
// var_dump($user);
//echo "\n";
if($user !== 'Не найден'){
$client_id = 0;
$arrObj = array();
$is_new_client = false;
if(isset($object['ownerdata'])){
$fio_client = trim($object['ownerdata']['fio']);
$phone = '+'.trim($object['ownerdata']['phone']);
}
/* if(isset($object['extra']['contact'])){
$phone = '+'.str_replace(['+', ' ', '-', ')', '('], '', $object['extra']['contact']['phone']);
$fio_client = '';
if(!is_array($object['extra']['contact']['surname'])){
$fio_client .= $object['extra']['contact']['surname'];
}
if(!is_array($object['extra']['contact']['name'])){
if($fio_client != '') $fio_client .= ' ';
$fio_client .= $object['extra']['contact']['name'];
}
if(!is_array($object['extra']['contact']['patronymic'])){
if($fio_client != '') $fio_client .= ' ';
$fio_client .= $object['extra']['contact']['patronymic'];
}
//trim($object['extra']['contact']['surname'].' '.$object['extra']['contact']['name'].' '.$object['extra']['contact']['patronymic'] );
}
if(isset($phone) && !empty($phone)){
$win = new WebHookIn(null, $agencyId);
$userIds = $win->getAllUserAgency($agencyId);
$sql_client = "SELECT * FROM clients WHERE phone='{$phone}' AND id_agent in (".implode(',', $userIds).")";
echo $sql_client."\n";
$q_client=mysql_query($sql_client);
if(mysql_num_rows($q_client) > 0){
$r_client = mysql_fetch_assoc($q_client);
$client_id = (int)$r_client['id'];
$arrObj = json_decode(html_entity_decode($r_client['objects']), ENT_QUOTES);
// var_dump($arrObj);
} else {
$is_new_client = true;
}
}
echo $phone. ' - '.(int)$is_new_client."\n";
if($client_id==0 && isset($phone) && !empty($phone)){
$sql = "INSERT INTO clients SET phone='{$phone}', fio='{$fio_client}', opis='По фиду объектов', id_agent={$user['id']}, who_work={$user['id']}, date_add=NOW(), confirm=1, stage=1, integration=100";
echo $sql."\n";
mysql_query($sql);
$client_id = mysql_insert_id();
}*/
//if(isset($object['owner_contract_exclusive'])){
/* $sqlA = "SELECT * FROM `activities` WHERE user_id = $user[agencyId] and name='Внешний прайс'";
echo $sqlA."\n";
$qA = mysql_query($sqlA);
if(mysql_num_rows($qA) == 0){
$sqlAI = "INSERT INTO activities set user_id=$user[agencyId], name='Внешний прайс'";
//echo $sqlAI."\n";
//mysql_query($sqlAI);
$activity_id = mysql_insert_id();
} else {
$rA = mysql_fetch_assoc($qA);
$activity_id = (int)$rA['id'];
}*/
//$object_activities[] = 'activity_id = 504';
//}
$comment = '';
/*if(isset($object['owner_contract_number'])){
$comment .= 'Номер договора: '.$object['owner_contract_number'];
}
if(isset($object['owner_contract_date_created'])){
if($comment != '') $comment .= '<br>';
$comment .= 'Дата подписания договора: '.date('d.m.Y', strtotime($object['owner_contract_date_created']));
}
if(isset($object['owner_contract_date'])){
if($comment != '') $comment .= '<br>';
$comment .= 'Дата окончания договора: '.date('d.m.Y', strtotime($object['owner_contract_date']));
//$object_event[] = array('comment'=>'дата окончания договора', 'type'=>'comment', 'create_date'=>date('Y-m-d H:i:s', strtotime($object['owner_contract_date'])), 'user_id'=>$user['id']);
}*/
if($comment != ''){
$object_event[] = "comment='".$comment."'";
$object_event[] = "user_id=".$user['id'];
$object_event[] = "type='comment'";
//$object_event[] = "create_date='".$date."'";
}
/* $baseObject[] = "archive = 1";
$spinxObject['archive'] = 1;*/
//var_dump($object_activities);
//var_dump($object_event);
//var_dump($baseObject);
//var_dump($sale_objects);
// var_dump($object_nb_info);
/*var_dump($additional_information);
var_dump($sp_metro);*/
//var_dump($location);
//var_dump($photos);
//$object['@attributes']['external_id'];
$sqle = "SELECT * FROM `bnru_objects` WHERE (internal_id = '".$object['@attributes']['internal-id']."') AND user_id = {$user['id']}";
echo $sqle."\n";
$qe = mysql_query($sqle);
if(mysql_num_rows($qe) == 0){
$number++;
$baseObject[] = "id_add_user = ".$user['id'];
$baseObject[] = "phone = '".$user['phone']."'";
$baseObject[] = "sobstv = '".$user['fio']."'";
$spinxObject['id_add_user'] = $user['id'];
$date = date('Y-m-d H:i:s');
if(isset($object['last-update-date'])){
$baseObject[] = "date_really_add = '".date('Y-m-d H:i:s',strtotime($object['last-update-date']))."'";
$spinxObject['date_really_add'] = strtotime($object['last-update-date']);
} else {
$baseObject[] = "date_really_add = '".date('Y-m-d H:i:s',strtotime($object['creation-date']))."'";
$spinxObject['date_really_add'] = strtotime($object['creation-date']);
}
if(isset($object['creation-date'])){
$date = date('Y-m-d H:i:s',strtotime($object['creation-date']));
}
$baseObject[] = "date_add = '".date('Y-m-d H:i:s')."'";
$spinxObject['date_add'] = time();
// $baseObject[] = "adres = '".$address."'";
//$location[] = "address = '".$address."'";
/* if(isset($object['location']['latitude']) && isset($object['location']['longitude'])){
$location[] = "latitude='".$object['location']['latitude']."'";
$location[] = "longitude='".$object['location']['longitude']."'";
}*/
var_dump($baseObject);
var_dump($sale_objects);
var_dump($object_nb_info);
var_dump($object_prices);
//if($number == 1) break;
// var_dump($objectPriceHistory);
//var_dump($location);
/* try {
$arrAdres = $this->getDadate($address);
if(!empty($arrAdres[0]['value'])){
$adres = $arrAdres[0]['value'];
} else {
$adres = $address;
}
$baseObject[] = "adres = '".$adres."'";
$spinxObject['adres'] = $adres;
if(!empty($arrAdres[0]['data']['house'])){
$baseObject[] = "dom = '".$arrAdres[0]['data']['house']."'";
}
} catch (Exception $e){
echo $object['@attributes']['internal-id'].' ';
if(isset($object['location']['street']) && !empty($object['location']['street'])){
$location[] = "street = '".$object['location']['street']."'";
}
if(isset($object['location']['house']) && !empty($object['location']['house'])){
$dopObject[] = "dom = '".$object['location']['house']."'";
$baseObject[] = "dom = '".$object['location']['house']."'";
}
if(isset($object['location']['korpus']) && !empty($object['location']['korpus'])){
$dopObject[] = "korpus = '".$object['location']['korpus']."'";
$baseObject[] = "korpus = '".$object['location']['korpus']."'";
}
if(isset($object['location']['litera']) && !empty($object['location']['litera'])){
$dopObject[] = "litera = '".$object['location']['litera']."'";
$baseObject[] = "litera = '".$object['location']['litera']."'";
}
$baseObject[] = "adres = '".$adres."'";
$spinxObject['adres'] = $adres;
echo $e->getMessage();
echo "\n";
}
if(isset($object['location']['latitude']) && isset($object['location']['longitude'])){
$location[] = "latitude='".$object['location']['latitude']."'";
$location[] = "longitude='".$object['location']['longitude']."'";
} else{
if(!empty($arrAdres[0]['data']['geo_lat'])){
$location[] = "latitude='".$arrAdres[0]['data']['geo_lat']."'";
$location[] = "longitude='".$arrAdres[0]['data']['geo_lon']."'";
}
}
if(!empty($location)){
$location[] = "address='".$adres."'";
if(!empty($arrAdres[0]['data']['city'])){
$location[] = "city='".$arrAdres[0]['data']['city']."'";
}
if(!empty($arrAdres[0]['data']['street_with_type'])){
$location[] = "street='".$arrAdres[0]['data']['street_with_type']."'";
}
} else {
$location[] = "city = '".$object['location']['locality-name']."'";
}
$query = "INSERT INTO objects SET ".implode(', ', $baseObject);
// echo $query."\n";
if(mysql_query($query)){
$object_id = mysql_insert_id();
$objectArr = array();
$objectArr[] = strval($object_id);
if(strpos($object['description'], 'Арт') !== false ){
$description = str_replace($object['objRep'], 'Арт. '.$object_id, str_replace("'", "`",$object['description']));
mysql_query("UPDATE objects SET opis='".mysql_real_escape_string($description)."' WHERE id=$object_id");
}
/* if(isset($phone) && !empty($phone)){
if(!in_array($object_id, $arrObj)){
$arrObj[] = strval($object_id);
}
$objList = htmlentities(json_encode($arrObj));
if($client_id == 0){
$role = '';
/* if($object['type'] == 'аренда'){
$role = "[&quot;Арендодатель&quot;]";
}
if($object['type'] == 'продажа') {
$role = "[&quot;Продавец&quot;]";
}*/
/* $funnel_id = 0;
$sql = "INSERT INTO clients SET phone='{$phone}', fio='{$fio_client}', opis='По фиду объектов', funnel_id={$funnel_id}, id_agent={$user['id']}, who_work={$user['id']},date_add=NOW(), deleted=0, objects='{$objList}', role='{$role}', confirm=1, stage=1, integration=100";
echo $sql."\n";
mysql_query($sql);
$client_id = mysql_insert_id();
$sql_obj = "INSERT INTO `client_objects`(`client_id`, `object_id`) VALUES ({$client_id},{$object_id})";
mysql_query($sql_obj);
$funnel_id_req = 0;
$name_req = "Реализация объекта для ".$fio_client;
$sql = "INSERT INTO requisitions SET name='{$name_req}', client_id={$client_id}, object_id={$object_id}, description='По фиду объектов', type_id=2, funnel_id={$funnel_id_req}, user_id={$user['id']}, who_work={$user['id']},who_delete={$user['id']}, deleted=0, confirm=1, stage=1, integration=100";
echo $sql."\n";
mysql_query($sql);
$req_id = mysql_insert_id();
if($req_id>0 && $funnel_id_req > 0){
$Requisitions = new Requisitions();
$Requisitions->get_class_etap($req_id, $funnel_id_req);
}
$sql_del = "INSERT INTO `events_clients`(`user_id`, `client_id`, `req_id`, `from_id`, `event`, `send_telegramm`, `read`) VALUES ({$user['id']}, 0, {$req_id}, {$user['id']}, 'delete', 1,1)";
//mysql_query($sql_del);
} else {
$up_client = "UPDATE clients SET objects='$objList' where id = $client_id";
$cl = new Clients();
$cl->update_objects($client_id, $objList);
mysql_query($up_client);
$funnel_id_req = 0;
$name_req = "Реализация объекта для ".$fio_client;
$sql = "INSERT INTO requisitions SET name='{$name_req}', client_id={$client_id}, object_id={$object_id}, description='По фиду объектов', type_id=2, funnel_id={$funnel_id_req}, user_id={$user['id']}, who_work={$user['id']},who_delete={$user['id']}, deleted=0, confirm=1, stage=1, integration=100";
echo $sql."\n";
mysql_query($sql);
$req_id = mysql_insert_id();
if($req_id>0 && $funnel_id_req > 0){
$Requisitions = new Requisitions();
$Requisitions->get_class_etap($req_id, $funnel_id_req);
}
$sql_del = "INSERT INTO `events_clients`(`user_id`, `client_id`, `req_id`, `from_id`, `event`, `send_telegramm`, `read`) VALUES ({$user['id']}, 0, {$req_id}, {$user['id']}, 'delete', 1,1)";
//mysql_query($sql_del);
}
if($client_id > 0){
$sql_b = "UPDATE bnru_objects SET client_id={$client_id} WHERE object_id = {$object_id}";
mysql_query($sql_b);
}
}
*/
/* if(!mysql_query("INSERT INTO bnru_objects SET user_id = ".$user['id'].", client_id={$client_id}, object_id =".$object_id.", internal_id = '".$object['@attributes']['internal-id']."'")){
echo mysql_error()."\n";
}
/* $complex_id = 98;
$complex_corpuse_id = 405;
$sql_complex = "SELECT id FROM complex_objects WHERE complex_id={$complex_id} AND object_id={$object_id}";
$q_complex = mysql_query($sql_complex);
if(mysql_num_rows($q_complex) == 0){
mysql_query("INSERT INTO complex_objects SET complex_id={$complex_id}, object_id={$object_id}, corpus_id={$complex_corpuse_id}");
}*/
/* if(!empty($additional_information)){
$additional_information[] = "object_id = ".$object_id;
$query = "INSERT INTO objects_additional_information SET ".implode(', ', $additional_information);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($sale_objects)){
$sale_objects[] = "object_id = ".$object_id;
$query = "INSERT INTO sale_objects SET ".implode(', ', $sale_objects);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($location)){
$location[] = "object_id = ".$object_id;
$query = "INSERT INTO object_location SET ".implode(', ', $location);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if (!empty($sp_metro)){
foreach($sp_metro as $metro){
$sql = "INSERT INTO sp_metro SET id_metro = $metro, id_obj=".$object_id;
if(!mysql_query($sql)){
echo mysql_error()."\n";
}
}
//echo $sql;
}
if(!empty($object_activities)){
$object_activities[] = "object_id=".$object_id;
$query = "INSERT INTO objects_activities SET ".implode(', ', $object_activities);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($object_event)){
$object_event[] = "object_id=".$object_id;
$query = "INSERT INTO user_object_events SET ".implode(', ', $object_event);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($object_nb_info)){
$object_nb_info[] = "object_id = ".$object_id;
$query = "INSERT INTO object_nb_info SET ".implode(', ', $object_nb_info);
echo $query."\n";
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($objectPriceHistory)){
$objectPriceHistory[] = "object_id = ".$object_id;
$query = "INSERT INTO objects_price_history SET ".implode(', ', $objectPriceHistory);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($object_prices)){
$object_prices[] = "object_id = ".$object_id;
$query = "INSERT INTO object_prices SET ".implode(', ', $object_prices);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($spinxObject)){
$spinxObject['id'] = $object_id;
$spinxObject['country_id'] = 171;
$columns = [];
$columnsVal = [];
foreach($spinxObject as $key => $val){
$columns[] = $key;
$columnsVal[] = "'".$val."'";
}
$sql_sh = "INSERT INTO objects_rt (".implode(',',$columns).")
VALUES(".implode(',',$columnsVal).")";
echo $sql_sh."\n";
$db_sphinx->query($sql_sh);
}
$photos = array();
$num=1;
// var_dump($object['image']);
if(isset($object['image']) && !empty($object['image'])){
$sql_photo = "SELECT id FROM objects_object_photo WHERE object_id = {$object_id}";
$q_photo = mysql_query($sql_photo);
if(mysql_num_rows($q_photo) == 0){
//var_dump($object['image']);
foreach($object['image'] as $img) {
echo $img."\n";
$ph = md5($img.time())."_ind.jpg";
$one = mb_substr($ph,0,1);
// ftp_mkdir($conn, "/photos/$one");
$two = mb_substr($ph,1,1);
// ftp_mkdir($conn, "/photos/$one/$two");
$three = mb_substr($ph,3,1);
// ftp_mkdir($conn, "/photos/$one/$two/$three");
$dstFile = "/$one/$two/$three/$ph";
$rf = SelectelApi::uploadFile($storageUrl, $token, $img, $dstFile, 'image/jpeg');
//если выложили в Selectel
if ($rf) {
//заменяем путь на новый
$new_path = "https://data.joywork.ru" . $dstFile;
$photos['photo'.$num] = $new_path;
echo $new_path."\n";
//удаляем файл с локального сервера
// unlink($fp);
}
else {
echo "не скопирован в $dstFile";
}
$num++;
}
//ftp_close($conn);
echo $object_id."\n";
// var_dump($photos);
$this->update_photo($object_id, $photos);
}
}
// $this->update_photo($object_id, $photos);
// break;
} else {
echo mysql_error()."\n";
}
//echo $object['external_id'].' - '; var_dump($baseObject); echo "\n\n";
// break;
// if($number == 1) break;
//}*/
// if($number == 1) break;
} else {
$total++;
$re=mysql_fetch_assoc($qe);
$object_id = $re['object_id'];
/*var_dump($opis);
var_dump($client_id);
var_dump($fio_client);
var_dump($phone);
var_dump($spinxObject);*/
/*$tag = '';
if(isset($object['village-name']) && !empty($object['village-name'])){
$tag = trim(mb_strtolower($object['village-name']));
$sql_a = "SELECT * FROM `activities` where user_id = 22666 AND LOWER(name) = '{$tag}'";
$q_a = mysql_query($sql_a);
$r_a = mysql_fetch_assoc($q_a);
if(isset($r_a['id'])){
$sql_a2 = "SELECT * FROM `objects_activities` WHERE object_id = {$object_id} AND activity_id = {$r_a['id']}";
$q_a2 = mysql_query($sql_a2);
if(mysql_num_rows($q_a2) == 0){
$sql_in = "INSERT INTO objects_activities (object_id, activity_id) VALUES ({$object_id}, {$r_a['id']})";
echo $sql_in."\n";
$q_in = mysql_query($sql_in);
}
} else {
echo $tag."\n";
}
}
/* if(!empty($object['cadastral-number'])){
$sql = "UPDATE objects SET cadastral_number='{$object['cadastral-number']}' WHERE id = {$object_id}";
echo $sql."\n";
mysql_query("UPDATE objects SET cadastral_number='{$object['cadastral-number']}' WHERE id = {$object_id}");
}
/* if(isset($phone) && !empty($phone)){
if(!in_array($object_id, $arrObj)){
$arrObj[] = strval($object_id);
}
$objList = htmlentities(json_encode($arrObj));
if($client_id == 0){
$role = '';
/* if($object['type'] == 'аренда'){
$role = "[&quot;Арендодатель&quot;]";
}
if($object['type'] == 'продажа') {
$role = "[&quot;Продавец&quot;]";
}*/
/* $funnel_id = 0;
$sql = "INSERT INTO clients SET phone='{$phone}', fio='{$fio_client}', opis='По фиду объектов', funnel_id={$funnel_id}, id_agent={$user['id']}, who_work={$user['id']},date_add=NOW(), deleted=0, objects='{$objList}', role='{$role}', confirm=1, stage=1, integration=100";
echo $sql."\n";
mysql_query($sql);
$client_id = mysql_insert_id();
$sql_obj = "INSERT INTO `client_objects`(`client_id`, `object_id`) VALUES ({$client_id},{$object_id})";
mysql_query($sql_obj);
$funnel_id_req = 0;
$name_req = "Реализация объекта для ".$fio_client;
$sql = "INSERT INTO requisitions SET name='{$name_req}', client_id={$client_id}, object_id={$object_id}, description='По фиду объектов', type_id=2, funnel_id={$funnel_id_req}, user_id={$user['id']}, who_work={$user['id']},who_delete={$user['id']}, deleted=1, confirm=1, stage=1, integration=100";
echo $sql."\n";
mysql_query($sql);
$req_id = mysql_insert_id();
if($req_id>0 && $funnel_id_req > 0){
$Requisitions = new Requisitions();
$Requisitions->get_class_etap($req_id, $funnel_id_req);
}
$sql_del = "INSERT INTO `events_clients`(`user_id`, `client_id`, `req_id`, `from_id`, `event`, `send_telegramm`, `read`) VALUES ({$user['id']}, 0, {$req_id}, {$user['id']}, 'delete', 1,1)";
mysql_query($sql_del);
/* } else {
$up_client = "UPDATE clients SET objects='$objList' where id = $client_id";
$cl = new Clients();
$cl->update_objects($client_id, $objList);
mysql_query($up_client);
$funnel_id_req = 0;
$name_req = "Реализация объекта для ".$fio_client;
$sql = "INSERT INTO requisitions SET name='{$name_req}', client_id={$client_id}, object_id={$object_id}, description='По фиду объектов', type_id=2, funnel_id={$funnel_id_req}, user_id={$user['id']}, who_work={$user['id']},who_delete={$user['id']}, deleted=1, confirm=1, stage=1, integration=100";
echo $sql."\n";
mysql_query($sql);
$req_id = mysql_insert_id();
if($req_id>0 && $funnel_id_req > 0){
$Requisitions = new Requisitions();
$Requisitions->get_class_etap($req_id, $funnel_id_req);
}
$sql_del = "INSERT INTO `events_clients`(`user_id`, `client_id`, `req_id`, `from_id`, `event`, `send_telegramm`, `read`) VALUES ({$user['id']}, 0, {$req_id}, {$user['id']}, 'delete', 1,1)";
mysql_query($sql_del);
}
if($client_id > 0){
$sql_b = "UPDATE bnru_objects SET client_id={$client_id} WHERE object_id = {$object_id}";
mysql_query($sql_b);
}
}*/
// if($object_id >= 48970789){
// $dopObject[] = "archive = 1";
$location = array();
$baseObject = array();
//var_dump($baseObject);
//var_dump($objectPriceHistory);
//var_dump($location);
// echo $address."\n";
/* try {
$arrAdres = $this->getDadate($address);
if(!empty($arrAdres[0]['value'])){
$adres = $arrAdres[0]['value'];
} else {
$adres = $address;
}
$baseObject[] = "adres = '".$adres."'";
if(!empty($arrAdres[0]['data']['house'])){
$baseObject[] = "dom = '".$arrAdres[0]['data']['house']."'";
}
} catch (Exception $e){
echo $object['@attributes']['internal-id'].' ';
$baseObject[] = "adres = '".$adres."'";
echo $e->getMessage();
echo "\n";
}
if(isset($object['location']['latitude']) && isset($object['location']['longitude'])){
$location[] = "latitude='".$object['location']['latitude']."'";
$location[] = "longitude='".$object['location']['longitude']."'";
} else{
if(!empty($arrAdres[0]['data']['geo_lat'])){
$location[] = "latitude='".$arrAdres[0]['data']['geo_lat']."'";
$location[] = "longitude='".$arrAdres[0]['data']['geo_lon']."'";
}
}
if(!empty($location)){
$location[] = "address='".$adres."'";
if(!empty($arrAdres[0]['data']['city'])){
$location[] = "city='".$arrAdres[0]['data']['city']."'";
}
if(!empty($arrAdres[0]['data']['street_with_type'])){
$location[] = "street='".$arrAdres[0]['data']['street_with_type']."'";
}
}
// var_dump($baseObject);
// var_dump($location);
if(!empty($location)){
$query = "UPDATE object_location SET ".implode(', ', $location)." WHERE object_id = ".$object_id;
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
var_dump($baseObject);
if(!empty($baseObject)){
$query = "UPDATE objects SET ".implode(', ', $baseObject)." WHERE id = ".$object_id;
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
$sql_sh = "UPDATE objects SET archive = 1 WHERE id = {$object_id}";
echo $sql_sh."\n";
$db_sphinx->query($sql_sh);
//if($total > 9) break;
// $location[] = "city='".$arrAdres[0]['data']['city']."'";
/* echo $object['objRep']."\n";
$description = str_replace($object['objRep'], 'Арт. '.$object_id, $object['description']);*/
//var_dump($baseObject);
//$baseObject[] = "opis='".str_replace("'", "`",$description)."'";
/* $baseObject[] = "id_add_user = ".$user['id'];
$baseObject[] = "phone = '".$user['phone']."'";
$baseObject[] = "sobstv = '".$user['fio']."'";
$query = "UPDATE objects SET ".implode(', ', $baseObject)." WHERE id = ".$object_id;
// echo $query;
if(!mysql_query($query)){
echo mysql_error()."\n";
}*/
/* if(strpos($object['description'], 'Арт') !== false ){
$description = str_replace($object['objRep'], 'Арт. '.$object_id, str_replace("'", "`",$object['description']));
mysql_query("UPDATE objects SET opis='".$description."' WHERE id=$object_id");
}
if(!empty($sale_objects)){
//$sale_objects[] = "object_id = ".$object_id;
$query = "UPDATE sale_objects SET ".implode(', ', $sale_objects)." WHERE object_id = ".$object_id;
//echo $query."\n";
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($additional_information)){
//objects_additional_information WHERE object_id
$sql = "SELECT id FROM objects_additional_information WHERE object_id = ".$object_id;
$q = mysql_query($sql);
if(mysql_num_rows($q) == 0){
$additional_information[] = "object_id = ".$object_id;
$query = "INSERT INTO objects_additional_information SET ".implode(', ', $additional_information);
} else {
$query = "UPDATE objects_additional_information SET ".implode(', ', $additional_information)." WHERE object_id = ".$object_id;
}
//echo $query."\n";
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($object_nb_info)){
//objects_additional_information WHERE object_id
$sql = "SELECT id FROM object_nb_info WHERE object_id = ".$object_id;
$q = mysql_query($sql);
if(mysql_num_rows($q) == 0){
$additional_information[] = "object_id = ".$object_id;
$query = "INSERT INTO object_nb_info SET ".implode(', ', $object_nb_info);
} else {
$query = "UPDATE object_nb_info SET ".implode(', ', $object_nb_info)." WHERE object_id = ".$object_id;
}
//echo $query."\n";
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}*/
/* $number++;
$photos = array();
$num=1;
// var_dump($object['image']);*/
/* if(isset($object['image']) && !empty($object['image'])){
$sql_photo = "delete from objects_object_photo WHERE object_id = {$object_id}";
$q_photo = mysql_query($sql_photo);
// if(mysql_num_rows($q_photo) == 0){
//var_dump($object['image']);
foreach($object['image'] as $img) {
echo $img."\n";
$ph = md5($img.time())."_ind.jpg";
$one = mb_substr($ph,0,1);
// ftp_mkdir($conn, "/photos/$one");
$two = mb_substr($ph,1,1);
// ftp_mkdir($conn, "/photos/$one/$two");
$three = mb_substr($ph,3,1);
// ftp_mkdir($conn, "/photos/$one/$two/$three");
$dstFile = "/$one/$two/$three/$ph";
$rf = SelectelApi::uploadFile($storageUrl, $token, $img, $dstFile, 'image/jpeg');
//если выложили в Selectel
if ($rf) {
//заменяем путь на новый
$new_path = "https://data.joywork.ru" . $dstFile;
$photos['photo'.$num] = $new_path;
echo $new_path."\n";
//удаляем файл с локального сервера
// unlink($fp);
}
else {
echo "не скопирован в $dstFile";
}
$num++;
}
//ftp_close($conn);
echo $object_id."\n";
// var_dump($photos);
$this->update_photo($object_id, $photos);
// }
}*/
// }
// if($number == 1) break;
// $this->update_photo($object_id, $photos);
// break;
// if($total == 1) break;
}
} else {
echo $object['sales-agent']['email']."\n";
echo $object['sales-agent']['phone']."\n";
// $total++;
}
//if($number > 1) break;
}
echo $number."\n";
//}
}
//echo $total;
}
}
/* public function getObjectsAvito($url){
$xmlArray = $this->XmlArray($url);
$array = array();
$objects = $xmlArray['Ads']['Ad'];
echo count($objects)."\n";
foreach($objects as $object){
$baseObject = array();
$additional_information = array();
$sp_metro = array();
$sale_objects = array();
$location = array();
//$sql = "SELECT id FROM objects WHERE id = $object[Id]";
//$q = mysql_query($sql);
//if(mysql_num_rows($q) == 0){
//$baseObject[]="id=".$object['Id'];
if(strpos($object['Address'],'Петрозаводск') !== false){
$baseObject[] = 'id_rf_region = 13';
} else if(strpos($object['Address'],'Респ Карелия') !== false){
$baseObject[] = 'id_rf_region = 13';
} else if(strpos($object['Address'],'Краснодарский край') !== false){
$baseObject[] = 'id_rf_region = 26';
} else if(strpos($object['Address'],'Калужская Область') !== false){
$baseObject[] = 'id_rf_region = 43';
} else if(strpos($object['Address'],'Республика Крым') !== false){
$baseObject[] = 'id_rf_region = 3';
}
else if (strpos($object['Address'],'Самарская область') !== false){
$baseObject[] = 'id_rf_region = 66';
} else if(strpos($object['Address'],'Москва') !== false || strpos($object['Address'],'Московская обл') !== false){
$baseObject[] = 'id_rf_region = 1';
}
else {
echo $object['Address']."\n";
}
//$baseObject[] = 'id_rf_region = 78';
/* $baseObject[] = "adres='".$object['Address']."'";
if(isset($object['Latitude']) && isset($object['Longitude'])){
$location[] = "latitude='".$object['Latitude']."'";
$location[] = "longitude='".$object['Longitude']."'";
$location[] = "address='".$object['Address']."'";
}*/
/* $address = $object['Address'];
try {
$arrAdres = $this->getDadate($address);
if(!empty($arrAdres[0]['value'])){
$adres = $arrAdres[0]['value'];
} else {
$adres = $address;
}
$baseObject[] = "adres = '".$adres."'";
if(!empty($arrAdres[0]['data']['house'])){
$baseObject[] = "dom = '".$arrAdres[0]['data']['house']."'";
}
} catch (Exception $e){
echo $object['@attributes']['internal-id'].' ';
echo $e->getMessage();
echo "\n";
}
if(!empty($arrAdres[0]['data']['geo_lat'])){
$location[] = "latitude='".$arrAdres[0]['data']['geo_lat']."'";
$location[] = "longitude='".$arrAdres[0]['data']['geo_lon']."'";
}
if(!empty($location)){
$location[] = "address='".$adres."'";
if(!empty($arrAdres[0]['data']['city'])){
$location[] = "city='".$arrAdres[0]['data']['city']."'";
}
if(!empty($arrAdres[0]['data']['street_with_type'])){
$location[] = "street='".$arrAdres[0]['data']['street_with_type']."'";
}
}*/
/*(isset($object['description'])){
$description = $object['description'];
$objRep = '';
$exD = explode(' ', $description);
//var_dump($exD);
if(isset($exD[0]) && isset($exD[1])){
$objRep .= $exD[0].' '.$exD[1];
}
$object['objRep'] = $objRep;
//echo $object['objRep']."\n";
$baseObject[]="opis = '".htmlentities(str_replace("'", "`",$object['description']))."'";
}*/
/* if(isset($object['Description'])){
$description = $object['Description'];
$objRep = '';
$exD = explode(' ', $description);
//var_dump($exD);
if(isset($exD[0]) && isset($exD[1])){
$objRep .= $exD[0].' '.$exD[1];
}
$object['objRep'] = $objRep;
$baseObject[] = "opis = '".htmlentities(str_replace('\n','<br>',$object['Description']))."'";
}*/
/* if(isset($object['Category'])){
if($object['Category'] == "Квартиры"){
$baseObject[] = 'type = 1';
$nazv = $object['Rooms']."-к квартира (".$object['Square']." м.кв)";
$baseObject[] = "nazv = '".$nazv."'";
} else if($object['Category'] == "Дома, дачи, коттеджи"){
$baseObject[] = 'type = 3';
$nazv = $object['ObjectType']." (".$object['Square']." м.кв)";
$baseObject[] = "nazv = '".$nazv."'";
} else if($object['Category'] == "Комнаты"){
$baseObject[] = 'type = 2';
$nazv = "Комната (".$object['Square']." м.кв)";
$baseObject[] = "nazv = '".$nazv."'";
} else if($object['Category'] == "Земельные участки"){
$baseObject[] = 'type = 7';
$nazv = "Участок";
if(isset($object['Square'])){
$nazv .= " (".$object['Square']." м.кв)";
}
$baseObject[] = "nazv = '".$nazv."'";
} else if($object['Category'] == "Коммерческая недвижимость"){
$baseObject[] = 'type = 4';
if($object['ObjectType'] == "Здание"){
$baseObject[] = 'type_category = 6';
$additional_information[] = 'commercial_object_id = 6';
$nazv = $object['ObjectType']." (".$object['Square']." м.кв)";
} else if($object['ObjectType'] == "Помещение свободного назначения"){
$baseObject[] = 'type_category = 5';
$additional_information[] = 'commercial_object_id = 5';
$nazv = $object['ObjectType']." (".$object['Square']." м.кв)";
} else if($object['ObjectType'] == "Офисное помещение"){
$baseObject[] = 'type_category = 1';
$additional_information[] = 'commercial_object_id = 1';
$nazv = $object['ObjectType']." (".$object['Square']." м.кв)";
} else if($object['ObjectType'] == "Складское помещение"){
$baseObject[] = 'type_category = 2';
$additional_information[] = 'commercial_object_id = 2';
$nazv = $object['ObjectType']." (".$object['Square']." м.кв)";
} else {
echo $object['ObjectType']."\n";
}
} else {
echo $object['Category']."\n";
}
}
if(isset($object['OperationType'])){
if($object['OperationType'] == "Продам"){
$baseObject[] = "operation_type = 1";
} else if($object['OperationType'] == "Сдам"){
$baseObject[] = "operation_type = 0";
} else {
echo $object['OperationType']."\n";
}
}
if(isset($object['Price'])){
$baseObject[] = "stoim = '".$object['Price']."'";
}
if(isset($object['Rooms'])){
$baseObject[] = "komnat = '".$object['Rooms']."'";
}
if(isset($object['Square'])){
$baseObject[] = "ploshad = '".$object['Square']."'";
}
if(isset($object['Floor'])){
$baseObject[] = "etazh = '".$object['Floor']."'";
}
if(isset($object['Floors'])){
$baseObject[] = "etazh_iz = '".$object['Floors']."'";
}
if(isset($object['HouseType'])){
//$sale_objects[] = "house_type = ";
//$baseObject[] = "Floors = '".$object['Floors']."'";
if($object['HouseType'] == "Монолитный"){
$sale_objects[] = "house_type = 15";
} else if($object['HouseType'] == "Кирпичный"){
$sale_objects[] = "house_type = 1";
} else if($object['HouseType'] == "Панельный"){
$sale_objects[] = "house_type = 2";
} else if($object['HouseType'] == "Деревянный"){
$sale_objects[] = "house_type = 18";
} else{
echo $object['HouseType']."\n";
}
}
if(isset($object['BalconyOrLoggia'])){
if($object['BalconyOrLoggia'] == "Балкон"){
$additional_information[] = "balcony = 1";
} else if ($object['BalconyOrLoggia'] == "Балкон"){
$additional_information[] = "Лоджия = 1";
}
}
if(isset($object['CadastralNumber'])){
if(!is_array($object['CadastralNumber'])){
$baseObject[] = "cadastral_number='".$object['CadastralNumber']."'";
}
//var_dump($object['CadastralNumber']);
}
$user = $this->set_agents($object['ContactPhone']);
if(!empty($baseObject)){
//echo $object['external_id'].'-';
$user = $this->set_agents($object['ContactPhone'], $object['EMail']);
// var_dump($user);
/* $baseObject[] = "id_add_user = ".$user['id'];
$baseObject[] = "phone = '".$user['phone']."'";
$baseObject[] = "sobstv = '".$user['fio']."'";
$baseObject[] = "date_really_add = '".date('Y-m-d H:i:s')."'";
$baseObject[] = "date_add = '".date('Y-m-d H:i:s')."'";*/
// var_dump($baseObject);
//var_dump($sale_objects);
//var_dump($additional_information);
/* $sqle = "SELECT * FROM `bnru_objects` WHERE internal_id = '".$object['Id']."'";
$qe = mysql_query($sqle);
if(mysql_num_rows($qe) == 0){ /*
try {
$arrAdres = $this->getDadate($address);
if(!empty($arrAdres[0]['value'])){
$adres = $arrAdres[0]['value'];
} else {
$adres = $address;
}
$baseObject[] = "adres = '".$adres."'";
if(!empty($arrAdres[0]['data']['house'])){
$baseObject[] = "dom = '".$arrAdres[0]['data']['house']."'";
}
} catch (Exception $e){
echo $object['@attributes']['internal-id'].' ';
echo $e->getMessage();
echo "\n";
}
$query = "INSERT INTO objects SET ".implode(', ', $baseObject);
//echo $query."\n";
if(mysql_query($query)){
$object_id = mysql_insert_id();
if(!mysql_query("INSERT INTO bnru_objects SET user_id = ".$user['id'].", object_id =".$object_id.", internal_id = '".$object['Id']."'")){
echo mysql_error()."\n";
}
if(strpos($object['Description'], 'Арт') !== false ){
$description = str_replace($object['objRep'], 'Арт. '.$object_id, str_replace("'", "`",$object['Description']));
mysql_query("UPDATE objects SET opis='".$description."' WHERE id=$object_id");
}
if(!empty($additional_information)){
$additional_information[] = "object_id = ".$object_id;
$query = "INSERT INTO objects_additional_information SET ".implode(', ', $additional_information);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($sale_objects)){
$sale_objects[] = "object_id = ".$object_id;
$query = "INSERT INTO sale_objects SET ".implode(', ', $sale_objects);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
if(!empty($location)){
$location[] = "object_id = ".$object_id;
$query = "INSERT INTO object_location SET ".implode(', ', $location);
if(!mysql_query($query)){
echo mysql_error()."\n";
}
}
$photos = array();
$num=1;
if(isset($object['Images'])){
//var_dump($object['Images']['Image']);
$counter = 0;
foreach($object['Images']['Image'] as $img){
//var_dump($im['@attributes']['url']);
//var_dump($img);
$ph = md5($img['@attributes']['url'].time())."_adresa.jpg";
$one = mb_substr($ph,0,1);
ftp_mkdir($conn, "/photos/$one");
$two = mb_substr($ph,1,1);
ftp_mkdir($conn, "/photos/$one/$two");
$three = mb_substr($ph,3,1);
ftp_mkdir($conn, "/photos/$one/$two/$three");
$dstFile = "/photos/$one/$two/$three/$ph";
if (ftp_put($conn, $dstFile, $img['@attributes']['url'], FTP_ASCII)) {
echo "скопирован в $dstFile";
// copy($img,$_SERVER['DOCUMENT_ROOT']."/photos/".$new_path) ;
//echo $new_path."\n";
$photos['photo'.$num] = $dstFile;
} else {
echo "не скопирован в $dstFile";
}
$num++;
}
}
$this->update_photo($object_id, $photos);
} else {
echo mysql_error()."\n";
}*/
/* } else{
/* $re = mysql_fetch_assoc($qe);
$object_id = $re['object_id'];
$query = "UPDATE objects SET ".implode(', ', $baseObject)." WHERE id = ".$object_id;
echo $query."\n";
/* if(!mysql_query($query)){
echo mysql_error()."\n";
}*/
/* }
}
else {
//echo $object['Id']."\n";
}
}
}
}