/public_html/adm/import_transilvania/all_hotels.php
PHP | 143 lines | 122 code | 17 blank | 4 comment | 8 complexity | 16d8e6e8a783fe00a28e0fcb69e645bc MD5 | raw file
- <?php
- $sel_hoteluri = "SELECT Accommodation_UnitID, Accommodation_Name, Accommodation_Stars, Accommodation_City_Name, Accommodation_City_ID FROM preturi_transilvania GROUP BY Accommodation_UnitID ";
- $que_hoteluri = mysql_query($sel_hoteluri);
- while($row_hoteluri = mysql_fetch_array($que_hoteluri)) {
- $nume_hotel = explode("*", $row_hoteluri['Accommodation_Name']);
- $hotels['denumire'][] = trim(substr($nume_hotel[0],0,-1));
- $hotels['id_hotel'][] = $row_hoteluri['Accommodation_UnitID'];
- $hotels['stele'][] = $row_hoteluri['Accommodation_Stars'];
- $hotels['localitate'][] = $row_hoteluri['Accommodation_City_Name'];
- $hotels['localitate_id'][] = $row_hoteluri['Accommodation_City_ID'];
- }
- //echo '<ol>';
- foreach($hotels['denumire'] as $key => $value) {
- $sel_loc = "SELECT * FROM localitati_corespondent WHERE nume_furnizor = '".$hotels['localitate'][$key]."' AND code_furnizor = '".$hotels['localitate_id'][$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 ('".$hotels['localitate'][$key]."', '".$hotels['localitate_id'][$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 = '".$hotels['localitate'][$key]."' AND code_furnizor = '".$hotels['localitate_id'][$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_hotels = "SELECT * FROM import_hoteluri WHERE nume_hotel = '".$value."' AND stele_hotel = '".$hotels['stele'][$key]."' AND city = '".$hotel_city."' ";
- $que_hotels = mysql_query($sel_hotels);
- $row_hotels = mysql_fetch_array($que_hotels);
- if(mysql_num_rows($que_hotels)<1) {
- $ins_sql[] = '("'.$hotels['id_hotel'][$key].'", "'.$value.'", "'.$hotels['stele'][$key].'", "'.$hotel_city.'", "'.$id_furnizor.'")';
- }
- //echo '<li>("'.$value.'", "'.$hotels['stele'][$key].'", "'.$hotel_city.'", "'.$id_furnizor.'")</li>';
- @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, id_furnizor) VALUES ".implode(',', $ins_sql)." ";
- $que_hotel = mysql_query($ins_hotel) or die(mysql_error());
- @mysql_free_result($que_hotel);
- }
- foreach($aida_countries[$id_furnizor] as $k_tara => $v_tara) {
- $sHeader = '<soapenv:Header>
- <ns:AuthHeader>
- <ns:Username>ocaziituristice</ns:Username>
- <ns:Password>rev14</ns:Password>
- <ns:ResellerCode>DVIN</ns:ResellerCode>
- </ns:AuthHeader>
- </soapenv:Header>';
-
- $sXml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://aida.dcsplus.net/ws/2010">
- '.$sHeader.'
- <soapenv:Body>
- <ns:AIDA_GlobeCitiesRQ>
- <ns:Filters>
- <ns:Country ID="'.$k_tara.'" />
- </ns:Filters>
- </ns:AIDA_GlobeCitiesRQ>
- </soapenv:Body>
- </soapenv:Envelope>';
-
- $ch = curl_init($sUrl);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $sXml);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $sResponse = curl_exec($ch);
-
- $localitati = new SimpleXMLElement($sResponse);
- $cities = $localitati->children("SOAP-ENV",true)->Body->children("ns1",true)->AIDA_GlobeCitiesRS->children("ns1",true)->Cities;
- foreach($cities->children("ns1",true)->City as $k_city => $v_city) {
- $sel_loc = "SELECT * FROM localitati_corespondent WHERE nume_furnizor = '".(string) $v_city->attributes()->Name."' AND code_furnizor = '".(string) $v_city->attributes()->ID."' 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 ('".(string) $v_city->attributes()->Name."', '".(string) $v_city->attributes()->ID."', '".$id_furnizor."') ";
- $que_city = mysql_query($ins_city) or die(mysql_error());
- @mysql_free_result($que_city);
-
- $sel_oras = "SELECT code_furnizor FROM localitati_corespondent WHERE nume_furnizor = '".(string) $v_city->attributes()->Name."' AND code_furnizor = '".(string) $v_city->attributes()->ID."' 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['code_furnizor'];
- } else {
- $hotel_city = $row_loc['code_furnizor'];
- }
- @mysql_free_result($que_loc);
-
- $sXml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://aida.dcsplus.net/ws/2010">
- '.$sHeader.'
- <soapenv:Body>
- <ns:AIDA_AccUnitsRQ>
- <ns:Filters>
- <ns:City ID="'.$hotel_city.'" />
- </ns:Filters>
- </ns:AIDA_AccUnitsRQ>
- </soapenv:Body>
- </soapenv:Envelope>';
-
- $ch = curl_init($sUrl);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $sXml);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $sResponse = curl_exec($ch);
-
- $hoteluri = new SimpleXMLElement($sResponse);
- $hoteluri_xml = $hoteluri->children("SOAP-ENV",true)->Body->children("ns1",true)->AIDA_AccUnitsRS->children("ns1",true)->AccUnits;
- foreach($hoteluri_xml->children("ns1",true)->AccUnit as $k_hotel => $v_hotel) {
- $sel_hotels = "SELECT * FROM import_hoteluri WHERE id_hotel = '".$v_hotel->attributes()->ID."' AND stele_hotel = '".$v_hotel->attributes()->Stars."' AND city = '".$row_loc['id']."' ";
- $que_hotels = mysql_query($sel_hotels);
- $row_hotels = mysql_fetch_array($que_hotels);
- if(mysql_num_rows($que_hotels)<1) {
- $ins_sql2[] = '("'.$v_hotel->attributes()->ID.'", "'.$v_hotel->attributes()->Name.'", "'.$v_hotel->attributes()->Stars.'", "'.$row_loc['id'].'", "'.$id_furnizor.'")';
- }
- //echo '<li>("'.$v_hotel->attributes()->ID.'", "'.$v_hotel->attributes()->Name.'", "'.$v_hotel->attributes()->Stars.'", "'.$row_loc['id'].'", "'.$id_furnizor.'")</li>';
- @mysql_free_result($que_hotels);
- }
- }
- }
- if(sizeof($ins_sql2)>0) {
- $ins_hotel = "INSERT INTO import_hoteluri (id_hotel, nume_hotel, stele_hotel, city, id_furnizor) VALUES ".implode(',', $ins_sql2)." ";
- $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_transilvania.php";</script>';
- ?>