Advertisement
Guest User

Untitled

a guest
Jun 1st, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.89 KB | None | 0 0
  1. <?php
  2. define("_VALID_PHP", true);
  3. require_once("../autoload.php");
  4.  
  5. ////////////////////////////////////////////////////////////////
  6. if(post('do_comment')){ // makes an api call to process the comment
  7. print $api->request('process_comment', false, 'json');
  8. }
  9. ////////////////////////////////////////////////////////////////
  10. if(post('getprice')){ //returns the price of the item
  11. $return = array();
  12. $href_ids = "";
  13. foreach(post('attributes') as $attribute){
  14. $what = 'id';
  15. $table = TABLE_PRODUCTS_ATTR_HREF;
  16. $where = 'product_id = "'.(int)post('product_id').'" AND attribute_id = "'.(int)$attribute['attribute_id'].'" AND value_id = "'.(int)$attribute['attribute_value_id'].'"';
  17. $result = $db->getResults($what, $table, $where);
  18. // $return []= $result[];
  19. $href_ids.=$result[0]['id'].",";
  20. }
  21. $href_ids = rtrim($href_ids, ',');
  22. $what = 'price';
  23. $table = TABLE_PRODUCTS_DATA;
  24. $where = 'product_id = "'.(int)post('product_id').'" AND attr_href_ids = "'.$href_ids.'"';
  25. $result = $db->getResults($what, $table, $where);
  26. print json_encode($result[0]['price'], JSON_PRETTY_PRINT);
  27. // print $api->request('process_comment', false, 'json');
  28. }
  29. if(post('slider_images')) { //gets slider images from the database
  30. $get_slider = $db->getResults("value, slide_id", "slider_layers", "type='background' LIMIT 10");
  31. if($get_slider){
  32. foreach($get_slider as $slider){
  33. $title = $db->getValue("title", "slider_slides", "id = ".$slider['slide_id']);
  34. $return[] = array(
  35. 'value' => $slider['value'],
  36. 'title' => $title
  37. );
  38. }
  39. }else{
  40. $return = array(
  41. 'status' => 0,
  42. 'res' => 'no images'
  43. );
  44. }
  45.  
  46. print json_encode($return, JSON_PRETTY_PRINT);
  47.  
  48. }
  49.  
  50. if(post('gallery')) { //gets gallery images from the database
  51. $limit = post('gallery');
  52. $start = post('start');
  53. if(post('start')) {
  54. $get_images = $db->getResults("id,image", "gallery" ,"id != 0 LIMIT ".$start.",".$limit."");
  55. } else {
  56. $get_images = $db->getResults("id,image", "gallery" ,"id != 0 LIMIT ".$limit."");
  57. }
  58. print json_encode($get_images, JSON_PRETTY_PRINT);
  59. }
  60.  
  61. if(post('get_rooms')) { // gets post('get_rooms') number of rooms with pagination
  62. $limit = post('get_rooms');
  63. $start = post('start');
  64. if(post('start')) {
  65. $get_rooms = $db->getResults("id, title{$lang->dblang} as title, price, saving, address, size, description{$lang->dblang} as description, city_id, country_id,max_capacity", TABLE_OBJECTS,"cid='1' ORDER BY id DESC LIMIT ".$start.",".$limit."");
  66. } else {
  67. $get_rooms = $db->getResults("id, title{$lang->dblang} as title, price, saving, address, size, description{$lang->dblang} as description, city_id, country_id,max_capacity", TABLE_OBJECTS,"cid='1' ORDER BY id DESC LIMIT ".$limit."");
  68. }
  69. foreach($get_rooms as $key => $room) {
  70. $image = $db->getResults("*", 'objects_images',"object_id='".$room['id']."' ORDER BY id DESC LIMIT 1");
  71. $rooms[] = array(
  72. 'id' => $room['id'],
  73. 'title' => $room['title'],
  74. 'price' => $room['price'],
  75. 'saving' => $room['saving'],
  76. 'description' => $room['description'],
  77. 'image' => $image[0]['image'],
  78. 'city_id' => $room['city_id'],
  79. 'country_id' => $room['country_id'],
  80. 'room_size' => $room['size'],
  81. 'room_capacity' => $room['max_capacity']
  82. );
  83. }
  84. print json_encode($rooms, JSON_PRETTY_PRINT);
  85. }
  86.  
  87. if(post('get_places')) { // gets post('get_places') number of places with pagination
  88. $limit = post('get_places');
  89. $start = post('start');
  90. if(post('start')) {
  91. $get_rooms = $db->getResults("id, title{$lang->dblang} as title, address, worktime, phone, lat, lng, views", TABLE_OBJECTS,"cid='4' ORDER BY id DESC LIMIT ".$start.",".$limit."");
  92. } else {
  93. $get_rooms = $db->getResults("id, title{$lang->dblang} as title, address, worktime, phone, lat, lng, views", TABLE_OBJECTS,"cid='4' ORDER BY id DESC LIMIT ".$limit."");
  94. }
  95. foreach($get_rooms as $key => $room) {
  96. $image = $db->getResults("*", 'objects_images',"object_id='".$room['id']."' ORDER BY id DESC");
  97. $likes = $db->getValue("COUNT(id)", "places_favourites", "place_id = ".$room['id']);
  98.  
  99. $onestar = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 1 AND place_id = ".$room['id']);
  100. $twoostars = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 2 AND place_id = ".$room['id']);
  101. $threestars = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 3 AND place_id = ".$room['id']);
  102. $fourstars = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 4 AND place_id = ".$room['id']);
  103. $fivestars = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 5 AND place_id = ".$room['id']);
  104. $total = $db->getValue("COUNT(id)", "places_reviews", "place_id = ".$room['id']);
  105. $reviews = $db->getResults("user_name, review_message, rate_count", "places_reviews", "place_id = ".$room['id']." LIMIT 5");
  106. if(!$total){
  107. $totalCount = 1;
  108. }else{
  109. $totalCount = $total;
  110. }
  111. if(!$reviews){
  112. $reviews = array();
  113. }
  114. $average = ($onestar*1 + $twoostars*2 + $threestars*3 + $fourstars*4 + $fivestars*5)/$totalCount;
  115. $rooms[] = array(
  116. 'id' => $room['id'],
  117. 'title' => $room['title'],
  118. 'location' => $room['address'],
  119. 'worktime' => $room['worktime'],
  120. 'phone' => $room['phone'],
  121. 'lat' => $room['lat'],
  122. 'lng' => $room['lng'],
  123. 'image' => $image,
  124. 'visiter_count' => $room['views'],
  125. 'like_count' => $likes,
  126. 'one_star' => $onestar,
  127. 'two_stars' => $twoostars,
  128. 'three_stars' => $threestars,
  129. 'four_stars' => $fourstars,
  130. 'five_stars' => $fivestars,
  131. 'total_rate_count' => $total,
  132. 'average_rate_count' => $average,
  133. 'reviews' => $reviews,
  134.  
  135. );
  136. }
  137. print json_encode($rooms, JSON_PRETTY_PRINT);
  138. }
  139.  
  140. if(post('reset_password') && !empty(post('reset_password'))) { //resets the password and sends it back to email
  141. global $db, $core;
  142.  
  143. $msgs = array();
  144. $return = array();
  145.  
  146. if (empty(post('email'))) {
  147. $msgs['[name="email"]'] = _USERS_ERROR_EMAIL;
  148. }
  149.  
  150. if (!isValidEmail(post('email'))){
  151. $msgs['[name="email"]'] = _USERS_ERROR_EMAIL_INVALID;
  152. }
  153.  
  154. if (!emailExists(post('email'))){
  155. $msgs['[name="email"]'] = 'Email акаунта не се ползва от нито един потребител.';
  156. }
  157.  
  158. if (empty($msgs)){
  159. $rand = rand(1000000, 9999999);
  160. $data = array(
  161. 'forgot_password' => $rand,
  162. );
  163. $email = sanitize(post('email'));
  164. $db->update(TABLE_USERS, $data, "email='".$email."'");
  165.  
  166. include(BASEPATH . API_DIR . PLUGINS_DIR. "Phpmailer/PHPMailerAutoload.php");
  167. $mail = new PHPMailer();
  168. $to = sanitize(post('email'));
  169. $mail->IsHTML(true);
  170. $mail->CharSet = 'UTF-8';
  171. $mail->From = $core->site_email;
  172. $mail->FromName = $core->site_name;
  173. $mail->AddAddress($to);
  174. $mail->AddReplyTo('no-reply@vsichkotok.bg', 'VsichkoTok');
  175. $mail->Subject = $core->site_name.' - Забравена парола';
  176. $link = '';
  177. if($core->site_id == '1'){
  178. $link = 'http://vsichkotok.bg/index/29-nova-parola.html?forgot_password='.$rand.'';
  179. }
  180. if($core->site_id == '3'){
  181. $link = 'http://elektromobili.bg/new-password/34-nova-parola.html?forgot_password='.$rand.'';
  182. }
  183. $mail->Body = 'Вие направихте заявка за нулиране на паролата. <a href="'.$link.'">Кликнете тук за да въведете своята нова парола.</a>';
  184. if($mail->Send()) {
  185. $return = array(
  186. 'status' => 1,
  187. );
  188. }else {
  189. $return = array(
  190. 'status' => 0,
  191. );
  192. }
  193. }else {
  194. $return = array(
  195. 'status' => 0,
  196. );
  197. }
  198.  
  199. print json_encode($return, JSON_PRETTY_PRINT);
  200. }
  201.  
  202. if(post('login') && !empty(post('login'))) { // user login
  203.  
  204. global $db, $core, $user;
  205.  
  206. $msgs = array();
  207. $return = array();
  208.  
  209. if (post('email') == ""){
  210. $msgs['email_empty'] = _USERS_ERROR_EMAIL;
  211. } elseif (post('password') == "") {
  212. $msgs['password_empty'] = _USERS_ERROR_PASSWORD;
  213. } else {
  214. $status = $user->check_user_status(get('email'), post('password'));
  215. switch ($status) {
  216. case 0:
  217. $msgs['email_password'] = _USERS_ERROR_EMAIL_PASSWORD;
  218. break;
  219.  
  220. case 1:
  221. $msgs['acc_actived'] = _USERS_ERROR_ACC_ACTIVED;
  222. break;
  223. }
  224. }
  225.  
  226. if (empty($msgs)&& $status==2) {
  227. if(post('is_mobile') && post('is_mobile') == 1){
  228. $return = array(
  229. 'status' => 1,
  230. );
  231. } else {
  232. $return = array(
  233. 'status' => 1,
  234. );
  235. }
  236.  
  237. } else {
  238. if(post('is_mobile') && post('is_mobile') == 1){
  239. $return = array(
  240. 'status' => 0,
  241. );
  242. } else {
  243. $return = array(
  244. 'status' => 0,
  245. );
  246. }
  247.  
  248. }
  249. print json_encode($return, JSON_PRETTY_PRINT);
  250. }
  251. if(post('get_user_info') && post('get_user_info') != 0){ //gets user information where email = post('email')
  252.  
  253. global $db, $core, $user;
  254.  
  255. $email = sanitize(post('email'));
  256.  
  257. $sql = "SELECT id, email, first_name, last_name, phone, address, city_id, balance, userlevel, tag, active, fbid, created, lastlogin, lastip FROM " . TABLE_USERS . " WHERE email = '" . $email . "'";
  258. $row = $db->first($sql);
  259.  
  260. if($row['address']){
  261. $row['address'] = cleanOut($row['address']);
  262. }
  263.  
  264. if (!$email)
  265. return false;
  266.  
  267. print json_encode($row, JSON_PRETTY_PRINT);
  268. }
  269.  
  270. if(post('update_object_views')) { //increaases the object views
  271. $object = post('update_object_views');
  272. $oldviews = $db->getValue('views', TABLE_OBJECTS, "id='".$object."'");
  273. $new_views = $oldviews+1;
  274. $views = array(
  275. 'views' => $new_views
  276. );
  277. $update = $db->update(TABLE_OBJECTS, $views, "id='".$object."'");
  278. if($update) {
  279. $response = array(
  280. 'res' => '1',
  281. 'views' => $new_views
  282. );
  283. } else {
  284. $response = array(
  285. 'res' => '0',
  286. 'views' => $new_views
  287. );
  288. }
  289. print json_encode($response, JSON_PRETTY_PRINT);
  290.  
  291. }
  292.  
  293. if(post('register')) { //registration function
  294.  
  295. $msgs = array();
  296. $return = array();
  297.  
  298. if (empty(post('first_name'))) {
  299. $msgs['[name="first_name"]'] = _USERS_ERROR_FIRST_NAME;
  300. }
  301.  
  302. if (empty(post('last_name'))) {
  303. $msgs['[name="last_name"]'] = _USERS_ERROR_LAST_NAME;
  304. }
  305.  
  306. if (empty(post('email'))) {
  307. $msgs['[name="email"]'] = _USERS_ERROR_EMAIL;
  308. }
  309.  
  310. if (!isValidEmail(post('email')))
  311. $msgs['[name="email"]'] = _USERS_ERROR_EMAIL_INVALID;
  312.  
  313. if (emailExists(post('email')))
  314. $msgs['[name="email"]'] = _USERS_ERROR_EMAIL_TAKEN;
  315.  
  316. if (empty(post('password')))
  317. $msgs['[name="password"]'] = _USERS_ERROR_PASSWORD;
  318.  
  319. if (strlen(post('password')) < 6)
  320. $msgs['[name="password"]'] = str_replace("<%n%>", "6", _USERS_ERROR_PASSWORD_LENGHT);
  321.  
  322. if (empty($msgs)){
  323. $data = array(
  324. 'email' => sanitize(post('email')),
  325. 'first_name' => sanitize(post('first_name')),
  326. 'last_name' => sanitize(post('last_name')),
  327. 'phone' => sanitize(post('phone')),
  328. 'interest' => sanitize(post('interest')),
  329. 'active' => '1',
  330. );
  331.  
  332. if (post('password') != "") {
  333. $data['password'] = md5(post('password'));
  334. }
  335.  
  336. $db->insert(TABLE_USERS, $data);
  337. $message = _USERS_SUCCESS_INSERT;
  338.  
  339. if ($db->affected()){
  340. $return = array(
  341. 'status' => 1,
  342. 'msg' => $message,
  343. );
  344. }
  345. } else {
  346. $return = array(
  347. 'status' => 0,
  348. 'error_fields' => $msgs,
  349. );
  350. }
  351.  
  352. print json_encode($return, JSON_PRETTY_PRINT);
  353.  
  354. }
  355.  
  356. if(post('get_room_service')){ //get the available room services
  357. $limit = post('get_room_service');
  358. $start = post('start');
  359. if(post('start')) {
  360. $get_room_service = $db->getResults("*", TABLE_SERVICES ,"id != 0 LIMIT ".$start.",".$limit."");
  361. } else {
  362. $get_room_service = $db->getResults("*", TABLE_SERVICES ,"id != 0 LIMIT ".$limit."");
  363. }
  364. if($get_room_service){
  365. foreach($get_room_service as $key => $service) {
  366. $services[] = array(
  367. 'id' => $service['id'],
  368. 'title' => $service['title'],
  369. 'image' => $service['image'],
  370. 'description' => $service['description']
  371. );
  372. }
  373. }else{
  374. $services = array(
  375. 'status' => 0,
  376. 'msg' => 'no services'
  377. );
  378. }
  379.  
  380. print json_encode($services, JSON_PRETTY_PRINT);
  381. }
  382.  
  383. if(post('get_extras')){ //get the available room extras
  384. $limit = post('get_extras');
  385. $start = post('start');
  386. if(post('start')) {
  387. $get_extras = $db->getResults("*", TABLE_ROOM_EXTRAS ,"id != 0 LIMIT ".$start.",".$limit."");
  388. } else {
  389. $get_extras = $db->getResults("*", TABLE_ROOM_EXTRAS ,"id != 0 LIMIT ".$limit."");
  390. }
  391. if($get_extras){
  392. foreach($get_extras as $key => $extra) {
  393. $extras[] = array(
  394. 'id' => $extra['id'],
  395. 'title' => $extra['title'],
  396. 'body' => $extra['body'],
  397. 'icon' => $extra['image']
  398. );
  399. }
  400. }else{
  401. $extras = array(
  402. 'status' => 0,
  403. 'msg' => 'no extras'
  404. );
  405. }
  406.  
  407. print json_encode($extras, JSON_PRETTY_PRINT);
  408. }
  409.  
  410. if(post('get_comments')){ // get 5 top rated commments where rating > 1
  411. $get_comments = $db->getResults("*", TABLE_COMMENTS, "rating > 1 ORDER BY rating DESC LIMIT 5");
  412. if($get_comments){
  413. foreach($get_comments as $key => $comment){
  414. if($comment['hotel_id'] != '0'){
  415.  
  416. $user = $comment['username'];
  417. $query = $db->getValues('city_id, country_id, name', TABLE_HOTELS, "id='".$comment['hotel_id']."'");
  418.  
  419. $city = $db->getValue("title", TABLE_CITIES, "id = '".$query['city_id']."'");
  420. $country = $db->getValue("title", TABLE_COUNTRIES, "id = '".$query['country_id']."'");
  421. $commentText = $comment['comment'];
  422. $rating = $comment['rating'];
  423. $location = $city. ', ' . $country;
  424.  
  425.  
  426. $result[] = array(
  427. 'username' => $user,
  428. 'location' => $location,
  429. 'hotel_name' => $query['name'],
  430. 'comment' => $commentText,
  431. 'rating' => $rating
  432. );
  433. }
  434.  
  435. }
  436. }else{
  437. $result = array(
  438. 'status' => 0,
  439. 'msg' => 'no comments'
  440. );
  441. }
  442.  
  443. print json_encode($result, JSON_PRETTY_PRINT);
  444. }
  445. if(post('get_total_reviews')){ //get the number of 5 star reviewws
  446. $count = 0;
  447.  
  448. $reviews = $db->getResults("rating", TABLE_COMMENTS);
  449. if($reviews){
  450. foreach($reviews as $review){
  451. if($review['rating'] == '5'){
  452. $count++;
  453. }
  454. }
  455.  
  456. $return = array(
  457. 'count' => $count
  458. );
  459. }else{
  460. $return = array(
  461. 'count' => 0
  462. );
  463. }
  464.  
  465. print json_encode($return, JSON_PRETTY_PRINT);
  466.  
  467. }
  468. if(post('get_special_offers')){ // get the room special offers
  469. $limit = post('get_special_offers');
  470. $start = post('start');
  471. if(post('start')) {
  472. $get_offers = $db->getResults("*", TABLE_SPECIAL_OFFERS ,"id != 0 LIMIT ".$start.",".$limit."");
  473. } else {
  474. $get_offers = $db->getResults("*", TABLE_SPECIAL_OFFERS ,"id != 0 LIMIT ".$limit."");
  475. }
  476. if($get_offers){
  477. foreach($get_offers as $offer){
  478. $image = $db->getResults("id,image", TABLE_SPECIAL_OFFERS, "id = ".$offer['id']);
  479. $country = $db->getValue("title", TABLE_COUNTRIES, "id = ".$offer['country_id']);
  480. $city = $db->getValue("title", TABLE_CITIES, "id = ".$offer['city_id']);
  481. $discount = (1 - ($offer['promo_price']/$offer['price']))*100;
  482. $discount = round($discount);
  483. $return[] = array(
  484. 'id' => $offer['id'],
  485. 'title' => $offer['title'],
  486. 'description' => $offer['description'],
  487. 'price' => $offer['price']." lv",
  488. 'promo_price' => $offer['promo_price']." lv",
  489. 'discount' => $discount,
  490. 'image' => $image,
  491. 'country' => $country,
  492. 'city' => $city
  493. );
  494. }
  495. }else{
  496. $return[] = array(
  497. 'status' => 0,
  498. 'msg' => 'no offers'
  499. );
  500. }
  501.  
  502. print json_encode($return, JSON_PRETTY_PRINT);
  503. }
  504. if(post('get_countries')){ // get all the countries from the db
  505. $get_countries = $db->getResults("*", TABLE_HOTELS);
  506. $return = array();
  507. if($get_countries){
  508. foreach($get_countries as $country){
  509. $countryName = $db->getValue("title", TABLE_COUNTRIES, "id = ".$country['country_id']);
  510. $count = $db->getValue("COUNT(id)", TABLE_HOTELS, "country_id = '".$country['country_id']."'");
  511.  
  512. $return[] = array(
  513. 'country_id' => $country['country_id'],
  514. 'name' => $countryName,
  515. 'hotels_count' => $count
  516. );
  517.  
  518. }
  519.  
  520. }else{
  521. $return[] = array(
  522. 'status' => 0,
  523. 'msg' => 'no offers'
  524. );
  525. }
  526.  
  527. print json_encode($return, JSON_PRETTY_PRINT);
  528. }
  529.  
  530. if(post('get_hotels_by_country')){ // get all the hotels in a given country
  531. $country_id = post('get_hotels_by_country');
  532. $countries = $db->getResults("*", TABLE_HOTELS, "country_id = ".$country_id);
  533. $hotelsByCity = array();
  534. $i=0;
  535. foreach($countries as $key=>$country){
  536.  
  537. $cityName = $db->getValue("title", TABLE_CITIES, "id = ".$country['city_id']);
  538. $countryName = $db->getValue("title", TABLE_COUNTRIES, "id = ".$country['country_id']);
  539.  
  540. $hotelsByCity[$cityName][] = array(
  541. 'id' => $country['id'],
  542. 'name' => $country['name'],
  543. 'countryId' => $country['country_id'],
  544. 'image' => $country['image'],
  545. 'cityId' => $country['city_id'],
  546. 'cityName' => $cityName,
  547. 'countryName' => $countryName
  548. );
  549. $i++;
  550. }
  551. print json_encode($hotelsByCity, JSON_PRETTY_PRINT);
  552. }
  553. if(post('get_hotels_by_city')){ // get all hotels by city
  554. $city_id = post('get_hotels_by_city');
  555. $countries = $db->getResults("*", TABLE_HOTELS, "city_id = ".$city_id);
  556. $hotelsByCity = array();
  557.  
  558. foreach($countries as $country){
  559. $cityName = $db->getValue("title", TABLE_CITIES, "id = ".$country['city_id']);
  560. $countryName = $db->getValue("title", TABLE_COUNTRIES, "id = ".$country['country_id']);
  561.  
  562. $hotelsByCity[] = array(
  563. 'id' => $country['id'],
  564. 'name' => $country['name'],
  565. 'image' => $country['image'],
  566. 'cityName' => $cityName,
  567. 'countryName' => $countryName
  568. );
  569. }
  570. print json_encode($hotelsByCity, JSON_PRETTY_PRINT);
  571. }
  572. if(post('get_transport')){ // get all the transport units - bus, taxi etc
  573. $transport = $db->getResults("*", TABLE_TRANSPORT);
  574. $transportArr = array();
  575.  
  576. foreach($transport as $single){
  577. $images = $db->getResults("transport_id, image", "transportation_image", "transport_id =".$single['id']);
  578.  
  579. $transportArr[] = array(
  580. 'id' => $single['id'],
  581. 'title' => $single['title'],
  582. 'description' => $single['description'],
  583. 'image' => $images,
  584. 'price' => $single['price'],
  585. 'phone' => $single['phone'],
  586. 'hotel_id' => $single['hotel_id']
  587. );
  588. }
  589. print json_encode($transportArr, JSON_PRETTY_PRINT);
  590. }
  591. // API for each hotel
  592. if(post('get_room_service_hotel')){ // get the available room services for each hotel
  593. $hotelId = post('hotel_id');
  594. $limit = post('get_room_service_hotel');
  595. $start = post('start');
  596. if(post('start')) {
  597. $get_room_service = $db->getResults("*", TABLE_SERVICES ,"hotel_id = ".$hotelId." LIMIT ".$start.",".$limit."");
  598. } else {
  599. $get_room_service = $db->getResults("*", TABLE_SERVICES ,"hotel_id = ".$hotelId." LIMIT ".$limit."");
  600. }
  601. if($get_room_service){
  602. foreach($get_room_service as $key => $service) {
  603. $services[] = array(
  604. 'id' => $service['id'],
  605. 'title' => $service['title'],
  606. 'image' => $service['image'],
  607. 'description' => $service['description']
  608. );
  609. }
  610. }else{
  611. $services = array(
  612. 'status' => 0,
  613. 'msg' => 'no services'
  614. );
  615. }
  616.  
  617. print json_encode($services, JSON_PRETTY_PRINT);
  618. }
  619.  
  620. if(post('get_special_offers_hotel')){ // get special offers for each hotel
  621. $limit = post('get_special_offers_hotel');
  622. $start = post('start');
  623. $hotelId = post('hotel_id');
  624. if(post('start')) {
  625. $get_offers = $db->getResults("*", TABLE_SPECIAL_OFFERS ,"hotel_id = ".$hotelId." LIMIT ".$start.",".$limit."");
  626. } else {
  627. $get_offers = $db->getResults("*", TABLE_SPECIAL_OFFERS ,"hotel_id = ".$hotelId." LIMIT ".$limit."");
  628. }
  629. if($get_offers){
  630. foreach($get_offers as $offer){
  631. $country = $db->getValue("title", TABLE_COUNTRIES, "id = ".$offer['country_id']);
  632. $city = $db->getValue("title", TABLE_CITIES, "id = ".$offer['city_id']);
  633.  
  634. $return[] = array(
  635. 'id' => $offer['id'],
  636. 'title' => $offer['title'],
  637. 'price' => $offer['price'],
  638. 'promo_price' => $offer['promo_price'],
  639. 'image' => $offer['image'],
  640. 'country' => $country,
  641. 'city' => $city
  642. );
  643. }
  644. }else{
  645. $return[] = array(
  646. 'status' => 0,
  647. 'msg' => 'no offers'
  648. );
  649. }
  650.  
  651. print json_encode($return, JSON_PRETTY_PRINT);
  652. }
  653.  
  654. if(post('get_extras_hotel')){ //get extras for each hotel
  655. $limit = post('get_extras_hotel');
  656. $start = post('start');
  657. $hotelId = post('hotel_id');
  658. if(post('start')) {
  659. $get_extras = $db->getResults("*", TABLE_ROOM_EXTRAS ,"hotel_id = ".$hotelId." LIMIT ".$start.",".$limit."");
  660. } else {
  661. $get_extras = $db->getResults("*", TABLE_ROOM_EXTRAS ,"hotel_id = ".$hotelId." LIMIT ".$limit."");
  662. }
  663. if($get_extras){
  664. foreach($get_extras as $key => $extra) {
  665. $extras[] = array(
  666. 'id' => $extra['id'],
  667. 'title' => $extra['title'],
  668. 'body' => $extra['body'],
  669. 'image' => $extra['image']
  670. );
  671. }
  672. }else{
  673. $extras = array(
  674. 'status' => 0,
  675. 'msg' => 'no extras'
  676. );
  677. }
  678.  
  679. print json_encode($extras, JSON_PRETTY_PRINT);
  680. }
  681. if(post('get_rooms_hotel')) { //get rooms for each hotel
  682. $limit = post('get_rooms_hotel');
  683. $start = post('start');
  684. $hotelId = post('hotel_id');
  685. if(post('start')) {
  686. $get_rooms = $db->getResults("id, title{$lang->dblang} as title, price, saving, address, size, description{$lang->dblang} as description, city_id, country_id,max_capacity", TABLE_OBJECTS,"cid='1' AND hotel_id =".$hotelId." ORDER BY id DESC LIMIT ".$start.",".$limit."");
  687. } else {
  688. $get_rooms = $db->getResults("id, title{$lang->dblang} as title, price, saving, address, size, description{$lang->dblang} as description, city_id, country_id,max_capacity", TABLE_OBJECTS,"cid='1' AND hotel_id =".$hotelId." ORDER BY id DESC LIMIT ".$limit."");
  689. }
  690. foreach($get_rooms as $key => $room) {
  691. $image = $db->getResults("*", 'objects_images', "id='" . $room['id'] . "' ORDER BY id DESC LIMIT 1");
  692. $rooms[] = array('id' => $room['id'], 'title' => $room['title'], 'price' => $room['price'], 'saving' => $room['saving'], 'description' => $room['description'], 'image' => $image[0]['image'], 'city_id' => $room['city_id'], 'country_id' => $room['country_id'], 'room_size' => $room['size'], 'room_capacity' => $room['max_capacity']);
  693. }
  694. print json_encode($rooms, JSON_PRETTY_PRINT);
  695. }
  696.  
  697. if(post('get_hotel_details')){ // get all the hotel info
  698. $hotelId = post('get_hotel_details');
  699.  
  700. //hotel name
  701. $hotel = $db->getResults("*", TABLE_HOTELS, "id = ".$hotelId);
  702. //review count
  703. $reviews = $db->getValue("COUNT(id)", TABLE_COMMENTS, "hotel_id = ".$hotelId);
  704. //special offers
  705. $offers = $db->getResults("*", TABLE_SPECIAL_OFFERS, "hotel_id = ".$hotelId);
  706. //rooms
  707. $rooms = $db->getResults("id, title{$lang->dblang}, description{$lang->dblang}, price, size, max_capacity", TABLE_OBJECTS, "cid = '1' AND hotel_id =".$hotelId);
  708. $extras = $db->getResults("id, image", TABLE_ROOM_EXTRAS, "hotel_id = ".$hotelId);
  709. //galery
  710. $gallery = $db->getResults("*", "gallery", "hotel_id = ".$hotelId);
  711. //todo facilities
  712. $amentities = $db->getResults("*", TABLE_AMENTITIES, "hotel_id =".$hotelId);
  713. //reviews
  714. $comments = $db->getResults("*", TABLE_COMMENTS, "hotel_id = ".$hotelId);
  715.  
  716. $return['0'] = array(
  717. 'hotel_type' => $hotel[0]['name'],
  718. 'total_users' => $reviews,
  719. );
  720.  
  721. if(is_array($offers)){
  722. foreach($offers as $offer){
  723. $return['0']['packages'][] = array(
  724. 'id' => $offer['id'],
  725. 'title' => $offer['title'],
  726. 'description' => $offer['description'],
  727. 'image' => $offer['image'],
  728.  
  729. );
  730. }
  731. }
  732.  
  733. if(is_array($rooms)){
  734. foreach($rooms as $key => $room){
  735. $image = $db->getResults("*", 'objects_images',"object_id='".$room['id']."' ORDER BY id DESC LIMIT 1");
  736. $return['0']['room_and_price'][$key] = array(
  737. 'id' => $room['id'],
  738. 'room_name' => $room['title_en'],
  739. 'price' => $room['price'],
  740. 'description' => $room['description_en'],
  741. 'image' => $image[0]['image'],
  742. 'room_size' => $room['size'],
  743. 'room_capacity' => $room['max_capacity']
  744. );
  745. if(is_array($extras)){
  746. foreach($extras as $key1 => $extra){
  747. $return['0']['room_and_price'][$key]['room_extras'][$key1] = array(
  748. 'id' => $extra['id'],
  749. 'image' => $extra['image']
  750. );
  751. }
  752. }
  753.  
  754. }
  755. }
  756.  
  757. if(is_array($gallery)){
  758. foreach($gallery as $single){
  759. $return['0']['gallery'][] = array(
  760. 'id' => $single['id'],
  761. 'gallery' => $single['image']
  762. );
  763. }
  764. }
  765.  
  766. if(is_array($amentities)){
  767. foreach($amentities as $amentity){
  768. $images = $db->getValue("image", "amentities_images", "a_id = ".$amentity['id']);
  769.  
  770. $return['0']['facilities_and_services'][] = array(
  771. 'id' => $amentity['id'],
  772. 'title' => htmlspecialchars_decode($amentity['title']),
  773. 'description' => htmlspecialchars_decode($amentity['description']),
  774. 'phone' => $amentity['phone'],
  775. 'worktime' => $amentity['worktime'],
  776. 'image' => $images
  777. );
  778. }
  779. }
  780.  
  781. if(is_array($comments)){
  782. foreach($comments as $comment){
  783. $username = $db->getValues("first_name, last_name", TABLE_USERS, "id = ".$comment['user_id']);
  784. $name = $username['first_name'] . " " . $username['last_name'];
  785. $hotel = $db->getValue("name", TABLE_HOTELS, "id = ".$hotelId);
  786. $return['0']['reviews'][] = array(
  787. 'id' => $comment['id'],
  788. 'name' => $name,
  789. 'comment' => $comment['comment'],
  790. 'hotel_name' => $hotel
  791. );
  792. }
  793. }
  794. print json_encode($return, JSON_PRETTY_PRINT);
  795. }
  796.  
  797. if(post('get_amentities')){ // get hotel amentities
  798. $limit = post('get_amentities');
  799. $start = post('start');
  800. if(post('start')) {
  801. $get_amentities = $db->getResults("*", TABLE_AMENTITIES ,"id != 0 LIMIT ".$start.",".$limit."");
  802. } else {
  803. $get_amentities = $db->getResults("*", TABLE_AMENTITIES ,"id != 0 LIMIT ".$limit."");
  804. }
  805. if($get_amentities){
  806. foreach($get_amentities as $amentity){
  807. $images = $db->getResults("a_id, image", "amentities_images", "a_id = ".$amentity['id']);
  808. $return[] = array(
  809. 'id' => $amentity['id'],
  810. 'title' => htmlspecialchars_decode($amentity['title']),
  811. 'description' => htmlspecialchars_decode($amentity['description']),
  812. 'phone' => $amentity['phone'],
  813. 'worktime' => $amentity['worktime'],
  814. 'image' => $images,
  815. 'hotel_id' => $amentity['hotel_id'],
  816. );
  817. }
  818. }else{
  819. $return[] = array(
  820. 'status' => 0,
  821. 'msg' => 'no offers'
  822. );
  823. }
  824.  
  825. print json_encode($return, JSON_PRETTY_PRINT);
  826. }
  827.  
  828. if(post('get_amentities_hotel')){ //get amentities for each hotel
  829. $limit = post('get_amentities_hotel');
  830. $start = post('start');
  831. $hotelId = post('hotel_id');
  832. if(post('start')) {
  833. $get_amentities = $db->getResults("*", TABLE_AMENTITIES ,"hotel_id = ".$hotelId." LIMIT ".$start.",".$limit."");
  834. } else {
  835. $get_amentities = $db->getResults("*", TABLE_AMENTITIES ,"hotel_id = ".$hotelId." LIMIT ".$limit."");
  836. }
  837. if($get_amentities){
  838. foreach($get_amentities as $amentity){
  839. $return[] = array(
  840. 'id' => $amentity['id'],
  841. 'title' => htmlspecialchars_decode($amentity['title']),
  842. 'description' => htmlspecialchars_decode($amentity['description']),
  843. 'phone' => $amentity['phone'],
  844. 'worktime' => $amentity['worktime'],
  845. 'image' => $amentity['image'],
  846. 'hotel_id' => $amentity['hotel_id'],
  847. );
  848. }
  849. }else{
  850. $return[] = array(
  851. 'status' => 0,
  852. 'msg' => 'no offers'
  853. );
  854. }
  855.  
  856. print json_encode($return, JSON_PRETTY_PRINT);
  857. }
  858.  
  859. if(post('insert_notification')) { // insert an ordered romm service in the db
  860. $data = array(
  861. "room_number" => post('room_number'),
  862. "service_id" => post('service_id'),
  863. "email" => post('email'),
  864. "time" => post('time')
  865. );
  866. $insert_service = $db->insert("ordered_services", $data);
  867.  
  868. if($insert_service) {
  869. $return = array(
  870. "status" => '1'
  871. );
  872. } else {
  873. $return = array(
  874. "status" => '0'
  875. );
  876. }
  877. print json_encode($return, JSON_PRETTY_PRINT);
  878. }
  879.  
  880. if(post('submit_request')){ // submit registration
  881. $data = array(
  882. 'email' => post('email'),
  883. 'travel_stay' => post('travel_stay'),
  884. 'status' => post('status'),
  885. 'food_board' => post('food_board'),
  886. 'device_id' => post('device_id'),
  887. 'fcm_token' => post('fcm_token')
  888. );
  889. $insert = $db->insert("users_barcelo", $data);
  890.  
  891. if($insert){
  892. $return = array(
  893. 'status' => '1'
  894. );
  895. }else{
  896. $return = array(
  897. 'status' => '0'
  898. );
  899. }
  900. print json_encode($return, JSON_PRETTY_PRINT);
  901. }
  902. if(post('submit_form')){ //insert question form to database
  903. $data = array(
  904. 'name' => post('name'),
  905. 'room_no' => post('room_no'),
  906. 'question' => post('question'),
  907. 'created' => "NOW()"
  908. );
  909. $insert = $db->insert(TABLE_FORMS, $data);
  910.  
  911. if($insert){
  912. $return = array(
  913. 'status' => '1',
  914. 'res' => 'Successfully added'
  915. );
  916. }else{
  917. $return = array(
  918. 'status' => '0',
  919. 'res' => 'Something went wrong, try again'
  920. );
  921. }
  922. print json_encode($return, JSON_PRETTY_PRINT);
  923. }
  924.  
  925. if(post('request_add_review')){ // insert room/hotel review
  926. $placeId = post('place_id');
  927. $contactNo = post('email');
  928. $message = post('review_message');
  929. $rating = post('rate_count');
  930.  
  931. if(isset($placeId) && isset($contactNo) && isset($message)){
  932. $data = array(
  933. 'place_id' => $placeId,
  934. 'email' => $contactNo,
  935. 'review_message' => $message,
  936. 'rate_count' => $rating,
  937. );
  938.  
  939. $insert = $db->insert("places_reviews", $data);
  940. if($insert){
  941. $return = array(
  942. 'status' => '1',
  943. 'res' => 'success'
  944. );
  945. }else{
  946. $return = array(
  947. 'status' => '0',
  948. 'res' => 'error'
  949. );
  950. }
  951. }else{
  952. $return = array(
  953. 'status' => '0',
  954. 'res' => 'missing fields'
  955. );
  956. }
  957. print json_encode($return, JSON_PRETTY_PRINT);
  958. }
  959.  
  960. if(post('request_favorite')){ //add a place to favourites list
  961. $placeId = post('place_id');
  962. $contactNo = post('email');
  963.  
  964. if(isset($placeId) && isset($contactNo)){
  965. $data = array(
  966. 'place_id' => $placeId,
  967. 'email' => $contactNo,
  968. );
  969.  
  970. $insert = $db->insert("places_favourites", $data);
  971. if($insert){
  972. $return = array(
  973. 'status' => '1',
  974. 'res' => 'success'
  975. );
  976. }else{
  977. $return = array(
  978. 'status' => '0',
  979. 'res' => 'error'
  980. );
  981. }
  982. }else{
  983. $return = array(
  984. 'status' => '0',
  985. 'res' => 'missing fields'
  986. );
  987. }
  988. print json_encode($return, JSON_PRETTY_PRINT);
  989. }
  990.  
  991. if(post('request_want_to_go')){ // add a place to the to-go list
  992. $placeId = post('place_id');
  993. $contactNo = post('email');
  994.  
  995. if(isset($placeId) && isset($contactNo)){
  996. $data = array(
  997. 'place_id' => $placeId,
  998. 'email' => $contactNo,
  999. );
  1000.  
  1001. $insert = $db->insert("places_to_go", $data);
  1002. if($insert){
  1003. $return = array(
  1004. 'status' => '1',
  1005. 'res' => 'success'
  1006. );
  1007. }else{
  1008. $return = array(
  1009. 'status' => '0',
  1010. 'res' => 'error'
  1011. );
  1012. }
  1013. }else{
  1014. $return = array(
  1015. 'status' => '0',
  1016. 'res' => 'missing fields'
  1017. );
  1018. }
  1019. print json_encode($return, JSON_PRETTY_PRINT);
  1020. }
  1021.  
  1022. if(post('get_amentities_icons')){ // get the amentities information
  1023. $amentities = $db->getResults("id, title, description, icon, phone", TABLE_AMENTITIES);
  1024. if($amentities){
  1025. foreach($amentities as $amentity){
  1026. $return[] = array(
  1027. 'id' => $amentity['id'],
  1028. 'title' => htmlspecialchars_decode($amentity['title']),
  1029. 'description' => htmlspecialchars_decode($amentity['description']),
  1030. 'phone' => $amentity['phone'],
  1031. 'icon' => $amentity['icon'],
  1032. );
  1033. }
  1034. }else{
  1035. $return = array(
  1036. 'status' => '0',
  1037. 'res' => 'no records found'
  1038. );
  1039. }
  1040. print json_encode($return, JSON_PRETTY_PRINT);
  1041.  
  1042. }
  1043. if(post('booking_request')){ // make a booking request
  1044. $first = post('first_name');
  1045. $last = post('last_name');
  1046. $email = post('email');
  1047. $startDate = post('start_date');
  1048. $endDate = post('end_date');
  1049.  
  1050. if(isset($first) && isset($last) && isset($email) && isset($startDate) && isset($endDate)){
  1051. $name = $first . " " . $last;
  1052. $data = array(
  1053. 'name' => $name,
  1054. 'email' => $email,
  1055. 'start_date' => $startDate,
  1056. 'end_date' => $endDate,
  1057. 'room_id' => post('room_id'),
  1058. 'child_count' => post('child_count'),
  1059. 'adult_count' => post('adult_count'),
  1060. 'extra_info' => post('extra_info'),
  1061. 'phone' => post('phone'),
  1062. 'created' => "NOW()"
  1063. );
  1064. $insert = $db->insert(TABLE_BOOKING, $data);
  1065. if($insert){
  1066. $return = array(
  1067. 'status' => '1',
  1068. 'msg' => 'success'
  1069. );
  1070. }else{
  1071. $return = array(
  1072. 'status' => '0',
  1073. 'msg' => 'something went wrong, try again'
  1074. );
  1075. }
  1076. }else{
  1077. $return = array(
  1078. 'status' => '0',
  1079. 'msg' => 'missing fields'
  1080. );
  1081. }
  1082.  
  1083. print json_encode($return, JSON_PRETTY_PRINT);
  1084. }
  1085.  
  1086. if(post('get_room_details')){ //get room details
  1087. $roomId = post('get_room_details');
  1088. $roomInfo = $db->getValues("title$lang->dblang, description$lang->dblang, size, max_capacity", "objects", "id=".$roomId);
  1089. $extras = $db->getResults("*", "room_extras_href", "room_id = ".$roomId);
  1090. $images = $db->getResults("*", "objects_images", "object_id = ".$roomId);
  1091. $extrasImg = array();
  1092. $roomImg = array();
  1093. if($extras){
  1094. foreach($extras as $key => $extra){
  1095. $img = $db->getValues("id, image", TABLE_ROOM_EXTRAS, "id = ".$extra['extra_id']);
  1096. array_push($extrasImg, $img);
  1097. }
  1098. }
  1099. if($images){
  1100. foreach($images as $key => $image){
  1101. array_push($roomImg, $image);
  1102. }
  1103. }
  1104.  
  1105. if($roomInfo){
  1106. $return = array(
  1107. 'title' => $roomInfo['title'.$lang->dblang],
  1108. 'description' => $roomInfo['description'.$lang->dblang],
  1109. 'size' => $roomInfo['size'],
  1110. 'max_capacity' => $roomInfo['max_capacity'],
  1111. 'extras' => $extrasImg,
  1112. 'images' => $roomImg
  1113. );
  1114. }else{
  1115. $return = array(
  1116. 'status' => '0',
  1117. 'msg' => 'room not found'
  1118. );
  1119. }
  1120.  
  1121. print json_encode($return, JSON_PRETTY_PRINT);
  1122. }
  1123. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement