Hi
am using using sugar 4.2.*, i want to restrict the drop down values based on the role.how to do this. plz guide me.
regards.
BSK
Hi
am using using sugar 4.2.*, i want to restrict the drop down values based on the role.how to do this. plz guide me.
regards.
BSK
Hi,
I fear what you want to do is not possible with sugar.
Cheers
Gunnar
Gunnar von Boehn
myCRMspace
Hi there, we did this in the EditView.php file.Originally Posted by bands
If you notice that all drop downs / Selects are built within this page.
What I did was setup seperate drop down arrays and based off ot the Role, is which one got loaded.
Let me know if you need more help, I'll show you some code.
Hi,
I think this is something that would also be interesting for other users. Could you post what you did here? It would be something that should also be put in the SugarWiki.
Are the modifications safe from new versions and patches?
Cheers Malcolm
Genius4U Limited - Ingenious simple IT solutions for you / Genial einfache IT Lösungen für Sie
http://www.genius4u.com or http://www.genius4u.de
I'll try to write it up in a format that will make it easy for all to follow.Originally Posted by malcolmh
I believe the code to be mod & version safe with the exception of adding a new EditView.php file and lead.php (my example, we used lead).
I'm almost done with the document. If it's something that gets added to the Wiki, who makes that decision? How can I submit it to be added to the Wiki?
Last edited by sacramentojoe; 2006-12-13 at 01:11 AM.
Hi sacramentojoe, this enhancement you have sounds terrific.
The Sugar Wiki is available for any community member to extend and enhance. If you need assistance then just shout out and we can help. Wiki syntax examples are rampant across the web but we can help if need be.
Andy
Andy Dreisch
Vice President, Online Team
Check out our Podcasts!
Sugar University for training
Sugar Wiki for developer and user help
SugarForge for modules, themes, lang packs
SugarExchange for production-ready extensions
Enter/view bugs via the Sugar bug tracker
Hi Andy, I'm new to the whole Wiki idea so I'll definitely need some assistance.Originally Posted by andydreisch
I have a rough draft written but I'm going to spend some more time going over the details and making sure that I didn't miss anything.
Joe
HiOriginally Posted by sacramentojoe
can u show me some code...so that i can proceed..
thanks
bsk
OK, here is my attempt to explain this. If there is an easier / cleaner way to do this, feel free to let me know.
How to Add Role Restriction to a Drop Down
The first thing I did was create three (3) drop downs.
I prefer to manually create them but you can create them via the studio if you’d like.
Here is what my /custom/include/language/en_us.lang.php file looks like
This first drop down is going to be the drop down that I use when I create my custom field. I chose to have the main drop down contain all of the values. If for some reason the logic I’m going to build was to fail, the user will be able to see all of the options. You could just as easily make this one value such as ‘Default’. It’s up to you.
This is the drop down list that will get loaded if they have manager view.Code:$app_list_strings[‘role_select_dom’] = array( ‘Manager View 1’ => ‘Manager View 1’, ‘Manager View 2’ => ‘Manager View 2’, ‘Regular View 1’ => ‘Regular View 1’, ‘Regular View 2’ => ‘Regular View 2’,);
This is the drop down list that will get loaded if they have a non-manager view.Code:$app_list_strings[‘manager_role_select_dom’] = array( ‘Manager View 1’ => ‘Manager View 1’, ‘Manager View 2’ => ‘Manager View 2’,);
For this example, I’ll be using the lead module.Code:$app_list_strings[‘regular_role_select_dom’] = array( ‘Regular View 1’ => ‘Regular View 1’, ‘Regular View 2’ => ‘Regular View 2’,);
I went through the Studio to create my custom field.
I chose a drop down as the custom field type and I selected the “role_select_dom” as the drop down to use. I named my custom field “role_select”. Again, this will be loading ALL of the values by default. I then proceeded to add this new custom field to the EditView.html and DetailView.html of the Lead module. I also did this via the Studio.
If you open up the EditView.html, you’ll see a line similar to this.
This line tells us 2 things.Code:<select name=”role_select_c”>{OPTIONS_ROLE_SELECT_C}</Select>
1. The name of our custom field is actually role_select_c.
2. The options for the select come from OPTIONS_ROLE_SELECT_C and this is what we'll be over riding.
Now that I know the name of the custom field, I added it to the variable list in the Lead.php file
This is necessary as it maps the custom field to a member variable that we can reference later.Code:var $role_select_c ;
The next step is to edit EditView.php.
All custom fields are loaded with this statement.If you look in EditView.php for OPTIONS_ROLE_SELECT_C, you will not see it. It's built in the background by calling this script.
//Add Custom Fields
Since our field is custom, we’ll want to make changes AFTER this line in order to over-ride the value.Code:require_once('modules/DynamicFields/templates/Files/EditView.php');
I borrowed the next bit of Code from a post where Julian gives an example to check for roles.
http://sugarcrm.com/forums/showthread.php?t=9829
That's all there is to it. You could also get away with creating 2 drop downs, one for manager view and one for default view and only switch the manager view if the manager is loaded. As usual, there is more than one way to get things done but here is how I did it.Code:$role_to_check = "Team Manager"; // change this to the name of the role that you want to do a check on global $current_user; // grab the $current_user object require_once("modules/ACLRoles/ACLRole.php"); $acl_role_obj = new ACLRole(); $user_roles = $acl_role_obj->getUserRoles($current_user->id); // grab a list of the current user's roles $user_in_role = FALSE; foreach ($user_roles as $role) { if ($role->name == $role_to_check) { // is the user in the role we're trying to restrict? $user_in_role = TRUE; break; } } //If the user is in the role, display the Manager view dropdown //Here, we’re over riding the OPTIONS_ROLE_SELECT_C, notice how we’re now referencing the role_select_c variable that we added to Lead.php if ($user_in_role) { $xtpl->assign("OPTIONS_ROLE_SELECT_C",get_select_options_with_id($app_list_strings['manager_role_select_dom],$focus->role_select_c)); }else{ //User is not in role, display the regular / default values $xtpl->assign("OPTIONS_ROLE_SELECT_C",get_select_options_with_id($app_list_strings['regular_role_select_dom'],$focus->role_select_c)); }
Last edited by sacramentojoe; 2006-12-13 at 05:01 PM.
Hi sacramentojoe
Thanks for ur quick reply....
regards
bsk
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks