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