How can I create a conditional statement to filter certain roles from seeing data.
example: I have a report from a webform, but want to hide personal information like email and phone# and only admins should be able to see it in the report.

e.g.: if role=admin
show data
end if

thanks!

Comments

Anonymous’s picture

I dont have any experience on webform but I think it will be something like:

global $user;

$roles = array_flip($user->roles);
if (!array_key_exists('admin', $roles)) {
  //remove the fields
}

vako’s picture

Thanks. I tried it in the code and got a syntax error. Here's the actual code, appreciate any help:
...
$header = array(
theme('table_select_header_cell'),
array('data' => t('Username'), 'field' => 'u.name'),
t('Profile'),
array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
array('data' => t('Last access'), 'field' => 'u.access'),
array('data' => t('Status'), 'field' => 'u.status'), <-- I need the following two fields be visible only to admins and assistant admins
t('')

}
);

the error was:
Parse error: syntax error, unexpected '<', expecting ')' in .../user.admin.inc on line 914

vako’s picture

OK, let me put it in a different way:

If we have a table with columns: Name Address Phone# Email
and we want to hide Phone# and Email columns from anonymous visitors, how can it be done?

Hope someone will be able to give me a sample code to accomplish this.