PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/public_html/adm/import_nova/all_hotels.php

https://bitbucket.org/ocaziituristice/ocaziituristice.ro
PHP | 189 lines | 134 code | 40 blank | 15 comment | 7 complexity | 5fe807bc8f7774b8602beb4966a220f6 MD5 | raw file
  1. <?php
  2. $xml = simplexml_load_file($sUrl);
  3. //error_reporting(E_ALL);
  4. //ini_set('display_errors', 1);
  5. $cod_tara="RO";
  6. $hoteluri = array();
  7. $tari_Xml = '<?xml version="1.0" encoding="UTF-8"?>
  8. <Request RequestType="getCountryRequest">
  9. <AuditInfo>
  10. <RequestId>'.date("dmYHis").'</RequestId>
  11. <RequestUser>'.$RequestUser.'</RequestUser>
  12. <RequestPass>'.$RequestPass.'</RequestPass>
  13. <RequestTime>'.date("Y-m-d").'T'.date("H-i-s").'</RequestTime>
  14. <RequestLang>RO</RequestLang>
  15. </AuditInfo>
  16. <RequestDetails>
  17. <getCountryRequest/>
  18. </RequestDetails>
  19. </Request>';
  20. //if(!$err_logare_admin) echo "pppp". $servicii_supliemtare_Xml ;
  21. $ch = curl_init($sUrl);
  22. curl_setopt($ch, CURLOPT_POST, 1);
  23. curl_setopt($ch, CURLOPT_POSTFIELDS, $tari_Xml);
  24. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  25. curl_setopt($ch, CURLOPT_HEADER, 0);
  26. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  27. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  28. $sResponse_tari = curl_exec($ch);
  29. $tari_Xml = new SimpleXMLElement($sResponse_tari);
  30. //if(!$err_logare_admin) { echo '<pre>';print_r($tari_Xml);echo '</pre>'; echo $sXml ; }
  31. foreach($tari_Xml->ResponseDetails->getCountryResponse->Country as $value_tari)
  32. {
  33. //$country_code[]=trim($value_tari->CountryCode);
  34. if(!$err_logare_admin) { echo '<pre>';print_r($country_code);echo '</pre>'; echo $sXml ; }
  35. $localitati_Xml = '<?xml version="1.0" encoding="UTF-8"?>
  36. <Request RequestType="getCityRequest">
  37. <AuditInfo>
  38. <RequestId>'.date("dmYHis").'</RequestId>
  39. <RequestUser>'.$RequestUser.'</RequestUser>
  40. <RequestPass>'.$RequestPass.'</RequestPass>
  41. <RequestTime>'.date("Y-m-d").'T'.date("H-i-s").'</RequestTime>
  42. <RequestLang>RO</RequestLang>
  43. </AuditInfo>
  44. <RequestDetails>
  45. <getCityRequest CountryCode="'.trim($value_tari->CountryCode).'" />
  46. </RequestDetails>
  47. </Request>';
  48. //if(!$err_logare_admin) echo "pppp". $servicii_supliemtare_Xml ;
  49. $ch = curl_init($sUrl);
  50. curl_setopt($ch, CURLOPT_POST, 1);
  51. curl_setopt($ch, CURLOPT_POSTFIELDS, $localitati_Xml);
  52. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  53. curl_setopt($ch, CURLOPT_HEADER, 0);
  54. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  55. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  56. $sResponse_localitati = curl_exec($ch);
  57. $localitati_Xml = new SimpleXMLElement($sResponse_localitati);
  58. //if(!$err_logare_admin) { echo '<pre>';print_r($localitati_Xml);echo '</pre>'; echo $sXml ; }
  59. foreach($localitati_Xml->ResponseDetails->getCityResponse->City as $value_loc)
  60. {
  61. //echo '<pre>';print_r($value_loc);echo '</pre>';
  62. echo "<br />".(string)$value_loc->CityCode;
  63. $hoteluri_Xml = '<?xml version="1.0" encoding="UTF-8"?>
  64. <Request RequestType="getOwnHotelsRequest">
  65. <AuditInfo>
  66. <RequestId>'.date("dmYHis").'</RequestId>
  67. <RequestUser>'.$RequestUser.'</RequestUser>
  68. <RequestPass>'.$RequestPass.'</RequestPass>
  69. <RequestTime>'.date("Y-m-d").'T'.date("H-i-s").'</RequestTime>
  70. <RequestLang>RO</RequestLang>
  71. </AuditInfo>
  72. <RequestDetails>
  73. <getOwnHotelsRequest >
  74. <CityCode>'.(string)$value_loc->CityCode.'</CityCode>
  75. </getOwnHotelsRequest >
  76. </RequestDetails>
  77. </Request>' ;
  78. $ch = curl_init($sUrl);
  79. curl_setopt($ch, CURLOPT_POST, 1);
  80. curl_setopt($ch, CURLOPT_POSTFIELDS, $hoteluri_Xml);
  81. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  82. curl_setopt($ch, CURLOPT_HEADER, 0);
  83. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  84. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  85. $sResponse_hoteluri = curl_exec($ch);
  86. $hoteluri_Xml = new SimpleXMLElement($sResponse_hoteluri);
  87. //if(!$err_logare_admin) { echo '<pre>';print_r($hoteluri_Xml->ResponseDetails->getOwnHotelsResponse);echo '</pre>'; echo $sXml ; }
  88. foreach($hoteluri_Xml->ResponseDetails->getOwnHotelsResponse->Hotel as $value_hotel)
  89. {
  90. $hoteluri['hotel']['nume'][trim($value_hotel->HotelCode)] = trim($value_hotel->HotelName);
  91. //$hoteluri['hotel']['stele'][trim($value_hotel->HotelCode)] = trim($value_hotel->hotel->attributes()->category);
  92. $hoteluri['hotel']['nume_loc'][trim($value_hotel->HotelCode)] = trim($value_hotel->CityName);
  93. $hoteluri['hotel']['code_loc'][trim($value_hotel->HotelCode)] = trim($value_hotel->CityCode);
  94. $hoteluri['hotel']['tara'][trim($value_hotel->HotelCode)] = trim($value_hotel->CountryCode);
  95. }
  96. }
  97. }
  98. //echo '<pre>';print_r($hoteluri['hotel']);echo '</pre>';
  99. //$hoteluri['hotel']['nume'] = array_unique($hoteluri['hotel']['nume']);
  100. if(sizeof($hoteluri)>0) {
  101. $ins_sql = array();
  102. //echo '<ol>';
  103. foreach($hoteluri['hotel']['nume'] as $key => $value) {
  104. $value = str_replace("andamp;", "&amp;", $value);
  105. $value = str_replace("amp;", "&amp;", $value);
  106. $value = str_replace("&&", "&", $value);
  107. $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."' ";
  108. $que_loc = mysql_query($sel_loc);
  109. $row_loc = mysql_fetch_array($que_loc);
  110. if(mysql_num_rows($que_loc)<1) {
  111. $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."') ";
  112. $que_city = mysql_query($ins_city) or die(mysql_error());
  113. @mysql_free_result($que_city);
  114. $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."' ";
  115. $que_oras = mysql_query($sel_oras);
  116. $row_oras = mysql_fetch_array($que_oras);
  117. @mysql_free_result($que_oras);
  118. $hotel_city = $row_oras['id'];
  119. } else {
  120. $hotel_city = $row_loc['id'];
  121. }
  122. @mysql_free_result($que_loc);
  123. $sel_tara = "SELECT id_tara FROM tari WHERE country_code = '".$hoteluri['hotel']['tara'][$key]."' ";
  124. $que_tara = mysql_query($sel_tara);
  125. $row_tara = mysql_fetch_array($que_tara);
  126. $sel_hotels = 'SELECT * FROM import_hoteluri WHERE id_hotel = "'.$key.'" AND nume_hotel = "'.$value.'" ';
  127. $que_hotels = mysql_query($sel_hotels);
  128. $row_hotels = mysql_fetch_array($que_hotels);
  129. if(mysql_num_rows($que_hotels)<1) {
  130. $ins_sql[] = '("'.$key.'", "'.$value.'", "'.$hoteluri['hotel']['stele'][$key].'", "'.$hotel_city.'", "'.$row_tara['id_tara'].'", "'.$id_furnizor.'")';
  131. }
  132. //echo '<li>("'.$key.'", "'.$value.'", "'.$hotel_city.'", "'.$row_tara['id_tara'].'", "'.$id_furnizor.'")</li>';
  133. @mysql_free_result($que_tara);
  134. @mysql_free_result($que_hotels);
  135. }
  136. //echo '</ol>';
  137. if(sizeof($ins_sql)>0) {
  138. $ins_hotel = "INSERT INTO import_hoteluri (id_hotel, nume_hotel, stele_hotel, city, country, id_furnizor) VALUES ".implode(',', $ins_sql)." ";
  139. $que_hotel = mysql_query($ins_hotel) or die(mysql_error());
  140. @mysql_free_result($que_hotel);
  141. }
  142. echo '<script>alert("Hotelurile au fost updatate cu succes."); document.location.href="/adm/import_nova.php";</script>';
  143. } else {
  144. echo '<script>alert("EROARE!!! Va rugam incercati din nou mai tarziu!"); document.location.href="/adm/import_nova.php";</script>';
  145. }
  146. ?>