RESET THE VALUE OF A FIELD IN ALL RECORDS OR IN FIELDS IN MULTIPLE TABLES (CHECK BOXES ONLY) - Nov 11th, 2011
|
And here’s another useful plugin from Carl Crowder at Interactive Tools called fieldResetter. This one does exactly that. It resets the all the values of one or more fields in one or more tables globally. I’m using it to reset a field in a membership database called paid_for_current_year, which needs to be reset at the end of each year.
After implementing the plugin, you'll find the option to execute the global change in the "Advanced Commands" pull down menu at the bottom of the record list for that section editor.
You can download this plugin from:
http://www.thecmsbcookbook.com/downloads/fieldResetter.zip
Implementation is really simple.
If you want to globally reset the value of a check box field called “paid_for_current_year” to “0" in a table called “members”, you’d adjust the array on line 15 to:
$GLOBALS['FIELD_RESET_FIELDS'] = array( array('Table name' => 'members', 'fieldName' => 'paid_for_current_year', 'resetValue' => 0 ) );
If you have 2 fields to be reset, you’d adjust the array to:
$GLOBALS['FIELD_RESET_FIELDS'] = array( array('Table name' => 'members', 'fieldName' => 'paid_for_current_year', 'resetValue' => 0 ), array('Table name' => 'members', 'fieldName' => 'other_field', 'resetValue' => 0 ) ); );
For 2 tables:
$GLOBALS['FIELD_RESET_FIELDS'] = array( array('Table name' => 'members', 'fieldName' => 'paid_for_current_year', 'resetValue' => 0 ), array('Table name' => 'other_table', 'fieldName' => 'other_field', 'resetValue' => 0 ) );
Let’s say you wanted to give permission to accomplish this to a “Super Admin only, you could add a check box field to your Accounts section called 'super_admin' and change the check on line 27 to
if ( !$CURRENT_USER['super_admin'] ) return;
If you make the “super_admin” field a system field, it will be harder to inadvertently change it’s value.
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.