title: Ion auth only show users in certain group
body: <p>I have installed a user management with Ion auth in codeigniter. Now i'm facing the following challenge. </p>
  
  <p>When logged in and visiting the auto/index page an overview of users is shown. I'm using 3 different admin levels. Each user is connected to a company. (the company id is added in the users_groups table)</p>
  
  <p>Admin
  company-admin
  company-user</p>
  
  <p>The super admin should see all the users,
  The Admin should only see the users which are also in the same company
  The user has got no access to the auth/index (that already works)</p>
  
  <p>How can I create a page in such a way that a Admin only sees his company users. Below an examaple of the index function of my auth.php controller.</p>
  
  <pre><code>//redirect if needed, otherwise display the user list
  function index()
  {
  
      if (!$this-&gt;ion_auth-&gt;logged_in())
      {
          //redirect them to the login page
          redirect('dashboard/', 'refresh');
      }
      elseif ($this-&gt;ion_auth-&gt;in_group('company-user')) 
      {
          //redirect them to the home page because they must be an administrator to view this
          redirect('dashboard/', 'refresh');
  
  
          //set the flash data error message if there is one
          $this-&gt;data['message'] = (validation_errors()) ? validation_errors() : $this-&gt;session-&gt;flashdata('message');
  
          //list the users
          $this-&gt;data['users'] = $this-&gt;ion_auth-&gt;users()-&gt;result();
          foreach ($this-&gt;data['users'] as $k =&gt; $user)
          {
              $this-&gt;data['users'][$k]-&gt;groups = $this-&gt;ion_auth-&gt;get_users_groups($user-&gt;id)-&gt;result();              
          }           
          foreach ($this-&gt;data['users'] as $k =&gt; $user)
          {
              $this-&gt;data['users'][$k]-&gt;companies = $this-&gt;ion_auth-&gt;get_company($user-&gt;id)-&gt;result();        
          }           
  
  
      }
      elseif ($this-&gt;ion_auth-&gt;logged_in() &amp;&amp; $this-&gt;ion_auth-&gt;in_group("company-admin"))
      {
          //set the flash data error message if there is one
          $this-&gt;data['message'] = (validation_errors()) ? validation_errors() : $this-&gt;session-&gt;flashdata('message');
  
          //list the users
          $this-&gt;data['users'] = $this-&gt;ion_auth-&gt;users()-&gt;result();
          foreach ($this-&gt;data['users'] as $k =&gt; $user)
          {
              $this-&gt;data['users'][$k]-&gt;groups = $this-&gt;ion_auth-&gt;get_users_groups($user-&gt;id)-&gt;result();
          }
          foreach ($this-&gt;data['users'] as $k =&gt; $user)
          {
              $this-&gt;data['users'][$k]-&gt;companies = $this-&gt;ion_auth-&gt;get_company($user-&gt;id)-&gt;result();
          }
  
  
          $this-&gt;_render_page('admin/auth/index', $this-&gt;data);
      }       
      else
      {
          //set the flash data error message if there is one
          $this-&gt;data['message'] = (validation_errors()) ? validation_errors() : $this-&gt;session-&gt;flashdata('message');
  
          //list the users
          $this-&gt;data['users'] = $this-&gt;ion_auth-&gt;users()-&gt;result();
          foreach ($this-&gt;data['users'] as $k =&gt; $user)
          {
              $this-&gt;data['users'][$k]-&gt;groups = $this-&gt;ion_auth-&gt;get_users_groups($user-&gt;id)-&gt;result();
          }
          foreach ($this-&gt;data['users'] as $k =&gt; $user)
          {
              $this-&gt;data['users'][$k]-&gt;companies = $this-&gt;ion_auth-&gt;get_company($user-&gt;id)-&gt;result();
          }
  
          $this-&gt;_render_page('admin/auth/index', $this-&gt;data);
      }
  }
  </code></pre>
  
  <p>Does anyone know what i've got to add to the elseif ($this->ion_auth->in_group("company-admin")) part in order to only show the users in the same company as the company-admin?</p>
  
  <p>//////////////////////////////////////////////////////</p>
  
  <p>Thanks for the answer. Now i've made the following changes:</p>
  
  <p>I'm answering this way, to have the possibility to show code. I have changed my controller but still see users from other companies. I have changed this as following:</p>
  
  <pre><code>elseif ($this-&gt;ion_auth-&gt;in_group("company-admin"))
      {
          //set the flash data error message if there is one
          $this-&gt;data['message'] = (validation_errors()) ? validation_errors() : $this-&gt;session-&gt;flashdata('message');
  
          // Check the company the user is in
          $user_in_company = $this-&gt;ion_auth-&gt;get_users_companies(); // Return array groups
  
          //list the users
          $this-&gt;data['users'] = $this-&gt;ion_auth-&gt;users()-&gt;result($user_in_company);
          foreach ($this-&gt;data['users'] as $k =&gt; $user)
          {
              $this-&gt;data['users'][$k]-&gt;groups = $this-&gt;ion_auth-&gt;get_users_groups($user-&gt;id)-&gt;result();
          }
          foreach ($this-&gt;data['users'] as $k =&gt; $user)
          {
              $this-&gt;data['users'][$k]-&gt;companies = $this-&gt;ion_auth-&gt;get_company($user-&gt;id)-&gt;result();
          }
  
          $this-&gt;_render_page('admin/auth/index', $this-&gt;data);
      }   
  </code></pre>
  
  <p>I would expect to view only the users within the company thoug.. wat could be wrong with my controller?</p>