public static function getRestaurantUser($id_user)
 {
     $objRestoUser = new RestaurantUserModel();
     $arrRestoUser = $objRestoUser->getWhere("id_user='******'");
     MasterDish::checkCount($arrRestoUser);
     $exp = explode(",", str_replace(" ", "", $objRestoUser->crud_webservice_allowed));
     $sem = array();
     foreach ($arrRestoUser as $o) {
         foreach ($exp as $attr) {
             $sem[$attr] = stripslashes($o->{$attr});
         }
     }
     return $sem;
 }
 public function repositionTables()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_restaurant = isset($_POST['id_restaurant']) ? addslashes($_POST['id_restaurant']) : "";
     if (!$id_restaurant) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $jsonTables = isset($_POST['tables']) ? $_POST['tables'] : "";
     if (!$jsonTables) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $jsonArrayTables = json_decode($jsonTables);
     //        pr($jsonArrayTables);
     $countjsonArrayTables = count($jsonArrayTables);
     //        pr($countTables);
     $objResto = new MasterRestaurantModel();
     $arrResto = $objResto->getWhere("id_restaurant='{$id_restaurant}'");
     MasterDish::checkCount($arrResto);
     $countTablesinResto = $arrResto[0]->table_quantity;
     //        pr($arrResto);
     $objTable = new MasterTableModel();
     $arrTable = $objTable->getWhere("id_restaurant='{$id_restaurant}'");
     if ($countTablesinResto != $countjsonArrayTables) {
         Generic::errorMsg("Wrong Quantity");
     }
     //        $break = false;
     //        foreach ($jsonArrayTables as $key => $objTables) {
     ////
     //            $arrReposTable = $objTable->getWhere("id_restaurant='$id_restaurant' AND id_table='$objTables->table_id' ");
     //            if (count($arrReposTable) == 0) {
     //                $break = true;
     //                $msg = $msg . " $objTables->table_id can't find in database.";
     //            }
     //        }
     //        if ($break == false) {
     //            foreach ($jsonArrayTables as $key => $objTables) {
     //                $arrReposTable = $objTable->getWhere("id_restaurant='$id_restaurant' AND id_table='$objTables->table_id' ");
     ////               $arrReposTable[0]->table_position = $key + 1;
     //                $arrReposTable[0]->load = 1;
     //                $arrReposTable[0]->save();
     //            }
     //        }
     $counter = 1;
     foreach ($jsonArrayTables as $jsonObjTable) {
         $table = new MasterTableModel();
         $table->getByID($jsonObjTable->table_id);
         $table->table_position = $counter;
         $table->save();
         $counter++;
     }
     $json['status_code'] = 1;
     $json['results']['message'] = "success";
     echo json_encode($json);
     die;
 }
 public static function getOrder($id_order)
 {
     $objOrder = new MasterOrderModel();
     $arrOrder = $objOrder->getWhere("id_order = '{$id_order}' ORDER BY id_order asc");
     MasterDish::checkCount($arrOrder);
     $exp = explode(",", str_replace(" ", "", $objOrder->crud_webservice_allowed));
     $sem = array();
     foreach ($arrOrder as $o) {
         foreach ($exp as $attr) {
             $sem[$attr] = stripslashes($o->{$attr});
         }
         if ($o->id_table != 0) {
             $table = new MasterTableModel();
             $table->getByID($o->id_table);
             $sem["table_number"] = $table->table_number;
         }
     }
     return $sem;
 }
 public function restoDish()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     // fav, nearby
     $cmd = isset($_GET['cmd']) ? addslashes($_GET['cmd']) : "";
     if (!$cmd) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $distance = isset($_GET['distance']) ? addslashes($_GET['distance']) : 20;
     if (!$distance) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
     if (!$lat) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
     if (!$long) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         $json['status_code'] = 0;
         $json['status_message'] = "No Page Found";
         echo json_encode($json);
         die;
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         $json['status_code'] = 0;
         $json['status_message'] = "Limit Error";
         echo json_encode($json);
         die;
     }
     $begin = ($page - 1) * $limit;
     $objRestaurant = new MasterRestaurantModel();
     $objDish = new MasterDishModel();
     global $db;
     $q = "SELECT *,SQRT(POW(69.1 * (latitude - {$lat}), 2) + POW(69.1 * ({$long} - longitude) * COS(latitude / 57.3), 2)) AS distance\nFROM {$objRestaurant->table_name} HAVING distance < {$distance} ORDER BY distance";
     //echo $q;
     $arrResto = $db->query($q, 2);
     //        pr($arrResto);
     MasterDish::checkCount($arrResto);
     $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed));
     //tmbh untuk add photo url
     $arrPicsToAddPhotoUrl = $objRestaurant->crud_add_photourl;
     $arrPicsDishToAddPhotoUrl = $objRestaurant->crud_add_photourl;
     $json['results']['Dish'] = array();
     if ($cmd == "fav") {
         $arrDishHelp = array();
         $qdish = "SELECT {$objDish->table_name}.*, SQRT(POW(69.1 * ({$objRestaurant->table_name}.latitude - {$lat}), 2) + POW(69.1 * ({$long} - {$objRestaurant->table_name}.longitude) * COS({$objRestaurant->table_name}.latitude / 57.3), 2)) AS distance FROM {$objDish->table_name} LEFT JOIN {$objRestaurant->table_name} ON  {$objRestaurant->table_name}.id_restaurant= {$objDish->table_name}.id_restaurant HAVING distance < {$distance} ORDER BY distance, {$objDish->table_name}.fav DESC LIMIT {$begin},{$limit}";
         $arrDish = $db->query($qdish, 2);
         foreach ($arrDish as $dish) {
             $jarak = $dish->distance;
             $dish = MasterDish::getDish($dish->id_dish);
             $dish['distance'] = $jarak;
             $dish['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($dish['id_restaurant']);
             $arrDishHelp[] = $dish;
         }
         $json['results']['Dish'] = $arrDishHelp;
     } elseif ($cmd == "nearby") {
         $qdish = "SELECT objDish.*, SQRT(POW(69.1 * (objDish.latitude - {$lat}), 2) + POW(69.1 * ({$long} - objDish.longitude) * COS(objDish.latitude / 57.3), 2)) AS distance" . " FROM (SELECT menurevo__ms_dish.*, menurevo__ms_restaurant.latitude, menurevo__ms_restaurant.longitude FROM menurevo__ms_dish LEFT JOIN menurevo__ms_restaurant ON menurevo__ms_dish.id_restaurant = menurevo__ms_restaurant.id_restaurant ORDER BY menurevo__ms_dish.fav DESC)as objDish " . "GROUP BY objDish.id_restaurant HAVING distance < 20 ORDER BY distance ASC LIMIT {$begin},{$limit}";
         //            echo $qdish;
         $arrDish = $db->query($qdish, 2);
         $arrDishHelp = array();
         foreach ($arrDish as $dish) {
             $jarak = $dish->distance;
             $dish = MasterDish::getDish($dish->id_dish);
             $dish['distance'] = $jarak;
             $dish['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($dish['id_restaurant']);
             $arrDishHelp[] = $dish;
         }
         $json['results']['Dish'] = $arrDishHelp;
     }
     echo json_encode($json);
     die;
 }
 public function restoUserLogin()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $id_restaurant = isset($_POST['id_restaurant']) ? addslashes($_POST['id_restaurant']) : "";
     if (!$id_restaurant) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $pin = isset($_POST['pin']) ? addslashes($_POST['pin']) : "";
     if (!$pin) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $json = array();
     $json['status_code'] = 1;
     $objRestoUsers = new RestaurantUserModel();
     $arrRestoUsers = $objRestoUsers->getWhere("id_restaurant = '{$id_restaurant}' AND pin_password='******' AND status='1'");
     MasterDish::checkCount($arrRestoUsers);
     $sem = array();
     foreach ($arrRestoUsers as $val) {
         $sem['user'] = RestaurantUser::getRestaurantUser($val->id_user);
     }
     $json['results'] = $sem;
     echo json_encode($json);
     die;
 }
 public function getRestoTables()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_restaurant = isset($_GET['id_restaurant']) ? addslashes($_GET['id_restaurant']) : "";
     if (!$id_restaurant) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $objTable = new MasterTableModel();
     global $db;
     //        $q = "SELECT * FROM {$objTable->table_name} WHERE id_restaurant='$id_restaurant' ORDER BY table_position ASC";
     //        $arrTable = $db->query($q, 2);
     $arrTable = $objTable->getWhere("id_restaurant='{$id_restaurant}' ORDER BY table_position ASC");
     MasterDish::checkCount($arrTable);
     $exp = explode(",", str_replace(" ", "", $objTable->crud_webservice_allowed));
     //        pr($arrTable);
     $semTable = array();
     foreach ($arrTable as $table) {
         foreach ($exp as $attr) {
             $semTable[$attr] = $table->{$attr};
         }
         $json['results']['Table'][] = $semTable;
     }
     $objResto = new MasterRestaurantModel();
     $arrResto = $objResto->getWhere("id_restaurant='{$id_restaurant}'");
     MasterDish::checkCount($arrResto);
     foreach ($arrResto as $key => $index) {
         $json['results']['Table Col'] = $arrResto[$key]->table_column;
         $json['results']['Table Qty'] = $arrResto[$key]->table_quantity;
     }
     echo json_encode($json);
     die;
 }
 public static function getCategoryNameByID($id_category)
 {
     $objCategory = new MasterCategoryModel();
     $arrCat = $objCategory->getWhere("id_category='{$id_category}' LIMIT 1");
     MasterDish::checkCount($arrCat);
     //        echo $arrCat[0]->name;
     return $arrCat[0]->name;
 }