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; }