【问题标题】:How can I hide data for User Roles in Perfex CRM?如何在 Perfex CRM 中隐藏用户角色的数据?
【发布时间】:2023-03-15 07:20:01
【问题描述】:

我需要一个功能来隐藏 Perfex CRM for User Roles 的某些部分。示例:折扣区。

我尝试使用此代码:

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

但没有任何效果,它为每个人隐藏了这部分,包括管理员。

编辑

这个正在工作,但只是为了通过 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();
    }

【问题讨论】:

  • 我不确定这是您的客户端代码还是服务器端代码,并且它不会使用 php 或 javascript 编译,因此您可能只是将其转储到浏览器中,然后尝试解释它。你的 JavaScript 控制台有错误吗?
  • 不:/没有错误。它称为 STYLE,但适用于所有人,而不仅仅是角色。
  • 你在哪里调用那个函数?

标签: javascript php codeigniter


【解决方案1】:

hide_fields_nonusers() 很可能会产生 PHP 错误,因为此函数不是完全有效的 PHP 代码。

回答您的问题 - 根据您提供的内容 - 如果您在 $role 不等于 4 时将样式标签作为 PHP 代码回显,这应该可以。

注意:如果您没有收到任何错误消息,则表明该函数根本没有执行。正如 Marcel 评论的那样,如果您可以发布您调用此函数的位置,我们可以更仔细地查看。

PHP

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

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));
    }
}

【讨论】:

  • 我将它添加到仅用于管理区域的自定义 JavaScript(后端),这是 Perfex CRM 的一个模块。试过你的,但不起作用:/它为每个人隐藏了#sconto,包括角色 4。
  • 我也为您添加了一个 javascript 解决方案 - 在答案中更新 - 如果它仍然无法正常工作,请告诉我?
  • 什么都没有。他们俩都不起作用...使用 PHP 功能,系统可以为所有人隐藏。我用工作代码编辑问题,但不是为了我需要的东西......
猜你喜欢
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 2018-07-19
  • 2012-09-16
  • 1970-01-01
  • 1970-01-01
  • 2011-12-29
  • 2011-07-06
相关资源
最近更新 更多