public function add() { $this->checkPageAction($this->page_id, Action::$Add); if (Request::ajax()) { if (Input::has('actionType')) { switch (Input::get('actionType')) { case 'checkGroupName': if (Input::has('group_name') && Input::has('company_id')) { $group_name = Input::get('group_name'); $company_id = Input::get('company_id'); $group = Group::where(array('group_name' => $group_name, 'company_id' => $company_id))->get(); if (count($group) > 0) { return 'false'; } } return 'true'; break; case 'addGroup': if (Request::isMethod('post') && Input::has('company_id') && Input::has('group_name') && Input::has('data')) { $data = json_decode(Input::get('data'), TRUE); $group_name = Input::get('group_name'); $company_id = Input::get('company_id'); $group = Group::where(array('group_name' => $group_name, 'company_id' => $company_id))->get(); if (count($group) > 0 || count($data) == 0) { return json_encode(array('msg' => 'Unable to add group, Please try again later!')); } else { $group = new Group(); $group->group_name = $group_name; $group->company_id = $company_id; if ($group->save()) { //$group_id = $group->group_id; $permissions = array(); foreach ($data as $permission_data) { $permissions[] = new Permission($permission_data); } if ($group->permission()->saveMany($permissions)) { return json_encode(array('status' => 'true', 'msg' => 'Successfully Added Group!')); } else { $group->delete(); return json_encode(array('status' => 'false', 'msg' => 'Unable To Add Group!')); } } return json_encode(array('status' => 'false', 'msg' => 'Unable To Add Group!')); } } return json_encode(array('status' => 'false', 'msg' => 'Invalid Request!')); break; } } } $user = User::find(Auth::id()); $group_id = $user->group_id; $company_id = $user->group->company_id; return view('content.setting.group.form.group_form', array('group_id' => $group_id, 'company_id' => $company_id)); }
public function edit($id) { $this->checkPageAction($this->page_id, Action::$Edit); if (!User::find($id) || User::find($id)->remove_status == 'Active') { $this->diplayError(404); } if (Request::ajax() && Input::has('actionType')) { $responce = array(); switch (Input::get('actionType')) { case 'groupList': $group_list = array(); if (Input::has('company_id')) { $user = User::find(Auth::id()); if ($user->group->group_name != 'Admin') { $groups[] = $user->group; } else { $company_id = Input::get('company_id'); $groups = Group::where('company_id', $company_id)->get(); } foreach ($groups as $group) { $group_list[] = array('id' => $group->group_id, 'text' => $group->group_name); } } return json_encode($group_list); break; case 'status': $responce['status'] = false; if (User::updateStatus($id)) { $responce['status'] = true; } return json_encode($responce); break; case 'resetPwd': $responce['msg'] = 'Failed in reseting password!'; if (User::resetPassword($id)) { $responce['msg'] = 'Successfully reset password!'; } return json_encode($responce); break; case 'updateUser': if (Request::isMethod('post') && Input::has('user') && Input::has('userinfo')) { if (!User::find($id)) { return json_encode(array('msg' => 'Unable to find user, Please try again later!')); } else { $user_detail = json_decode(Input::get('user'), TRUE); $userInfo = json_decode(Input::get('userinfo'), TRUE); $user = User::find($id); if (!$this->checkUserValidation($id)) { return json_encode(array('status' => 'false', 'msg' => 'Unable to update user due to some restrictions!')); } $prevData = $user->toArray(); $user->fill($user_detail); if ($user->save()) { $user->userinfo->fill($userInfo); if ($user->userinfo->save()) { return json_encode(array('status' => 'true', 'msg' => 'Successfully Updated User!')); } else { $user->fill($prevData); $user->save(); return json_encode(array('status' => 'false', 'msg' => 'Unable To Update User!')); } } return json_encode(array('status' => 'false', 'msg' => 'Unable To Update User!')); } } break; } } $user = User::find(Auth::id()); $company_id = $user->group->company_id; return view('content.setting.users.form.user_form', array('company_id' => $company_id, 'user_data' => User::find($id))); }