foreach ($prices[0] as $item2) {
$all_price_sumnar++;
preg_match_all("'DATE=\"(.*?)\"'si", $item2, $date);
$price_date=$date[1][0];
$price_date=$price_date[0].$price_date[1].$price_date[2].$price_date[3]."-".$price_date[4].$price_date[5]."-".$price_date[6].$price_date[7];
preg_match_all("'N=\"(.*?)\"'si", $item2, $nights);
$price_nights=$nights[1][0];
preg_match_all("'VAL=\"(.*?)\"'si", $item2, $val);
$price_val=$val[1][0];
$elemdat = explode("-",$price_date);
$price_date_sec = mktime (0,0,0,$elemdat[1],$elemdat[2],$elemdat[0]);
if ($min_date_sec>$price_date_sec) {$min_date=$price_date;}
if ($max_date_sec<$price_date_sec) {$max_date=$price_date;}
// $SQL = "INSERT IGNORE INTO anextour_hotels (name) VALUES ('$price_hotelname');";
// $result = $DB->Query($SQL) or die(mysql_error());
$enabledprice=0;
if ($now_date_sec<=$price_date_sec) {
for ($ii=0;$ii<count($hotels_mas);$ii++) { // если найден такой символьный код в массиве инфоблоков, то записываем, если нет - то на нет и суда нет
//if ($hotels_mas[$ii][0]==$price_hotelname) {$enabledprice=1; break;} // нужно переделать сравнение с id в инфоблоке
//////////////////////////////////////////////////////////////////////
// var_dump($hotels_mas[$ii][1]);
if ($hotels_mas[$ii][1]==$price_id_anex){$enabledprice=1; break;}
// var_dump($hotels_mas[$ii][1]);
//////////////////////////////////////////////////////////////////////
}
// $SQL = "SELECT id from anextour_hotels where id_anex = '$price_id_anex'";
// $res = mysql_query($SQL);
// if(mysql_num_rows($res)) {$enabledprice=1;}
}
//if ($price_hotelname=='DOMINA PRESTIGE SEA') {$price_hotelname='DOMINA PRESTIGE POOL';}
//if ($price_hotelname=='DOMINA SULTAN POOL') {$price_hotelname='DOMINA SULTAN BEACH';}
// echo $enabledprice." ".$price_transportfrom." ".$price_chd." ".$price_inf."________";
if ($enabledprice==1 and $price_transportfrom=='Moscow' and $price_chd==0 and $price_inf==0) {
$elements_true_param++;
$SQL="SELECT id FROM anextour_spo_price WHERE spoid='$price_spo' and country='$price_country' and city='$price_city' and adl='$price_adl' and chd='$price_chd' and inf='$price_inf' and currency='$price_currency' and hotelname='$price_id_anex' and star='$price_star' and room='$price_room' and meal='$price_meal' and depature_from='$price_transportfrom' and depature_to='$price_transportto' and depature_date='$price_date' and days='$price_nights' and price='$price_val' and datecreate='$price_datecreate' LIMIT 1";
// hotelname = '$price_id_anex'
$res = mysql_query($SQL);
if(mysql_num_rows($res)) {$price_in_base=1; $elements_true_no_add++;}
else {$price_in_base=0;}
$true_replace=0;
$true_add=0;
$replace_id=0;
$SQL="SELECT id FROM anextour_spo_price WHERE hotelname='$price_id_anex' and depature_date='$price_date' and adl='$price_adl' and room='$price_room' and meal='$price_meal' and days='$price_nights' and datecreate<'$price_datecreate'";
// hotelname = '$price_id_anex'
$res = mysql_query($SQL);
if(mysql_num_rows($res)) {
while ($line = mysql_fetch_row($res)) {
$replace_id=$line[0];
$true_replace=1;
}}
if ($true_replace==0) {
$SQL="SELECT id FROM anextour_spo_price WHERE hotelname='$price_id_anex' and depature_date='$price_date' and adl='$price_adl' and room='$price_room' and meal='$price_meal' and days='$price_nights' and datecreate>='$price_datecreate'";
// hotelname = '$price_id_anex'
$res = mysql_query($SQL);
if(mysql_num_rows($res)) {$true_add=0; $elements_true_no_add++;}
else {$true_add=1;}
}
if (($true_replace==1 or $true_add==1) and ($price_in_base==0)) {
$elements_true_add_replace++;
$numprice++;
$all_price++;
$an++;
$anex_id = $an*100 + 1;
// var_dump($anex_id);
if ($sqfix=='') {
$sqfix=$sqfix." ('$anex_id','$price_spo','$price_country','$price_city','$price_adl','$price_chd','$price_inf','$price_currency','$price_id_anex','$price_star','$price_room','$price_meal','$price_transportfrom','$price_transportto','$price_date','$price_nights','$price_val','$price_datecreate','0')";
// '$price_id_anex'
}
else {
$sqfix=$sqfix.",('$anex_id','$price_spo','$price_country','$price_city','$price_adl','$price_chd','$price_inf','$price_currency','$price_id_anex','$price_star','$price_room','$price_meal','$price_transportfrom','$price_transportto','$price_date','$price_nights','$price_val','$price_datecreate','0')";
// '$price_id_anex'
}
}
if ($true_replace==1) {
$SQL = "DELETE FROM anextour_spo_price WHERE id='$replace_id'";
$result = $DB->Query($SQL);
$SQL = "DELETE FROM gate_spo_price_turkish WHERE id='$replace_id'";
$result = $DB->Query($SQL);
$SQL = "DELETE FROM gate_spo_price_egipt WHERE id='$replace_id'";
$result = $DB->Query($SQL);
}
}else{
$elements_false_param++;
}
if ($numprice>=$numstep*$step and $sqfix!='') {
$numstep++;
$SQL = "INSERT IGNORE INTO anextour_spo_price (id,spoid,country,city,adl,chd,inf,currency,hotelname,star,room,meal,depature_from,depature_to,depature_date,days,price,datecreate,download) VALUES $sqfix;";
$result = $DB->Query($SQL) or die(mysql_error());
// var_dump($SQL);
// var_dump($result);
$sqfix="";
}