public function update($id)
 {
     $data = Input::all();
     $avatar = Input::file('avatar');
     if (FEUsersHelper::isCurrentUser($id)) {
         $validator = FEUsersHelper::validateUpdateInfo();
         if ($validator->fails()) {
             $messages = $validator->messages();
             $errors = json_encode($messages);
             echo $errors;
         } else {
             $user = Users::where('account', $data['account'])->first();
             $user['fullname'] = $data['fullname'];
             $user['email'] = $data['email'];
             $user['phone'] = $data['phone'];
             $user['address'] = $data['address'];
             $user['about'] = $data['about'];
             if ($avatar) {
                 $upload_avatar_folder = 'avatar/' . $user->account . "/";
                 $name = $avatar->getFilename() . uniqid() . "." . $avatar->getClientOriginalExtension();
                 $avatar->move(public_path() . "/" . $upload_avatar_folder, $name);
                 $user->avatar = 'public/' . $upload_avatar_folder . $name;
             }
             $user->save();
             Session::flush('user');
             Session::put('user', $user);
             echo json_encode('success');
         }
     } else {
         echo json_encode('fail');
     }
     //        return false;
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     if (FEUsersHelper::isCurrentUser($id)) {
         $user = User::find($id);
         return View::make('frontend/users/edit')->with('user', $user);
     }
 }
 public function destroy($id)
 {
     $like = Like::find($id);
     if (FEUsersHelper::isCurrentUser($like['user_id'])) {
         $like->is_deleted = 1;
         $like->save();
         echo 'success';
     } else {
         echo 'fail';
     }
 }
 public function update($id)
 {
     $follow = Follow::find($id);
     if (FEUsersHelper::isCurrentUser($follow->follower->id)) {
         $follow->is_deleted = 1;
         $follow->save();
         echo 'true';
     } else {
         echo 'false';
     }
 }
 public function destroy($id)
 {
     $post = Post::find($id);
     if ($post && FEUsersHelper::isCurrentUser($post->user->id)) {
         FELikesHelper::delete($post->getEntry()->id);
         FEEntriesHelper::delete($post->id, 1);
         $post->delete();
         echo 'true';
     } else {
         echo 'false';
     }
 }
 private function getViewProfileDatas($user_id)
 {
     $privacy = Privacy::where('name', "Công khai")->get()->first();
     $datas = array();
     if (FEUsersHelper::isCurrentUser($user_id)) {
         $entries = Entry::where('user_id', $user_id)->orderBy('updated_at', 'DESC')->paginate($this->entries_per_page);
         $left_albums = Album::where('user_id', $user_id)->orderBy('updated_at', 'DESC')->get();
     } else {
         $entries = Entry::where('user_id', $user_id)->where('privacy', $privacy->id)->orderBy('updated_at', 'DESC')->paginate($this->entries_per_page);
         $left_albums = Album::where('user_id', $user_id)->where('privacy', 1)->orderBy('updated_at', 'DESC')->get();
     }
     return array("entries" => $entries, "left_albums" => $left_albums);
 }
 public function update($id)
 {
     $blog = Blog::find($id);
     if (FEUsersHelper::isCurrentUser($blog->user->id)) {
         $blog->title = Input::get('title');
         $blog->content = Input::get('content');
         $blog->privacy = Input::get('privacy');
         $blog->save();
         FEEntriesHelper::updatePrivacy($blog->id, 2, $blog->privacy);
         return Redirect::back();
     } else {
         return Redirect::to('/');
     }
 }
 public function index()
 {
     $user_id = Input::get('user_id');
     $user = User::find($user_id);
     if ($user) {
         if (FEUsersHelper::isCurrentUser($user->id)) {
             $images_d = Image::where('user_id', '=', $user->id);
         } else {
             $album_id = Album::where('user_id', '=', $user->id)->where('privacy', PrivaciesHelper::getId("Công khai"))->select('id')->get();
             $images_d = Image::where('user_id', '=', $user->id)->whereIn('album_id', $album_id->fetch('id')->toArray());
         }
         return View::make('frontend/photos/images/index')->with('user', $user)->with('images', $images_d->paginate($this->image_per_page));
     } else {
         return Redirect::to('/');
     }
 }
 public function show($id)
 {
     if (FEUsersHelper::isLogged()) {
         $conversation = Conversation::find($id);
         if ($conversation) {
             if (FEUsersHelper::isCurrentUser($conversation->user1_id) || FEUsersHelper::isCurrentUser($conversation->user2_id)) {
                 return View::make('frontend/messages/show')->with('user', User::find(Session::get('user')['id']))->with('conversations', $this->conversations)->with('conversation', $conversation);
             } else {
                 return Redirect::to('message');
             }
         } else {
             return Redirect::to('message');
         }
     } else {
         return Redirect::to('/');
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     $user = User::find($id);
     foreach ($user->products as $product) {
         $product->delete();
     }
     if (FEUsersHelper::isCurrentUser($id)) {
         Session::flush('current_user');
     }
     $user->delete();
     Session::flash('status', true);
     Session::flash('messages', array('Đã xóa user'));
     return Redirect::route('admin.user.index');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $exchange = Exchange::find($id);
     $respone = Input::get('respone');
     if (FEUsersHelper::isCurrentUser($exchange->r_user_id && $respone)) {
         if ($respone == 'Đồng ý') {
             Session::flash('messages', array('Đã xác nhận trao đổi'));
             $exchange->status = 1;
         } elseif ($respone == 'Xóa') {
             Session::flash('messages', array('Đã hủy yêu cầu trao đổi'));
             $exchange->status = -1;
         }
         $exchange->save();
         Session::flash('status', true);
         return Redirect::to('exchange?user_id=' . $exchange->r_user_id . '&action=receive');
     } else {
         return Redirect::to('/');
     }
 }
 public function update($id)
 {
     $album = Album::find($id);
     if (FEUsersHelper::isCurrentUser($album->id)) {
         $album->title = Input::get('title');
         $album->privacy = Input::get('privacy');
         $album->save();
         FEEntriesHelper::updatePrivacy($album->id, 2, Input::get('privacy'));
     }
     return Redirect::back();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $product = Product::find($id);
     if (FEUsersHelper::isCurrentUser($product->user->id)) {
         $product->delete();
         Session::flash('status', true);
         Session::flash('messages', array('Đã xóa'));
     }
     return Redirect::to('/');
 }