How can I hide data for User Roles in Perfex CRM?

Viewed 746

I need a function that hides some parts of Perfex CRM for User Roles. Example: Discount area.

I tried with this code:

function hide_fields_nonusers()
{
    if ($role != '4') {    
        <style type="text/css">
            #sconto {
                display: none !important;
            }
            #discount_area {display: none !important;}
        </style>
 }

But nothing works, it hides that part for everyone, admin included.

EDIT

This one is working, but just for get employee role by ID.

/**
     * Get employee role by id
     * @param  mixed $id Optional role id
     * @return mixed     array if not id passed else object
     */
    public function get($id = '')
    {
        if (is_numeric($id)) {

            $role = $this->app_object_cache->get('role-' . $id);

            if ($role) {
                return $role;
            }

            $this->db->where('roleid', $id);

            $role              = $this->db->get(db_prefix() . 'roles')->row();
            $role->permissions = !empty($role->permissions) ? unserialize($role->permissions) : [];

            $this->app_object_cache->add('role-' . $id, $role);

            return $role;
        }

        return $this->db->get(db_prefix() . 'roles')->result_array();
    }
1 Answers

It's likely hide_fields_nonusers() would produce a PHP error as this function is not quite valid PHP code.

To answer your question - based on what you have provided - if you echo out the style tags as PHP code when $role does not equal 4 this should work.

Note: If you're not receiving any error messages then it would suggest the function is not executing at all. As Marcel commented, if you can post where you call this function we could look a little closer.

PHP

public function hide_fields_nonusers()
{
  
    if ($role != '4') {    
        echo '<style type="text/css">
              #sconto { display:none !important; }
              #discount_area { display:none !important; }
              </style>';
    }
}

OR for JavaScript

if ($role != 4) {
    var css   = '#sconto { display:none !important; }
                 #discount_area { display:none !important; }',
        head  = document.head || document.getElementsByTagName('head')[0],
        style = document.createElement('style');

    head.appendChild(style);

    style.type = 'text/css';
    if (style.styleSheet) {
       // This is required for IE8 and below.
       style.styleSheet.cssText = css;
    } else {
       style.appendChild(document.createTextNode(css));
    }
}
Related