public function read_hotels2($startdate = '25/11/2015', $days) { $countries = $this->db->get_Mercan_Countries($this->source_id); foreach ($countries as $country) { //get country City $cities = $this->db->get_Mercan_Cities($this->source_id, $country['id']); $arr_hotel_list = array(); foreach ($cities as $city) { for ($i = 0; $i <= $days; $i++) { for ($k = 1; $k <= 5; $k++) { //add i day to start $d2 = date_create_from_format('d/m/Y', $startdate); $d2->modify('+' . $i . ' day'); $params = array('checkin_date' => $startdate, 'checkout_date' => $d2->format('d/m/Y'), 'sel_country' => $country['code'], 'sel_city' => $city['code'], 'chk_ratings' => '1.0,2.0,3.0,4.0,5.0', 'sel_nationality' => 'IN', 'sel_currency' => 'USD', 'availableonly' => '1', 'roomDetails' => '[{"numberOfAdults":' . $k . '}]', 'gzip' => 'no'); $params['action'] = 'hotel_search'; $hotels = json_decode(get_Requestbody($params)); foreach ($hotels->HotelList as $h) { $ldetail = array('action' => 'hotel_detail', 'hotel_id' => $h->HotelId, 'unique_id' => $hotels->SearchUniqueId); $details = json_decode(get_Requestbody($ldetail)); //add hotel id $arr_hotel_list[$h->HotelId] = array(); $arr_attr = array(); foreach ($details->Amenities->HotelAmenities as $attr) { if ($attr->AmenityName == 'Spa') { array_push($arr_attr, hot_attr_spa); } elseif ($attr->AmenityName == 'LAUNDRY SERVICE') { array_push($arr_attr, hot_attr_launch); } elseif ($attr->AmenityName == 'Swimming pool') { array_push($arr_attr, hot_attr_pool); } } $arr_hotel_list[$h->HotelId]['attributes'] = $arr_attr; // save images in array $imgs = array(); $ig = array(); foreach ($details->HotelImages as $img) { $ig['ThumbnailUrl'] = $img->ThumbnailUrl; $ig['BigUrl'] = $img->BigUrl; array_push($imgs, $ig); } $arr_hotel_list[$h->HotelId]['image'] = $imgs; //add room_type $room_type = array(); foreach ($h->HotelProperty as $hprpty) { foreach ($hprpty->RoomRates as $rmrte) { array_push($room_type, array('RoomCategory' => $rmrte->RoomCategory, 'LocalHotelId' => $h->LocalHotelId, 'RoomType' => $rmrte->RoomType)); } } $arr_hotel_list[$h->HotelId]['RoomType'] = $room_type; } } } } //add hotel Detail $this->db->AddHotelDetails($this->source_id, $arr_hotel_list); } }
echo '<h1> Erro : </h1><br/>'; echo '<h2>Room UNAVIABLE </h2><br/>'; exit; } echo '<h1> Result : </h1><br/>'; sleep(5); //send reservation request $params = array(); $params['section_unique_id'] = $SectionUniqueId; $params['action'] = 'hotel_reservation'; $params['unique_id'] = $SearchUniqueId; $params['hotel_id'] = $HotelId; $params['agent_ref_no'] = 4444; $params['roomDetails'] = '[{"numberOfChilds":1,"roomClassId":"' . $ClassUniqueId . '","passangers":[{"salutation":"Mr","first_name":"' . $_POST['name'] . '","last_name":"' . $_POST['family'] . '"}]}]'; //var_dump($params);exit; $final = json_decode(get_Requestbody($params)); print_r($final); function get_Requestbody($param) { $params = $param; $params['username'] = Public_Api_Username; $params['password'] = Public_Api_Password; $params['gzip'] = 'no'; $url = Public_Api_URl; $str = ''; foreach ($params as $index => $value) { $str .= $index . '=' . $value . '&'; } //remove last '&' $str = trim($str, "&"); $url .= '?' . $str;
$tik = mysql_query($str, connect_db()); $ins = mysql_insert_id(); //request cities of this country & save in DB $p = array('action' => 'getcity', 'country' => $country->Code); $cities = json_decode(get_Requestbody($p)); foreach ($cities->CityInfo as $city) { $sql_city = "INSERT INTO `hot_city_source` (`id`, `source_id`, `name`, `city_source_id`, `country_id`) VALUES (NULL, 5, '" . $city->Name . "', '" . $city->CityCode . "', " . $ins . ")"; $r = mysql_query($sql_city, connect_db()); $ins_city = mysql_insert_id(); //get local hotel list % insert into hotel_temp $p1 = array('action' => 'get_local_hotels', 'sel_country' => $country->Code, 'sel_city' => $city->CityCode); $hotels = json_decode(get_Requestbody($p1)); foreach ($hotels->LocalHotelList as $htl) { //get local hotel detail & save in db $hdtl = array('action' => 'get_local_hotel_details', 'id' => $htl->Id); $details = json_decode(get_Requestbody($hdtl)); //save in hotel_temp $source_id = 5; $tmp['name'] = str_replace('\'', '`', $details->Name); $tmp['source_id'] = '5'; $tmp['src_id'] = $htl->Id; $tmp['latiude'] = $details->Latitude; $tmp['longitude'] = $details->Longitude; $tmp['img'] = $details->MainImage; $tmp['star'] = $details->Rating ? $details->Rating : ''; $tmp['description'] = str_replace('\'', '`', $details->LongDesc); $tmp['site'] = $details->Website; $tmp['currency_id'] = 2; $tmp['city_id'] = $ins_city; $tmp['en_name'] = str_replace('\'', '`', $details->Name); $tmp['en_description'] = str_replace('\'', '`', $details->LongDesc);
function get_avail($startdate = '', $days = 1, $hotel_id) { if (!$startdate) { $startdate = date('d/n/Y'); } //read all hotels from hotel_source //$select="SELECT * FROM `hotels_source` WHERE `source_id` = 5"; $select = "SELECT * FROM `hotels_source` WHERE `source_id` = 5 AND hotels_id={$hotel_id} AND `extra_data` != ''"; //var_dump($select);exit; $result = mysql_query($select, connect_db()); while ($row = mysql_fetch_assoc($result)) { //var_dump($row);exit; //get contry % city codes $city = json_decode($row['extra_data'])->city; $country = json_decode($row['extra_data'])->country; for ($i = 1; $i <= $days; $i++) { for ($k = 1; $k <= 5; $k++) { //add 1 day to start $d1 = date_create_from_format('d/n/Y', $startdate); $d1->modify('+' . ($i - 1) . ' day'); $d2 = date_create_from_format('d/n/Y', $startdate); $d2->modify('+' . $i . ' day'); $params = array('checkin_date' => $d1->format('d/n/Y'), 'checkout_date' => $d2->format('d/n/Y'), 'sel_country' => $country, 'sel_city' => $city, 'chk_ratings' => '1.0,2.0,3.0,4.0,5.0', 'sel_nationality' => 'IN', 'sel_currency' => 'USD', 'availableonly' => '1', 'roomDetails' => '[{"numberOfAdults":' . $k . '}]'); $params['action'] = 'hotel_search'; $params['number_of_rooms'] = 1; //get hotel list $items = json_decode(get_Requestbody($params)); if (property_exists($items, 'HotelList')) { foreach ($items->HotelList as $h) { //var_dump($h->LocalHotelId); //var_dump($row['id_source_hotel']); if ($h->LocalHotelId == $row['id_source_hotel']) { //insert to avail ables foreach ($h->HotelProperty as $hprpty) { $rmrte = $hprpty->RoomRates[0]; //insert room type echo '<pre><br/>'; $slt = "SELECT * FROM `hot_room_type` WHERE `name` ='{$rmrte->RoomCategory}' AND `source_id` = 5 AND `id_source_hotel`='{$h->LocalHotelId}' And `capa_adult`={$k}"; //var_dump($slt); $rr = mysql_query($slt); //var_dump(mysql_num_rows($rr)); if (mysql_num_rows($rr)) { $row2 = mysql_fetch_assoc($rr); $id_room_type = $row2['id']; } else { $strrmtpe = "INSERT INTO `hot_room_type` (`id`, `name`, `en_name`, `source_id`, `id_room_source`, `id_source_hotel`,`capa_adult`) VALUES (NULL, '" . $rmrte->RoomCategory . "', '" . $rmrte->RoomCategory . "', '5', '', '" . $h->LocalHotelId . "',{$k});"; if (mysql_query($strrmtpe, connect_db())) { //add room services $id_room_type = mysql_insert_id(); $s_svc = "INSERT INTO `room_type_services_rel` (`id`, `id_room_type`, `id_room_type_services`, `val`) VALUES (NULL, '" . $id_room_type . "'," . hot_room_service_type . ", '" . $rmrte->RoomType . "')"; if (mysql_query($s_svc, connect_db())) { $last_id = mysql_insert_id(); } } } //get hotels id //$str="select "; //insert avail $inser = "INSERT INTO `hotel_avail` (`id`, `room_type_id`, `hotels_id`, `tarikh`,`avi_date`, `capa`, `price`, `currency_id`, `en`, `source_id`) VALUES (NULL, " . $id_room_type . ", '" . $hotel_id . "', '" . date('Y-n-d H:i:s') . "','" . $d1->format('Y-n-d') . "', 1, '" . $rmrte->RoomRate . "', '2', '3', '5')"; //var_dump($inser);exit; var_dump(mysql_query($inser, connect_db())); } } } } } } } // 1 ha ro be 2 $up = "update `hotel_avail` set en=2 WHERE `source_id` = 5 and en=1 AND hotels_id={$hotel_id}"; var_dump(mysql_query($up)); $up = "update `hotel_avail` set en=1 WHERE `source_id` = 5 and en=3 AND hotels_id={$hotel_id}"; var_dump(mysql_query($up)); $up = "delete from `hotel_avail` WHERE `source_id` = 5 and en=2 AND hotels_id={$hotel_id}"; var_dump(mysql_query($up)); }