-
-
Save PrimozRome/24e98a1822941f4fddd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function action_update($id = null) | |
{ | |
$errors = null; | |
$user = Model_User::find($id); | |
if(!$user) | |
{ | |
Session::set_flash('error', 'User with does not exist'); | |
Response::redirect('users'); | |
} | |
else | |
{ | |
if (Input::method() == 'POST') | |
{ | |
try | |
{ | |
// create user | |
$user->username = Input::post('email'); | |
$user->email = Input::post('email'); | |
$user->password = Input::post('password'); | |
$user->profile->lastname = Input::post('lastname'); | |
$user->profile->company = Input::post('company'); | |
$user->profile->address1 = Input::post('address1'); | |
$user->profile->address2 = Input::post('address2'); | |
$user->profile->post = Input::post('post'); | |
$user->profile->city = Input::post('city'); | |
$user->profile->country_id = Input::post('country_id'); | |
$user->profile->state_id = Input::post('state_id'); | |
$user->profile->phone = Input::post('phone'); | |
$user->profile->vatid = Input::post('vatid'); | |
$user->profile->subscription = Input::post('subscription'); | |
$user->profile->saop_code = Input::post('saop_code'); | |
$permissions = \Model_Permission::find('all'); | |
foreach($permissions as $permission): | |
echo $permission->id.'<br/>'; | |
if(in_array($permission->id, Input::post('permissions', array()))) | |
{ | |
$user->permissions[$permission->id] = $permission; | |
} | |
else | |
{ | |
unset($user->permissions[$permission->id]); | |
} | |
endforeach; | |
die(); | |
$roles = \Model_Role::find('all'); | |
foreach($roles as $role): | |
if(in_array($role->id, Input::post('roles'))) | |
{ | |
$user->roles[$role->id] = $role; | |
} | |
else | |
{ | |
unset($user->roles[$role->id]); | |
} | |
endforeach; | |
if ($user->save()) | |
{ | |
Session::set_flash('success', 'User »' . $user->profile->get_full_name() . '« updated'); | |
Model_Activity::create_activity($this->current_user->id, Inflector::singularize(Uri::segment(1)), $id, Uri::segment(2)); | |
//Response::redirect('users'); | |
} | |
else | |
{ | |
Session::set_flash('error', 'There was error updating user.'); | |
} | |
} | |
catch (Orm\ValidationFailed $e) | |
{ | |
Session::set_flash('error', 'There was error updating user. Check input data.'); | |
$errors = $e->get_fieldset(); | |
if($errors) | |
{ | |
$errors = $errors->error(); | |
} | |
else | |
{ | |
$errors['password'] = true; | |
} | |
} | |
} | |
$view = View::forge('users/form'); | |
$view->errors = $errors; | |
$view->permissions = Model_Permission::get_permissions(); | |
$view->user = $user; | |
$this->template->title = $view->title = 'Users » Update'; | |
$this->template->content = $view; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment