public function loadHome()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $cmd = Generic::mustCheck($_GET['cmd'], "No CMD Found");
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         $page = 1;
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         $limit = 10;
     }
     $begin = ($page - 1) * $limit;
     $json = array();
     $sem = array();
     $json['status_code'] = 1;
     if ($cmd == "fav" || $cmd == "nearby") {
         global $db;
         $objRestaurant = new MasterRestaurantModel();
         $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed));
         $arrPicsToAddPhotoUrl = $objRestaurant->crud_add_photourl;
         $currentLat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
         if (!$currentLat) {
             Generic::errorMsg("No Lat");
         }
         $currentLong = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
         if (!$currentLong) {
             Generic::errorMsg("No Long");
         }
         if ($cmd == "fav") {
             //                $arr = $objRestaurant->getOrderBy("fav DESC  LIMIT $begin,$limit", "*");
             $q = "SELECT *, SQRT(POW(69.1 * (latitude - {$currentLat}), 2) + POW(69.1 * ({$currentLong} - longitude) * COS(latitude / 57.3), 2)) AS distance FROM {$objRestaurant->table_name} WHERE show_in_apps='1' HAVING distance < 1000000 ORDER by fav DESC, DISTANCE ASC  LIMIT {$begin},{$limit}";
             //                echo $q;
             $arr = $db->query($q, 2);
         } elseif ($cmd == "nearby") {
             $q = "SELECT *, SQRT(POW(69.1 * (latitude - {$currentLat}), 2) + POW(69.1 * ({$currentLong} - longitude) * COS(latitude / 57.3), 2)) AS distance FROM {$objRestaurant->table_name} WHERE show_in_apps='1' HAVING distance < 1000000 ORDER by DISTANCE ASC  LIMIT {$begin},{$limit}";
             $arr = $db->query($q, 2);
             if (count($arr) == 0) {
                 Generic::errorMsg("No Count");
                 die;
             }
         }
     } elseif ($cmd == "recommendation") {
         $objRecommendation = new RecommendationModel();
         $exp = explode(",", str_replace(" ", "", $objRecommendation->crud_webservice_allowed));
         $arrPicsToAddPhotoUrl = $objRecommendation->crud_add_photourl;
         $arr = $objRecommendation->getWhere("show_in_apps='1' AND DATE(end) >= DATE(NOW()) AND DATE(start)<= DATE(NOW())  LIMIT {$begin},{$limit}");
         if (count($arr) == 0) {
             $json['status_code'] = 0;
             $json['status_message'] = "No ID Found";
             echo json_encode($json);
             die;
         }
     } else {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $json["results"]['restaurant'] = array();
     foreach ($arr as $o) {
         foreach ($exp as $attr) {
             if (in_array($attr, $arrPicsToAddPhotoUrl)) {
                 $sem[$attr] = Generic::insertImageUrl($o->{$attr});
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
             $sem['disc_mr'] = MasterOrder::getDiscountMR($o->id_restaurant);
         }
         if ($cmd == "fav" || $cmd == "nearby") {
             $sem["distance"] = sqrt(pow(69.09999999999999 * ($o->latitude - $currentLat), 2) + pow(69.09999999999999 * ($currentLong - $o->longitude) * cos($o->latitude / 57.3), 2));
         }
         if ($cmd == "recommendation") {
             $sem['restaurant'] = User::getRestaurant($o->id_restaurant);
         }
         $json["results"]['restaurant'][] = $sem;
     }
     echo json_encode($json);
     die;
 }
 public function loadHomeRecommendation()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         Generic::errorMsg("No Page Found");
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         Generic::errorMsg("Limit Error");
     }
     $begin = ($page - 1) * $limit;
     $json = array();
     $sem = array();
     $objRecommendation = new RecommendationModel();
     $exp = explode(",", str_replace(" ", "", $objRecommendation->crud_webservice_allowed));
     $arrPicsToAddPhotoUrl = $objRecommendation->crud_add_photourl;
     $arr = $objRecommendation->getWhere("DATE(end) >= DATE(NOW()) AND DATE(start)<= DATE(NOW())  LIMIT {$begin},{$limit}");
     if (count($arr) == 0) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $json["results"]['restaurant'] = array();
     foreach ($arr as $o) {
         foreach ($exp as $attr) {
             if (in_array($attr, $arrPicsToAddPhotoUrl)) {
                 $sem[$attr] = Generic::insertImageUrl($o->{$attr});
             } elseif ($attr == "time_open" || $attr == "time_close") {
                 $sem[$attr] = date('H:i', strtotime(stripslashes($o->{$attr})));
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
             $sem['disc_mr'] = MasterOrder::getDiscountMR($o->id_restaurant);
         }
         $sem['restaurant'] = User::getRestaurant($o->id_restaurant);
         $json["results"]['restaurant'][] = $sem;
     }
     echo json_encode($json);
     die;
 }