daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Aug 20th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * Administrator tool for managing role permissions
  4. *
  5. * @author Patrick Tinsley
  6. */
  7. class Administer_permissions extends MY_Controller
  8. {
  9.     function Administer_permissions()
  10.     {
  11.         parent::MY_Controller();
  12.  
  13.         // Load Libraries
  14.         $this->load->library('Form_validation');
  15.  
  16.         // Load Helpers
  17.         $this->load->helper('form');
  18.  
  19.         // Load modules
  20.         $this->load->model('dx_auth/permissions', 'permissions');
  21.         $this->load->model('dx_auth/roles', 'roles');
  22.     }
  23.  
  24.     function index()
  25.     {
  26.         //if they don't have permission, kick them back
  27.         if ( ! $this->dx_auth->get_permission_value('administer_permissions'))
  28.         {
  29.             $data['refresh']['timer'] = 3;
  30.             $data['refresh']['url'] = '';
  31.             $data['page_content'] = 'You do not have permission to edit permissions.';
  32.             $this->load->view('plain_view', $data);
  33.             return;
  34.         }
  35.  
  36.         // Default role_id that will be showed
  37.         $role_id = $this->input->post('role') ? $this->input->post('role') : 1;
  38.  
  39.         /* Get post input and apply it to database */
  40.  
  41.         // If button save pressed
  42.         if ($this->input->post('save'))
  43.         {
  44.             // Convert back text area into array to be stored in permission data
  45.             $allowed_uris = explode("\n", $this->input->post('allowed_uris'));
  46.  
  47.             // Remove white space if available
  48.             array_map('trim', $allowed_uris);
  49.  
  50.             // Get role_id permission data first.
  51.             // So the previously set permission array key won't be
  52.             // overwritten with new array with key $key only,
  53.             // when calling set_permission_data later.
  54.             $permission_data = $this->permissions->get_permission_data($this->input->post('role'));
  55.  
  56.             // Set value in permission data array
  57.  
  58.             // User Permissions
  59.             $permission_data['administer_users'] = $this->input->post('administer_users');
  60.             $permission_data['add_users'] = $this->input->post('add_users');
  61.             $permission_data['delete_users'] = $this->input->post('delete_users');
  62.             $permission_data['edit_users'] = $this->input->post('edit_users');
  63.  
  64.             // Project Permissions
  65.             $permission_data['administer_projects'] = $this->input->post('administer_projects');
  66.             $permission_data['create_project'] = $this->input->post('create_project');
  67.             $permission_data['delete_project'] = $this->input->post('delete_project');
  68.             $permission_data['upload_project_file'] = $this->input->post('upload_project_file');
  69.             $permission_data['map_users_to_project'] = $this->input->post('map_users_to_project');
  70.             $permission_data['administer_scos'] = $this->input->post('administer_scos');
  71.  
  72.             // Permissions permissions, lol
  73.             $permission_data['administer_permissions'] = $this->input->post('administer_permissions');
  74.             $permission_data['uri'] = $allowed_uris;
  75.  
  76.             // Set URI permission data
  77.             // IMPORTANT: uri permission data, is saved using 'uri' as key.
  78.             // So this key name is preserved, if you want to use custom permission use other key.
  79.             $this->permissions->set_permission_value($role_id, 'uri', $allowed_uris);
  80.  
  81.             // Set permission data for role_id
  82.             $this->permissions->set_permission_data($role_id, $permission_data);
  83.         }
  84.  
  85.         /* Showing page to user */
  86.  
  87.         // Get all role from database
  88.         $data['roles'] = $this->roles->get_all()->result();
  89.  
  90.         // Get permissions
  91.         $data['administer_users'] = $this->permissions->get_permission_value($role_id,
  92.                                                                               'administer_users');
  93.         $data['add_users'] = $this->permissions->get_permission_value($role_id,
  94.                                                                          'add_users');
  95.         $data['delete_users'] = $this->permissions->get_permission_value($role_id,
  96.                                                                            'delete_users');
  97.         $data['edit_users'] = $this->permissions->get_permission_value($role_id,
  98.                                                                          'edit_users');
  99.         $data['administer_projects'] = $this->permissions->get_permission_value($role_id,
  100.                                                                                  'administer_projects');
  101.         $data['create_project'] = $this->permissions->get_permission_value($role_id,
  102.                                                                              'create_project');
  103.         $data['delete_project'] = $this->permissions->get_permission_value($role_id,
  104.                                                                              'delete_project');
  105.         $data['map_users_to_project'] = $this->permissions->get_permission_value($role_id,
  106.                                                                                    'map_users_to_project');
  107.         $data['administer_scos'] = $this->permissions->get_permission_value($role_id, 'administer_scos');
  108.         $data['administer_permissions'] = $this->permissions->get_permission_value($role_id,
  109.                                                                                   'administer_permissions');
  110.         $data['upload_project_file'] = $this->permissions->get_permission_value($role_id,
  111.                                                                                   'upload_project_file');
  112.  
  113.         // Get allowed uri permissions
  114.         $data['allowed_uris'] = $this->permissions->get_permission_value($role_id,
  115.         'uri');
  116.  
  117.         // Load view
  118.         $data['page_content'] = $this->load->view('backend/custom_permissions', $data, TRUE);
  119.  
  120.  
  121.         $data['page_content_title'] = 'Administer Permissions';
  122.  
  123.         $this->load->view('main_view', $data);
  124.     }
  125. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top