TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 18, 2024, 01:25:28 PM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 112
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 46
  • Total: 46

Settings Membergroup Permissions for Articles/Blocks

Started by feeble, May 17, 2006, 03:39:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

feeble

To Restrict which membergroups can view a particular article
In php mode use the following code to restrict this article to only group 11, or any other group that you choose.

Demo: http://www.nsxhq.com/index.php?page=34

Code: Just copy this in an article to give it a go, just replace 11, to the membergroup that you would like only to see this article. Just needs to be in php mode and you good to go
if ( in_array(11, $GLOBALS['user_info']['groups']) )
{
echo"<div align='center'>You can see this because you are in the correct membergroup</div>";
}
else{
echo "<div align='center'>You do not have permission to see this</div>";
}


should work in both article and block, just make sure php is activated

G6Cad

When you post those things, it would be good if you provide more information around it.
EG, what file to look for, and what string in that file, if it is some files that need to be replaced.

Or if it is code that goes into a Block, What kind of Block (in this case i guess itÂÃ,´s a PhP block)
In the whole, a bit more information about the code and what it do so more people can understand even if they have no coding experience at all.

Thanks in Advance

feeble


Assistance

#3
if it goes into a php block then how are you hiding the/a/and/or  "Article" block ?

how would someone enable for more then one group?

JPDeni

This is for an article, not a block. The blocks already have settings for whether different member groups can see them.

The real beauty of this is that the same article can say different things for different people. For example, I've got a little javascript Wordsearch game in an article. If the membergroup is Admin or Global Moderator, when they go to the page, they see not only the game, but a dropdown list of all of the files I've created for the game and, if they select one of the file names, the contents of the file shows up in a textarea where the file can be edited.

In another article, I've got a list of links (from a database I'd set up on another site). I included a link to edit the links which only shows up when an Admin or Global Moderator is viewing the page. It's really spiffy.

Quotehow would someone enable for more then one group?

If you wanted to give groups 11 and 14 the permission, you would do this:

if ( in_array(11, $GLOBALS['user_info']['groups']) || in_array(14, $GLOBALS['user_info']['groups']) )
{
echo"<div align='center'>You can see this because you are in the correct membergroup</div>";
}
else{
echo "<div align='center'>You do not have permission to see this</div>";
}


You could even be really fancy and say something like


if ( in_array(11, $GLOBALS['user_info']['groups']) || in_array(14, $GLOBALS['user_info']['groups']) )
{
echo"<div align='center'>You're in one of my favorite member groups</div>";
}
if ( in_array(10, $GLOBALS['user_info']['groups']) || in_array(9, $GLOBALS['user_info']['groups']) )
{
echo"<div align='center'>You're in an okay member group</div>";
}
else{
echo "<div align='center'>I don't like people in your group</div>";
}


You wouldn't say those things, of course, but you could put anything in there.

You can also use this within a php block.

Assistance

i was not aware we could do php in articles
this changes the entire meaning of life ( at least on my board )

second part I allready knew, just makes it easier for others that dont and are using search or viewing this page :)

it does help the board in the long run and ty for the explanation

G6Cad

A little more tease here. "Me really like the feeling of being cruel  >:D "
In the next release you will have A LOT more freedome with code blocks and ways to show them in your forum.
you will be able to put the articles where you want and the same with blocks, nothing binds eather one of them to be at one place or another. :D

hebxi1

exactly what I was looking for ... thanks for the snippet and yay! for the search function! :D

stigmartyr

Hooray for the search feature.  I haven't posted much but wanted it to be known I come back to TP.net often looking for snippets and guidance.  I'm using this code and it works great!