api_model.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <?php
  2. class api_model extends Model {
  3. private $API = 'https://szollosil.bbus.smbinfo.hu/api/index.php';
  4. private $API_KEY = '92JxvN5Zeti4E1FDwKg0QPEl3md4vY63';
  5. public function getGroupsList() {
  6. $curl = curl_init();
  7. curl_setopt_array($curl, array(
  8. CURLOPT_URL => $this->API.'/affiliateapi/groups',
  9. CURLOPT_RETURNTRANSFER => true,
  10. CURLOPT_ENCODING => '',
  11. CURLOPT_MAXREDIRS => 10,
  12. CURLOPT_TIMEOUT => 0,
  13. CURLOPT_FOLLOWLOCATION => true,
  14. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  15. CURLOPT_CUSTOMREQUEST => 'GET',
  16. CURLOPT_HTTPHEADER => array(
  17. 'DOLAPIKEY: '.$this->API_KEY
  18. ),
  19. ));
  20. $response = curl_exec($curl);
  21. curl_close($curl);
  22. $groups = [];
  23. $response = json_decode($response, true);
  24. foreach ($response as $key => $item) {
  25. $group = [];
  26. $group['id'] = $key;
  27. $group['label'] = $item;
  28. $groups[] = $group;
  29. }
  30. //$data = json_encode($groups, true);
  31. return $groups;
  32. }
  33. public function getProductsList($groupID) {
  34. $curl = curl_init();
  35. curl_setopt_array($curl, array(
  36. CURLOPT_URL => $this->API.'/affiliateapi/products?group_id='.$groupID,
  37. CURLOPT_RETURNTRANSFER => true,
  38. CURLOPT_ENCODING => '',
  39. CURLOPT_MAXREDIRS => 10,
  40. CURLOPT_TIMEOUT => 0,
  41. CURLOPT_FOLLOWLOCATION => true,
  42. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  43. CURLOPT_CUSTOMREQUEST => 'GET',
  44. CURLOPT_HTTPHEADER => array(
  45. 'DOLAPIKEY: '.$this->API_KEY
  46. ),
  47. ));
  48. $response = curl_exec($curl);
  49. curl_close($curl);
  50. $products = [];
  51. $response = json_decode($response, true);
  52. foreach ($response as $group) {
  53. foreach ($group as $key => $categories) {
  54. foreach ($categories as $item) {
  55. $product = [];
  56. $product['id'] = $item['id'];
  57. $product['name'] = $item['label'];
  58. $product['price'] = $item['price'];
  59. $products[$key]['products'][] = $product;
  60. }
  61. $products[$key]['label'] = $products[$key]['products'][0]['name'];
  62. $products[$key]['key'] = $key;
  63. }
  64. }
  65. //$data = json_encode($products, true);
  66. return $products;
  67. }
  68. public function getEventsList($groupID) {
  69. $curl = curl_init();
  70. curl_setopt_array($curl, array(
  71. CURLOPT_URL => $this->API.'/affiliateapi/events?group_id='.$groupID.'&groupByDate=1',
  72. CURLOPT_RETURNTRANSFER => true,
  73. CURLOPT_ENCODING => '',
  74. CURLOPT_MAXREDIRS => 10,
  75. CURLOPT_TIMEOUT => 0,
  76. CURLOPT_FOLLOWLOCATION => true,
  77. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  78. CURLOPT_CUSTOMREQUEST => 'GET',
  79. CURLOPT_HTTPHEADER => array(
  80. 'DOLAPIKEY: '.$this->API_KEY
  81. ),
  82. ));
  83. $response = curl_exec($curl);
  84. curl_close($curl);
  85. $events = [];
  86. $response = json_decode($response, true);
  87. foreach ($response as $key => $item) {
  88. $event = [];
  89. $event['key'] = $key;
  90. foreach ($item as $subkey => $subitem) {
  91. $sub = [];
  92. $date = explode(' ', $subkey);
  93. $sub['id'] = $subitem['id'];
  94. $sub['label'] = $subitem['label'];
  95. $sub['description'] = $subitem['description'];
  96. $sub['date'] = $date[0];
  97. $sub['time'] = substr($date[1],0,-3);
  98. $sub['max_num'] = $subitem['max_num'];
  99. $sub['participants'] = $subitem['participants'];
  100. $sub['available'] = $subitem['max_num'] - $subitem['participants'];
  101. $event['dates'][] = $sub;
  102. }
  103. $event['label'] = $event['dates'][0]['label'];
  104. $event['description'] = $event['dates'][0]['description'];
  105. $event['date'] = $event['dates'][0]['date'];
  106. $event['time'] = $event['dates'][0]['time'];
  107. $event['available'] = $event['dates'][0]['available'];
  108. $events[] = $event;
  109. }
  110. //$data = json_encode($events, true);
  111. return $events;
  112. }
  113. public function getMenusList($eventID) {
  114. $curl = curl_init();
  115. curl_setopt_array($curl, array(
  116. CURLOPT_URL => $this->API.'/affiliateapi/menus?eventDetailId='.$eventID,
  117. CURLOPT_RETURNTRANSFER => true,
  118. CURLOPT_ENCODING => '',
  119. CURLOPT_MAXREDIRS => 10,
  120. CURLOPT_TIMEOUT => 0,
  121. CURLOPT_FOLLOWLOCATION => true,
  122. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  123. CURLOPT_CUSTOMREQUEST => 'GET',
  124. CURLOPT_HTTPHEADER => array(
  125. 'DOLAPIKEY: '.$this->API_KEY
  126. ),
  127. ));
  128. $response = curl_exec($curl);
  129. curl_close($curl);
  130. $response = json_decode($response, true);
  131. foreach ($response as $key => $item) {
  132. $menu = [];
  133. $menu['id'] = $item['fk_product'];
  134. $menu['label'] = $item['label'];
  135. $menu['description'] = $item['description'];
  136. $menu['price'] = $item['price'];
  137. $menus[] = $menu;
  138. }
  139. //$data = json_encode($events, true);
  140. return $menus;
  141. }
  142. public function getEvents($packageid, $participants) {
  143. $curl = curl_init();
  144. curl_setopt_array($curl, array(
  145. CURLOPT_URL => $this->API.'/affiliateapi/events?id='.$packageid.'&participants='.$participants,
  146. CURLOPT_RETURNTRANSFER => true,
  147. CURLOPT_ENCODING => '',
  148. CURLOPT_MAXREDIRS => 10,
  149. CURLOPT_TIMEOUT => 0,
  150. CURLOPT_FOLLOWLOCATION => true,
  151. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  152. CURLOPT_CUSTOMREQUEST => 'GET',
  153. CURLOPT_HTTPHEADER => array(
  154. 'DOLAPIKEY: '.$this->API_KEY
  155. ),
  156. ));
  157. $response = curl_exec($curl);
  158. curl_close($curl);
  159. $events = [];
  160. $response = json_decode($response, true);
  161. foreach ($response as $item) {
  162. $event = [];
  163. $date_temp = explode(' ', $item['start_date']);
  164. $date_exp = explode('-',$date_temp[0]);
  165. $honap = $date_exp[1] < 10 ? str_replace('0','',$date_exp[1]) : $date_exp[1];
  166. $nap = $date_exp[2] < 10 ? str_replace('0','',$date_exp[2]) : $date_exp[2];
  167. $datum = $date_exp[0] .'-'. $honap .'-'. $nap;
  168. $timePart = substr($date_temp[1], 0, -3);
  169. $event['id'] = $item['id'];
  170. $event['date'] = $datum;
  171. $event['datum'] = $date_temp[0];
  172. $event['time'] = $timePart;
  173. $event['products'] = $item['products'];
  174. $events[] = $event;
  175. }
  176. $data = json_encode($events, true);
  177. return $data;
  178. }
  179. public function getProductImage() {
  180. $id = $this->escapeString($_REQUEST['id']);
  181. $row = $this->query("select * from azonics_products where slide_title='".$id."' AND slide_status='1';");
  182. return $row[0];
  183. }
  184. public function getServices() {
  185. $rows = $this->query("select * from azonics_services where box_status='1';");
  186. $result = [];
  187. foreach ($rows as $row) {
  188. $result[] = $row;
  189. }
  190. return $result;
  191. }
  192. public function getGroupNameByID($groupID) {
  193. $rows = $this->query("select * from azonics_services where box_status='1' AND parent_service='".$groupID."';");
  194. return $rows[0]->box_subtitle;
  195. }
  196. public function getProdutNameByID($productID) {
  197. $rows = $this->query("select * from azonics_services where box_status='1' AND parent_service='".$groupID."';");
  198. return $rows[0]->box_subtitle;
  199. }
  200. public function initializeTransaction() {
  201. $curl = curl_init();
  202. curl_setopt_array($curl, array(
  203. CURLOPT_URL => $this->API.'/affiliateapi/init',
  204. CURLOPT_RETURNTRANSFER => true,
  205. CURLOPT_ENCODING => '',
  206. CURLOPT_MAXREDIRS => 10,
  207. CURLOPT_TIMEOUT => 0,
  208. CURLOPT_FOLLOWLOCATION => true,
  209. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  210. CURLOPT_CUSTOMREQUEST => 'GET',
  211. CURLOPT_HTTPHEADER => array(
  212. 'DOLAPIKEY: '.$this->API_KEY
  213. ),
  214. ));
  215. $response = curl_exec($curl);
  216. $response = str_replace('"','',$response);
  217. curl_close($curl);
  218. return $response;
  219. }
  220. public function startReservation() {
  221. $curl = curl_init();
  222. $post_data = array(
  223. 'uuid' => $_REQUEST['uuid'],
  224. 'event_id' => $_REQUEST['event_id'],
  225. 'qty' => $_REQUEST['qty']
  226. );
  227. curl_setopt_array($curl, array(
  228. CURLOPT_URL => $this->API.'/affiliateapi/reserve',
  229. CURLOPT_RETURNTRANSFER => true,
  230. CURLOPT_ENCODING => '',
  231. CURLOPT_MAXREDIRS => 10,
  232. CURLOPT_TIMEOUT => 0,
  233. CURLOPT_FOLLOWLOCATION => true,
  234. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  235. CURLOPT_CUSTOMREQUEST => 'POST',
  236. CURLOPT_POSTFIELDS => http_build_query($post_data),
  237. CURLOPT_HTTPHEADER => array(
  238. 'DOLAPIKEY: '.$this->API_KEY
  239. ),
  240. ));
  241. $response = curl_exec($curl);
  242. curl_close($curl);
  243. return $response;
  244. }
  245. public function order() {
  246. $data = json_decode($_REQUEST['data']);
  247. $curl = curl_init();
  248. $post_data = $data;
  249. $post_data->uuid = str_replace('"','',$post_data->uuid);
  250. curl_setopt_array($curl, array(
  251. CURLOPT_URL => $this->API.'/affiliateapi/order',
  252. CURLOPT_RETURNTRANSFER => true,
  253. CURLOPT_ENCODING => '',
  254. CURLOPT_MAXREDIRS => 10,
  255. CURLOPT_TIMEOUT => 0,
  256. CURLOPT_FOLLOWLOCATION => true,
  257. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  258. CURLOPT_CUSTOMREQUEST => 'POST',
  259. CURLOPT_POSTFIELDS => json_encode($post_data),
  260. CURLOPT_HTTPHEADER => array(
  261. 'Content-Type: application/json',
  262. 'DOLAPIKEY: '.$this->API_KEY
  263. ),
  264. ));
  265. //print_r(json_encode($post_data));
  266. //die();
  267. $response = curl_exec($curl);
  268. curl_close($curl);
  269. return $response;
  270. }
  271. public function paymentstatus() {
  272. $curl = curl_init();
  273. curl_setopt_array($curl, array(
  274. CURLOPT_URL => $this->API.'/affiliateapi/paymentstatus?uuid='.$_REQUEST['uuid'],
  275. CURLOPT_RETURNTRANSFER => true,
  276. CURLOPT_ENCODING => '',
  277. CURLOPT_MAXREDIRS => 10,
  278. CURLOPT_TIMEOUT => 0,
  279. CURLOPT_FOLLOWLOCATION => true,
  280. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  281. CURLOPT_CUSTOMREQUEST => 'GET',
  282. CURLOPT_HTTPHEADER => array(
  283. 'DOLAPIKEY: '.$this->API_KEY
  284. ),
  285. ));
  286. $response = curl_exec($curl);
  287. curl_close($curl);
  288. return $response;
  289. }
  290. public function getProviderDetails() {
  291. $curl = curl_init();
  292. curl_setopt_array($curl, array(
  293. CURLOPT_URL => $this->API.'/affiliateapi/getCustomerData',
  294. CURLOPT_RETURNTRANSFER => true,
  295. CURLOPT_ENCODING => '',
  296. CURLOPT_MAXREDIRS => 10,
  297. CURLOPT_TIMEOUT => 0,
  298. CURLOPT_FOLLOWLOCATION => true,
  299. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  300. CURLOPT_CUSTOMREQUEST => 'GET',
  301. CURLOPT_HTTPHEADER => array(
  302. 'DOLAPIKEY: '.$this->API_KEY
  303. ),
  304. ));
  305. $response = curl_exec($curl);
  306. curl_close($curl);
  307. return $response;
  308. }
  309. public function getLabels($lang = 'hu') {
  310. $rows = $this->query("select
  311. setting_name,
  312. setting_value_text,
  313. setting_value_text_en,
  314. setting_status from azonics_settings where setting_status='1';");
  315. foreach ($rows as $row) {
  316. if ($lang == 'en') {
  317. $row->setting_value_text = $row->setting_value_text_en;
  318. }
  319. $results[] = $row;
  320. }
  321. return $results;
  322. }
  323. public function getGroups($lang = 'hu') {
  324. $rows = $this->query("SELECT * FROM `azonics_services` WHERE box_status=1;");
  325. foreach ($rows as $row) {
  326. if ($lang == 'en') {
  327. $row->box_subtitle = $row->box_subtitle_en;
  328. $row->box_title = $row->box_button_text_en;
  329. }
  330. $results[] = $row;
  331. }
  332. return $results;
  333. }
  334. public function getGroupID($groupKey) {
  335. $row = $this->query("SELECT * FROM `azonics_services` WHERE box_status=1 AND box_title_en='".$groupKey."';");
  336. return $row[0]->parent_service;
  337. }
  338. public function getLowestEventprice($eventID) {
  339. $events = $this->getMenusList($eventID);
  340. foreach ($events as $event) {
  341. if (!isset($lowest) || $event['price'] < $lowest) {
  342. $lowest = $event['price'];
  343. }
  344. }
  345. return formatize::currency(round($lowest));
  346. }
  347. public function getEventsData($groupID, $lang = 'hu') {
  348. $parentID = $this->getGroupID($groupID);
  349. $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$parentID.";");
  350. foreach ($rows as $row) {
  351. $row->parent_price = $this->getLowestEventprice($row->parent_event);
  352. $images = $this->query("SELECT * FROM `azonics_events_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  353. $row->images = $images;
  354. $row->dates = $this->getEventsList($groupID);
  355. if ($lang == 'en') {
  356. $row->box_title = $row->box_title_en;
  357. $row->box_subtitle = $row->box_subtitle_en;
  358. }
  359. $results[] = $row;
  360. }
  361. return $results;
  362. }
  363. public function getEventMenus($eventID, $lang = 'hu') {
  364. $rows = $this->query("SELECT * FROM `azonics_packages` WHERE box_status=1 AND parent_event=".$eventID." ORDER BY box_order ASC;");
  365. $menus = $this->getMenusList($eventID);
  366. foreach ($rows as $row) {
  367. $images = $this->query("SELECT * FROM `azonics_package_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  368. $row->images = $images;
  369. foreach ($menus as $menu) {
  370. if ($menu['id'] == $row->parent_menu) {
  371. $row->parent_price = $menu['price'];
  372. }
  373. }
  374. if ($lang == 'en') {
  375. $row->box_title = $row->box_title_en;
  376. $row->box_subtitle = $row->box_subtitle_en;
  377. }
  378. if (count($images) > 0) {
  379. $results[] = $row;
  380. }
  381. }
  382. return $results;
  383. }
  384. public function getEventName($groupID, $eventID) {
  385. $row = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$groupID." AND parent_event=".$eventID.";");
  386. return $row[0]->box_title;
  387. }
  388. public function getEventsRawList() {
  389. $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1;");
  390. return $rows;
  391. }
  392. public function getProductsData($groupID, $lang = 'hu') {
  393. $items = $this->getProductsList($groupID);
  394. $rows = $this->query("SELECT * FROM `azonics_prods` WHERE box_status=1 AND parent_service=".$groupID.";");
  395. foreach ($rows as $row) {
  396. $images = $this->query("SELECT * FROM `azonics_prods_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  397. $row->images = $images;
  398. $row->items = $items[$row->parent_prods]['products'];
  399. if ($lang == 'en') {
  400. $row->box_title = $row->box_title_en;
  401. $row->box_subtitle = $row->box_subtitle_en;
  402. }
  403. $results[] = $row;
  404. }
  405. return $results;
  406. }
  407. public function getContent($slug, $lang = 'hu') {
  408. $row = $this->query("SELECT * FROM `azonics_blog` WHERE page_status=1 AND page_slug='".$slug."';");
  409. if ($lang == 'en') {
  410. $row[0]->page_title = $row[0]->page_title_en;
  411. $row[0]->page_content = $row[0]->page_content_en;
  412. }
  413. return $row[0];
  414. }
  415. public function getUID() {
  416. $curl = curl_init();
  417. curl_setopt_array($curl, array(
  418. CURLOPT_URL => $this->API.'/affiliateapi/init',
  419. CURLOPT_RETURNTRANSFER => true,
  420. CURLOPT_ENCODING => '',
  421. CURLOPT_MAXREDIRS => 10,
  422. CURLOPT_TIMEOUT => 0,
  423. CURLOPT_FOLLOWLOCATION => true,
  424. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  425. CURLOPT_CUSTOMREQUEST => 'GET',
  426. CURLOPT_HTTPHEADER => array(
  427. 'DOLAPIKEY: '.$this->API_KEY
  428. ),
  429. ));
  430. $response = curl_exec($curl);
  431. curl_close($curl);
  432. return $response;
  433. }
  434. public function reserveEvent($uuid, $eventID, $qty) {
  435. $curl = curl_init();
  436. $post_data = array('uuid' => $uuid, 'event_id' => $eventID, 'qty' => $qty);
  437. curl_setopt_array($curl, array(
  438. CURLOPT_URL => $this->API.'/affiliateapi/reserve',
  439. CURLOPT_RETURNTRANSFER => true,
  440. CURLOPT_ENCODING => '',
  441. CURLOPT_MAXREDIRS => 10,
  442. CURLOPT_TIMEOUT => 0,
  443. CURLOPT_FOLLOWLOCATION => true,
  444. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  445. CURLOPT_CUSTOMREQUEST => 'POST',
  446. CURLOPT_POSTFIELDS => json_encode($post_data),
  447. CURLOPT_HTTPHEADER => array(
  448. 'Content-Type:application/json',
  449. 'DOLAPIKEY: '.$this->API_KEY
  450. ),
  451. ));
  452. $response = curl_exec($curl);
  453. curl_close($curl);
  454. return json_decode($response);
  455. }
  456. public function getHotels($onlyHotels = false) {
  457. $curl = curl_init();
  458. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  459. if ($onlyHotels) {
  460. //$url .= '?givePartnerData=1';
  461. }
  462. curl_setopt_array($curl, array(
  463. CURLOPT_URL => $url,
  464. CURLOPT_RETURNTRANSFER => true,
  465. CURLOPT_ENCODING => '',
  466. CURLOPT_MAXREDIRS => 10,
  467. CURLOPT_TIMEOUT => 0,
  468. CURLOPT_FOLLOWLOCATION => true,
  469. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  470. CURLOPT_CUSTOMREQUEST => 'GET',
  471. CURLOPT_HTTPHEADER => array(
  472. 'DOLAPIKEY: '.$this->API_KEY
  473. ),
  474. ));
  475. $response = curl_exec($curl);
  476. curl_close($curl);
  477. $groups = [];
  478. $response = json_decode($response, true);
  479. foreach ($response as $key => $value) {
  480. if ($value['contracted_partner'] == '1') {
  481. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label']);
  482. }
  483. }
  484. return $options;
  485. }
  486. public function checkout($data) {
  487. $curl = curl_init();
  488. curl_setopt_array($curl, array(
  489. CURLOPT_URL => $this->API.'/affiliateapi/order',
  490. CURLOPT_RETURNTRANSFER => true,
  491. CURLOPT_ENCODING => '',
  492. CURLOPT_MAXREDIRS => 10,
  493. CURLOPT_TIMEOUT => 0,
  494. CURLOPT_FOLLOWLOCATION => true,
  495. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  496. CURLOPT_CUSTOMREQUEST => 'POST',
  497. CURLOPT_POSTFIELDS => json_encode($data),
  498. CURLOPT_HTTPHEADER => array(
  499. 'Content-Type:application/json',
  500. 'DOLAPIKEY: '.$this->API_KEY
  501. ),
  502. ));
  503. $response = curl_exec($curl);
  504. curl_close($curl);
  505. return json_decode($response);
  506. }
  507. public function getCountries() {
  508. $curl = curl_init();
  509. curl_setopt_array($curl, array(
  510. CURLOPT_URL => $this->API.'/setup/dictionary/countries?sortfield=code&sortorder=ASC&limit=3000',
  511. CURLOPT_RETURNTRANSFER => true,
  512. CURLOPT_ENCODING => '',
  513. CURLOPT_MAXREDIRS => 10,
  514. CURLOPT_TIMEOUT => 0,
  515. CURLOPT_FOLLOWLOCATION => true,
  516. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  517. CURLOPT_CUSTOMREQUEST => 'GET',
  518. CURLOPT_HTTPHEADER => array(
  519. 'DOLAPIKEY: '.$this->API_KEY
  520. ),
  521. ));
  522. $response = curl_exec($curl);
  523. curl_close($curl);
  524. $options = [];
  525. $response = json_decode($response, true);
  526. foreach ($response as $value) {
  527. $options[] = array('key' => $value['id'].'_'.$value['code'], 'value' => $value['label']);
  528. }
  529. return $options;
  530. }
  531. public function getPaymentStatus($uuid) {
  532. $curl = curl_init();
  533. curl_setopt_array($curl, array(
  534. CURLOPT_URL => $this->API.'/affiliateapi/paymentstatus?uuid='.$uuid,
  535. CURLOPT_RETURNTRANSFER => true,
  536. CURLOPT_ENCODING => '',
  537. CURLOPT_MAXREDIRS => 10,
  538. CURLOPT_TIMEOUT => 0,
  539. CURLOPT_FOLLOWLOCATION => true,
  540. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  541. CURLOPT_CUSTOMREQUEST => 'GET',
  542. CURLOPT_HTTPHEADER => array(
  543. 'DOLAPIKEY: '.$this->API_KEY
  544. ),
  545. ));
  546. $response = curl_exec($curl);
  547. curl_close($curl);
  548. $response = json_decode($response, true);
  549. return $response;
  550. }
  551. public function authenticateUser($username, $password) {
  552. $row = $this->query("SELECT * FROM `azonics_admin_users` WHERE admin_pass='".$password."' AND (admin_email='".$username."' OR admin_name='".$username."') AND admin_status='1';");
  553. if (count($row) == 0) {
  554. return ['success' => false];
  555. }
  556. else {
  557. return [
  558. 'success' => true,
  559. 'name' => $row[0]->admin_name,
  560. 'hotel' => $row[0]->admin_dashboard
  561. ];
  562. }
  563. }
  564. public function getMonthRevenue($hotelID, $actualMonth = 0) {
  565. $curl = curl_init();
  566. $postfix = '';
  567. if ($actualMonth == 1) {
  568. $postfix = '&actualMonth='.$actualMonth;
  569. }
  570. curl_setopt_array($curl, array(
  571. CURLOPT_URL => $this->API.'/affiliateapi/getAmount?hotel_id='.$hotelID.$postfix,
  572. CURLOPT_RETURNTRANSFER => true,
  573. CURLOPT_ENCODING => '',
  574. CURLOPT_MAXREDIRS => 10,
  575. CURLOPT_TIMEOUT => 0,
  576. CURLOPT_FOLLOWLOCATION => true,
  577. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  578. CURLOPT_CUSTOMREQUEST => 'GET',
  579. CURLOPT_HTTPHEADER => array(
  580. 'DOLAPIKEY: '.$this->API_KEY
  581. ),
  582. ));
  583. $response = curl_exec($curl);
  584. curl_close($curl);
  585. $response = str_replace('"','',$response);
  586. $result = intval($response);
  587. return $result;
  588. }
  589. public function getReports() {
  590. $hotels = $this->getHotels(true);
  591. $reports = [];
  592. $userData = unserialize($_SESSION['admin_user']->admin_dashboard);
  593. foreach ($userData as $hotelID) {
  594. $hotel = array_filter($hotels, function($h) use ($hotelID) {
  595. return $h['key'] == $hotelID;
  596. });
  597. if (!empty($hotel)) {
  598. $hotel = array_values($hotel)[0];
  599. }
  600. $report = [];
  601. $report['hotel'] = $hotel['value'];
  602. $report['actual_month'] = $this->getMonthRevenue($hotelID, 1);
  603. $report['last_month'] = $this->getMonthRevenue($hotelID, 0);
  604. $reports[] = $report;
  605. }
  606. return $reports;
  607. }
  608. }