public function updateLevel(Request $request) { $user = User::with(['level', 'courses' => function ($query) { $query->where('level', '1')->where('validated', 1); }])->where('id', $request->id)->first(); $oldLevel = ucfirst($user->level->name); if (Auth::check()) { if (Auth::user()->id != $user->id) { if (Auth::user()->level_id == 5 || Auth::user()->level_id == 4 && $user->level_id < 4) { if ($request->level < 3 && $user->courses->count() > 0) { Flash::error('Impossible de rétrograder cet utilisateur à ce level car il est professeur de ' . $user->courses->count() . ' cours.'); return Redirect::back(); } $newLevel = ucfirst(Level::find($request->level)->name); $modif = $user->level_id > $request->level ? 'downgraded' : 'upgraded'; $user->level_id = $request->level; $user->save(); Flash::success('Le changement a été effectué avec succès.'); makeModification('users', printUserLinkV2($user) . ' as been ' . $modif . ' from ' . $oldLevel . ' to ' . $newLevel . '.'); return Redirect::back(); } } } Flash::error('Vous n\'avez pas les droits nécéssaires pour cela.'); return Redirect::back(); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $level_id = Auth::user()->level_id; $role_id = Level::find($level_id)->role_id; $role = Role::find($role_id); if ($role->name != 'SystemAdmin') { return redirect()->route('admin.department.index')->with('message', 'Access deny!'); } return $next($request); }
public function levelDel(Request $request) { $level = $request->input("level"); $readerNum = Reader::where('level', '=', $level)->count(); if ($readerNum > 0) { return redirect("/admin/levelManage")->with("msg", "还有用户在此等级,无法删除!"); } $l = Level::find($level); $l->delete(); return redirect("/admin/levelManage")->with("msg", "删除成功!"); }
public function clear(Request $request) { foreach ($request->input('checkbox') as $key => $value) { $model = Level::find($value); $model->delete(); } return redirect()->route('admin.level.index')->with('success', 'successfully deleted'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(UpdateStaffRequest $request, $id) { $department = $request->department; $position = $request->position; $level = $request->level; //is manager if (Gate::allows('check-manager')) { $this->validate($request, ['department' => 'required|numeric|not_in:0']); if ($id == Auth::user()->id) { $department = 0; } else { $department = $request->department; } } else { if (Gate::allows('check-leader')) { $department = Auth::user()->department_id; } else { if (Gate::allows('check-admin')) { $this->validate($request, ['department' => 'required|numeric|not_in:0']); $temp1 = (int) $request->level; $role = Level::find($temp1); if ($role->role_id == 2) { $department = 0; $position = 0; } else { $department = $request->department; } } else { $department = Auth::user()->department_id; $position = Auth::user()->position_id; $level = Auth::user()->level_id; } } } if ($id == Auth::user()->id) { $department = Auth::user()->department_id; $position = Auth::user()->position_id; $level = Auth::user()->level_id; $request->rActive = 1; } $birth = date('Y-m-d', strtotime($request->txtBirth)); $staff = Staff::find($id); $staff->name = $request->txtName; $staff->phone = $request->txtPhone; $staff->birthday = $birth; $staff->position_id = $position; $staff->level_id = $level; $staff->department_id = $department; $staff->active = $request->rActive; $staff->save(); return redirect()->route('admin.staff.edit', $id)->with('message', 'Update profile success'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { try { $lv = Level::find($id); $lv->delete(); \Session::flash('sucess_message', 'Level is sucessfully DELETED.'); } catch (Exception $e) { \Session::flash('error_message', 'Oops!! Level could not DELETED.'); } return redirect('myAdmin/levels'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $level = Level::find($id); $level->delete(); return redirect()->route('admin.level.index')->with('message', 'Delete level success!'); }
public function clear(Request $request) { if (\Auth::user()->role_id != 4) { return view('html.error-403'); } foreach ($request->input('checkbox') as $key => $value) { $model = Level::find($value); $model->delete(); } return redirect()->route('admin.level.index')->with('success', 'successfully deleted'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make([$request->all(), 'nom_classe' => $request->nom_classe, 'capacite_classe' => $request->capacite_classe, 'niveau' => $request->niveau, 'branche' => $request->branche, 'grade' => $request->grade], ['nom_classe' => 'required', 'capacite_classe' => 'required|integer', 'grade' => 'required|integer'], ['nom_classe.required' => "le nom de la classe est requis", 'capacite_classe.required' => "la capacité de la classe est requis", 'capacite_classe.integer' => "la capacité de la classe doit etre un nombre entier", 'niveau.integer' => "Le Niveau est requis", 'grade.integer' => "Le Niveau Global est requis"]); if ($validator->passes()) { $niveau_global = \Auth::user()->grades()->where('id', $request->grade)->first()->name; $cr = new Classroom(); $cr->nom_classe = $request->nom_classe; $cr->code_classe = $request->code_classe; $cr->capacite_classe = $request->capacite_classe; $cr->niveau = $request->niveau; $cr->school_year_id = $request->ann_scol; if ($niveau_global == 'Lycée') { $cr->branche = $request->branche; } else { $cr->branche = ''; } $cr->user_id = \Auth::user()->id; $cr->save(); $ts = new Timesheet(); $ts->user_id = \Auth::user()->id; $ts->classroom_id = $cr->id; $ts->school_year_id = $request->ann_scol; $ts->save(); $level = Level::find($request->niveau); if ($niveau_global == 'Lycée') { DB::table('branch_classroom_level')->insert(['classroom_id' => $cr->id, 'branch_id' => $request->branche, 'level_id' => $level->id]); } else { $level->lesClasses()->attach([$cr->id]); } if ($cr) { if (isset($request->select)) { $classe = Classroom::where('user_id', \Auth::user()->id)->where('id', $cr->id)->first(); $classe->matters()->attach($request->select); } } return redirect()->action('StatisticsController@gestion')->with('success', 'Informations bien enregistrées'); } else { return redirect()->back()->withErrors($validator); } }
public function removeMember(Request $request, $id) { $user = User::find($request->id); $user->update(['level_id' => 1]); $user->sendNotification('Vous êtes maintenant <b>Membre</b>.'); $name = Level::find($id)->name; Modification::create(['table' => 'levels', 'user_id' => Auth::user()->id, 'message' => 'removed ' . $user->first_name . ' ' . $user->last_name . ' from level ' . ucfirst($name) . 's']); Flash::success($user->first_name . ' ' . $user->last_name . ' a bien été retiré des ' . ucfirst($name) . 's'); return Redirect::back(); }
public function bookBorrowAction(Request $request) { $date = date("Y-m-d"); $reader_id = $request->input("reader-id"); $isbn = $request->input("isbn"); $reader = Reader::find($reader_id); //对输入信息进行检查 if ($reader == null) { return redirect('/admin/bookBorrow')->with("msg", "读者证编号有误,请检查!"); } if ($reader['loss'] == true) { //挂失处理 return redirect('/admin/bookBorrow')->with("msg", "该借书证已挂失,请先解挂后再借书!"); } $book = Book::where("isbn", '=', $isbn)->first(); if ($book == null) { return redirect('/admin/bookBorrow')->with("msg", "图书ISBN有误,请检查!"); } if ($book['quantity-in'] - $book['quantity-out'] - $book['quantity-loss'] < 1) { return redirect('/admin/bookBorrow')->with("msg", "图书数量不足,请检查ISBN!"); } $level = Level::find($reader['level']); $borrowedBookNum = Borrow::where("reader-id", '=', $reader_id)->where("returned", '=', false)->where('loss', '<>', true)->get()->count(); if ($borrowedBookNum >= $level['numbers']) { //借书数量限制 return redirect('/admin/bookBorrow')->with("msg", "该用户借书数量超过限制,请先归还部分图书!"); } $book['quantity-out'] += 1; $book->save(); $borrow = new Borrow(); $shouldReturnDate = date("Y-m-d", strtotime("+" . $level['days'] . " days")); $borrow['reader-id'] = $reader_id; $borrow['book-id'] = $book['book-id']; $borrow['date-borrow'] = $date; $borrow['date-should-return'] = $shouldReturnDate; $borrow->save(); return redirect('/admin/bookBorrow')->with("msg", "借阅成功!"); }