⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Get permission data from Database



leoenessa
  • profile picture
  • Member

Posted 29 October 2013 - 17:18 PM

Hi guys. I'm having problems to do a simple permission system on my Webapp. My DB has a table called "usuario" that has informations about the users of the system. One of these columns is called "privilegio" that has value '0' for administrators and 1 for regular users. An administrator has the power to Add and edit users on the system. Im trying to take this behavior querying my database with the cod of the logged user and getting its permission. If the user is not on the administrator group (privilegio=1) then the add/edit/delete buttons will be unset.

public function usuario() {
   if($this->session->userdata('logged')){ 
      $crud = new grocery_CRUD(); 
      $crud->set_subject("Usuário"); 
      $crud->set_theme('datatables'); 
      $crud->set_table("usuario"); 
      (...) 
      $crud->field_type('privilegio','dropdown',array('0'=>'Administrador','1'=>'Usuario'));
      (...) 
      $this->db->select('privilegio');
      $this->db->get('usuario'); 
      $result = $this->db->where('cod_func',$this->session->userdata('cod_func')); 
      if(!$result){ 
         $crud->unset_add(); 
         $crud->unset_edit(); 
         $crud->unset_delete(); 
      }
(...)

The problem (and the question) is that this code only list the user that is logged on, not the others already registered on the system and stored on "usuario" table. I wonder that the list is been made by my query (what is not the behavior I would like) I wonder you could undestand my doubt. Sorry for my bad english.


Amit Shah
  • profile picture
  • Member

Posted 30 October 2013 - 22:46 PM

Hi there

 

Welcome to GC forums.

Well if i correctly understand - what you need is to disallow the users other thn with admin privileges to delete / edit .. etc.. what you seems to have done right by unsetting the add / edit / delete.

This much we understood i believe

but the part of your queries ... sorry was not clear as what you required / requested for.

It wil be great if you can explain your requirement more clearly.


leoenessa
  • profile picture
  • Member

Posted 31 October 2013 - 15:54 PM

Thank you for your attention Amit.
I've chances the query code to This:


$this->db->select('privilegio');

    $this->db->from('usuario');

    $this->db->where('cod_func',$this->session->userdata('cod_func')); 
    $this->db->limit(1); 
    $result = $this->db->get(); 
    If(!$result){
        (....)
    }
 

 

But now i got an error that says that cant convert CI DB to int.
Whats wrong? :(
 
Thank you again