Plugin Idea: Default Field Values Per User

Hello, All...

Whilst working on a community project I've run into an issue that's given me an idea for a useful plugin. I'm not entirely sure if it's possible but here's the scenario...

Under normal circumstances, when user Joe Bloggs adds a record to the system he is able to assign it to a category by means of a drop-down list. Instead of allowing him to choose, however, I want the plugin to assign a value automatically based on his user number.

For example, whenever Joe adds a new record, the category selector would have a pre-defined value of "Book Club" - which Joe cannot change.

Alternatively, instead of assigning a default value, the plugin could simply limit the available categories in the drop-down list.

So, if Joe is a member of the Book Club and the Wine Appreciation Society, only these two options are available to him in the drop-down category selector list.

I think this would be very useful.

Is it possible?

:o)

Perchpole

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: [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