Ejemplo n.º 1
0
 public function findUserDetailByEmpCode($emp_code = null)
 {
     //function to find all company name
     App::import("Model", "UserDetail");
     $model = new UserDetail();
     $query = $model->find('all', array('fields' => array('user_name', 'email'), 'conditions' => array('UserDetail.emp_code' => $emp_code)));
     if (empty($query)) {
         return 0;
     } else {
         return $query;
     }
 }
Ejemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id = FALSE)
 {
     // Assign $id if FALSE
     if ($id === FALSE) {
         $id = $this->user->id;
     }
     // Check if self or admin
     if ($this->user['id'] == $id || $this->user->hasAccess('user.all')) {
         // Validate the create form
         $validator = Validator::make(Input::all(), array('first_name' => 'required', 'last_name' => 'required', 'company_name' => 'required', 'work_phone' => 'required', 'mobile_phone' => 'required', 'address' => 'required', 'city' => 'required', 'state' => 'required', 'zip' => 'required'));
         if ($validator->fails()) {
             return Redirect::back()->withInput()->withErrors($validator);
         } else {
             // Update UserDetail with Post Values
             try {
                 // Get the user
                 $user = Sentry::findUserByID($id);
                 // Update UserDetail
                 $user_detail = UserDetail::find($user->id);
                 $user_detail->first_name = Input::get('first_name');
                 $user_detail->last_name = Input::get('last_name');
                 $user_detail->company_name = Input::get('company_name');
                 $user_detail->address = Input::get('address');
                 $user_detail->address2 = Input::get('address2');
                 $user_detail->city = Input::get('city');
                 $user_detail->state = Input::get('state');
                 $user_detail->zip = Input::get('zip');
                 $user_detail->country = Input::get('country');
                 $user_detail->work_phone = Input::get('work_phone');
                 $user_detail->mobile_phone = Input::get('mobile_phone');
                 $user_detail->save();
                 // Only Admin users can update a user's groups
                 if ($this->user->hasAccess('user.all')) {
                     // Get groups
                     $group_client = Sentry::findGroupByName('client');
                     $group_staff = Sentry::findGroupByName('staff');
                     $group_admin = Sentry::findGroupByName('admin');
                     // Client group
                     if (Input::has($group_client->name)) {
                         if (!$user->inGroup($group_client)) {
                             $user->addGroup($group_client);
                         }
                     } else {
                         if ($user->inGroup($group_client)) {
                             $user->removeGroup($group_client);
                         }
                     }
                     // Staff group
                     if (Input::has($group_staff->name)) {
                         if (!$user->inGroup($group_staff)) {
                             $user->addGroup($group_staff);
                         }
                     } else {
                         if ($user->inGroup($group_staff)) {
                             $user->removeGroup($group_staff);
                         }
                     }
                     // Admin group
                     if (Input::has($group_admin->name)) {
                         if (!$user->inGroup($group_admin)) {
                             $user->addGroup($group_admin);
                         }
                     } else {
                         if ($user->inGroup($group_admin)) {
                             $user->removeGroup($group_admin);
                         }
                     }
                 }
                 Session::flash('alert_success', 'User Details Updated Successfully.');
                 return Redirect::to('/user/' . $user->id);
             } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
                 Session::flash('alert_danger', 'User Details Update Failed.');
                 return Redirect::to('/dashboard');
             } catch (Cartalyst\Sentry\Users\UserExistsException $e) {
                 Session::flash('alert_danger', 'User Details Update Failed.');
                 return Redirect::to('/dashboard');
             } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
                 Session::flash('alert_danger', 'User not found.');
                 return Redirect::to('/dashboard');
             } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
                 Session::flash('alert_danger', 'One of the User Groups was not found.');
                 return Redirect::to('/dashboard');
             }
         }
     } else {
         Session::flash('alert_danger', 'Access denied.');
         return Redirect::to('dashboard');
     }
 }