Example #1
0
 public function action_add()
 {
     $this->template->title = 'Add Role';
     //print_r($data['roles']);
     $data = array();
     if ($_POST) {
         $role = new Model_Role();
         $post = $role->validate_create($_POST);
         if ($post->check()) {
             $values = $post->as_array();
             unset($post);
             $role->name = $values['name'];
             $role->description = $values['description'];
             $role->save();
             Request::instance()->redirect('role/index');
         } else {
             #Get errors for display in view
             $data['errors'] = $post->errors('racl/role/add', TRUE);
             #Repopulate $_POST data
             $_POST = $post->as_array();
         }
     }
     //
     $this->template->content = View::factory('racl/role/add', $data);
 }
Example #2
0
 /**
  * CRUD controller: UPDATE
  */
 public function action_update()
 {
     $id_role = $this->request->param('id');
     //we do not allow modify the admin
     if ($id_role == Model_Role::ROLE_ADMIN) {
         Alert::set(Alert::WARNING, __('Admin Role can not be modified!'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'role')));
     }
     $this->template->title = __('Update') . ' ' . __($this->_orm_model) . ' ' . $id_role;
     $role = new Model_Role($id_role);
     if ($this->request->post() and $role->loaded()) {
         //delete all the access
         DB::delete('access')->where('id_role', '=', $role->id_role)->execute();
         //set all the access where post = on
         foreach ($_POST as $key => $value) {
             if ($value == 'on') {
                 DB::insert('access', array('id_role', 'access'))->values(array($role->id_role, str_replace('|', '.', $key)))->execute();
             }
         }
         //saving the role params
         $role->name = core::post('name');
         $role->description = core::post('description');
         $role->save();
         Alert::set(Alert::SUCCESS, __('Item updated'));
         $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller())));
     }
     //getting controllers actions
     $controllers = Model_Access::list_controllers();
     //get all the access this user has
     $query = DB::select('access')->from('access')->where('id_role', '=', $id_role)->execute();
     $access_in_use = array_keys($query->as_array('access'));
     // d(in_array('access_index',$access_in_use));
     //d($access_in_use);
     return $this->render('oc-panel/pages/role/update', array('role' => $role, 'controllers' => $controllers, 'access_in_use' => $access_in_use));
 }