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
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
//test changes
class HotelServices extends CI_Controller {
var $auth_token;
public function __construct() {
parent::__construct();
date_default_timezone_set("Asia/Riyadh");
$this->load->model('HotelServices_model');
$this->load->model('Validation_hotel_model');
$method = $this->router->fetch_method();
$data = (array) json_decode(file_get_contents('php://input'));
if (isset(apache_request_headers()['Auth']) || isset(apache_request_headers()['auth'])) {
$this->auth_token = (isset(apache_request_headers()['Auth']))?apache_request_headers()['Auth']:apache_request_headers()['auth'];
$data['auth_token'] = $this->auth_token;
}
$res = $this->Validation_hotel_model->validation_check($method, $data);
if($res['state'] == 1) {
$this->errorResponse($res['response']['code'], $res['response']['message']);
die;
}
}
public function response($data) {
$result = array(
'status' => 'success',
'data' =>$data
);
print json_encode($result);
}
public function successResponse($data='') {
$result = array(
'status' => 'success',
);
print json_encode($result);
}
public function errorResponse($errorCode, $errorDesc) {
$result = array(
'status' => 'error',
'error'=> $errorCode,
'message'=> $errorDesc
);
print json_encode($result);
}
public function get_hotel_city_list(){
$data = $_GET;
$res = $this->HotelServices_model->get_hotel_city_list($data);
if($res['status'] == 1){
$this->response($res['data']);
}else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function hotel_search(){
$data = (array)json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->HotelServices_model->hotel_search($data);
if($res['status'] == 1){
$this->response($res['data']);
}else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function get_specific_hotel_content(){
$data = (array)json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->HotelServices_model->get_specific_hotel_content($data);
if($res['status'] == 1){
$this->response($res['data']);
}else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function get_room_rates(){
$data = (array)json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->HotelServices_model->get_room_rates($data);
if($res['status'] == 1){
$this->response($res['data']);
}else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function get_rate_rules(){
$data = (array) json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->HotelServices_model->get_rate_rules($data);
if($res['status'] == 1){
$this->response($res['data']);
}else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function hotel_book(){
$data = (array)json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->HotelServices_model->hotel_book($data);
if($res['status'] == 1){
$this->response($res['data']);
}else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function trawex_cancel_booking(){
$data = (array)json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->HotelServices_model->trawex_cancel_booking($data);
if($res['status'] == 1){
$this->response($res['data']);
}else{
$this->errorResponse($res['code'],$res['message']);
}
}
}
?>