1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
class Hotel_model extends CI_Model {
public function _consruct(){
parent::_construct();
}
public function auth_token_get($token) {
$rs = $this->db->select('user_id')->where('auth_token', $token)->get('customer_auth')->row();
if(count($rs) > 0) {
return $rs->user_id;
} else {
return 0;
}
}
public function get_hotel_city_list($data){
try{
$user_id = $this->auth_token_get($data['auth_token']);
if($user_id > 0) {
$cond = '';
if(isset($data['query']) && !empty($data['query'])){
$cond = "AND THC.hotel_city_name LIKE '%".$data['query']."%'";
}
$sql = "SELECT HC.hotel_city_id FROM hotel_cities AS HC
INNER JOIN translator_hotel_city AS THC ON(THC.hotel_city_id=HC.hotel_city_id)
WHERE HC.status=1 $cond GROUP BY HC.hotel_city_id";
$count = $this->db->query($sql)->num_rows();
if($count >= 1){
$perPage = 10;
$page = (isset($data['page']))?$data['page']:1;
$limit = ($page - 1) * $perPage;
$meta = array('total_pages'=>ceil($count/$perPage),'total'=>$count,
'current_page'=>$page,'per_page'=>$perPage);
$sql = "SELECT THC.hotel_city_id AS id,HC.hotel_city_icon AS image
FROM translator_hotel_city AS THC
INNER JOIN hotel_cities AS HC ON (HC.hotel_city_id=THC.hotel_city_id)
WHERE THC.status=1 $cond GROUP BY HC.hotel_city_id LIMIT $limit,$perPage";
$hotelData = $this->db->query($sql)->result_array();
$countryData = $this->getCountryData($user_id);
$lang = $countryData['language_code'];
foreach ($hotelData as $key => $value) {
if(!empty($lanTrans = langTranslator($value['id'],'HCTY',$lang))){
$hotelData[$key]['name'] = $lanTrans['hotel_city_name'];
}
}
if(count($hotelData) < 0){
$res = array('status'=>0,'message'=>'No Data Found','code'=>'ER10');
}
$res = array('status'=>1,'data'=>array('city_list'=>$hotelData,'meta'=>$meta));
}else{
$res = array('status'=>0,'message'=>'No Data Found','code'=>'ER10');
}
}else{
$res = array('status'=>0,'message'=>'User Authentication Failed','code'=>'ER15');
}
} catch(Exception $e){
$res = array('status'=>0,'message'=>'Ohh No!! Something Went South!!','code'=>'ER08');
}
return $res;
}
public function hotel_search($data){
try{
$user_id = $this->auth_token_get($data['auth_token']);
if($user_id > 0) {
$trackingId = time().rand(100000,999999);
$settings = getSettings();
if(!isset($data['nextToken']) && empty($data['nextToken'])){
$this->db->select('nationality');
$userData = $this->db->get_where('customer',array('customer_id'=>$user_id))->row_array();
$countryData = $this->getCountryData($user_id);
}
$url = (isset($data['nextToken']) && !empty($data['nextToken']))?"https://trawex.biz/api/hotel_trawexv5/getMoreHotels?user_id=".$settings['trawex_user_id']."&user_password=".$settings['trawex_user_password']."&access=".$settings['trawex_access']."&ip_address=".$settings['trawex_ip_address']."&sessionId=".$data['sessionId']."&nextToken=".$data['nextToken']."&trackingId=".$data['trackingId']."":"https://trawex.biz/api/hotel_trawexv5/hotel_search";
if(!isset($data['nextToken']) && empty($data['nextToken'])){
$postData = array('user_id'=>$settings['trawex_user_id'],
'user_password'=>$settings['trawex_user_password'],
'access'=>$settings['trawex_access'],
'ip_address'=>$settings['trawex_ip_address'],
'trackingId'=>$trackingId,'city_name'=>$data['city_name'],
'country_name'=>$data['country_name'],
'room_count'=>$data['room_count'],'adult'=>$data['adult'],
'child'=>$data['child'],'child_age'=>$data['child_age'],
'checkin'=>$data['checkin'],'checkout'=>$data['checkout'],
'client_nationality'=>$userData['nationality'],
'requiredCurrency'=>$countryData['currency']);
}
$postFields = (isset($data['nextToken']) && !empty($data['nextToken']))?'':$postData;
$result = $this->passToJsonCurl($url,$postFields);
if(!empty($result)){
$result = json_decode($result);
$result->status->trackingId = (!isset($data['nextToken']) && empty($data['nextToken']))?$trackingId:$data['trackingId'];
$res = array('status'=>1,'data'=>array('itineraries'=> $result));
}else{
$res = array('status'=>0,'message'=>'No Data Found','code'=>'ER07');
}
}else{
$res = array('status'=>0,'message'=>'User Authentication Error','code'=>'ER10');
}
}catch(Exception $e){
$res = array('status'=>0,'message'=>'Ohh No!! Something Went South!!','code'=>'ER08');
}
return $res;
}
public function get_specific_hotel_content($data){
try{
$user_id = $this->auth_token_get($data['auth_token']);
if($user_id > 0) {
$settings = getSettings();
$url = "https://trawex.biz/api/hotel_trawexv5/get_specific_hotel_content?user_id=".$settings['trawex_user_id']."&user_password=".$settings['trawex_user_password']."&access=".$settings['trawex_access']."&ip_address=".$settings['trawex_ip_address']."&sessionId=".$data['sessionId']."&trackingId=".$data['trackingId']."&productId=".$data['productId']."&hotelId=".$data['hotelId']."";
$result = $this->passToJsonCurl($url,'');
if(!empty($result)){
$result = json_decode($result);
$result->trackingId = $data['trackingId'];
$res = array('status'=>1,'data'=>$result);
}else{
$res = array('status'=>0,'message'=>'No Data Found','code'=>'ER06');
}
}else{
$res = array('status'=>0,'message'=>'User Authentication Error','code'=>'ER10');
}
}catch(Exception $e){
$res = array('status'=>0,'message'=>'Ohh No!! Something Went South!!','code'=>'ER08');
}
return $res;
}
public function get_room_rates($data){
try{
$user_id = $this->auth_token_get($data['auth_token']);
if($user_id > 0){
$settings = getSettings();
$url = "https://trawex.biz/api/hotel_trawexv5/get_room_rates";
$postData = array("user_id"=>$settings['trawex_user_id'],"user_password"=>$settings['trawex_user_password'],"access"=>$settings['trawex_access'],"ip_address"=>$settings['trawex_ip_address'],"TraceId"=>$data['TraceId'],"propertyid"=>$data['propertyid'],"trackingId"=>$data['trackingId'],"sessionId"=>$data['sessionId'],"productId"=>$data['productId'],"TokenId"=>$data['TokenId'],"resultindex"=>$data['resultindex'],"hotelcode"=>$data['hotelcode']);
$result = $this->passToJsonCurl($url,$postData);
if(!empty($result)){
$result = json_decode($result);
$result->trackingId = $data['trackingId'];
$res = array('status'=>1,'data'=>$result);
}else{
$res = array('status'=>0,'message'=>'No data Found','code'=>'ER06');
}
}else{
$res = array('status'=>0,'message'=>'User Authentication Error','code'=>'ER10');
}
}catch (Exception $e){
$res = array('status'=>0,'message'=>'Ohh No!! Something Went South!!','code'=>'ER08');
}
return $res;
}
public function get_rate_rules($data){
try{
$user_id = $this->auth_token_get($data['auth_token']);
if($user_id > 0){
$settings = getSettings();
$url = "https://trawex.biz/api/hotel_trawexv5/get_rate_rules";
$postData = array(
"user_id"=>$settings['trawex_user_id'],
"user_password"=>$settings['trawex_user_password'],
"access"=>$settings['trawex_access'],
"ip_address"=>$settings['trawex_ip_address'],
"TraceId"=>$data['TraceId'],"propertyid"=>$data['propertyid'],
"trackingId"=>$data['trackingId'],"sessionId"=>$data['sessionId'],
"productId"=>$data['productId'],"TokenId"=>$data['TokenId'],
"resultindex"=>$data['resultindex'],"hotelcode"=>$data['hotelcode'],
"allocationDetails"=>$data['allocationDetails'],
"booking_token"=>$data['booking_token'],
"hotel_name"=>$data['hotel_name'],"infosource"=>$data['infosource'],
"meal_code"=>$data['meal_code'],
"rate_basis_id"=>$data['rate_basis_id'],
"room_code"=>$data['room_code'],"boardCode"=>$data['boardCode'],
"roomType_runno"=>$data['roomType_runno']);
$result = $this->passToJsonCurl($url,$postData);
if(!empty($result)){
$result = json_decode($result);
$result->trackingId = $data['trackingId'];
$res = array('status'=>1,'data'=>$result);
}else{
$res = array('status'=>0,'message'=>'No data Found','code'=>'ER06');
}
}else{
$res = array('status'=>0,'message'=>'User Authentication Error','code'=>'ER10');
}
} catch(Exception $e){
$res = array('status'=>0,'message'=>'Ohh No!! Something Went South!!','code'=>'ER08');
}
return $res;
}
public function hotel_book($data){
try{
$user_id = $this->auth_token_get($data['auth_token']);
if($user_id > 0){
$settings = getSettings();
$url = "https://trawex.biz/api/hotel_trawexv5/hotel_book";
$postData = array(
"user_id"=>$settings['trawex_user_id'],
"user_password"=>$settings['trawex_user_password'],
"access"=>$settings['trawex_access'],
"ip_address"=>$settings['trawex_ip_address'],
"TraceId"=>$data['TraceId'],"propertyid"=>$data['propertyid'],
"trackingId"=>$data['trackingId'],"sessionId"=>$data['sessionId'],
"productId"=>$data['productId'],"TokenId"=>$data['TokenId'],
"resultindex"=>$data['resultindex'],"hotelcode"=>$data['hotelcode'],
"changedOccupancy"=>$data['changedOccupancy'],
"extrabeds"=>$data['extrabeds'],
"guests_details"=>$data['guests_details'],"refcode"=>$data['refcode'],
"prebookingtoken"=>$data['prebookingtoken']
);
$result = $this->passToJsonCurl($url,$postData);
if(!empty($result)){
$result = json_decode($result);
$result->trackingId = $data['trackingId'];
$res = array('status'=>1,'data'=>$result);
}else{
$res = array('status'=>0,'message'=>'No data Found','code'=>'ER06');
}
}else{
$res = array('status'=>0,'message'=>'User Authentication Error','code'=>'ER10');
}
} catch(Exception $e){
$res = array('status'=>0,'message'=>'Ohh No!! Something Went South!!','code'=>'ER08');
}
return $res;
}
public function trawex_cancel_booking($data){
try{
$user_id = $this->auth_token_get($data['auth_token']);
if($user_id > 0){
$settings = getSettings();
$url = "https://trawex.biz/api/hotel_trawexv5/cancel_booking";
$postData = array(
"user_id"=>$settings['trawex_user_id'],
"user_password"=>$settings['trawex_user_password'],
"access"=>$settings['trawex_access'],
"ip_address"=>$settings['trawex_ip_address'],
'trackingId'=>$data['trackingId'],'productId'=>$data['productId'],
'supplierConfirmationNum'=>$data['supplierConfirmationNum'],
'reference'=>$data['reference']
);
$result = $this->passToJsonCurl($url,$postData);
if(!empty($result)){
$result = json_decode($result);
$result->trackingId = $data['trackingId'];
$res = array('status'=>1,'data'=>$result);
}else{
$res = array('status'=>0,'message'=>'No data Found','code'=>'ER06');
}
}else{
$res = array('status'=>0,'message'=>'User Authentication Error','code'=>'ER10');
}
} catch(Exception $e){
$re = array('status'=>0,'message'=>'Ohh No!! Something Went South!!','code'=>'ER08');
}
return $res;
}
public function getCountryData($user_id){
$ctryData = '';
if(!empty($user_id)){
$sql = "SELECT CTRY.* FROM customer AS CUST
INNER JOIN country AS CTRY ON (CTRY.country_id=CUST.country_id)
WHERE CUST.customer_id='$user_id'";
$ctryData = $this->db->query($sql)->row_array();
}
if(empty($ctryData)){
$ctryData = $this->db->query("SELECT * FROM country WHERE language_code='EN'")->row_array();
}
return $ctryData;
}
public function passToJsonCurl($url='',$postData=array()){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($postData));
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type:application/json'));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
?>