The problem with doing it with a dropdown with an eval script is that if User A edit the form and selects a status s/he has access to ... then User B edits it, and doesn't have access to that value ... it won't display correctly, 'cos the current value has no corresponding option.
I think a better approach would be to use a join element, to a 'status codes' table, which has the status title and the J! access level needed to use it, and use the 'eval options' to set any options they don't have access to to be disabled.
I just played around with this on my test site ... created a 'status_codes' table like ...
id - normal int primary key
status - field
access_level - join element to J!'s #__viewlevels table (using 'id' as value)
Then on another form, I added a join element to 'status_codes', with 'id' as the value and 'status' as the lable, and in the "Advanced" tab, in the Eval options:
Code:
db = JFactory::getDbo();
$query = $db->getQuery(true);
// select the 'access_level' for this status value
$query->select('access_level')->from('fab_status')->where('id = ' . $db->quote($opt->value));
$db->setQuery($query);
$access = $db->loadResult();
if (!empty($access)) {
// if we got an access level, check to see if the logged on user is in that level
$myLevels = $this->user->getAuthorisedViewLevels();
if (!in_array($access, $myLevels)) {
// if they don't have access, set disable
$opt->disable = true;
}
}
You should then have the complete list of statuses in the dropdown, but ones you don't have access to are disabled (greyed out).
The only wrinkle I ran into is the Use A / User B thing, whereby if User B doesn't have access to the current status and edits the form, the join element will show that value as the current selection (even though it's disabled) ... but when they submit the form, the value won't get submitted (HTML forms don't submit disabled values), so the selection gets cleared in the submitted form.
I kinda hacked round this with a commit:
https://github.com/Fabrik/fabrik/commit/d71044250dd1f2ed2577674807d7a14b272e15e4
(ignore the title of the commit) ... which automagically clears the 'disabled' attribute if the selected value is disabled, when submitting.
So ... if you do a github update, and follow the way I did it, that should work for you.
-- hugh