Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Controller_Admin_Users extends Controller_Admin_Authcheck {
- // public $title = 'Novum » ';
- public function before()
- {
- parent::before();
- $this->template->link_group_id = 1;
- $this->template->menu_links = Model_Link::find()->where('link_group_id',$this->template->link_group_id)->get();
- $this->template->left_menu_name = Model_Link_Group::find($this->template->link_group_id);
- /*if (!Session::get('user')){
- Response::redirect('admin');
- }*/
- }
- public function action_index()
- {
- $data['users'] = Model_User::find('all');
- $this->template->title = $this->title . 'Panel użytkowników';
- $this->template->content = View::factory('admin/users/index', $data);
- }
- public function action_view($id = null)
- {
- $data['user'] = Model_User::find($id);
- $this->template->title = $this->title . 'User';
- $this->template->content = View::factory('admin/users/view', $data);
- }
- public function action_create($id = null)
- {
- if (Input::method() == 'POST')
- {
- $role_id=!Input::post('role_id') ? $role_id=3 : Input::post('role_id'); // 3 = Pracownika
- $group_id=!Input::post('group_id') ? $group_id=4 : Input::post('group_id'); // 4 = Novum
- $user = Model_User::factory(array(
- 'name' => Input::post('name'),
- 'login' => Inflector::friendly_title(Inflector::ascii(Input::post('name')),'_',true), // tworzy imie_nazwisko
- 'pass' => Str::random('alnum',8),
- 'phone' => Input::post('phone'),
- 'mail' => Input::post('mail'),
- 'role_id' => $role_id,
- 'group_id' => $group_id,
- 'active' => 0,
- ));
- if ($user and $user->save())
- {
- Session::set_flash('success', 'Dodano user ID#' . $user->id . '.');
- Response::redirect('admin/users');
- }
- else
- {
- Session::set_flash('notice', 'Nie można było zapisać user.');
- }
- }
- $this->template->title = $this->title . 'Panel użytkowników';
- $this->template->content = View::factory('admin/users/create');
- }
- public function action_edit($id = null)
- {
- $user = Model_User::find($id);
- if (Input::method() == 'POST')
- {
- $user->name = Input::post('name');
- $user->login = Input::post('login');
- $user->pass = Input::post('pass');
- $user->phone = Input::post('phone');
- $user->mail = Input::post('mail');
- $user->last_login = Input::post('last_login');
- $user->registered = Input::post('registered');
- $user->role_id = Input::post('role_id');
- $user->group_id = Input::post('group_id');
- $user->active = Input::post('active');
- if ($user->save())
- {
- Session::set_flash('success', 'Zaktualizowano user ID#' . $id);
- Response::redirect('admin/users');
- }
- else
- {
- Session::set_flash('notice', 'Nie udało się zaktualizować user ID#' . $id);
- }
- }
- else
- {
- $this->template->set_global('user', $user);
- }
- $this->template->title = $this->title . 'Panel użytkowników';
- $this->template->content = View::factory('admin/users/edit');
- }
- public function action_delete($id = null)
- {
- if ($user = Model_User::find($id))
- {
- $user->delete();
- Session::set_flash('success', 'Skasowano user #' . $id);
- }
- else
- {
- Session::set_flash('notice', 'Nie można było skasować user #' . $id);
- }
- Response::redirect('admin/users');
- }
- }
- /* End of file users.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement