PDA

View Full Version : How do you implement varname from new settings in custom php script?


EquinoxWorld
07-18-2011, 12:07 PM
Hello everyone, I have been trying to figure those out on my own for the whole weekend with no avail, I hope someone has some ideas as to what I can do to solve my concern.

I just created my first option for my custom script (first one! :) ) through debug mode in settings panel in admincp. It's called "Can View Contests" (of new group " Contest Of The Week") and I set the default value to be 6 as the usergroup allowed to view these pages by default. The option also has a varname which I created (oftw_can_view). Aside from the values of the new settings created how I do Implement now this new option into my custom pages? I want to be able to restrict with this option the ability to see these pages of my script to only usergroup 6 (for now by default).?? Please if anyone has any ideas or can shed any light please share. :) I can control who sees each page by a simple if condition within the php code of each page but I want to be able to control it globally and not have to edit each page every time I want to allow another usergroup.

Best Regards,

Equinox

Hope everyone had a great weekend.

Disasterpiece
07-18-2011, 12:18 PM
All variables which you defined in the settings are available through
$vbulletin->options['oftw_can_view']

the code snippet you're looking for is:
if (!is_member_of($vbulletin->userinfo, $vbulletin->options['oftw_can_view'])) {
print_no_permission();
}

If you want to improve your setting so you can define more usergroups separated through commata, use this instead:
if (!(is_member_of($vbulletin->userinfo, explode(',',$vbulletin->options['oftw_can_view'])))) {
print_no_permission();
}


Also make sure to position this code after global.php inclusion.

EquinoxWorld
07-18-2011, 12:33 PM
Thank you so much for the fast reply Disasterpiece. Works perfect, now I understand so much better how those options work. Opens up a whole world of possibilities. :)

Just to see if I have it clear. I'll use the first if condition if I only want ot allow one usegroup per the options and the second if it's more that one?

--------------- Added 1310996257 at 1310996257 ---------------

Funny thing I tried to add another usegroup to this option like usergroups allowed: 6, 1 for example and I press save it loads returns to that same page but the value still remains 6 and not 6,1 like I had put?? Any ideas what I could be doing wrong?

kh99
07-18-2011, 01:16 PM
What did you select for "Data Validation Type"? If you want to be able to enter a comma-separated list you need to select "free".

EquinoxWorld
07-18-2011, 01:20 PM
What did you select for "Data Validation Type"? If you want to be able to enter a comma-separated list you need to select "free".

Integer... ?

Ahhhh perfect now using Free.! Thanks khn99 :) Now it all works perfectly. Is there any official vb documentation one could use for this sort of issues?

Disasterpiece
07-18-2011, 01:52 PM
6, 1 could make problems when you don't make the code more foolproof, but when you consistently stick to 1,2,3 instead of 1, 2, 3 then there are no problems :)

EquinoxWorld
07-18-2011, 03:01 PM
6, 1 could make problems when you don't make the code more foolproof, but when you consistently stick to 1,2,3 instead of 1, 2, 3 then there are no problems :)

Good to know. At this point of my skill level I need every "foolproof" tip you can give me. :) Still learning but I love it though, I carry around a note pad to right down code in case I come up with an idea...Hope to be sharing with the community some of my work soon.