Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.39 KB | None | 0 0
  1. <?php
  2. class Controller_Admin_Users extends Controller_Admin_Authcheck {
  3.  
  4.       //  public $title = 'Novum &raquo; ';
  5.     public function before()
  6.     {
  7.         parent::before();
  8.  
  9.         $this->template->link_group_id = 1;
  10.         $this->template->menu_links =  Model_Link::find()->where('link_group_id',$this->template->link_group_id)->get();
  11.         $this->template->left_menu_name = Model_Link_Group::find($this->template->link_group_id);
  12.  
  13.         /*if (!Session::get('user')){
  14.             Response::redirect('admin');
  15.         }*/
  16.     }
  17.     public function action_index()
  18.     {
  19.         $data['users'] = Model_User::find('all');
  20.         $this->template->title = $this->title . 'Panel użytkowników';
  21.         $this->template->content = View::factory('admin/users/index', $data);
  22.     }
  23.  
  24.     public function action_view($id = null)
  25.     {
  26.         $data['user'] = Model_User::find($id);
  27.  
  28.         $this->template->title = $this->title . 'User';
  29.         $this->template->content = View::factory('admin/users/view', $data);
  30.     }
  31.  
  32.     public function action_create($id = null)
  33.     {
  34.         if (Input::method() == 'POST')
  35.         {
  36.             $role_id=!Input::post('role_id') ? $role_id=3 : Input::post('role_id'); // 3 = Pracownika
  37.             $group_id=!Input::post('group_id') ? $group_id=4 : Input::post('group_id'); // 4 = Novum
  38.             $user = Model_User::factory(array(
  39.                 'name' => Input::post('name'),
  40.                 'login' => Inflector::friendly_title(Inflector::ascii(Input::post('name')),'_',true), // tworzy imie_nazwisko
  41.                 'pass' => Str::random('alnum',8),
  42.                 'phone' => Input::post('phone'),
  43.                 'mail' => Input::post('mail'),
  44.                 'role_id' => $role_id,
  45.                 'group_id' => $group_id,
  46.                 'active' => 0,
  47.             ));
  48.  
  49.             if ($user and $user->save())
  50.             {
  51.                 Session::set_flash('success', 'Dodano user ID#' . $user->id . '.');
  52.  
  53.                 Response::redirect('admin/users');
  54.             }
  55.  
  56.             else
  57.             {
  58.                 Session::set_flash('notice', 'Nie można było zapisać user.');
  59.             }
  60.         }
  61.  
  62.         $this->template->title = $this->title . 'Panel użytkowników';
  63.         $this->template->content = View::factory('admin/users/create');
  64.     }
  65.  
  66.     public function action_edit($id = null)
  67.     {
  68.         $user = Model_User::find($id);
  69.  
  70.         if (Input::method() == 'POST')
  71.         {
  72.             $user->name = Input::post('name');
  73.             $user->login = Input::post('login');
  74.             $user->pass = Input::post('pass');
  75.             $user->phone = Input::post('phone');
  76.             $user->mail = Input::post('mail');
  77.             $user->last_login = Input::post('last_login');
  78.             $user->registered = Input::post('registered');
  79.             $user->role_id = Input::post('role_id');
  80.             $user->group_id = Input::post('group_id');
  81.             $user->active = Input::post('active');
  82.  
  83.             if ($user->save())
  84.             {
  85.                 Session::set_flash('success', 'Zaktualizowano user ID#' . $id);
  86.  
  87.                 Response::redirect('admin/users');
  88.             }
  89.  
  90.             else
  91.             {
  92.                 Session::set_flash('notice', 'Nie udało się zaktualizować user ID#' . $id);
  93.             }
  94.         }
  95.  
  96.         else
  97.         {
  98.             $this->template->set_global('user', $user);
  99.         }
  100.  
  101.         $this->template->title = $this->title . 'Panel użytkowników';
  102.         $this->template->content = View::factory('admin/users/edit');
  103.     }
  104.  
  105.     public function action_delete($id = null)
  106.     {
  107.         if ($user = Model_User::find($id))
  108.         {
  109.             $user->delete();
  110.  
  111.             Session::set_flash('success', 'Skasowano user #' . $id);
  112.         }
  113.  
  114.         else
  115.         {
  116.             Session::set_flash('notice', 'Nie można było skasować user #' . $id);
  117.         }
  118.  
  119.         Response::redirect('admin/users');
  120.     }
  121.  
  122.  
  123. }
  124.  
  125. /* End of file users.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement