public static function getAllCategories()
 {
     $objCategories = new MasterCategoryModel();
     $arrAllCategories = $objCategories->getAll();
     foreach ($arrAllCategories as $val) {
         $arrCat[] = $val->name;
     }
     return $arrCat;
 }
 public function getCategoriesByResto()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idRestaurant = Generic::mustCheck($_GET['id_restaurant'], Keys::$ERR_NOT_FOUND_ID_RESTAURANT);
     $objResto = new MasterRestaurantModel();
     $objResto->getByID($idRestaurant);
     if (!Generic::IsNullOrEmptyString($objResto->id_categories)) {
         $arrCategories = explode(",", $objResto->id_categories);
     } else {
         $arrCategories = array();
     }
     $categories = array();
     foreach ($arrCategories as $idCat) {
         $c = new MasterCategoryModel();
         $c->getByID($idCat);
         if ($c->id_category) {
             $categories[] = $c->name;
         }
     }
     //        pr($arrCategories);
     //        pr($categories);
     $results['categories'] = $categories;
     $rawTags = array();
     $id_dish = isset($_GET['id_dish']) ? addslashes($_GET['id_dish']) : "";
     if ($id_dish) {
         $dish = new MasterDishModel();
         $dish->getByID($id_dish);
         $tagsIds = explode(",", $dish->dish_tags);
         if (count($tagsIds) != 0) {
             foreach ($tagsIds as $tagsId) {
                 if ($tagsId == null || $tagsId == "") {
                     continue;
                 }
                 $dishTag = new MasterDishTagModel();
                 $dishTag->getByID($tagsId);
                 $b["id_tag"] = $dishTag->id_tag;
                 $b["name"] = $dishTag->name;
                 $rawTags[] = $b;
             }
         }
     }
     $results['raw_tags'] = $rawTags;
     Generic::finish($results);
 }
 public function updateDish()
 {
     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;
     }
     $jsonDish = isset($_POST['dishes']) ? $_POST['dishes'] : "";
     if (!$jsonDish) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $jsonArrayDish = json_decode($jsonDish);
     $objDish = new MasterDishModel();
     $sem = array();
     $semCheck = array();
     foreach ($jsonArrayDish as $key => $value) {
         $arrDish = $objDish->getWhere("id_dish='{$value->id_dish}'");
         if (count($arrDish) > 0) {
             foreach ($value as $key => $dish) {
                 if (in_array($key, $objDish->crud_add_photourl)) {
                     $picname = MasterRestaurant::savePic($dish);
                     $arrDish[0]->{$key} = $picname;
                 } elseif ($key == "category_name") {
                     $objCategory = new MasterCategoryModel();
                     $arrCategory = $objCategory->getWhere("name='{$dish}'");
                     if (count($arrCategory) == 0) {
                         $objCategory->name = strtoupper($dish);
                         $objCategory->status = "1";
                         $objCategory->save();
                     }
                     $arrCategory = $objCategory->getWhere("name='{$dish}'");
                     $arrDish[0]->id_category = $arrCategory[0]->id_category;
                 } else {
                     $arrDish[0]->{$key} = $dish;
                 }
                 $arrDish[0]->id_restaurant = $id_restaurant;
             }
             $arrDish[0]->load = 1;
             $arrDish[0]->save();
             $sem[] = "id_dish: " . $value->id_dish . " or " . $value->name . " are  updated";
             $semCheck[] = 1;
         } else {
             $sem[] = "id_dish: " . $value->id_dish . " or " . $value->name . " not found";
             $semCheck[] = 0;
         }
     }
     //        pr($semCheck);
     if (!in_array(1, $semCheck)) {
         $json['status_code'] = 0;
     } else {
         $json['status_code'] = 1;
     }
     $json['results'] = $sem;
     echo json_encode($json);
     die;
 }
    public function createNewRestaurant()
    {
        ?>
        <style>
            .controls {
                margin-top: 10px;
                border: 1px solid transparent;
                border-radius: 2px 0 0 2px;
                box-sizing: border-box;
                -moz-box-sizing: border-box;
                height: 32px;
                outline: none;
                box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
            }

            #pac-input {
                background-color: #fff;
                font-family: Roboto;
                font-size: 15px;
                font-weight: 300;
                margin-left: 12px;
                margin-right: 12px;
                padding: 0 11px 0 13px;
                text-overflow: ellipsis;
                width: 80%;
            }

            #pac-input:focus {
                border-color: #4d90fe;
            }

            .pac-container {
                font-family: Roboto;
            }

            #type-selector {
                color: #fff;
                background-color: #4d90fe;
                padding: 5px 11px 0px 11px;
            }

            #type-selector label {
                font-family: Roboto;
                font-size: 13px;
                font-weight: 300;
            }
        </style>
        <div class="col-sm-12">
            <h1>Create New Restaurant</h1>
        </div>

        <div id="formgroup_name" class="form-group">
            <label for="name" class=" col-sm-2 control-label">Name</label>

            <div class="col-sm-10"><input type="text" name="name" value="" id="name" class="form-control"> <span
                    class="help-block" id="warning_name"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_email" class="form-group">
            <label for="email" class=" col-sm-2 control-label">Email</label>

            <div class="col-sm-10"><input type="text" name="email" value="" id="email"
                                          class="form-control"> <span class="help-block" id="warning_email"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_phone_no" class="form-group">
            <label for="phone_no" class=" col-sm-2 control-label">Phone</label>

            <div class="col-sm-10"><input type="text" name="phone_no" value="" id="phone_no"
                                          class="form-control"> <span class="help-block" id="warning_phone_no"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_time_open" class="form-group">
            <label for="time_open" class=" col-sm-2 control-label">time_open</label>

            <div class="col-sm-10"><input type="time" name="time_open" value="" id="time_open"
                                          class="form-control"> <span class="help-block" id="warning_time_open"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_time_close" class="form-group">
            <label for="time_close" class=" col-sm-2 control-label">time_close</label>

            <div class="col-sm-10"><input type="time" name="time_close" value="" id="time_close"
                                          class="form-control"> <span class="help-block" id="warning_time_close"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_halal" class="form-group">
            <label for="halal" class=" col-sm-2 control-label">Halal</label>

            <div class="col-sm-10"><select class="form-control" name="halal" id="halal">
                    <option value="1">Yes</option>
                    <option value="0" selected="">No</option>
                </select>
                <span class="help-block" id="warning_halal"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_foto" class="form-group">
            <label for="image_logo" class=" col-sm-2 control-label">image_logo</label>

            <div class="col-sm-10">
                <div id="loaderholder_foto_old_1465962690"
                     style="position: absolute; margin-top: 30px; margin-left: 40px; display: none;"
                     class="inputfotoloader">Loading...
                </div>
                <span id="foto_1465962690">
                    <div class="foto100">
                        <img src="/images/noimage.jpg" id="holder_foto_old_1465962690"
                             onload="OnImageLoadMR(event,72,30);">
                    </div>
                        <input type="file" name="file_image_logo" id="file_foto" value="noimage.jpg">
                        <input type="hidden" name="image_logo" id="foto" value="noimage.jpg">
                </span>
                <style>
                    .inputfotoloader,
                    .inputfotoloader:before,
                    .inputfotoloader:after {
                        background: #888;
                        -webkit-animation: load1 1s infinite ease-in-out;
                        animation: load1 1s infinite ease-in-out;
                        width: 1em;
                        height: 4em;
                    }

                    .inputfotoloader:before,
                    .inputfotoloader:after {
                        position: absolute;
                        top: 0;
                        content: '';
                    }

                    .inputfotoloader:before {
                        left: -1.5em;
                    }

                    .inputfotoloader {
                        text-indent: -9999em;
                        margin: 8em auto;
                        position: relative;
                        font-size: 11px;
                        -webkit-animation-delay: -0.16s;
                        animation-delay: -0.16s;
                    }

                    .inputfotoloader:after {
                        left: 1.5em;
                        -webkit-animation-delay: -0.32s;
                        animation-delay: -0.32s;
                    }

                    @-webkit-keyframes load1 {
                        0%,
                        80%,
                        100% {
                            box-shadow: 0 0 #888;
                            height: 4em;
                        }
                        40% {
                            box-shadow: 0 -2em #888;
                            height: 5em;
                        }
                    }

                    @keyframes load1 {
                        0%,
                        80%,
                        100% {
                            box-shadow: 0 0 #888;
                            height: 4em;
                        }
                        40% {
                            box-shadow: 0 -2em #888;
                            height: 5em;
                        }
                    }

                </style>
                <script type="text/javascript">
                    var fileTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp'];  //acceptable file types

                    document.querySelector('#foto_1465962690 input[type=file]').addEventListener('change', function (event) {
                        // Read files

                        var files = event.target.files;
                        for (var i = 0; i < files.length; i++) {
                            if (files[i].type.match(/image.*/)) {
                                var reader = new FileReader();
                                var extension = files[i].name.split('.').pop().toLowerCase();
                                var isSuccess = fileTypes.indexOf(extension) > -1;
                                console.log(extension);
                                console.log(reader);
                                console.log(isSuccess);
                                if (isSuccess) {

                                    //check size
                                    if (extension == "png" || extension == "gif") {

                                        //kalau png atau gif, tidak di resize, krn we want to preserve the transparency and animations
                                        if (typeof FileReader !== "undefined") {
                                            var sizess = files[i].size;
                                            // check file size
                                            console.log(sizess);

                                        }
                                        inputFotoFiles_1465962690(event);

                                    } else {
                                        reader.onload = function (readerEvent) {
                                            var image = new Image();
                                            image.onload = function (imageEvent) {
                                                // Resize image
                                                var canvas = document.createElement('canvas'),
                                                    max_size = 1200,
                                                    width = image.width,
                                                    height = image.height;
                                                if (width > height) {
                                                    if (width > max_size) {
                                                        height *= max_size / width;
                                                        width = max_size;
                                                    }
                                                } else {
                                                    if (height > max_size) {
                                                        width *= max_size / height;
                                                        height = max_size;
                                                    }
                                                }
                                                canvas.width = width;
                                                canvas.height = height;
                                                canvas.getContext('2d').drawImage(image, 0, 0, width, height);
                                                var xhr = new XMLHttpRequest();
                                                if (xhr.upload) {

                                                    // Update progress
                                                    xhr.upload.addEventListener('progress', function (event) {
                                                        var percent = parseInt(event.loaded / event.total * 100);
                                                        $("#loaderholder_foto_old_1465962690").show();

                                                    }, false);

                                                    xhr.onreadystatechange = function (event) {
                                                        if (xhr.readyState == 4) {
                                                            if (xhr.status == 200) {
                                                                $("#loaderholder_foto_old_1465962690").hide();
                                                                var imageHtml = document.getElementById("holder_foto_old_1465962690");

                                                                imageHtml.removeAttribute("style");
                                                                imageHtml.removeAttribute("width");
                                                                imageHtml.removeAttribute("height");
                                                                imageHtml.src = '/' + 'uploads/' + xhr.responseText;
                                                                $('#foto_1465962690 #foto').val(xhr.responseText);
                                                                console.log('Image uploaded: ' + xhr.responseText);
                                                            } else {
                                                                //imageElement.parentNode.removeChild(imageElement);
                                                            }
                                                        }
                                                    }

                                                    // Start upload
                                                    xhr.open('post', '/uploader/uploadres?adafile=noimage.jpg&ext=' + extension, true);
                                                    xhr.send(canvas.toDataURL('image/' + extension));

                                                }
                                            }
                                            image.src = readerEvent.target.result;

                                        }
                                        reader.readAsDataURL(files[i]);
                                    }//else png or gif


                                }//success
                                else {
                                    alert("Please only upload image files");
                                    console.log("err type");
                                }
                            } else {
                                alert("Please only upload image files");
                                console.log("err type");
                            }
                        }

                    });

                    // Catch the form submit and upload the files
                    function inputFotoFiles_1465962690(event) {
                        files = event.target.files;
                        event.stopPropagation(); // Stop stuff happening
                        event.preventDefault(); // Totally stop stuff happening

                        // START A LOADING SPINNER HERE

                        // Create a formdata object and add the files
                        var data = new FormData();
                        $.each(files, function (key, value) {
                            data.append(key, value);
                        });
                        //console.log(data);
                        $.ajax({
                            url: '/Uploader/uploadres_ext?t=1465962690&files=1&adafile=noimage.jpg',
                            type: 'POST',
                            data: data,
                            cache: false,
                            dataType: 'json',
                            processData: false, // Don't process the files
                            contentType: false, // Set content type to false as jQuery will tell the server its a query string request
                            success: function (data, textStatus, jqXHR) {
                                // console.log(data);

                                if (data.bool) {
                                    var imageHtml = document.getElementById("holder_foto_old_1465962690");

                                    imageHtml.removeAttribute("style");
                                    imageHtml.removeAttribute("width");
                                    imageHtml.removeAttribute("height");
                                    imageHtml.src = '/' + 'uploads/' + data.filename;
                                    $('#foto_1465962690 #foto').val(data.filename);
                                    imageHtml.src = '/uploads/' + data.filename;
                                    console.log('Image uploaded: ' + data.filename);

                                } else {
                                    // Handle errors here
                                    console.log('ERRORS: ' + data.error);
                                    $("#file_repeat_foto_1465962690").show();
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                // Handle errors here
                                console.log('ERRORS: ' + textStatus);
                                // STOP LOADING SPINNER
                            }
                        });
                    }
                </script>
                <span class="help-block" id="warning_foto"></span>
            </div>
            <div class="clearfix"></div>
        </div>


        <div id="formgroup_map" class="form-group">
            <label for="map" class=" col-sm-2 control-label">Map</label>

            <div class="col-sm-10">
                <input id="pac-input" class="controls" type="text" placeholder="Search">

                <div class="col-sm-12" id="map" style="width: 100%;height: 450px;background-color: #CCC;"></div>
                <script>
                    function setLatLong(lat, lng) {
                        var marker = new google.maps.Marker({
                            position: {lat: lat, lng: lng},
                            map: map,
                            title: $("#name").val
                        });
                        $("#latitude").val(lat);
                        $("#longitude").val(lng);
                        var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lng + "&language=en&key=AIzaSyAjTYhXjHK4MgwGPK8UlveENUMCjgZcSZA";
                        console.log(url);
                        $.ajax({
                            method: "GET",
                            url: url
                        })
                            .done(function (msg) {
                                if (msg.results[3] == null) {
                                    $("#district").val("");
                                    $("#city").val("");
                                    $("#latitude").val("");
                                    $("#longitude").val("");
                                    alert("Cannot get exact location\nPlease zoom in and select again");
                                    return;
                                }
                                var arrComponents = msg.results[3].address_components;
//                                console.log(arrComponents);
                                $.each(arrComponents, function (jObj) {
                                    console.log(arrComponents[jObj].types[0]);
                                    if (arrComponents[jObj].types[0] == "administrative_area_level_3") {
                                        $("#district").val(arrComponents[jObj].long_name.toUpperCase());
                                    }
                                    else if (arrComponents[jObj].types[0] == "administrative_area_level_2") {
                                        $("#city").val(arrComponents[jObj].long_name.toUpperCase());
                                    }
                                });
                            });
                    }

                </script>
                <script>
                    function initAutocomplete() {
                        var map = new google.maps.Map(document.getElementById("map"), {
                            center: {lat: -6.175883636877263, lng: 106.82710647583008},
                            zoom: 13,
                            mapTypeId: google.maps.MapTypeId.ROADMAP
                        });

                        // Create the search box and link it to the UI element.
                        var input = document.getElementById("pac-input");
                        var searchBox = new google.maps.places.SearchBox(input);
                        map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

                        // Bias the SearchBox results towards current map's viewport.
                        map.addListener("bounds_changed", function () {
                            searchBox.setBounds(map.getBounds());
                        });

                        var markers = [];

                        google.maps.event.addListener(map, "click", function (event) {
                            markers.forEach(function (marker) {
                                marker.setMap(null);
                            });
                            markers = [];
                            var icon = {
                                size: new google.maps.Size(71, 71),
                                origin: new google.maps.Point(0, 0),
                                anchor: new google.maps.Point(17, 34),
                                scaledSize: new google.maps.Size(25, 25)
                            };
                            markers.push(new google.maps.Marker({
                                map: map,
                                icon: icon,
                                position: {lat: event.latLng.lat(), lng: event.latLng.lng()}
                            }));
                            setLatLong(event.latLng.lat(), event.latLng.lng());
                        });

                        // [START region_getplaces]
                        // Listen for the event fired when the user selects a prediction and retrieve
                        // more details for that place.
                        searchBox.addListener("places_changed", function () {
                            var places = searchBox.getPlaces();

                            if (places.length == 0) {
                                return;
                            }

                            // Clear out the old markers.
                            markers.forEach(function (marker) {
                                marker.setMap(null);
                            });
                            markers = [];

                            // For each place, get the icon, name and location.
                            var bounds = new google.maps.LatLngBounds();
                            places.forEach(function (place) {
//                                var icon = {
//                                    size: new google.maps.Size(71, 71),
//                                    origin: new google.maps.Point(0, 0),
//                                    anchor: new google.maps.Point(17, 34),
//                                    scaledSize: new google.maps.Size(25, 25)
//                                };
//
//                                // Create a marker for each place.
//                                markers.push(new google.maps.Marker({
//                                    map: map,
//                                    icon: icon,
//                                    title: place.name,
//                                    position: place.geometry.location
//                                }));

                                if (place.geometry.viewport) {
                                    // Only geocodes have viewport.
                                    bounds.union(place.geometry.viewport);
                                } else {
                                    bounds.extend(place.geometry.location);
                                }
                            });
                            map.fitBounds(bounds);
                        });
                        // [END region_getplaces]
                    }


                </script>
                <script
                    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAjTYhXjHK4MgwGPK8UlveENUMCjgZcSZA&libraries=places&callback=initAutocomplete"
                    async defer></script>

                <span class="help-block" id="warning_map"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_address" class="form-group">
            <label for="address" class=" col-sm-2 control-label">address</label>

            <div class="col-sm-10"><input type="text" name="address" value="" id="address"
                                          class="form-control"> <span
                    class="help-block" id="warning_address"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_district" class="form-group">
            <label for="district" class=" col-sm-2 control-label">District</label>

            <div class="col-sm-10">
                <input type="text" name="district" value="" id="district" class="form-control" disabled>
                <span class="help-block" id="warning_district"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_city" class="form-group">
            <label for="city" class=" col-sm-2 control-label">City</label>

            <div class="col-sm-10">
                <input type="text" name="city" value="" id="city" class="form-control" disabled>
                <span class="help-block" id="warning_city"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_latitude" class="form-group">
            <label for="latitude" class=" col-sm-2 control-label">Latitude</label>

            <div class="col-sm-10">
                <input type="text" name="latitude" value="" id="latitude" class="form-control" disabled>
                <span class="help-block" id="warning_latitude"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_longitude" class="form-group">
            <label for="longitude" class=" col-sm-2 control-label">Longitude</label>

            <div class="col-sm-10">
                <input type="text" name="longitude" value="" id="longitude" class="form-control" disabled>
                <span class="help-block" id="warning_longitude"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_restaurant_type" class="form-group">
            <label for="restaurant_type" class=" col-sm-2 control-label">Restaurant Type</label>

            <div class="col-sm-10"><select class="form-control" name="restaurant_type" id="restaurant_type">
                    <option value="0">Select Restaurant Type</option>
                    <?php 
        $rType = new MasterRestaurantTypeModel();
        $arrRType = $rType->getAll();
        foreach ($arrRType as $r) {
            if (Generic::IsNullOrEmptyString($r->name)) {
                continue;
            }
            ?>
                        <option value="<?php 
            echo $r->id_restaurant_type;
            ?>
"><?php 
            echo $r->name;
            ?>
</option>
                        <?php 
        }
        ?>
                </select>
                <span class="help-block" id="warning_restaurant_type"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_id_cuisine" class="form-group">
            <label for="id_cuisine" class=" col-sm-2 control-label">ID Cuisine</label>

            <div class="col-sm-10"><select class="form-control" name="id_cuisine" id="id_cuisine">
                    <option value="0">Select Cuisine</option>
                    <?php 
        $rType = new CuisineModel();
        $arrRType = $rType->getWhere("status='1'");
        foreach ($arrRType as $r) {
            if (Generic::IsNullOrEmptyString($r->name_cuisine)) {
                continue;
            }
            ?>
                        <option value="<?php 
            echo $r->id_cuisine;
            ?>
"><?php 
            echo $r->name_cuisine;
            ?>
</option>
                        <?php 
        }
        ?>
                </select>
                <span class="help-block" id="warning_id_cuisine"></span>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_cat_choices" class="form-group">
            <label for="cat_choices" class=" col-sm-2 control-label">Categories</label>

            <div class="col-sm-8">
                <select class="form-control" name="cat_choices" id="cat_choices">
                    <option value="-1">Select Category</option>
                    <?php 
        $c = new MasterCategoryModel();
        $arrCats = $c->getWhere("status='1'");
        foreach ($arrCats as $r) {
            if (Generic::IsNullOrEmptyString($r->name)) {
                continue;
            }
            ?>
                        <option value="<?php 
            echo $r->id_category;
            ?>
"><?php 
            echo $r->name;
            ?>
</option>
                        <?php 
        }
        ?>
                </select>
                <span class="help-block" id="warning_voided"></span>
            </div>
            <div class="col-sm-2">
                <button type="button" id="button_select_cat" class="btn btn-default" style="width: 100%;">Add</button>
            </div>
            <div class="clearfix"></div>
        </div>

        <div id="formgroup_selected_cat" class="form-group">
            <label for="selected_cat" class=" col-sm-2 control-label">Selected Category</label>

            <div class="col-sm-10">
                <input type="text" name="selected_cat" id="selected_cat" class="form-control">
                <span class="help-block" id="warning_selected_cat"></span>
            </div>
            <div class="clearfix"></div>
        </div>
        <script>
            $('#button_select_cat').click(
                function () {
                    var restoChoice = $('select#cat_choices');
                    var selectedVal = restoChoice.val();
                    var selectedText = restoChoice.find('option:selected').text();
                    if (restoChoice.prop('disabled')) {
                        alert("All Restaurant Selected");
                        return;
                    }

                    if (selectedVal == '-1' || selectedVal == null || selectedVal == '') {
                        alert("Please Select Restaurant");
                        return;
                    }
                    $("select#cat_choices option:selected").remove();
                    $('#selected_cat').tokenfield();
                    $('#selected_cat').tokenfield('createToken', {value: selectedVal, label: selectedText});
                    restoChoice.val('');
                }
            );

            $('#selected_cat')
                .on('tokenfield:removedtoken', function (e) {
                    var value = e.attrs.value;
                    var label = e.attrs.label;
                    var restoChoice = $('select#cat_choices');
                    restoChoice
                        .append($("<option></option>")
                            .attr("value", value)
                            .text(label));

                    if (value == '0') {
                        restoChoice.prop("disabled", false);
                    }

                    var selectList = $('select#cat_choices option');
                    selectList.sort(function (a, b) {
                        a = a.value;
                        b = b.value;

                        return a - b;
                    });
                    restoChoice.html(selectList);
                    restoChoice.val(value);
                });

            function clearFields() {
                lwrefresh('DiscCreditCard');
            }
        </script>

        <div class="form-group">
            <div class="col-sm-12">
                <button id="submit_create_new_resto" class="btn btn-default">submit</button>
                <button id="cancel_create_new_resto" class="btn btn-default">cancel</button>
                <script>
                    $("#cancel_create_new_resto").click(function (event) {
                        event.preventDefault();
                        lwclose(window.selected_page);
                    });
                </script>
            </div>
        </div>
        <?php 
    }
 private function viewSearchTerm($searchType, $searchTerm)
 {
     switch ($searchType) {
         case "1":
             $rt = new MasterRestaurantTypeModel();
             $rt->getByID($searchTerm);
             return $rt->name;
         case "2":
             $r = new MasterCategoryModel();
             $r->getByID($searchTerm);
             return $r->name;
         case "3":
             $r = new CuisineModel();
             $r->getByID($searchTerm);
             return $r->name_cuisine;
             //            case "4": {
             //                return new Leap\View\InputText("text", "search_term", "search_term", $this->search_term);
             //            }
             //            case "5": {
             //                $r = new MasterDishTagModel();
             //                $r->getByID($searchTerm);
             //                return $r->name;
             //            }
             //            case "6": {
             //                return new Leap\View\InputText("text", "search_term", "search_term", $this->search_term);
             //            }
         //            case "4": {
         //                return new Leap\View\InputText("text", "search_term", "search_term", $this->search_term);
         //            }
         //            case "5": {
         //                $r = new MasterDishTagModel();
         //                $r->getByID($searchTerm);
         //                return $r->name;
         //            }
         //            case "6": {
         //                return new Leap\View\InputText("text", "search_term", "search_term", $this->search_term);
         //            }
         case "7":
             $r = new MasterRestaurantModel();
             $r->getByID($searchTerm);
             return $r->name;
         case "8888":
             return "Not Available";
         default:
             return "Not Available";
     }
 }
 public function setRestoCategories()
 {
     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) {
         Generic::errorMsg("Restaurant ID not Found");
     }
     $category = isset($_POST['categories']) ? $_POST['categories'] : "";
     if (!$category) {
         Generic::errorMsg("Category ID not found!");
     }
     $resto = new MasterRestaurantModel();
     $resto->getByID($id_restaurant);
     $arrOldCategories = explode(",", $resto->id_categories);
     $jsonCategories = json_decode($category);
     $jsonCategorieshlp = array();
     foreach ($jsonCategories as $cat) {
         $jsonCategorieshlp[] = $cat->category_name;
     }
     if (!in_array("OTHERS", $jsonCategorieshlp)) {
         $jsonCategorieshlp[] = "OTHERS";
     }
     $jsonCategorieshlp = array_unique($jsonCategorieshlp);
     $objCategory = new MasterCategoryModel();
     $idCategories = array();
     foreach ($jsonCategorieshlp as $category) {
         $arrCategory = $objCategory->getWhere("name = '{$category}'");
         if (count($arrCategory) == 0 && !Generic::IsNullOrEmptyString($category)) {
             $oc = new MasterCategoryModel();
             $oc->name = strtoupper($category);
             $oc->status = "1";
             $oc->is_drink = "0";
             $oc->save();
         }
     }
     foreach ($jsonCategorieshlp as $category) {
         $arrCategory = $objCategory->getWhere("name = '{$category}'");
         foreach ($arrCategory as $val) {
             $idCategories[] = $val->id_category;
         }
     }
     //compare old categories to new categories
     //cari yang dulu ada sekarang ga ada
     //migrasi dish ke others
     $missingCategories = array_diff($arrOldCategories, $idCategories);
     foreach ($missingCategories as $category) {
         $d = new MasterDishModel();
         $arrDishes = $d->getWhere("id_category = '{$category}' AND id_restaurant = '{$id_restaurant}'");
         foreach ($arrDishes as $dish) {
             $dish->load = 1;
             $dish->id_category = "0";
             $dish->save();
         }
     }
     $objRestaurant = new MasterRestaurantModel();
     $arrResto = $objRestaurant->getWhere("id_restaurant = '{$id_restaurant}'");
     if (count($arrResto) == 0) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $idCategories = implode(",", $idCategories);
     $arrResto[0]->id_categories = $idCategories;
     $arrResto[0]->load = 1;
     $idSave = $arrResto[0]->save();
     if (!$idSave) {
         Generic::errorMsg(Lang::t('save failed'));
     } else {
         $json['status_code'] = 1;
         $json['results'] = "Success";
     }
     echo json_encode($json);
     die;
 }
 public function searchTypeDataSet()
 {
     $searchType = $_GET['search_type'];
     $json = array();
     switch ($searchType) {
         case "1":
             $rt = new MasterRestaurantTypeModel();
             $arr = $rt->getWhere("name!=''");
             foreach ($arr as $restoType) {
                 $b['value'] = $restoType->id_restaurant_type;
                 $b['text'] = $restoType->name;
                 $json[] = $b;
             }
             break;
         case "2":
             $r = new MasterCategoryModel();
             $arr = $r->getWhere("name!=''");
             foreach ($arr as $tag) {
                 $b['value'] = $tag->id_category;
                 $b['text'] = $tag->name;
                 $json[] = $b;
             }
             break;
         case "3":
             $r = new CuisineModel();
             $arrRC = $r->getWhere("name_cuisine!=''");
             foreach ($arrRC as $cuisine) {
                 $b['value'] = $cuisine->id_cuisine;
                 $b['text'] = $cuisine->name_cuisine;
                 $json[] = $b;
             }
             break;
             //            case "5": {
             //                $r = new MasterDishTagModel();
             //                $arr = $r->getWhere("name!=''");
             //                foreach ($arr as $tag) {
             //                    $b['value'] = $tag->id_tag;
             //                    $b['text'] = $tag->name;
             //                    $json[] = $b;
             //                }
             //                break;
             //            }
         //            case "5": {
         //                $r = new MasterDishTagModel();
         //                $arr = $r->getWhere("name!=''");
         //                foreach ($arr as $tag) {
         //                    $b['value'] = $tag->id_tag;
         //                    $b['text'] = $tag->name;
         //                    $json[] = $b;
         //                }
         //                break;
         //            }
         case "7":
             $rt = new MasterRestaurantModel();
             $arr = $rt->getWhere("name!=''");
             foreach ($arr as $resto) {
                 $b['value'] = $resto->id_restaurant;
                 $b['text'] = $resto->name;
                 $json[] = $b;
             }
             break;
         default:
             $b['value'] = 8888;
             $b['text'] = "Not Available";
             $json[] = $b;
             break;
     }
     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;
 }
 public function isCategoryIdValid($catId)
 {
     $mc = new MasterCategoryModel();
     $mc->getByID($catId);
     if (Generic::IsNullOrEmptyString($mc->id_category)) {
         return false;
     } else {
         return true;
     }
 }