vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   What Conditional do I need to specify *Secondary* User Groups? (https://vborg.vbsupport.ru/showthread.php?t=68872)

Ocean 08-30-2004 01:50 PM

What Conditional do I need to specify *Secondary* User Groups?
 
If I want a section of code in a PHP file to apply to Administrators (Group ID 6) only, I might use the following conditional:


PHP Code:

 
if ($bbuserinfo[usergroupid]==6)
{
 



However, that conditional only works if the Primary User Group for a user is Group ID 6.

How does this conditional need to be modified so that it also works if a user's Secondary User Group is Group ID 6?


Thanks!

rake 08-30-2004 02:03 PM

$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups))
{

}

or, if you want to combine...

$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups) OR $bbuserinfo['usergroupid'] == 6)
{

}

Zachery 08-30-2004 02:14 PM

Quote:

Originally Posted by rake
$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups))
{

}

or, if you want to combine...

$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups) OR $bbuserinfo['usergroupid'] == 6)
{

}

OIr if your connected to vBulletin just use is_member_of

Ocean 08-30-2004 02:31 PM

Quote:

Originally Posted by Zachery

OIr if your connected to vBulletin just use is_member_of

Hi, Zachery! Out of curiosity, what do you mean by "if your connected to vBulletin"? Do you mean if I'm talking about the vB PHP files as opposed to generic PHP coding in general?

If so, than I can tell you that I am talking about the vB PHP files. And in that case, could you give me an example of the proper syntax to use with "is_member_of"?


Thanks!

Ocean 08-30-2004 02:32 PM

Quote:

Originally Posted by rake

$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups))
{

}

or, if you want to combine...

$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups) OR $bbuserinfo['usergroupid'] == 6)
{

}

Hi, Rake! Thanks for replying! Out of curiosity, is there any reason to combine the two conditionals the way you did on your second example? Wouldn't the first one catch both Primary as well as Secondary groups?

rake 08-30-2004 02:43 PM

Hey Ocean.
Yes, you're right in fact. I was under the impression that the function only gets the secondary group ids, but it also fetches the primary group, by default
Code:

function fetch_membergroupids_array($user, $getprimary = true)
For the is_member_of function:

Code:

function is_member_of($userinfo, $usergroupid)

Zachery 08-30-2004 02:53 PM

Quote:

Originally Posted by Ocean
Hi, Rake! Thanks for replying! Out of curiosity, is there any reason to combine the two conditionals the way you did on your second example? Wouldn't the first one catch both Primary as well as Secondary groups?

IF you included vBulletins global.php you can use its functions

so is_member_of($var, x) will work :)

Ocean 08-30-2004 03:25 PM

Quote:

Originally Posted by Zachery

IF you included vBulletins global.php you can use its functions

so is_member_of($var, x) will work :)

This would be for code added to ShowThread.php and Misc.php - so I am assuming that there wouldn't be a problem, yes?

And that being the case, is this the proper syntax?


PHP Code:

 
if (is_member_of($bbuserinfo6)
{
 



Or am I formatting it wrong?

rake 08-30-2004 03:32 PM

should be:

if (is_member_of($bbuserinfo, 6))
{

}

Ocean 08-30-2004 03:33 PM

Quote:

Originally Posted by rake

should be:

if (is_member_of($bbuserinfo, 6))
{

}

I got caught by the trailing parenthesis! Thanks, rake and Zachery. I appreciate all of your help! :)


All times are GMT. The time now is 04:43 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01163 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete