phpBB.com     phpBB Academy     phpBB Modders     phpBB Weekly     ktuk     phpBB Hacks     Vlad Studio  

Showing information based on Group

The tutorial shows how to show different information depending on what group a user is in

Not enough for a full proper MOD, but too useful not to share
Forum rules
Please read over our forum guidelines

Showing information based on Group

Postby kenny » 29 Nov 2009, 02:23

I keep loosing this snippet and quite often I notice people asking for it, so I decided to post it here. Credit goes to RMcGirr83 for the code itself - I'd like to make it clear that he posted this on phpbb.com. I'm merely relaying the info :)

Comment:
#
#-----[ OPEN ]------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------
#
Code: Select all
    // application/xhtml+xml not used because of IE
    header('Content-type: text/html; charset=UTF-8'); 

#
#-----[ BEFORE, ADD ]------------------------------------------
#
Code: Select all
    // Check what group a user is in
    if ( !function_exists('group_memberships') )
    {
        include_once($phpbb_root_path . 'includes/functions_user.'.$phpEx);
    }

    $groups = group_memberships(false,$user->data['user_id']);
    foreach ($groups as $grouprec)
    {
        $template->assign_vars(array(
            'S_GROUP_' . $grouprec['group_id'] => true
        
));
    } 


Now on any page, you should be able to use this switch
Code: Select all
<!-- IF S_GROUP_X -->

Just replace X with ID of the group. You can also expand on that and add multiple groups and/or any other template function that is built into phpBB
Code: Select all
<!-- IF S_GROUP_1 or S_GROUP_2 --> // if user is in either of the groups

Code: Select all
<!-- IF S_GROUP_1 and S_GROUP_2 --> // User has to be in both groups to return true

Code: Select all
<!-- IF not S_GROUP_X --> // Show for all except that group
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Donate to 6 String MODs
If you like any of the work that I do here, please consider donating.
click the image on the left for a list of some of the advantages of donating



Re: Showing information based on Group

Postby 1nkling » 07 Mar 2010, 19:12

Hi, I've tried this yesterday on my forum but when I add the section of code to functions.php and upload it I then get an error on my board saying :

Parse error: syntax error, unexpected $end in /home/myserver/shropshire-suzuki.co.uk/forum/includes/functions.php on line 3765

Any idea where I'm going wrong?

Thanks
User avatar
1nkling
Registered User
Registered User
 
Posts: 4
Joined: 07 Mar 2010, 14:35

Re: Showing information based on Group

Postby kenny » 07 Mar 2010, 20:48

I had a thought when I seen that error. Did you add an ENDIF to the HTML that you're trying to hide?
eg:
Code: Select all
<!-- IF S_GROUP_X -->
//code here
<!-- ENDIF -->

If not, add that ENDIF at the end of your template code, purge the cache and it should work :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Re: Showing information based on Group

Postby 1nkling » 08 Mar 2010, 00:40

kenny » Yesterday, 20:48 wrote:I had a thought when I seen that error. Did you add an ENDIF to the HTML that you're trying to hide?
eg:
Code: Select all
<!-- IF S_GROUP_X -->
//code here
<!-- ENDIF -->

If not, add that ENDIF at the end of your template code, purge the cache and it should work :)


I'm getting this error before I've even edited any of the html.. as soon as I edit the functions.php if I hit refresh on my forum I get that error or similar..
User avatar
1nkling
Registered User
Registered User
 
Posts: 4
Joined: 07 Mar 2010, 14:35

Re: Showing information based on Group

Postby kenny » 08 Mar 2010, 19:20

Can you post what your functions.php file looks like after you make the change? Post the 8 lines before and after that code please :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Showing information based on Group

Postby 1nkling » 08 Mar 2010, 21:21

Here ya go, hope thats right.. Few more than 8 lines at the end.. :)

Code: Select all
      'T_ICONS'            => $config['icons_path'],
      'T_RANKS'            => $config['ranks_path'],
      'T_UPLOAD'            => $config['upload_path'],

      'SITE_LOGO_IMG'         => $user->img('site_logo'),

      'A_COOKIE_SETTINGS'      => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')),
   ));

    // Check what group a user is in
    if ( !function_exists('group_memberships') )
    {
        include_once($phpbb_root_path . 'includes/functions_user.'.$phpEx);
    }

    $groups = group_memberships(false,$user->data['user_id']);
    foreach ($groups as $grouprec)
    {
        $template->assign_vars(array(
            'S_GROUP_' . $grouprec['group_id'] => true
        ));
    }
   
   // application/xhtml+xml not used because of IE
   header('Content-type: text/html; charset=UTF-8');

   header('Cache-Control: private, no-cache="set-cookie"');
   header('Expires: 0');
   header('Pragma: no-cache');

   return;
}

User avatar
1nkling
Registered User
Registered User
 
Posts: 4
Joined: 07 Mar 2010, 14:35

Showing information based on Group

Postby 1nkling » 10 Mar 2010, 19:04

Well, as kenny already knows because I talked to him in IRC I've solved this problem..

I'm not entirely sure what I did the first time but earlier I thought I'd have one more go and it worked!
I guess somehow I must have made a mistake in the steps I took.. :oops:

Anyway.. all is good and I am able to hide adverts from my donating members.. Great it of code, just what I needed, thanks load! :)
User avatar
1nkling
Registered User
Registered User
 
Posts: 4
Joined: 07 Mar 2010, 14:35




Return to Code Snippets

Who is online

Google [Bot], MSN [Bot], Yahoo [Bot]


cron