public function getRestoInitData()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $rid = $_GET['id_restaurant'];
     if (!isset($rid) || $rid == null) {
         Generic::errorMsg("Restaurant ID Not Found");
     }
     $resto = new MasterRestaurantModel();
     $resto->getByID($rid);
     $r["id_restaurant"] = $resto->id_restaurant;
     $r["name"] = $resto->name;
     $r["address"] = $resto->address;
     $r["district"] = $resto->district;
     $r["city"] = $resto->city;
     $r["email"] = $resto->email;
     $r["phone_no"] = $resto->phone_no;
     $r["time_open"] = date("H:i", strtotime($resto->time_open));
     $r["time_close"] = date("H:i", strtotime($resto->time_close));
     $r["image_logo"] = trim($resto->image_logo) != "" ? _BPATH . "uploads/" . $resto->image_logo : "";
     $r["restaurant_type"] = $resto->restaurant_type;
     $r["id_cuisine"] = $resto->id_cuisine;
     $r["halal"] = $resto->halal;
     $r["latitude"] = $resto->latitude;
     $r["longitude"] = $resto->longitude;
     $rawTags = array();
     $tagsIds = explode(",", $resto->restaurant_tags);
     if (count($tagsIds) != 0) {
         foreach ($tagsIds as $tagsId) {
             if ($tagsId == null || $tagsId == "") {
                 continue;
             }
             $restoTag = new MasterRestaurantTagModel();
             $restoTag->getByID($tagsId);
             $b["id_tag"] = $restoTag->id_tag;
             $b["name"] = $restoTag->tag_name;
             $rawTags[] = $b;
         }
     }
     $r["raw_tags"] = $rawTags;
     $this->jsonResults["restaurant"] = $r;
     $cuisine = new CuisineModel();
     $cs = array();
     foreach ($cuisine->getAll() as $cu) {
         $c["id_cuisine"] = $cu->id_cuisine;
         $c["name_cuisine"] = $cu->name_cuisine;
         $cs[] = $c;
     }
     if (count($cs) > 0) {
         $this->jsonResults["cuisine"] = $cs;
     }
     $rType = new MasterRestaurantTypeModel();
     $rts = array();
     foreach ($rType->getAll() as $ty) {
         $rt["id_restaurant_type"] = $ty->id_restaurant_type;
         $rt["name"] = $ty->name;
         $rts[] = $rt;
     }
     if (count($rts) > 0) {
         $this->jsonResults["restaurant_type"] = $rts;
     }
     $this->finish();
     die;
 }
 public static function getTagNameByID($id_tag)
 {
     $objRestoTag = new MasterRestaurantTagModel();
     $objRestoTag->getByID($id_tag);
     return $objRestoTag->tag_name;
 }
 public function updateResto()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $cmd = isset($_POST['cmd']) ? addslashes($_POST['cmd']) : "";
     if (!$cmd) {
         Generic::errorMsg("Hacking attempt!");
     }
     $id_restaurant = isset($_POST['id_restaurant']) ? addslashes($_POST['id_restaurant']) : "";
     if (!$id_restaurant) {
         Generic::errorMsg("No Restaurant ID Found");
     }
     $rawTags = isset($_POST['raw_tags']) ? addslashes($_POST['raw_tags']) : "";
     $newTagsIds = array();
     //TODO dapat string tags separated by comma, explode
     //TODO cek MasterRestaurantTagModel kalo duplikasi ambil id nya masukin $newTagsIds
     //TODO kalo engga duplikasi, save row baru, ambil id nya masukin $newTagsIds
     if ($rawTags) {
         $arrRawTags = array_unique(explode(",", $rawTags));
         foreach ($arrRawTags as $rawTag) {
             if ($rawTag == null || $rawTag == "") {
                 continue;
             }
             $rawTag = strtoupper($rawTag);
             $t = new MasterRestaurantTagModel();
             $arrTags = $t->getWhere("tag_name = '{$rawTag}'");
             //                pr($arrTags);
             if (count($arrTags) == 0) {
                 $tt = new MasterRestaurantTagModel();
                 $tt->tag_name = $rawTag;
                 $id = $tt->save();
             } else {
                 $id = $arrTags[0]->id_tag;
             }
             $newTagsIds[] = $id;
         }
     }
     $objRestaurant = new MasterRestaurantModel();
     $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed));
     $objRestaurant->getById($id_restaurant);
     if ($objRestaurant->id_restaurant != $id_restaurant) {
         Generic::errorMsg("No Restaurant ID Found");
     }
     if ($cmd == "initResto") {
         $onlyUpdates['aktiv'] = "1";
     } elseif ($cmd == "updateResto") {
     } else {
         Generic::errorMsg("No CMD ID Found");
     }
     foreach ($exp as $attr) {
         if ($_POST[$attr] != "") {
             if ($attr == "image_logo") {
                 $file = self::savePic($_POST[$attr]);
                 $onlyUpdates[$attr] = $file;
             } else {
                 $onlyUpdates[$attr] = $_POST[$attr];
             }
         }
     }
     $objRestaurant->fill($onlyUpdates);
     if (count($newTagsIds) != 0) {
         $objRestaurant->restaurant_tags = implode(",", array_unique($newTagsIds));
     }
     $id = $objRestaurant->save();
     if (!$id) {
         Generic::errorMsg("Failed to Save");
     } else {
         $json['status_code'] = 1;
         $json['results']['message'] = "success";
     }
     echo json_encode($json);
     die;
 }
 public function overwriteForm($return, $returnfull)
 {
     $return = parent::overwriteForm($return, $returnfull);
     //        if ($this->image_logo == "") {
     //            $this->image_logo = "noimage.jpg";
     //        }
     //        $return['image_logo'] = new InputFotoMR("foto", "image_logo", $this->image_logo);
     $return['image_logo'] = new \Leap\View\InputFotoCropperPop("1:1", "image_logo", "image_logo", $this->image_logo);
     if (!isset($this->time_open)) {
         $dt = leap_mysqldate();
     } else {
         $dt = $this->time_open;
     }
     $return['time_open'] = new \Leap\View\InputText("time", "time_open", "time_open", $dt);
     if (!isset($this->time_close)) {
         $dt = leap_mysqldate();
     } else {
         $dt = $this->time_close;
     }
     $return['time_close'] = new \Leap\View\InputText("time", "time_close", "time_close", $dt);
     $return['halal'] = new Leap\View\InputSelect(array("1" => "Yes", "0" => "No"), "halal", "halal", $this->status);
     $return['aktiv'] = new Leap\View\InputSelect(array("1" => "Yes", "0" => "No"), "aktiv", "aktiv", $this->aktiv);
     $return['menu_status'] = new Leap\View\InputSelect(array("1" => "Active", "0" => "Inactive"), "menu_status", "menu_status", $this->menu_status);
     $return['menu_status']->setReadOnly();
     $return['address'] = new \Leap\View\InputMap('address' . time(), 'latitude', 'longitude', $this->latitude, $this->longitude, 'address', $this->address);
     $return['district'] = new \Leap\View\InputText("text", "district" . time(), "district", $this->district);
     $return['district']->setReadOnly();
     $return['city'] = new \Leap\View\InputText("text", "city" . time(), "city", $this->city);
     $return['city']->setReadOnly();
     $return['latitude'] = new \Leap\View\InputText("text", "latitude" . time(), "latitude", $this->latitude);
     $return['latitude']->setReadOnly();
     $return['longitude'] = new \Leap\View\InputText("text", "longitude" . time(), "longitude", $this->longitude);
     $return['longitude']->setReadOnly();
     $ca = new MasterCategoryModel();
     $arr = $ca->getWhere("status='1'");
     $arrCats = array();
     foreach ($arr as $cat) {
         $arrCats[$cat->id_category] = $cat->name;
     }
     $return['id_categories'] = new \Leap\View\InputMultiTablet($arrCats, "id_categories", "id_categories", $this->id_categories);
     $rt = new MasterRestaurantTagModel();
     $arr = $rt->getAll();
     $arrTags = array();
     foreach ($arr as $tag) {
         $arrTags[$tag->id_tag] = $tag->tag_name;
     }
     //        $return['restaurant_tags'] = new \Leap\View\InputMultiTablet($arrTags, "restaurant_tags", "restaurant_tags", $this->restaurant_tags);
     $return['restaurant_tags'] = new \Leap\View\InputText("hidden", "restaurant_tags", "restaurant_tags", $this->restaurant_tags);
     $return['fav'] = new \Leap\View\InputText("text", "fav", "fav", $this->fav);
     $return['fav']->setReadOnly();
     $return['id_set_tables'] = new \Leap\View\InputText("text", "id_set_tables", "id_set_tables", $this->id_set_tables);
     $return['id_set_tables']->setReadOnly();
     if ($return['id_set_tables']->value == 0) {
         $return['id_set_tables']->value = "Active";
     }
     global $db;
     $q = "SELECT id_restaurant_type, name FROM menurevo__ms_restaurant_type WHERE 1";
     $res = $db->query($q, 2);
     foreach ($res as $value) {
         $arrHelp[$value->id_restaurant_type] = $value->name;
     }
     $return['restaurant_type'] = new Leap\View\InputSelect($arrHelp, "restaurant_type", "restaurant_type", $this->restaurant_type);
     // Cuisine
     $q = "SELECT id_cuisine, name_cuisine FROM menurevo__cuisine WHERE 1";
     $res = $db->query($q, 2);
     foreach ($res as $value) {
         $arrHelp[$value->id_cuisine] = $value->name_cuisine;
     }
     $return['id_cuisine'] = new Leap\View\InputSelect($arrHelp, "id_cuisine", "id_cuisine", $this->id_cuisine);
     $return['service_charge'] = new \Leap\View\InputTextRightAddOn("text", "service_charge", "service_charge", " % ", $this->service_charge);
     $return['tax_pb_1'] = new \Leap\View\InputTextRightAddOn("text", "tax_pb_1", "tax_pb_1", " % ", $this->tax_pb_1);
     $return['disc_resto'] = new \Leap\View\InputTextRightAddOn("text", "disc_resto", "disc_resto", " % ", $this->disc_resto);
     $return['new_set_table'] = new Leap\View\InputSelect(array("1" => "Yes", "0" => "No"), "new_set_table", "new_set_table", $this->new_set_table);
     $return['new_set_table']->setReadOnly();
     $return['table_quantity'] = new \Leap\View\InputText("text", "table_quantity", "table_quantity", $this->table_quantity);
     $return['table_quantity']->setReadOnly();
     $return['table_column'] = new \Leap\View\InputText("text", "table_column", "table_column", $this->table_column);
     $return['table_column']->setReadOnly();
     $return['layout_type'] = new Leap\View\InputSelect(array("1" => "Type 1", "2" => "Type 2"), "layout_type", "layout_type", $this->layout_type);
     $return['order_number'] = new \Leap\View\InputText("text", "order_number", "order_number", $this->order_number);
     $return['order_number']->setReadOnly();
     $return['now_open'] = new Leap\View\InputSelect(array("1" => "Yes", "0" => "No"), "now_open", "now_open", $this->now_open);
     $return['show_in_apps'] = new Leap\View\InputSelect(array("1" => "Yes", "0" => "No"), "show_in_apps", "show_in_apps", $this->show_in_apps);
     return $return;
 }