/public_html/adm/import_nova/all_hotels.php
PHP | 189 lines | 134 code | 40 blank | 15 comment | 7 complexity | 5fe807bc8f7774b8602beb4966a220f6 MD5 | raw file
- <?php
- $xml = simplexml_load_file($sUrl);
- //error_reporting(E_ALL);
- //ini_set('display_errors', 1);
- $cod_tara="RO";
- $hoteluri = array();
- $tari_Xml = '<?xml version="1.0" encoding="UTF-8"?>
- <Request RequestType="getCountryRequest">
- <AuditInfo>
- <RequestId>'.date("dmYHis").'</RequestId>
- <RequestUser>'.$RequestUser.'</RequestUser>
- <RequestPass>'.$RequestPass.'</RequestPass>
- <RequestTime>'.date("Y-m-d").'T'.date("H-i-s").'</RequestTime>
- <RequestLang>RO</RequestLang>
- </AuditInfo>
- <RequestDetails>
- <getCountryRequest/>
- </RequestDetails>
- </Request>';
- //if(!$err_logare_admin) echo "pppp". $servicii_supliemtare_Xml ;
- $ch = curl_init($sUrl);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $tari_Xml);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 20);
- $sResponse_tari = curl_exec($ch);
- $tari_Xml = new SimpleXMLElement($sResponse_tari);
- //if(!$err_logare_admin) { echo '<pre>';print_r($tari_Xml);echo '</pre>'; echo $sXml ; }
- foreach($tari_Xml->ResponseDetails->getCountryResponse->Country as $value_tari)
- {
- //$country_code[]=trim($value_tari->CountryCode);
- if(!$err_logare_admin) { echo '<pre>';print_r($country_code);echo '</pre>'; echo $sXml ; }
- $localitati_Xml = '<?xml version="1.0" encoding="UTF-8"?>
- <Request RequestType="getCityRequest">
- <AuditInfo>
- <RequestId>'.date("dmYHis").'</RequestId>
- <RequestUser>'.$RequestUser.'</RequestUser>
- <RequestPass>'.$RequestPass.'</RequestPass>
- <RequestTime>'.date("Y-m-d").'T'.date("H-i-s").'</RequestTime>
- <RequestLang>RO</RequestLang>
- </AuditInfo>
- <RequestDetails>
- <getCityRequest CountryCode="'.trim($value_tari->CountryCode).'" />
- </RequestDetails>
- </Request>';
- //if(!$err_logare_admin) echo "pppp". $servicii_supliemtare_Xml ;
- $ch = curl_init($sUrl);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $localitati_Xml);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 20);
- $sResponse_localitati = curl_exec($ch);
- $localitati_Xml = new SimpleXMLElement($sResponse_localitati);
- //if(!$err_logare_admin) { echo '<pre>';print_r($localitati_Xml);echo '</pre>'; echo $sXml ; }
- foreach($localitati_Xml->ResponseDetails->getCityResponse->City as $value_loc)
- {
- //echo '<pre>';print_r($value_loc);echo '</pre>';
- echo "<br />".(string)$value_loc->CityCode;
- $hoteluri_Xml = '<?xml version="1.0" encoding="UTF-8"?>
- <Request RequestType="getOwnHotelsRequest">
- <AuditInfo>
- <RequestId>'.date("dmYHis").'</RequestId>
- <RequestUser>'.$RequestUser.'</RequestUser>
- <RequestPass>'.$RequestPass.'</RequestPass>
- <RequestTime>'.date("Y-m-d").'T'.date("H-i-s").'</RequestTime>
- <RequestLang>RO</RequestLang>
- </AuditInfo>
-
- <RequestDetails>
- <getOwnHotelsRequest >
- <CityCode>'.(string)$value_loc->CityCode.'</CityCode>
- </getOwnHotelsRequest >
- </RequestDetails>
- </Request>' ;
- $ch = curl_init($sUrl);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $hoteluri_Xml);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 20);
- $sResponse_hoteluri = curl_exec($ch);
- $hoteluri_Xml = new SimpleXMLElement($sResponse_hoteluri);
- //if(!$err_logare_admin) { echo '<pre>';print_r($hoteluri_Xml->ResponseDetails->getOwnHotelsResponse);echo '</pre>'; echo $sXml ; }
- foreach($hoteluri_Xml->ResponseDetails->getOwnHotelsResponse->Hotel as $value_hotel)
- {
- $hoteluri['hotel']['nume'][trim($value_hotel->HotelCode)] = trim($value_hotel->HotelName);
- //$hoteluri['hotel']['stele'][trim($value_hotel->HotelCode)] = trim($value_hotel->hotel->attributes()->category);
- $hoteluri['hotel']['nume_loc'][trim($value_hotel->HotelCode)] = trim($value_hotel->CityName);
- $hoteluri['hotel']['code_loc'][trim($value_hotel->HotelCode)] = trim($value_hotel->CityCode);
- $hoteluri['hotel']['tara'][trim($value_hotel->HotelCode)] = trim($value_hotel->CountryCode);
- }
- }
- }
- //echo '<pre>';print_r($hoteluri['hotel']);echo '</pre>';
- //$hoteluri['hotel']['nume'] = array_unique($hoteluri['hotel']['nume']);
- if(sizeof($hoteluri)>0) {
- $ins_sql = array();
- //echo '<ol>';
- foreach($hoteluri['hotel']['nume'] as $key => $value) {
- $value = str_replace("andamp;", "&", $value);
- $value = str_replace("amp;", "&", $value);
- $value = str_replace("&&", "&", $value);
-
- $sel_loc = "SELECT * FROM localitati_corespondent WHERE nume_furnizor = '".$hoteluri['hotel']['nume_loc'][$key]."' AND code_furnizor = '".$hoteluri['hotel']['code_loc'][$key]."' AND id_furnizor = '".$id_furnizor."' ";
- $que_loc = mysql_query($sel_loc);
- $row_loc = mysql_fetch_array($que_loc);
- if(mysql_num_rows($que_loc)<1) {
- $ins_city = "INSERT INTO localitati_corespondent (nume_furnizor, code_furnizor, id_furnizor) VALUES ('".$hoteluri['hotel']['nume_loc'][$key]."', '".$hoteluri['hotel']['code_loc'][$key]."', '".$id_furnizor."') ";
- $que_city = mysql_query($ins_city) or die(mysql_error());
- @mysql_free_result($que_city);
-
- $sel_oras = "SELECT id FROM localitati_corespondent WHERE nume_furnizor = '".$hoteluri['hotel']['nume_loc'][$key]."' AND code_furnizor = '".$hoteluri['hotel']['code_loc'][$key]."' AND id_furnizor = '".$id_furnizor."' ";
- $que_oras = mysql_query($sel_oras);
- $row_oras = mysql_fetch_array($que_oras);
- @mysql_free_result($que_oras);
-
- $hotel_city = $row_oras['id'];
- } else {
- $hotel_city = $row_loc['id'];
- }
- @mysql_free_result($que_loc);
-
- $sel_tara = "SELECT id_tara FROM tari WHERE country_code = '".$hoteluri['hotel']['tara'][$key]."' ";
- $que_tara = mysql_query($sel_tara);
- $row_tara = mysql_fetch_array($que_tara);
-
- $sel_hotels = 'SELECT * FROM import_hoteluri WHERE id_hotel = "'.$key.'" AND nume_hotel = "'.$value.'" ';
- $que_hotels = mysql_query($sel_hotels);
- $row_hotels = mysql_fetch_array($que_hotels);
- if(mysql_num_rows($que_hotels)<1) {
- $ins_sql[] = '("'.$key.'", "'.$value.'", "'.$hoteluri['hotel']['stele'][$key].'", "'.$hotel_city.'", "'.$row_tara['id_tara'].'", "'.$id_furnizor.'")';
- }
- //echo '<li>("'.$key.'", "'.$value.'", "'.$hotel_city.'", "'.$row_tara['id_tara'].'", "'.$id_furnizor.'")</li>';
- @mysql_free_result($que_tara);
- @mysql_free_result($que_hotels);
- }
- //echo '</ol>';
- if(sizeof($ins_sql)>0) {
- $ins_hotel = "INSERT INTO import_hoteluri (id_hotel, nume_hotel, stele_hotel, city, country, id_furnizor) VALUES ".implode(',', $ins_sql)." ";
- $que_hotel = mysql_query($ins_hotel) or die(mysql_error());
- @mysql_free_result($que_hotel);
- }
- echo '<script>alert("Hotelurile au fost updatate cu succes."); document.location.href="/adm/import_nova.php";</script>';
- } else {
- echo '<script>alert("EROARE!!! Va rugam incercati din nou mai tarziu!"); document.location.href="/adm/import_nova.php";</script>';
- }
- ?>