Hi everyone,
I try to display different panels in my custom module’s detail view based on users’ roles.
Here is my code for view.detail.php
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.detail.php');
class a1234_meViewDetail extends ViewDetail
{
function a1234_meViewDetail()
{
parent::ViewDetail();
}
function display()
{
if(empty($this->bean->id)) {
global $app_strings;
sugar_die($app_strings['ERROR_NO_RECORD']);
}
if(file_exists('cache/modules/' . $this->bean->module_dir . '/DetailView.tpl')) unlink('cache/modules/' . $this->bean->module_dir . '/DetailView.tpl');
require_once('modules/a1234_me/metadata/toggle_panel_fieldsdefs.php');
global $current_user;
foreach($toggle_panel_fieldsdefs as $role => $field_defs){
foreach($field_defs as $field => $visible){
if ($current_user->check_role_membership($role)){
foreach($this->dv->defs['panels'] as $panel => $panel_defs){
if ((strtoupper($panel) == strtoupper($field)) && ($visible == 0)) {
//$this->dv->defs['panels'][$panel] = array();
unset($this->dv->defs['panels'][$panel]);
}
}
}
}
}
parent::display();
}
}
However, there is a problem.
After I login as one role, the code works well, for example, a sale panel is hidden.
I switch to another role which the sale panel should be displayed.
Nevertheless, the sale panel is still hidden from that user.
Once a panel is unset, it never come back until repair the system.
Can anybody help me?