Plugin Idea: Default Field Values Per User

Re: [Perchpole] Plugin Idea: Default Field Values Per User

By Jason - September 20, 2011

Hi,

Your second option, limiting the values in the drop down, can be done without a plugin by setting your own mysql select statement for the drop down. You would have access to the $CURRENT_USER array, so you'd be able to limit options based on values set in their user accounts record.

The first options, giving a default value behind the scenes, would require a plugin. One option would be to hide the drop down by either making it admin only, or using the show/hide fields pluging (http://www.interactivetools.com/add-ons/detail.php?Show-Hide-Fields-For-Users-1036) then you can have a custom plugin that, when a new record is saved, assigns updates the record with a category value somehow based on the current user.

If you'd like us to create that plugin for you, please email consulting@interactivetools.com and we can go over some options.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Plugin Idea: Default Field Values Per User

Hi, Jason -

I've followed you advice and put together some code. I feel I'm close to achieving my goal but it isn't working as expected.

I created a new multi-select list in the cms_accounts editor (called "categoryAccess"). This echoes the available $categories. I can then assign the categories on a per user basis.

Next, in the cms_records editor I have set up the $category selector with the following MySQL code:

<?php
$categoryAccess = join( ",", explode( "\t", trim( $CURRENT_USER['categoryAccess'], "\t" ) ) );
?>
SELECT cms_category.num, cms_category.name
FROM cms_category
WHERE cms_category.num
IN ('$categoryAccess')
GROUP BY cms_category.num


In theory only those categories which match the current user's categoryAccess numbers should be returned.

It should work - but it doesn't! For some reason I'm not aware of the $categoryAccess variable is not being passed to the query.

Can you give me some advice, please!

:0)

Perch

Re: [Perchpole] Plugin Idea: Default Field Values Per User

By Jason - September 28, 2011

Hi Perch,

You definitely have the right idea. What you need to do is use <?php ?> tags to echo out your variables into the SQL string.

Try this:

<?php
$categoryAccess = join( ",", explode( "\t", trim( $CURRENT_USER['categoryAccess'], "\t" ) ) );
?>
SELECT num, name
FROM `<?php echo $TABLE_PREFIX;?>category`
WHERE num
IN (<?php echo $categoryAccess;?>)
GROUP BY num


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Plugin Idea: Default Field Values Per User

Way-hey!

Thanks, Jason.

:0)

Perch