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 userUpdateProfile() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $idUser = Generic::mustCheck($_POST['id_user'], "ID user required"); $fullName = Generic::mustCheck($_POST['full_name'], "Empty Full Name"); $userName = Generic::mustCheck($_POST['user_name'], "Empty User Name"); $email = Generic::mustCheck($_POST['email'], "Empty Email"); $password = Generic::mustCheck($_POST['pwd'], "Empty Password"); $idCuisine = Generic::mustCheck($_POST['pref_cuisine'], "Cuisine Not Selected"); $birthday = Generic::mustCheck($_POST['birthday'], "Empty Birthday"); $phoneNo = Generic::mustCheck($_POST['phone_no'], "Empty Phone Number"); $fbId = Generic::IsNullOrEmptyString($_POST['fb_id']) ? "" : $_POST['fb_id']; $latitude = Generic::IsNullOrEmptyString($_POST['lat']) ? "" : $_POST['lat']; $longitude = Generic::IsNullOrEmptyString($_POST['long']) ? "" : $_POST['long']; $district = Generic::IsNullOrEmptyString($_POST['district']) ? "" : $_POST['district']; $city = Generic::IsNullOrEmptyString($_POST['city']) ? "" : $_POST['city']; $pic = Generic::IsNullOrEmptyString($_POST['pic']) ? "" : MasterRestaurant::savePic($_POST['pic']); ///START OF LOVELY VALIDATION TIME if (!Generic::isValidUserName($userName)) { Generic::errorMsg("Username must only contains alphanumeric (and/or) \\'.\\', \\'-\\', \\'_\\'"); } if (!Generic::isValidUserNameLength($userName)) { Generic::errorMsg("Max username length is 20"); } if (!Generic::isValidEmail($email)) { Generic::errorMsg("Email format not valid"); } if (!Generic::isValidPassword($password)) { Generic::errorMsg("Password must contain minimum 5 character and no whitespace"); } $user = new UserModel(); $user->getByID($idUser); if ($birthday != $user->birthday) { Generic::errorMsg("Birthday cannot be changed"); } if ($userName != $user->user_name) { Generic::errorMsg("Username cannot be changed"); } if (!Generic::IsNullOrEmptyString($user->fb_id) && $fbId != $user->fb_id) { Generic::errorMsg("Facebook cannot be changed"); } else { $user->fb_id = $fbId; } ///END OF LOVELY VALIDATION TIME, HOW SAD :( $user->full_name = $fullName; $user->email = $email; $user->password = $password; $user->id_cuisine = $idCuisine; $user->phone_no = $phoneNo; if (!Generic::IsNullOrEmptyString($pic)) { $user->pic = $pic; } if (!Generic::IsNullOrEmptyString($latitude)) { $user->latitude = $latitude; $user->last_lat = $latitude; } if (!Generic::IsNullOrEmptyString($longitude)) { $user->longitude = $longitude; $user->last_long = $longitude; } if (!Generic::IsNullOrEmptyString($district)) { $user->district = $district; $user->last_district = $district; } if (!Generic::IsNullOrEmptyString($city)) { $user->city = $city; $user->last_city = $city; } $user->status = "1"; $uid = $user->save(); if (!$uid) { Generic::errorMsg("Failed Creating User"); } else { $json['status_code'] = 1; $json['results']['fb_id'] = $user->fb_id; $json['results']['id_user'] = $idUser; $json['results']['user_name'] = $user->user_name; $json['results']['full_name'] = $user->full_name; $json['results']['email'] = $user->email; $json['results']['pic'] = Generic::insertImageUrl($user->pic); echo json_encode($json); die; } }