PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/adm/import_transilvania/all_hotels.php

https://bitbucket.org/ocaziituristice/ocaziituristice.ro
PHP | 143 lines | 122 code | 17 blank | 4 comment | 8 complexity | 16d8e6e8a783fe00a28e0fcb69e645bc MD5 | raw file
  1. <?php
  2. $sel_hoteluri = "SELECT Accommodation_UnitID, Accommodation_Name, Accommodation_Stars, Accommodation_City_Name, Accommodation_City_ID FROM preturi_transilvania GROUP BY Accommodation_UnitID ";
  3. $que_hoteluri = mysql_query($sel_hoteluri);
  4. while($row_hoteluri = mysql_fetch_array($que_hoteluri)) {
  5. $nume_hotel = explode("*", $row_hoteluri['Accommodation_Name']);
  6. $hotels['denumire'][] = trim(substr($nume_hotel[0],0,-1));
  7. $hotels['id_hotel'][] = $row_hoteluri['Accommodation_UnitID'];
  8. $hotels['stele'][] = $row_hoteluri['Accommodation_Stars'];
  9. $hotels['localitate'][] = $row_hoteluri['Accommodation_City_Name'];
  10. $hotels['localitate_id'][] = $row_hoteluri['Accommodation_City_ID'];
  11. }
  12. //echo '<ol>';
  13. foreach($hotels['denumire'] as $key => $value) {
  14. $sel_loc = "SELECT * FROM localitati_corespondent WHERE nume_furnizor = '".$hotels['localitate'][$key]."' AND code_furnizor = '".$hotels['localitate_id'][$key]."' AND id_furnizor = '".$id_furnizor."' ";
  15. $que_loc = mysql_query($sel_loc);
  16. $row_loc = mysql_fetch_array($que_loc);
  17. if(mysql_num_rows($que_loc)<1) {
  18. $ins_city = "INSERT INTO localitati_corespondent (nume_furnizor, code_furnizor, id_furnizor) VALUES ('".$hotels['localitate'][$key]."', '".$hotels['localitate_id'][$key]."', '".$id_furnizor."') ";
  19. $que_city = mysql_query($ins_city) or die(mysql_error());
  20. @mysql_free_result($que_city);
  21. $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."' ";
  22. $que_oras = mysql_query($sel_oras);
  23. $row_oras = mysql_fetch_array($que_oras);
  24. @mysql_free_result($que_oras);
  25. $hotel_city = $row_oras['id'];
  26. } else {
  27. $hotel_city = $row_loc['id'];
  28. }
  29. @mysql_free_result($que_loc);
  30. $sel_hotels = "SELECT * FROM import_hoteluri WHERE nume_hotel = '".$value."' AND stele_hotel = '".$hotels['stele'][$key]."' AND city = '".$hotel_city."' ";
  31. $que_hotels = mysql_query($sel_hotels);
  32. $row_hotels = mysql_fetch_array($que_hotels);
  33. if(mysql_num_rows($que_hotels)<1) {
  34. $ins_sql[] = '("'.$hotels['id_hotel'][$key].'", "'.$value.'", "'.$hotels['stele'][$key].'", "'.$hotel_city.'", "'.$id_furnizor.'")';
  35. }
  36. //echo '<li>("'.$value.'", "'.$hotels['stele'][$key].'", "'.$hotel_city.'", "'.$id_furnizor.'")</li>';
  37. @mysql_free_result($que_hotels);
  38. }
  39. //echo '</ol>';
  40. if(sizeof($ins_sql)>0) {
  41. $ins_hotel = "INSERT INTO import_hoteluri (id_hotel, nume_hotel, stele_hotel, city, id_furnizor) VALUES ".implode(',', $ins_sql)." ";
  42. $que_hotel = mysql_query($ins_hotel) or die(mysql_error());
  43. @mysql_free_result($que_hotel);
  44. }
  45. foreach($aida_countries[$id_furnizor] as $k_tara => $v_tara) {
  46. $sHeader = '<soapenv:Header>
  47. <ns:AuthHeader>
  48. <ns:Username>ocaziituristice</ns:Username>
  49. <ns:Password>rev14</ns:Password>
  50. <ns:ResellerCode>DVIN</ns:ResellerCode>
  51. </ns:AuthHeader>
  52. </soapenv:Header>';
  53. $sXml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://aida.dcsplus.net/ws/2010">
  54. '.$sHeader.'
  55. <soapenv:Body>
  56. <ns:AIDA_GlobeCitiesRQ>
  57. <ns:Filters>
  58. <ns:Country ID="'.$k_tara.'" />
  59. </ns:Filters>
  60. </ns:AIDA_GlobeCitiesRQ>
  61. </soapenv:Body>
  62. </soapenv:Envelope>';
  63. $ch = curl_init($sUrl);
  64. curl_setopt($ch, CURLOPT_POST, 1);
  65. curl_setopt($ch, CURLOPT_POSTFIELDS, $sXml);
  66. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  67. curl_setopt($ch, CURLOPT_HEADER, 0);
  68. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  69. $sResponse = curl_exec($ch);
  70. $localitati = new SimpleXMLElement($sResponse);
  71. $cities = $localitati->children("SOAP-ENV",true)->Body->children("ns1",true)->AIDA_GlobeCitiesRS->children("ns1",true)->Cities;
  72. foreach($cities->children("ns1",true)->City as $k_city => $v_city) {
  73. $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."' ";
  74. $que_loc = mysql_query($sel_loc);
  75. $row_loc = mysql_fetch_array($que_loc);
  76. if(mysql_num_rows($que_loc)<1) {
  77. $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."') ";
  78. $que_city = mysql_query($ins_city) or die(mysql_error());
  79. @mysql_free_result($que_city);
  80. $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."' ";
  81. $que_oras = mysql_query($sel_oras);
  82. $row_oras = mysql_fetch_array($que_oras);
  83. @mysql_free_result($que_oras);
  84. $hotel_city = $row_oras['code_furnizor'];
  85. } else {
  86. $hotel_city = $row_loc['code_furnizor'];
  87. }
  88. @mysql_free_result($que_loc);
  89. $sXml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://aida.dcsplus.net/ws/2010">
  90. '.$sHeader.'
  91. <soapenv:Body>
  92. <ns:AIDA_AccUnitsRQ>
  93. <ns:Filters>
  94. <ns:City ID="'.$hotel_city.'" />
  95. </ns:Filters>
  96. </ns:AIDA_AccUnitsRQ>
  97. </soapenv:Body>
  98. </soapenv:Envelope>';
  99. $ch = curl_init($sUrl);
  100. curl_setopt($ch, CURLOPT_POST, 1);
  101. curl_setopt($ch, CURLOPT_POSTFIELDS, $sXml);
  102. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  103. curl_setopt($ch, CURLOPT_HEADER, 0);
  104. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  105. $sResponse = curl_exec($ch);
  106. $hoteluri = new SimpleXMLElement($sResponse);
  107. $hoteluri_xml = $hoteluri->children("SOAP-ENV",true)->Body->children("ns1",true)->AIDA_AccUnitsRS->children("ns1",true)->AccUnits;
  108. foreach($hoteluri_xml->children("ns1",true)->AccUnit as $k_hotel => $v_hotel) {
  109. $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']."' ";
  110. $que_hotels = mysql_query($sel_hotels);
  111. $row_hotels = mysql_fetch_array($que_hotels);
  112. if(mysql_num_rows($que_hotels)<1) {
  113. $ins_sql2[] = '("'.$v_hotel->attributes()->ID.'", "'.$v_hotel->attributes()->Name.'", "'.$v_hotel->attributes()->Stars.'", "'.$row_loc['id'].'", "'.$id_furnizor.'")';
  114. }
  115. //echo '<li>("'.$v_hotel->attributes()->ID.'", "'.$v_hotel->attributes()->Name.'", "'.$v_hotel->attributes()->Stars.'", "'.$row_loc['id'].'", "'.$id_furnizor.'")</li>';
  116. @mysql_free_result($que_hotels);
  117. }
  118. }
  119. }
  120. if(sizeof($ins_sql2)>0) {
  121. $ins_hotel = "INSERT INTO import_hoteluri (id_hotel, nume_hotel, stele_hotel, city, id_furnizor) VALUES ".implode(',', $ins_sql2)." ";
  122. $que_hotel = mysql_query($ins_hotel) or die(mysql_error());
  123. @mysql_free_result($que_hotel);
  124. }
  125. echo '<script>alert("Hotelurile au fost updatate cu succes."); document.location.href="/adm/import_transilvania.php";</script>';
  126. ?>