Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("_VALID_PHP", true);
- require_once("../autoload.php");
- ////////////////////////////////////////////////////////////////
- if(post('do_comment')){ // makes an api call to process the comment
- print $api->request('process_comment', false, 'json');
- }
- ////////////////////////////////////////////////////////////////
- if(post('getprice')){ //returns the price of the item
- $return = array();
- $href_ids = "";
- foreach(post('attributes') as $attribute){
- $what = 'id';
- $table = TABLE_PRODUCTS_ATTR_HREF;
- $where = 'product_id = "'.(int)post('product_id').'" AND attribute_id = "'.(int)$attribute['attribute_id'].'" AND value_id = "'.(int)$attribute['attribute_value_id'].'"';
- $result = $db->getResults($what, $table, $where);
- // $return []= $result[];
- $href_ids.=$result[0]['id'].",";
- }
- $href_ids = rtrim($href_ids, ',');
- $what = 'price';
- $table = TABLE_PRODUCTS_DATA;
- $where = 'product_id = "'.(int)post('product_id').'" AND attr_href_ids = "'.$href_ids.'"';
- $result = $db->getResults($what, $table, $where);
- print json_encode($result[0]['price'], JSON_PRETTY_PRINT);
- // print $api->request('process_comment', false, 'json');
- }
- if(post('slider_images')) { //gets slider images from the database
- $get_slider = $db->getResults("value, slide_id", "slider_layers", "type='background' LIMIT 10");
- if($get_slider){
- foreach($get_slider as $slider){
- $title = $db->getValue("title", "slider_slides", "id = ".$slider['slide_id']);
- $return[] = array(
- 'value' => $slider['value'],
- 'title' => $title
- );
- }
- }else{
- $return = array(
- 'status' => 0,
- 'res' => 'no images'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('gallery')) { //gets gallery images from the database
- $limit = post('gallery');
- $start = post('start');
- if(post('start')) {
- $get_images = $db->getResults("id,image", "gallery" ,"id != 0 LIMIT ".$start.",".$limit."");
- } else {
- $get_images = $db->getResults("id,image", "gallery" ,"id != 0 LIMIT ".$limit."");
- }
- print json_encode($get_images, JSON_PRETTY_PRINT);
- }
- if(post('get_rooms')) { // gets post('get_rooms') number of rooms with pagination
- $limit = post('get_rooms');
- $start = post('start');
- if(post('start')) {
- $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."");
- } else {
- $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."");
- }
- foreach($get_rooms as $key => $room) {
- $image = $db->getResults("*", 'objects_images',"object_id='".$room['id']."' ORDER BY id DESC LIMIT 1");
- $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']
- );
- }
- print json_encode($rooms, JSON_PRETTY_PRINT);
- }
- if(post('get_places')) { // gets post('get_places') number of places with pagination
- $limit = post('get_places');
- $start = post('start');
- if(post('start')) {
- $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."");
- } else {
- $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."");
- }
- foreach($get_rooms as $key => $room) {
- $image = $db->getResults("*", 'objects_images',"object_id='".$room['id']."' ORDER BY id DESC");
- $likes = $db->getValue("COUNT(id)", "places_favourites", "place_id = ".$room['id']);
- $onestar = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 1 AND place_id = ".$room['id']);
- $twoostars = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 2 AND place_id = ".$room['id']);
- $threestars = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 3 AND place_id = ".$room['id']);
- $fourstars = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 4 AND place_id = ".$room['id']);
- $fivestars = $db->getValue("COUNT(id)", "places_reviews", "rate_count = 5 AND place_id = ".$room['id']);
- $total = $db->getValue("COUNT(id)", "places_reviews", "place_id = ".$room['id']);
- $reviews = $db->getResults("user_name, review_message, rate_count", "places_reviews", "place_id = ".$room['id']." LIMIT 5");
- if(!$total){
- $totalCount = 1;
- }else{
- $totalCount = $total;
- }
- if(!$reviews){
- $reviews = array();
- }
- $average = ($onestar*1 + $twoostars*2 + $threestars*3 + $fourstars*4 + $fivestars*5)/$totalCount;
- $rooms[] = array(
- 'id' => $room['id'],
- 'title' => $room['title'],
- 'location' => $room['address'],
- 'worktime' => $room['worktime'],
- 'phone' => $room['phone'],
- 'lat' => $room['lat'],
- 'lng' => $room['lng'],
- 'image' => $image,
- 'visiter_count' => $room['views'],
- 'like_count' => $likes,
- 'one_star' => $onestar,
- 'two_stars' => $twoostars,
- 'three_stars' => $threestars,
- 'four_stars' => $fourstars,
- 'five_stars' => $fivestars,
- 'total_rate_count' => $total,
- 'average_rate_count' => $average,
- 'reviews' => $reviews,
- );
- }
- print json_encode($rooms, JSON_PRETTY_PRINT);
- }
- if(post('reset_password') && !empty(post('reset_password'))) { //resets the password and sends it back to email
- global $db, $core;
- $msgs = array();
- $return = array();
- if (empty(post('email'))) {
- $msgs['[name="email"]'] = _USERS_ERROR_EMAIL;
- }
- if (!isValidEmail(post('email'))){
- $msgs['[name="email"]'] = _USERS_ERROR_EMAIL_INVALID;
- }
- if (!emailExists(post('email'))){
- $msgs['[name="email"]'] = 'Email акаунта не се ползва от нито един потребител.';
- }
- if (empty($msgs)){
- $rand = rand(1000000, 9999999);
- $data = array(
- 'forgot_password' => $rand,
- );
- $email = sanitize(post('email'));
- $db->update(TABLE_USERS, $data, "email='".$email."'");
- include(BASEPATH . API_DIR . PLUGINS_DIR. "Phpmailer/PHPMailerAutoload.php");
- $mail = new PHPMailer();
- $to = sanitize(post('email'));
- $mail->IsHTML(true);
- $mail->CharSet = 'UTF-8';
- $mail->From = $core->site_email;
- $mail->FromName = $core->site_name;
- $mail->AddAddress($to);
- $mail->AddReplyTo('no-reply@vsichkotok.bg', 'VsichkoTok');
- $mail->Subject = $core->site_name.' - Забравена парола';
- $link = '';
- if($core->site_id == '1'){
- $link = 'http://vsichkotok.bg/index/29-nova-parola.html?forgot_password='.$rand.'';
- }
- if($core->site_id == '3'){
- $link = 'http://elektromobili.bg/new-password/34-nova-parola.html?forgot_password='.$rand.'';
- }
- $mail->Body = 'Вие направихте заявка за нулиране на паролата. <a href="'.$link.'">Кликнете тук за да въведете своята нова парола.</a>';
- if($mail->Send()) {
- $return = array(
- 'status' => 1,
- );
- }else {
- $return = array(
- 'status' => 0,
- );
- }
- }else {
- $return = array(
- 'status' => 0,
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('login') && !empty(post('login'))) { // user login
- global $db, $core, $user;
- $msgs = array();
- $return = array();
- if (post('email') == ""){
- $msgs['email_empty'] = _USERS_ERROR_EMAIL;
- } elseif (post('password') == "") {
- $msgs['password_empty'] = _USERS_ERROR_PASSWORD;
- } else {
- $status = $user->check_user_status(get('email'), post('password'));
- switch ($status) {
- case 0:
- $msgs['email_password'] = _USERS_ERROR_EMAIL_PASSWORD;
- break;
- case 1:
- $msgs['acc_actived'] = _USERS_ERROR_ACC_ACTIVED;
- break;
- }
- }
- if (empty($msgs)&& $status==2) {
- if(post('is_mobile') && post('is_mobile') == 1){
- $return = array(
- 'status' => 1,
- );
- } else {
- $return = array(
- 'status' => 1,
- );
- }
- } else {
- if(post('is_mobile') && post('is_mobile') == 1){
- $return = array(
- 'status' => 0,
- );
- } else {
- $return = array(
- 'status' => 0,
- );
- }
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_user_info') && post('get_user_info') != 0){ //gets user information where email = post('email')
- global $db, $core, $user;
- $email = sanitize(post('email'));
- $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 . "'";
- $row = $db->first($sql);
- if($row['address']){
- $row['address'] = cleanOut($row['address']);
- }
- if (!$email)
- return false;
- print json_encode($row, JSON_PRETTY_PRINT);
- }
- if(post('update_object_views')) { //increaases the object views
- $object = post('update_object_views');
- $oldviews = $db->getValue('views', TABLE_OBJECTS, "id='".$object."'");
- $new_views = $oldviews+1;
- $views = array(
- 'views' => $new_views
- );
- $update = $db->update(TABLE_OBJECTS, $views, "id='".$object."'");
- if($update) {
- $response = array(
- 'res' => '1',
- 'views' => $new_views
- );
- } else {
- $response = array(
- 'res' => '0',
- 'views' => $new_views
- );
- }
- print json_encode($response, JSON_PRETTY_PRINT);
- }
- if(post('register')) { //registration function
- $msgs = array();
- $return = array();
- if (empty(post('first_name'))) {
- $msgs['[name="first_name"]'] = _USERS_ERROR_FIRST_NAME;
- }
- if (empty(post('last_name'))) {
- $msgs['[name="last_name"]'] = _USERS_ERROR_LAST_NAME;
- }
- if (empty(post('email'))) {
- $msgs['[name="email"]'] = _USERS_ERROR_EMAIL;
- }
- if (!isValidEmail(post('email')))
- $msgs['[name="email"]'] = _USERS_ERROR_EMAIL_INVALID;
- if (emailExists(post('email')))
- $msgs['[name="email"]'] = _USERS_ERROR_EMAIL_TAKEN;
- if (empty(post('password')))
- $msgs['[name="password"]'] = _USERS_ERROR_PASSWORD;
- if (strlen(post('password')) < 6)
- $msgs['[name="password"]'] = str_replace("<%n%>", "6", _USERS_ERROR_PASSWORD_LENGHT);
- if (empty($msgs)){
- $data = array(
- 'email' => sanitize(post('email')),
- 'first_name' => sanitize(post('first_name')),
- 'last_name' => sanitize(post('last_name')),
- 'phone' => sanitize(post('phone')),
- 'interest' => sanitize(post('interest')),
- 'active' => '1',
- );
- if (post('password') != "") {
- $data['password'] = md5(post('password'));
- }
- $db->insert(TABLE_USERS, $data);
- $message = _USERS_SUCCESS_INSERT;
- if ($db->affected()){
- $return = array(
- 'status' => 1,
- 'msg' => $message,
- );
- }
- } else {
- $return = array(
- 'status' => 0,
- 'error_fields' => $msgs,
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_room_service')){ //get the available room services
- $limit = post('get_room_service');
- $start = post('start');
- if(post('start')) {
- $get_room_service = $db->getResults("*", TABLE_SERVICES ,"id != 0 LIMIT ".$start.",".$limit."");
- } else {
- $get_room_service = $db->getResults("*", TABLE_SERVICES ,"id != 0 LIMIT ".$limit."");
- }
- if($get_room_service){
- foreach($get_room_service as $key => $service) {
- $services[] = array(
- 'id' => $service['id'],
- 'title' => $service['title'],
- 'image' => $service['image'],
- 'description' => $service['description']
- );
- }
- }else{
- $services = array(
- 'status' => 0,
- 'msg' => 'no services'
- );
- }
- print json_encode($services, JSON_PRETTY_PRINT);
- }
- if(post('get_extras')){ //get the available room extras
- $limit = post('get_extras');
- $start = post('start');
- if(post('start')) {
- $get_extras = $db->getResults("*", TABLE_ROOM_EXTRAS ,"id != 0 LIMIT ".$start.",".$limit."");
- } else {
- $get_extras = $db->getResults("*", TABLE_ROOM_EXTRAS ,"id != 0 LIMIT ".$limit."");
- }
- if($get_extras){
- foreach($get_extras as $key => $extra) {
- $extras[] = array(
- 'id' => $extra['id'],
- 'title' => $extra['title'],
- 'body' => $extra['body'],
- 'icon' => $extra['image']
- );
- }
- }else{
- $extras = array(
- 'status' => 0,
- 'msg' => 'no extras'
- );
- }
- print json_encode($extras, JSON_PRETTY_PRINT);
- }
- if(post('get_comments')){ // get 5 top rated commments where rating > 1
- $get_comments = $db->getResults("*", TABLE_COMMENTS, "rating > 1 ORDER BY rating DESC LIMIT 5");
- if($get_comments){
- foreach($get_comments as $key => $comment){
- if($comment['hotel_id'] != '0'){
- $user = $comment['username'];
- $query = $db->getValues('city_id, country_id, name', TABLE_HOTELS, "id='".$comment['hotel_id']."'");
- $city = $db->getValue("title", TABLE_CITIES, "id = '".$query['city_id']."'");
- $country = $db->getValue("title", TABLE_COUNTRIES, "id = '".$query['country_id']."'");
- $commentText = $comment['comment'];
- $rating = $comment['rating'];
- $location = $city. ', ' . $country;
- $result[] = array(
- 'username' => $user,
- 'location' => $location,
- 'hotel_name' => $query['name'],
- 'comment' => $commentText,
- 'rating' => $rating
- );
- }
- }
- }else{
- $result = array(
- 'status' => 0,
- 'msg' => 'no comments'
- );
- }
- print json_encode($result, JSON_PRETTY_PRINT);
- }
- if(post('get_total_reviews')){ //get the number of 5 star reviewws
- $count = 0;
- $reviews = $db->getResults("rating", TABLE_COMMENTS);
- if($reviews){
- foreach($reviews as $review){
- if($review['rating'] == '5'){
- $count++;
- }
- }
- $return = array(
- 'count' => $count
- );
- }else{
- $return = array(
- 'count' => 0
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_special_offers')){ // get the room special offers
- $limit = post('get_special_offers');
- $start = post('start');
- if(post('start')) {
- $get_offers = $db->getResults("*", TABLE_SPECIAL_OFFERS ,"id != 0 LIMIT ".$start.",".$limit."");
- } else {
- $get_offers = $db->getResults("*", TABLE_SPECIAL_OFFERS ,"id != 0 LIMIT ".$limit."");
- }
- if($get_offers){
- foreach($get_offers as $offer){
- $image = $db->getResults("id,image", TABLE_SPECIAL_OFFERS, "id = ".$offer['id']);
- $country = $db->getValue("title", TABLE_COUNTRIES, "id = ".$offer['country_id']);
- $city = $db->getValue("title", TABLE_CITIES, "id = ".$offer['city_id']);
- $discount = (1 - ($offer['promo_price']/$offer['price']))*100;
- $discount = round($discount);
- $return[] = array(
- 'id' => $offer['id'],
- 'title' => $offer['title'],
- 'description' => $offer['description'],
- 'price' => $offer['price']." lv",
- 'promo_price' => $offer['promo_price']." lv",
- 'discount' => $discount,
- 'image' => $image,
- 'country' => $country,
- 'city' => $city
- );
- }
- }else{
- $return[] = array(
- 'status' => 0,
- 'msg' => 'no offers'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_countries')){ // get all the countries from the db
- $get_countries = $db->getResults("*", TABLE_HOTELS);
- $return = array();
- if($get_countries){
- foreach($get_countries as $country){
- $countryName = $db->getValue("title", TABLE_COUNTRIES, "id = ".$country['country_id']);
- $count = $db->getValue("COUNT(id)", TABLE_HOTELS, "country_id = '".$country['country_id']."'");
- $return[] = array(
- 'country_id' => $country['country_id'],
- 'name' => $countryName,
- 'hotels_count' => $count
- );
- }
- }else{
- $return[] = array(
- 'status' => 0,
- 'msg' => 'no offers'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_hotels_by_country')){ // get all the hotels in a given country
- $country_id = post('get_hotels_by_country');
- $countries = $db->getResults("*", TABLE_HOTELS, "country_id = ".$country_id);
- $hotelsByCity = array();
- $i=0;
- foreach($countries as $key=>$country){
- $cityName = $db->getValue("title", TABLE_CITIES, "id = ".$country['city_id']);
- $countryName = $db->getValue("title", TABLE_COUNTRIES, "id = ".$country['country_id']);
- $hotelsByCity[$cityName][] = array(
- 'id' => $country['id'],
- 'name' => $country['name'],
- 'countryId' => $country['country_id'],
- 'image' => $country['image'],
- 'cityId' => $country['city_id'],
- 'cityName' => $cityName,
- 'countryName' => $countryName
- );
- $i++;
- }
- print json_encode($hotelsByCity, JSON_PRETTY_PRINT);
- }
- if(post('get_hotels_by_city')){ // get all hotels by city
- $city_id = post('get_hotels_by_city');
- $countries = $db->getResults("*", TABLE_HOTELS, "city_id = ".$city_id);
- $hotelsByCity = array();
- foreach($countries as $country){
- $cityName = $db->getValue("title", TABLE_CITIES, "id = ".$country['city_id']);
- $countryName = $db->getValue("title", TABLE_COUNTRIES, "id = ".$country['country_id']);
- $hotelsByCity[] = array(
- 'id' => $country['id'],
- 'name' => $country['name'],
- 'image' => $country['image'],
- 'cityName' => $cityName,
- 'countryName' => $countryName
- );
- }
- print json_encode($hotelsByCity, JSON_PRETTY_PRINT);
- }
- if(post('get_transport')){ // get all the transport units - bus, taxi etc
- $transport = $db->getResults("*", TABLE_TRANSPORT);
- $transportArr = array();
- foreach($transport as $single){
- $images = $db->getResults("transport_id, image", "transportation_image", "transport_id =".$single['id']);
- $transportArr[] = array(
- 'id' => $single['id'],
- 'title' => $single['title'],
- 'description' => $single['description'],
- 'image' => $images,
- 'price' => $single['price'],
- 'phone' => $single['phone'],
- 'hotel_id' => $single['hotel_id']
- );
- }
- print json_encode($transportArr, JSON_PRETTY_PRINT);
- }
- // API for each hotel
- if(post('get_room_service_hotel')){ // get the available room services for each hotel
- $hotelId = post('hotel_id');
- $limit = post('get_room_service_hotel');
- $start = post('start');
- if(post('start')) {
- $get_room_service = $db->getResults("*", TABLE_SERVICES ,"hotel_id = ".$hotelId." LIMIT ".$start.",".$limit."");
- } else {
- $get_room_service = $db->getResults("*", TABLE_SERVICES ,"hotel_id = ".$hotelId." LIMIT ".$limit."");
- }
- if($get_room_service){
- foreach($get_room_service as $key => $service) {
- $services[] = array(
- 'id' => $service['id'],
- 'title' => $service['title'],
- 'image' => $service['image'],
- 'description' => $service['description']
- );
- }
- }else{
- $services = array(
- 'status' => 0,
- 'msg' => 'no services'
- );
- }
- print json_encode($services, JSON_PRETTY_PRINT);
- }
- if(post('get_special_offers_hotel')){ // get special offers for each hotel
- $limit = post('get_special_offers_hotel');
- $start = post('start');
- $hotelId = post('hotel_id');
- if(post('start')) {
- $get_offers = $db->getResults("*", TABLE_SPECIAL_OFFERS ,"hotel_id = ".$hotelId." LIMIT ".$start.",".$limit."");
- } else {
- $get_offers = $db->getResults("*", TABLE_SPECIAL_OFFERS ,"hotel_id = ".$hotelId." LIMIT ".$limit."");
- }
- if($get_offers){
- foreach($get_offers as $offer){
- $country = $db->getValue("title", TABLE_COUNTRIES, "id = ".$offer['country_id']);
- $city = $db->getValue("title", TABLE_CITIES, "id = ".$offer['city_id']);
- $return[] = array(
- 'id' => $offer['id'],
- 'title' => $offer['title'],
- 'price' => $offer['price'],
- 'promo_price' => $offer['promo_price'],
- 'image' => $offer['image'],
- 'country' => $country,
- 'city' => $city
- );
- }
- }else{
- $return[] = array(
- 'status' => 0,
- 'msg' => 'no offers'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_extras_hotel')){ //get extras for each hotel
- $limit = post('get_extras_hotel');
- $start = post('start');
- $hotelId = post('hotel_id');
- if(post('start')) {
- $get_extras = $db->getResults("*", TABLE_ROOM_EXTRAS ,"hotel_id = ".$hotelId." LIMIT ".$start.",".$limit."");
- } else {
- $get_extras = $db->getResults("*", TABLE_ROOM_EXTRAS ,"hotel_id = ".$hotelId." LIMIT ".$limit."");
- }
- if($get_extras){
- foreach($get_extras as $key => $extra) {
- $extras[] = array(
- 'id' => $extra['id'],
- 'title' => $extra['title'],
- 'body' => $extra['body'],
- 'image' => $extra['image']
- );
- }
- }else{
- $extras = array(
- 'status' => 0,
- 'msg' => 'no extras'
- );
- }
- print json_encode($extras, JSON_PRETTY_PRINT);
- }
- if(post('get_rooms_hotel')) { //get rooms for each hotel
- $limit = post('get_rooms_hotel');
- $start = post('start');
- $hotelId = post('hotel_id');
- if(post('start')) {
- $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."");
- } else {
- $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."");
- }
- foreach($get_rooms as $key => $room) {
- $image = $db->getResults("*", 'objects_images', "id='" . $room['id'] . "' ORDER BY id DESC LIMIT 1");
- $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']);
- }
- print json_encode($rooms, JSON_PRETTY_PRINT);
- }
- if(post('get_hotel_details')){ // get all the hotel info
- $hotelId = post('get_hotel_details');
- //hotel name
- $hotel = $db->getResults("*", TABLE_HOTELS, "id = ".$hotelId);
- //review count
- $reviews = $db->getValue("COUNT(id)", TABLE_COMMENTS, "hotel_id = ".$hotelId);
- //special offers
- $offers = $db->getResults("*", TABLE_SPECIAL_OFFERS, "hotel_id = ".$hotelId);
- //rooms
- $rooms = $db->getResults("id, title{$lang->dblang}, description{$lang->dblang}, price, size, max_capacity", TABLE_OBJECTS, "cid = '1' AND hotel_id =".$hotelId);
- $extras = $db->getResults("id, image", TABLE_ROOM_EXTRAS, "hotel_id = ".$hotelId);
- //galery
- $gallery = $db->getResults("*", "gallery", "hotel_id = ".$hotelId);
- //todo facilities
- $amentities = $db->getResults("*", TABLE_AMENTITIES, "hotel_id =".$hotelId);
- //reviews
- $comments = $db->getResults("*", TABLE_COMMENTS, "hotel_id = ".$hotelId);
- $return['0'] = array(
- 'hotel_type' => $hotel[0]['name'],
- 'total_users' => $reviews,
- );
- if(is_array($offers)){
- foreach($offers as $offer){
- $return['0']['packages'][] = array(
- 'id' => $offer['id'],
- 'title' => $offer['title'],
- 'description' => $offer['description'],
- 'image' => $offer['image'],
- );
- }
- }
- if(is_array($rooms)){
- foreach($rooms as $key => $room){
- $image = $db->getResults("*", 'objects_images',"object_id='".$room['id']."' ORDER BY id DESC LIMIT 1");
- $return['0']['room_and_price'][$key] = array(
- 'id' => $room['id'],
- 'room_name' => $room['title_en'],
- 'price' => $room['price'],
- 'description' => $room['description_en'],
- 'image' => $image[0]['image'],
- 'room_size' => $room['size'],
- 'room_capacity' => $room['max_capacity']
- );
- if(is_array($extras)){
- foreach($extras as $key1 => $extra){
- $return['0']['room_and_price'][$key]['room_extras'][$key1] = array(
- 'id' => $extra['id'],
- 'image' => $extra['image']
- );
- }
- }
- }
- }
- if(is_array($gallery)){
- foreach($gallery as $single){
- $return['0']['gallery'][] = array(
- 'id' => $single['id'],
- 'gallery' => $single['image']
- );
- }
- }
- if(is_array($amentities)){
- foreach($amentities as $amentity){
- $images = $db->getValue("image", "amentities_images", "a_id = ".$amentity['id']);
- $return['0']['facilities_and_services'][] = array(
- 'id' => $amentity['id'],
- 'title' => htmlspecialchars_decode($amentity['title']),
- 'description' => htmlspecialchars_decode($amentity['description']),
- 'phone' => $amentity['phone'],
- 'worktime' => $amentity['worktime'],
- 'image' => $images
- );
- }
- }
- if(is_array($comments)){
- foreach($comments as $comment){
- $username = $db->getValues("first_name, last_name", TABLE_USERS, "id = ".$comment['user_id']);
- $name = $username['first_name'] . " " . $username['last_name'];
- $hotel = $db->getValue("name", TABLE_HOTELS, "id = ".$hotelId);
- $return['0']['reviews'][] = array(
- 'id' => $comment['id'],
- 'name' => $name,
- 'comment' => $comment['comment'],
- 'hotel_name' => $hotel
- );
- }
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_amentities')){ // get hotel amentities
- $limit = post('get_amentities');
- $start = post('start');
- if(post('start')) {
- $get_amentities = $db->getResults("*", TABLE_AMENTITIES ,"id != 0 LIMIT ".$start.",".$limit."");
- } else {
- $get_amentities = $db->getResults("*", TABLE_AMENTITIES ,"id != 0 LIMIT ".$limit."");
- }
- if($get_amentities){
- foreach($get_amentities as $amentity){
- $images = $db->getResults("a_id, image", "amentities_images", "a_id = ".$amentity['id']);
- $return[] = array(
- 'id' => $amentity['id'],
- 'title' => htmlspecialchars_decode($amentity['title']),
- 'description' => htmlspecialchars_decode($amentity['description']),
- 'phone' => $amentity['phone'],
- 'worktime' => $amentity['worktime'],
- 'image' => $images,
- 'hotel_id' => $amentity['hotel_id'],
- );
- }
- }else{
- $return[] = array(
- 'status' => 0,
- 'msg' => 'no offers'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_amentities_hotel')){ //get amentities for each hotel
- $limit = post('get_amentities_hotel');
- $start = post('start');
- $hotelId = post('hotel_id');
- if(post('start')) {
- $get_amentities = $db->getResults("*", TABLE_AMENTITIES ,"hotel_id = ".$hotelId." LIMIT ".$start.",".$limit."");
- } else {
- $get_amentities = $db->getResults("*", TABLE_AMENTITIES ,"hotel_id = ".$hotelId." LIMIT ".$limit."");
- }
- if($get_amentities){
- foreach($get_amentities as $amentity){
- $return[] = array(
- 'id' => $amentity['id'],
- 'title' => htmlspecialchars_decode($amentity['title']),
- 'description' => htmlspecialchars_decode($amentity['description']),
- 'phone' => $amentity['phone'],
- 'worktime' => $amentity['worktime'],
- 'image' => $amentity['image'],
- 'hotel_id' => $amentity['hotel_id'],
- );
- }
- }else{
- $return[] = array(
- 'status' => 0,
- 'msg' => 'no offers'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('insert_notification')) { // insert an ordered romm service in the db
- $data = array(
- "room_number" => post('room_number'),
- "service_id" => post('service_id'),
- "email" => post('email'),
- "time" => post('time')
- );
- $insert_service = $db->insert("ordered_services", $data);
- if($insert_service) {
- $return = array(
- "status" => '1'
- );
- } else {
- $return = array(
- "status" => '0'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('submit_request')){ // submit registration
- $data = array(
- 'email' => post('email'),
- 'travel_stay' => post('travel_stay'),
- 'status' => post('status'),
- 'food_board' => post('food_board'),
- 'device_id' => post('device_id'),
- 'fcm_token' => post('fcm_token')
- );
- $insert = $db->insert("users_barcelo", $data);
- if($insert){
- $return = array(
- 'status' => '1'
- );
- }else{
- $return = array(
- 'status' => '0'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('submit_form')){ //insert question form to database
- $data = array(
- 'name' => post('name'),
- 'room_no' => post('room_no'),
- 'question' => post('question'),
- 'created' => "NOW()"
- );
- $insert = $db->insert(TABLE_FORMS, $data);
- if($insert){
- $return = array(
- 'status' => '1',
- 'res' => 'Successfully added'
- );
- }else{
- $return = array(
- 'status' => '0',
- 'res' => 'Something went wrong, try again'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('request_add_review')){ // insert room/hotel review
- $placeId = post('place_id');
- $contactNo = post('email');
- $message = post('review_message');
- $rating = post('rate_count');
- if(isset($placeId) && isset($contactNo) && isset($message)){
- $data = array(
- 'place_id' => $placeId,
- 'email' => $contactNo,
- 'review_message' => $message,
- 'rate_count' => $rating,
- );
- $insert = $db->insert("places_reviews", $data);
- if($insert){
- $return = array(
- 'status' => '1',
- 'res' => 'success'
- );
- }else{
- $return = array(
- 'status' => '0',
- 'res' => 'error'
- );
- }
- }else{
- $return = array(
- 'status' => '0',
- 'res' => 'missing fields'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('request_favorite')){ //add a place to favourites list
- $placeId = post('place_id');
- $contactNo = post('email');
- if(isset($placeId) && isset($contactNo)){
- $data = array(
- 'place_id' => $placeId,
- 'email' => $contactNo,
- );
- $insert = $db->insert("places_favourites", $data);
- if($insert){
- $return = array(
- 'status' => '1',
- 'res' => 'success'
- );
- }else{
- $return = array(
- 'status' => '0',
- 'res' => 'error'
- );
- }
- }else{
- $return = array(
- 'status' => '0',
- 'res' => 'missing fields'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('request_want_to_go')){ // add a place to the to-go list
- $placeId = post('place_id');
- $contactNo = post('email');
- if(isset($placeId) && isset($contactNo)){
- $data = array(
- 'place_id' => $placeId,
- 'email' => $contactNo,
- );
- $insert = $db->insert("places_to_go", $data);
- if($insert){
- $return = array(
- 'status' => '1',
- 'res' => 'success'
- );
- }else{
- $return = array(
- 'status' => '0',
- 'res' => 'error'
- );
- }
- }else{
- $return = array(
- 'status' => '0',
- 'res' => 'missing fields'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_amentities_icons')){ // get the amentities information
- $amentities = $db->getResults("id, title, description, icon, phone", TABLE_AMENTITIES);
- if($amentities){
- foreach($amentities as $amentity){
- $return[] = array(
- 'id' => $amentity['id'],
- 'title' => htmlspecialchars_decode($amentity['title']),
- 'description' => htmlspecialchars_decode($amentity['description']),
- 'phone' => $amentity['phone'],
- 'icon' => $amentity['icon'],
- );
- }
- }else{
- $return = array(
- 'status' => '0',
- 'res' => 'no records found'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('booking_request')){ // make a booking request
- $first = post('first_name');
- $last = post('last_name');
- $email = post('email');
- $startDate = post('start_date');
- $endDate = post('end_date');
- if(isset($first) && isset($last) && isset($email) && isset($startDate) && isset($endDate)){
- $name = $first . " " . $last;
- $data = array(
- 'name' => $name,
- 'email' => $email,
- 'start_date' => $startDate,
- 'end_date' => $endDate,
- 'room_id' => post('room_id'),
- 'child_count' => post('child_count'),
- 'adult_count' => post('adult_count'),
- 'extra_info' => post('extra_info'),
- 'phone' => post('phone'),
- 'created' => "NOW()"
- );
- $insert = $db->insert(TABLE_BOOKING, $data);
- if($insert){
- $return = array(
- 'status' => '1',
- 'msg' => 'success'
- );
- }else{
- $return = array(
- 'status' => '0',
- 'msg' => 'something went wrong, try again'
- );
- }
- }else{
- $return = array(
- 'status' => '0',
- 'msg' => 'missing fields'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- if(post('get_room_details')){ //get room details
- $roomId = post('get_room_details');
- $roomInfo = $db->getValues("title$lang->dblang, description$lang->dblang, size, max_capacity", "objects", "id=".$roomId);
- $extras = $db->getResults("*", "room_extras_href", "room_id = ".$roomId);
- $images = $db->getResults("*", "objects_images", "object_id = ".$roomId);
- $extrasImg = array();
- $roomImg = array();
- if($extras){
- foreach($extras as $key => $extra){
- $img = $db->getValues("id, image", TABLE_ROOM_EXTRAS, "id = ".$extra['extra_id']);
- array_push($extrasImg, $img);
- }
- }
- if($images){
- foreach($images as $key => $image){
- array_push($roomImg, $image);
- }
- }
- if($roomInfo){
- $return = array(
- 'title' => $roomInfo['title'.$lang->dblang],
- 'description' => $roomInfo['description'.$lang->dblang],
- 'size' => $roomInfo['size'],
- 'max_capacity' => $roomInfo['max_capacity'],
- 'extras' => $extrasImg,
- 'images' => $roomImg
- );
- }else{
- $return = array(
- 'status' => '0',
- 'msg' => 'room not found'
- );
- }
- print json_encode($return, JSON_PRETTY_PRINT);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement