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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,913
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 577
  • Total: 578
  • @rjen

Article Category Permissions

Started by Inny, April 29, 2009, 11:47:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zetan

Ok, try


if (in_array('7,9,10', $GLOBALS['user_info']['groups']))

maldave

Quote from: Zetan on June 24, 2009, 02:31:38 PM
Ok, try


if (in_array('7,9,10', $GLOBALS['user_info']['groups']))


I did and it didn't work either  :-\

Zetan

Hmmm... I've probably got the placement wrong. It may need to "exclude" member groups.
I'm not the greatest code guru, I am one of the greatest Copy / Pasters, though. :P

Perhaps somebody else can help.

IchBin

In your code you need to put the right variable in place. $GLOBALS is not a variable. It should look like this:

{
global $context;
if ($context['user']['is_guest'])
echo '
This page is available to Members Only. ';
}
{
global $context;
if (in_array(7, $context['user_info']['groups']))
echo '
<iframe id="myframe" src="eqdkp" marginheight="0" vspace="0" hspace="0" scrolling="no" width="100%" frameborder="0" height="1200">none</iframe>';
}
{
global $context;
if (in_array(9, $context['user_info']['groups']))
echo '
<iframe id="myframe" src="eqdkp" marginheight="0" vspace="0" hspace="0" scrolling="no" width="100%" frameborder="0" height="1200">none</iframe>';
}

maldave

Quote from: IchBinâ„¢ on June 24, 2009, 04:02:00 PM
In your code you need to put the right variable in place. $GLOBALS is not a variable. It should look like this:

{
global $context;
if ($context['user']['is_guest'])
echo '
This page is available to Members Only. ';
}
{
global $context;
if (in_array(7, $context['user_info']['groups']))
echo '
<iframe id="myframe" src="eqdkp" marginheight="0" vspace="0" hspace="0" scrolling="no" width="100%" frameborder="0" height="1200">none</iframe>';
}
{
global $context;
if (in_array(9, $context['user_info']['groups']))
echo '
<iframe id="myframe" src="eqdkp" marginheight="0" vspace="0" hspace="0" scrolling="no" width="100%" frameborder="0" height="1200">none</iframe>';
}


IchBin, the change that you purposed didn't work for me. This is the code that you suggested;


if (in_array(7, $context['user_info']['groups']))


When I try to use that I get a blank screen and the page that I want to show in the iframe doesn't show. Since this didn't work I had to use the old one that looks like this;

if (in_array(7, $GLOBALS['user_info']['groups']))

Freddy

#25
I don't think (not sure) but $context['user_info']['groups'] may not exist.

I think you need to use $user_info, where $user_info['groups'] contains all the groups the member is in.

Try this :

global $user_info;

// List all your allowed member groups in this array here...
$allowedMemberGroups = array(7,9,10,11);

$valid = false;

foreach ($allowedMemberGroups as $needle)
{
if (in_array($needle, $user_info['groups']))
$valid = true;
}

if ($valid == false)
{
echo '
This page is available to certain members only. ';
}
elseif ($valid == true)
{
echo '
Here is my iFrame or whatever...';
}


I've only tested it a little, seems to work okay here.

BTW; $user_info is a much much smaller array than $GLOBALS, so whatever you do I would suggest using that instead - it may just save a little on processing.

Also worth noting that a member can be in more than one group - eg an admin could be group 1 but maybe also a newbie in group 4 of the post count group.  Probably won't make much difference to this idea though...

maldave

Quote from: freddy888 on June 24, 2009, 04:53:34 PM
I don't think (not sure) but $context['user_info']['groups'] may not exist.

I think you need to use $user_info, where $user_info['groups'] contains all the groups the member is in.

Try this :

global $user_info;

// List all your allowed boards in this array here...
$allowedBoards = array(7,9,10,11);

$valid = false;

foreach ($allowedBoards as $needle)
{
if (in_array($needle, $user_info['groups']))
$valid = true;
}

if ($valid == false)
{
echo '
This page is available to certain members only. ';
}
elseif ($valid == true)
{
echo '
Here is my iFrame or whatever...';
}


I've only tested it a little, seems to work okay here.

BTW; $user_info is a much much smaller array than $GLOBALS, so whatever you do I would suggest using that instead - it may just save a little on processing.

Also worth noting that a member can be in more than one group - eg an admin could be group 1 but maybe also a newbie in group 4 of the post count group.  Probably won't make much difference to this idea though...

This is perfect ;D It works just wondeful and you can exactly put in what groups that should access it ;D Thank you for sharing this code   ;D ;D

Freddy

#27
You are welcome, glad it works :)

Freddy

Just had another look at my code...

I should have used something like $allowedMemberGroups rather than $allowedBoards - I was getting mixed up with another bit of code I did for board access.  So change it to something more appropriate if you want.

I've edited the code I posted above a little, but it's still basically the same thing.  All I did was make the variable name appropriate.

maldave

Quote from: freddy888 on June 24, 2009, 08:24:47 PM
Just had another look at my code...

I should have used something like $allowedMemberGroups rather than $allowedBoards - I was getting mixed up with another bit of code I did for board access.  So change it to something more appropriate if you want.

I've edited the code I posted above a little, but it's still basically the same thing.  All I did was make the variable name appropriate.

Ok I updated it ^^

This website is proudly hosted on Crocweb Cloud Website Hosting.